]>
Commit | Line | Data |
---|---|---|
d3ad40de | 1 | .\" |
726f6388 JA |
2 | .\" MAN PAGE COMMENTS to |
3 | .\" | |
4 | .\" Chet Ramey | |
726f6388 | 5 | .\" Case Western Reserve University |
e225d5a9 | 6 | .\" chet@po.cwru.edu |
726f6388 | 7 | .\" |
abe2eb5b | 8 | .\" Last Change: Sat Feb 4 17:32:13 EST 2012 |
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 |
abe2eb5b | 13 | .TH BASH 1 "2012 February 4" "GNU Bash 4.2" |
726f6388 JA |
14 | .\" |
15 | .\" There's some problem with having a `@' | |
16 | .\" in a tagged paragraph with the BSD man macros. | |
17 | .\" It has to do with `@' appearing in the }1 macro. | |
18 | .\" This is a problem on 4.3 BSD and Ultrix, but Sun | |
19 | .\" appears to have fixed it. | |
20 | .\" If you're seeing the characters | |
21 | .\" `@u-3p' appearing before the lines reading | |
22 | .\" `possible-hostname-completions | |
23 | .\" and `complete-hostname' down in READLINE, | |
24 | .\" then uncomment this redefinition. | |
25 | .\" | |
26 | .de }1 | |
27 | .ds ]X \&\\*(]B\\ | |
28 | .nr )E 0 | |
29 | .if !"\\$1"" .nr )I \\$1n | |
30 | .}f | |
31 | .ll \\n(LLu | |
32 | .in \\n()Ru+\\n(INu+\\n()Iu | |
33 | .ti \\n(INu | |
34 | .ie !\\n()Iu+\\n()Ru-\w\a\\*(]X\au-3p \{\\*(]X | |
35 | .br\} | |
36 | .el \\*(]X\h\a|\\n()Iu+\\n()Ru\a\c | |
37 | .}f | |
38 | .. | |
39 | .\" | |
40 | .\" File Name macro. This used to be `.PN', for Path Name, | |
41 | .\" but Sun doesn't seem to like that very much. | |
42 | .\" | |
43 | .de FN | |
44 | \fI\|\\$1\|\fP | |
45 | .. | |
46 | .SH NAME | |
ccc6cda3 | 47 | bash \- GNU Bourne-Again SHell |
726f6388 JA |
48 | .SH SYNOPSIS |
49 | .B bash | |
50 | [options] | |
e67d0029 | 51 | [command_string | file] |
726f6388 | 52 | .SH COPYRIGHT |
5a318736 CR |
53 | .if n Bash is Copyright (C) 1989-2012 by the Free Software Foundation, Inc. |
54 | .if t Bash is Copyright \(co 1989-2012 by the Free Software Foundation, Inc. | |
726f6388 JA |
55 | .SH DESCRIPTION |
56 | .B Bash | |
ccc6cda3 | 57 | is an \fBsh\fR-compatible command language interpreter that |
726f6388 JA |
58 | executes commands read from the standard input or from a file. |
59 | .B Bash | |
60 | also incorporates useful features from the \fIKorn\fP and \fIC\fP | |
61 | shells (\fBksh\fP and \fBcsh\fP). | |
62 | .PP | |
63 | .B Bash | |
ac18b312 CR |
64 | is intended to be a conformant implementation of the |
65 | Shell and Utilities portion of the IEEE POSIX specification | |
66 | (IEEE Standard 1003.1). | |
7790f917 CR |
67 | .B Bash |
68 | can be configured to be POSIX-conformant by default. | |
726f6388 | 69 | .SH OPTIONS |
3d8cce26 CR |
70 | All of the single-character shell options documented in the |
71 | description of the \fBset\fR builtin command can be used as options | |
72 | when the shell is invoked. | |
73 | In addition, \fBbash\fR | |
cce855bc | 74 | interprets the following options when it is invoked: |
726f6388 JA |
75 | .PP |
76 | .PD 0 | |
77 | .TP 10 | |
e67d0029 | 78 | .B \-c |
ccc6cda3 | 79 | If the |
726f6388 | 80 | .B \-c |
e67d0029 CR |
81 | option is present, then commands are read from the first non-option argument |
82 | .IR command_string . | |
726f6388 | 83 | If there are arguments after the |
e67d0029 | 84 | .IR command_string , |
726f6388 JA |
85 | they are assigned to the positional parameters, starting with |
86 | .BR $0 . | |
87 | .TP | |
7117c2d2 JA |
88 | .B \-i |
89 | If the | |
90 | .B \-i | |
91 | option is present, the shell is | |
92 | .IR interactive . | |
93 | .TP | |
94 | .B \-l | |
95 | Make | |
96 | .B bash | |
97 | act as if it had been invoked as a login shell (see | |
98 | .SM | |
99 | .B INVOCATION | |
100 | below). | |
101 | .TP | |
ccc6cda3 JA |
102 | .B \-r |
103 | If the | |
104 | .B \-r | |
cce855bc | 105 | option is present, the shell becomes |
ccc6cda3 JA |
106 | .I restricted |
107 | (see | |
108 | .SM | |
109 | .B "RESTRICTED SHELL" | |
110 | below). | |
111 | .TP | |
726f6388 JA |
112 | .B \-s |
113 | If the | |
114 | .B \-s | |
cce855bc | 115 | option is present, or if no arguments remain after option |
726f6388 JA |
116 | processing, then commands are read from the standard input. |
117 | This option allows the positional parameters to be set | |
118 | when invoking an interactive shell. | |
119 | .TP | |
ccc6cda3 JA |
120 | .B \-D |
121 | A list of all double-quoted strings preceded by \fB$\fP | |
22e63b05 | 122 | is printed on the standard output. |
ccc6cda3 JA |
123 | These are the strings that |
124 | are subject to language translation when the current locale | |
28ef6c31 | 125 | is not \fBC\fP or \fBPOSIX\fP. |
ccc6cda3 JA |
126 | This implies the \fB\-n\fP option; no commands will be executed. |
127 | .TP | |
f73dda09 JA |
128 | .B [\-+]O [\fIshopt_option\fP] |
129 | \fIshopt_option\fP is one of the shell options accepted by the | |
130 | \fBshopt\fP builtin (see | |
131 | .SM | |
132 | .B SHELL BUILTIN COMMANDS | |
133 | below). | |
134 | If \fIshopt_option\fP is present, \fB\-O\fP sets the value of that option; | |
135 | \fB+O\fP unsets it. | |
136 | If \fIshopt_option\fP is not supplied, the names and values of the shell | |
137 | options accepted by \fBshopt\fP are printed on the standard output. | |
138 | If the invocation option is \fB+O\fP, the output is displayed in a format | |
139 | that may be reused as input. | |
140 | .TP | |
ccc6cda3 JA |
141 | .B \-\- |
142 | A | |
143 | .B \-\- | |
726f6388 JA |
144 | signals the end of options and disables further option processing. |
145 | Any arguments after the | |
726f6388 | 146 | .B \-\- |
ccc6cda3 JA |
147 | are treated as filenames and arguments. An argument of |
148 | .B \- | |
149 | is equivalent to \fB\-\-\fP. | |
726f6388 JA |
150 | .PD |
151 | .PP | |
152 | .B Bash | |
ccc6cda3 JA |
153 | also interprets a number of multi-character options. |
154 | These options must appear on the command line before the | |
7117c2d2 | 155 | single-character options to be recognized. |
726f6388 JA |
156 | .PP |
157 | .PD 0 | |
726f6388 | 158 | .TP |
d3a24ed2 CR |
159 | .B \-\-debugger |
160 | Arrange for the debugger profile to be executed before the shell | |
2206f89a CR |
161 | starts. |
162 | Turns on extended debugging mode (see the description of the | |
d3a24ed2 CR |
163 | .B extdebug |
164 | option to the | |
165 | .B shopt | |
d3a24ed2 CR |
166 | builtin below). |
167 | .TP | |
cce855bc JA |
168 | .B \-\-dump\-po\-strings |
169 | Equivalent to \fB\-D\fP, but the output is in the GNU \fIgettext\fP | |
170 | \fBpo\fP (portable object) file format. | |
171 | .TP | |
ccc6cda3 JA |
172 | .B \-\-dump\-strings |
173 | Equivalent to \fB\-D\fP. | |
174 | .TP | |
175 | .B \-\-help | |
176 | Display a usage message on standard output and exit successfully. | |
177 | .TP | |
28ef6c31 | 178 | \fB\-\-init\-file\fP \fIfile\fP |
7117c2d2 | 179 | .PD 0 |
28ef6c31 JA |
180 | .TP |
181 | \fB\-\-rcfile\fP \fIfile\fP | |
182 | .PD | |
183 | Execute commands from | |
184 | .I file | |
185 | instead of the standard personal initialization file | |
186 | .I ~/.bashrc | |
187 | if the shell is interactive (see | |
188 | .SM | |
189 | .B INVOCATION | |
190 | below). | |
191 | .TP | |
ccc6cda3 | 192 | .B \-\-login |
7117c2d2 | 193 | Equivalent to \fB\-l\fP. |
ccc6cda3 JA |
194 | .TP |
195 | .B \-\-noediting | |
196 | Do not use the GNU | |
197 | .B readline | |
bb70624e | 198 | library to read command lines when the shell is interactive. |
ccc6cda3 JA |
199 | .TP |
200 | .B \-\-noprofile | |
201 | Do not read either the system-wide startup file | |
726f6388 JA |
202 | .FN /etc/profile |
203 | or any of the personal initialization files | |
204 | .IR ~/.bash_profile , | |
205 | .IR ~/.bash_login , | |
206 | or | |
207 | .IR ~/.profile . | |
208 | By default, | |
209 | .B bash | |
ccc6cda3 | 210 | reads these files when it is invoked as a login shell (see |
726f6388 JA |
211 | .SM |
212 | .B INVOCATION | |
213 | below). | |
214 | .TP | |
ccc6cda3 JA |
215 | .B \-\-norc |
216 | Do not read and execute the personal initialization file | |
217 | .I ~/.bashrc | |
218 | if the shell is interactive. | |
219 | This option is on by default if the shell is invoked as | |
220 | .BR sh . | |
221 | .TP | |
222 | .B \-\-posix | |
223 | Change the behavior of \fBbash\fP where the default operation differs | |
ac18b312 | 224 | from the POSIX standard to match the standard (\fIposix mode\fP). |
726f6388 | 225 | .TP |
ccc6cda3 JA |
226 | .B \-\-restricted |
227 | The shell becomes restricted (see | |
228 | .SM | |
229 | .B "RESTRICTED SHELL" | |
726f6388 JA |
230 | below). |
231 | .TP | |
ccc6cda3 JA |
232 | .B \-\-verbose |
233 | Equivalent to \fB\-v\fP. | |
726f6388 | 234 | .TP |
ccc6cda3 JA |
235 | .B \-\-version |
236 | Show version information for this instance of | |
237 | .B bash | |
238 | on the standard output and exit successfully. | |
726f6388 JA |
239 | .PD |
240 | .SH ARGUMENTS | |
241 | If arguments remain after option processing, and neither the | |
242 | .B \-c | |
243 | nor the | |
244 | .B \-s | |
245 | option has been supplied, the first argument is assumed to | |
ccc6cda3 JA |
246 | be the name of a file containing shell commands. |
247 | If | |
726f6388 JA |
248 | .B bash |
249 | is invoked in this fashion, | |
250 | .B $0 | |
251 | is set to the name of the file, and the positional parameters | |
252 | are set to the remaining arguments. | |
253 | .B Bash | |
254 | reads and executes commands from this file, then exits. | |
ccc6cda3 JA |
255 | \fBBash\fP's exit status is the exit status of the last command |
256 | executed in the script. | |
257 | If no commands are executed, the exit status is 0. | |
f73dda09 JA |
258 | An attempt is first made to open the file in the current directory, and, |
259 | if no file is found, then the shell searches the directories in | |
260 | .SM | |
261 | .B PATH | |
262 | for the script. | |
ccc6cda3 JA |
263 | .SH INVOCATION |
264 | A \fIlogin shell\fP is one whose first character of argument zero is a | |
265 | .BR \- , | |
266 | or one started with the | |
267 | .B \-\-login | |
268 | option. | |
269 | .PP | |
bb70624e JA |
270 | An \fIinteractive\fP shell is one started without non-option arguments |
271 | and without the | |
272 | .B \-c | |
273 | option | |
da5b17cd | 274 | whose standard input and error are |
ccc6cda3 JA |
275 | both connected to terminals (as determined by |
276 | .IR isatty (3)), | |
277 | or one started with the | |
278 | .B \-i | |
279 | option. | |
280 | .SM | |
281 | .B PS1 | |
282 | is set and | |
283 | .B $\- | |
284 | includes | |
285 | .B i | |
286 | if | |
287 | .B bash | |
288 | is interactive, | |
289 | allowing a shell script or a startup file to test this state. | |
290 | .PP | |
291 | The following paragraphs describe how | |
292 | .B bash | |
293 | executes its startup files. | |
294 | If any of the files exist but cannot be read, | |
295 | .B bash | |
296 | reports an error. | |
b28ff8c9 | 297 | Tildes are expanded in filenames as described below under |
ccc6cda3 JA |
298 | .B "Tilde Expansion" |
299 | in the | |
300 | .SM | |
301 | .B EXPANSION | |
302 | section. | |
303 | .PP | |
304 | When | |
305 | .B bash | |
b72432fd JA |
306 | is invoked as an interactive login shell, or as a non-interactive shell |
307 | with the \fB\-\-login\fP option, it first reads and | |
d166f048 JA |
308 | executes commands from the file \fI/etc/profile\fP, if that |
309 | file exists. | |
ccc6cda3 JA |
310 | After reading that file, it looks for \fI~/.bash_profile\fP, |
311 | \fI~/.bash_login\fP, and \fI~/.profile\fP, in that order, and reads | |
312 | and executes commands from the first one that exists and is readable. | |
313 | The | |
314 | .B \-\-noprofile | |
315 | option may be used when the shell is started to inhibit this behavior. | |
316 | .PP | |
317 | When a login shell exits, | |
318 | .B bash | |
319 | reads and executes commands from the file \fI~/.bash_logout\fP, if it | |
320 | exists. | |
321 | .PP | |
322 | When an interactive shell that is not a login shell is started, | |
323 | .B bash | |
324 | reads and executes commands from \fI~/.bashrc\fP, if that file exists. | |
325 | This may be inhibited by using the | |
326 | .B \-\-norc | |
327 | option. | |
328 | The \fB\-\-rcfile\fP \fIfile\fP option will force | |
329 | .B bash | |
330 | to read and execute commands from \fIfile\fP instead of \fI~/.bashrc\fP. | |
331 | .PP | |
332 | When | |
333 | .B bash | |
334 | is started non-interactively, to run a shell script, for example, it | |
335 | looks for the variable | |
336 | .SM | |
337 | .B BASH_ENV | |
338 | in the environment, expands its value if it appears there, and uses the | |
339 | expanded value as the name of a file to read and execute. | |
340 | .B Bash | |
341 | behaves as if the following command were executed: | |
342 | .sp .5 | |
343 | .RS | |
28ef6c31 JA |
344 | .if t \f(CWif [ \-n "$BASH_ENV" ]; then . "$BASH_ENV"; fi\fP |
345 | .if n if [ \-n "$BASH_ENV" ]; then . "$BASH_ENV"; fi | |
ccc6cda3 JA |
346 | .RE |
347 | .sp .5 | |
348 | but the value of the | |
349 | .SM | |
350 | .B PATH | |
b28ff8c9 | 351 | variable is not used to search for the filename. |
ccc6cda3 JA |
352 | .PP |
353 | If | |
354 | .B bash | |
355 | is invoked with the name | |
356 | .BR sh , | |
357 | it tries to mimic the startup behavior of historical versions of | |
358 | .B sh | |
359 | as closely as possible, | |
360 | while conforming to the POSIX standard as well. | |
b72432fd JA |
361 | When invoked as an interactive login shell, or a non-interactive |
362 | shell with the \fB\-\-login\fP option, it first attempts to | |
cce855bc | 363 | read and execute commands from |
ccc6cda3 JA |
364 | .I /etc/profile |
365 | and | |
366 | .IR ~/.profile , | |
367 | in that order. | |
368 | The | |
369 | .B \-\-noprofile | |
370 | option may be used to inhibit this behavior. | |
371 | When invoked as an interactive shell with the name | |
372 | .BR sh , | |
373 | .B bash | |
374 | looks for the variable | |
375 | .SM | |
376 | .BR ENV , | |
377 | expands its value if it is defined, and uses the | |
378 | expanded value as the name of a file to read and execute. | |
379 | Since a shell invoked as | |
380 | .B sh | |
381 | does not attempt to read and execute commands from any other startup | |
382 | files, the | |
383 | .B \-\-rcfile | |
384 | option has no effect. | |
385 | A non-interactive shell invoked with the name | |
386 | .B sh | |
b72432fd | 387 | does not attempt to read any other startup files. |
ccc6cda3 JA |
388 | When invoked as |
389 | .BR sh , | |
390 | .B bash | |
391 | enters | |
392 | .I posix | |
393 | mode after the startup files are read. | |
394 | .PP | |
395 | When | |
396 | .B bash | |
397 | is started in | |
398 | .I posix | |
399 | mode, as with the | |
400 | .B \-\-posix | |
401 | command line option, it follows the POSIX standard for startup files. | |
cce855bc | 402 | In this mode, interactive shells expand the |
ccc6cda3 JA |
403 | .SM |
404 | .B ENV | |
cce855bc | 405 | variable and commands are read and executed from the file |
ccc6cda3 JA |
406 | whose name is the expanded value. |
407 | No other startup files are read. | |
ccc6cda3 JA |
408 | .PP |
409 | .B Bash | |
866961ad | 410 | attempts to determine when it is being run with its standard input |
dc60d4e0 | 411 | connected to a network connection, as when executed by the remote shell |
866961ad | 412 | daemon, usually \fIrshd\fP, or the secure shell daemon \fIsshd\fP. |
ccc6cda3 JA |
413 | If |
414 | .B bash | |
866961ad | 415 | determines it is being run in this fashion, it reads and executes |
ccc6cda3 JA |
416 | commands from \fI~/.bashrc\fP, if that file exists and is readable. |
417 | It will not do this if invoked as \fBsh\fP. | |
418 | The | |
419 | .B \-\-norc | |
420 | option may be used to inhibit this behavior, and the | |
421 | .B \-\-rcfile | |
422 | option may be used to force another file to be read, but | |
423 | \fIrshd\fP does not generally invoke the shell with those options | |
424 | or allow them to be specified. | |
b72432fd JA |
425 | .PP |
426 | If the shell is started with the effective user (group) id not equal to the | |
427 | real user (group) id, and the \fB\-p\fP option is not supplied, no startup | |
f73dda09 JA |
428 | files are read, shell functions are not inherited from the environment, the |
429 | .SM | |
691aebcb | 430 | .BR SHELLOPTS , |
984a1947 | 431 | .SM |
691aebcb | 432 | .BR BASHOPTS , |
984a1947 | 433 | .SM |
691aebcb CR |
434 | .BR CDPATH , |
435 | and | |
984a1947 | 436 | .SM |
691aebcb CR |
437 | .B GLOBIGNORE |
438 | variables, if they appear in the environment, are ignored, | |
b72432fd JA |
439 | and the effective user id is set to the real user id. |
440 | If the \fB\-p\fP option is supplied at invocation, the startup behavior is | |
441 | the same, but the effective user id is not reset. | |
726f6388 | 442 | .SH DEFINITIONS |
ccc6cda3 JA |
443 | .PP |
444 | The following definitions are used throughout the rest of this | |
445 | document. | |
726f6388 JA |
446 | .PD 0 |
447 | .TP | |
448 | .B blank | |
449 | A space or tab. | |
450 | .TP | |
451 | .B word | |
452 | A sequence of characters considered as a single unit by the shell. | |
453 | Also known as a | |
454 | .BR token . | |
455 | .TP | |
456 | .B name | |
457 | A | |
458 | .I word | |
459 | consisting only of alphanumeric characters and underscores, and | |
460 | beginning with an alphabetic character or an underscore. Also | |
461 | referred to as an | |
462 | .BR identifier . | |
463 | .TP | |
464 | .B metacharacter | |
465 | A character that, when unquoted, separates words. One of the following: | |
466 | .br | |
467 | .RS | |
468 | .PP | |
469 | .if t \fB| & ; ( ) < > space tab\fP | |
470 | .if n \fB| & ; ( ) < > space tab\fP | |
471 | .RE | |
472 | .PP | |
473 | .TP | |
474 | .B control operator | |
475 | A \fItoken\fP that performs a control function. It is one of the following | |
476 | symbols: | |
477 | .RS | |
478 | .PP | |
adc6cff5 | 479 | .if t \fB|| & && ; ;; ( ) | |& <newline>\fP |
8943768b | 480 | .if n \fB|| & && ; ;; ( ) | |& <newline>\fP |
726f6388 JA |
481 | .RE |
482 | .PD | |
483 | .SH "RESERVED WORDS" | |
484 | \fIReserved words\fP are words that have a special meaning to the shell. | |
485 | The following words are recognized as reserved when unquoted and either | |
486 | the first word of a simple command (see | |
487 | .SM | |
488 | .B SHELL GRAMMAR | |
489 | below) or the third word of a | |
490 | .B case | |
491 | or | |
492 | .B for | |
493 | command: | |
494 | .if t .RS | |
495 | .PP | |
496 | .B | |
cce855bc JA |
497 | .if n ! case do done elif else esac fi for function if in select then until while { } time [[ ]] |
498 | .if t ! case do done elif else esac fi for function if in select then until while { } time [[ ]] | |
726f6388 | 499 | .if t .RE |
726f6388 JA |
500 | .SH "SHELL GRAMMAR" |
501 | .SS Simple Commands | |
502 | .PP | |
503 | A \fIsimple command\fP is a sequence of optional variable assignments | |
ccc6cda3 | 504 | followed by \fBblank\fP-separated words and redirections, and |
726f6388 | 505 | terminated by a \fIcontrol operator\fP. The first word |
f73dda09 JA |
506 | specifies the command to be executed, and is passed as argument zero. |
507 | The remaining words are passed as arguments to the invoked command. | |
726f6388 JA |
508 | .PP |
509 | The return value of a \fIsimple command\fP is its exit status, or | |
510 | 128+\fIn\^\fP if the command is terminated by signal | |
511 | .IR n . | |
512 | .SS Pipelines | |
513 | .PP | |
514 | A \fIpipeline\fP is a sequence of one or more commands separated by | |
8943768b CR |
515 | one of the control operators |
516 | .B | | |
517 | or \fB|&\fP. | |
726f6388 JA |
518 | The format for a pipeline is: |
519 | .RS | |
520 | .PP | |
8943768b | 521 | [\fBtime\fP [\fB\-p\fP]] [ ! ] \fIcommand\fP [ [\fB|\fP\(bv\fB|&\fP] \fIcommand2\fP ... ] |
726f6388 JA |
522 | .RE |
523 | .PP | |
524 | The standard output of | |
525 | .I command | |
f73dda09 | 526 | is connected via a pipe to the standard input of |
726f6388 JA |
527 | .IR command2 . |
528 | This connection is performed before any redirections specified by the | |
529 | command (see | |
530 | .SM | |
531 | .B REDIRECTION | |
532 | below). | |
c920c360 CR |
533 | If \fB|&\fP is used, \fIcommand\fP's standard output and standard error |
534 | are connected to | |
535 | \fIcommand2\fP's standard input through the pipe; | |
536 | it is shorthand for \fB2>&1 |\fP. | |
537 | This implicit redirection of the standard error is | |
538 | performed after any redirections specified by the command. | |
726f6388 | 539 | .PP |
d3a24ed2 CR |
540 | The return status of a pipeline is the exit status of the last |
541 | command, unless the \fBpipefail\fP option is enabled. | |
542 | If \fBpipefail\fP is enabled, the pipeline's return status is the | |
543 | value of the last (rightmost) command to exit with a non-zero status, | |
544 | or zero if all commands exit successfully. | |
726f6388 JA |
545 | If the reserved word |
546 | .B ! | |
d3a24ed2 CR |
547 | precedes a pipeline, the exit status of that pipeline is the logical |
548 | negation of the exit status as described above. | |
ccc6cda3 | 549 | The shell waits for all commands in the pipeline to |
726f6388 JA |
550 | terminate before returning a value. |
551 | .PP | |
ccc6cda3 JA |
552 | If the |
553 | .B time | |
554 | reserved word precedes a pipeline, the elapsed as well as user and | |
555 | system time consumed by its execution are reported when the pipeline | |
556 | terminates. | |
557 | The \fB\-p\fP option changes the output format to that specified by POSIX. | |
7d92f73f CR |
558 | When the shell is in \fIposix mode\fP, it does not recognize |
559 | \fBtime\fP as a reserved word if the next token begins with a `-'. | |
ccc6cda3 JA |
560 | The |
561 | .SM | |
562 | .B TIMEFORMAT | |
563 | variable may be set to a format string that specifies how the timing | |
564 | information should be displayed; see the description of | |
565 | .SM | |
566 | .B TIMEFORMAT | |
567 | under | |
568 | .B "Shell Variables" | |
569 | below. | |
570 | .PP | |
6faad625 CR |
571 | When the shell is in \fIposix mode\fP, \fBtime\fP |
572 | may be followed by a newline. In this case, the shell displays the | |
573 | total user and system time consumed by the shell and its children. | |
574 | The | |
575 | .SM | |
576 | .B TIMEFORMAT | |
577 | variable may be used to specify the format of | |
578 | the time information. | |
579 | .PP | |
726f6388 JA |
580 | Each command in a pipeline is executed as a separate process (i.e., in a |
581 | subshell). | |
582 | .SS Lists | |
583 | .PP | |
584 | A \fIlist\fP is a sequence of one or more pipelines separated by one | |
585 | of the operators | |
586 | .BR ; , | |
587 | .BR & , | |
588 | .BR && , | |
589 | or | |
adc6cff5 | 590 | .BR || , |
ccc6cda3 | 591 | and optionally terminated by one of |
726f6388 JA |
592 | .BR ; , |
593 | .BR & , | |
594 | or | |
595 | .BR <newline> . | |
596 | .PP | |
597 | Of these list operators, | |
598 | .B && | |
599 | and | |
adc6cff5 | 600 | .B || |
726f6388 JA |
601 | have equal precedence, followed by |
602 | .B ; | |
603 | and | |
b1a26c01 | 604 | .BR & , |
726f6388 JA |
605 | which have equal precedence. |
606 | .PP | |
7117c2d2 JA |
607 | A sequence of one or more newlines may appear in a \fIlist\fP instead |
608 | of a semicolon to delimit commands. | |
609 | .PP | |
726f6388 JA |
610 | If a command is terminated by the control operator |
611 | .BR & , | |
612 | the shell executes the command in the \fIbackground\fP | |
613 | in a subshell. The shell does not wait for the command to | |
614 | finish, and the return status is 0. Commands separated by a | |
615 | .B ; | |
616 | are executed sequentially; the shell waits for each | |
617 | command to terminate in turn. The return status is the | |
618 | exit status of the last command executed. | |
619 | .PP | |
6fbe7620 | 620 | AND and OR lists are sequences of one of more pipelines separated by the |
adc6cff5 | 621 | \fB&&\fP and \fB||\fP control operators, respectively. |
6fbe7620 | 622 | AND and OR lists are executed with left associativity. |
726f6388 JA |
623 | An AND list has the form |
624 | .RS | |
625 | .PP | |
bb70624e | 626 | \fIcommand1\fP \fB&&\fP \fIcommand2\fP |
726f6388 JA |
627 | .RE |
628 | .PP | |
629 | .I command2 | |
630 | is executed if, and only if, | |
bb70624e | 631 | .I command1 |
726f6388 JA |
632 | returns an exit status of zero. |
633 | .PP | |
634 | An OR list has the form | |
635 | .RS | |
636 | .PP | |
adc6cff5 | 637 | \fIcommand1\fP \fB||\fP \fIcommand2\fP |
726f6388 JA |
638 | .PP |
639 | .RE | |
640 | .PP | |
641 | .I command2 | |
642 | is executed if and only if | |
bb70624e | 643 | .I command1 |
6fbe7620 CR |
644 | returns a non-zero exit status. |
645 | The return status of | |
726f6388 JA |
646 | AND and OR lists is the exit status of the last command |
647 | executed in the list. | |
648 | .SS Compound Commands | |
649 | .PP | |
f4f5e1c2 CR |
650 | A \fIcompound command\fP is one of the following. |
651 | In most cases a \fIlist\fP in a command's description may be separated from | |
652 | the rest of the command by one or more newlines, and may be followed by a | |
653 | newline in place of a semicolon. | |
726f6388 JA |
654 | .TP |
655 | (\fIlist\fP) | |
d3a24ed2 CR |
656 | \fIlist\fP is executed in a subshell environment (see |
657 | .SM | |
658 | \fBCOMMAND EXECUTION ENVIRONMENT\fP | |
659 | below). | |
660 | Variable assignments and builtin | |
726f6388 JA |
661 | commands that affect the shell's environment do not remain in effect |
662 | after the command completes. The return status is the exit status of | |
663 | \fIlist\fP. | |
664 | .TP | |
665 | { \fIlist\fP; } | |
ccc6cda3 JA |
666 | \fIlist\fP is simply executed in the current shell environment. |
667 | \fIlist\fP must be terminated with a newline or semicolon. | |
668 | This is known as a \fIgroup command\fP. | |
669 | The return status is the exit status of | |
726f6388 | 670 | \fIlist\fP. |
d3a24ed2 | 671 | Note that unlike the metacharacters \fB(\fP and \fB)\fP, \fB{\fP and |
f73dda09 JA |
672 | \fB}\fP are \fIreserved words\fP and must occur where a reserved |
673 | word is permitted to be recognized. Since they do not cause a word | |
641d8f00 CR |
674 | break, they must be separated from \fIlist\fP by whitespace or another |
675 | shell metacharacter. | |
726f6388 | 676 | .TP |
ccc6cda3 JA |
677 | ((\fIexpression\fP)) |
678 | The \fIexpression\fP is evaluated according to the rules described | |
679 | below under | |
680 | .SM | |
681 | .BR "ARITHMETIC EVALUATION" . | |
682 | If the value of the expression is non-zero, the return status is 0; | |
683 | otherwise the return status is 1. This is exactly equivalent to | |
684 | \fBlet "\fIexpression\fP"\fR. | |
685 | .TP | |
cce855bc JA |
686 | \fB[[\fP \fIexpression\fP \fB]]\fP |
687 | Return a status of 0 or 1 depending on the evaluation of | |
688 | the conditional expression \fIexpression\fP. | |
689 | Expressions are composed of the primaries described below under | |
690 | .SM | |
691 | .BR "CONDITIONAL EXPRESSIONS" . | |
692 | Word splitting and pathname expansion are not performed on the words | |
15825757 CR |
693 | between the \fB[[\fP and \fB]]\fP; tilde expansion, |
694 | parameter and variable expansion, | |
695 | arithmetic expansion, command substitution, process | |
cce855bc | 696 | substitution, and quote removal are performed. |
d3a24ed2 CR |
697 | Conditional operators such as \fB\-f\fP must be unquoted to be recognized |
698 | as primaries. | |
cce855bc JA |
699 | .if t .sp 0.5 |
700 | .if n .sp 1 | |
54a1fa7c | 701 | When used with \fB[[\fP, the \fB<\fP and \fB>\fP operators sort |
a8fd3f3e CR |
702 | lexicographically using the current locale. |
703 | .if t .sp 0.5 | |
704 | .if n .sp 1 | |
cce855bc JA |
705 | When the \fB==\fP and \fB!=\fP operators are used, the string to the |
706 | right of the operator is considered a pattern and matched according | |
707 | to the rules described below under \fBPattern Matching\fP. | |
2206f89a CR |
708 | If the shell option |
709 | .B nocasematch | |
710 | is enabled, the match is performed without regard to the case | |
711 | of alphabetic characters. | |
dc8fbaf9 CR |
712 | The return value is 0 if the string matches (\fB==\fP) or does not match |
713 | (\fB!=\fP) the pattern, and 1 otherwise. | |
e192f341 CR |
714 | Any part of the pattern may be quoted to force the quoted portion |
715 | to be matched as a string. | |
cce855bc JA |
716 | .if t .sp 0.5 |
717 | .if n .sp 1 | |
d3a24ed2 CR |
718 | An additional binary operator, \fB=~\fP, is available, with the same |
719 | precedence as \fB==\fP and \fB!=\fP. | |
720 | When it is used, the string to the right of the operator is considered | |
721 | an extended regular expression and matched accordingly (as in \fIregex\fP(3)). | |
d7f49990 CR |
722 | The return value is 0 if the string matches |
723 | the pattern, and 1 otherwise. | |
d3a24ed2 CR |
724 | If the regular expression is syntactically incorrect, the conditional |
725 | expression's return value is 2. | |
726 | If the shell option | |
2206f89a | 727 | .B nocasematch |
d3a24ed2 CR |
728 | is enabled, the match is performed without regard to the case |
729 | of alphabetic characters. | |
e192f341 CR |
730 | Any part of the pattern may be quoted to force the quoted portion |
731 | to be matched as a string. | |
084c952b CR |
732 | Bracket expressions in regular expressions must be treated carefully, |
733 | since normal quoting characters lose their meanings between brackets. | |
734 | If the pattern is stored in a shell variable, quoting the variable | |
735 | expansion forces the entire pattern to be matched as a string. | |
d3a24ed2 | 736 | Substrings matched by parenthesized subexpressions within the regular |
984a1947 CR |
737 | expression are saved in the array variable |
738 | .SM | |
739 | .BR BASH_REMATCH . | |
740 | The element of | |
741 | .SM | |
742 | .B BASH_REMATCH | |
743 | with index 0 is the portion of the string | |
d3a24ed2 | 744 | matching the entire regular expression. |
984a1947 CR |
745 | The element of |
746 | .SM | |
747 | .B BASH_REMATCH | |
748 | with index \fIn\fP is the portion of the | |
d3a24ed2 CR |
749 | string matching the \fIn\fPth parenthesized subexpression. |
750 | .if t .sp 0.5 | |
751 | .if n .sp 1 | |
cce855bc JA |
752 | Expressions may be combined using the following operators, listed |
753 | in decreasing order of precedence: | |
754 | .if t .sp 0.5 | |
755 | .if n .sp 1 | |
756 | .RS | |
757 | .PD 0 | |
758 | .TP | |
759 | .B ( \fIexpression\fP ) | |
760 | Returns the value of \fIexpression\fP. | |
761 | This may be used to override the normal precedence of operators. | |
762 | .TP | |
763 | .B ! \fIexpression\fP | |
764 | True if | |
765 | .I expression | |
766 | is false. | |
767 | .TP | |
768 | \fIexpression1\fP \fB&&\fP \fIexpression2\fP | |
769 | True if both | |
770 | .I expression1 | |
771 | and | |
772 | .I expression2 | |
773 | are true. | |
774 | .TP | |
adc6cff5 | 775 | \fIexpression1\fP \fB||\fP \fIexpression2\fP |
cce855bc JA |
776 | True if either |
777 | .I expression1 | |
778 | or | |
779 | .I expression2 | |
780 | is true. | |
781 | .PD | |
cce855bc | 782 | .LP |
adc6cff5 | 783 | The \fB&&\fP and \fB||\fP |
7117c2d2 | 784 | operators do not evaluate \fIexpression2\fP if the value of |
cce855bc JA |
785 | \fIexpression1\fP is sufficient to determine the return value of |
786 | the entire conditional expression. | |
f73dda09 | 787 | .RE |
cce855bc | 788 | .TP |
0d8616ff | 789 | \fBfor\fP \fIname\fP [ [ \fBin\fP [ \fIword ...\fP ] ] ; ] \fBdo\fP \fIlist\fP ; \fBdone\fP |
726f6388 | 790 | The list of words following \fBin\fP is expanded, generating a list |
bb70624e JA |
791 | of items. |
792 | The variable \fIname\fP is set to each element of this list | |
793 | in turn, and \fIlist\fP is executed each time. | |
794 | If the \fBin\fP \fIword\fP is omitted, the \fBfor\fP command executes | |
795 | \fIlist\fP once for each positional parameter that is set (see | |
726f6388 JA |
796 | .SM |
797 | .B PARAMETERS | |
798 | below). | |
cce855bc JA |
799 | The return status is the exit status of the last command that executes. |
800 | If the expansion of the items following \fBin\fP results in an empty | |
801 | list, no commands are executed, and the return status is 0. | |
726f6388 | 802 | .TP |
bb70624e JA |
803 | \fBfor\fP (( \fIexpr1\fP ; \fIexpr2\fP ; \fIexpr3\fP )) ; \fBdo\fP \fIlist\fP ; \fBdone\fP |
804 | First, the arithmetic expression \fIexpr1\fP is evaluated according | |
805 | to the rules described below under | |
806 | .SM | |
807 | .BR "ARITHMETIC EVALUATION" . | |
808 | The arithmetic expression \fIexpr2\fP is then evaluated repeatedly | |
809 | until it evaluates to zero. | |
810 | Each time \fIexpr2\fP evaluates to a non-zero value, \fIlist\fP is | |
811 | executed and the arithmetic expression \fIexpr3\fP is evaluated. | |
812 | If any expression is omitted, it behaves as if it evaluates to 1. | |
813 | The return value is the exit status of the last command in \fIlist\fP | |
814 | that is executed, or false if any of the expressions is invalid. | |
815 | .TP | |
b72432fd | 816 | \fBselect\fP \fIname\fP [ \fBin\fP \fIword\fP ] ; \fBdo\fP \fIlist\fP ; \fBdone\fP |
726f6388 JA |
817 | The list of words following \fBin\fP is expanded, generating a list |
818 | of items. The set of expanded words is printed on the standard | |
819 | error, each preceded by a number. If the \fBin\fP | |
820 | \fIword\fP is omitted, the positional parameters are printed (see | |
821 | .SM | |
822 | .B PARAMETERS | |
823 | below). The | |
984a1947 | 824 | .SM |
726f6388 JA |
825 | .B PS3 |
826 | prompt is then displayed and a line read from the standard input. | |
ccc6cda3 | 827 | If the line consists of a number corresponding to one of |
726f6388 JA |
828 | the displayed words, then the value of |
829 | .I name | |
830 | is set to that word. If the line is empty, the words and prompt | |
831 | are displayed again. If EOF is read, the command completes. Any | |
832 | other value read causes | |
833 | .I name | |
834 | to be set to null. The line read is saved in the variable | |
984a1947 | 835 | .SM |
726f6388 JA |
836 | .BR REPLY . |
837 | The | |
838 | .I list | |
839 | is executed after each selection until a | |
840 | .B break | |
726f6388 JA |
841 | command is executed. |
842 | The exit status of | |
843 | .B select | |
844 | is the exit status of the last command executed in | |
845 | .IR list , | |
846 | or zero if no commands were executed. | |
847 | .TP | |
bb70624e | 848 | \fBcase\fP \fIword\fP \fBin\fP [ [(] \fIpattern\fP [ \fB|\fP \fIpattern\fP ] \ |
726f6388 JA |
849 | ... ) \fIlist\fP ;; ] ... \fBesac\fP |
850 | A \fBcase\fP command first expands \fIword\fP, and tries to match | |
851 | it against each \fIpattern\fP in turn, using the same matching rules | |
852 | as for pathname expansion (see | |
853 | .B Pathname Expansion | |
2206f89a | 854 | below). |
dc8fbaf9 | 855 | The \fIword\fP is expanded using tilde |
d3ad40de | 856 | expansion, parameter and variable expansion, arithmetic substitution, |
dc8fbaf9 CR |
857 | command substitution, process substitution and quote removal. |
858 | Each \fIpattern\fP examined is expanded using tilde | |
d3ad40de | 859 | expansion, parameter and variable expansion, arithmetic substitution, |
dc8fbaf9 | 860 | command substitution, and process substitution. |
2206f89a CR |
861 | If the shell option |
862 | .B nocasematch | |
863 | is enabled, the match is performed without regard to the case | |
864 | of alphabetic characters. | |
8943768b CR |
865 | When a match is found, the corresponding \fIlist\fP is executed. |
866 | If the \fB;;\fP operator is used, no subsequent matches are attempted after | |
867 | the first pattern match. | |
868 | Using \fB;&\fP in place of \fB;;\fP causes execution to continue with | |
869 | the \fIlist\fP associated with the next set of patterns. | |
870 | Using \fB;;&\fP in place of \fB;;\fP causes the shell to test the next | |
871 | pattern list in the statement, if any, and execute any associated \fIlist\fP | |
872 | on a successful match. | |
873 | The exit status is zero if no | |
ccc6cda3 | 874 | pattern matches. Otherwise, it is the exit status of the |
726f6388 JA |
875 | last command executed in \fIlist\fP. |
876 | .TP | |
ccc6cda3 JA |
877 | \fBif\fP \fIlist\fP; \fBthen\fP \fIlist;\fP \ |
878 | [ \fBelif\fP \fIlist\fP; \fBthen\fP \fIlist\fP; ] ... \ | |
879 | [ \fBelse\fP \fIlist\fP; ] \fBfi\fP | |
726f6388 JA |
880 | The |
881 | .B if | |
882 | .I list | |
883 | is executed. If its exit status is zero, the | |
884 | \fBthen\fP \fIlist\fP is executed. Otherwise, each \fBelif\fP | |
885 | \fIlist\fP is executed in turn, and if its exit status is zero, | |
886 | the corresponding \fBthen\fP \fIlist\fP is executed and the | |
887 | command completes. Otherwise, the \fBelse\fP \fIlist\fP is | |
888 | executed, if present. The exit status is the exit status of the | |
889 | last command executed, or zero if no condition tested true. | |
890 | .TP | |
89c77bc7 | 891 | \fBwhile\fP \fIlist-1\fP; \fBdo\fP \fIlist-2\fP; \fBdone\fP |
7117c2d2 | 892 | .PD 0 |
726f6388 | 893 | .TP |
89c77bc7 | 894 | \fBuntil\fP \fIlist-1\fP; \fBdo\fP \fIlist-2\fP; \fBdone\fP |
726f6388 | 895 | .PD |
89c77bc7 CR |
896 | The \fBwhile\fP command continuously executes the list |
897 | \fIlist-2\fP as long as the last command in the list \fIlist-1\fP returns | |
726f6388 JA |
898 | an exit status of zero. The \fBuntil\fP command is identical |
899 | to the \fBwhile\fP command, except that the test is negated; | |
89c77bc7 | 900 | .I list-2 |
726f6388 | 901 | is executed as long as the last command in |
89c77bc7 | 902 | .I list-1 |
ccc6cda3 | 903 | returns a non-zero exit status. |
726f6388 JA |
904 | The exit status of the \fBwhile\fP and \fBuntil\fP commands |
905 | is the exit status | |
89c77bc7 | 906 | of the last command executed in \fIlist-2\fP, or zero if |
726f6388 | 907 | none was executed. |
09767ff0 CR |
908 | .SS Coprocesses |
909 | .PP | |
910 | A \fIcoprocess\fP is a shell command preceded by the \fBcoproc\fP reserved | |
911 | word. | |
912 | A coprocess is executed asynchronously in a subshell, as if the command | |
913 | had been terminated with the \fB&\fP control operator, with a two-way pipe | |
914 | established between the executing shell and the coprocess. | |
915 | .PP | |
916 | The format for a coprocess is: | |
917 | .RS | |
918 | .PP | |
919 | \fBcoproc\fP [\fINAME\fP] \fIcommand\fP [\fIredirections\fP] | |
920 | .RE | |
921 | .PP | |
922 | This creates a coprocess named \fINAME\fP. | |
f6da9f85 | 923 | If \fINAME\fP is not supplied, the default name is \fBCOPROC\fP. |
e141c35a CR |
924 | \fINAME\fP must not be supplied if \fIcommand\fP is a \fIsimple |
925 | command\fP (see above); otherwise, it is interpreted as the first word | |
926 | of the simple command. | |
b28ff8c9 | 927 | When the coprocess is executed, the shell creates an array variable (see |
09767ff0 CR |
928 | .B Arrays |
929 | below) named \fINAME\fP in the context of the executing shell. | |
930 | The standard output of | |
931 | .I command | |
932 | is connected via a pipe to a file descriptor in the executing shell, | |
933 | and that file descriptor is assigned to \fINAME\fP[0]. | |
934 | The standard input of | |
935 | .I command | |
936 | is connected via a pipe to a file descriptor in the executing shell, | |
937 | and that file descriptor is assigned to \fINAME\fP[1]. | |
938 | This pipe is established before any redirections specified by the | |
939 | command (see | |
940 | .SM | |
941 | .B REDIRECTION | |
942 | below). | |
943 | The file descriptors can be utilized as arguments to shell commands | |
944 | and redirections using standard word expansions. | |
dc60d4e0 | 945 | The process ID of the shell spawned to execute the coprocess is |
30915f17 CR |
946 | available as the value of the variable \fINAME\fP_PID. |
947 | The \fBwait\fP | |
948 | builtin command may be used to wait for the coprocess to terminate. | |
09767ff0 CR |
949 | .PP |
950 | The return status of a coprocess is the exit status of \fIcommand\fP. | |
d3a24ed2 CR |
951 | .SS Shell Function Definitions |
952 | .PP | |
953 | A shell function is an object that is called like a simple command and | |
954 | executes a compound command with a new set of positional parameters. | |
955 | Shell functions are declared as follows: | |
956 | .TP | |
9ec5ed66 CR |
957 | \fIname\fP () \fIcompound\-command\fP [\fIredirection\fP] |
958 | .PD 0 | |
959 | .TP | |
960 | \fBfunction\fP \fIname\fP [()] \fIcompound\-command\fP [\fIredirection\fP] | |
961 | .PD | |
d3a24ed2 CR |
962 | This defines a function named \fIname\fP. |
963 | The reserved word \fBfunction\fP is optional. | |
964 | If the \fBfunction\fP reserved word is supplied, the parentheses are optional. | |
965 | The \fIbody\fP of the function is the compound command | |
966 | .I compound\-command | |
967 | (see \fBCompound Commands\fP above). | |
968 | That command is usually a \fIlist\fP of commands between { and }, but | |
969 | may be any command listed under \fBCompound Commands\fP above. | |
970 | \fIcompound\-command\fP is executed whenever \fIname\fP is specified as the | |
971 | name of a simple command. | |
b28ff8c9 CR |
972 | When in \fIposix mode\fP, \fIname\fP may not be the name of one of the |
973 | POSIX \fIspecial builtins\fP. | |
d3a24ed2 CR |
974 | Any redirections (see |
975 | .SM | |
976 | .B REDIRECTION | |
977 | below) specified when a function is defined are performed | |
978 | when the function is executed. | |
979 | The exit status of a function definition is zero unless a syntax error | |
980 | occurs or a readonly function with the same name already exists. | |
981 | When executed, the exit status of a function is the exit status of the | |
982 | last command executed in the body. (See | |
726f6388 JA |
983 | .SM |
984 | .B FUNCTIONS | |
985 | below.) | |
986 | .SH COMMENTS | |
ccc6cda3 JA |
987 | In a non-interactive shell, or an interactive shell in which the |
988 | .B interactive_comments | |
989 | option to the | |
990 | .B shopt | |
991 | builtin is enabled (see | |
992 | .SM | |
993 | .B "SHELL BUILTIN COMMANDS" | |
994 | below), a word beginning with | |
726f6388 JA |
995 | .B # |
996 | causes that word and all remaining characters on that line to | |
997 | be ignored. An interactive shell without the | |
ccc6cda3 | 998 | .B interactive_comments |
ccc6cda3 JA |
999 | option enabled does not allow comments. The |
1000 | .B interactive_comments | |
1001 | option is on by default in interactive shells. | |
726f6388 JA |
1002 | .SH QUOTING |
1003 | \fIQuoting\fP is used to remove the special meaning of certain | |
1004 | characters or words to the shell. Quoting can be used to | |
1005 | disable special treatment for special characters, to prevent | |
1006 | reserved words from being recognized as such, and to prevent | |
1007 | parameter expansion. | |
1008 | .PP | |
1009 | Each of the \fImetacharacters\fP listed above under | |
1010 | .SM | |
1011 | .B DEFINITIONS | |
bb70624e JA |
1012 | has special meaning to the shell and must be quoted if it is to |
1013 | represent itself. | |
1014 | .PP | |
5c96a638 CR |
1015 | When the command history expansion facilities are being used |
1016 | (see | |
1017 | .SM | |
1018 | .B HISTORY EXPANSION | |
1019 | below), the | |
bb70624e JA |
1020 | \fIhistory expansion\fP character, usually \fB!\fP, must be quoted |
1021 | to prevent history expansion. | |
1022 | .PP | |
1023 | There are three quoting mechanisms: the | |
726f6388 JA |
1024 | .IR "escape character" , |
1025 | single quotes, and double quotes. | |
1026 | .PP | |
1027 | A non-quoted backslash (\fB\e\fP) is the | |
1028 | .IR "escape character" . | |
1029 | It preserves the literal value of the next character that follows, | |
1030 | with the exception of <newline>. If a \fB\e\fP<newline> pair | |
cce855bc JA |
1031 | appears, and the backslash is not itself quoted, the \fB\e\fP<newline> |
1032 | is treated as a line continuation (that is, it is removed from the | |
1033 | input stream and effectively ignored). | |
726f6388 JA |
1034 | .PP |
1035 | Enclosing characters in single quotes preserves the literal value | |
1036 | of each character within the quotes. A single quote may not occur | |
1037 | between single quotes, even when preceded by a backslash. | |
1038 | .PP | |
1039 | Enclosing characters in double quotes preserves the literal value | |
1040 | of all characters within the quotes, with the exception of | |
1041 | .BR $ , | |
3d4e09aa | 1042 | .BR \` , |
5c96a638 CR |
1043 | .BR \e , |
1044 | and, when history expansion is enabled, | |
1045 | .BR ! . | |
726f6388 JA |
1046 | The characters |
1047 | .B $ | |
1048 | and | |
3d4e09aa | 1049 | .B \` |
726f6388 JA |
1050 | retain their special meaning within double quotes. The backslash |
1051 | retains its special meaning only when followed by one of the following | |
1052 | characters: | |
1053 | .BR $ , | |
3d4e09aa | 1054 | .BR \` , |
726f6388 JA |
1055 | \^\fB"\fP\^, |
1056 | .BR \e , | |
1057 | or | |
1058 | .BR <newline> . | |
1059 | A double quote may be quoted within double quotes by preceding it with | |
1060 | a backslash. | |
5c96a638 CR |
1061 | If enabled, history expansion will be performed unless an |
1062 | .B ! | |
1063 | appearing in double quotes is escaped using a backslash. | |
1064 | The backslash preceding the | |
1065 | .B ! | |
1066 | is not removed. | |
726f6388 JA |
1067 | .PP |
1068 | The special parameters | |
1069 | .B * | |
1070 | and | |
1071 | .B @ | |
1072 | have special meaning when in double | |
1073 | quotes (see | |
1074 | .SM | |
1075 | .B PARAMETERS | |
1076 | below). | |
ccc6cda3 | 1077 | .PP |
20587658 | 1078 | Words of the form \fB$\fP\(aq\fIstring\fP\(aq are treated specially. The |
ccc6cda3 | 1079 | word expands to \fIstring\fP, with backslash-escaped characters replaced |
f75912ae | 1080 | as specified by the ANSI C standard. Backslash escape sequences, if |
ccc6cda3 JA |
1081 | present, are decoded as follows: |
1082 | .RS | |
1083 | .PD 0 | |
1084 | .TP | |
1085 | .B \ea | |
1086 | alert (bell) | |
1087 | .TP | |
1088 | .B \eb | |
1089 | backspace | |
1090 | .TP | |
1091 | .B \ee | |
a3143574 CR |
1092 | .TP |
1093 | .B \eE | |
ccc6cda3 JA |
1094 | an escape character |
1095 | .TP | |
1096 | .B \ef | |
1097 | form feed | |
1098 | .TP | |
1099 | .B \en | |
1100 | new line | |
1101 | .TP | |
1102 | .B \er | |
1103 | carriage return | |
1104 | .TP | |
1105 | .B \et | |
1106 | horizontal tab | |
1107 | .TP | |
1108 | .B \ev | |
1109 | vertical tab | |
1110 | .TP | |
1111 | .B \e\e | |
1112 | backslash | |
bb70624e | 1113 | .TP |
20587658 | 1114 | .B \e\(aq |
bb70624e | 1115 | single quote |
a3143574 CR |
1116 | .TP |
1117 | .B \e\(dq | |
1118 | double quote | |
ccc6cda3 JA |
1119 | .TP |
1120 | .B \e\fInnn\fP | |
f73dda09 | 1121 | the eight-bit character whose value is the octal value \fInnn\fP |
cce855bc JA |
1122 | (one to three digits) |
1123 | .TP | |
f73dda09 JA |
1124 | .B \ex\fIHH\fP |
1125 | the eight-bit character whose value is the hexadecimal value \fIHH\fP | |
1126 | (one or two hex digits) | |
7117c2d2 | 1127 | .TP |
eb0b2ad8 CR |
1128 | .B \eu\fIHHHH\fP |
1129 | the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value | |
1130 | \fIHHHH\fP (one to four hex digits) | |
1131 | .TP | |
1132 | .B \eU\fIHHHHHHHH\fP | |
1133 | the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value | |
1134 | \fIHHHHHHHH\fP (one to eight hex digits) | |
1135 | .TP | |
7117c2d2 JA |
1136 | .B \ec\fIx\fP |
1137 | a control-\fIx\fP character | |
ccc6cda3 JA |
1138 | .PD |
1139 | .RE | |
1140 | .LP | |
bb70624e | 1141 | The expanded result is single-quoted, as if the dollar sign had |
ccc6cda3 JA |
1142 | not been present. |
1143 | .PP | |
08e72d7a CR |
1144 | A double-quoted string preceded by a dollar sign (\fB$\fP\(dq\fIstring\fP\(dq) |
1145 | will cause the string to be translated according to the current locale. | |
ccc6cda3 JA |
1146 | If the current locale is \fBC\fP or \fBPOSIX\fP, the dollar sign |
1147 | is ignored. | |
1148 | If the string is translated and replaced, the replacement is | |
1149 | double-quoted. | |
726f6388 JA |
1150 | .SH PARAMETERS |
1151 | A | |
1152 | .I parameter | |
ccc6cda3 JA |
1153 | is an entity that stores values. |
1154 | It can be a | |
726f6388 JA |
1155 | .IR name , |
1156 | a number, or one of the special characters listed below under | |
1157 | .BR "Special Parameters" . | |
d3a24ed2 | 1158 | A |
726f6388 JA |
1159 | .I variable |
1160 | is a parameter denoted by a | |
1161 | .IR name . | |
f73dda09 JA |
1162 | A variable has a \fIvalue\fP and zero or more \fIattributes\fP. |
1163 | Attributes are assigned using the | |
1164 | .B declare | |
1165 | builtin command (see | |
1166 | .B declare | |
1167 | below in | |
1168 | .SM | |
1169 | .BR "SHELL BUILTIN COMMANDS" ). | |
726f6388 JA |
1170 | .PP |
1171 | A parameter is set if it has been assigned a value. The null string is | |
1172 | a valid value. Once a variable is set, it may be unset only by using | |
1173 | the | |
1174 | .B unset | |
1175 | builtin command (see | |
1176 | .SM | |
1177 | .B SHELL BUILTIN COMMANDS | |
1178 | below). | |
1179 | .PP | |
1180 | A | |
1181 | .I variable | |
1182 | may be assigned to by a statement of the form | |
1183 | .RS | |
1184 | .PP | |
1185 | \fIname\fP=[\fIvalue\fP] | |
1186 | .RE | |
1187 | .PP | |
1188 | If | |
1189 | .I value | |
1190 | is not given, the variable is assigned the null string. All | |
1191 | .I values | |
bb70624e JA |
1192 | undergo tilde expansion, parameter and variable expansion, |
1193 | command substitution, arithmetic expansion, and quote | |
ccc6cda3 JA |
1194 | removal (see |
1195 | .SM | |
1196 | .B EXPANSION | |
1197 | below). If the variable has its | |
cce855bc | 1198 | .B integer |
f73dda09 | 1199 | attribute set, then |
726f6388 | 1200 | .I value |
d3a24ed2 | 1201 | is evaluated as an arithmetic expression even if the $((...)) expansion is |
cce855bc | 1202 | not used (see |
ccc6cda3 JA |
1203 | .B "Arithmetic Expansion" |
1204 | below). | |
1205 | Word splitting is not performed, with the exception | |
726f6388 JA |
1206 | of \fB"$@"\fP as explained below under |
1207 | .BR "Special Parameters" . | |
1208 | Pathname expansion is not performed. | |
f73dda09 | 1209 | Assignment statements may also appear as arguments to the |
5e13499c | 1210 | .BR alias , |
f73dda09 JA |
1211 | .BR declare , |
1212 | .BR typeset , | |
1213 | .BR export , | |
1214 | .BR readonly , | |
1215 | and | |
1216 | .B local | |
1217 | builtin commands. | |
19baff85 CR |
1218 | When in \fIposix mode\fP, these builtins may appear in a command after |
1219 | one or more instances of the \fBcommand\fP builtin and retain these | |
1220 | assignment statement properties. | |
d11b8b46 CR |
1221 | .PP |
1222 | In the context where an assignment statement is assigning a value | |
1223 | to a shell variable or array index, the += operator can be used to | |
1224 | append to or add to the variable's previous value. | |
dc60d4e0 | 1225 | When += is applied to a variable for which the \fIinteger\fP attribute has been |
d11b8b46 CR |
1226 | set, \fIvalue\fP is evaluated as an arithmetic expression and added to the |
1227 | variable's current value, which is also evaluated. | |
1228 | When += is applied to an array variable using compound assignment (see | |
1229 | .B Arrays | |
1230 | below), the | |
1231 | variable's value is not unset (as it is when using =), and new values are | |
fdf670ea CR |
1232 | appended to the array beginning at one greater than the array's maximum index |
1233 | (for indexed arrays) or added as additional key\-value pairs in an | |
1234 | associative array. | |
d11b8b46 CR |
1235 | When applied to a string-valued variable, \fIvalue\fP is expanded and |
1236 | appended to the variable's value. | |
726f6388 JA |
1237 | .SS Positional Parameters |
1238 | .PP | |
1239 | A | |
1240 | .I positional parameter | |
1241 | is a parameter denoted by one or more | |
1242 | digits, other than the single digit 0. Positional parameters are | |
1243 | assigned from the shell's arguments when it is invoked, | |
1244 | and may be reassigned using the | |
1245 | .B set | |
1246 | builtin command. Positional parameters may not be assigned to | |
1247 | with assignment statements. The positional parameters are | |
1248 | temporarily replaced when a shell function is executed (see | |
1249 | .SM | |
1250 | .B FUNCTIONS | |
1251 | below). | |
1252 | .PP | |
1253 | When a positional parameter consisting of more than a single | |
1254 | digit is expanded, it must be enclosed in braces (see | |
1255 | .SM | |
1256 | .B EXPANSION | |
1257 | below). | |
1258 | .SS Special Parameters | |
1259 | .PP | |
1260 | The shell treats several parameters specially. These parameters may | |
1261 | only be referenced; assignment to them is not allowed. | |
1262 | .PD 0 | |
1263 | .TP | |
1264 | .B * | |
1265 | Expands to the positional parameters, starting from one. When the | |
1266 | expansion occurs within double quotes, it expands to a single word | |
1267 | with the value of each parameter separated by the first character | |
1268 | of the | |
1269 | .SM | |
1270 | .B IFS | |
cce855bc JA |
1271 | special variable. That is, "\fB$*\fP" is equivalent |
1272 | to "\fB$1\fP\fIc\fP\fB$2\fP\fIc\fP\fB...\fP", where | |
726f6388 JA |
1273 | .I c |
1274 | is the first character of the value of the | |
1275 | .SM | |
1276 | .B IFS | |
1277 | variable. If | |
1278 | .SM | |
1279 | .B IFS | |
d166f048 JA |
1280 | is unset, the parameters are separated by spaces. |
1281 | If | |
1282 | .SM | |
1283 | .B IFS | |
1284 | is null, the parameters are joined without intervening separators. | |
726f6388 JA |
1285 | .TP |
1286 | .B @ | |
1287 | Expands to the positional parameters, starting from one. When the | |
cce855bc JA |
1288 | expansion occurs within double quotes, each parameter expands to a |
1289 | separate word. That is, "\fB$@\fP" is equivalent to | |
1290 | "\fB$1\fP" "\fB$2\fP" ... | |
be7d8f2d CR |
1291 | If the double-quoted expansion occurs within a word, the expansion of |
1292 | the first parameter is joined with the beginning part of the original | |
1293 | word, and the expansion of the last parameter is joined with the last | |
1294 | part of the original word. | |
cce855bc | 1295 | When there are no positional parameters, "\fB$@\fP" and |
726f6388 JA |
1296 | .B $@ |
1297 | expand to nothing (i.e., they are removed). | |
1298 | .TP | |
1299 | .B # | |
1300 | Expands to the number of positional parameters in decimal. | |
1301 | .TP | |
1302 | .B ? | |
e882163b | 1303 | Expands to the exit status of the most recently executed foreground |
726f6388 JA |
1304 | pipeline. |
1305 | .TP | |
1306 | .B \- | |
1307 | Expands to the current option flags as specified upon invocation, | |
1308 | by the | |
1309 | .B set | |
1310 | builtin command, or those set by the shell itself | |
1311 | (such as the | |
1312 | .B \-i | |
cce855bc | 1313 | option). |
726f6388 JA |
1314 | .TP |
1315 | .B $ | |
1316 | Expands to the process ID of the shell. In a () subshell, it | |
1317 | expands to the process ID of the current shell, not the | |
1318 | subshell. | |
1319 | .TP | |
1320 | .B ! | |
1321 | Expands to the process ID of the most recently executed background | |
1322 | (asynchronous) command. | |
1323 | .TP | |
1324 | .B 0 | |
1325 | Expands to the name of the shell or shell script. This is set at | |
1326 | shell initialization. If | |
1327 | .B bash | |
1328 | is invoked with a file of commands, | |
1329 | .B $0 | |
1330 | is set to the name of that file. If | |
1331 | .B bash | |
1332 | is started with the | |
1333 | .B \-c | |
1334 | option, then | |
1335 | .B $0 | |
1336 | is set to the first argument after the string to be | |
1337 | executed, if one is present. Otherwise, it is set | |
b28ff8c9 | 1338 | to the filename used to invoke |
726f6388 JA |
1339 | .BR bash , |
1340 | as given by argument zero. | |
1341 | .TP | |
1342 | .B _ | |
cc87ba64 CR |
1343 | At shell startup, set to the absolute pathname used to invoke the |
1344 | shell or shell script being executed as passed in the environment | |
1345 | or argument list. | |
ccc6cda3 JA |
1346 | Subsequently, expands to the last argument to the previous command, |
1347 | after expansion. | |
cc87ba64 CR |
1348 | Also set to the full pathname used to invoke each command executed |
1349 | and placed in the environment exported to that command. | |
ccc6cda3 JA |
1350 | When checking mail, this parameter holds the name of the mail file |
1351 | currently being checked. | |
726f6388 JA |
1352 | .PD |
1353 | .SS Shell Variables | |
1354 | .PP | |
1355 | The following variables are set by the shell: | |
1356 | .PP | |
1357 | .PD 0 | |
1358 | .TP | |
726f6388 | 1359 | .B BASH |
b28ff8c9 | 1360 | Expands to the full filename used to invoke this instance of |
726f6388 JA |
1361 | .BR bash . |
1362 | .TP | |
691aebcb CR |
1363 | .B BASHOPTS |
1364 | A colon-separated list of enabled shell options. Each word in | |
1365 | the list is a valid argument for the | |
1366 | .B \-s | |
1367 | option to the | |
1368 | .B shopt | |
1369 | builtin command (see | |
1370 | .SM | |
1371 | .B "SHELL BUILTIN COMMANDS" | |
1372 | below). The options appearing in | |
1373 | .SM | |
1374 | .B BASHOPTS | |
1375 | are those reported as | |
1376 | .I on | |
1377 | by \fBshopt\fP. | |
1378 | If this variable is in the environment when | |
1379 | .B bash | |
1380 | starts up, each shell option in the list will be enabled before | |
1381 | reading any startup files. | |
1382 | This variable is read-only. | |
1383 | .TP | |
d3ad40de | 1384 | .B BASHPID |
dc60d4e0 | 1385 | Expands to the process ID of the current \fBbash\fP process. |
d3ad40de | 1386 | This differs from \fB$$\fP under certain circumstances, such as subshells |
29d25b54 | 1387 | that do not require \fBbash\fP to be re-initialized. |
d3ad40de | 1388 | .TP |
fdf670ea CR |
1389 | .B BASH_ALIASES |
1390 | An associative array variable whose members correspond to the internal | |
5cdaaf76 | 1391 | list of aliases as maintained by the \fBalias\fP builtin. |
fdf670ea CR |
1392 | Elements added to this array appear in the alias list; unsetting array |
1393 | elements cause aliases to be removed from the alias list. | |
1394 | .TP | |
d3a24ed2 CR |
1395 | .B BASH_ARGC |
1396 | An array variable whose values are the number of parameters in each | |
29d25b54 | 1397 | frame of the current \fBbash\fP execution call stack. |
2206f89a | 1398 | The number of |
d3a24ed2 | 1399 | parameters to the current subroutine (shell function or script executed |
2206f89a CR |
1400 | with \fB.\fP or \fBsource\fP) is at the top of the stack. |
1401 | When a subroutine is executed, the number of parameters passed is pushed onto | |
984a1947 CR |
1402 | .SM |
1403 | .BR BASH_ARGC . | |
1404 | The shell sets | |
1405 | .SM | |
1406 | .B BASH_ARGC | |
1407 | only when in extended debugging mode (see the description of the | |
2206f89a CR |
1408 | .B extdebug |
1409 | option to the | |
1410 | .B shopt | |
1411 | builtin below) | |
d3a24ed2 CR |
1412 | .TP |
1413 | .B BASH_ARGV | |
29d25b54 | 1414 | An array variable containing all of the parameters in the current \fBbash\fP |
d3a24ed2 CR |
1415 | execution call stack. The final parameter of the last subroutine call |
1416 | is at the top of the stack; the first parameter of the initial call is | |
1417 | at the bottom. When a subroutine is executed, the parameters supplied | |
984a1947 CR |
1418 | are pushed onto |
1419 | .SM | |
1420 | .BR BASH_ARGV . | |
1421 | The shell sets | |
1422 | .SM | |
1423 | .B BASH_ARGV | |
1424 | only when in extended debugging mode | |
2206f89a CR |
1425 | (see the description of the |
1426 | .B extdebug | |
1427 | option to the | |
1428 | .B shopt | |
1429 | builtin below) | |
d3a24ed2 | 1430 | .TP |
fdf670ea CR |
1431 | .B BASH_CMDS |
1432 | An associative array variable whose members correspond to the internal | |
1433 | hash table of commands as maintained by the \fBhash\fP builtin. | |
1434 | Elements added to this array appear in the hash table; unsetting array | |
1435 | elements cause commands to be removed from the hash table. | |
1436 | .TP | |
d3a24ed2 CR |
1437 | .B BASH_COMMAND |
1438 | The command currently being executed or about to be executed, unless the | |
1439 | shell is executing a command as the result of a trap, | |
1440 | in which case it is the command executing at the time of the trap. | |
1441 | .TP | |
1442 | .B BASH_EXECUTION_STRING | |
1443 | The command argument to the \fB\-c\fP invocation option. | |
1444 | .TP | |
1445 | .B BASH_LINENO | |
1446 | An array variable whose members are the line numbers in source files | |
7d92f73f | 1447 | where each corresponding member of |
984a1947 | 1448 | .SM |
7d92f73f CR |
1449 | .B FUNCNAME |
1450 | was invoked. | |
d3a24ed2 | 1451 | \fB${BASH_LINENO[\fP\fI$i\fP\fB]}\fP is the line number in the source |
7d92f73f CR |
1452 | file (\fB${BASH_SOURCE[\fP\fI$i+1\fP\fB]}\fP) where |
1453 | \fB${FUNCNAME[\fP\fI$i\fP\fB]}\fP was called | |
3d4e09aa CR |
1454 | (or \fB${BASH_LINENO[\fP\fI$i-1\fP\fB]}\fP if referenced within another |
1455 | shell function). | |
984a1947 CR |
1456 | Use |
1457 | .SM | |
1458 | .B LINENO | |
1459 | to obtain the current line number. | |
d3a24ed2 CR |
1460 | .TP |
1461 | .B BASH_REMATCH | |
1462 | An array variable whose members are assigned by the \fB=~\fP binary | |
1463 | operator to the \fB[[\fP conditional command. | |
1464 | The element with index 0 is the portion of the string | |
1465 | matching the entire regular expression. | |
1466 | The element with index \fIn\fP is the portion of the | |
1467 | string matching the \fIn\fPth parenthesized subexpression. | |
1468 | This variable is read-only. | |
1469 | .TP | |
1470 | .B BASH_SOURCE | |
7d92f73f CR |
1471 | An array variable whose members are the source filenames |
1472 | where the corresponding shell function names in the | |
984a1947 CR |
1473 | .SM |
1474 | .B FUNCNAME | |
7d92f73f CR |
1475 | array variable are defined. |
1476 | The shell function | |
1477 | \fB${FUNCNAME[\fP\fI$i\fP\fB]}\fP is defined in the file | |
1478 | \fB${BASH_SOURCE[\fP\fI$i\fP\fB]}\fP and called from | |
1479 | \fB${BASH_SOURCE[\fP\fI$i+1\fP\fB]}\fP. | |
d3a24ed2 CR |
1480 | .TP |
1481 | .B BASH_SUBSHELL | |
c1854f2d CR |
1482 | Incremented by one within each subshell or subshell environment when |
1483 | the shell begins executing in that environment. | |
d3a24ed2 CR |
1484 | The initial value is 0. |
1485 | .TP | |
ccc6cda3 | 1486 | .B BASH_VERSINFO |
cce855bc JA |
1487 | A readonly array variable whose members hold version information for |
1488 | this instance of | |
ccc6cda3 JA |
1489 | .BR bash . |
1490 | The values assigned to the array members are as follows: | |
1491 | .sp .5 | |
1492 | .RS | |
ccc6cda3 JA |
1493 | .TP 24 |
1494 | .B BASH_VERSINFO[\fR0\fP] | |
1495 | The major version number (the \fIrelease\fP). | |
1496 | .TP | |
1497 | .B BASH_VERSINFO[\fR1\fP] | |
1498 | The minor version number (the \fIversion\fP). | |
1499 | .TP | |
1500 | .B BASH_VERSINFO[\fR2\fP] | |
1501 | The patch level. | |
1502 | .TP | |
1503 | .B BASH_VERSINFO[\fR3\fP] | |
1504 | The build version. | |
1505 | .TP | |
1506 | .B BASH_VERSINFO[\fR4\fP] | |
1507 | The release status (e.g., \fIbeta1\fP). | |
1508 | .TP | |
1509 | .B BASH_VERSINFO[\fR5\fP] | |
984a1947 CR |
1510 | The value of |
1511 | .SM | |
1512 | .BR MACHTYPE . | |
ccc6cda3 JA |
1513 | .RE |
1514 | .TP | |
f73dda09 JA |
1515 | .B BASH_VERSION |
1516 | Expands to a string describing the version of this instance of | |
1517 | .BR bash . | |
726f6388 | 1518 | .TP |
f73dda09 JA |
1519 | .B COMP_CWORD |
1520 | An index into \fB${COMP_WORDS}\fP of the word containing the current | |
1521 | cursor position. | |
1522 | This variable is available only in shell functions invoked by the | |
1523 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1524 | below). | |
1525 | .TP | |
d3ad40de CR |
1526 | .B COMP_KEY |
1527 | The key (or final key of a key sequence) used to invoke the current | |
1528 | completion function. | |
1529 | .TP | |
f73dda09 JA |
1530 | .B COMP_LINE |
1531 | The current command line. | |
1532 | This variable is available only in shell functions and external | |
1533 | commands invoked by the | |
1534 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1535 | below). | |
1536 | .TP | |
1537 | .B COMP_POINT | |
1538 | The index of the current cursor position relative to the beginning of | |
1539 | the current command. | |
1540 | If the current cursor position is at the end of the current command, | |
1541 | the value of this variable is equal to \fB${#COMP_LINE}\fP. | |
1542 | This variable is available only in shell functions and external | |
1543 | commands invoked by the | |
1544 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1545 | below). | |
1546 | .TP | |
d3ad40de CR |
1547 | .B COMP_TYPE |
1548 | Set to an integer value corresponding to the type of completion attempted | |
1549 | that caused a completion function to be called: | |
1550 | \fITAB\fP, for normal completion, | |
1551 | \fI?\fP, for listing completions after successive tabs, | |
1552 | \fI!\fP, for listing alternatives on partial word completion, | |
1553 | \fI@\fP, to list completions if the word is not unmodified, | |
1554 | or | |
1555 | \fI%\fP, for menu completion. | |
1556 | This variable is available only in shell functions and external | |
1557 | commands invoked by the | |
1558 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1559 | below). | |
1560 | .TP | |
d3a24ed2 | 1561 | .B COMP_WORDBREAKS |
db31fb26 | 1562 | The set of characters that the \fBreadline\fP library treats as word |
d3a24ed2 CR |
1563 | separators when performing word completion. |
1564 | If | |
1565 | .SM | |
1566 | .B COMP_WORDBREAKS | |
1567 | is unset, it loses its special properties, even if it is | |
1568 | subsequently reset. | |
1569 | .TP | |
f73dda09 JA |
1570 | .B COMP_WORDS |
1571 | An array variable (see \fBArrays\fP below) consisting of the individual | |
1572 | words in the current command line. | |
db31fb26 | 1573 | The line is split into words as \fBreadline\fP would split it, using |
984a1947 CR |
1574 | .SM |
1575 | .B COMP_WORDBREAKS | |
1576 | as described above. | |
f73dda09 JA |
1577 | This variable is available only in shell functions invoked by the |
1578 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1579 | below). | |
1580 | .TP | |
5cdaaf76 CR |
1581 | .B COPROC |
1582 | An array variable (see \fBArrays\fP below) created to hold the file descriptors | |
1583 | for output from and input to an unnamed coprocess (see \fBCoprocesses\fP | |
1584 | above). | |
1585 | .TP | |
f73dda09 JA |
1586 | .B DIRSTACK |
1587 | An array variable (see | |
1588 | .B Arrays | |
1589 | below) containing the current contents of the directory stack. | |
1590 | Directories appear in the stack in the order they are displayed by the | |
1591 | .B dirs | |
1592 | builtin. | |
1593 | Assigning to members of this array variable may be used to modify | |
1594 | directories already in the stack, but the | |
1595 | .B pushd | |
1596 | and | |
1597 | .B popd | |
1598 | builtins must be used to add and remove directories. | |
1599 | Assignment to this variable will not change the current directory. | |
726f6388 JA |
1600 | If |
1601 | .SM | |
f73dda09 | 1602 | .B DIRSTACK |
726f6388 JA |
1603 | is unset, it loses its special properties, even if it is |
1604 | subsequently reset. | |
1605 | .TP | |
f73dda09 JA |
1606 | .B EUID |
1607 | Expands to the effective user ID of the current user, initialized at | |
1608 | shell startup. This variable is readonly. | |
1609 | .TP | |
1610 | .B FUNCNAME | |
d3a24ed2 CR |
1611 | An array variable containing the names of all shell functions |
1612 | currently in the execution call stack. | |
1613 | The element with index 0 is the name of any currently-executing | |
1614 | shell function. | |
7d92f73f | 1615 | The bottom-most element (the one with the highest index) is |
d3ad40de CR |
1616 | .if t \f(CW"main"\fP. |
1617 | .if n "main". | |
f73dda09 JA |
1618 | This variable exists only when a shell function is executing. |
1619 | Assignments to | |
726f6388 | 1620 | .SM |
f73dda09 JA |
1621 | .B FUNCNAME |
1622 | have no effect and return an error status. | |
726f6388 JA |
1623 | If |
1624 | .SM | |
f73dda09 | 1625 | .B FUNCNAME |
726f6388 JA |
1626 | is unset, it loses its special properties, even if it is |
1627 | subsequently reset. | |
7d92f73f CR |
1628 | .if t .sp 0.5 |
1629 | .if n .sp 1 | |
1630 | This variable can be used with \fBBASH_LINENO\fP and \fBBASH_SOURCE\fP. | |
1631 | Each element of \fBFUNCNAME\fP has corresponding elements in | |
1632 | \fBBASH_LINENO\fP and \fBBASH_SOURCE\fP to describe the call stack. | |
1633 | For instance, \fB${FUNCNAME[\fP\fI$i\fP\fB]}\fP was called from the file | |
1634 | \fB${BASH_SOURCE[\fP\fI$i+1\fP\fB]}\fP at line number | |
1635 | \fB${BASH_LINENO[\fP\fI$i\fP\fB]}\fP. | |
1636 | The \fBcaller\fP builtin displays the current call stack using this | |
1637 | information. | |
726f6388 | 1638 | .TP |
f73dda09 JA |
1639 | .B GROUPS |
1640 | An array variable containing the list of groups of which the current | |
1641 | user is a member. | |
1642 | Assignments to | |
1643 | .SM | |
1644 | .B GROUPS | |
1645 | have no effect and return an error status. | |
726f6388 JA |
1646 | If |
1647 | .SM | |
f73dda09 | 1648 | .B GROUPS |
726f6388 JA |
1649 | is unset, it loses its special properties, even if it is |
1650 | subsequently reset. | |
1651 | .TP | |
1652 | .B HISTCMD | |
1653 | The history number, or index in the history list, of the current | |
ccc6cda3 JA |
1654 | command. |
1655 | If | |
726f6388 JA |
1656 | .SM |
1657 | .B HISTCMD | |
1658 | is unset, it loses its special properties, even if it is | |
1659 | subsequently reset. | |
1660 | .TP | |
f73dda09 JA |
1661 | .B HOSTNAME |
1662 | Automatically set to the name of the current host. | |
bb70624e | 1663 | .TP |
f73dda09 JA |
1664 | .B HOSTTYPE |
1665 | Automatically set to a string that uniquely | |
1666 | describes the type of machine on which | |
1667 | .B bash | |
1668 | is executing. | |
1669 | The default is system-dependent. | |
1670 | .TP | |
1671 | .B LINENO | |
1672 | Each time this parameter is referenced, the shell substitutes | |
1673 | a decimal number representing the current sequential line number | |
1674 | (starting with 1) within a script or function. When not in a | |
1675 | script or function, the value substituted is not guaranteed to | |
1676 | be meaningful. | |
ccc6cda3 JA |
1677 | If |
1678 | .SM | |
f73dda09 | 1679 | .B LINENO |
ccc6cda3 JA |
1680 | is unset, it loses its special properties, even if it is |
1681 | subsequently reset. | |
1682 | .TP | |
f73dda09 JA |
1683 | .B MACHTYPE |
1684 | Automatically set to a string that fully describes the system | |
1685 | type on which | |
1686 | .B bash | |
1687 | is executing, in the standard GNU \fIcpu-company-system\fP format. | |
1688 | The default is system-dependent. | |
1689 | .TP | |
5cdaaf76 CR |
1690 | .B MAPFILE |
1691 | An array variable (see \fBArrays\fP below) created to hold the text | |
1692 | read by the \fBmapfile\fP builtin when no variable name is supplied. | |
1693 | .TP | |
f73dda09 JA |
1694 | .B OLDPWD |
1695 | The previous working directory as set by the | |
1696 | .B cd | |
1697 | command. | |
ccc6cda3 | 1698 | .TP |
726f6388 JA |
1699 | .B OPTARG |
1700 | The value of the last option argument processed by the | |
1701 | .B getopts | |
1702 | builtin command (see | |
1703 | .SM | |
1704 | .B SHELL BUILTIN COMMANDS | |
1705 | below). | |
1706 | .TP | |
1707 | .B OPTIND | |
1708 | The index of the next argument to be processed by the | |
1709 | .B getopts | |
1710 | builtin command (see | |
1711 | .SM | |
1712 | .B SHELL BUILTIN COMMANDS | |
1713 | below). | |
1714 | .TP | |
726f6388 JA |
1715 | .B OSTYPE |
1716 | Automatically set to a string that | |
1717 | describes the operating system on which | |
1718 | .B bash | |
ccc6cda3 JA |
1719 | is executing. |
1720 | The default is system-dependent. | |
1721 | .TP | |
f73dda09 JA |
1722 | .B PIPESTATUS |
1723 | An array variable (see | |
1724 | .B Arrays | |
1725 | below) containing a list of exit status values from the processes | |
1726 | in the most-recently-executed foreground pipeline (which may | |
1727 | contain only a single command). | |
ccc6cda3 | 1728 | .TP |
f73dda09 JA |
1729 | .B PPID |
1730 | The process ID of the shell's parent. This variable is readonly. | |
1731 | .TP | |
1732 | .B PWD | |
1733 | The current working directory as set by the | |
1734 | .B cd | |
1735 | command. | |
1736 | .TP | |
1737 | .B RANDOM | |
1738 | Each time this parameter is referenced, a random integer between | |
1739 | 0 and 32767 is | |
1740 | generated. The sequence of random numbers may be initialized by assigning | |
1741 | a value to | |
1742 | .SM | |
1743 | .BR RANDOM . | |
1744 | If | |
1745 | .SM | |
1746 | .B RANDOM | |
1747 | is unset, it loses its special properties, even if it is | |
1748 | subsequently reset. | |
1749 | .TP | |
5cdaaf76 CR |
1750 | .B READLINE_LINE |
1751 | The contents of the | |
1752 | .B readline | |
1753 | line buffer, for use with | |
1754 | .if t \f(CWbind -x\fP | |
1755 | .if n "bind -x" | |
1756 | (see | |
1757 | .SM | |
1758 | .B "SHELL BUILTIN COMMANDS" | |
1759 | below). | |
1760 | .TP | |
1761 | .B READLINE_POINT | |
1762 | The position of the insertion point in the | |
1763 | .B readline | |
1764 | line buffer, for use with | |
1765 | .if t \f(CWbind -x\fP | |
1766 | .if n "bind -x" | |
1767 | (see | |
1768 | .SM | |
1769 | .B "SHELL BUILTIN COMMANDS" | |
1770 | below). | |
1771 | .TP | |
f73dda09 JA |
1772 | .B REPLY |
1773 | Set to the line of input read by the | |
1774 | .B read | |
1775 | builtin command when no arguments are supplied. | |
1776 | .TP | |
1777 | .B SECONDS | |
1778 | Each time this parameter is | |
1779 | referenced, the number of seconds since shell invocation is returned. If a | |
1780 | value is assigned to | |
1781 | .SM | |
1782 | .BR SECONDS , | |
1783 | the value returned upon subsequent | |
1784 | references is | |
1785 | the number of seconds since the assignment plus the value assigned. | |
1786 | If | |
1787 | .SM | |
1788 | .B SECONDS | |
1789 | is unset, it loses its special properties, even if it is | |
1790 | subsequently reset. | |
1791 | .TP | |
1792 | .B SHELLOPTS | |
1793 | A colon-separated list of enabled shell options. Each word in | |
1794 | the list is a valid argument for the | |
1795 | .B \-o | |
1796 | option to the | |
1797 | .B set | |
1798 | builtin command (see | |
1799 | .SM | |
1800 | .B "SHELL BUILTIN COMMANDS" | |
1801 | below). The options appearing in | |
ccc6cda3 JA |
1802 | .SM |
1803 | .B SHELLOPTS | |
1804 | are those reported as | |
1805 | .I on | |
1806 | by \fBset \-o\fP. | |
1807 | If this variable is in the environment when | |
1808 | .B bash | |
1809 | starts up, each shell option in the list will be enabled before | |
1810 | reading any startup files. | |
1811 | This variable is read-only. | |
bb70624e | 1812 | .TP |
f73dda09 JA |
1813 | .B SHLVL |
1814 | Incremented by one each time an instance of | |
1815 | .B bash | |
1816 | is started. | |
bb70624e | 1817 | .TP |
f73dda09 JA |
1818 | .B UID |
1819 | Expands to the user ID of the current user, initialized at shell startup. | |
1820 | This variable is readonly. | |
726f6388 JA |
1821 | .PD |
1822 | .PP | |
1823 | The following variables are used by the shell. In some cases, | |
1824 | .B bash | |
1825 | assigns a default value to a variable; these cases are noted | |
1826 | below. | |
1827 | .PP | |
1828 | .PD 0 | |
1829 | .TP | |
d166f048 | 1830 | .B BASH_ENV |
726f6388 JA |
1831 | If this parameter is set when \fBbash\fP is executing a shell script, |
1832 | its value is interpreted as a filename containing commands to | |
1833 | initialize the shell, as in | |
cce855bc | 1834 | .IR ~/.bashrc . |
726f6388 JA |
1835 | The value of |
1836 | .SM | |
d166f048 | 1837 | .B BASH_ENV |
726f6388 | 1838 | is subjected to parameter expansion, command substitution, and arithmetic |
b28ff8c9 | 1839 | expansion before being interpreted as a filename. |
726f6388 JA |
1840 | .SM |
1841 | .B PATH | |
b28ff8c9 | 1842 | is not used to search for the resultant filename. |
726f6388 | 1843 | .TP |
8f714a7c CR |
1844 | .B BASH_XTRACEFD |
1845 | If set to an integer corresponding to a valid file descriptor, \fBbash\fP | |
1846 | will write the trace output generated when | |
1847 | .if t \f(CWset -x\fP | |
1848 | .if n \fIset -x\fP | |
1849 | is enabled to that file descriptor. | |
984a1947 CR |
1850 | The file descriptor is closed when |
1851 | .SM | |
1852 | .B BASH_XTRACEFD | |
1853 | is unset or assigned a new value. | |
1854 | Unsetting | |
1855 | .SM | |
1856 | .B BASH_XTRACEFD | |
1857 | or assigning it the empty string causes the | |
8f714a7c | 1858 | trace output to be sent to the standard error. |
984a1947 CR |
1859 | Note that setting |
1860 | .SM | |
1861 | .B BASH_XTRACEFD | |
1862 | to 2 (the standard error file | |
8f714a7c CR |
1863 | descriptor) and then unsetting it will result in the standard error |
1864 | being closed. | |
1865 | .TP | |
5cdaaf76 CR |
1866 | .B CDPATH |
1867 | The search path for the | |
1868 | .B cd | |
1869 | command. | |
1870 | This is a colon-separated list of directories in which the shell looks | |
1871 | for destination directories specified by the | |
1872 | .B cd | |
1873 | command. | |
1874 | A sample value is | |
1875 | .if t \f(CW".:~:/usr"\fP. | |
1876 | .if n ".:~:/usr". | |
1877 | .TP | |
f73dda09 | 1878 | .B COLUMNS |
54a1fa7c | 1879 | Used by the \fBselect\fP compound command to determine the terminal width |
276cb932 CR |
1880 | when printing selection lists. Automatically set in an interactive shell |
1881 | upon receipt of a | |
9c7f20c7 CR |
1882 | .SM |
1883 | .BR SIGWINCH . | |
726f6388 | 1884 | .TP |
f73dda09 JA |
1885 | .B COMPREPLY |
1886 | An array variable from which \fBbash\fP reads the possible completions | |
1887 | generated by a shell function invoked by the programmable completion | |
1888 | facility (see \fBProgrammable Completion\fP below). | |
ba4ab055 | 1889 | Each array element contains one possible completion. |
726f6388 | 1890 | .TP |
d3a24ed2 CR |
1891 | .B EMACS |
1892 | If \fBbash\fP finds this variable in the environment when the shell starts | |
1893 | with value | |
1894 | .if t \f(CWt\fP, | |
1895 | .if n "t", | |
5f8cde23 | 1896 | it assumes that the shell is running in an Emacs shell buffer and disables |
d3a24ed2 CR |
1897 | line editing. |
1898 | .TP | |
5cdaaf76 CR |
1899 | .B ENV |
1900 | Similar to | |
1901 | .SM | |
1902 | .BR BASH_ENV ; | |
1903 | used when the shell is invoked in POSIX mode. | |
1904 | .TP | |
f73dda09 JA |
1905 | .B FCEDIT |
1906 | The default editor for the | |
1907 | .B fc | |
1908 | builtin command. | |
726f6388 | 1909 | .TP |
f73dda09 JA |
1910 | .B FIGNORE |
1911 | A colon-separated list of suffixes to ignore when performing | |
1912 | filename completion (see | |
726f6388 | 1913 | .SM |
f73dda09 JA |
1914 | .B READLINE |
1915 | below). | |
1916 | A filename whose suffix matches one of the entries in | |
726f6388 | 1917 | .SM |
f73dda09 JA |
1918 | .B FIGNORE |
1919 | is excluded from the list of matched filenames. | |
7117c2d2 JA |
1920 | A sample value is |
1921 | .if t \f(CW".o:~"\fP. | |
1922 | .if n ".o:~". | |
ccc6cda3 | 1923 | .TP |
6faad625 CR |
1924 | .B FUNCNEST |
1925 | If set to a numeric value greater than 0, defines a maximum function | |
1926 | nesting level. Function invocations that exceed this nesting level | |
1927 | will cause the current command to abort. | |
1928 | .TP | |
f73dda09 JA |
1929 | .B GLOBIGNORE |
1930 | A colon-separated list of patterns defining the set of filenames to | |
1931 | be ignored by pathname expansion. | |
1932 | If a filename matched by a pathname expansion pattern also matches one | |
1933 | of the patterns in | |
726f6388 | 1934 | .SM |
f73dda09 JA |
1935 | .BR GLOBIGNORE , |
1936 | it is removed from the list of matches. | |
1937 | .TP | |
1938 | .B HISTCONTROL | |
d3a24ed2 CR |
1939 | A colon-separated list of values controlling how commands are saved on |
1940 | the history list. | |
1941 | If the list of values includes | |
f73dda09 JA |
1942 | .IR ignorespace , |
1943 | lines which begin with a | |
1944 | .B space | |
d3a24ed2 CR |
1945 | character are not saved in the history list. |
1946 | A value of | |
1947 | .I ignoredups | |
1948 | causes lines matching the previous history entry to not be saved. | |
f73dda09 JA |
1949 | A value of |
1950 | .I ignoreboth | |
d3a24ed2 CR |
1951 | is shorthand for \fIignorespace\fP and \fIignoredups\fP. |
1952 | A value of | |
1953 | .IR erasedups | |
1954 | causes all previous lines matching the current line to be removed from | |
1955 | the history list before that line is saved. | |
1956 | Any value not in the above list is ignored. | |
984a1947 CR |
1957 | If |
1958 | .SM | |
1959 | .B HISTCONTROL | |
1960 | is unset, or does not include a valid value, | |
d3a24ed2 CR |
1961 | all lines read by the shell parser are saved on the history list, |
1962 | subject to the value of | |
984a1947 | 1963 | .SM |
f73dda09 JA |
1964 | .BR HISTIGNORE . |
1965 | The second and subsequent lines of a multi-line compound command are | |
1966 | not tested, and are added to the history regardless of the value of | |
984a1947 | 1967 | .SM |
f73dda09 | 1968 | .BR HISTCONTROL . |
726f6388 JA |
1969 | .TP |
1970 | .B HISTFILE | |
ccc6cda3 | 1971 | The name of the file in which command history is saved (see |
726f6388 JA |
1972 | .SM |
1973 | .B HISTORY | |
ccc6cda3 | 1974 | below). The default value is \fI~/.bash_history\fP. If unset, the |
726f6388 JA |
1975 | command history is not saved when an interactive shell exits. |
1976 | .TP | |
1977 | .B HISTFILESIZE | |
1978 | The maximum number of lines contained in the history file. When this | |
1979 | variable is assigned a value, the history file is truncated, if | |
4b82d1cd CR |
1980 | necessary, |
1981 | to contain no more than that number of lines by removing the oldest entries. | |
1982 | The history file is also truncated to this size after | |
ccc6cda3 | 1983 | writing it when an interactive shell exits. |
4b82d1cd | 1984 | If the value is 0, the history file is truncated to zero size. |
e67d0029 | 1985 | Non-numeric values and numeric values less than zero inhibit truncation. |
4b82d1cd CR |
1986 | The shell sets the default value to the value of \fBHISTSIZE\fP |
1987 | after reading any startup files. | |
726f6388 | 1988 | .TP |
f73dda09 JA |
1989 | .B HISTIGNORE |
1990 | A colon-separated list of patterns used to decide which command lines | |
1991 | should be saved on the history list. Each pattern is anchored at the | |
1992 | beginning of the line and must match the complete line (no implicit | |
1993 | `\fB*\fP' is appended). Each pattern is tested against the line | |
1994 | after the checks specified by | |
984a1947 | 1995 | .SM |
f73dda09 JA |
1996 | .B HISTCONTROL |
1997 | are applied. | |
1998 | In addition to the normal shell pattern matching characters, `\fB&\fP' | |
1999 | matches the previous history line. `\fB&\fP' may be escaped using a | |
2000 | backslash; the backslash is removed before attempting a match. | |
2001 | The second and subsequent lines of a multi-line compound command are | |
2002 | not tested, and are added to the history regardless of the value of | |
984a1947 | 2003 | .SM |
f73dda09 JA |
2004 | .BR HISTIGNORE . |
2005 | .TP | |
2006 | .B HISTSIZE | |
2007 | The number of commands to remember in the command history (see | |
2008 | .SM | |
2009 | .B HISTORY | |
4b82d1cd CR |
2010 | below). |
2011 | If the value is 0, commands are not saved in the history list. | |
2012 | Numeric values less than zero result in every command being saved | |
2013 | on the history list (there is no limit). | |
2014 | The shell sets the default value to 500 after reading any startup files. | |
f73dda09 | 2015 | .TP |
d3a24ed2 CR |
2016 | .B HISTTIMEFORMAT |
2017 | If this variable is set and not null, its value is used as a format string | |
2018 | for \fIstrftime\fP(3) to print the time stamp associated with each history | |
2019 | entry displayed by the \fBhistory\fP builtin. | |
2020 | If this variable is set, time stamps are written to the history file so | |
2021 | they may be preserved across shell sessions. | |
d3ad40de CR |
2022 | This uses the history comment character to distinguish timestamps from |
2023 | other history lines. | |
d3a24ed2 | 2024 | .TP |
f73dda09 JA |
2025 | .B HOME |
2026 | The home directory of the current user; the default argument for the | |
2027 | \fBcd\fP builtin command. | |
2028 | The value of this variable is also used when performing tilde expansion. | |
2029 | .TP | |
2030 | .B HOSTFILE | |
2031 | Contains the name of a file in the same format as | |
2032 | .FN /etc/hosts | |
2033 | that should be read when the shell needs to complete a | |
2034 | hostname. | |
2035 | The list of possible hostname completions may be changed while the | |
2036 | shell is running; | |
2037 | the next time hostname completion is attempted after the | |
2038 | value is changed, | |
726f6388 | 2039 | .B bash |
f73dda09 JA |
2040 | adds the contents of the new file to the existing list. |
2041 | If | |
726f6388 | 2042 | .SM |
f73dda09 | 2043 | .B HOSTFILE |
9dd88db7 CR |
2044 | is set, but has no value, or does not name a readable file, |
2045 | \fBbash\fP attempts to read | |
f73dda09 JA |
2046 | .FN /etc/hosts |
2047 | to obtain the list of possible hostname completions. | |
2048 | When | |
726f6388 | 2049 | .SM |
f73dda09 JA |
2050 | .B HOSTFILE |
2051 | is unset, the hostname list is cleared. | |
2052 | .TP | |
2053 | .B IFS | |
2054 | The | |
2055 | .I Internal Field Separator | |
2056 | that is used | |
2057 | for word splitting after expansion and to | |
2058 | split lines into words with the | |
2059 | .B read | |
2060 | builtin command. The default value is | |
2061 | ``<space><tab><newline>''. | |
2062 | .TP | |
2063 | .B IGNOREEOF | |
2064 | Controls the | |
2065 | action of an interactive shell on receipt of an | |
2066 | .SM | |
2067 | .B EOF | |
2068 | character as the sole input. If set, the value is the number of | |
2069 | consecutive | |
2070 | .SM | |
2071 | .B EOF | |
2072 | characters which must be | |
2073 | typed as the first characters on an input line before | |
2074 | .B bash | |
2075 | exits. If the variable exists but does not have a numeric value, or | |
2076 | has no value, the default value is 10. If it does not exist, | |
2077 | .SM | |
2078 | .B EOF | |
2079 | signifies the end of input to the shell. | |
2080 | .TP | |
2081 | .B INPUTRC | |
2082 | The filename for the | |
2083 | .B readline | |
2084 | startup file, overriding the default of | |
2085 | .FN ~/.inputrc | |
2086 | (see | |
2087 | .SM | |
2088 | .B READLINE | |
2089 | below). | |
726f6388 | 2090 | .TP |
ccc6cda3 JA |
2091 | .B LANG |
2092 | Used to determine the locale category for any category not specifically | |
2093 | selected with a variable starting with \fBLC_\fP. | |
2094 | .TP | |
2095 | .B LC_ALL | |
984a1947 CR |
2096 | This variable overrides the value of |
2097 | .SM | |
2098 | .B LANG | |
2099 | and any other | |
ccc6cda3 JA |
2100 | \fBLC_\fP variable specifying a locale category. |
2101 | .TP | |
2102 | .B LC_COLLATE | |
2103 | This variable determines the collation order used when sorting the | |
cce855bc JA |
2104 | results of pathname expansion, and determines the behavior of range |
2105 | expressions, equivalence classes, and collating sequences within | |
2106 | pathname expansion and pattern matching. | |
2107 | .TP | |
2108 | .B LC_CTYPE | |
2109 | This variable determines the interpretation of characters and the | |
2110 | behavior of character classes within pathname expansion and pattern | |
2111 | matching. | |
ccc6cda3 JA |
2112 | .TP |
2113 | .B LC_MESSAGES | |
2114 | This variable determines the locale used to translate double-quoted | |
2115 | strings preceded by a \fB$\fP. | |
2116 | .TP | |
bb70624e JA |
2117 | .B LC_NUMERIC |
2118 | This variable determines the locale category used for number formatting. | |
2119 | .TP | |
28ef6c31 | 2120 | .B LINES |
54a1fa7c | 2121 | Used by the \fBselect\fP compound command to determine the column length |
276cb932 CR |
2122 | for printing selection lists. Automatically set by an interactive shell |
2123 | upon receipt of a | |
984a1947 CR |
2124 | .SM |
2125 | .BR SIGWINCH . | |
28ef6c31 | 2126 | .TP |
f73dda09 | 2127 | .B MAIL |
9ec5ed66 | 2128 | If this parameter is set to a file or directory name and the |
726f6388 | 2129 | .SM |
f73dda09 JA |
2130 | .B MAILPATH |
2131 | variable is not set, | |
726f6388 | 2132 | .B bash |
9ec5ed66 CR |
2133 | informs the user of the arrival of mail in the specified file or |
2134 | Maildir-format directory. | |
726f6388 | 2135 | .TP |
f73dda09 JA |
2136 | .B MAILCHECK |
2137 | Specifies how | |
2138 | often (in seconds) | |
2139 | .B bash | |
2140 | checks for mail. The default is 60 seconds. When it is time to check | |
2141 | for mail, the shell does so before displaying the primary prompt. | |
2142 | If this variable is unset, or set to a value that is not a number | |
2143 | greater than or equal to zero, the shell disables mail checking. | |
726f6388 | 2144 | .TP |
f73dda09 | 2145 | .B MAILPATH |
b28ff8c9 | 2146 | A colon-separated list of filenames to be checked for mail. |
f73dda09 | 2147 | The message to be printed when mail arrives in a particular file |
b28ff8c9 | 2148 | may be specified by separating the filename from the message with a `?'. |
f73dda09 JA |
2149 | When used in the text of the message, \fB$_\fP expands to the name of |
2150 | the current mailfile. | |
2151 | Example: | |
2152 | .RS | |
2153 | .PP | |
20587658 | 2154 | \fBMAILPATH\fP=\(aq/var/mail/bfox?"You have mail":~/shell\-mail?"$_ has mail!"\(aq |
f73dda09 JA |
2155 | .PP |
2156 | .B Bash | |
2157 | supplies a default value for this variable, but the location of the user | |
2158 | mail files that it uses is system dependent (e.g., /var/mail/\fB$USER\fP). | |
2159 | .RE | |
726f6388 | 2160 | .TP |
f73dda09 JA |
2161 | .B OPTERR |
2162 | If set to the value 1, | |
2163 | .B bash | |
2164 | displays error messages generated by the | |
2165 | .B getopts | |
2166 | builtin command (see | |
726f6388 | 2167 | .SM |
f73dda09 | 2168 | .B SHELL BUILTIN COMMANDS |
ccc6cda3 | 2169 | below). |
726f6388 | 2170 | .SM |
f73dda09 JA |
2171 | .B OPTERR |
2172 | is initialized to 1 each time the shell is invoked or a shell | |
2173 | script is executed. | |
ccc6cda3 | 2174 | .TP |
f73dda09 JA |
2175 | .B PATH |
2176 | The search path for commands. It | |
2177 | is a colon-separated list of directories in which | |
2178 | the shell looks for commands (see | |
ccc6cda3 | 2179 | .SM |
f73dda09 | 2180 | .B COMMAND EXECUTION |
d3a24ed2 | 2181 | below). |
984a1947 CR |
2182 | A zero-length (null) directory name in the value of |
2183 | .SM | |
2184 | .B PATH | |
2185 | indicates the current directory. | |
d3a24ed2 CR |
2186 | A null directory name may appear as two adjacent colons, or as an initial |
2187 | or trailing colon. | |
2188 | The default path is system-dependent, | |
f73dda09 JA |
2189 | and is set by the administrator who installs |
2190 | .BR bash . | |
2191 | A common value is | |
f6da9f85 CR |
2192 | .if t \f(CW/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin\fP. |
2193 | .if n ``/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin''. | |
726f6388 | 2194 | .TP |
f73dda09 JA |
2195 | .B POSIXLY_CORRECT |
2196 | If this variable is in the environment when \fBbash\fP starts, the shell | |
2197 | enters \fIposix mode\fP before reading the startup files, as if the | |
2198 | .B \-\-posix | |
2199 | invocation option had been supplied. If it is set while the shell is | |
2200 | running, \fBbash\fP enables \fIposix mode\fP, as if the command | |
2201 | .if t \f(CWset -o posix\fP | |
2202 | .if n \fIset -o posix\fP | |
2203 | had been executed. | |
726f6388 | 2204 | .TP |
f73dda09 JA |
2205 | .B PROMPT_COMMAND |
2206 | If set, the value is executed as a command prior to issuing each primary | |
2207 | prompt. | |
ccc6cda3 | 2208 | .TP |
ed35cb4a CR |
2209 | .B PROMPT_DIRTRIM |
2210 | If set to a number greater than zero, the value is used as the number of | |
d0ca3503 | 2211 | trailing directory components to retain when expanding the \fB\ew\fP and |
ed35cb4a CR |
2212 | \fB\eW\fP prompt string escapes (see |
2213 | .SM | |
2214 | .B PROMPTING | |
2215 | below). Characters removed are replaced with an ellipsis. | |
2216 | .TP | |
f73dda09 JA |
2217 | .B PS1 |
2218 | The value of this parameter is expanded (see | |
2219 | .SM | |
2220 | .B PROMPTING | |
2221 | below) and used as the primary prompt string. The default value is | |
2222 | ``\fB\es\-\ev\e$ \fP''. | |
726f6388 | 2223 | .TP |
f73dda09 JA |
2224 | .B PS2 |
2225 | The value of this parameter is expanded as with | |
984a1947 | 2226 | .SM |
f73dda09 JA |
2227 | .B PS1 |
2228 | and used as the secondary prompt string. The default is | |
2229 | ``\fB> \fP''. | |
2230 | .TP | |
2231 | .B PS3 | |
2232 | The value of this parameter is used as the prompt for the | |
2233 | .B select | |
2234 | command (see | |
726f6388 | 2235 | .SM |
f73dda09 JA |
2236 | .B SHELL GRAMMAR |
2237 | above). | |
726f6388 | 2238 | .TP |
f73dda09 JA |
2239 | .B PS4 |
2240 | The value of this parameter is expanded as with | |
984a1947 | 2241 | .SM |
f73dda09 JA |
2242 | .B PS1 |
2243 | and the value is printed before each command | |
726f6388 | 2244 | .B bash |
f73dda09 | 2245 | displays during an execution trace. The first character of |
bb70624e | 2246 | .SM |
f73dda09 JA |
2247 | .B PS4 |
2248 | is replicated multiple times, as necessary, to indicate multiple | |
2249 | levels of indirection. The default is ``\fB+ \fP''. | |
2250 | .TP | |
61deeb13 CR |
2251 | .B SHELL |
2252 | The full pathname to the shell is kept in this environment variable. | |
2253 | If it is not set when the shell starts, | |
2254 | .B bash | |
2255 | assigns to it the full pathname of the current user's login shell. | |
2256 | .TP | |
f73dda09 JA |
2257 | .B TIMEFORMAT |
2258 | The value of this parameter is used as a format string specifying | |
2259 | how the timing information for pipelines prefixed with the | |
2260 | .B time | |
2261 | reserved word should be displayed. | |
2262 | The \fB%\fP character introduces an escape sequence that is | |
2263 | expanded to a time value or other information. | |
2264 | The escape sequences and their meanings are as follows; the | |
2265 | braces denote optional portions. | |
2266 | .sp .5 | |
2267 | .RS | |
2268 | .PD 0 | |
2269 | .TP 10 | |
2270 | .B %% | |
2271 | A literal \fB%\fP. | |
2272 | .TP | |
2273 | .B %[\fIp\fP][l]R | |
2274 | The elapsed time in seconds. | |
2275 | .TP | |
2276 | .B %[\fIp\fP][l]U | |
2277 | The number of CPU seconds spent in user mode. | |
2278 | .TP | |
2279 | .B %[\fIp\fP][l]S | |
2280 | The number of CPU seconds spent in system mode. | |
2281 | .TP | |
2282 | .B %P | |
2283 | The CPU percentage, computed as (%U + %S) / %R. | |
2284 | .PD | |
2285 | .RE | |
2286 | .IP | |
2287 | The optional \fIp\fP is a digit specifying the \fIprecision\fP, | |
2288 | the number of fractional digits after a decimal point. | |
2289 | A value of 0 causes no decimal point or fraction to be output. | |
2290 | At most three places after the decimal point may be specified; | |
2291 | values of \fIp\fP greater than 3 are changed to 3. | |
2292 | If \fIp\fP is not specified, the value 3 is used. | |
2293 | .IP | |
2294 | The optional \fBl\fP specifies a longer format, including | |
2295 | minutes, of the form \fIMM\fPm\fISS\fP.\fIFF\fPs. | |
2296 | The value of \fIp\fP determines whether or not the fraction is | |
2297 | included. | |
2298 | .IP | |
2299 | If this variable is not set, \fBbash\fP acts as if it had the | |
20587658 | 2300 | value \fB$\(aq\enreal\et%3lR\enuser\et%3lU\ensys\t%3lS\(aq\fP. |
f73dda09 JA |
2301 | If the value is null, no timing information is displayed. |
2302 | A trailing newline is added when the format string is displayed. | |
54a1fa7c | 2303 | .PD 0 |
f73dda09 JA |
2304 | .TP |
2305 | .B TMOUT | |
984a1947 CR |
2306 | If set to a value greater than zero, |
2307 | .SM | |
2308 | .B TMOUT | |
2309 | is treated as the | |
7117c2d2 JA |
2310 | default timeout for the \fBread\fP builtin. |
2311 | The \fBselect\fP command terminates if input does not arrive | |
984a1947 CR |
2312 | after |
2313 | .SM | |
2314 | .B TMOUT | |
2315 | seconds when input is coming from a terminal. | |
7117c2d2 | 2316 | In an interactive shell, the value is interpreted as the |
f73dda09 JA |
2317 | number of seconds to wait for input after issuing the primary prompt. |
2318 | .B Bash | |
2319 | terminates after waiting for that number of seconds if input does | |
2320 | not arrive. | |
726f6388 | 2321 | .TP |
1569c106 | 2322 | .B TMPDIR |
5f8cde23 CR |
2323 | If set, \fBbash\fP uses its value as the name of a directory in which |
2324 | \fBbash\fP creates temporary files for the shell's use. | |
1569c106 | 2325 | .TP |
726f6388 JA |
2326 | .B auto_resume |
2327 | This variable controls how the shell interacts with the user and | |
2328 | job control. If this variable is set, single word simple | |
2329 | commands without redirections are treated as candidates for resumption | |
2330 | of an existing stopped job. There is no ambiguity allowed; if there is | |
2331 | more than one job beginning with the string typed, the job most recently | |
2332 | accessed is selected. The | |
2333 | .I name | |
2334 | of a stopped job, in this context, is the command line used to | |
2335 | start it. | |
2336 | If set to the value | |
2337 | .IR exact , | |
2338 | the string supplied must match the name of a stopped job exactly; | |
2339 | if set to | |
2340 | .IR substring , | |
2341 | the string supplied needs to match a substring of the name of a | |
2342 | stopped job. The | |
2343 | .I substring | |
2344 | value provides functionality analogous to the | |
2345 | .B %? | |
ccc6cda3 | 2346 | job identifier (see |
726f6388 JA |
2347 | .SM |
2348 | .B JOB CONTROL | |
2349 | below). If set to any other value, the supplied string must | |
2350 | be a prefix of a stopped job's name; this provides functionality | |
22e63b05 | 2351 | analogous to the \fB%\fP\fIstring\fP job identifier. |
bb70624e | 2352 | .TP |
f73dda09 JA |
2353 | .B histchars |
2354 | The two or three characters which control history expansion | |
2355 | and tokenization (see | |
2356 | .SM | |
2357 | .B HISTORY EXPANSION | |
2358 | below). The first character is the \fIhistory expansion\fP character, | |
2359 | the character which signals the start of a history | |
2360 | expansion, normally `\fB!\fP'. | |
2361 | The second character is the \fIquick substitution\fP | |
2362 | character, which is used as shorthand for re-running the previous | |
2363 | command entered, substituting one string for another in the command. | |
2364 | The default is `\fB^\fP'. | |
2365 | The optional third character is the character | |
2366 | which indicates that the remainder of the line is a comment when found | |
2367 | as the first character of a word, normally `\fB#\fP'. The history | |
2368 | comment character causes history substitution to be skipped for the | |
2369 | remaining words on the line. It does not necessarily cause the shell | |
2370 | parser to treat the rest of the line as a comment. | |
726f6388 | 2371 | .PD |
ccc6cda3 JA |
2372 | .SS Arrays |
2373 | .B Bash | |
fdf670ea | 2374 | provides one-dimensional indexed and associative array variables. |
09767ff0 | 2375 | Any variable may be used as an indexed array; the |
ccc6cda3 | 2376 | .B declare |
fdf670ea CR |
2377 | builtin will explicitly declare an array. |
2378 | There is no maximum | |
ccc6cda3 | 2379 | limit on the size of an array, nor any requirement that members |
fdf670ea CR |
2380 | be indexed or assigned contiguously. |
2381 | Indexed arrays are referenced using integers (including arithmetic | |
09767ff0 CR |
2382 | expressions) and are zero-based; associative arrays are referenced |
2383 | using arbitrary strings. | |
ccc6cda3 | 2384 | .PP |
fdf670ea CR |
2385 | An indexed array is created automatically if any variable is assigned to |
2386 | using the syntax \fIname\fP[\fIsubscript\fP]=\fIvalue\fP. The | |
ccc6cda3 | 2387 | .I subscript |
67362c60 | 2388 | is treated as an arithmetic expression that must evaluate to a number. |
67362c60 | 2389 | To explicitly declare an indexed array, use |
ccc6cda3 JA |
2390 | .B declare \-a \fIname\fP |
2391 | (see | |
2392 | .SM | |
2393 | .B SHELL BUILTIN COMMANDS | |
2394 | below). | |
2395 | .B declare \-a \fIname\fP[\fIsubscript\fP] | |
09767ff0 CR |
2396 | is also accepted; the \fIsubscript\fP is ignored. |
2397 | .PP | |
2398 | Associative arrays are created using | |
2399 | .BR "declare \-A \fIname\fP" . | |
2400 | .PP | |
2401 | Attributes may be | |
ccc6cda3 JA |
2402 | specified for an array variable using the |
2403 | .B declare | |
2404 | and | |
2405 | .B readonly | |
2406 | builtins. Each attribute applies to all members of an array. | |
2407 | .PP | |
2408 | Arrays are assigned to using compound assignments of the form | |
2409 | \fIname\fP=\fB(\fPvalue\fI1\fP ... value\fIn\fP\fB)\fP, where each | |
09767ff0 | 2410 | \fIvalue\fP is of the form [\fIsubscript\fP]=\fIstring\fP. |
b28ff8c9 | 2411 | Indexed array assignments do not require anything but \fIstring\fP. |
09767ff0 CR |
2412 | When assigning to indexed arrays, if the optional brackets and subscript |
2413 | are supplied, that index is assigned to; | |
ccc6cda3 JA |
2414 | otherwise the index of the element assigned is the last index assigned |
2415 | to by the statement plus one. Indexing starts at zero. | |
fdf670ea CR |
2416 | .PP |
2417 | When assigning to an associative array, the subscript is required. | |
2418 | .PP | |
ccc6cda3 JA |
2419 | This syntax is also accepted by the |
2420 | .B declare | |
2421 | builtin. Individual array elements may be assigned to using the | |
2422 | \fIname\fP[\fIsubscript\fP]=\fIvalue\fP syntax introduced above. | |
2423 | .PP | |
2424 | Any element of an array may be referenced using | |
2425 | ${\fIname\fP[\fIsubscript\fP]}. The braces are required to avoid | |
2426 | conflicts with pathname expansion. If | |
2427 | \fIsubscript\fP is \fB@\fP or \fB*\fP, the word expands to | |
2428 | all members of \fIname\fP. These subscripts differ only when the | |
2429 | word appears within double quotes. If the word is double-quoted, | |
2430 | ${\fIname\fP[*]} expands to a single | |
2431 | word with the value of each array member separated by the first | |
2432 | character of the | |
2433 | .SM | |
2434 | .B IFS | |
2435 | special variable, and ${\fIname\fP[@]} expands each element of | |
2436 | \fIname\fP to a separate word. When there are no array members, | |
be7d8f2d CR |
2437 | ${\fIname\fP[@]} expands to nothing. |
2438 | If the double-quoted expansion occurs within a word, the expansion of | |
2439 | the first parameter is joined with the beginning part of the original | |
2440 | word, and the expansion of the last parameter is joined with the last | |
2441 | part of the original word. | |
2442 | This is analogous to the expansion | |
ccc6cda3 JA |
2443 | of the special parameters \fB*\fP and \fB@\fP (see |
2444 | .B Special Parameters | |
2445 | above). ${#\fIname\fP[\fIsubscript\fP]} expands to the length of | |
2446 | ${\fIname\fP[\fIsubscript\fP]}. If \fIsubscript\fP is \fB*\fP or | |
2447 | \fB@\fP, the expansion is the number of elements in the array. | |
2448 | Referencing an array variable without a subscript is equivalent to | |
fdf670ea | 2449 | referencing the array with a subscript of 0. |
d9e1f41e CR |
2450 | If the |
2451 | .I subscript | |
2452 | used to reference an element of an indexed array | |
2453 | evaluates to a number less than zero, it is used as | |
2454 | an offset from one greater than the array's maximum index (so a subcript | |
2455 | of -1 refers to the last element of the array). | |
ccc6cda3 | 2456 | .PP |
94a5513e CR |
2457 | An array variable is considered set if a subscript has been assigned a |
2458 | value. The null string is a valid value. | |
2459 | .PP | |
ccc6cda3 JA |
2460 | The |
2461 | .B unset | |
bb70624e | 2462 | builtin is used to destroy arrays. \fBunset\fP \fIname\fP[\fIsubscript\fP] |
ccc6cda3 | 2463 | destroys the array element at index \fIsubscript\fP. |
d0ca3503 CR |
2464 | Care must be taken to avoid unwanted side effects caused by pathname |
2465 | expansion. | |
ccc6cda3 JA |
2466 | \fBunset\fP \fIname\fP, where \fIname\fP is an array, or |
2467 | \fBunset\fP \fIname\fP[\fIsubscript\fP], where | |
2468 | \fIsubscript\fP is \fB*\fP or \fB@\fP, removes the entire array. | |
2469 | .PP | |
2470 | The | |
2471 | .BR declare , | |
2472 | .BR local , | |
2473 | and | |
2474 | .B readonly | |
2475 | builtins each accept a | |
2476 | .B \-a | |
fdf670ea CR |
2477 | option to specify an indexed array and a |
2478 | .B \-A | |
2479 | option to specify an associative array. | |
54a1fa7c CR |
2480 | If both options are supplied, |
2481 | .B \-A | |
2482 | takes precedence. | |
fdf670ea | 2483 | The |
ccc6cda3 JA |
2484 | .B read |
2485 | builtin accepts a | |
2486 | .B \-a | |
2487 | option to assign a list of words read from the standard input | |
2488 | to an array. The | |
2489 | .B set | |
2490 | and | |
2491 | .B declare | |
2492 | builtins display array values in a way that allows them to be | |
2493 | reused as assignments. | |
726f6388 JA |
2494 | .SH EXPANSION |
2495 | Expansion is performed on the command line after it has been split into | |
2496 | words. There are seven kinds of expansion performed: | |
2497 | .IR "brace expansion" , | |
2498 | .IR "tilde expansion" , | |
2499 | .IR "parameter and variable expansion" , | |
2500 | .IR "command substitution" , | |
2501 | .IR "arithmetic expansion" , | |
2502 | .IR "word splitting" , | |
2503 | and | |
2504 | .IR "pathname expansion" . | |
2505 | .PP | |
2506 | The order of expansions is: brace expansion, tilde expansion, | |
ccc6cda3 JA |
2507 | parameter, variable and arithmetic expansion and |
2508 | command substitution | |
2509 | (done in a left-to-right fashion), word splitting, and pathname | |
726f6388 JA |
2510 | expansion. |
2511 | .PP | |
2512 | On systems that can support it, there is an additional expansion | |
2513 | available: \fIprocess substitution\fP. | |
2514 | .PP | |
2515 | Only brace expansion, word splitting, and pathname expansion | |
2516 | can change the number of words of the expansion; other expansions | |
2517 | expand a single word to a single word. | |
ccc6cda3 | 2518 | The only exceptions to this are the expansions of |
cce855bc | 2519 | "\fB$@\fP" and "\fB${\fP\fIname\fP\fB[@]}\fP" |
ccc6cda3 | 2520 | as explained above (see |
726f6388 JA |
2521 | .SM |
2522 | .BR PARAMETERS ). | |
2523 | .SS Brace Expansion | |
2524 | .PP | |
2525 | .I "Brace expansion" | |
2526 | is a mechanism by which arbitrary strings | |
2527 | may be generated. This mechanism is similar to | |
2528 | \fIpathname expansion\fP, but the filenames generated | |
2529 | need not exist. Patterns to be brace expanded take | |
2530 | the form of an optional | |
2531 | .IR preamble , | |
d3a24ed2 CR |
2532 | followed by either a series of comma-separated strings or |
2533 | a sequence expression between a pair of braces, followed by | |
2534 | an optional | |
cce855bc | 2535 | .IR postscript . |
ccc6cda3 | 2536 | The preamble is prefixed to each string contained |
cce855bc | 2537 | within the braces, and the postscript is then appended |
726f6388 JA |
2538 | to each resulting string, expanding left to right. |
2539 | .PP | |
2540 | Brace expansions may be nested. The results of each expanded | |
2541 | string are not sorted; left to right order is preserved. | |
2542 | For example, a\fB{\fPd,c,b\fB}\fPe expands into `ade ace abe'. | |
2543 | .PP | |
8943768b | 2544 | A sequence expression takes the form |
36211029 | 2545 | \fB{\fP\fIx\fP\fB..\fP\fIy\fP\fB[..\fP\fIincr\fP\fB]}\fP, |
8943768b CR |
2546 | where \fIx\fP and \fIy\fP are either integers or single characters, |
2547 | and \fIincr\fP, an optional increment, is an integer. | |
d3a24ed2 CR |
2548 | When integers are supplied, the expression expands to each number between |
2549 | \fIx\fP and \fIy\fP, inclusive. | |
8943768b CR |
2550 | Supplied integers may be prefixed with \fI0\fP to force each term to have the |
2551 | same width. When either \fIx\fP or \fPy\fP begins with a zero, the shell | |
2552 | attempts to force all generated terms to contain the same number of digits, | |
2553 | zero-padding where necessary. | |
d3a24ed2 CR |
2554 | When characters are supplied, the expression expands to each character |
2555 | lexicographically between \fIx\fP and \fIy\fP, inclusive. Note that | |
2556 | both \fIx\fP and \fIy\fP must be of the same type. | |
8943768b CR |
2557 | When the increment is supplied, it is used as the difference between |
2558 | each term. The default increment is 1 or -1 as appropriate. | |
d3a24ed2 | 2559 | .PP |
726f6388 JA |
2560 | Brace expansion is performed before any other expansions, |
2561 | and any characters special to other expansions are preserved | |
2562 | in the result. It is strictly textual. | |
2563 | .B Bash | |
2564 | does not apply any syntactic interpretation to the context of the | |
2565 | expansion or the text between the braces. | |
2566 | .PP | |
2567 | A correctly-formed brace expansion must contain unquoted opening | |
d3a24ed2 CR |
2568 | and closing braces, and at least one unquoted comma or a valid |
2569 | sequence expression. | |
726f6388 | 2570 | Any incorrectly formed brace expansion is left unchanged. |
ccc6cda3 JA |
2571 | A \fB{\fP or \fB,\fP may be quoted with a backslash to prevent its |
2572 | being considered part of a brace expression. | |
bb70624e JA |
2573 | To avoid conflicts with parameter expansion, the string \fB${\fP |
2574 | is not considered eligible for brace expansion. | |
726f6388 JA |
2575 | .PP |
2576 | This construct is typically used as shorthand when the common | |
2577 | prefix of the strings to be generated is longer than in the | |
2578 | above example: | |
2579 | .RS | |
2580 | .PP | |
2581 | mkdir /usr/local/src/bash/{old,new,dist,bugs} | |
2582 | .RE | |
2583 | or | |
2584 | .RS | |
2585 | chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}} | |
2586 | .RE | |
2587 | .PP | |
2588 | Brace expansion introduces a slight incompatibility with | |
ccc6cda3 JA |
2589 | historical versions of |
2590 | .BR sh . | |
726f6388 JA |
2591 | .B sh |
2592 | does not treat opening or closing braces specially when they | |
2593 | appear as part of a word, and preserves them in the output. | |
2594 | .B Bash | |
2595 | removes braces from words as a consequence of brace | |
2596 | expansion. For example, a word entered to | |
2597 | .B sh | |
2598 | as \fIfile{1,2}\fP | |
2599 | appears identically in the output. The same word is | |
2600 | output as | |
2601 | .I file1 file2 | |
2602 | after expansion by | |
2603 | .BR bash . | |
2604 | If strict compatibility with | |
2605 | .B sh | |
2606 | is desired, start | |
2607 | .B bash | |
2608 | with the | |
ccc6cda3 JA |
2609 | .B +B |
2610 | option or disable brace expansion with the | |
2611 | .B +B | |
726f6388 JA |
2612 | option to the |
2613 | .B set | |
2614 | command (see | |
2615 | .SM | |
2616 | .B SHELL BUILTIN COMMANDS | |
2617 | below). | |
2618 | .SS Tilde Expansion | |
2619 | .PP | |
cce855bc JA |
2620 | If a word begins with an unquoted tilde character (`\fB~\fP'), all of |
2621 | the characters preceding the first unquoted slash (or all characters, | |
2622 | if there is no unquoted slash) are considered a \fItilde-prefix\fP. | |
2623 | If none of the characters in the tilde-prefix are quoted, the | |
2624 | characters in the tilde-prefix following the tilde are treated as a | |
2625 | possible \fIlogin name\fP. | |
2626 | If this login name is the null string, the tilde is replaced with the | |
2627 | value of the shell parameter | |
726f6388 JA |
2628 | .SM |
2629 | .BR HOME . | |
2630 | If | |
2631 | .SM | |
2632 | .B HOME | |
cce855bc JA |
2633 | is unset, the home directory of the user executing the shell is |
2634 | substituted instead. | |
2635 | Otherwise, the tilde-prefix is replaced with the home directory | |
2636 | associated with the specified login name. | |
726f6388 | 2637 | .PP |
cce855bc | 2638 | If the tilde-prefix is a `~+', the value of the shell variable |
726f6388 JA |
2639 | .SM |
2640 | .B PWD | |
cce855bc JA |
2641 | replaces the tilde-prefix. |
2642 | If the tilde-prefix is a `~\-', the value of the shell variable | |
2643 | .SM | |
2644 | .BR OLDPWD , | |
2645 | if it is set, is substituted. | |
2646 | If the characters following the tilde in the tilde-prefix consist | |
2647 | of a number \fIN\fP, optionally prefixed | |
2648 | by a `+' or a `\-', the tilde-prefix is replaced with the corresponding | |
2649 | element from the directory stack, as it would be displayed by the | |
2650 | .B dirs | |
2651 | builtin invoked with the tilde-prefix as an argument. | |
2652 | If the characters following the tilde in the tilde-prefix consist of a | |
2653 | number without a leading `+' or `\-', `+' is assumed. | |
2654 | .PP | |
2655 | If the login name is invalid, or the tilde expansion fails, the word | |
2656 | is unchanged. | |
726f6388 | 2657 | .PP |
cce855bc JA |
2658 | Each variable assignment is checked for unquoted tilde-prefixes immediately |
2659 | following a | |
726f6388 | 2660 | .B : |
43df7bbb | 2661 | or the first |
726f6388 | 2662 | .BR = . |
cce855bc | 2663 | In these cases, tilde expansion is also performed. |
b28ff8c9 | 2664 | Consequently, one may use filenames with tildes in assignments to |
726f6388 JA |
2665 | .SM |
2666 | .BR PATH , | |
2667 | .SM | |
2668 | .BR MAILPATH , | |
2669 | and | |
2670 | .SM | |
2671 | .BR CDPATH , | |
2672 | and the shell assigns the expanded value. | |
2673 | .SS Parameter Expansion | |
2674 | .PP | |
2675 | The `\fB$\fP' character introduces parameter expansion, | |
2676 | command substitution, or arithmetic expansion. The parameter name | |
2677 | or symbol to be expanded may be enclosed in braces, which | |
2678 | are optional but serve to protect the variable to be expanded from | |
2679 | characters immediately following it which could be | |
2680 | interpreted as part of the name. | |
2681 | .PP | |
cce855bc JA |
2682 | When braces are used, the matching ending brace is the first `\fB}\fP' |
2683 | not escaped by a backslash or within a quoted string, and not within an | |
f75912ae | 2684 | embedded arithmetic expansion, command substitution, or parameter |
cce855bc JA |
2685 | expansion. |
2686 | .PP | |
726f6388 JA |
2687 | .PD 0 |
2688 | .TP | |
2689 | ${\fIparameter\fP} | |
2690 | The value of \fIparameter\fP is substituted. The braces are required | |
2691 | when | |
2692 | .I parameter | |
2693 | is a positional parameter with more than one digit, | |
2694 | or when | |
2695 | .I parameter | |
2696 | is followed by a character which is not to be | |
2697 | interpreted as part of its name. | |
2698 | .PD | |
2699 | .PP | |
08e72d7a | 2700 | If the first character of \fIparameter\fP is an exclamation point (\fB!\fP), |
ccc6cda3 JA |
2701 | a level of variable indirection is introduced. |
2702 | \fBBash\fP uses the value of the variable formed from the rest of | |
2703 | \fIparameter\fP as the name of the variable; this variable is then | |
bb70624e | 2704 | expanded and that value is used in the rest of the substitution, rather |
ccc6cda3 JA |
2705 | than the value of \fIparameter\fP itself. |
2706 | This is known as \fIindirect expansion\fP. | |
54a1fa7c | 2707 | The exceptions to this are the expansions of ${\fB!\fP\fIprefix\fP\fB*\fP} and |
d3a24ed2 CR |
2708 | ${\fB!\fP\fIname\fP[\fI@\fP]} described below. |
2709 | The exclamation point must immediately follow the left brace in order to | |
2710 | introduce indirection. | |
ccc6cda3 | 2711 | .PP |
726f6388 JA |
2712 | In each of the cases below, \fIword\fP is subject to tilde expansion, |
2713 | parameter expansion, command substitution, and arithmetic expansion. | |
e141c35a CR |
2714 | .PP |
2715 | When not performing substring expansion, using the forms documented below, | |
2716 | \fBbash\fP tests for a parameter that is unset or null. Omitting the colon | |
2717 | results in a test only for a parameter that is unset. | |
726f6388 JA |
2718 | .PP |
2719 | .PD 0 | |
2720 | .TP | |
2721 | ${\fIparameter\fP\fB:\-\fP\fIword\fP} | |
2722 | \fBUse Default Values\fP. If | |
2723 | .I parameter | |
2724 | is unset or null, the expansion of | |
2725 | .I word | |
2726 | is substituted. Otherwise, the value of | |
2727 | .I parameter | |
2728 | is substituted. | |
2729 | .TP | |
2730 | ${\fIparameter\fP\fB:=\fP\fIword\fP} | |
2731 | \fBAssign Default Values\fP. | |
2732 | If | |
2733 | .I parameter | |
2734 | is unset or null, the expansion of | |
2735 | .I word | |
2736 | is assigned to | |
2737 | .IR parameter . | |
2738 | The value of | |
2739 | .I parameter | |
2740 | is then substituted. Positional parameters and special parameters may | |
2741 | not be assigned to in this way. | |
2742 | .TP | |
2743 | ${\fIparameter\fP\fB:?\fP\fIword\fP} | |
2744 | \fBDisplay Error if Null or Unset\fP. | |
2745 | If | |
2746 | .I parameter | |
2747 | is null or unset, the expansion of \fIword\fP (or a message to that effect | |
2748 | if | |
2749 | .I word | |
2750 | is not present) is written to the standard error and the shell, if it | |
2751 | is not interactive, exits. Otherwise, the value of \fIparameter\fP is | |
2752 | substituted. | |
2753 | .TP | |
2754 | ${\fIparameter\fP\fB:+\fP\fIword\fP} | |
2755 | \fBUse Alternate Value\fP. | |
2756 | If | |
2757 | .I parameter | |
2758 | is null or unset, nothing is substituted, otherwise the expansion of | |
2759 | .I word | |
2760 | is substituted. | |
2761 | .TP | |
ccc6cda3 | 2762 | ${\fIparameter\fP\fB:\fP\fIoffset\fP} |
7117c2d2 | 2763 | .PD 0 |
ccc6cda3 JA |
2764 | .TP |
2765 | ${\fIparameter\fP\fB:\fP\fIoffset\fP\fB:\fP\fIlength\fP} | |
2766 | .PD | |
dc60d4e0 | 2767 | \fBSubstring Expansion\fP. |
bb70624e JA |
2768 | Expands to up to \fIlength\fP characters of \fIparameter\fP |
2769 | starting at the character specified by \fIoffset\fP. | |
ccc6cda3 | 2770 | If \fIlength\fP is omitted, expands to the substring of |
bb70624e | 2771 | \fIparameter\fP starting at the character specified by \fIoffset\fP. |
ccc6cda3 JA |
2772 | \fIlength\fP and \fIoffset\fP are arithmetic expressions (see |
2773 | .SM | |
2774 | .B | |
2775 | ARITHMETIC EVALUATION | |
2776 | below). | |
ccc6cda3 JA |
2777 | If \fIoffset\fP evaluates to a number less than zero, the value |
2778 | is used as an offset from the end of the value of \fIparameter\fP. | |
67362c60 CR |
2779 | If \fIlength\fP evaluates to a number less than zero, and \fIparameter\fP |
2780 | is not \fB@\fP and not an indexed or associative array, it is interpreted | |
2781 | as an offset from the end of the value of \fIparameter\fP rather than | |
2782 | a number of characters, and the expansion is the characters between the | |
2783 | two offsets. | |
ccc6cda3 JA |
2784 | If \fIparameter\fP is \fB@\fP, the result is \fIlength\fP positional |
2785 | parameters beginning at \fIoffset\fP. | |
09767ff0 | 2786 | If \fIparameter\fP is an indexed array name subscripted by @ or *, |
ccc6cda3 JA |
2787 | the result is the \fIlength\fP |
2788 | members of the array beginning with ${\fIparameter\fP[\fIoffset\fP]}. | |
ec2199bd CR |
2789 | A negative \fIoffset\fP is taken relative to one greater than the maximum |
2790 | index of the specified array. | |
09767ff0 CR |
2791 | Substring expansion applied to an associative array produces undefined |
2792 | results. | |
ec2199bd CR |
2793 | Note that a negative offset must be separated from the colon by at least |
2794 | one space to avoid being confused with the :- expansion. | |
cce855bc | 2795 | Substring indexing is zero-based unless the positional parameters |
d3ad40de CR |
2796 | are used, in which case the indexing starts at 1 by default. |
2797 | If \fIoffset\fP is 0, and the positional parameters are used, \fB$0\fP is | |
2798 | prefixed to the list. | |
ccc6cda3 | 2799 | .TP |
bb70624e | 2800 | ${\fB!\fP\fIprefix\fP\fB*\fP} |
d3a24ed2 CR |
2801 | .PD 0 |
2802 | .TP | |
2803 | ${\fB!\fP\fIprefix\fP\fB@\fP} | |
2804 | .PD | |
dc60d4e0 | 2805 | \fBNames matching prefix\fP. |
bb70624e JA |
2806 | Expands to the names of variables whose names begin with \fIprefix\fP, |
2807 | separated by the first character of the | |
2808 | .SM | |
2809 | .B IFS | |
2810 | special variable. | |
d3ad40de CR |
2811 | When \fI@\fP is used and the expansion appears within double quotes, each |
2812 | variable name expands to a separate word. | |
bb70624e | 2813 | .TP |
d3a24ed2 CR |
2814 | ${\fB!\fP\fIname\fP[\fI@\fP]} |
2815 | .PD 0 | |
2816 | .TP | |
2817 | ${\fB!\fP\fIname\fP[\fI*\fP]} | |
2818 | .PD | |
dc60d4e0 | 2819 | \fBList of array keys\fP. |
d3a24ed2 CR |
2820 | If \fIname\fP is an array variable, expands to the list of array indices |
2821 | (keys) assigned in \fIname\fP. | |
2822 | If \fIname\fP is not an array, expands to 0 if \fIname\fP is set and null | |
2823 | otherwise. | |
2824 | When \fI@\fP is used and the expansion appears within double quotes, each | |
2825 | key expands to a separate word. | |
2826 | .TP | |
726f6388 | 2827 | ${\fB#\fP\fIparameter\fP} |
dc60d4e0 | 2828 | \fBParameter length\fP. |
726f6388 | 2829 | The length in characters of the value of \fIparameter\fP is substituted. |
ccc6cda3 JA |
2830 | If |
2831 | .I parameter | |
2832 | is | |
726f6388 JA |
2833 | .B * |
2834 | or | |
2835 | .BR @ , | |
cce855bc | 2836 | the value substituted is the number of positional parameters. |
ccc6cda3 JA |
2837 | If |
2838 | .I parameter | |
2839 | is an array name subscripted by | |
726f6388 | 2840 | .B * |
ccc6cda3 JA |
2841 | or |
2842 | .BR @ , | |
cce855bc | 2843 | the value substituted is the number of elements in the array. |
726f6388 | 2844 | .TP |
726f6388 | 2845 | ${\fIparameter\fP\fB#\fP\fIword\fP} |
7117c2d2 | 2846 | .PD 0 |
726f6388 JA |
2847 | .TP |
2848 | ${\fIparameter\fP\fB##\fP\fIword\fP} | |
2849 | .PD | |
dc60d4e0 | 2850 | \fBRemove matching prefix pattern\fP. |
726f6388 JA |
2851 | The |
2852 | .I word | |
2853 | is expanded to produce a pattern just as in pathname | |
2854 | expansion. If the pattern matches the beginning of | |
2855 | the value of | |
2856 | .IR parameter , | |
cce855bc | 2857 | then the result of the expansion is the expanded value of |
726f6388 | 2858 | .I parameter |
ccc6cda3 JA |
2859 | with the shortest matching pattern (the ``\fB#\fP'' case) or the |
2860 | longest matching pattern (the ``\fB##\fP'' case) deleted. | |
2861 | If | |
2862 | .I parameter | |
2863 | is | |
2864 | .B @ | |
2865 | or | |
2866 | .BR * , | |
2867 | the pattern removal operation is applied to each positional | |
2868 | parameter in turn, and the expansion is the resultant list. | |
2869 | If | |
2870 | .I parameter | |
2871 | is an array variable subscripted with | |
2872 | .B @ | |
2873 | or | |
2874 | .BR * , | |
2875 | the pattern removal operation is applied to each member of the | |
2876 | array in turn, and the expansion is the resultant list. | |
726f6388 | 2877 | .TP |
726f6388 | 2878 | ${\fIparameter\fP\fB%\fP\fIword\fP} |
7117c2d2 | 2879 | .PD 0 |
726f6388 JA |
2880 | .TP |
2881 | ${\fIparameter\fP\fB%%\fP\fIword\fP} | |
2882 | .PD | |
dc60d4e0 | 2883 | \fBRemove matching suffix pattern\fP. |
726f6388 | 2884 | The \fIword\fP is expanded to produce a pattern just as in |
ccc6cda3 | 2885 | pathname expansion. |
cce855bc | 2886 | If the pattern matches a trailing portion of the expanded value of |
726f6388 | 2887 | .IR parameter , |
cce855bc | 2888 | then the result of the expansion is the expanded value of |
726f6388 | 2889 | .I parameter |
ccc6cda3 JA |
2890 | with the shortest matching pattern (the ``\fB%\fP'' case) or the |
2891 | longest matching pattern (the ``\fB%%\fP'' case) deleted. | |
2892 | If | |
2893 | .I parameter | |
2894 | is | |
2895 | .B @ | |
2896 | or | |
2897 | .BR * , | |
2898 | the pattern removal operation is applied to each positional | |
2899 | parameter in turn, and the expansion is the resultant list. | |
2900 | If | |
2901 | .I parameter | |
2902 | is an array variable subscripted with | |
2903 | .B @ | |
2904 | or | |
2905 | .BR * , | |
2906 | the pattern removal operation is applied to each member of the | |
2907 | array in turn, and the expansion is the resultant list. | |
2908 | .TP | |
ccc6cda3 | 2909 | ${\fIparameter\fP\fB/\fP\fIpattern\fP\fB/\fP\fIstring\fP} |
dc60d4e0 | 2910 | \fBPattern substitution\fP. |
ccc6cda3 JA |
2911 | The \fIpattern\fP is expanded to produce a pattern just as in |
2912 | pathname expansion. | |
2913 | \fIParameter\fP is expanded and the longest match of \fIpattern\fP | |
2914 | against its value is replaced with \fIstring\fP. | |
e6598ba4 | 2915 | If \fIpattern\fP begins with \fB/\fP, all matches of \fIpattern\fP are |
dc8fbaf9 | 2916 | replaced with \fIstring\fP. Normally only the first match is replaced. |
ccc6cda3 | 2917 | If \fIpattern\fP begins with \fB#\fP, it must match at the beginning |
b72432fd | 2918 | of the expanded value of \fIparameter\fP. |
ccc6cda3 | 2919 | If \fIpattern\fP begins with \fB%\fP, it must match at the end |
b72432fd | 2920 | of the expanded value of \fIparameter\fP. |
ccc6cda3 JA |
2921 | If \fIstring\fP is null, matches of \fIpattern\fP are deleted |
2922 | and the \fB/\fP following \fIpattern\fP may be omitted. | |
2923 | If | |
2924 | .I parameter | |
2925 | is | |
2926 | .B @ | |
2927 | or | |
2928 | .BR * , | |
2929 | the substitution operation is applied to each positional | |
2930 | parameter in turn, and the expansion is the resultant list. | |
2931 | If | |
2932 | .I parameter | |
2933 | is an array variable subscripted with | |
2934 | .B @ | |
2935 | or | |
2936 | .BR * , | |
2937 | the substitution operation is applied to each member of the | |
2938 | array in turn, and the expansion is the resultant list. | |
09767ff0 CR |
2939 | .TP |
2940 | ${\fIparameter\fP\fB^\fP\fIpattern\fP} | |
2941 | .PD 0 | |
2942 | .TP | |
2943 | ${\fIparameter\fP\fB^^\fP\fIpattern\fP} | |
2944 | .TP | |
2945 | ${\fIparameter\fP\fB,\fP\fIpattern\fP} | |
2946 | .TP | |
2947 | ${\fIparameter\fP\fB,,\fP\fIpattern\fP} | |
2948 | .PD | |
dc60d4e0 | 2949 | \fBCase modification\fP. |
09767ff0 CR |
2950 | This expansion modifies the case of alphabetic characters in \fIparameter\fP. |
2951 | The \fIpattern\fP is expanded to produce a pattern just as in | |
2952 | pathname expansion. | |
45c0f7f8 CR |
2953 | Each character in the expanded value of \fIparameter\fP is tested against |
2954 | \fIpattern\fP, and, if it matches the pattern, its case is converted. | |
2955 | The pattern should not attempt to match more than one character. | |
09767ff0 CR |
2956 | The \fB^\fP operator converts lowercase letters matching \fIpattern\fP |
2957 | to uppercase; the \fB,\fP operator converts matching uppercase letters | |
2958 | to lowercase. | |
2959 | The \fB^^\fP and \fB,,\fP expansions convert each matched character in the | |
2960 | expanded value; the \fB^\fP and \fB,\fP expansions match and convert only | |
5cdaaf76 | 2961 | the first character in the expanded value. |
09767ff0 CR |
2962 | If \fIpattern\fP is omitted, it is treated like a \fB?\fP, which matches |
2963 | every character. | |
2964 | If | |
2965 | .I parameter | |
2966 | is | |
2967 | .B @ | |
2968 | or | |
2969 | .BR * , | |
2970 | the case modification operation is applied to each positional | |
2971 | parameter in turn, and the expansion is the resultant list. | |
2972 | If | |
2973 | .I parameter | |
2974 | is an array variable subscripted with | |
2975 | .B @ | |
2976 | or | |
2977 | .BR * , | |
2978 | the case modification operation is applied to each member of the | |
2979 | array in turn, and the expansion is the resultant list. | |
726f6388 JA |
2980 | .SS Command Substitution |
2981 | .PP | |
cce855bc | 2982 | \fICommand substitution\fP allows the output of a command to replace |
726f6388 | 2983 | the command name. There are two forms: |
726f6388 JA |
2984 | .RS |
2985 | .PP | |
2986 | \fB$(\fP\fIcommand\fP\|\fB)\fP | |
2987 | .RE | |
2988 | or | |
2989 | .RS | |
3d4e09aa | 2990 | \fB\`\fP\fIcommand\fP\fB\`\fP |
726f6388 JA |
2991 | .RE |
2992 | .PP | |
ccc6cda3 | 2993 | .B Bash |
726f6388 JA |
2994 | performs the expansion by executing \fIcommand\fP and |
2995 | replacing the command substitution with the standard output of the | |
2996 | command, with any trailing newlines deleted. | |
cce855bc JA |
2997 | Embedded newlines are not deleted, but they may be removed during |
2998 | word splitting. | |
2999 | The command substitution \fB$(cat \fIfile\fP)\fR can be replaced by | |
3000 | the equivalent but faster \fB$(< \fIfile\fP)\fR. | |
726f6388 | 3001 | .PP |
ccc6cda3 | 3002 | When the old-style backquote form of substitution is used, |
726f6388 JA |
3003 | backslash retains its literal meaning except when followed by |
3004 | .BR $ , | |
3d4e09aa | 3005 | .BR \` , |
726f6388 JA |
3006 | or |
3007 | .BR \e . | |
cce855bc JA |
3008 | The first backquote not preceded by a backslash terminates the |
3009 | command substitution. | |
726f6388 JA |
3010 | When using the $(\^\fIcommand\fP\|) form, all characters between the |
3011 | parentheses make up the command; none are treated specially. | |
3012 | .PP | |
cce855bc | 3013 | Command substitutions may be nested. To nest when using the backquoted form, |
726f6388 JA |
3014 | escape the inner backquotes with backslashes. |
3015 | .PP | |
3016 | If the substitution appears within double quotes, word splitting and | |
3017 | pathname expansion are not performed on the results. | |
3018 | .SS Arithmetic Expansion | |
3019 | .PP | |
3020 | Arithmetic expansion allows the evaluation of an arithmetic expression | |
ccc6cda3 | 3021 | and the substitution of the result. The format for arithmetic expansion is: |
726f6388 JA |
3022 | .RS |
3023 | .PP | |
726f6388 JA |
3024 | \fB$((\fP\fIexpression\fP\fB))\fP |
3025 | .RE | |
3026 | .PP | |
3027 | The | |
3028 | .I expression | |
3029 | is treated as if it were within double quotes, but a double quote | |
ccc6cda3 JA |
3030 | inside the parentheses is not treated specially. |
3031 | All tokens in the expression undergo parameter expansion, string | |
3032 | expansion, command substitution, and quote removal. | |
d3a24ed2 | 3033 | Arithmetic expansions may be nested. |
726f6388 JA |
3034 | .PP |
3035 | The evaluation is performed according to the rules listed below under | |
3036 | .SM | |
3037 | .BR "ARITHMETIC EVALUATION" . | |
3038 | If | |
3039 | .I expression | |
3040 | is invalid, | |
3041 | .B bash | |
3042 | prints a message indicating failure and no substitution occurs. | |
3043 | .SS Process Substitution | |
3044 | .PP | |
3045 | \fIProcess substitution\fP is supported on systems that support named | |
3046 | pipes (\fIFIFOs\fP) or the \fB/dev/fd\fP method of naming open files. | |
3047 | It takes the form of | |
3048 | \fB<(\fP\fIlist\^\fP\fB)\fP | |
3049 | or | |
3050 | \fB>(\fP\fIlist\^\fP\fB)\fP. | |
3051 | The process \fIlist\fP is run with its input or output connected to a | |
3052 | \fIFIFO\fP or some file in \fB/dev/fd\fP. The name of this file is | |
3053 | passed as an argument to the current command as the result of the | |
3054 | expansion. If the \fB>(\fP\fIlist\^\fP\fB)\fP form is used, writing to | |
3055 | the file will provide input for \fIlist\fP. If the | |
3056 | \fB<(\fP\fIlist\^\fP\fB)\fP form is used, the file passed as an | |
3057 | argument should be read to obtain the output of \fIlist\fP. | |
3058 | .PP | |
bb70624e | 3059 | When available, process substitution is performed |
ccc6cda3 JA |
3060 | simultaneously with parameter and variable expansion, |
3061 | command substitution, | |
3062 | and arithmetic expansion. | |
726f6388 JA |
3063 | .SS Word Splitting |
3064 | .PP | |
3065 | The shell scans the results of | |
3066 | parameter expansion, | |
3067 | command substitution, | |
3068 | and | |
3069 | arithmetic expansion | |
3070 | that did not occur within double quotes for | |
3071 | .IR "word splitting" . | |
3072 | .PP | |
3073 | The shell treats each character of | |
3074 | .SM | |
3075 | .B IFS | |
3076 | as a delimiter, and splits the results of the other | |
ccc6cda3 | 3077 | expansions into words on these characters. If |
726f6388 JA |
3078 | .SM |
3079 | .B IFS | |
ccc6cda3 JA |
3080 | is unset, or its |
3081 | value is exactly | |
726f6388 JA |
3082 | .BR <space><tab><newline> , |
3083 | the default, then | |
d3ad40de CR |
3084 | sequences of |
3085 | .BR <space> , | |
3086 | .BR <tab> , | |
3087 | and | |
3088 | .B <newline> | |
3089 | at the beginning and end of the results of the previous | |
3090 | expansions are ignored, and | |
726f6388 JA |
3091 | any sequence of |
3092 | .SM | |
3093 | .B IFS | |
d3ad40de CR |
3094 | characters not at the beginning or end serves to delimit words. |
3095 | If | |
726f6388 JA |
3096 | .SM |
3097 | .B IFS | |
3098 | has a value other than the default, then sequences of | |
3099 | the whitespace characters | |
3100 | .B space | |
3101 | and | |
3102 | .B tab | |
3103 | are ignored at the beginning and end of the | |
3104 | word, as long as the whitespace character is in the | |
3105 | value of | |
3106 | .SM | |
3107 | .BR IFS | |
3108 | (an | |
3109 | .SM | |
3110 | .B IFS | |
3111 | whitespace character). | |
3112 | Any character in | |
3113 | .SM | |
3114 | .B IFS | |
3115 | that is not | |
3116 | .SM | |
3117 | .B IFS | |
3118 | whitespace, along with any adjacent | |
3119 | .SM | |
3120 | .B IFS | |
3121 | whitespace characters, delimits a field. | |
3122 | A sequence of | |
3123 | .SM | |
3124 | .B IFS | |
3125 | whitespace characters is also treated as a delimiter. | |
3126 | If the value of | |
3127 | .SM | |
3128 | .B IFS | |
3129 | is null, no word splitting occurs. | |
726f6388 | 3130 | .PP |
20587658 | 3131 | Explicit null arguments (\^\f3"\^"\fP or \^\f3\(aq\^\(aq\fP\^) are retained. |
ccc6cda3 | 3132 | Unquoted implicit null arguments, resulting from the expansion of |
bb70624e | 3133 | parameters that have no values, are removed. |
ccc6cda3 JA |
3134 | If a parameter with no value is expanded within double quotes, a |
3135 | null argument results and is retained. | |
726f6388 JA |
3136 | .PP |
3137 | Note that if no expansion occurs, no splitting | |
3138 | is performed. | |
3139 | .SS Pathname Expansion | |
3140 | .PP | |
3141 | After word splitting, | |
3142 | unless the | |
3143 | .B \-f | |
3144 | option has been set, | |
3145 | .B bash | |
ccc6cda3 | 3146 | scans each word for the characters |
726f6388 JA |
3147 | .BR * , |
3148 | .BR ? , | |
3149 | and | |
3150 | .BR [ . | |
3151 | If one of these characters appears, then the word is | |
3152 | regarded as a | |
3153 | .IR pattern , | |
3154 | and replaced with an alphabetically sorted list of | |
b28ff8c9 | 3155 | filenames matching the pattern |
bfd181e7 CR |
3156 | (see |
3157 | .SM | |
3158 | .B "Pattern Matching" | |
3159 | below). | |
b28ff8c9 | 3160 | If no matching filenames are found, |
ccc6cda3 JA |
3161 | and the shell option |
3162 | .B nullglob | |
57a3f689 | 3163 | is not enabled, the word is left unchanged. |
cce855bc JA |
3164 | If the |
3165 | .B nullglob | |
3166 | option is set, and no matches are found, | |
726f6388 | 3167 | the word is removed. |
d3a24ed2 CR |
3168 | If the |
3169 | .B failglob | |
3170 | shell option is set, and no matches are found, an error message | |
3171 | is printed and the command is not executed. | |
cce855bc JA |
3172 | If the shell option |
3173 | .B nocaseglob | |
3174 | is enabled, the match is performed without regard to the case | |
3175 | of alphabetic characters. | |
ccc6cda3 | 3176 | When a pattern is used for pathname expansion, |
726f6388 JA |
3177 | the character |
3178 | .B ``.'' | |
3179 | at the start of a name or immediately following a slash | |
ccc6cda3 JA |
3180 | must be matched explicitly, unless the shell option |
3181 | .B dotglob | |
3182 | is set. | |
cce855bc JA |
3183 | When matching a pathname, the slash character must always be |
3184 | matched explicitly. | |
ccc6cda3 | 3185 | In other cases, the |
726f6388 JA |
3186 | .B ``.'' |
3187 | character is not treated specially. | |
ccc6cda3 JA |
3188 | See the description of |
3189 | .B shopt | |
3190 | below under | |
3191 | .SM | |
3192 | .B SHELL BUILTIN COMMANDS | |
3193 | for a description of the | |
cce855bc JA |
3194 | .BR nocaseglob , |
3195 | .BR nullglob , | |
d3a24ed2 | 3196 | .BR failglob , |
ccc6cda3 JA |
3197 | and |
3198 | .B dotglob | |
3199 | shell options. | |
3200 | .PP | |
3201 | The | |
3202 | .SM | |
3203 | .B GLOBIGNORE | |
b28ff8c9 | 3204 | shell variable may be used to restrict the set of filenames matching a |
ccc6cda3 JA |
3205 | .IR pattern . |
3206 | If | |
3207 | .SM | |
3208 | .B GLOBIGNORE | |
b28ff8c9 | 3209 | is set, each matching filename that also matches one of the patterns in |
ccc6cda3 JA |
3210 | .SM |
3211 | .B GLOBIGNORE | |
3212 | is removed from the list of matches. | |
b28ff8c9 | 3213 | The filenames |
ccc6cda3 JA |
3214 | .B ``.'' |
3215 | and | |
3216 | .B ``..'' | |
d3a24ed2 | 3217 | are always ignored when |
ccc6cda3 JA |
3218 | .SM |
3219 | .B GLOBIGNORE | |
d3a24ed2 | 3220 | is set and not null. However, setting |
ccc6cda3 JA |
3221 | .SM |
3222 | .B GLOBIGNORE | |
d3a24ed2 | 3223 | to a non-null value has the effect of enabling the |
ccc6cda3 | 3224 | .B dotglob |
b28ff8c9 | 3225 | shell option, so all other filenames beginning with a |
ccc6cda3 JA |
3226 | .B ``.'' |
3227 | will match. | |
b28ff8c9 | 3228 | To get the old behavior of ignoring filenames beginning with a |
ccc6cda3 JA |
3229 | .BR ``.'' , |
3230 | make | |
3231 | .B ``.*'' | |
3232 | one of the patterns in | |
3233 | .SM | |
3234 | .BR GLOBIGNORE . | |
3235 | The | |
3236 | .B dotglob | |
3237 | option is disabled when | |
3238 | .SM | |
3239 | .B GLOBIGNORE | |
3240 | is unset. | |
726f6388 | 3241 | .PP |
cce855bc JA |
3242 | \fBPattern Matching\fP |
3243 | .PP | |
3244 | Any character that appears in a pattern, other than the special pattern | |
3245 | characters described below, matches itself. The NUL character may not | |
d3a24ed2 CR |
3246 | occur in a pattern. A backslash escapes the following character; the |
3247 | escaping backslash is discarded when matching. | |
3248 | The special pattern characters must be quoted if | |
cce855bc JA |
3249 | they are to be matched literally. |
3250 | .PP | |
726f6388 JA |
3251 | The special pattern characters have the following meanings: |
3252 | .PP | |
3253 | .PD 0 | |
89c77bc7 | 3254 | .RS |
726f6388 JA |
3255 | .TP |
3256 | .B * | |
3257 | Matches any string, including the null string. | |
4ac1ff98 | 3258 | When the \fBglobstar\fP shell option is enabled, and \fB*\fP is used in |
d0ca3503 | 3259 | a pathname expansion context, two adjacent \fB*\fPs used as a single |
4ac1ff98 CR |
3260 | pattern will match all files and zero or more directories and |
3261 | subdirectories. | |
3262 | If followed by a \fB/\fP, two adjacent \fB*\fPs will match only directories | |
3263 | and subdirectories. | |
726f6388 JA |
3264 | .TP |
3265 | .B ? | |
3266 | Matches any single character. | |
3267 | .TP | |
3268 | .B [...] | |
3269 | Matches any one of the enclosed characters. A pair of characters | |
28ef6c31 JA |
3270 | separated by a hyphen denotes a |
3271 | \fIrange expression\fP; | |
3272 | any character that sorts between those two characters, inclusive, | |
3273 | using the current locale's collating sequence and character set, | |
726f6388 JA |
3274 | is matched. If the first character following the |
3275 | .B [ | |
3276 | is a | |
3277 | .B ! | |
3278 | or a | |
3279 | .B ^ | |
ccc6cda3 | 3280 | then any character not enclosed is matched. |
28ef6c31 | 3281 | The sorting order of characters in range expressions is determined by |
3443670e | 3282 | the current locale and the values of the |
984a1947 CR |
3283 | .SM |
3284 | .B LC_COLLATE | |
3443670e CR |
3285 | or |
3286 | .SM | |
3287 | .B LC_ALL | |
3288 | shell variables, if set. | |
3289 | To obtain the traditional interpretation of range expressions, where | |
3290 | .B [a\-d] | |
3291 | is equivalent to | |
3292 | .BR [abcd] , | |
3293 | set value of the | |
3294 | .B LC_ALL | |
3295 | shell variable to | |
74d0116b CR |
3296 | .BR C , |
3297 | or enable the | |
3298 | .B globasciiranges | |
3299 | shell option. | |
ccc6cda3 | 3300 | A |
726f6388 | 3301 | .B \- |
726f6388 JA |
3302 | may be matched by including it as the first or last character |
3303 | in the set. | |
ccc6cda3 JA |
3304 | A |
3305 | .B ] | |
3306 | may be matched by including it as the first character | |
3307 | in the set. | |
cce855bc JA |
3308 | .br |
3309 | .if t .sp 0.5 | |
3310 | .if n .sp 1 | |
3311 | Within | |
3312 | .B [ | |
3313 | and | |
3314 | .BR ] , | |
3315 | \fIcharacter classes\fP can be specified using the syntax | |
3316 | \fB[:\fP\fIclass\fP\fB:]\fP, where \fIclass\fP is one of the | |
ac18b312 | 3317 | following classes defined in the POSIX standard: |
cce855bc JA |
3318 | .PP |
3319 | .RS | |
3320 | .B | |
7117c2d2 JA |
3321 | .if n alnum alpha ascii blank cntrl digit graph lower print punct space upper word xdigit |
3322 | .if t alnum alpha ascii blank cntrl digit graph lower print punct space upper word xdigit | |
cce855bc JA |
3323 | .br |
3324 | A character class matches any character belonging to that class. | |
7117c2d2 | 3325 | The \fBword\fP character class matches letters, digits, and the character _. |
cce855bc JA |
3326 | .br |
3327 | .if t .sp 0.5 | |
3328 | .if n .sp 1 | |
3329 | Within | |
3330 | .B [ | |
3331 | and | |
3332 | .BR ] , | |
3333 | an \fIequivalence class\fP can be specified using the syntax | |
3334 | \fB[=\fP\fIc\fP\fB=]\fP, which matches all characters with the | |
3335 | same collation weight (as defined by the current locale) as | |
3336 | the character \fIc\fP. | |
3337 | .br | |
3338 | .if t .sp 0.5 | |
3339 | .if n .sp 1 | |
3340 | Within | |
3341 | .B [ | |
3342 | and | |
3343 | .BR ] , | |
3344 | the syntax \fB[.\fP\fIsymbol\fP\fB.]\fP matches the collating symbol | |
3345 | \fIsymbol\fP. | |
3346 | .RE | |
89c77bc7 | 3347 | .RE |
cce855bc JA |
3348 | .PD |
3349 | .PP | |
3350 | If the \fBextglob\fP shell option is enabled using the \fBshopt\fP | |
3351 | builtin, several extended pattern matching operators are recognized. | |
bb70624e | 3352 | In the following description, a \fIpattern-list\fP is a list of one |
cce855bc JA |
3353 | or more patterns separated by a \fB|\fP. |
3354 | Composite patterns may be formed using one or more of the following | |
3355 | sub-patterns: | |
3356 | .sp 1 | |
3357 | .PD 0 | |
3358 | .RS | |
3359 | .TP | |
3360 | \fB?(\fP\^\fIpattern-list\^\fP\fB)\fP | |
3361 | Matches zero or one occurrence of the given patterns | |
3362 | .TP | |
3363 | \fB*(\fP\^\fIpattern-list\^\fP\fB)\fP | |
3364 | Matches zero or more occurrences of the given patterns | |
3365 | .TP | |
3366 | \fB+(\fP\^\fIpattern-list\^\fP\fB)\fP | |
3367 | Matches one or more occurrences of the given patterns | |
3368 | .TP | |
3369 | \fB@(\fP\^\fIpattern-list\^\fP\fB)\fP | |
43df7bbb | 3370 | Matches one of the given patterns |
cce855bc JA |
3371 | .TP |
3372 | \fB!(\fP\^\fIpattern-list\^\fP\fB)\fP | |
3373 | Matches anything except one of the given patterns | |
3374 | .RE | |
726f6388 JA |
3375 | .PD |
3376 | .SS Quote Removal | |
3377 | .PP | |
3378 | After the preceding expansions, all unquoted occurrences of the | |
3379 | characters | |
3380 | .BR \e , | |
20587658 | 3381 | .BR \(aq , |
ccc6cda3 JA |
3382 | and \^\f3"\fP\^ that did not result from one of the above |
3383 | expansions are removed. | |
726f6388 JA |
3384 | .SH REDIRECTION |
3385 | Before a command is executed, its input and output | |
3386 | may be | |
3387 | .I redirected | |
3388 | using a special notation interpreted by the shell. | |
c31d56a7 CR |
3389 | Redirection allows commands' file handles to be |
3390 | duplicated, opened, closed, | |
3391 | made to refer to different files, | |
3392 | and can change the files the command reads from and writes to. | |
3393 | Redirection may also be used to modify file handles in the | |
3394 | current shell execution environment. | |
3395 | The following redirection | |
726f6388 JA |
3396 | operators may precede or appear anywhere within a |
3397 | .I simple command | |
3398 | or may follow a | |
3399 | .IR command . | |
3400 | Redirections are processed in the order they appear, from | |
3401 | left to right. | |
3402 | .PP | |
a8fd3f3e CR |
3403 | Each redirection that may be preceded by a file descriptor number |
3404 | may instead be preceded by a word of the form {\fIvarname\fP}. | |
3405 | In this case, for each redirection operator except | |
3406 | >&- and <&-, the shell will allocate a file descriptor greater | |
19baff85 CR |
3407 | than or equal to 10 and assign it to \fIvarname\fP. |
3408 | If >&- or <&- is preceded | |
a8fd3f3e CR |
3409 | by {\fIvarname\fP}, the value of \fIvarname\fP defines the file |
3410 | descriptor to close. | |
3411 | .PP | |
726f6388 JA |
3412 | In the following descriptions, if the file descriptor number is |
3413 | omitted, and the first character of the redirection operator is | |
3414 | .BR < , | |
3415 | the redirection refers to the standard input (file descriptor | |
3416 | 0). If the first character of the redirection operator is | |
3417 | .BR > , | |
3418 | the redirection refers to the standard output (file descriptor | |
3419 | 1). | |
3420 | .PP | |
cce855bc | 3421 | The word following the redirection operator in the following |
7610e0c5 CR |
3422 | descriptions, unless otherwise noted, is subjected to |
3423 | brace expansion, tilde expansion, parameter and variable expansion, | |
3424 | command substitution, arithmetic expansion, quote removal, | |
3425 | pathname expansion, and word splitting. | |
cce855bc | 3426 | If it expands to more than one word, |
726f6388 JA |
3427 | .B bash |
3428 | reports an error. | |
3429 | .PP | |
3430 | Note that the order of redirections is significant. For example, | |
3431 | the command | |
3432 | .RS | |
3433 | .PP | |
3434 | ls \fB>\fP dirlist 2\fB>&\fP1 | |
3435 | .RE | |
3436 | .PP | |
3437 | directs both standard output and standard error to the file | |
3438 | .IR dirlist , | |
3439 | while the command | |
3440 | .RS | |
3441 | .PP | |
3442 | ls 2\fB>&\fP1 \fB>\fP dirlist | |
3443 | .RE | |
3444 | .PP | |
3445 | directs only the standard output to file | |
3446 | .IR dirlist , | |
db31fb26 | 3447 | because the standard error was duplicated from the standard output |
726f6388 JA |
3448 | before the standard output was redirected to |
3449 | .IR dirlist . | |
cce855bc | 3450 | .PP |
bb70624e JA |
3451 | \fBBash\fP handles several filenames specially when they are used in |
3452 | redirections, as described in the following table: | |
3453 | .RS | |
3454 | .PP | |
3455 | .PD 0 | |
3456 | .TP | |
3457 | .B /dev/fd/\fIfd\fP | |
3458 | If \fIfd\fP is a valid integer, file descriptor \fIfd\fP is duplicated. | |
3459 | .TP | |
3460 | .B /dev/stdin | |
3461 | File descriptor 0 is duplicated. | |
3462 | .TP | |
3463 | .B /dev/stdout | |
3464 | File descriptor 1 is duplicated. | |
3465 | .TP | |
3466 | .B /dev/stderr | |
3467 | File descriptor 2 is duplicated. | |
3468 | .TP | |
3469 | .B /dev/tcp/\fIhost\fP/\fIport\fP | |
3470 | If \fIhost\fP is a valid hostname or Internet address, and \fIport\fP | |
f73dda09 JA |
3471 | is an integer port number or service name, \fBbash\fP attempts to open |
3472 | a TCP connection to the corresponding socket. | |
bb70624e JA |
3473 | .TP |
3474 | .B /dev/udp/\fIhost\fP/\fIport\fP | |
3475 | If \fIhost\fP is a valid hostname or Internet address, and \fIport\fP | |
f73dda09 JA |
3476 | is an integer port number or service name, \fBbash\fP attempts to open |
3477 | a UDP connection to the corresponding socket. | |
bb70624e JA |
3478 | .PD |
3479 | .RE | |
3480 | .PP | |
cce855bc | 3481 | A failure to open or create a file causes the redirection to fail. |
cac4cdbf CR |
3482 | .PP |
3483 | Redirections using file descriptors greater than 9 should be used with | |
3484 | care, as they may conflict with file descriptors the shell uses | |
3485 | internally. | |
726f6388 JA |
3486 | .SS Redirecting Input |
3487 | .PP | |
3488 | Redirection of input causes the file whose name results from | |
3489 | the expansion of | |
3490 | .I word | |
3491 | to be opened for reading on file descriptor | |
3492 | .IR n , | |
3493 | or the standard input (file descriptor 0) if | |
3494 | .I n | |
3495 | is not specified. | |
3496 | .PP | |
3497 | The general format for redirecting input is: | |
3498 | .RS | |
3499 | .PP | |
3500 | [\fIn\fP]\fB<\fP\fIword\fP | |
3501 | .RE | |
3502 | .SS Redirecting Output | |
3503 | .PP | |
3504 | Redirection of output causes the file whose name results from | |
3505 | the expansion of | |
3506 | .I word | |
3507 | to be opened for writing on file descriptor | |
3508 | .IR n , | |
3509 | or the standard output (file descriptor 1) if | |
3510 | .I n | |
3511 | is not specified. If the file does not exist it is created; | |
3512 | if it does exist it is truncated to zero size. | |
3513 | .PP | |
3514 | The general format for redirecting output is: | |
3515 | .RS | |
3516 | .PP | |
3517 | [\fIn\fP]\fB>\fP\fIword\fP | |
3518 | .RE | |
3519 | .PP | |
3520 | If the redirection operator is | |
ccc6cda3 JA |
3521 | .BR > , |
3522 | and the | |
cce855bc | 3523 | .B noclobber |
ccc6cda3 JA |
3524 | option to the |
3525 | .B set | |
bb70624e | 3526 | builtin has been enabled, the redirection will fail if the file |
cce855bc JA |
3527 | whose name results from the expansion of \fIword\fP exists and is |
3528 | a regular file. | |
ccc6cda3 | 3529 | If the redirection operator is |
726f6388 | 3530 | .BR >| , |
cce855bc JA |
3531 | or the redirection operator is |
3532 | .B > | |
3533 | and the | |
3534 | .B noclobber | |
726f6388 JA |
3535 | option to the |
3536 | .B set | |
cce855bc | 3537 | builtin command is not enabled, the redirection is attempted even |
ccc6cda3 | 3538 | if the file named by \fIword\fP exists. |
726f6388 JA |
3539 | .SS Appending Redirected Output |
3540 | .PP | |
3541 | Redirection of output in this fashion | |
3542 | causes the file whose name results from | |
3543 | the expansion of | |
3544 | .I word | |
3545 | to be opened for appending on file descriptor | |
3546 | .IR n , | |
3547 | or the standard output (file descriptor 1) if | |
3548 | .I n | |
3549 | is not specified. If the file does not exist it is created. | |
3550 | .PP | |
3551 | The general format for appending output is: | |
3552 | .RS | |
3553 | .PP | |
3554 | [\fIn\fP]\fB>>\fP\fIword\fP | |
3555 | .RE | |
3556 | .PP | |
3557 | .SS Redirecting Standard Output and Standard Error | |
3558 | .PP | |
8943768b | 3559 | This construct allows both the |
726f6388 JA |
3560 | standard output (file descriptor 1) and |
3561 | the standard error output (file descriptor 2) | |
3562 | to be redirected to the file whose name is the | |
3563 | expansion of | |
8943768b | 3564 | .IR word . |
726f6388 JA |
3565 | .PP |
3566 | There are two formats for redirecting standard output and | |
3567 | standard error: | |
3568 | .RS | |
3569 | .PP | |
3570 | \fB&>\fP\fIword\fP | |
3571 | .RE | |
3572 | and | |
3573 | .RS | |
3574 | \fB>&\fP\fIword\fP | |
3575 | .RE | |
3576 | .PP | |
3577 | Of the two forms, the first is preferred. | |
3578 | This is semantically equivalent to | |
3579 | .RS | |
3580 | .PP | |
3581 | \fB>\fP\fIword\fP 2\fB>&\fP1 | |
3582 | .RE | |
8943768b | 3583 | .PP |
c5402025 CR |
3584 | When using the second form, \fIword\fP may not expand to a number or |
3585 | \fB\-\fP. If it does, other redirection operators apply | |
3586 | (see \fBDuplicating File Descriptors\fP below) for compatibility | |
3587 | reasons. | |
8943768b CR |
3588 | .SS Appending Standard Output and Standard Error |
3589 | .PP | |
3590 | This construct allows both the | |
3591 | standard output (file descriptor 1) and | |
3592 | the standard error output (file descriptor 2) | |
3593 | to be appended to the file whose name is the | |
3594 | expansion of | |
3595 | .IR word . | |
3596 | .PP | |
3597 | The format for appending standard output and standard error is: | |
3598 | .RS | |
3599 | .PP | |
3600 | \fB&>>\fP\fIword\fP | |
3601 | .RE | |
3602 | .PP | |
3603 | This is semantically equivalent to | |
3604 | .RS | |
3605 | .PP | |
3606 | \fB>>\fP\fIword\fP 2\fB>&\fP1 | |
3607 | .RE | |
f6da9f85 CR |
3608 | .PP |
3609 | (see \fBDuplicating File Descriptors\fP below). | |
726f6388 JA |
3610 | .SS Here Documents |
3611 | .PP | |
3612 | This type of redirection instructs the shell to read input from the | |
3613 | current source until a line containing only | |
626d0694 | 3614 | .I delimiter |
726f6388 JA |
3615 | (with no trailing blanks) |
3616 | is seen. All of | |
3617 | the lines read up to that point are then used as the standard | |
3618 | input for a command. | |
3619 | .PP | |
7117c2d2 | 3620 | The format of here-documents is: |
726f6388 JA |
3621 | .RS |
3622 | .PP | |
3623 | .nf | |
3624 | \fB<<\fP[\fB\-\fP]\fIword\fP | |
f73dda09 | 3625 | \fIhere-document\fP |
726f6388 JA |
3626 | \fIdelimiter\fP |
3627 | .fi | |
3628 | .RE | |
3629 | .PP | |
7610e0c5 CR |
3630 | No parameter and variable expansion, command substitution, |
3631 | arithmetic expansion, or pathname expansion is performed on | |
726f6388 JA |
3632 | .IR word . |
3633 | If any characters in | |
3634 | .I word | |
3635 | are quoted, the | |
3636 | .I delimiter | |
3637 | is the result of quote removal on | |
3638 | .IR word , | |
cce855bc JA |
3639 | and the lines in the here-document are not expanded. |
3640 | If \fIword\fP is unquoted, | |
726f6388 JA |
3641 | all lines of the here-document are subjected to parameter expansion, |
3642 | command substitution, and arithmetic expansion. In the latter | |
bb70624e | 3643 | case, the character sequence |
726f6388 JA |
3644 | .B \e<newline> |
3645 | is ignored, and | |
3646 | .B \e | |
3647 | must be used to quote the characters | |
3648 | .BR \e , | |
3649 | .BR $ , | |
3650 | and | |
3d4e09aa | 3651 | .BR \` . |
726f6388 JA |
3652 | .PP |
3653 | If the redirection operator is | |
3654 | .BR <<\- , | |
3655 | then all leading tab characters are stripped from input lines and the | |
3656 | line containing | |
3657 | .IR delimiter . | |
3658 | This allows | |
3659 | here-documents within shell scripts to be indented in a | |
3660 | natural fashion. | |
7117c2d2 JA |
3661 | .SS "Here Strings" |
3662 | A variant of here documents, the format is: | |
3663 | .RS | |
3664 | .PP | |
3665 | .nf | |
3666 | \fB<<<\fP\fIword\fP | |
3667 | .fi | |
3668 | .RE | |
3669 | .PP | |
7610e0c5 CR |
3670 | The \fIword\fP undergoes |
3671 | brace expansion, tilde expansion, parameter and variable expansion, | |
3672 | command substitution, arithmetic expansion, and quote removal. | |
3673 | Pathname expansion word splitting are not performed. | |
3674 | The result is supplied as a single string to the command on its | |
3675 | standard input. | |
726f6388 JA |
3676 | .SS "Duplicating File Descriptors" |
3677 | .PP | |
3678 | The redirection operator | |
3679 | .RS | |
3680 | .PP | |
3681 | [\fIn\fP]\fB<&\fP\fIword\fP | |
3682 | .RE | |
3683 | .PP | |
3684 | is used to duplicate input file descriptors. | |
3685 | If | |
3686 | .I word | |
3687 | expands to one or more digits, the file descriptor denoted by | |
3688 | .I n | |
cce855bc JA |
3689 | is made to be a copy of that file descriptor. |
3690 | If the digits in | |
3691 | .I word | |
3692 | do not specify a file descriptor open for input, a redirection error occurs. | |
3693 | If | |
726f6388 JA |
3694 | .I word |
3695 | evaluates to | |
3696 | .BR \- , | |
3697 | file descriptor | |
3698 | .I n | |
3699 | is closed. If | |
3700 | .I n | |
3701 | is not specified, the standard input (file descriptor 0) is used. | |
3702 | .PP | |
3703 | The operator | |
3704 | .RS | |
3705 | .PP | |
3706 | [\fIn\fP]\fB>&\fP\fIword\fP | |
3707 | .RE | |
3708 | .PP | |
3709 | is used similarly to duplicate output file descriptors. If | |
3710 | .I n | |
3711 | is not specified, the standard output (file descriptor 1) is used. | |
cce855bc JA |
3712 | If the digits in |
3713 | .I word | |
3714 | do not specify a file descriptor open for output, a redirection error occurs. | |
c5402025 CR |
3715 | If |
3716 | .I word | |
3717 | evaluates to | |
3718 | .BR \- , | |
3719 | file descriptor | |
3720 | .I n | |
3721 | is closed. | |
726f6388 | 3722 | As a special case, if \fIn\fP is omitted, and \fIword\fP does not |
c5402025 | 3723 | expand to one or more digits or \fB\-\fP, the standard output and standard |
726f6388 | 3724 | error are redirected as described previously. |
7117c2d2 JA |
3725 | .SS "Moving File Descriptors" |
3726 | .PP | |
3727 | The redirection operator | |
3728 | .RS | |
3729 | .PP | |
3730 | [\fIn\fP]\fB<&\fP\fIdigit\fP\fB\-\fP | |
3731 | .RE | |
3732 | .PP | |
3733 | moves the file descriptor \fIdigit\fP to file descriptor | |
3734 | .IR n , | |
3735 | or the standard input (file descriptor 0) if \fIn\fP is not specified. | |
3736 | \fIdigit\fP is closed after being duplicated to \fIn\fP. | |
3737 | .PP | |
3738 | Similarly, the redirection operator | |
3739 | .RS | |
3740 | .PP | |
3741 | [\fIn\fP]\fB>&\fP\fIdigit\fP\fB\-\fP | |
3742 | .RE | |
3743 | .PP | |
3744 | moves the file descriptor \fIdigit\fP to file descriptor | |
3745 | .IR n , | |
3746 | or the standard output (file descriptor 1) if \fIn\fP is not specified. | |
726f6388 JA |
3747 | .SS "Opening File Descriptors for Reading and Writing" |
3748 | .PP | |
3749 | The redirection operator | |
3750 | .RS | |
3751 | .PP | |
3752 | [\fIn\fP]\fB<>\fP\fIword\fP | |
3753 | .RE | |
3754 | .PP | |
3755 | causes the file whose name is the expansion of | |
3756 | .I word | |
3757 | to be opened for both reading and writing on file descriptor | |
3758 | .IR n , | |
ccc6cda3 | 3759 | or on file descriptor 0 if |
726f6388 JA |
3760 | .I n |
3761 | is not specified. If the file does not exist, it is created. | |
726f6388 | 3762 | .SH ALIASES |
bb70624e | 3763 | \fIAliases\fP allow a string to be substituted for a word when it is used |
cce855bc | 3764 | as the first word of a simple command. |
bb70624e | 3765 | The shell maintains a list of aliases that may be set and unset with the |
726f6388 JA |
3766 | .B alias |
3767 | and | |
3768 | .B unalias | |
3769 | builtin commands (see | |
3770 | .SM | |
3771 | .B SHELL BUILTIN COMMANDS | |
3772 | below). | |
de8913bd | 3773 | The first word of each simple command, if unquoted, |
726f6388 JA |
3774 | is checked to see if it has an |
3775 | alias. If so, that word is replaced by the text of the alias. | |
3d4e09aa | 3776 | The characters \fB/\fP, \fB$\fP, \fB\`\fP, and \fB=\fP and |
de8913bd CR |
3777 | any of the shell \fImetacharacters\fP or quoting characters |
3778 | listed above may not appear in an alias name. | |
3779 | The replacement text may contain any valid shell input, | |
3780 | including shell metacharacters. | |
3781 | The first word of the replacement text is tested | |
726f6388 | 3782 | for aliases, but a word that is identical to an alias being expanded |
de8913bd CR |
3783 | is not expanded a second time. |
3784 | This means that one may alias | |
726f6388 JA |
3785 | .B ls |
3786 | to | |
3787 | .BR "ls \-F" , | |
3788 | for instance, and | |
3789 | .B bash | |
3790 | does not try to recursively expand the replacement text. | |
3791 | If the last character of the alias value is a | |
3792 | .IR blank , | |
3793 | then the next command | |
3794 | word following the alias is also checked for alias expansion. | |
3795 | .PP | |
3796 | Aliases are created and listed with the | |
3797 | .B alias | |
3798 | command, and removed with the | |
3799 | .B unalias | |
3800 | command. | |
3801 | .PP | |
ccc6cda3 | 3802 | There is no mechanism for using arguments in the replacement text. |
bb70624e JA |
3803 | If arguments are needed, a shell function should be used (see |
3804 | .SM | |
3805 | .B FUNCTIONS | |
3806 | below). | |
726f6388 | 3807 | .PP |
ccc6cda3 JA |
3808 | Aliases are not expanded when the shell is not interactive, unless |
3809 | the | |
3810 | .B expand_aliases | |
3811 | shell option is set using | |
3812 | .B shopt | |
3813 | (see the description of | |
3814 | .B shopt | |
3815 | under | |
3816 | .SM | |
3817 | \fBSHELL BUILTIN COMMANDS\fP | |
3818 | below). | |
726f6388 JA |
3819 | .PP |
3820 | The rules concerning the definition and use of aliases are | |
3821 | somewhat confusing. | |
3822 | .B Bash | |
3823 | always reads at least one complete line | |
3824 | of input before executing any | |
3825 | of the commands on that line. Aliases are expanded when a | |
3826 | command is read, not when it is executed. Therefore, an | |
3827 | alias definition appearing on the same line as another | |
3828 | command does not take effect until the next line of input is read. | |
ccc6cda3 | 3829 | The commands following the alias definition |
726f6388 JA |
3830 | on that line are not affected by the new alias. |
3831 | This behavior is also an issue when functions are executed. | |
cce855bc | 3832 | Aliases are expanded when a function definition is read, |
726f6388 JA |
3833 | not when the function is executed, because a function definition |
3834 | is itself a compound command. As a consequence, aliases | |
3835 | defined in a function are not available until after that | |
3836 | function is executed. To be safe, always put | |
3837 | alias definitions on a separate line, and do not use | |
3838 | .B alias | |
3839 | in compound commands. | |
3840 | .PP | |
cce855bc | 3841 | For almost every purpose, aliases are superseded by |
726f6388 | 3842 | shell functions. |
ccc6cda3 JA |
3843 | .SH FUNCTIONS |
3844 | A shell function, defined as described above under | |
3845 | .SM | |
3846 | .BR "SHELL GRAMMAR" , | |
3847 | stores a series of commands for later execution. | |
bb70624e JA |
3848 | When the name of a shell function is used as a simple command name, |
3849 | the list of commands associated with that function name is executed. | |
ccc6cda3 JA |
3850 | Functions are executed in the context of the |
3851 | current shell; no new process is created to interpret | |
3852 | them (contrast this with the execution of a shell script). | |
3853 | When a function is executed, the arguments to the | |
3854 | function become the positional parameters | |
bb70624e JA |
3855 | during its execution. |
3856 | The special parameter | |
ccc6cda3 | 3857 | .B # |
dc60d4e0 | 3858 | is updated to reflect the change. Special parameter \fB0\fP |
bb70624e | 3859 | is unchanged. |
d3a24ed2 | 3860 | The first element of the |
bb70624e JA |
3861 | .SM |
3862 | .B FUNCNAME | |
3863 | variable is set to the name of the function while the function | |
3864 | is executing. | |
4301bca7 | 3865 | .PP |
bb70624e | 3866 | All other aspects of the shell execution |
ccc6cda3 | 3867 | environment are identical between a function and its caller |
4301bca7 | 3868 | with these exceptions: the |
ccc6cda3 JA |
3869 | .SM |
3870 | .B DEBUG | |
76a8d78d CR |
3871 | and |
3872 | .B RETURN | |
3873 | traps (see the description of the | |
ccc6cda3 JA |
3874 | .B trap |
3875 | builtin under | |
3876 | .SM | |
3877 | .B SHELL BUILTIN COMMANDS | |
76a8d78d | 3878 | below) are not inherited unless the function has been given the |
7117c2d2 JA |
3879 | \fBtrace\fP attribute (see the description of the |
3880 | .SM | |
3881 | .B declare | |
d3a24ed2 CR |
3882 | builtin below) or the |
3883 | \fB\-o functrace\fP shell option has been enabled with | |
3884 | the \fBset\fP builtin | |
4301bca7 CR |
3885 | (in which case all functions inherit the \fBDEBUG\fP and \fBRETURN\fP traps), |
3886 | and the | |
3887 | .SM | |
3888 | .B ERR | |
3889 | trap is not inherited unless the \fB\-o errtrace\fP shell option has | |
3890 | been enabled. | |
726f6388 | 3891 | .PP |
ccc6cda3 JA |
3892 | Variables local to the function may be declared with the |
3893 | .B local | |
3894 | builtin command. Ordinarily, variables and their values | |
3895 | are shared between the function and its caller. | |
726f6388 | 3896 | .PP |
6faad625 CR |
3897 | The \fBFUNCNEST\fP variable, if set to a numeric value greater |
3898 | than 0, defines a maximum function nesting level. Function | |
3899 | invocations that exceed the limit cause the entire command to | |
3900 | abort. | |
3901 | .PP | |
ccc6cda3 JA |
3902 | If the builtin command |
3903 | .B return | |
3904 | is executed in a function, the function completes and | |
3905 | execution resumes with the next command after the function | |
d3a24ed2 CR |
3906 | call. |
3907 | Any command associated with the \fBRETURN\fP trap is executed | |
3908 | before execution resumes. | |
3909 | When a function completes, the values of the | |
ccc6cda3 JA |
3910 | positional parameters and the special parameter |
3911 | .B # | |
cce855bc | 3912 | are restored to the values they had prior to the function's |
ccc6cda3 | 3913 | execution. |
726f6388 | 3914 | .PP |
ccc6cda3 JA |
3915 | Function names and definitions may be listed with the |
3916 | .B \-f | |
726f6388 | 3917 | option to the |
ccc6cda3 JA |
3918 | .B declare |
3919 | or | |
3920 | .B typeset | |
3921 | builtin commands. The | |
3922 | .B \-F | |
3923 | option to | |
3924 | .B declare | |
3925 | or | |
3926 | .B typeset | |
d3a24ed2 CR |
3927 | will list the function names only |
3928 | (and optionally the source file and line number, if the \fBextdebug\fP | |
3929 | shell option is enabled). | |
ccc6cda3 JA |
3930 | Functions may be exported so that subshells |
3931 | automatically have them defined with the | |
3932 | .B \-f | |
3933 | option to the | |
3934 | .B export | |
3935 | builtin. | |
11a6f9a9 CR |
3936 | A function definition may be deleted using the \fB\-f\fP option to |
3937 | the | |
3938 | .B unset | |
3939 | builtin. | |
d3a24ed2 CR |
3940 | Note that shell functions and variables with the same name may result |
3941 | in multiple identically-named entries in the environment passed to the | |
3942 | shell's children. | |
3943 | Care should be taken in cases where this may cause a problem. | |
726f6388 | 3944 | .PP |
7d92f73f CR |
3945 | Functions may be recursive. |
3946 | The \fBFUNCNEST\fP variable may be used to limit the depth of the | |
3947 | function call stack and restrict the number of function invocations. | |
3948 | By default, no limit is imposed on the number of recursive calls. | |
cce855bc JA |
3949 | .SH "ARITHMETIC EVALUATION" |
3950 | The shell allows arithmetic expressions to be evaluated, under | |
d3a24ed2 CR |
3951 | certain circumstances (see the \fBlet\fP and \fBdeclare\fP builtin |
3952 | commands and \fBArithmetic Expansion\fP). | |
7117c2d2 | 3953 | Evaluation is done in fixed-width integers with no check for overflow, |
cce855bc | 3954 | though division by 0 is trapped and flagged as an error. |
d3a24ed2 CR |
3955 | The operators and their precedence, associativity, and values |
3956 | are the same as in the C language. | |
cce855bc JA |
3957 | The following list of operators is grouped into levels of |
3958 | equal-precedence operators. | |
3959 | The levels are listed in order of decreasing precedence. | |
726f6388 | 3960 | .PP |
cce855bc JA |
3961 | .PD 0 |
3962 | .TP | |
bb70624e JA |
3963 | .B \fIid\fP++ \fIid\fP\-\- |
3964 | variable post-increment and post-decrement | |
3965 | .TP | |
3966 | .B ++\fIid\fP \-\-\fIid\fP | |
3967 | variable pre-increment and pre-decrement | |
3968 | .TP | |
cce855bc JA |
3969 | .B \- + |
3970 | unary minus and plus | |
3971 | .TP | |
3972 | .B ! ~ | |
3973 | logical and bitwise negation | |
3974 | .TP | |
3975 | .B ** | |
3976 | exponentiation | |
3977 | .TP | |
3978 | .B * / % | |
3979 | multiplication, division, remainder | |
3980 | .TP | |
3981 | .B + \- | |
3982 | addition, subtraction | |
3983 | .TP | |
3984 | .B << >> | |
3985 | left and right bitwise shifts | |
3986 | .TP | |
3987 | .B <= >= < > | |
3988 | comparison | |
3989 | .TP | |
3990 | .B == != | |
3991 | equality and inequality | |
3992 | .TP | |
3993 | .B & | |
3994 | bitwise AND | |
3995 | .TP | |
3996 | .B ^ | |
3997 | bitwise exclusive OR | |
3998 | .TP | |
3999 | .B | | |
4000 | bitwise OR | |
4001 | .TP | |
4002 | .B && | |
4003 | logical AND | |
4004 | .TP | |
4005 | .B || | |
4006 | logical OR | |
4007 | .TP | |
4008 | .B \fIexpr\fP?\fIexpr\fP:\fIexpr\fP | |
d3a24ed2 | 4009 | conditional operator |
cce855bc JA |
4010 | .TP |
4011 | .B = *= /= %= += \-= <<= >>= &= ^= |= | |
4012 | assignment | |
bb70624e JA |
4013 | .TP |
4014 | .B \fIexpr1\fP , \fIexpr2\fP | |
4015 | comma | |
cce855bc | 4016 | .PD |
ccc6cda3 | 4017 | .PP |
cce855bc | 4018 | Shell variables are allowed as operands; parameter expansion is |
bb70624e JA |
4019 | performed before the expression is evaluated. |
4020 | Within an expression, shell variables may also be referenced by name | |
4021 | without using the parameter expansion syntax. | |
d3a24ed2 CR |
4022 | A shell variable that is null or unset evaluates to 0 when referenced |
4023 | by name without using the parameter expansion syntax. | |
bb70624e | 4024 | The value of a variable is evaluated as an arithmetic expression |
d3a24ed2 CR |
4025 | when it is referenced, or when a variable which has been given the |
4026 | \fIinteger\fP attribute using \fBdeclare -i\fP is assigned a value. | |
4027 | A null value evaluates to 0. | |
dc60d4e0 | 4028 | A shell variable need not have its \fIinteger\fP attribute |
cce855bc | 4029 | turned on to be used in an expression. |
ccc6cda3 | 4030 | .PP |
cce855bc JA |
4031 | Constants with a leading 0 are interpreted as octal numbers. |
4032 | A leading 0x or 0X denotes hexadecimal. | |
1b13a290 | 4033 | Otherwise, numbers take the form [\fIbase#\fP]n, where the optional \fIbase\fP |
cce855bc JA |
4034 | is a decimal number between 2 and 64 representing the arithmetic |
4035 | base, and \fIn\fP is a number in that base. | |
bb70624e | 4036 | If \fIbase#\fP is omitted, then base 10 is used. |
c31d56a7 CR |
4037 | When specifying \fIn\fP, |
4038 | the digits greater< than 9 are represented by the lowercase letters, | |
f73dda09 | 4039 | the uppercase letters, @, and _, in that order. |
cce855bc | 4040 | If \fIbase\fP is less than or equal to 36, lowercase and uppercase |
f75912ae | 4041 | letters may be used interchangeably to represent numbers between 10 |
cce855bc | 4042 | and 35. |
ccc6cda3 | 4043 | .PP |
cce855bc JA |
4044 | Operators are evaluated in order of precedence. Sub-expressions in |
4045 | parentheses are evaluated first and may override the precedence | |
4046 | rules above. | |
4047 | .SH "CONDITIONAL EXPRESSIONS" | |
4048 | Conditional expressions are used by the \fB[[\fP compound command and | |
4049 | the \fBtest\fP and \fB[\fP builtin commands to test file attributes | |
4050 | and perform string and arithmetic comparisons. | |
4051 | Expressions are formed from the following unary or binary primaries. | |
4052 | If any \fIfile\fP argument to one of the primaries is of the form | |
bb70624e JA |
4053 | \fI/dev/fd/n\fP, then file descriptor \fIn\fP is checked. |
4054 | If the \fIfile\fP argument to one of the primaries is one of | |
4055 | \fI/dev/stdin\fP, \fI/dev/stdout\fP, or \fI/dev/stderr\fP, file | |
4056 | descriptor 0, 1, or 2, respectively, is checked. | |
be7d8f2d CR |
4057 | .PP |
4058 | Unless otherwise specified, primaries that operate on files follow symbolic | |
4059 | links and operate on the target of the link, rather than the link itself. | |
6bf8a8a7 CR |
4060 | .if t .sp 0.5 |
4061 | .if n .sp 1 | |
54a1fa7c | 4062 | When used with \fB[[\fP, the \fB<\fP and \fB>\fP operators sort |
6bf8a8a7 | 4063 | lexicographically using the current locale. |
54a1fa7c | 4064 | The \fBtest\fP command sorts using ASCII ordering. |
cce855bc JA |
4065 | .sp 1 |
4066 | .PD 0 | |
4067 | .TP | |
4068 | .B \-a \fIfile\fP | |
4069 | True if \fIfile\fP exists. | |
4070 | .TP | |
4071 | .B \-b \fIfile\fP | |
4072 | True if \fIfile\fP exists and is a block special file. | |
4073 | .TP | |
4074 | .B \-c \fIfile\fP | |
4075 | True if \fIfile\fP exists and is a character special file. | |
4076 | .TP | |
4077 | .B \-d \fIfile\fP | |
4078 | True if \fIfile\fP exists and is a directory. | |
4079 | .TP | |
4080 | .B \-e \fIfile\fP | |
4081 | True if \fIfile\fP exists. | |
4082 | .TP | |
4083 | .B \-f \fIfile\fP | |
4084 | True if \fIfile\fP exists and is a regular file. | |
4085 | .TP | |
4086 | .B \-g \fIfile\fP | |
4087 | True if \fIfile\fP exists and is set-group-id. | |
4088 | .TP | |
b72432fd JA |
4089 | .B \-h \fIfile\fP |
4090 | True if \fIfile\fP exists and is a symbolic link. | |
4091 | .TP | |
cce855bc JA |
4092 | .B \-k \fIfile\fP |
4093 | True if \fIfile\fP exists and its ``sticky'' bit is set. | |
4094 | .TP | |
4095 | .B \-p \fIfile\fP | |
4096 | True if \fIfile\fP exists and is a named pipe (FIFO). | |
4097 | .TP | |
4098 | .B \-r \fIfile\fP | |
4099 | True if \fIfile\fP exists and is readable. | |
4100 | .TP | |
4101 | .B \-s \fIfile\fP | |
4102 | True if \fIfile\fP exists and has a size greater than zero. | |
4103 | .TP | |
4104 | .B \-t \fIfd\fP | |
4105 | True if file descriptor | |
4106 | .I fd | |
4107 | is open and refers to a terminal. | |
4108 | .TP | |
4109 | .B \-u \fIfile\fP | |
4110 | True if \fIfile\fP exists and its set-user-id bit is set. | |
4111 | .TP | |
4112 | .B \-w \fIfile\fP | |
4113 | True if \fIfile\fP exists and is writable. | |
4114 | .TP | |
4115 | .B \-x \fIfile\fP | |
4116 | True if \fIfile\fP exists and is executable. | |
4117 | .TP | |
cce855bc JA |
4118 | .B \-G \fIfile\fP |
4119 | True if \fIfile\fP exists and is owned by the effective group id. | |
4120 | .TP | |
4121 | .B \-L \fIfile\fP | |
4122 | True if \fIfile\fP exists and is a symbolic link. | |
4123 | .TP | |
5cdaaf76 CR |
4124 | .B \-N \fIfile\fP |
4125 | True if \fIfile\fP exists and has been modified since it was last read. | |
4126 | .TP | |
4127 | .B \-O \fIfile\fP | |
4128 | True if \fIfile\fP exists and is owned by the effective user id. | |
4129 | .TP | |
cce855bc JA |
4130 | .B \-S \fIfile\fP |
4131 | True if \fIfile\fP exists and is a socket. | |
4132 | .TP | |
5cdaaf76 CR |
4133 | \fIfile1\fP \fB\-ef\fP \fIfile2\fP |
4134 | True if \fIfile1\fP and \fIfile2\fP refer to the same device and | |
4135 | inode numbers. | |
cce855bc JA |
4136 | .TP |
4137 | \fIfile1\fP \-\fBnt\fP \fIfile2\fP | |
7117c2d2 JA |
4138 | True if \fIfile1\fP is newer (according to modification date) than \fIfile2\fP, |
4139 | or if \fIfile1\fP exists and \fPfile2\fP does not. | |
cce855bc JA |
4140 | .TP |
4141 | \fIfile1\fP \-\fBot\fP \fIfile2\fP | |
7117c2d2 JA |
4142 | True if \fIfile1\fP is older than \fIfile2\fP, or if \fIfile2\fP exists |
4143 | and \fIfile1\fP does not. | |
cce855bc | 4144 | .TP |
cce855bc | 4145 | .B \-o \fIoptname\fP |
6faad625 | 4146 | True if the shell option |
cce855bc JA |
4147 | .I optname |
4148 | is enabled. | |
4149 | See the list of options under the description of the | |
4150 | .B \-o | |
4151 | option to the | |
4152 | .B set | |
4153 | builtin below. | |
4154 | .TP | |
6faad625 CR |
4155 | .B \-v \fIvarname\fP |
4156 | True if the shell variable | |
4157 | .I varname | |
4158 | is set (has been assigned a value). | |
4159 | .TP | |
cce855bc JA |
4160 | .B \-z \fIstring\fP |
4161 | True if the length of \fIstring\fP is zero. | |
4162 | .TP | |
cce855bc | 4163 | \fIstring\fP |
f085a21f CR |
4164 | .PD 0 |
4165 | .TP | |
4166 | .B \-n \fIstring\fP | |
4167 | .PD | |
cce855bc JA |
4168 | True if the length of |
4169 | .I string | |
4170 | is non-zero. | |
4171 | .TP | |
4172 | \fIstring1\fP \fB==\fP \fIstring2\fP | |
a3143574 CR |
4173 | .PD 0 |
4174 | .TP | |
4175 | \fIstring1\fP \fB=\fP \fIstring2\fP | |
4176 | .PD | |
4177 | True if the strings are equal. \fB=\fP should be used | |
4178 | with the \fBtest\fP command for POSIX conformance. | |
cce855bc JA |
4179 | .TP |
4180 | \fIstring1\fP \fB!=\fP \fIstring2\fP | |
4181 | True if the strings are not equal. | |
4182 | .TP | |
4183 | \fIstring1\fP \fB<\fP \fIstring2\fP | |
0d8616ff | 4184 | True if \fIstring1\fP sorts before \fIstring2\fP lexicographically. |
cce855bc JA |
4185 | .TP |
4186 | \fIstring1\fP \fB>\fP \fIstring2\fP | |
0d8616ff | 4187 | True if \fIstring1\fP sorts after \fIstring2\fP lexicographically. |
cce855bc JA |
4188 | .TP |
4189 | .I \fIarg1\fP \fBOP\fP \fIarg2\fP | |
4190 | .SM | |
4191 | .B OP | |
4192 | is one of | |
4193 | .BR \-eq , | |
4194 | .BR \-ne , | |
4195 | .BR \-lt , | |
4196 | .BR \-le , | |
4197 | .BR \-gt , | |
4198 | or | |
4199 | .BR \-ge . | |
4200 | These arithmetic binary operators return true if \fIarg1\fP | |
4201 | is equal to, not equal to, less than, less than or equal to, | |
4202 | greater than, or greater than or equal to \fIarg2\fP, respectively. | |
4203 | .I Arg1 | |
4204 | and | |
4205 | .I arg2 | |
4206 | may be positive or negative integers. | |
4207 | .PD | |
4208 | .SH "SIMPLE COMMAND EXPANSION" | |
4209 | When a simple command is executed, the shell performs the following | |
4210 | expansions, assignments, and redirections, from left to right. | |
4211 | .IP 1. | |
4212 | The words that the parser has marked as variable assignments (those | |
4213 | preceding the command name) and redirections are saved for later | |
4214 | processing. | |
4215 | .IP 2. | |
4216 | The words that are not variable assignments or redirections are | |
4217 | expanded. If any words remain after expansion, the first word | |
4218 | is taken to be the name of the command and the remaining words are | |
4219 | the arguments. | |
4220 | .IP 3. | |
4221 | Redirections are performed as described above under | |
4222 | .SM | |
4223 | .BR REDIRECTION . | |
4224 | .IP 4. | |
4225 | The text after the \fB=\fP in each variable assignment undergoes tilde | |
4226 | expansion, parameter expansion, command substitution, arithmetic expansion, | |
4227 | and quote removal before being assigned to the variable. | |
4228 | .PP | |
4229 | If no command name results, the variable assignments affect the current | |
4230 | shell environment. Otherwise, the variables are added to the environment | |
4231 | of the executed command and do not affect the current shell environment. | |
4232 | If any of the assignments attempts to assign a value to a readonly variable, | |
4233 | an error occurs, and the command exits with a non-zero status. | |
4234 | .PP | |
4235 | If no command name results, redirections are performed, but do not | |
4236 | affect the current shell environment. A redirection error causes the | |
4237 | command to exit with a non-zero status. | |
4238 | .PP | |
4239 | If there is a command name left after expansion, execution proceeds as | |
4240 | described below. Otherwise, the command exits. If one of the expansions | |
4241 | contained a command substitution, the exit status of the command is | |
4242 | the exit status of the last command substitution performed. If there | |
4243 | were no command substitutions, the command exits with a status of zero. | |
4244 | .SH "COMMAND EXECUTION" | |
4245 | After a command has been split into words, if it results in a | |
4246 | simple command and an optional list of arguments, the following | |
4247 | actions are taken. | |
4248 | .PP | |
4249 | If the command name contains no slashes, the shell attempts to | |
4250 | locate it. If there exists a shell function by that name, that | |
4251 | function is invoked as described above in | |
4252 | .SM | |
4253 | .BR FUNCTIONS . | |
4254 | If the name does not match a function, the shell searches for | |
4255 | it in the list of shell builtins. If a match is found, that | |
4256 | builtin is invoked. | |
4257 | .PP | |
4258 | If the name is neither a shell function nor a builtin, | |
4259 | and contains no slashes, | |
4260 | .B bash | |
4261 | searches each element of the | |
4262 | .SM | |
4263 | .B PATH | |
4264 | for a directory containing an executable file by that name. | |
4265 | .B Bash | |
bb70624e | 4266 | uses a hash table to remember the full pathnames of executable |
cce855bc JA |
4267 | files (see |
4268 | .B hash | |
4269 | under | |
4270 | .SM | |
4271 | .B "SHELL BUILTIN COMMANDS" | |
4272 | below). | |
4273 | A full search of the directories in | |
4274 | .SM | |
4275 | .B PATH | |
4276 | is performed only if the command is not found in the hash table. | |
245a493c CR |
4277 | If the search is unsuccessful, the shell searches for a defined shell |
4278 | function named \fBcommand_not_found_handle\fP. | |
4279 | If that function exists, it is invoked with the original command and | |
4280 | the original command's arguments as its arguments, and the function's | |
4281 | exit status becomes the exit status of the shell. | |
4282 | If that function is not defined, the shell prints an error | |
cce855bc JA |
4283 | message and returns an exit status of 127. |
4284 | .PP | |
4285 | If the search is successful, or if the command name contains | |
4286 | one or more slashes, the shell executes the named program in a | |
4287 | separate execution environment. | |
4288 | Argument 0 is set to the name given, and the remaining arguments | |
4289 | to the command are set to the arguments given, if any. | |
4290 | .PP | |
4291 | If this execution fails because the file is not in executable | |
4292 | format, and the file is not a directory, it is assumed to be | |
4293 | a \fIshell script\fP, a file | |
4294 | containing shell commands. A subshell is spawned to execute | |
4295 | it. This subshell reinitializes itself, so | |
4296 | that the effect is as if a new shell had been invoked | |
4297 | to handle the script, with the exception that the locations of | |
4298 | commands remembered by the parent (see | |
4299 | .B hash | |
4300 | below under | |
4301 | .SM | |
4302 | \fBSHELL BUILTIN COMMANDS\fP) | |
4303 | are retained by the child. | |
4304 | .PP | |
4305 | If the program is a file beginning with | |
4306 | .BR #! , | |
4307 | the remainder of the first line specifies an interpreter | |
4308 | for the program. The shell executes the | |
4309 | specified interpreter on operating systems that do not | |
4310 | handle this executable format themselves. The arguments to the | |
4311 | interpreter consist of a single optional argument following the | |
4312 | interpreter name on the first line of the program, followed | |
4313 | by the name of the program, followed by the command | |
4314 | arguments, if any. | |
4315 | .SH COMMAND EXECUTION ENVIRONMENT | |
4316 | The shell has an \fIexecution environment\fP, which consists of the | |
4317 | following: | |
cce855bc JA |
4318 | .IP \(bu |
4319 | open files inherited by the shell at invocation, as modified by | |
4320 | redirections supplied to the \fBexec\fP builtin | |
4321 | .IP \(bu | |
4322 | the current working directory as set by \fBcd\fP, \fBpushd\fP, or | |
4323 | \fBpopd\fP, or inherited by the shell at invocation | |
4324 | .IP \(bu | |
4325 | the file creation mode mask as set by \fBumask\fP or inherited from | |
4326 | the shell's parent | |
4327 | .IP \(bu | |
4328 | current traps set by \fBtrap\fP | |
4329 | .IP \(bu | |
4330 | shell parameters that are set by variable assignment or with \fBset\fP | |
4331 | or inherited from the shell's parent in the environment | |
4332 | .IP \(bu | |
4333 | shell functions defined during execution or inherited from the shell's | |
4334 | parent in the environment | |
4335 | .IP \(bu | |
4336 | options enabled at invocation (either by default or with command-line | |
4337 | arguments) or by \fBset\fP | |
4338 | .IP \(bu | |
4339 | options enabled by \fBshopt\fP | |
4340 | .IP \(bu | |
4341 | shell aliases defined with \fBalias\fP | |
4342 | .IP \(bu | |
4343 | various process IDs, including those of background jobs, the value | |
984a1947 CR |
4344 | of \fB$$\fP, and the value of |
4345 | .SM | |
4346 | .B PPID | |
cce855bc JA |
4347 | .PP |
4348 | When a simple command other than a builtin or shell function | |
4349 | is to be executed, it | |
4350 | is invoked in a separate execution environment that consists of | |
4351 | the following. Unless otherwise noted, the values are inherited | |
4352 | from the shell. | |
984a1947 | 4353 | .if n .sp 1 |
cce855bc JA |
4354 | .IP \(bu |
4355 | the shell's open files, plus any modifications and additions specified | |
4356 | by redirections to the command | |
4357 | .IP \(bu | |
4358 | the current working directory | |
4359 | .IP \(bu | |
4360 | the file creation mode mask | |
4361 | .IP \(bu | |
d3a24ed2 CR |
4362 | shell variables and functions marked for export, along with variables |
4363 | exported for the command, passed in the environment | |
cce855bc | 4364 | .IP \(bu |
d3a24ed2 CR |
4365 | traps caught by the shell are reset to the values inherited from the |
4366 | shell's parent, and traps ignored by the shell are ignored | |
cce855bc JA |
4367 | .PP |
4368 | A command invoked in this separate environment cannot affect the | |
4369 | shell's execution environment. | |
4370 | .PP | |
d3a24ed2 CR |
4371 | Command substitution, commands grouped with parentheses, |
4372 | and asynchronous commands are invoked in a | |
cce855bc JA |
4373 | subshell environment that is a duplicate of the shell environment, |
4374 | except that traps caught by the shell are reset to the values | |
4375 | that the shell inherited from its parent at invocation. Builtin | |
4376 | commands that are invoked as part of a pipeline are also executed in a | |
4377 | subshell environment. Changes made to the subshell environment | |
4378 | cannot affect the shell's execution environment. | |
f73dda09 | 4379 | .PP |
012bac39 | 4380 | Subshells spawned to execute command substitutions inherit the value of |
dc60d4e0 CR |
4381 | the \fB\-e\fP option from the parent shell. When not in \fIposix\fP mode, |
4382 | \fBbash\fP clears the \fB\-e\fP option in such subshells. | |
012bac39 | 4383 | .PP |
f73dda09 JA |
4384 | If a command is followed by a \fB&\fP and job control is not active, the |
4385 | default standard input for the command is the empty file \fI/dev/null\fP. | |
4386 | Otherwise, the invoked command inherits the file descriptors of the calling | |
4387 | shell as modified by redirections. | |
cce855bc JA |
4388 | .SH ENVIRONMENT |
4389 | When a program is invoked it is given an array of strings | |
4390 | called the | |
4391 | .IR environment . | |
4392 | This is a list of | |
4393 | \fIname\fP\-\fIvalue\fP pairs, of the form | |
4394 | .IR "name\fR=\fPvalue" . | |
4395 | .PP | |
bb70624e JA |
4396 | The shell provides several ways to manipulate the environment. |
4397 | On invocation, the shell scans its own environment and | |
cce855bc JA |
4398 | creates a parameter for each name found, automatically marking |
4399 | it for | |
4400 | .I export | |
4401 | to child processes. Executed commands inherit the environment. | |
4402 | The | |
4403 | .B export | |
4404 | and | |
4405 | .B declare \-x | |
4406 | commands allow parameters and functions to be added to and | |
4407 | deleted from the environment. If the value of a parameter | |
4408 | in the environment is modified, the new value becomes part | |
4409 | of the environment, replacing the old. The environment | |
4410 | inherited by any executed command consists of the shell's | |
4411 | initial environment, whose values may be modified in the shell, | |
4412 | less any pairs removed by the | |
4413 | .B unset | |
4414 | command, plus any additions via the | |
4415 | .B export | |
4416 | and | |
4417 | .B declare \-x | |
4418 | commands. | |
4419 | .PP | |
4420 | The environment for any | |
4421 | .I simple command | |
4422 | or function may be augmented temporarily by prefixing it with | |
4423 | parameter assignments, as described above in | |
4424 | .SM | |
4425 | .BR PARAMETERS . | |
4426 | These assignment statements affect only the environment seen | |
4427 | by that command. | |
4428 | .PP | |
4429 | If the | |
4430 | .B \-k | |
4431 | option is set (see the | |
4432 | .B set | |
4433 | builtin command below), then | |
4434 | .I all | |
4435 | parameter assignments are placed in the environment for a command, | |
4436 | not just those that precede the command name. | |
4437 | .PP | |
4438 | When | |
4439 | .B bash | |
4440 | invokes an external command, the variable | |
4441 | .B _ | |
b28ff8c9 | 4442 | is set to the full filename of the command and passed to that |
ccc6cda3 JA |
4443 | command in its environment. |
4444 | .SH "EXIT STATUS" | |
35ee8ea0 CR |
4445 | .PP |
4446 | The exit status of an executed command is the value returned by the | |
4447 | \fIwaitpid\fP system call or equivalent function. Exit statuses | |
4448 | fall between 0 and 255, though, as explained below, the shell may | |
4449 | use values above 125 specially. Exit statuses from shell builtins and | |
4450 | compound commands are also limited to this range. Under certain | |
4451 | circumstances, the shell will use special values to indicate specific | |
4452 | failure modes. | |
4453 | .PP | |
cce855bc | 4454 | For the shell's purposes, a command which exits with a |
ccc6cda3 JA |
4455 | zero exit status has succeeded. An exit status of zero |
4456 | indicates success. A non-zero exit status indicates failure. | |
bb70624e JA |
4457 | When a command terminates on a fatal signal \fIN\fP, \fBbash\fP uses |
4458 | the value of 128+\fIN\fP as the exit status. | |
ccc6cda3 JA |
4459 | .PP |
4460 | If a command is not found, the child process created to | |
4461 | execute it returns a status of 127. If a command is found | |
4462 | but is not executable, the return status is 126. | |
4463 | .PP | |
cce855bc JA |
4464 | If a command fails because of an error during expansion or redirection, |
4465 | the exit status is greater than zero. | |
4466 | .PP | |
ccc6cda3 JA |
4467 | Shell builtin commands return a status of 0 (\fItrue\fP) if |
4468 | successful, and non-zero (\fIfalse\fP) if an error occurs | |
4469 | while they execute. | |
4470 | All builtins return an exit status of 2 to indicate incorrect usage. | |
4471 | .PP | |
4472 | \fBBash\fP itself returns the exit status of the last command | |
4473 | executed, unless a syntax error occurs, in which case it exits | |
4474 | with a non-zero value. See also the \fBexit\fP builtin | |
4475 | command below. | |
4476 | .SH SIGNALS | |
cce855bc | 4477 | When \fBbash\fP is interactive, in the absence of any traps, it ignores |
ccc6cda3 JA |
4478 | .SM |
4479 | .B SIGTERM | |
4480 | (so that \fBkill 0\fP does not kill an interactive shell), | |
4481 | and | |
4482 | .SM | |
4483 | .B SIGINT | |
4484 | is caught and handled (so that the \fBwait\fP builtin is interruptible). | |
4485 | In all cases, \fBbash\fP ignores | |
4486 | .SM | |
4487 | .BR SIGQUIT . | |
4488 | If job control is in effect, | |
4489 | .B bash | |
4490 | ignores | |
4491 | .SM | |
4492 | .BR SIGTTIN , | |
4493 | .SM | |
4494 | .BR SIGTTOU , | |
4495 | and | |
4496 | .SM | |
4497 | .BR SIGTSTP . | |
4498 | .PP | |
5e13499c | 4499 | Non-builtin commands run by \fBbash\fP have signal handlers |
cce855bc JA |
4500 | set to the values inherited by the shell from its parent. |
4501 | When job control is not in effect, asynchronous commands | |
ccc6cda3 JA |
4502 | ignore |
4503 | .SM | |
4504 | .B SIGINT | |
4505 | and | |
4506 | .SM | |
cce855bc | 4507 | .B SIGQUIT |
5e13499c | 4508 | in addition to these inherited handlers. |
ccc6cda3 JA |
4509 | Commands run as a result of command substitution ignore the |
4510 | keyboard-generated job control signals | |
4511 | .SM | |
4512 | .BR SIGTTIN , | |
4513 | .SM | |
4514 | .BR SIGTTOU , | |
4515 | and | |
4516 | .SM | |
4517 | .BR SIGTSTP . | |
4518 | .PP | |
4519 | The shell exits by default upon receipt of a | |
4520 | .SM | |
4521 | .BR SIGHUP . | |
f73dda09 | 4522 | Before exiting, an interactive shell resends the |
ccc6cda3 JA |
4523 | .SM |
4524 | .B SIGHUP | |
cce855bc JA |
4525 | to all jobs, running or stopped. |
4526 | Stopped jobs are sent | |
4527 | .SM | |
4528 | .B SIGCONT | |
4529 | to ensure that they receive the | |
4530 | .SM | |
4531 | .BR SIGHUP . | |
4532 | To prevent the shell from | |
4533 | sending the signal to a particular job, it should be removed from the | |
ccc6cda3 JA |
4534 | jobs table with the |
4535 | .B disown | |
4536 | builtin (see | |
4537 | .SM | |
4538 | .B "SHELL BUILTIN COMMANDS" | |
cce855bc JA |
4539 | below) or marked |
4540 | to not receive | |
ccc6cda3 | 4541 | .SM |
cce855bc JA |
4542 | .B SIGHUP |
4543 | using | |
4544 | .BR "disown \-h" . | |
4545 | .PP | |
4546 | If the | |
4547 | .B huponexit | |
4548 | shell option has been set with | |
4549 | .BR shopt , | |
4550 | .B bash | |
4551 | sends a | |
4552 | .SM | |
4553 | .B SIGHUP | |
4554 | to all jobs when an interactive login shell exits. | |
4555 | .PP | |
b66cc816 | 4556 | If \fBbash\fP is waiting for a command to complete and receives a signal |
5e13499c CR |
4557 | for which a trap has been set, the trap will not be executed until |
4558 | the command completes. | |
cce855bc JA |
4559 | When \fBbash\fP is waiting for an asynchronous command via the \fBwait\fP |
4560 | builtin, the reception of a signal for which a trap has been set will | |
4561 | cause the \fBwait\fP builtin to return immediately with an exit status | |
4562 | greater than 128, immediately after which the trap is executed. | |
ccc6cda3 JA |
4563 | .SH "JOB CONTROL" |
4564 | .I Job control | |
4565 | refers to the ability to selectively stop (\fIsuspend\fP) | |
4566 | the execution of processes and continue (\fIresume\fP) | |
4567 | their execution at a later point. A user typically employs | |
4568 | this facility via an interactive interface supplied jointly | |
602bb739 | 4569 | by the operating system kernel's terminal driver and |
ccc6cda3 JA |
4570 | .BR bash . |
4571 | .PP | |
4572 | The shell associates a | |
4573 | .I job | |
4574 | with each pipeline. It keeps a table of currently executing | |
4575 | jobs, which may be listed with the | |
4576 | .B jobs | |
4577 | command. When | |
4578 | .B bash | |
4579 | starts a job asynchronously (in the | |
4580 | .IR background ), | |
4581 | it prints a line that looks like: | |
4582 | .RS | |
4583 | .PP | |
4584 | [1] 25647 | |
4585 | .RE | |
4586 | .PP | |
4587 | indicating that this job is job number 1 and that the process ID | |
4588 | of the last process in the pipeline associated with this job is 25647. | |
4589 | All of the processes in a single pipeline are members of the same job. | |
4590 | .B Bash | |
4591 | uses the | |
4592 | .I job | |
4593 | abstraction as the basis for job control. | |
4594 | .PP | |
4595 | To facilitate the implementation of the user interface to job | |
bb70624e | 4596 | control, the operating system maintains the notion of a \fIcurrent terminal |
ccc6cda3 JA |
4597 | process group ID\fP. Members of this process group (processes whose |
4598 | process group ID is equal to the current terminal process group ID) | |
4599 | receive keyboard-generated signals such as | |
4600 | .SM | |
4601 | .BR SIGINT . | |
4602 | These processes are said to be in the | |
4603 | .IR foreground . | |
4604 | .I Background | |
4605 | processes are those whose process group ID differs from the terminal's; | |
4606 | such processes are immune to keyboard-generated signals. | |
602bb739 CR |
4607 | Only foreground processes are allowed to read from or, if the |
4608 | user so specifies with \f(CWstty tostop\fP, write to the | |
4609 | terminal. | |
4610 | Background processes which attempt to read from (write to when | |
4611 | \f(CWstty tostop\fP is in effect) the | |
ccc6cda3 JA |
4612 | terminal are sent a |
4613 | .SM | |
4614 | .B SIGTTIN (SIGTTOU) | |
602bb739 | 4615 | signal by the kernel's terminal driver, |
ccc6cda3 JA |
4616 | which, unless caught, suspends the process. |
4617 | .PP | |
4618 | If the operating system on which | |
4619 | .B bash | |
4620 | is running supports | |
4621 | job control, | |
4622 | .B bash | |
bb70624e | 4623 | contains facilities to use it. |
ccc6cda3 JA |
4624 | Typing the |
4625 | .I suspend | |
4626 | character (typically | |
4627 | .BR ^Z , | |
4628 | Control-Z) while a process is running | |
bb70624e | 4629 | causes that process to be stopped and returns control to |
ccc6cda3 JA |
4630 | .BR bash . |
4631 | Typing the | |
4632 | .I "delayed suspend" | |
4633 | character (typically | |
4634 | .BR ^Y , | |
4635 | Control-Y) causes the process to be stopped when it | |
4636 | attempts to read input from the terminal, and control to | |
4637 | be returned to | |
4638 | .BR bash . | |
cce855bc | 4639 | The user may then manipulate the state of this job, using the |
ccc6cda3 JA |
4640 | .B bg |
4641 | command to continue it in the background, the | |
4642 | .B fg | |
4643 | command to continue it in the foreground, or | |
4644 | the | |
4645 | .B kill | |
4646 | command to kill it. A \fB^Z\fP takes effect immediately, | |
4647 | and has the additional side effect of causing pending output | |
4648 | and typeahead to be discarded. | |
4649 | .PP | |
4650 | There are a number of ways to refer to a job in the shell. | |
4651 | The character | |
4652 | .B % | |
8e1a6eaa | 4653 | introduces a job specification (\fIjobspec\fP). Job number |
ccc6cda3 JA |
4654 | .I n |
4655 | may be referred to as | |
4656 | .BR %n . | |
4657 | A job may also be referred to using a prefix of the name used to | |
4658 | start it, or using a substring that appears in its command line. | |
4659 | For example, | |
4660 | .B %ce | |
4661 | refers to a stopped | |
4662 | .B ce | |
4663 | job. If a prefix matches more than one job, | |
4664 | .B bash | |
4665 | reports an error. Using | |
4666 | .BR %?ce , | |
4667 | on the other hand, refers to any job containing the string | |
4668 | .B ce | |
4669 | in its command line. If the substring matches more than one job, | |
4670 | .B bash | |
4671 | reports an error. The symbols | |
4672 | .B %% | |
4673 | and | |
4674 | .B %+ | |
4675 | refer to the shell's notion of the | |
4676 | .IR "current job" , | |
4677 | which is the last job stopped while it was in | |
cce855bc | 4678 | the foreground or started in the background. |
ccc6cda3 JA |
4679 | The |
4680 | .I "previous job" | |
4681 | may be referenced using | |
4682 | .BR %\- . | |
e33f2203 CR |
4683 | If there is only a single job, \fB%+\fP and \fB%\-\fP can both be used |
4684 | to refer to that job. | |
ccc6cda3 JA |
4685 | In output pertaining to jobs (e.g., the output of the |
4686 | .B jobs | |
4687 | command), the current job is always flagged with a | |
4688 | .BR + , | |
4689 | and the previous job with a | |
4690 | .BR \- . | |
43df7bbb CR |
4691 | A single % (with no accompanying job specification) also refers to the |
4692 | current job. | |
726f6388 | 4693 | .PP |
ccc6cda3 JA |
4694 | Simply naming a job can be used to bring it into the |
4695 | foreground: | |
4696 | .B %1 | |
4697 | is a synonym for | |
4698 | \fB``fg %1''\fP, | |
4699 | bringing job 1 from the background into the foreground. | |
4700 | Similarly, | |
4701 | .B ``%1 &'' | |
4702 | resumes job 1 in the background, equivalent to | |
4703 | \fB``bg %1''\fP. | |
726f6388 | 4704 | .PP |
ccc6cda3 JA |
4705 | The shell learns immediately whenever a job changes state. |
4706 | Normally, | |
4707 | .B bash | |
4708 | waits until it is about to print a prompt before reporting | |
4709 | changes in a job's status so as to not interrupt | |
4710 | any other output. If the | |
4711 | .B \-b | |
4712 | option to the | |
726f6388 | 4713 | .B set |
ccc6cda3 | 4714 | builtin command |
cce855bc | 4715 | is enabled, |
726f6388 | 4716 | .B bash |
ccc6cda3 | 4717 | reports such changes immediately. |
f73dda09 JA |
4718 | Any trap on |
4719 | .SM | |
4720 | .B SIGCHLD | |
4721 | is executed for each child that exits. | |
726f6388 | 4722 | .PP |
ccc6cda3 JA |
4723 | If an attempt to exit |
4724 | .B bash | |
d3ad40de CR |
4725 | is made while jobs are stopped (or, if the \fBcheckjobs\fP shell option has |
4726 | been enabled using the \fBshopt\fP builtin, running), the shell prints a | |
4727 | warning message, and, if the \fBcheckjobs\fP option is enabled, lists the | |
4728 | jobs and their statuses. | |
4729 | The | |
ccc6cda3 | 4730 | .B jobs |
d3ad40de | 4731 | command may then be used to inspect their status. |
ccc6cda3 | 4732 | If a second attempt to exit is made without an intervening command, |
d3ad40de | 4733 | the shell does not print another warning, and any stopped |
ccc6cda3 | 4734 | jobs are terminated. |
726f6388 JA |
4735 | .SH PROMPTING |
4736 | When executing interactively, | |
4737 | .B bash | |
4738 | displays the primary prompt | |
4739 | .SM | |
4740 | .B PS1 | |
4741 | when it is ready to read a command, and the secondary prompt | |
4742 | .SM | |
4743 | .B PS2 | |
4744 | when it needs more input to complete a command. | |
4745 | .B Bash | |
4746 | allows these prompt strings to be customized by inserting a number of | |
4747 | backslash-escaped special characters that are decoded as follows: | |
4748 | .RS | |
4749 | .PD 0 | |
4750 | .TP | |
ccc6cda3 JA |
4751 | .B \ea |
4752 | an ASCII bell character (07) | |
726f6388 JA |
4753 | .TP |
4754 | .B \ed | |
4755 | the date in "Weekday Month Date" format (e.g., "Tue May 26") | |
4756 | .TP | |
7117c2d2 JA |
4757 | .B \eD{\fIformat\fP} |
4758 | the \fIformat\fP is passed to \fIstrftime\fP(3) and the result is inserted | |
4759 | into the prompt string; an empty \fIformat\fP results in a locale-specific | |
4760 | time representation. The braces are required | |
4761 | .TP | |
ccc6cda3 JA |
4762 | .B \ee |
4763 | an ASCII escape character (033) | |
4764 | .TP | |
4765 | .B \eh | |
4766 | the hostname up to the first `.' | |
4767 | .TP | |
4768 | .B \eH | |
4769 | the hostname | |
4770 | .TP | |
bb70624e JA |
4771 | .B \ej |
4772 | the number of jobs currently managed by the shell | |
4773 | .TP | |
4774 | .B \el | |
4775 | the basename of the shell's terminal device name | |
4776 | .TP | |
726f6388 JA |
4777 | .B \en |
4778 | newline | |
4779 | .TP | |
cce855bc JA |
4780 | .B \er |
4781 | carriage return | |
4782 | .TP | |
726f6388 JA |
4783 | .B \es |
4784 | the name of the shell, the basename of | |
4785 | .B $0 | |
4786 | (the portion following the final slash) | |
4787 | .TP | |
ccc6cda3 JA |
4788 | .B \et |
4789 | the current time in 24-hour HH:MM:SS format | |
726f6388 | 4790 | .TP |
ccc6cda3 JA |
4791 | .B \eT |
4792 | the current time in 12-hour HH:MM:SS format | |
4793 | .TP | |
4794 | .B \e@ | |
4795 | the current time in 12-hour am/pm format | |
726f6388 | 4796 | .TP |
f73dda09 JA |
4797 | .B \eA |
4798 | the current time in 24-hour HH:MM format | |
4799 | .TP | |
726f6388 JA |
4800 | .B \eu |
4801 | the username of the current user | |
4802 | .TP | |
ccc6cda3 JA |
4803 | .B \ev |
4804 | the version of \fBbash\fP (e.g., 2.00) | |
726f6388 | 4805 | .TP |
ccc6cda3 | 4806 | .B \eV |
a5e25162 | 4807 | the release of \fBbash\fP, version + patch level (e.g., 2.00.0) |
ccc6cda3 JA |
4808 | .TP |
4809 | .B \ew | |
984a1947 CR |
4810 | the current working directory, with |
4811 | .SM | |
4812 | .B $HOME | |
4813 | abbreviated with a tilde | |
4814 | (uses the value of the | |
4815 | .SM | |
4816 | .B PROMPT_DIRTRIM | |
4817 | variable) | |
ccc6cda3 JA |
4818 | .TP |
4819 | .B \eW | |
984a1947 CR |
4820 | the basename of the current working directory, with |
4821 | .SM | |
4822 | .B $HOME | |
12d937f9 | 4823 | abbreviated with a tilde |
726f6388 JA |
4824 | .TP |
4825 | .B \e! | |
4826 | the history number of this command | |
4827 | .TP | |
ccc6cda3 JA |
4828 | .B \e# |
4829 | the command number of this command | |
4830 | .TP | |
726f6388 JA |
4831 | .B \e$ |
4832 | if the effective UID is 0, a | |
4833 | .BR # , | |
4834 | otherwise a | |
4835 | .B $ | |
4836 | .TP | |
ccc6cda3 JA |
4837 | .B \e\fInnn\fP |
4838 | the character corresponding to the octal number \fInnn\fP | |
726f6388 JA |
4839 | .TP |
4840 | .B \e\e | |
4841 | a backslash | |
4842 | .TP | |
4843 | .B \e[ | |
4844 | begin a sequence of non-printing characters, which could be used to | |
4845 | embed a terminal control sequence into the prompt | |
4846 | .TP | |
4847 | .B \e] | |
4848 | end a sequence of non-printing characters | |
4849 | .PD | |
4850 | .RE | |
4851 | .PP | |
4852 | The command number and the history number are usually different: | |
4853 | the history number of a command is its position in the history | |
4854 | list, which may include commands restored from the history file | |
4855 | (see | |
4856 | .SM | |
4857 | .B HISTORY | |
4858 | below), while the command number is the position in the sequence | |
4859 | of commands executed during the current shell session. | |
4860 | After the string is decoded, it is expanded via | |
bb70624e JA |
4861 | parameter expansion, command substitution, arithmetic |
4862 | expansion, and quote removal, subject to the value of the | |
ccc6cda3 JA |
4863 | .B promptvars |
4864 | shell option (see the description of the | |
4865 | .B shopt | |
4866 | command under | |
4867 | .SM | |
4868 | .B "SHELL BUILTIN COMMANDS" | |
4869 | below). | |
726f6388 JA |
4870 | .SH READLINE |
4871 | This is the library that handles reading input when using an interactive | |
4872 | shell, unless the | |
d166f048 | 4873 | .B \-\-noediting |
ccc6cda3 | 4874 | option is given at shell invocation. |
14e8b2a7 CR |
4875 | Line editing is also used when using the \fB\-e\fP option to the |
4876 | \fBread\fP builtin. | |
dc60d4e0 | 4877 | By default, the line editing commands are similar to those of Emacs. |
726f6388 | 4878 | A vi-style line editing interface is also available. |
14e8b2a7 CR |
4879 | Line editing can be enabled at any time using the |
4880 | .B \-o emacs | |
ccc6cda3 | 4881 | or |
14e8b2a7 | 4882 | .B \-o vi |
ccc6cda3 JA |
4883 | options to the |
4884 | .B set | |
4885 | builtin (see | |
4886 | .SM | |
4887 | .B SHELL BUILTIN COMMANDS | |
4888 | below). | |
14e8b2a7 CR |
4889 | To turn off line editing after the shell is running, use the |
4890 | .B +o emacs | |
4891 | or | |
4892 | .B +o vi | |
4893 | options to the | |
4894 | .B set | |
4895 | builtin. | |
ccc6cda3 | 4896 | .SS "Readline Notation" |
726f6388 | 4897 | .PP |
dc60d4e0 | 4898 | In this section, the Emacs-style notation is used to denote |
726f6388 JA |
4899 | keystrokes. Control keys are denoted by C\-\fIkey\fR, e.g., C\-n |
4900 | means Control\-N. Similarly, | |
4901 | .I meta | |
4902 | keys are denoted by M\-\fIkey\fR, so M\-x means Meta\-X. (On keyboards | |
4903 | without a | |
4904 | .I meta | |
4905 | key, M\-\fIx\fP means ESC \fIx\fP, i.e., press the Escape key | |
4906 | then the | |
4907 | .I x | |
4908 | key. This makes ESC the \fImeta prefix\fP. | |
4909 | The combination M\-C\-\fIx\fP means ESC\-Control\-\fIx\fP, | |
4910 | or press the Escape key | |
4911 | then hold the Control key while pressing the | |
4912 | .I x | |
4913 | key.) | |
4914 | .PP | |
ccc6cda3 JA |
4915 | Readline commands may be given numeric |
4916 | .IR arguments , | |
4917 | which normally act as a repeat count. | |
4918 | Sometimes, however, it is the sign of the argument that is significant. | |
4919 | Passing a negative argument to a command that acts in the forward | |
4920 | direction (e.g., \fBkill\-line\fP) causes that command to act in a | |
4921 | backward direction. | |
4922 | Commands whose behavior with arguments deviates from this are noted | |
4923 | below. | |
4924 | .PP | |
4925 | When a command is described as \fIkilling\fP text, the text | |
4926 | deleted is saved for possible future retrieval | |
4927 | (\fIyanking\fP). The killed text is saved in a | |
4928 | \fIkill ring\fP. Consecutive kills cause the text to be | |
4929 | accumulated into one unit, which can be yanked all at once. | |
4930 | Commands which do not kill text separate the chunks of text | |
4931 | on the kill ring. | |
4932 | .SS "Readline Initialization" | |
4933 | .PP | |
4934 | Readline is customized by putting commands in an initialization | |
4935 | file (the \fIinputrc\fP file). | |
4936 | The name of this file is taken from the value of the | |
726f6388 | 4937 | .SM |
ccc6cda3 JA |
4938 | .B INPUTRC |
4939 | variable. If that variable is unset, the default is | |
726f6388 | 4940 | .IR ~/.inputrc . |
ccc6cda3 JA |
4941 | When a program which uses the readline library starts up, the |
4942 | initialization file is read, and the key bindings and variables | |
4943 | are set. | |
4944 | There are only a few basic constructs allowed in the | |
4945 | readline initialization file. | |
4946 | Blank lines are ignored. | |
4947 | Lines beginning with a \fB#\fP are comments. | |
4948 | Lines beginning with a \fB$\fP indicate conditional constructs. | |
4949 | Other lines denote key bindings and variable settings. | |
4950 | .PP | |
4951 | The default key-bindings may be changed with an | |
4952 | .I inputrc | |
4953 | file. | |
726f6388 JA |
4954 | Other programs that use this library may add their own commands |
4955 | and bindings. | |
4956 | .PP | |
4957 | For example, placing | |
4958 | .RS | |
4959 | .PP | |
4960 | M\-Control\-u: universal\-argument | |
4961 | .RE | |
4962 | or | |
4963 | .RS | |
4964 | C\-Meta\-u: universal\-argument | |
4965 | .RE | |
4966 | into the | |
ccc6cda3 | 4967 | .I inputrc |
726f6388 JA |
4968 | would make M\-C\-u execute the readline command |
4969 | .IR universal\-argument . | |
4970 | .PP | |
4971 | The following symbolic character names are recognized: | |
4972 | .IR RUBOUT , | |
4973 | .IR DEL , | |
4974 | .IR ESC , | |
4975 | .IR LFD , | |
4976 | .IR NEWLINE , | |
4977 | .IR RET , | |
4978 | .IR RETURN , | |
4979 | .IR SPC , | |
4980 | .IR SPACE , | |
4981 | and | |
4982 | .IR TAB . | |
bb70624e | 4983 | .PP |
726f6388 JA |
4984 | In addition to command names, readline allows keys to be bound |
4985 | to a string that is inserted when the key is pressed (a \fImacro\fP). | |
ccc6cda3 | 4986 | .SS "Readline Key Bindings" |
726f6388 JA |
4987 | .PP |
4988 | The syntax for controlling key bindings in the | |
cce855bc | 4989 | .I inputrc |
726f6388 JA |
4990 | file is simple. All that is required is the name of the |
4991 | command or the text of a macro and a key sequence to which | |
4992 | it should be bound. The name may be specified in one of two ways: | |
ccc6cda3 | 4993 | as a symbolic key name, possibly with \fIMeta\-\fP or \fIControl\-\fP |
726f6388 | 4994 | prefixes, or as a key sequence. |
28ef6c31 | 4995 | .PP |
cce855bc | 4996 | When using the form \fBkeyname\fP:\^\fIfunction\-name\fP or \fImacro\fP, |
726f6388 JA |
4997 | .I keyname |
4998 | is the name of a key spelled out in English. For example: | |
4999 | .sp | |
5000 | .RS | |
5001 | Control-u: universal\-argument | |
5002 | .br | |
5003 | Meta-Rubout: backward-kill-word | |
5004 | .br | |
ccc6cda3 | 5005 | Control-o: "> output" |
726f6388 JA |
5006 | .RE |
5007 | .LP | |
5008 | In the above example, | |
ccc6cda3 | 5009 | .I C\-u |
726f6388 JA |
5010 | is bound to the function |
5011 | .BR universal\-argument , | |
ccc6cda3 | 5012 | .I M\-DEL |
726f6388 JA |
5013 | is bound to the function |
5014 | .BR backward\-kill\-word , | |
5015 | and | |
ccc6cda3 | 5016 | .I C\-o |
726f6388 JA |
5017 | is bound to run the macro |
5018 | expressed on the right hand side (that is, to insert the text | |
28ef6c31 JA |
5019 | .if t \f(CW> output\fP |
5020 | .if n ``> output'' | |
726f6388 JA |
5021 | into the line). |
5022 | .PP | |
cce855bc | 5023 | In the second form, \fB"keyseq"\fP:\^\fIfunction\-name\fP or \fImacro\fP, |
726f6388 JA |
5024 | .B keyseq |
5025 | differs from | |
5026 | .B keyname | |
5027 | above in that strings denoting | |
5028 | an entire key sequence may be specified by placing the sequence | |
5029 | within double quotes. Some GNU Emacs style key escapes can be | |
28ef6c31 JA |
5030 | used, as in the following example, but the symbolic character names |
5031 | are not recognized. | |
726f6388 JA |
5032 | .sp |
5033 | .RS | |
ccc6cda3 | 5034 | "\eC\-u": universal\-argument |
726f6388 | 5035 | .br |
ccc6cda3 | 5036 | "\eC\-x\eC\-r": re\-read\-init\-file |
726f6388 JA |
5037 | .br |
5038 | "\ee[11~": "Function Key 1" | |
5039 | .RE | |
5040 | .PP | |
5041 | In this example, | |
ccc6cda3 | 5042 | .I C\-u |
726f6388 JA |
5043 | is again bound to the function |
5044 | .BR universal\-argument . | |
ccc6cda3 | 5045 | .I "C\-x C\-r" |
726f6388 JA |
5046 | is bound to the function |
5047 | .BR re\-read\-init\-file , | |
5048 | and | |
5049 | .I "ESC [ 1 1 ~" | |
5050 | is bound to insert the text | |
28ef6c31 JA |
5051 | .if t \f(CWFunction Key 1\fP. |
5052 | .if n ``Function Key 1''. | |
5053 | .PP | |
cce855bc | 5054 | The full set of GNU Emacs style escape sequences is |
726f6388 | 5055 | .RS |
cce855bc | 5056 | .PD 0 |
726f6388 JA |
5057 | .TP |
5058 | .B \eC\- | |
5059 | control prefix | |
5060 | .TP | |
ccc6cda3 | 5061 | .B \eM\- |
726f6388 JA |
5062 | meta prefix |
5063 | .TP | |
5064 | .B \ee | |
5065 | an escape character | |
5066 | .TP | |
5067 | .B \e\e | |
5068 | backslash | |
5069 | .TP | |
5070 | .B \e" | |
5071 | literal " | |
5072 | .TP | |
20587658 CR |
5073 | .B \e\(aq |
5074 | literal \(aq | |
726f6388 | 5075 | .RE |
cce855bc JA |
5076 | .PD |
5077 | .PP | |
5078 | In addition to the GNU Emacs style escape sequences, a second | |
5079 | set of backslash escapes is available: | |
5080 | .RS | |
5081 | .PD 0 | |
5082 | .TP | |
5083 | .B \ea | |
5084 | alert (bell) | |
5085 | .TP | |
5086 | .B \eb | |
5087 | backspace | |
5088 | .TP | |
5089 | .B \ed | |
5090 | delete | |
5091 | .TP | |
5092 | .B \ef | |
5093 | form feed | |
5094 | .TP | |
5095 | .B \en | |
5096 | newline | |
5097 | .TP | |
5098 | .B \er | |
5099 | carriage return | |
5100 | .TP | |
5101 | .B \et | |
5102 | horizontal tab | |
5103 | .TP | |
5104 | .B \ev | |
5105 | vertical tab | |
5106 | .TP | |
5107 | .B \e\fInnn\fP | |
f73dda09 | 5108 | the eight-bit character whose value is the octal value \fInnn\fP |
cce855bc JA |
5109 | (one to three digits) |
5110 | .TP | |
f73dda09 JA |
5111 | .B \ex\fIHH\fP |
5112 | the eight-bit character whose value is the hexadecimal value \fIHH\fP | |
5113 | (one or two hex digits) | |
cce855bc JA |
5114 | .RE |
5115 | .PD | |
726f6388 | 5116 | .PP |
cce855bc JA |
5117 | When entering the text of a macro, single or double quotes must |
5118 | be used to indicate a macro definition. | |
5119 | Unquoted text is assumed to be a function name. | |
5120 | In the macro body, the backslash escapes described above are expanded. | |
5121 | Backslash will quote any other character in the macro text, | |
20587658 | 5122 | including " and \(aq. |
726f6388 JA |
5123 | .PP |
5124 | .B Bash | |
5125 | allows the current readline key bindings to be displayed or modified | |
5126 | with the | |
5127 | .B bind | |
5128 | builtin command. The editing mode may be switched during interactive | |
5129 | use by using the | |
5130 | .B \-o | |
5131 | option to the | |
5132 | .B set | |
5133 | builtin command (see | |
5134 | .SM | |
5135 | .B SHELL BUILTIN COMMANDS | |
5136 | below). | |
ccc6cda3 | 5137 | .SS "Readline Variables" |
726f6388 JA |
5138 | .PP |
5139 | Readline has variables that can be used to further customize its | |
5140 | behavior. A variable may be set in the | |
5141 | .I inputrc | |
5142 | file with a statement of the form | |
5143 | .RS | |
5144 | .PP | |
5145 | \fBset\fP \fIvariable\-name\fP \fIvalue\fP | |
5146 | .RE | |
5147 | .PP | |
5148 | Except where noted, readline variables can take the values | |
5149 | .B On | |
5150 | or | |
ff247e74 CR |
5151 | .B Off |
5152 | (without regard to case). | |
5153 | Unrecognized variable names are ignored. | |
5154 | When a variable value is read, empty or null values, "on" (case-insensitive), | |
5155 | and "1" are equivalent to \fBOn\fP. All other values are equivalent to | |
5156 | \fBOff\fP. | |
726f6388 JA |
5157 | The variables and their default values are: |
5158 | .PP | |
5159 | .PD 0 | |
5160 | .TP | |
726f6388 JA |
5161 | .B bell\-style (audible) |
5162 | Controls what happens when readline wants to ring the terminal bell. | |
5163 | If set to \fBnone\fP, readline never rings the bell. If set to | |
5164 | \fBvisible\fP, readline uses a visible bell if one is available. | |
5165 | If set to \fBaudible\fP, readline attempts to ring the terminal's bell. | |
5166 | .TP | |
453f278a CR |
5167 | .B bind\-tty\-special\-chars (On) |
5168 | If set to \fBOn\fP, readline attempts to bind the control characters | |
5169 | treated specially by the kernel's terminal driver to their readline | |
5170 | equivalents. | |
5171 | .TP | |
5a318736 CR |
5172 | .B colored\-stats (Off) |
5173 | If set to \fBOn\fP, readline displays possible completions using different | |
5174 | colors to indicate their file type. | |
5175 | The color definitions are taken from the value of the \fBLS_COLORS\fP | |
5176 | environment variable. | |
5177 | .TP | |
726f6388 | 5178 | .B comment\-begin (``#'') |
bb70624e | 5179 | The string that is inserted when the readline |
ccc6cda3 | 5180 | .B insert\-comment |
726f6388 | 5181 | command is executed. |
ccc6cda3 JA |
5182 | This command is bound to |
5183 | .B M\-# | |
5184 | in emacs mode and to | |
5185 | .B # | |
5186 | in vi command mode. | |
726f6388 | 5187 | .TP |
cce855bc JA |
5188 | .B completion\-ignore\-case (Off) |
5189 | If set to \fBOn\fP, readline performs filename matching and completion | |
5190 | in a case\-insensitive fashion. | |
5191 | .TP | |
f13513ff CR |
5192 | .B completion\-prefix\-display\-length (0) |
5193 | The length in characters of the common prefix of a list of possible | |
5194 | completions that is displayed without modification. When set to a | |
5195 | value greater than zero, common prefixes longer than this value are | |
5196 | replaced with an ellipsis when displaying possible completions. | |
5197 | .TP | |
726f6388 JA |
5198 | .B completion\-query\-items (100) |
5199 | This determines when the user is queried about viewing | |
5200 | the number of possible completions | |
5201 | generated by the \fBpossible\-completions\fP command. | |
5202 | It may be set to any integer value greater than or equal to | |
5203 | zero. If the number of possible completions is greater than | |
5204 | or equal to the value of this variable, the user is asked whether | |
5205 | or not he wishes to view them; otherwise they are simply listed | |
5206 | on the terminal. | |
5207 | .TP | |
ccc6cda3 JA |
5208 | .B convert\-meta (On) |
5209 | If set to \fBOn\fP, readline will convert characters with the | |
5210 | eighth bit set to an ASCII key sequence | |
bb70624e | 5211 | by stripping the eighth bit and prefixing an |
ccc6cda3 JA |
5212 | escape character (in effect, using escape as the \fImeta prefix\fP). |
5213 | .TP | |
5214 | .B disable\-completion (Off) | |
5215 | If set to \fBOn\fP, readline will inhibit word completion. Completion | |
5216 | characters will be inserted into the line as if they had been | |
5217 | mapped to \fBself-insert\fP. | |
5218 | .TP | |
5219 | .B editing\-mode (emacs) | |
5220 | Controls whether readline begins with a set of key bindings similar | |
dc60d4e0 | 5221 | to \fIEmacs\fP or \fIvi\fP. |
ccc6cda3 JA |
5222 | .B editing\-mode |
5223 | can be set to either | |
5224 | .B emacs | |
5225 | or | |
5226 | .BR vi . | |
5227 | .TP | |
824dfe68 CR |
5228 | .B echo\-control\-characters (On) |
5229 | When set to \fBOn\fP, on operating systems that indicate they support it, | |
5230 | readline echoes a character corresponding to a signal generated from the | |
5231 | keyboard. | |
5232 | .TP | |
ccc6cda3 JA |
5233 | .B enable\-keypad (Off) |
5234 | When set to \fBOn\fP, readline will try to enable the application | |
5235 | keypad when it is called. Some systems need this to enable the | |
5236 | arrow keys. | |
5237 | .TP | |
08e72d7a CR |
5238 | .B enable\-meta\-key (On) |
5239 | When set to \fBOn\fP, readline will try to enable any meta modifier | |
5240 | key the terminal claims to support when it is called. On many terminals, | |
5241 | the meta key is used to send eight-bit characters. | |
5242 | .TP | |
ccc6cda3 | 5243 | .B expand\-tilde (Off) |
dc60d4e0 | 5244 | If set to \fBOn\fP, tilde expansion is performed when readline |
ccc6cda3 JA |
5245 | attempts word completion. |
5246 | .TP | |
cdb32d45 | 5247 | .B history\-preserve\-point (Off) |
dc60d4e0 | 5248 | If set to \fBOn\fP, the history code attempts to place point at the |
f75912ae | 5249 | same location on each history line retrieved with \fBprevious-history\fP |
f73dda09 JA |
5250 | or \fBnext-history\fP. |
5251 | .TP | |
1d0e1a34 CR |
5252 | .B history\-size (0) |
5253 | Set the maximum number of history entries saved in the history list. If | |
5254 | set to zero, the number of entries in the history list is not limited. | |
5255 | .TP | |
ccc6cda3 JA |
5256 | .B horizontal\-scroll\-mode (Off) |
5257 | When set to \fBOn\fP, makes readline use a single line for display, | |
5258 | scrolling the input horizontally on a single screen line when it | |
5259 | becomes longer than the screen width rather than wrapping to a new line. | |
5260 | .TP | |
5261 | .B input\-meta (Off) | |
5262 | If set to \fBOn\fP, readline will enable eight-bit input (that is, | |
5263 | it will not strip the high bit from the characters it reads), | |
5264 | regardless of what the terminal claims it can support. The name | |
5265 | .B meta\-flag | |
5266 | is a synonym for this variable. | |
5267 | .TP | |
b72432fd JA |
5268 | .B isearch\-terminators (``C\-[C\-J'') |
5269 | The string of characters that should terminate an incremental | |
5270 | search without subsequently executing the character as a command. | |
5271 | If this variable has not been given a value, the characters | |
5272 | \fIESC\fP and \fIC\-J\fP will terminate an incremental search. | |
5273 | .TP | |
726f6388 | 5274 | .B keymap (emacs) |
cce855bc | 5275 | Set the current readline keymap. The set of valid keymap names is |
ccc6cda3 JA |
5276 | \fIemacs, emacs\-standard, emacs\-meta, emacs\-ctlx, vi, |
5277 | vi\-command\fP, and | |
5278 | .IR vi\-insert . | |
5279 | \fIvi\fP is equivalent to \fIvi\-command\fP; \fIemacs\fP is | |
5280 | equivalent to \fIemacs\-standard\fP. The default value is | |
726f6388 JA |
5281 | .IR emacs ; |
5282 | the value of | |
5283 | .B editing\-mode | |
5284 | also affects the default keymap. | |
5285 | .TP | |
abe2eb5b CR |
5286 | .B keyseq\-timeout (500) |
5287 | Specifies the duration \fIreadline\fP will wait for a character when reading an | |
5288 | ambiguous key sequence (one that can form a complete key sequence using | |
5289 | the input read so far, or can take additional input to complete a longer | |
5290 | key sequence). | |
5291 | If no input is received within the timeout, \fIreadline\fP will use the shorter | |
5292 | but complete key sequence. | |
5293 | The value is specified in milliseconds, so a value of 1000 means that | |
5294 | \fIreadline\fP will wait one second for additional input. | |
5295 | If this variable is set to a value less than or equal to zero, or to a | |
5296 | non-numeric value, \fIreadline\fP will wait until another key is pressed to | |
5297 | decide which key sequence to complete. | |
5298 | .TP | |
ccc6cda3 JA |
5299 | .B mark\-directories (On) |
5300 | If set to \fBOn\fP, completed directory names have a slash | |
5301 | appended. | |
5302 | .TP | |
5303 | .B mark\-modified\-lines (Off) | |
5304 | If set to \fBOn\fP, history lines that have been modified are displayed | |
5305 | with a preceding asterisk (\fB*\fP). | |
5306 | .TP | |
7117c2d2 JA |
5307 | .B mark\-symlinked\-directories (Off) |
5308 | If set to \fBOn\fP, completed names which are symbolic links to directories | |
5309 | have a slash appended (subject to the value of | |
5310 | \fBmark\-directories\fP). | |
5311 | .TP | |
f73dda09 JA |
5312 | .B match\-hidden\-files (On) |
5313 | This variable, when set to \fBOn\fP, causes readline to match files whose | |
5314 | names begin with a `.' (hidden files) when performing filename | |
112ff2a6 CR |
5315 | completion. |
5316 | If set to \fBOff\fP, the leading `.' must be | |
f73dda09 JA |
5317 | supplied by the user in the filename to be completed. |
5318 | .TP | |
d7c725b5 CR |
5319 | .B menu\-complete\-display\-prefix (Off) |
5320 | If set to \fBOn\fP, menu completion displays the common prefix of the | |
5321 | list of possible completions (which may be empty) before cycling through | |
5322 | the list. | |
5323 | .TP | |
ccc6cda3 JA |
5324 | .B output\-meta (Off) |
5325 | If set to \fBOn\fP, readline will display characters with the | |
5326 | eighth bit set directly rather than as a meta-prefixed escape | |
5327 | sequence. | |
5328 | .TP | |
7117c2d2 JA |
5329 | .B page\-completions (On) |
5330 | If set to \fBOn\fP, readline uses an internal \fImore\fP-like pager | |
5331 | to display a screenful of possible completions at a time. | |
5332 | .TP | |
cce855bc JA |
5333 | .B print\-completions\-horizontally (Off) |
5334 | If set to \fBOn\fP, readline will display completions with matches | |
5335 | sorted horizontally in alphabetical order, rather than down the screen. | |
f13513ff CR |
5336 | .TP |
5337 | .B revert\-all\-at\-newline (Off) | |
dc60d4e0 | 5338 | If set to \fBOn\fP, readline will undo all changes to history lines |
f13513ff CR |
5339 | before returning when \fBaccept\-line\fP is executed. By default, |
5340 | history lines may be modified and retain individual undo lists across | |
5341 | calls to \fBreadline\fP. | |
cce855bc | 5342 | .TP |
726f6388 JA |
5343 | .B show\-all\-if\-ambiguous (Off) |
5344 | This alters the default behavior of the completion functions. If | |
5345 | set to | |
dc60d4e0 | 5346 | .BR On , |
726f6388 JA |
5347 | words which have more than one possible completion cause the |
5348 | matches to be listed immediately instead of ringing the bell. | |
5349 | .TP | |
d3a24ed2 CR |
5350 | .B show\-all\-if\-unmodified (Off) |
5351 | This alters the default behavior of the completion functions in | |
5352 | a fashion similar to \fBshow\-all\-if\-ambiguous\fP. | |
5353 | If set to | |
dc60d4e0 | 5354 | .BR On , |
d3a24ed2 CR |
5355 | words which have more than one possible completion without any |
5356 | possible partial completion (the possible completions don't share | |
5357 | a common prefix) cause the matches to be listed immediately instead | |
5358 | of ringing the bell. | |
5359 | .TP | |
8f714a7c CR |
5360 | .B skip\-completed\-text (Off) |
5361 | If set to \fBOn\fP, this alters the default completion behavior when | |
5362 | inserting a single match into the line. It's only active when | |
5363 | performing completion in the middle of a word. If enabled, readline | |
5364 | does not insert characters from the completion that match characters | |
5365 | after point in the word being completed, so portions of the word | |
5366 | following the cursor are not duplicated. | |
5367 | .TP | |
ccc6cda3 JA |
5368 | .B visible\-stats (Off) |
5369 | If set to \fBOn\fP, a character denoting a file's type as reported | |
5370 | by \fIstat\fP(2) is appended to the filename when listing possible | |
5371 | completions. | |
726f6388 | 5372 | .PD |
ccc6cda3 | 5373 | .SS "Readline Conditional Constructs" |
726f6388 JA |
5374 | .PP |
5375 | Readline implements a facility similar in spirit to the conditional | |
5376 | compilation features of the C preprocessor which allows key | |
5377 | bindings and variable settings to be performed as the result | |
cce855bc | 5378 | of tests. There are four parser directives used. |
726f6388 JA |
5379 | .IP \fB$if\fP |
5380 | The | |
5381 | .B $if | |
5382 | construct allows bindings to be made based on the | |
5383 | editing mode, the terminal being used, or the application using | |
5384 | readline. The text of the test extends to the end of the line; | |
5385 | no characters are required to isolate it. | |
5386 | .RS | |
5387 | .IP \fBmode\fP | |
5388 | The \fBmode=\fP form of the \fB$if\fP directive is used to test | |
5389 | whether readline is in emacs or vi mode. | |
5390 | This may be used in conjunction | |
5391 | with the \fBset keymap\fP command, for instance, to set bindings in | |
ccc6cda3 | 5392 | the \fIemacs\-standard\fP and \fIemacs\-ctlx\fP keymaps only if |
726f6388 JA |
5393 | readline is starting out in emacs mode. |
5394 | .IP \fBterm\fP | |
5395 | The \fBterm=\fP form may be used to include terminal-specific | |
5396 | key bindings, perhaps to bind the key sequences output by the | |
5397 | terminal's function keys. The word on the right side of the | |
5398 | .B = | |
cce855bc | 5399 | is tested against the both full name of the terminal and the portion |
726f6388 JA |
5400 | of the terminal name before the first \fB\-\fP. This allows |
5401 | .I sun | |
5402 | to match both | |
5403 | .I sun | |
5404 | and | |
5405 | .IR sun\-cmd , | |
5406 | for instance. | |
5407 | .IP \fBapplication\fP | |
5408 | The \fBapplication\fP construct is used to include | |
ccc6cda3 | 5409 | application-specific settings. Each program using the readline |
726f6388 JA |
5410 | library sets the \fIapplication name\fP, and an initialization |
5411 | file can test for a particular value. | |
5412 | This could be used to bind key sequences to functions useful for | |
5413 | a specific program. For instance, the following command adds a | |
dc60d4e0 | 5414 | key sequence that quotes the current or previous word in \fBbash\fP: |
cce855bc | 5415 | .sp 1 |
726f6388 JA |
5416 | .RS |
5417 | .nf | |
5418 | \fB$if\fP Bash | |
5419 | # Quote the current or previous word | |
ccc6cda3 | 5420 | "\eC\-xq": "\eeb\e"\eef\e"" |
726f6388 JA |
5421 | \fB$endif\fP |
5422 | .fi | |
5423 | .RE | |
5424 | .RE | |
5425 | .IP \fB$endif\fP | |
cce855bc | 5426 | This command, as seen in the previous example, terminates an |
726f6388 JA |
5427 | \fB$if\fP command. |
5428 | .IP \fB$else\fP | |
5429 | Commands in this branch of the \fB$if\fP directive are executed if | |
5430 | the test fails. | |
cce855bc JA |
5431 | .IP \fB$include\fP |
5432 | This directive takes a single filename as an argument and reads commands | |
5433 | and bindings from that file. For example, the following directive | |
5434 | would read \fI/etc/inputrc\fP: | |
5435 | .sp 1 | |
5436 | .RS | |
5437 | .nf | |
5438 | \fB$include\fP \^ \fI/etc/inputrc\fP | |
5439 | .fi | |
5440 | .RE | |
ccc6cda3 | 5441 | .SS Searching |
726f6388 | 5442 | .PP |
ccc6cda3 JA |
5443 | Readline provides commands for searching through the command history |
5444 | (see | |
5445 | .SM | |
5446 | .B HISTORY | |
5447 | below) for lines containing a specified string. | |
5448 | There are two search modes: | |
5449 | .I incremental | |
5450 | and | |
5451 | .IR non-incremental . | |
5452 | .PP | |
5453 | Incremental searches begin before the user has finished typing the | |
5454 | search string. | |
5455 | As each character of the search string is typed, readline displays | |
5456 | the next entry from the history matching the string typed so far. | |
5457 | An incremental search requires only as many characters as needed to | |
5458 | find the desired history entry. | |
bb70624e | 5459 | The characters present in the value of the \fBisearch-terminators\fP |
b72432fd JA |
5460 | variable are used to terminate an incremental search. |
5461 | If that variable has not been assigned a value the Escape and | |
5462 | Control-J characters will terminate an incremental search. | |
ccc6cda3 JA |
5463 | Control-G will abort an incremental search and restore the original |
5464 | line. | |
5465 | When the search is terminated, the history entry containing the | |
5466 | search string becomes the current line. | |
bb70624e | 5467 | .PP |
ccc6cda3 JA |
5468 | To find other matching entries in the history list, type Control-S or |
5469 | Control-R as appropriate. | |
5470 | This will search backward or forward in the history for the next | |
5471 | entry matching the search string typed so far. | |
5472 | Any other key sequence bound to a readline command will terminate | |
5473 | the search and execute that command. | |
5474 | For instance, a \fInewline\fP will terminate the search and accept | |
5475 | the line, thereby executing the command from the history list. | |
5476 | .PP | |
f73dda09 JA |
5477 | Readline remembers the last incremental search string. If two |
5478 | Control-Rs are typed without any intervening characters defining a | |
5479 | new search string, any remembered search string is used. | |
5480 | .PP | |
ccc6cda3 JA |
5481 | Non-incremental searches read the entire search string before starting |
5482 | to search for matching history lines. The search string may be | |
cce855bc | 5483 | typed by the user or be part of the contents of the current line. |
ccc6cda3 | 5484 | .SS "Readline Command Names" |
726f6388 JA |
5485 | .PP |
5486 | The following is a list of the names of the commands and the default | |
5487 | key sequences to which they are bound. | |
ccc6cda3 | 5488 | Command names without an accompanying key sequence are unbound by default. |
bb70624e JA |
5489 | In the following descriptions, \fIpoint\fP refers to the current cursor |
5490 | position, and \fImark\fP refers to a cursor position saved by the | |
5491 | \fBset\-mark\fP command. | |
5492 | The text between the point and mark is referred to as the \fIregion\fP. | |
726f6388 JA |
5493 | .SS Commands for Moving |
5494 | .PP | |
5495 | .PD 0 | |
5496 | .TP | |
5497 | .B beginning\-of\-line (C\-a) | |
5498 | Move to the start of the current line. | |
5499 | .TP | |
5500 | .B end\-of\-line (C\-e) | |
5501 | Move to the end of the line. | |
5502 | .TP | |
5503 | .B forward\-char (C\-f) | |
5504 | Move forward a character. | |
5505 | .TP | |
5506 | .B backward\-char (C\-b) | |
5507 | Move back a character. | |
5508 | .TP | |
5509 | .B forward\-word (M\-f) | |
5510 | Move forward to the end of the next word. Words are composed of | |
5511 | alphanumeric characters (letters and digits). | |
5512 | .TP | |
5513 | .B backward\-word (M\-b) | |
8c2fef19 CR |
5514 | Move back to the start of the current or previous word. |
5515 | Words are composed of alphanumeric characters (letters and digits). | |
5516 | .TP | |
5517 | .B shell\-forward\-word | |
5518 | Move forward to the end of the next word. | |
5519 | Words are delimited by non-quoted shell metacharacters. | |
5520 | .TP | |
5521 | .B shell\-backward\-word | |
5522 | Move back to the start of the current or previous word. | |
5523 | Words are delimited by non-quoted shell metacharacters. | |
726f6388 JA |
5524 | .TP |
5525 | .B clear\-screen (C\-l) | |
5526 | Clear the screen leaving the current line at the top of the screen. | |
5527 | With an argument, refresh the current line without clearing the | |
5528 | screen. | |
5529 | .TP | |
5530 | .B redraw\-current\-line | |
ccc6cda3 | 5531 | Refresh the current line. |
726f6388 JA |
5532 | .PD |
5533 | .SS Commands for Manipulating the History | |
5534 | .PP | |
5535 | .PD 0 | |
5536 | .TP | |
5537 | .B accept\-line (Newline, Return) | |
5538 | Accept the line regardless of where the cursor is. If this line is | |
ccc6cda3 | 5539 | non-empty, add it to the history list according to the state of the |
726f6388 JA |
5540 | .SM |
5541 | .B HISTCONTROL | |
5542 | variable. If the line is a modified history | |
5543 | line, then restore the history line to its original state. | |
5544 | .TP | |
5545 | .B previous\-history (C\-p) | |
5546 | Fetch the previous command from the history list, moving back in | |
5547 | the list. | |
5548 | .TP | |
5549 | .B next\-history (C\-n) | |
5550 | Fetch the next command from the history list, moving forward in the | |
5551 | list. | |
5552 | .TP | |
5553 | .B beginning\-of\-history (M\-<) | |
5554 | Move to the first line in the history. | |
5555 | .TP | |
5556 | .B end\-of\-history (M\->) | |
5557 | Move to the end of the input history, i.e., the line currently being | |
5558 | entered. | |
5559 | .TP | |
5560 | .B reverse\-search\-history (C\-r) | |
5561 | Search backward starting at the current line and moving `up' through | |
5562 | the history as necessary. This is an incremental search. | |
5563 | .TP | |
5564 | .B forward\-search\-history (C\-s) | |
5565 | Search forward starting at the current line and moving `down' through | |
5566 | the history as necessary. This is an incremental search. | |
5567 | .TP | |
5568 | .B non\-incremental\-reverse\-search\-history (M\-p) | |
5569 | Search backward through the history starting at the current line | |
ccc6cda3 | 5570 | using a non-incremental search for a string supplied by the user. |
726f6388 JA |
5571 | .TP |
5572 | .B non\-incremental\-forward\-search\-history (M\-n) | |
ccc6cda3 | 5573 | Search forward through the history using a non-incremental search for |
726f6388 JA |
5574 | a string supplied by the user. |
5575 | .TP | |
5576 | .B history\-search\-forward | |
5577 | Search forward through the history for the string of characters | |
bb70624e | 5578 | between the start of the current line and the point. |
ccc6cda3 | 5579 | This is a non-incremental search. |
726f6388 JA |
5580 | .TP |
5581 | .B history\-search\-backward | |
5582 | Search backward through the history for the string of characters | |
ccc6cda3 JA |
5583 | between the start of the current line and the point. |
5584 | This is a non-incremental search. | |
726f6388 JA |
5585 | .TP |
5586 | .B yank\-nth\-arg (M\-C\-y) | |
5587 | Insert the first argument to the previous command (usually | |
28ef6c31 JA |
5588 | the second word on the previous line) at point. |
5589 | With an argument | |
726f6388 JA |
5590 | .IR n , |
5591 | insert the \fIn\fPth word from the previous command (the words | |
5592 | in the previous command begin with word 0). A negative argument | |
5593 | inserts the \fIn\fPth word from the end of the previous command. | |
eb2bb562 CR |
5594 | Once the argument \fIn\fP is computed, the argument is extracted |
5595 | as if the "!\fIn\fP" history expansion had been specified. | |
726f6388 JA |
5596 | .TP |
5597 | .B | |
5598 | yank\-last\-arg (M\-.\^, M\-_\^) | |
ccc6cda3 | 5599 | Insert the last argument to the previous command (the last word of |
adc6cff5 CR |
5600 | the previous history entry). |
5601 | With a numeric argument, behave exactly like \fByank\-nth\-arg\fP. | |
cce855bc | 5602 | Successive calls to \fByank\-last\-arg\fP move back through the history |
adc6cff5 CR |
5603 | list, inserting the last word (or the word specified by the argument to |
5604 | the first call) of each line in turn. | |
5605 | Any numeric argument supplied to these successive calls determines | |
5606 | the direction to move through the history. A negative argument switches | |
5607 | the direction through the history (back or forward). | |
eb2bb562 CR |
5608 | The history expansion facilities are used to extract the last argument, |
5609 | as if the "!$" history expansion had been specified. | |
726f6388 JA |
5610 | .TP |
5611 | .B shell\-expand\-line (M\-C\-e) | |
cce855bc | 5612 | Expand the line as the shell does. This |
726f6388 JA |
5613 | performs alias and history expansion as well as all of the shell |
5614 | word expansions. See | |
5615 | .SM | |
5616 | .B HISTORY EXPANSION | |
5617 | below for a description of history expansion. | |
5618 | .TP | |
5619 | .B history\-expand\-line (M\-^) | |
d166f048 JA |
5620 | Perform history expansion on the current line. |
5621 | See | |
726f6388 JA |
5622 | .SM |
5623 | .B HISTORY EXPANSION | |
5624 | below for a description of history expansion. | |
5625 | .TP | |
cce855bc JA |
5626 | .B magic\-space |
5627 | Perform history expansion on the current line and insert a space. | |
5628 | See | |
5629 | .SM | |
5630 | .B HISTORY EXPANSION | |
5631 | below for a description of history expansion. | |
5632 | .TP | |
d166f048 JA |
5633 | .B alias\-expand\-line |
5634 | Perform alias expansion on the current line. | |
5635 | See | |
5636 | .SM | |
5637 | .B ALIASES | |
5638 | above for a description of alias expansion. | |
5639 | .TP | |
5640 | .B history\-and\-alias\-expand\-line | |
5641 | Perform history and alias expansion on the current line. | |
5642 | .TP | |
726f6388 JA |
5643 | .B insert\-last\-argument (M\-.\^, M\-_\^) |
5644 | A synonym for \fByank\-last\-arg\fP. | |
5645 | .TP | |
ccc6cda3 | 5646 | .B operate\-and\-get\-next (C\-o) |
726f6388 JA |
5647 | Accept the current line for execution and fetch the next line |
5648 | relative to the current line from the history for editing. Any | |
5649 | argument is ignored. | |
7117c2d2 JA |
5650 | .TP |
5651 | .B edit\-and\-execute\-command (C\-xC\-e) | |
5652 | Invoke an editor on the current command line, and execute the result as shell | |
5653 | commands. | |
5654 | \fBBash\fP attempts to invoke | |
5655 | .SM | |
dd4f3dd8 | 5656 | .BR $VISUAL , |
7117c2d2 JA |
5657 | .SM |
5658 | .BR $EDITOR , | |
5659 | and \fIemacs\fP as the editor, in that order. | |
726f6388 JA |
5660 | .PD |
5661 | .SS Commands for Changing Text | |
5662 | .PP | |
5663 | .PD 0 | |
5664 | .TP | |
5665 | .B delete\-char (C\-d) | |
28ef6c31 | 5666 | Delete the character at point. If point is at the |
726f6388 | 5667 | beginning of the line, there are no characters in the line, and |
cce855bc | 5668 | the last character typed was not bound to \fBdelete\-char\fP, |
726f6388 JA |
5669 | then return |
5670 | .SM | |
5671 | .BR EOF . | |
5672 | .TP | |
5673 | .B backward\-delete\-char (Rubout) | |
5674 | Delete the character behind the cursor. When given a numeric argument, | |
ccc6cda3 | 5675 | save the deleted text on the kill ring. |
726f6388 | 5676 | .TP |
b72432fd JA |
5677 | .B forward\-backward\-delete\-char |
5678 | Delete the character under the cursor, unless the cursor is at the | |
5679 | end of the line, in which case the character behind the cursor is | |
f73dda09 | 5680 | deleted. |
b72432fd | 5681 | .TP |
726f6388 | 5682 | .B quoted\-insert (C\-q, C\-v) |
cce855bc | 5683 | Add the next character typed to the line verbatim. This is |
726f6388 JA |
5684 | how to insert characters like \fBC\-q\fP, for example. |
5685 | .TP | |
ccc6cda3 | 5686 | .B tab\-insert (C\-v TAB) |
726f6388 JA |
5687 | Insert a tab character. |
5688 | .TP | |
5689 | .B self\-insert (a,\ b,\ A,\ 1,\ !,\ ...) | |
5690 | Insert the character typed. | |
5691 | .TP | |
5692 | .B transpose\-chars (C\-t) | |
28ef6c31 JA |
5693 | Drag the character before point forward over the character at point, |
5694 | moving point forward as well. | |
5695 | If point is at the end of the line, then this transposes | |
5696 | the two characters before point. | |
bb70624e | 5697 | Negative arguments have no effect. |
726f6388 JA |
5698 | .TP |
5699 | .B transpose\-words (M\-t) | |
bb70624e | 5700 | Drag the word before point past the word after point, |
28ef6c31 | 5701 | moving point over that word as well. |
f73dda09 JA |
5702 | If point is at the end of the line, this transposes |
5703 | the last two words on the line. | |
726f6388 JA |
5704 | .TP |
5705 | .B upcase\-word (M\-u) | |
5706 | Uppercase the current (or following) word. With a negative argument, | |
cce855bc | 5707 | uppercase the previous word, but do not move point. |
726f6388 JA |
5708 | .TP |
5709 | .B downcase\-word (M\-l) | |
5710 | Lowercase the current (or following) word. With a negative argument, | |
cce855bc | 5711 | lowercase the previous word, but do not move point. |
726f6388 JA |
5712 | .TP |
5713 | .B capitalize\-word (M\-c) | |
5714 | Capitalize the current (or following) word. With a negative argument, | |
cce855bc | 5715 | capitalize the previous word, but do not move point. |
7117c2d2 JA |
5716 | .TP |
5717 | .B overwrite\-mode | |
5718 | Toggle overwrite mode. With an explicit positive numeric argument, | |
5719 | switches to overwrite mode. With an explicit non-positive numeric | |
5720 | argument, switches to insert mode. This command affects only | |
5721 | \fBemacs\fP mode; \fBvi\fP mode does overwrite differently. | |
5722 | Each call to \fIreadline()\fP starts in insert mode. | |
5723 | In overwrite mode, characters bound to \fBself\-insert\fP replace | |
5724 | the text at point rather than pushing the text to the right. | |
5725 | Characters bound to \fBbackward\-delete\-char\fP replace the character | |
5726 | before point with a space. By default, this command is unbound. | |
726f6388 JA |
5727 | .PD |
5728 | .SS Killing and Yanking | |
5729 | .PP | |
5730 | .PD 0 | |
5731 | .TP | |
5732 | .B kill\-line (C\-k) | |
bb70624e | 5733 | Kill the text from point to the end of the line. |
726f6388 | 5734 | .TP |
ccc6cda3 | 5735 | .B backward\-kill\-line (C\-x Rubout) |
726f6388 JA |
5736 | Kill backward to the beginning of the line. |
5737 | .TP | |
5738 | .B unix\-line\-discard (C\-u) | |
5739 | Kill backward from point to the beginning of the line. | |
cce855bc | 5740 | The killed text is saved on the kill-ring. |
bb70624e | 5741 | .\" There is no real difference between this and backward-kill-line |
726f6388 JA |
5742 | .TP |
5743 | .B kill\-whole\-line | |
bb70624e | 5744 | Kill all characters on the current line, no matter where point is. |
726f6388 JA |
5745 | .TP |
5746 | .B kill\-word (M\-d) | |
bb70624e JA |
5747 | Kill from point to the end of the current word, or if between |
5748 | words, to the end of the next word. | |
5749 | Word boundaries are the same as those used by \fBforward\-word\fP. | |
726f6388 JA |
5750 | .TP |
5751 | .B backward\-kill\-word (M\-Rubout) | |
bb70624e JA |
5752 | Kill the word behind point. |
5753 | Word boundaries are the same as those used by \fBbackward\-word\fP. | |
726f6388 | 5754 | .TP |
8c2fef19 CR |
5755 | .B shell\-kill\-word (M\-d) |
5756 | Kill from point to the end of the current word, or if between | |
5757 | words, to the end of the next word. | |
5758 | Word boundaries are the same as those used by \fBshell\-forward\-word\fP. | |
5759 | .TP | |
5760 | .B shell\-backward\-kill\-word (M\-Rubout) | |
5761 | Kill the word behind point. | |
5762 | Word boundaries are the same as those used by \fBshell\-backward\-word\fP. | |
5763 | .TP | |
726f6388 | 5764 | .B unix\-word\-rubout (C\-w) |
bb70624e | 5765 | Kill the word behind point, using white space as a word boundary. |
bb70624e | 5766 | The killed text is saved on the kill-ring. |
113d85a4 CR |
5767 | .TP |
5768 | .B unix\-filename\-rubout | |
5769 | Kill the word behind point, using white space and the slash character | |
5770 | as the word boundaries. | |
5771 | The killed text is saved on the kill-ring. | |
ccc6cda3 JA |
5772 | .TP |
5773 | .B delete\-horizontal\-space (M\-\e) | |
5774 | Delete all spaces and tabs around point. | |
5775 | .TP | |
5776 | .B kill\-region | |
bb70624e | 5777 | Kill the text in the current region. |
ccc6cda3 JA |
5778 | .TP |
5779 | .B copy\-region\-as\-kill | |
5780 | Copy the text in the region to the kill buffer. | |
726f6388 | 5781 | .TP |
ccc6cda3 JA |
5782 | .B copy\-backward\-word |
5783 | Copy the word before point to the kill buffer. | |
cce855bc | 5784 | The word boundaries are the same as \fBbackward\-word\fP. |
ccc6cda3 JA |
5785 | .TP |
5786 | .B copy\-forward\-word | |
5787 | Copy the word following point to the kill buffer. | |
cce855bc | 5788 | The word boundaries are the same as \fBforward\-word\fP. |
726f6388 JA |
5789 | .TP |
5790 | .B yank (C\-y) | |
28ef6c31 | 5791 | Yank the top of the kill ring into the buffer at point. |
726f6388 JA |
5792 | .TP |
5793 | .B yank\-pop (M\-y) | |
ccc6cda3 | 5794 | Rotate the kill ring, and yank the new top. Only works following |
726f6388 JA |
5795 | .B yank |
5796 | or | |
5797 | .BR yank\-pop . | |
5798 | .PD | |
5799 | .SS Numeric Arguments | |
5800 | .PP | |
5801 | .PD 0 | |
5802 | .TP | |
5803 | .B digit\-argument (M\-0, M\-1, ..., M\-\-) | |
5804 | Add this digit to the argument already accumulating, or start a new | |
5805 | argument. M\-\- starts a negative argument. | |
5806 | .TP | |
5807 | .B universal\-argument | |
d166f048 JA |
5808 | This is another way to specify an argument. |
5809 | If this command is followed by one or more digits, optionally with a | |
5810 | leading minus sign, those digits define the argument. | |
5811 | If the command is followed by digits, executing | |
5812 | .B universal\-argument | |
5813 | again ends the numeric argument, but is otherwise ignored. | |
5814 | As a special case, if this command is immediately followed by a | |
5815 | character that is neither a digit or minus sign, the argument count | |
5816 | for the next command is multiplied by four. | |
726f6388 | 5817 | The argument count is initially one, so executing this function the |
d166f048 JA |
5818 | first time makes the argument count four, a second time makes the |
5819 | argument count sixteen, and so on. | |
726f6388 JA |
5820 | .PD |
5821 | .SS Completing | |
5822 | .PP | |
5823 | .PD 0 | |
5824 | .TP | |
5825 | .B complete (TAB) | |
5826 | Attempt to perform completion on the text before point. | |
5827 | .B Bash | |
5828 | attempts completion treating the text as a variable (if the | |
5829 | text begins with \fB$\fP), username (if the text begins with | |
5830 | \fB~\fP), hostname (if the text begins with \fB@\fP), or | |
5831 | command (including aliases and functions) in turn. If none | |
5832 | of these produces a match, filename completion is attempted. | |
5833 | .TP | |
ccc6cda3 | 5834 | .B possible\-completions (M\-?) |
726f6388 JA |
5835 | List the possible completions of the text before point. |
5836 | .TP | |
ccc6cda3 | 5837 | .B insert\-completions (M\-*) |
726f6388 JA |
5838 | Insert all completions of the text before point |
5839 | that would have been generated by | |
ccc6cda3 | 5840 | \fBpossible\-completions\fP. |
726f6388 | 5841 | .TP |
cce855bc JA |
5842 | .B menu\-complete |
5843 | Similar to \fBcomplete\fP, but replaces the word to be completed | |
5844 | with a single match from the list of possible completions. | |
5845 | Repeated execution of \fBmenu\-complete\fP steps through the list | |
5846 | of possible completions, inserting each match in turn. | |
28ef6c31 | 5847 | At the end of the list of completions, the bell is rung |
f73dda09 | 5848 | (subject to the setting of \fBbell\-style\fP) |
28ef6c31 | 5849 | and the original text is restored. |
cce855bc JA |
5850 | An argument of \fIn\fP moves \fIn\fP positions forward in the list |
5851 | of matches; a negative argument may be used to move backward | |
5852 | through the list. | |
5853 | This command is intended to be bound to \fBTAB\fP, but is unbound | |
5854 | by default. | |
5855 | .TP | |
dc60d4e0 | 5856 | .B menu\-complete\-backward |
9dd88db7 CR |
5857 | Identical to \fBmenu\-complete\fP, but moves backward through the list |
5858 | of possible completions, as if \fBmenu\-complete\fP had been given a | |
5859 | negative argument. This command is unbound by default. | |
5860 | .TP | |
b72432fd JA |
5861 | .B delete\-char\-or\-list |
5862 | Deletes the character under the cursor if not at the beginning or | |
bb70624e | 5863 | end of the line (like \fBdelete\-char\fP). |
b72432fd | 5864 | If at the end of the line, behaves identically to |
bb70624e | 5865 | \fBpossible\-completions\fP. |
b72432fd JA |
5866 | This command is unbound by default. |
5867 | .TP | |
726f6388 JA |
5868 | .B complete\-filename (M\-/) |
5869 | Attempt filename completion on the text before point. | |
5870 | .TP | |
5871 | .B possible\-filename\-completions (C\-x /) | |
5872 | List the possible completions of the text before point, | |
5873 | treating it as a filename. | |
5874 | .TP | |
5875 | .B complete\-username (M\-~) | |
5876 | Attempt completion on the text before point, treating | |
5877 | it as a username. | |
5878 | .TP | |
5879 | .B possible\-username\-completions (C\-x ~) | |
5880 | List the possible completions of the text before point, | |
5881 | treating it as a username. | |
5882 | .TP | |
5883 | .B complete\-variable (M\-$) | |
5884 | Attempt completion on the text before point, treating | |
5885 | it as a shell variable. | |
5886 | .TP | |
5887 | .B possible\-variable\-completions (C\-x $) | |
5888 | List the possible completions of the text before point, | |
5889 | treating it as a shell variable. | |
5890 | .TP | |
5891 | .B complete\-hostname (M\-@) | |
5892 | Attempt completion on the text before point, treating | |
5893 | it as a hostname. | |
5894 | .TP | |
5895 | .B possible\-hostname\-completions (C\-x @) | |
5896 | List the possible completions of the text before point, | |
5897 | treating it as a hostname. | |
5898 | .TP | |
5899 | .B complete\-command (M\-!) | |
5900 | Attempt completion on the text before point, treating | |
5901 | it as a command name. Command completion attempts to | |
5902 | match the text against aliases, reserved words, shell | |
cce855bc | 5903 | functions, shell builtins, and finally executable filenames, |
726f6388 JA |
5904 | in that order. |
5905 | .TP | |
5906 | .B possible\-command\-completions (C\-x !) | |
5907 | List the possible completions of the text before point, | |
5908 | treating it as a command name. | |
5909 | .TP | |
ccc6cda3 | 5910 | .B dynamic\-complete\-history (M\-TAB) |
726f6388 JA |
5911 | Attempt completion on the text before point, comparing |
5912 | the text against lines from the history list for possible | |
5913 | completion matches. | |
5914 | .TP | |
8943768b CR |
5915 | .B dabbrev\-expand |
5916 | Attempt menu completion on the text before point, comparing | |
5917 | the text against lines from the history list for possible | |
5918 | completion matches. | |
5919 | .TP | |
726f6388 | 5920 | .B complete\-into\-braces (M\-{) |
bb70624e | 5921 | Perform filename completion and insert the list of possible completions |
726f6388 JA |
5922 | enclosed within braces so the list is available to the shell (see |
5923 | .B Brace Expansion | |
5924 | above). | |
5925 | .PD | |
5926 | .SS Keyboard Macros | |
5927 | .PP | |
5928 | .PD 0 | |
5929 | .TP | |
ccc6cda3 | 5930 | .B start\-kbd\-macro (C\-x (\^) |
726f6388 JA |
5931 | Begin saving the characters typed into the current keyboard macro. |
5932 | .TP | |
ccc6cda3 | 5933 | .B end\-kbd\-macro (C\-x )\^) |
726f6388 | 5934 | Stop saving the characters typed into the current keyboard macro |
ccc6cda3 | 5935 | and store the definition. |
726f6388 | 5936 | .TP |
ccc6cda3 | 5937 | .B call\-last\-kbd\-macro (C\-x e) |
726f6388 JA |
5938 | Re-execute the last keyboard macro defined, by making the characters |
5939 | in the macro appear as if typed at the keyboard. | |
ba4ab055 CR |
5940 | .B print\-last\-kbd\-macro () |
5941 | Print the last keyboard macro defined in a format suitable for the | |
5942 | \fIinputrc\fP file. | |
726f6388 JA |
5943 | .PD |
5944 | .SS Miscellaneous | |
5945 | .PP | |
5946 | .PD 0 | |
5947 | .TP | |
5948 | .B re\-read\-init\-file (C\-x C\-r) | |
ccc6cda3 | 5949 | Read in the contents of the \fIinputrc\fP file, and incorporate |
726f6388 JA |
5950 | any bindings or variable assignments found there. |
5951 | .TP | |
5952 | .B abort (C\-g) | |
5953 | Abort the current editing command and | |
5954 | ring the terminal's bell (subject to the setting of | |
5955 | .BR bell\-style ). | |
5956 | .TP | |
ccc6cda3 JA |
5957 | .B do\-uppercase\-version (M\-a, M\-b, M\-\fIx\fP, ...) |
5958 | If the metafied character \fIx\fP is lowercase, run the command | |
5959 | that is bound to the corresponding uppercase character. | |
726f6388 JA |
5960 | .TP |
5961 | .B prefix\-meta (ESC) | |
5962 | Metafy the next character typed. | |
5963 | .SM | |
5964 | .B ESC | |
5965 | .B f | |
5966 | is equivalent to | |
5967 | .BR Meta\-f . | |
5968 | .TP | |
5969 | .B undo (C\-_, C\-x C\-u) | |
5970 | Incremental undo, separately remembered for each line. | |
5971 | .TP | |
5972 | .B revert\-line (M\-r) | |
cce855bc | 5973 | Undo all changes made to this line. This is like executing the |
726f6388 JA |
5974 | .B undo |
5975 | command enough times to return the line to its initial state. | |
5976 | .TP | |
b72432fd | 5977 | .B tilde\-expand (M\-&) |
726f6388 JA |
5978 | Perform tilde expansion on the current word. |
5979 | .TP | |
ccc6cda3 | 5980 | .B set\-mark (C\-@, M\-<space>) |
28ef6c31 | 5981 | Set the mark to the point. If a |
ccc6cda3 JA |
5982 | numeric argument is supplied, the mark is set to that position. |
5983 | .TP | |
5984 | .B exchange\-point\-and\-mark (C\-x C\-x) | |
5985 | Swap the point with the mark. The current cursor position is set to | |
5986 | the saved position, and the old cursor position is saved as the mark. | |
5987 | .TP | |
5988 | .B character\-search (C\-]) | |
5989 | A character is read and point is moved to the next occurrence of that | |
5990 | character. A negative count searches for previous occurrences. | |
5991 | .TP | |
5992 | .B character\-search\-backward (M\-C\-]) | |
5993 | A character is read and point is moved to the previous occurrence of that | |
5994 | character. A negative count searches for subsequent occurrences. | |
5995 | .TP | |
dc60d4e0 | 5996 | .B skip\-csi\-sequence |
691aebcb CR |
5997 | Read enough characters to consume a multi-key sequence such as those |
5998 | defined for keys like Home and End. Such sequences begin with a | |
5999 | Control Sequence Indicator (CSI), usually ESC\-[. If this sequence is | |
6000 | bound to "\e[", keys producing such sequences will have no effect | |
6001 | unless explicitly bound to a readline command, instead of inserting | |
6002 | stray characters into the editing buffer. This is unbound by default, | |
6003 | but usually bound to ESC\-[. | |
6004 | .TP | |
ccc6cda3 | 6005 | .B insert\-comment (M\-#) |
7117c2d2 | 6006 | Without a numeric argument, the value of the readline |
ccc6cda3 | 6007 | .B comment\-begin |
7117c2d2 JA |
6008 | variable is inserted at the beginning of the current line. |
6009 | If a numeric argument is supplied, this command acts as a toggle: if | |
6010 | the characters at the beginning of the line do not match the value | |
6011 | of \fBcomment\-begin\fP, the value is inserted, otherwise | |
db31fb26 | 6012 | the characters in \fBcomment\-begin\fP are deleted from the beginning of |
7117c2d2 JA |
6013 | the line. |
6014 | In either case, the line is accepted as if a newline had been typed. | |
6015 | The default value of | |
bb70624e | 6016 | \fBcomment\-begin\fP causes this command to make the current line |
ccc6cda3 | 6017 | a shell comment. |
7117c2d2 JA |
6018 | If a numeric argument causes the comment character to be removed, the line |
6019 | will be executed by the shell. | |
6020 | .TP | |
6021 | .B glob\-complete\-word (M\-g) | |
6022 | The word before point is treated as a pattern for pathname expansion, | |
6023 | with an asterisk implicitly appended. This pattern is used to | |
b28ff8c9 | 6024 | generate a list of matching filenames for possible completions. |
ccc6cda3 JA |
6025 | .TP |
6026 | .B glob\-expand\-word (C\-x *) | |
6027 | The word before point is treated as a pattern for pathname expansion, | |
b28ff8c9 | 6028 | and the list of matching filenames is inserted, replacing the word. |
7117c2d2 JA |
6029 | If a numeric argument is supplied, an asterisk is appended before |
6030 | pathname expansion. | |
ccc6cda3 JA |
6031 | .TP |
6032 | .B glob\-list\-expansions (C\-x g) | |
6033 | The list of expansions that would have been generated by | |
6034 | .B glob\-expand\-word | |
6035 | is displayed, and the line is redrawn. | |
7117c2d2 JA |
6036 | If a numeric argument is supplied, an asterisk is appended before |
6037 | pathname expansion. | |
ccc6cda3 | 6038 | .TP |
726f6388 JA |
6039 | .B dump\-functions |
6040 | Print all of the functions and their key bindings to the | |
6041 | readline output stream. If a numeric argument is supplied, | |
6042 | the output is formatted in such a way that it can be made part | |
6043 | of an \fIinputrc\fP file. | |
6044 | .TP | |
ccc6cda3 JA |
6045 | .B dump\-variables |
6046 | Print all of the settable readline variables and their values to the | |
6047 | readline output stream. If a numeric argument is supplied, | |
6048 | the output is formatted in such a way that it can be made part | |
6049 | of an \fIinputrc\fP file. | |
6050 | .TP | |
6051 | .B dump\-macros | |
6052 | Print all of the readline key sequences bound to macros and the | |
22e63b05 | 6053 | strings they output. If a numeric argument is supplied, |
ccc6cda3 JA |
6054 | the output is formatted in such a way that it can be made part |
6055 | of an \fIinputrc\fP file. | |
6056 | .TP | |
726f6388 JA |
6057 | .B display\-shell\-version (C\-x C\-v) |
6058 | Display version information about the current instance of | |
6059 | .BR bash . | |
6060 | .PD | |
bb70624e JA |
6061 | .SS Programmable Completion |
6062 | .PP | |
6063 | When word completion is attempted for an argument to a command for | |
6064 | which a completion specification (a \fIcompspec\fP) has been defined | |
6065 | using the \fBcomplete\fP builtin (see | |
6066 | .SM | |
6067 | .B "SHELL BUILTIN COMMANDS" | |
6068 | below), the programmable completion facilities are invoked. | |
6069 | .PP | |
6070 | First, the command name is identified. | |
3eb2d94a CR |
6071 | If the command word is the empty string (completion attempted at the |
6072 | beginning of an empty line), any compspec defined with | |
6073 | the \fB\-E\fP option to \fBcomplete\fP is used. | |
bb70624e JA |
6074 | If a compspec has been defined for that command, the |
6075 | compspec is used to generate the list of possible completions for the word. | |
6076 | If the command word is a full pathname, a compspec for the full | |
6077 | pathname is searched for first. | |
6078 | If no compspec is found for the full pathname, an attempt is made to | |
6079 | find a compspec for the portion following the final slash. | |
dc60d4e0 | 6080 | If those searches do not result in a compspec, any compspec defined with |
3eb2d94a | 6081 | the \fB\-D\fP option to \fBcomplete\fP is used as the default. |
bb70624e JA |
6082 | .PP |
6083 | Once a compspec has been found, it is used to generate the list of | |
6084 | matching words. | |
6085 | If a compspec is not found, the default \fBbash\fP completion as | |
6086 | described above under \fBCompleting\fP is performed. | |
6087 | .PP | |
6088 | First, the actions specified by the compspec are used. | |
6089 | Only matches which are prefixed by the word being completed are | |
6090 | returned. | |
6091 | When the | |
6092 | .B \-f | |
6093 | or | |
6094 | .B \-d | |
6095 | option is used for filename or directory name completion, the shell | |
6096 | variable | |
6097 | .SM | |
6098 | .B FIGNORE | |
6099 | is used to filter the matches. | |
6100 | .PP | |
d0ca3503 | 6101 | Any completions specified by a pathname expansion pattern to the |
bb70624e JA |
6102 | \fB\-G\fP option are generated next. |
6103 | The words generated by the pattern need not match the word | |
6104 | being completed. | |
6105 | The | |
6106 | .SM | |
6107 | .B GLOBIGNORE | |
6108 | shell variable is not used to filter the matches, but the | |
6109 | .SM | |
6110 | .B FIGNORE | |
6111 | variable is used. | |
6112 | .PP | |
6113 | Next, the string specified as the argument to the \fB\-W\fP option | |
6114 | is considered. | |
6115 | The string is first split using the characters in the | |
6116 | .SM | |
6117 | .B IFS | |
6118 | special variable as delimiters. | |
6119 | Shell quoting is honored. | |
6120 | Each word is then expanded using | |
6121 | brace expansion, tilde expansion, parameter and variable expansion, | |
6e70dbff | 6122 | command substitution, and arithmetic expansion, |
bb70624e JA |
6123 | as described above under |
6124 | .SM | |
6125 | .BR EXPANSION . | |
6126 | The results are split using the rules described above under | |
6127 | \fBWord Splitting\fP. | |
6128 | The results of the expansion are prefix-matched against the word being | |
6129 | completed, and the matching words become the possible completions. | |
6130 | .PP | |
6131 | After these matches have been generated, any shell function or command | |
6132 | specified with the \fB\-F\fP and \fB\-C\fP options is invoked. | |
6133 | When the command or function is invoked, the | |
6134 | .SM | |
d3ad40de CR |
6135 | .BR COMP_LINE , |
6136 | .SM | |
6137 | .BR COMP_POINT , | |
6138 | .SM | |
6139 | .BR COMP_KEY , | |
bb70624e JA |
6140 | and |
6141 | .SM | |
d3ad40de | 6142 | .B COMP_TYPE |
bb70624e JA |
6143 | variables are assigned values as described above under |
6144 | \fBShell Variables\fP. | |
6145 | If a shell function is being invoked, the | |
6146 | .SM | |
6147 | .B COMP_WORDS | |
6148 | and | |
6149 | .SM | |
6150 | .B COMP_CWORD | |
6151 | variables are also set. | |
ba4ab055 CR |
6152 | When the function or command is invoked, |
6153 | the first argument (\fB$1\fP) is the name of the command whose arguments are | |
6154 | being completed, | |
6155 | the second argument (\fB$2\fP) is the word being completed, | |
6156 | and the third argument (\fB$3\fP) is the word preceding the word being | |
6157 | completed on the current command line. | |
bb70624e JA |
6158 | No filtering of the generated completions against the word being completed |
6159 | is performed; the function or command has complete freedom in generating | |
6160 | the matches. | |
6161 | .PP | |
6162 | Any function specified with \fB\-F\fP is invoked first. | |
6163 | The function may use any of the shell facilities, including the | |
6164 | \fBcompgen\fP builtin described below, to generate the matches. | |
6165 | It must put the possible completions in the | |
6166 | .SM | |
6167 | .B COMPREPLY | |
ba4ab055 | 6168 | array variable, one per array element. |
bb70624e JA |
6169 | .PP |
6170 | Next, any command specified with the \fB\-C\fP option is invoked | |
6171 | in an environment equivalent to command substitution. | |
6172 | It should print a list of completions, one per line, to the | |
6173 | standard output. | |
6174 | Backslash may be used to escape a newline, if necessary. | |
6175 | .PP | |
6176 | After all of the possible completions are generated, any filter | |
6177 | specified with the \fB\-X\fP option is applied to the list. | |
6178 | The filter is a pattern as used for pathname expansion; a \fB&\fP | |
6179 | in the pattern is replaced with the text of the word being completed. | |
6180 | A literal \fB&\fP may be escaped with a backslash; the backslash | |
6181 | is removed before attempting a match. | |
6182 | Any completion that matches the pattern will be removed from the list. | |
6183 | A leading \fB!\fP negates the pattern; in this case any completion | |
6184 | not matching the pattern will be removed. | |
6185 | .PP | |
6186 | Finally, any prefix and suffix specified with the \fB\-P\fP and \fB\-S\fP | |
6187 | options are added to each member of the completion list, and the result is | |
6188 | returned to the readline completion code as the list of possible | |
6189 | completions. | |
6190 | .PP | |
28ef6c31 JA |
6191 | If the previously-applied actions do not generate any matches, and the |
6192 | \fB\-o dirnames\fP option was supplied to \fBcomplete\fP when the | |
6193 | compspec was defined, directory name completion is attempted. | |
6194 | .PP | |
d3a24ed2 CR |
6195 | If the \fB\-o plusdirs\fP option was supplied to \fBcomplete\fP when the |
6196 | compspec was defined, directory name completion is attempted and any | |
6197 | matches are added to the results of the other actions. | |
6198 | .PP | |
28ef6c31 JA |
6199 | By default, if a compspec is found, whatever it generates is returned |
6200 | to the completion code as the full set of possible completions. | |
bb70624e JA |
6201 | The default \fBbash\fP completions are not attempted, and the readline |
6202 | default of filename completion is disabled. | |
d3a24ed2 CR |
6203 | If the \fB\-o bashdefault\fP option was supplied to \fBcomplete\fP when |
6204 | the compspec was defined, the \fBbash\fP default completions are attempted | |
28ef6c31 | 6205 | if the compspec generates no matches. |
d3a24ed2 CR |
6206 | If the \fB\-o default\fP option was supplied to \fBcomplete\fP when the |
6207 | compspec was defined, readline's default completion will be performed | |
6208 | if the compspec (and, if attempted, the default \fBbash\fP completions) | |
6209 | generate no matches. | |
7117c2d2 JA |
6210 | .PP |
6211 | When a compspec indicates that directory name completion is desired, | |
6212 | the programmable completion functions force readline to append a slash | |
6213 | to completed names which are symbolic links to directories, subject to | |
6214 | the value of the \fBmark\-directories\fP readline variable, regardless | |
6215 | of the setting of the \fBmark-symlinked\-directories\fP readline variable. | |
3eb2d94a CR |
6216 | .PP |
6217 | There is some support for dynamically modifying completions. This is | |
6218 | most useful when used in combination with a default completion specified | |
6219 | with \fBcomplete -D\fP. | |
6220 | It's possible for shell functions executed as completion | |
6221 | handlers to indicate that completion should be retried by returning an | |
6222 | exit status of 124. If a shell function returns 124, and changes | |
6223 | the compspec associated with the command on which completion is being | |
6224 | attempted (supplied as the first argument when the function is executed), | |
6225 | programmable completion restarts from the beginning, with an | |
3d8cce26 | 6226 | attempt to find a new compspec for that command. This allows a set of |
3eb2d94a CR |
6227 | completions to be built dynamically as completion is attempted, rather than |
6228 | being loaded all at once. | |
6229 | .PP | |
6230 | For instance, assuming that there is a library of compspecs, each kept in a | |
6231 | file corresponding to the name of the command, the following default | |
6232 | completion function would load completions dynamically: | |
6233 | .PP | |
6234 | \f(CW_completion_loader() | |
6235 | .br | |
6236 | { | |
6237 | .br | |
6238 | . "/etc/bash_completion.d/$1.sh" >/dev/null 2>&1 && return 124 | |
6239 | .br | |
6240 | } | |
6241 | .br | |
6242 | complete -D -F _completion_loader | |
6243 | .br | |
6244 | \fP | |
726f6388 | 6245 | .SH HISTORY |
ccc6cda3 | 6246 | When the |
d166f048 | 6247 | .B \-o history |
ccc6cda3 JA |
6248 | option to the |
6249 | .B set | |
6250 | builtin is enabled, the shell provides access to the | |
6251 | \fIcommand history\fP, | |
bb70624e | 6252 | the list of commands previously typed. |
984a1947 CR |
6253 | The value of the |
6254 | .SM | |
6255 | .B HISTSIZE | |
6256 | variable is used as the | |
bb70624e JA |
6257 | number of commands to save in a history list. |
6258 | The text of the last | |
726f6388 JA |
6259 | .SM |
6260 | .B HISTSIZE | |
bb70624e | 6261 | commands (default 500) is saved. The shell |
726f6388 JA |
6262 | stores each command in the history list prior to parameter and |
6263 | variable expansion (see | |
6264 | .SM | |
6265 | .B EXPANSION | |
6266 | above) but after history expansion is performed, subject to the | |
6267 | values of the shell variables | |
ccc6cda3 JA |
6268 | .SM |
6269 | .B HISTIGNORE | |
726f6388 JA |
6270 | and |
6271 | .SM | |
6272 | .BR HISTCONTROL . | |
bb70624e | 6273 | .PP |
726f6388 JA |
6274 | On startup, the history is initialized from the file named by |
6275 | the variable | |
6276 | .SM | |
6277 | .B HISTFILE | |
6278 | (default \fI~/.bash_history\fP). | |
bb70624e | 6279 | The file named by the value of |
726f6388 JA |
6280 | .SM |
6281 | .B HISTFILE | |
6282 | is truncated, if necessary, to contain no more than | |
bb70624e | 6283 | the number of lines specified by the value of |
726f6388 | 6284 | .SM |
bb70624e | 6285 | .BR HISTFILESIZE . |
4b82d1cd CR |
6286 | If \fBHISTFILESIZE\fP is unset, or set to null, a non-numeric value, |
6287 | or a numeric value less than zero, the history file is not truncated. | |
d3ad40de CR |
6288 | When the history file is read, |
6289 | lines beginning with the history comment character followed immediately | |
6290 | by a digit are interpreted as timestamps for the preceding history line. | |
6291 | These timestamps are optionally displayed depending on the value of the | |
6292 | .SM | |
6293 | .B HISTTIMEFORMAT | |
6294 | variable. | |
ccc6cda3 JA |
6295 | When an interactive shell exits, the last |
6296 | .SM | |
bb70624e | 6297 | .B $HISTSIZE |
ccc6cda3 JA |
6298 | lines are copied from the history list to |
6299 | .SM | |
bb70624e | 6300 | .BR $HISTFILE . |
ccc6cda3 JA |
6301 | If the |
6302 | .B histappend | |
6303 | shell option is enabled | |
6304 | (see the description of | |
6305 | .B shopt | |
6306 | under | |
6307 | .SM | |
6308 | .B "SHELL BUILTIN COMMANDS" | |
6309 | below), the lines are appended to the history file, | |
6310 | otherwise the history file is overwritten. | |
6311 | If | |
6312 | .SM | |
6313 | .B HISTFILE | |
6314 | is unset, or if the history file is unwritable, the history is | |
d3ad40de CR |
6315 | not saved. |
6316 | If the | |
6317 | .SM | |
984a1947 | 6318 | .B HISTTIMEFORMAT |
d3ad40de CR |
6319 | variable is set, time stamps are written to the history file, marked |
6320 | with the history comment character, so | |
6321 | they may be preserved across shell sessions. | |
6322 | This uses the history comment character to distinguish timestamps from | |
6323 | other history lines. | |
6324 | After saving the history, the history file is truncated | |
ccc6cda3 JA |
6325 | to contain no more than |
6326 | .SM | |
6327 | .B HISTFILESIZE | |
6328 | lines. If | |
6329 | .SM | |
6330 | .B HISTFILESIZE | |
e67d0029 CR |
6331 | is unset, or set to null, a non-numeric value, |
6332 | or a numeric value less than zero, the history file is not truncated. | |
ccc6cda3 | 6333 | .PP |
726f6388 JA |
6334 | The builtin command |
6335 | .B fc | |
6336 | (see | |
6337 | .SM | |
6338 | .B SHELL BUILTIN COMMANDS | |
6339 | below) may be used to list or edit and re-execute a portion of | |
6340 | the history list. | |
6341 | The | |
6342 | .B history | |
bb70624e | 6343 | builtin may be used to display or modify the history list and |
ccc6cda3 | 6344 | manipulate the history file. |
bb70624e | 6345 | When using command-line editing, search commands |
726f6388 | 6346 | are available in each editing mode that provide access to the |
ccc6cda3 JA |
6347 | history list. |
6348 | .PP | |
6349 | The shell allows control over which commands are saved on the history | |
6350 | list. The | |
726f6388 | 6351 | .SM |
ccc6cda3 JA |
6352 | .B HISTCONTROL |
6353 | and | |
726f6388 | 6354 | .SM |
ccc6cda3 JA |
6355 | .B HISTIGNORE |
6356 | variables may be set to cause the shell to save only a subset of the | |
6357 | commands entered. | |
6358 | The | |
6359 | .B cmdhist | |
6360 | shell option, if enabled, causes the shell to attempt to save each | |
6361 | line of a multi-line command in the same history entry, adding | |
6362 | semicolons where necessary to preserve syntactic correctness. | |
6363 | The | |
6364 | .B lithist | |
6365 | shell option causes the shell to save the command with embedded newlines | |
6366 | instead of semicolons. See the description of the | |
6367 | .B shopt | |
6368 | builtin below under | |
6369 | .SM | |
6370 | .B "SHELL BUILTIN COMMANDS" | |
6371 | for information on setting and unsetting shell options. | |
726f6388 JA |
6372 | .SH "HISTORY EXPANSION" |
6373 | .PP | |
6374 | The shell supports a history expansion feature that | |
6375 | is similar to the history expansion in | |
6376 | .BR csh. | |
6377 | This section describes what syntax features are available. This | |
6378 | feature is enabled by default for interactive shells, and can be | |
6379 | disabled using the | |
863d31ae | 6380 | .B +H |
726f6388 JA |
6381 | option to the |
6382 | .B set | |
6383 | builtin command (see | |
6384 | .SM | |
6385 | .B SHELL BUILTIN COMMANDS | |
ccc6cda3 JA |
6386 | below). Non-interactive shells do not perform history expansion |
6387 | by default. | |
6388 | .PP | |
6389 | History expansions introduce words from the history list into | |
6390 | the input stream, making it easy to repeat commands, insert the | |
6391 | arguments to a previous command into the current input line, or | |
6392 | fix errors in previous commands quickly. | |
726f6388 JA |
6393 | .PP |
6394 | History expansion is performed immediately after a complete line | |
6395 | is read, before the shell breaks it into words. | |
ccc6cda3 | 6396 | It takes place in two parts. |
cce855bc | 6397 | The first is to determine which line from the history list |
ccc6cda3 JA |
6398 | to use during substitution. |
6399 | The second is to select portions of that line for inclusion into | |
6400 | the current one. | |
cce855bc | 6401 | The line selected from the history is the \fIevent\fP, |
ccc6cda3 JA |
6402 | and the portions of that line that are acted upon are \fIwords\fP. |
6403 | Various \fImodifiers\fP are available to manipulate the selected words. | |
6404 | The line is broken into words in the same fashion as when reading input, | |
6405 | so that several \fImetacharacter\fP-separated words surrounded by | |
cce855bc | 6406 | quotes are considered one word. |
ccc6cda3 JA |
6407 | History expansions are introduced by the appearance of the |
6408 | history expansion character, which is \^\fB!\fP\^ by default. | |
6409 | Only backslash (\^\fB\e\fP\^) and single quotes can quote | |
6410 | the history expansion character. | |
6411 | .PP | |
d3a24ed2 CR |
6412 | Several characters inhibit history expansion if found immediately |
6413 | following the history expansion character, even if it is unquoted: | |
6414 | space, tab, newline, carriage return, and \fB=\fP. | |
6415 | If the \fBextglob\fP shell option is enabled, \fB(\fP will also | |
6416 | inhibit expansion. | |
6417 | .PP | |
ccc6cda3 JA |
6418 | Several shell options settable with the |
6419 | .B shopt | |
6420 | builtin may be used to tailor the behavior of history expansion. | |
6421 | If the | |
6422 | .B histverify | |
6423 | shell option is enabled (see the description of the | |
6424 | .B shopt | |
984a1947 | 6425 | builtin below), and |
ccc6cda3 JA |
6426 | .B readline |
6427 | is being used, history substitutions are not immediately passed to | |
6428 | the shell parser. | |
6429 | Instead, the expanded line is reloaded into the | |
6430 | .B readline | |
6431 | editing buffer for further modification. | |
6432 | If | |
6433 | .B readline | |
6434 | is being used, and the | |
6435 | .B histreedit | |
6436 | shell option is enabled, a failed history substitution will be reloaded | |
6437 | into the | |
6438 | .B readline | |
6439 | editing buffer for correction. | |
6440 | The | |
6441 | .B \-p | |
6442 | option to the | |
6443 | .B history | |
6444 | builtin command may be used to see what a history expansion will | |
6445 | do before using it. | |
6446 | The | |
6447 | .B \-s | |
6448 | option to the | |
6449 | .B history | |
6450 | builtin may be used to add commands to the end of the history list | |
6451 | without actually executing them, so that they are available for | |
6452 | subsequent recall. | |
726f6388 JA |
6453 | .PP |
6454 | The shell allows control of the various characters used by the | |
6455 | history expansion mechanism (see the description of | |
6456 | .B histchars | |
6457 | above under | |
6458 | .BR "Shell Variables" ). | |
d3ad40de CR |
6459 | The shell uses |
6460 | the history comment character to mark history timestamps when | |
6461 | writing the history file. | |
726f6388 JA |
6462 | .SS Event Designators |
6463 | .PP | |
6464 | An event designator is a reference to a command line entry in the | |
6465 | history list. | |
5f8cde23 CR |
6466 | Unless the reference is absolute, events are relative to the current |
6467 | position in the history list. | |
726f6388 JA |
6468 | .PP |
6469 | .PD 0 | |
6470 | .TP | |
6471 | .B ! | |
6472 | Start a history substitution, except when followed by a | |
6473 | .BR blank , | |
d3a24ed2 CR |
6474 | newline, carriage return, = |
6475 | or ( (when the \fBextglob\fP shell option is enabled using | |
6476 | the \fBshopt\fP builtin). | |
726f6388 | 6477 | .TP |
726f6388 JA |
6478 | .B !\fIn\fR |
6479 | Refer to command line | |
6480 | .IR n . | |
6481 | .TP | |
6482 | .B !\-\fIn\fR | |
5f8cde23 | 6483 | Refer to the current command minus |
726f6388 JA |
6484 | .IR n . |
6485 | .TP | |
ccc6cda3 JA |
6486 | .B !! |
6487 | Refer to the previous command. This is a synonym for `!\-1'. | |
6488 | .TP | |
726f6388 | 6489 | .B !\fIstring\fR |
5f8cde23 CR |
6490 | Refer to the most recent command preceding the current position in the |
6491 | history list starting with | |
726f6388 JA |
6492 | .IR string . |
6493 | .TP | |
6494 | .B !?\fIstring\fR\fB[?]\fR | |
e3db237e | 6495 | Refer to the most recent command preceding the current position in the |
5f8cde23 | 6496 | history list containing |
726f6388 | 6497 | .IR string . |
ccc6cda3 JA |
6498 | The trailing \fB?\fP may be omitted if |
6499 | .I string | |
6500 | is followed immediately by a newline. | |
726f6388 JA |
6501 | .TP |
6502 | .B \d\s+2^\s-2\u\fIstring1\fP\d\s+2^\s-2\u\fIstring2\fP\d\s+2^\s-2\u | |
5f8cde23 | 6503 | Quick substitution. Repeat the previous command, replacing |
726f6388 JA |
6504 | .I string1 |
6505 | with | |
6506 | .IR string2 . | |
6507 | Equivalent to | |
6508 | ``!!:s/\fIstring1\fP/\fIstring2\fP/'' | |
6509 | (see \fBModifiers\fP below). | |
6510 | .TP | |
6511 | .B !# | |
6512 | The entire command line typed so far. | |
6513 | .PD | |
6514 | .SS Word Designators | |
6515 | .PP | |
ccc6cda3 | 6516 | Word designators are used to select desired words from the event. |
726f6388 JA |
6517 | A |
6518 | .B : | |
ccc6cda3 | 6519 | separates the event specification from the word designator. |
cce855bc | 6520 | It may be omitted if the word designator begins with a |
726f6388 JA |
6521 | .BR ^ , |
6522 | .BR $ , | |
6523 | .BR * , | |
ccc6cda3 | 6524 | .BR \- , |
726f6388 JA |
6525 | or |
6526 | .BR % . | |
6527 | Words are numbered from the beginning of the line, | |
ccc6cda3 JA |
6528 | with the first word being denoted by 0 (zero). |
6529 | Words are inserted into the current line separated by single spaces. | |
726f6388 JA |
6530 | .PP |
6531 | .PD 0 | |
6532 | .TP | |
6533 | .B 0 (zero) | |
6534 | The zeroth word. For the shell, this is the command | |
6535 | word. | |
6536 | .TP | |
6537 | .I n | |
6538 | The \fIn\fRth word. | |
6539 | .TP | |
6540 | .B ^ | |
6541 | The first argument. That is, word 1. | |
6542 | .TP | |
6543 | .B $ | |
6544 | The last argument. | |
6545 | .TP | |
6546 | .B % | |
6547 | The word matched by the most recent `?\fIstring\fR?' search. | |
6548 | .TP | |
6549 | .I x\fB\-\fPy | |
6550 | A range of words; `\-\fIy\fR' abbreviates `0\-\fIy\fR'. | |
6551 | .TP | |
6552 | .B * | |
6553 | All of the words but the zeroth. This is a synonym | |
6554 | for `\fI1\-$\fP'. It is not an error to use | |
6555 | .B * | |
6556 | if there is just one | |
6557 | word in the event; the empty string is returned in that case. | |
6558 | .TP | |
6559 | .B x* | |
6560 | Abbreviates \fIx\-$\fP. | |
6561 | .TP | |
6562 | .B x\- | |
6563 | Abbreviates \fIx\-$\fP like \fBx*\fP, but omits the last word. | |
6564 | .PD | |
ccc6cda3 JA |
6565 | .PP |
6566 | If a word designator is supplied without an event specification, the | |
6567 | previous command is used as the event. | |
726f6388 JA |
6568 | .SS Modifiers |
6569 | .PP | |
ccc6cda3 JA |
6570 | After the optional word designator, there may appear a sequence of |
6571 | one or more of the following modifiers, each preceded by a `:'. | |
726f6388 JA |
6572 | .PP |
6573 | .PD 0 | |
6574 | .PP | |
6575 | .TP | |
6576 | .B h | |
b28ff8c9 | 6577 | Remove a trailing filename component, leaving only the head. |
ccc6cda3 JA |
6578 | .TP |
6579 | .B t | |
b28ff8c9 | 6580 | Remove all leading filename components, leaving the tail. |
726f6388 JA |
6581 | .TP |
6582 | .B r | |
6583 | Remove a trailing suffix of the form \fI.xxx\fP, leaving the | |
6584 | basename. | |
6585 | .TP | |
6586 | .B e | |
6587 | Remove all but the trailing suffix. | |
6588 | .TP | |
726f6388 JA |
6589 | .B p |
6590 | Print the new command but do not execute it. | |
6591 | .TP | |
6592 | .B q | |
6593 | Quote the substituted words, escaping further substitutions. | |
6594 | .TP | |
cce855bc JA |
6595 | .B x |
6596 | Quote the substituted words as with | |
6597 | .BR q , | |
6598 | but break into words at | |
6599 | .B blanks | |
6600 | and newlines. | |
726f6388 | 6601 | .TP |
cce855bc JA |
6602 | .B s/\fIold\fP/\fInew\fP/ |
6603 | Substitute | |
6604 | .I new | |
6605 | for the first occurrence of | |
6606 | .I old | |
6607 | in the event line. Any delimiter can be used in place of /. The | |
6608 | final delimiter is optional if it is the last character of the | |
6609 | event line. The delimiter may be quoted in | |
6610 | .I old | |
6611 | and | |
6612 | .I new | |
6613 | with a single backslash. If & appears in | |
6614 | .IR new , | |
6615 | it is replaced by | |
6616 | .IR old . | |
6617 | A single backslash will quote the &. If | |
6618 | .I old | |
6619 | is null, it is set to the last | |
6620 | .I old | |
6621 | substituted, or, if no previous history substitutions took place, | |
6622 | the last | |
6623 | .I string | |
6624 | in a | |
6625 | .B !?\fIstring\fR\fB[?]\fR | |
6626 | search. | |
ccc6cda3 | 6627 | .TP |
cce855bc JA |
6628 | .B & |
6629 | Repeat the previous substitution. | |
6630 | .TP | |
6631 | .B g | |
6632 | Cause changes to be applied over the entire event line. This is | |
6633 | used in conjunction with `\fB:s\fP' (e.g., `\fB:gs/\fIold\fP/\fInew\fP/\fR') | |
6634 | or `\fB:&\fP'. If used with | |
6635 | `\fB:s\fP', any delimiter can be used | |
6636 | in place of /, and the final delimiter is optional | |
6637 | if it is the last character of the event line. | |
d3a24ed2 CR |
6638 | An \fBa\fP may be used as a synonym for \fBg\fP. |
6639 | .TP | |
6640 | .B G | |
6641 | Apply the following `\fBs\fP' modifier once to each word in the event line. | |
726f6388 | 6642 | .PD |
726f6388 JA |
6643 | .SH "SHELL BUILTIN COMMANDS" |
6644 | .\" start of bash_builtins | |
6645 | .zZ | |
ccc6cda3 JA |
6646 | .PP |
6647 | Unless otherwise noted, each builtin command documented in this | |
6648 | section as accepting options preceded by | |
6649 | .B \- | |
6650 | accepts | |
6651 | .B \-\- | |
6652 | to signify the end of the options. | |
6932f7f5 CR |
6653 | The \fB:\fP, \fBtrue\fP, \fBfalse\fP, and \fBtest\fP builtins |
6654 | do not accept options and do not treat \fB\-\-\fP specially. | |
6655 | The \fBexit\fP, \fBlogout\fP, \fBbreak\fP, \fBcontinue\fP, \fBlet\fP, | |
6656 | and \fBshift\fP builtins accept and process arguments beginning with | |
6657 | \fB\-\fP without requiring \fB\-\-\fP. | |
6658 | Other builtins that accept arguments but are not specified as accepting | |
6659 | options interpret arguments beginning with \fB\-\fP as invalid options and | |
6660 | require \fB\-\-\fP to prevent this interpretation. | |
ccc6cda3 | 6661 | .sp .5 |
726f6388 JA |
6662 | .PD 0 |
6663 | .TP | |
6664 | \fB:\fP [\fIarguments\fP] | |
6665 | .PD | |
6666 | No effect; the command does nothing beyond expanding | |
6667 | .I arguments | |
6668 | and performing any specified | |
6669 | redirections. A zero exit code is returned. | |
6670 | .TP | |
726f6388 | 6671 | \fB .\| \fP \fIfilename\fP [\fIarguments\fP] |
7117c2d2 | 6672 | .PD 0 |
726f6388 JA |
6673 | .TP |
6674 | \fBsource\fP \fIfilename\fP [\fIarguments\fP] | |
6675 | .PD | |
6676 | Read and execute commands from | |
6677 | .I filename | |
6678 | in the current | |
6679 | shell environment and return the exit status of the last command | |
6680 | executed from | |
6681 | .IR filename . | |
6682 | If | |
6683 | .I filename | |
b28ff8c9 | 6684 | does not contain a slash, filenames in |
726f6388 JA |
6685 | .SM |
6686 | .B PATH | |
6687 | are used to find the directory containing | |
6688 | .IR filename . | |
6689 | The file searched for in | |
6690 | .SM | |
6691 | .B PATH | |
28ef6c31 JA |
6692 | need not be executable. |
6693 | When \fBbash\fP is not in \fIposix mode\fP, the current directory is | |
726f6388 JA |
6694 | searched if no file is found in |
6695 | .SM | |
6696 | .BR PATH . | |
ccc6cda3 JA |
6697 | If the |
6698 | .B sourcepath | |
6699 | option to the | |
6700 | .B shopt | |
6701 | builtin command is turned off, the | |
6702 | .SM | |
6703 | .B PATH | |
6704 | is not searched. | |
726f6388 | 6705 | If any \fIarguments\fP are supplied, they become the positional |
ccc6cda3 | 6706 | parameters when \fIfilename\fP is executed. Otherwise the positional |
726f6388 JA |
6707 | parameters are unchanged. |
6708 | The return status is the status of the last command exited within | |
6709 | the script (0 if no commands are executed), and false if | |
6710 | .I filename | |
cce855bc | 6711 | is not found or cannot be read. |
726f6388 | 6712 | .TP |
ccc6cda3 JA |
6713 | \fBalias\fP [\fB\-p\fP] [\fIname\fP[=\fIvalue\fP] ...] |
6714 | \fBAlias\fP with no arguments or with the | |
6715 | .B \-p | |
6716 | option prints the list of aliases in the form | |
6717 | \fBalias\fP \fIname\fP=\fIvalue\fP on standard output. | |
6718 | When arguments are supplied, an alias is defined for | |
6719 | each \fIname\fP whose \fIvalue\fP is given. | |
6720 | A trailing space in \fIvalue\fP causes the next word to be | |
6721 | checked for alias substitution when the alias is expanded. | |
6722 | For each \fIname\fP in the argument list for which no \fIvalue\fP | |
6723 | is supplied, the name and value of the alias is printed. | |
6724 | \fBAlias\fP returns true unless a \fIname\fP is given for which | |
6725 | no alias has been defined. | |
726f6388 | 6726 | .TP |
de3341d1 CR |
6727 | \fBbg\fP [\fIjobspec\fP ...] |
6728 | Resume each suspended job \fIjobspec\fP in the background, as if it | |
cce855bc | 6729 | had been started with |
726f6388 | 6730 | .BR & . |
d3ad40de CR |
6731 | If |
6732 | .I jobspec | |
6733 | is not present, the shell's notion of the \fIcurrent job\fP is used. | |
726f6388 JA |
6734 | .B bg |
6735 | .I jobspec | |
6736 | returns 0 unless run when job control is disabled or, when run with | |
ff247e74 CR |
6737 | job control enabled, any specified \fIjobspec\fP was not found |
6738 | or was started without job control. | |
726f6388 | 6739 | .TP |
ba4ab055 | 6740 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] [\fB\-lpsvPSVX\fP] |
7117c2d2 | 6741 | .PD 0 |
cce855bc JA |
6742 | .TP |
6743 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] [\fB\-q\fP \fIfunction\fP] [\fB\-u\fP \fIfunction\fP] [\fB\-r\fP \fIkeyseq\fP] | |
726f6388 | 6744 | .TP |
ccc6cda3 | 6745 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fB\-f\fP \fIfilename\fP |
726f6388 | 6746 | .TP |
bb70624e JA |
6747 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fB\-x\fP \fIkeyseq\fP:\fIshell\-command\fP |
6748 | .TP | |
ccc6cda3 | 6749 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fIkeyseq\fP:\fIfunction\-name\fP |
7117c2d2 JA |
6750 | .TP |
6751 | \fBbind\fP \fIreadline\-command\fP | |
726f6388 JA |
6752 | .PD |
6753 | Display current | |
6754 | .B readline | |
7117c2d2 | 6755 | key and function bindings, bind a key sequence to a |
726f6388 | 6756 | .B readline |
7117c2d2 JA |
6757 | function or macro, or set a |
6758 | .B readline | |
6759 | variable. | |
6760 | Each non-option argument is a command as it would appear in | |
726f6388 | 6761 | .IR .inputrc , |
7117c2d2 JA |
6762 | but each binding or command must be passed as a separate argument; |
6763 | e.g., '"\eC\-x\eC\-r": re\-read\-init\-file'. | |
6764 | Options, if supplied, have the following meanings: | |
726f6388 JA |
6765 | .RS |
6766 | .PD 0 | |
6767 | .TP | |
6768 | .B \-m \fIkeymap\fP | |
6769 | Use | |
6770 | .I keymap | |
6771 | as the keymap to be affected by the subsequent bindings. | |
6772 | Acceptable | |
6773 | .I keymap | |
6774 | names are | |
ccc6cda3 | 6775 | \fIemacs, emacs\-standard, emacs\-meta, emacs\-ctlx, vi, |
28ef6c31 | 6776 | vi\-move, vi\-command\fP, and |
ccc6cda3 JA |
6777 | .IR vi\-insert . |
6778 | \fIvi\fP is equivalent to \fIvi\-command\fP; \fIemacs\fP is | |
6779 | equivalent to \fIemacs\-standard\fP. | |
726f6388 JA |
6780 | .TP |
6781 | .B \-l | |
ccc6cda3 JA |
6782 | List the names of all \fBreadline\fP functions. |
6783 | .TP | |
6784 | .B \-p | |
6785 | Display \fBreadline\fP function names and bindings in such a way | |
6786 | that they can be re-read. | |
6787 | .TP | |
6788 | .B \-P | |
6789 | List current \fBreadline\fP function names and bindings. | |
726f6388 | 6790 | .TP |
ccc6cda3 JA |
6791 | .B \-s |
6792 | Display \fBreadline\fP key sequences bound to macros and the strings | |
6793 | they output in such a way that they can be re-read. | |
6794 | .TP | |
6795 | .B \-S | |
6796 | Display \fBreadline\fP key sequences bound to macros and the strings | |
6797 | they output. | |
726f6388 | 6798 | .TP |
d3ad40de CR |
6799 | .B \-v |
6800 | Display \fBreadline\fP variable names and values in such a way that they | |
6801 | can be re-read. | |
6802 | .TP | |
6803 | .B \-V | |
6804 | List current \fBreadline\fP variable names and values. | |
6805 | .TP | |
726f6388 | 6806 | .B \-f \fIfilename\fP |
ccc6cda3 | 6807 | Read key bindings from \fIfilename\fP. |
726f6388 JA |
6808 | .TP |
6809 | .B \-q \fIfunction\fP | |
ccc6cda3 JA |
6810 | Query about which keys invoke the named \fIfunction\fP. |
6811 | .TP | |
cce855bc JA |
6812 | .B \-u \fIfunction\fP |
6813 | Unbind all keys bound to the named \fIfunction\fP. | |
6814 | .TP | |
ccc6cda3 JA |
6815 | .B \-r \fIkeyseq\fP |
6816 | Remove any current binding for \fIkeyseq\fP. | |
bb70624e JA |
6817 | .TP |
6818 | .B \-x \fIkeyseq\fP:\fIshell\-command\fP | |
6819 | Cause \fIshell\-command\fP to be executed whenever \fIkeyseq\fP is | |
6820 | entered. | |
8943768b | 6821 | When \fIshell\-command\fP is executed, the shell sets the |
984a1947 | 6822 | .SM |
8943768b CR |
6823 | .B READLINE_LINE |
6824 | variable to the contents of the \fBreadline\fP line buffer and the | |
984a1947 | 6825 | .SM |
8943768b CR |
6826 | .B READLINE_POINT |
6827 | variable to the current location of the insertion point. | |
6828 | If the executed command changes the value of | |
984a1947 | 6829 | .SM |
8943768b CR |
6830 | .B READLINE_LINE |
6831 | or | |
984a1947 | 6832 | .SM |
8943768b CR |
6833 | .BR READLINE_POINT , |
6834 | those new values will be reflected in the editing state. | |
ba4ab055 CR |
6835 | .TP |
6836 | .B \-X | |
6837 | List all key sequences bound to shell commands and the associated commands | |
6838 | in a format that can be reused as input. | |
726f6388 JA |
6839 | .PD |
6840 | .PP | |
6841 | The return value is 0 unless an unrecognized option is given or an | |
6842 | error occurred. | |
6843 | .RE | |
6844 | .TP | |
6845 | \fBbreak\fP [\fIn\fP] | |
6846 | Exit from within a | |
6847 | .BR for , | |
6848 | .BR while , | |
ccc6cda3 | 6849 | .BR until , |
726f6388 | 6850 | or |
ccc6cda3 | 6851 | .B select |
726f6388 JA |
6852 | loop. If \fIn\fP is specified, break \fIn\fP levels. |
6853 | .I n | |
6854 | must be \(>= 1. If | |
6855 | .I n | |
6856 | is greater than the number of enclosing loops, all enclosing loops | |
33fe8777 CR |
6857 | are exited. |
6858 | The return value is 0 unless \fIn\fP is not greater than or equal to 1. | |
726f6388 JA |
6859 | .TP |
6860 | \fBbuiltin\fP \fIshell\-builtin\fP [\fIarguments\fP] | |
6861 | Execute the specified shell builtin, passing it | |
6862 | .IR arguments , | |
6863 | and return its exit status. | |
cce855bc | 6864 | This is useful when defining a |
726f6388 | 6865 | function whose name is the same as a shell builtin, |
cce855bc JA |
6866 | retaining the functionality of the builtin within the function. |
6867 | The \fBcd\fP builtin is commonly redefined this way. | |
6868 | The return status is false if | |
726f6388 JA |
6869 | .I shell\-builtin |
6870 | is not a shell builtin command. | |
6871 | .TP | |
6a8fd0ed CR |
6872 | \fBcaller\fP [\fIexpr\fP] |
6873 | Returns the context of any active subroutine call (a shell function or | |
5cdaaf76 | 6874 | a script executed with the \fB.\fP or \fBsource\fP builtins). |
6a8fd0ed CR |
6875 | Without \fIexpr\fP, \fBcaller\fP displays the line number and source |
6876 | filename of the current subroutine call. | |
6877 | If a non-negative integer is supplied as \fIexpr\fP, \fBcaller\fP | |
6878 | displays the line number, subroutine name, and source file corresponding | |
6879 | to that position in the current execution call stack. This extra | |
6880 | information may be used, for example, to print a stack trace. The | |
6881 | current frame is frame 0. | |
6882 | The return value is 0 unless the shell is not executing a subroutine | |
6883 | call or \fIexpr\fP does not correspond to a valid position in the | |
6884 | call stack. | |
6885 | .TP | |
220537f2 | 6886 | \fBcd\fP [\fB\-L\fP|[\fB\-P\fP [\fB\-e\fP]]] [\fIdir\fP] |
2dead0c4 CR |
6887 | Change the current directory to \fIdir\fP. |
6888 | if \fIdir\fP is not supplied, the value of the | |
726f6388 JA |
6889 | .SM |
6890 | .B HOME | |
2dead0c4 CR |
6891 | shell variable is the default. |
6892 | Any additional arguments following \fIdir\fP are ignored. | |
726f6388 JA |
6893 | The variable |
6894 | .SM | |
6895 | .B CDPATH | |
ccc6cda3 | 6896 | defines the search path for the directory containing |
45c0f7f8 CR |
6897 | .IR dir : |
6898 | each directory name in | |
6899 | .SM | |
6900 | .B CDPATH | |
6901 | is searched for \fIdir\fP. | |
ccc6cda3 JA |
6902 | Alternative directory names in |
6903 | .SM | |
6904 | .B CDPATH | |
6905 | are separated by a colon (:). A null directory name in | |
726f6388 JA |
6906 | .SM |
6907 | .B CDPATH | |
ccc6cda3 | 6908 | is the same as the current directory, i.e., ``\fB.\fP''. If |
726f6388 JA |
6909 | .I dir |
6910 | begins with a slash (/), | |
6911 | then | |
6912 | .SM | |
6913 | .B CDPATH | |
ccc6cda3 JA |
6914 | is not used. The |
6915 | .B \-P | |
45c0f7f8 CR |
6916 | option causes \fBcd\fP to use the physical directory structure |
6917 | by resolving symbolic links while traversing \fIdir\fP and | |
6918 | before processing instances of \fI..\fP in \fIdir\fP (see also the | |
ccc6cda3 JA |
6919 | .B \-P |
6920 | option to the | |
6921 | .B set | |
6922 | builtin command); the | |
6923 | .B \-L | |
45c0f7f8 CR |
6924 | option forces symbolic links to be followed by resolving the link |
6925 | after processing instances of \fI..\fP in \fIdir\fP. | |
6926 | If \fI..\fP appears in \fIdir\fP, it is processed by removing the | |
6927 | immediately previous pathname component from \fIdir\fP, back to a slash | |
6928 | or the beginning of \fIdir\fP. | |
220537f2 CR |
6929 | If the |
6930 | .B \-e | |
6931 | option is supplied with | |
6932 | .BR \-P , | |
6933 | and the current working directory cannot be successfully determined | |
6934 | after a successful directory change, \fBcd\fP will return an unsuccessful | |
6935 | status. | |
6936 | An argument of | |
726f6388 | 6937 | .B \- |
19baff85 | 6938 | is converted to |
726f6388 | 6939 | .SM |
19baff85 CR |
6940 | .B $OLDPWD |
6941 | before the directory change is attempted. | |
984a1947 CR |
6942 | If a non-empty directory name from |
6943 | .SM | |
6944 | .B CDPATH | |
6945 | is used, or if | |
d3a24ed2 CR |
6946 | \fB\-\fP is the first argument, and the directory change is |
6947 | successful, the absolute pathname of the new working directory is | |
6948 | written to the standard output. | |
726f6388 JA |
6949 | The return value is true if the directory was successfully changed; |
6950 | false otherwise. | |
6951 | .TP | |
ccc6cda3 | 6952 | \fBcommand\fP [\fB\-pVv\fP] \fIcommand\fP [\fIarg\fP ...] |
726f6388 JA |
6953 | Run |
6954 | .I command | |
6955 | with | |
6956 | .I args | |
6957 | suppressing the normal shell function lookup. Only builtin | |
6958 | commands or commands found in the | |
6959 | .SM | |
6960 | .B PATH | |
6961 | are executed. If the | |
6962 | .B \-p | |
6963 | option is given, the search for | |
6964 | .I command | |
6965 | is performed using a default value for | |
984a1947 | 6966 | .SM |
726f6388 JA |
6967 | .B PATH |
6968 | that is guaranteed to find all of the standard utilities. | |
6969 | If either the | |
6970 | .B \-V | |
6971 | or | |
6972 | .B \-v | |
6973 | option is supplied, a description of | |
6974 | .I command | |
6975 | is printed. The | |
6976 | .B \-v | |
b28ff8c9 | 6977 | option causes a single word indicating the command or filename |
726f6388 JA |
6978 | used to invoke |
6979 | .I command | |
cce855bc | 6980 | to be displayed; the |
726f6388 JA |
6981 | .B \-V |
6982 | option produces a more verbose description. | |
726f6388 JA |
6983 | If the |
6984 | .B \-V | |
6985 | or | |
6986 | .B \-v | |
6987 | option is supplied, the exit status is 0 if | |
6988 | .I command | |
6989 | was found, and 1 if not. If neither option is supplied and | |
6990 | an error occurred or | |
6991 | .I command | |
6992 | cannot be found, the exit status is 127. Otherwise, the exit status of the | |
6993 | .B command | |
6994 | builtin is the exit status of | |
6995 | .IR command . | |
6996 | .TP | |
bb70624e JA |
6997 | \fBcompgen\fP [\fIoption\fP] [\fIword\fP] |
6998 | Generate possible completion matches for \fIword\fP according to | |
6999 | the \fIoption\fPs, which may be any option accepted by the | |
7000 | .B complete | |
7001 | builtin with the exception of \fB\-p\fP and \fB\-r\fP, and write | |
7002 | the matches to the standard output. | |
7003 | When using the \fB\-F\fP or \fB\-C\fP options, the various shell variables | |
7004 | set by the programmable completion facilities, while available, will not | |
7005 | have useful values. | |
7006 | .sp 1 | |
7007 | The matches will be generated in the same way as if the programmable | |
7008 | completion code had generated them directly from a completion specification | |
7009 | with the same flags. | |
7010 | If \fIword\fP is specified, only those completions matching \fIword\fP | |
7011 | will be displayed. | |
7012 | .sp 1 | |
7013 | The return value is true unless an invalid option is supplied, or no | |
7014 | matches were generated. | |
7015 | .TP | |
3eb2d94a | 7016 | \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 | 7017 | .br |
d3ad40de | 7018 | [\fB\-X\fP \fIfilterpat\fP] [\fB\-P\fP \fIprefix\fP] [\fB\-S\fP \fIsuffix\fP] \fIname\fP [\fIname ...\fP] |
7117c2d2 | 7019 | .PD 0 |
bb70624e | 7020 | .TP |
3eb2d94a | 7021 | \fBcomplete\fP \fB\-pr\fP [\fB\-DE\fP] [\fIname\fP ...] |
bb70624e JA |
7022 | .PD |
7023 | Specify how arguments to each \fIname\fP should be completed. | |
7024 | If the \fB\-p\fP option is supplied, or if no options are supplied, | |
7025 | existing completion specifications are printed in a way that allows | |
7026 | them to be reused as input. | |
7027 | The \fB\-r\fP option removes a completion specification for | |
7028 | each \fIname\fP, or, if no \fIname\fPs are supplied, all | |
7029 | completion specifications. | |
3eb2d94a CR |
7030 | The \fB\-D\fP option indicates that the remaining options and actions should |
7031 | apply to the ``default'' command completion; that is, completion attempted | |
7032 | on a command for which no completion has previously been defined. | |
6a8fd0ed CR |
7033 | The \fB\-E\fP option indicates that the remaining options and actions should |
7034 | apply to ``empty'' command completion; that is, completion attempted on a | |
7035 | blank line. | |
bb70624e JA |
7036 | .sp 1 |
7037 | The process of applying these completion specifications when word completion | |
7038 | is attempted is described above under \fBProgrammable Completion\fP. | |
7039 | .sp 1 | |
7040 | Other options, if specified, have the following meanings. | |
7041 | The arguments to the \fB\-G\fP, \fB\-W\fP, and \fB\-X\fP options | |
7042 | (and, if necessary, the \fB\-P\fP and \fB\-S\fP options) | |
7043 | should be quoted to protect them from expansion before the | |
7044 | .B complete | |
7045 | builtin is invoked. | |
7046 | .RS | |
7047 | .PD 0 | |
7048 | .TP 8 | |
28ef6c31 JA |
7049 | \fB\-o\fP \fIcomp-option\fP |
7050 | The \fIcomp-option\fP controls several aspects of the compspec's behavior | |
7051 | beyond the simple generation of completions. | |
7052 | \fIcomp-option\fP may be one of: | |
7053 | .RS | |
7054 | .TP 8 | |
d3a24ed2 CR |
7055 | .B bashdefault |
7056 | Perform the rest of the default \fBbash\fP completions if the compspec | |
7057 | generates no matches. | |
7058 | .TP 8 | |
28ef6c31 | 7059 | .B default |
7117c2d2 JA |
7060 | Use readline's default filename completion if the compspec generates |
7061 | no matches. | |
28ef6c31 JA |
7062 | .TP 8 |
7063 | .B dirnames | |
7064 | Perform directory name completion if the compspec generates no matches. | |
7065 | .TP 8 | |
7066 | .B filenames | |
7067 | Tell readline that the compspec generates filenames, so it can perform any | |
e77a3058 CR |
7068 | filename\-specific processing (like adding a slash to directory names, |
7069 | quoting special characters, or suppressing trailing spaces). | |
7070 | Intended to be used with shell functions. | |
7117c2d2 | 7071 | .TP 8 |
084c952b CR |
7072 | .B noquote |
7073 | Tell readline not to quote the completed words if they are filenames | |
7074 | (quoting filenames is the default). | |
7075 | .TP 8 | |
7117c2d2 JA |
7076 | .B nospace |
7077 | Tell readline not to append a space (the default) to words completed at | |
7078 | the end of the line. | |
301e2142 CR |
7079 | .TP 8 |
7080 | .B plusdirs | |
7081 | After any matches defined by the compspec are generated, | |
7082 | directory name completion is attempted and any | |
7083 | matches are added to the results of the other actions. | |
28ef6c31 JA |
7084 | .RE |
7085 | .TP 8 | |
bb70624e JA |
7086 | \fB\-A\fP \fIaction\fP |
7087 | The \fIaction\fP may be one of the following to generate a list of possible | |
7088 | completions: | |
7089 | .RS | |
7090 | .TP 8 | |
7091 | .B alias | |
7092 | Alias names. May also be specified as \fB\-a\fP. | |
7093 | .TP 8 | |
7094 | .B arrayvar | |
7095 | Array variable names. | |
7096 | .TP 8 | |
7097 | .B binding | |
7098 | \fBReadline\fP key binding names. | |
7099 | .TP 8 | |
7100 | .B builtin | |
7101 | Names of shell builtin commands. May also be specified as \fB\-b\fP. | |
7102 | .TP 8 | |
7103 | .B command | |
7104 | Command names. May also be specified as \fB\-c\fP. | |
7105 | .TP 8 | |
7106 | .B directory | |
7107 | Directory names. May also be specified as \fB\-d\fP. | |
7108 | .TP 8 | |
7109 | .B disabled | |
7110 | Names of disabled shell builtins. | |
7111 | .TP 8 | |
7112 | .B enabled | |
7113 | Names of enabled shell builtins. | |
7114 | .TP 8 | |
7115 | .B export | |
7116 | Names of exported shell variables. May also be specified as \fB\-e\fP. | |
7117 | .TP 8 | |
7118 | .B file | |
7119 | File names. May also be specified as \fB\-f\fP. | |
7120 | .TP 8 | |
7121 | .B function | |
7122 | Names of shell functions. | |
7123 | .TP 8 | |
f73dda09 JA |
7124 | .B group |
7125 | Group names. May also be specified as \fB\-g\fP. | |
7126 | .TP 8 | |
bb70624e JA |
7127 | .B helptopic |
7128 | Help topics as accepted by the \fBhelp\fP builtin. | |
7129 | .TP 8 | |
7130 | .B hostname | |
7131 | Hostnames, as taken from the file specified by the | |
7132 | .SM | |
7133 | .B HOSTFILE | |
7134 | shell variable. | |
7135 | .TP 8 | |
7136 | .B job | |
7137 | Job names, if job control is active. May also be specified as \fB\-j\fP. | |
7138 | .TP 8 | |
7139 | .B keyword | |
7140 | Shell reserved words. May also be specified as \fB\-k\fP. | |
7141 | .TP 8 | |
7142 | .B running | |
7143 | Names of running jobs, if job control is active. | |
7144 | .TP 8 | |
7117c2d2 JA |
7145 | .B service |
7146 | Service names. May also be specified as \fB\-s\fP. | |
7147 | .TP 8 | |
bb70624e JA |
7148 | .B setopt |
7149 | Valid arguments for the \fB\-o\fP option to the \fBset\fP builtin. | |
7150 | .TP 8 | |
7151 | .B shopt | |
7152 | Shell option names as accepted by the \fBshopt\fP builtin. | |
7153 | .TP 8 | |
7154 | .B signal | |
7155 | Signal names. | |
7156 | .TP 8 | |
7157 | .B stopped | |
7158 | Names of stopped jobs, if job control is active. | |
7159 | .TP 8 | |
7160 | .B user | |
7161 | User names. May also be specified as \fB\-u\fP. | |
7162 | .TP 8 | |
7163 | .B variable | |
7164 | Names of all shell variables. May also be specified as \fB\-v\fP. | |
7165 | .RE | |
7166 | .TP 8 | |
bb70624e JA |
7167 | \fB\-C\fP \fIcommand\fP |
7168 | \fIcommand\fP is executed in a subshell environment, and its output is | |
7169 | used as the possible completions. | |
7170 | .TP 8 | |
7171 | \fB\-F\fP \fIfunction\fP | |
7172 | The shell function \fIfunction\fP is executed in the current shell | |
7173 | environment. | |
ba4ab055 CR |
7174 | When the function is executed, |
7175 | the first argument (\fB$1\fP) is the name of the command whose arguments are | |
7176 | being completed, | |
7177 | the second argument (\fB$2\fP) is the word being completed, | |
7178 | and the third argument (\fB$3\fP) is the word preceding the word being | |
7179 | completed on the current command line. | |
bb70624e JA |
7180 | When it finishes, the possible completions are retrieved from the value |
7181 | of the | |
7182 | .SM | |
7183 | .B COMPREPLY | |
7184 | array variable. | |
7185 | .TP 8 | |
5cdaaf76 CR |
7186 | \fB\-G\fP \fIglobpat\fP |
7187 | The pathname expansion pattern \fIglobpat\fP is expanded to generate | |
7188 | the possible completions. | |
bb70624e JA |
7189 | .TP 8 |
7190 | \fB\-P\fP \fIprefix\fP | |
7191 | \fIprefix\fP is added at the beginning of each possible completion | |
7192 | after all other options have been applied. | |
7193 | .TP 8 | |
7194 | \fB\-S\fP \fIsuffix\fP | |
7195 | \fIsuffix\fP is appended to each possible completion | |
7196 | after all other options have been applied. | |
5cdaaf76 CR |
7197 | .TP 8 |
7198 | \fB\-W\fP \fIwordlist\fP | |
7199 | The \fIwordlist\fP is split using the characters in the | |
7200 | .SM | |
7201 | .B IFS | |
7202 | special variable as delimiters, and each resultant word is expanded. | |
7203 | The possible completions are the members of the resultant list which | |
7204 | match the word being completed. | |
7205 | .TP 8 | |
7206 | \fB\-X\fP \fIfilterpat\fP | |
7207 | \fIfilterpat\fP is a pattern as used for pathname expansion. | |
7208 | It is applied to the list of possible completions generated by the | |
7209 | preceding options and arguments, and each completion matching | |
7210 | \fIfilterpat\fP is removed from the list. | |
7211 | A leading \fB!\fP in \fIfilterpat\fP negates the pattern; in this | |
7212 | case, any completion not matching \fIfilterpat\fP is removed. | |
bb70624e JA |
7213 | .PD |
7214 | .PP | |
7215 | The return value is true unless an invalid option is supplied, an option | |
7216 | other than \fB\-p\fP or \fB\-r\fP is supplied without a \fIname\fP | |
7217 | argument, an attempt is made to remove a completion specification for | |
7218 | a \fIname\fP for which no specification exists, or | |
7219 | an error occurs adding a completion specification. | |
7220 | .RE | |
7221 | .TP | |
3eb2d94a | 7222 | \fBcompopt\fP [\fB\-o\fP \fIoption\fP] [\fB\-DE\fP] [\fB+o\fP \fIoption\fP] [\fIname\fP] |
6fbe7620 CR |
7223 | Modify completion options for each \fIname\fP according to the |
7224 | \fIoption\fPs, or for the | |
5cdaaf76 | 7225 | currently-executing completion if no \fIname\fPs are supplied. |
6fbe7620 CR |
7226 | If no \fIoption\fPs are given, display the completion options for each |
7227 | \fIname\fP or the current completion. | |
7228 | The possible values of \fIoption\fP are those valid for the \fBcomplete\fP | |
7229 | builtin described above. | |
3eb2d94a CR |
7230 | The \fB\-D\fP option indicates that the remaining options should |
7231 | apply to the ``default'' command completion; that is, completion attempted | |
7232 | on a command for which no completion has previously been defined. | |
7233 | The \fB\-E\fP option indicates that the remaining options should | |
7234 | apply to ``empty'' command completion; that is, completion attempted on a | |
7235 | blank line. | |
9c7f20c7 | 7236 | .sp 1 |
6fbe7620 CR |
7237 | The return value is true unless an invalid option is supplied, an attempt |
7238 | is made to modify the options for a \fIname\fP for which no completion | |
7239 | specification exists, or an output error occurs. | |
7240 | .TP | |
726f6388 JA |
7241 | \fBcontinue\fP [\fIn\fP] |
7242 | Resume the next iteration of the enclosing | |
7243 | .BR for , | |
7244 | .BR while , | |
ccc6cda3 | 7245 | .BR until , |
726f6388 | 7246 | or |
ccc6cda3 | 7247 | .B select |
726f6388 JA |
7248 | loop. |
7249 | If | |
7250 | .I n | |
7251 | is specified, resume at the \fIn\fPth enclosing loop. | |
7252 | .I n | |
7253 | must be \(>= 1. If | |
7254 | .I n | |
7255 | is greater than the number of enclosing loops, the last enclosing loop | |
33fe8777 CR |
7256 | (the ``top-level'' loop) is resumed. |
7257 | The return value is 0 unless \fIn\fP is not greater than or equal to 1. | |
726f6388 | 7258 | .TP |
6faad625 | 7259 | \fBdeclare\fP [\fB\-aAfFgilrtux\fP] [\fB\-p\fP] [\fIname\fP[=\fIvalue\fP] ...] |
726f6388 | 7260 | .PD 0 |
726f6388 | 7261 | .TP |
6faad625 | 7262 | \fBtypeset\fP [\fB\-aAfFgilrtux\fP] [\fB\-p\fP] [\fIname\fP[=\fIvalue\fP] ...] |
726f6388 | 7263 | .PD |
ccc6cda3 JA |
7264 | Declare variables and/or give them attributes. |
7265 | If no \fIname\fPs are given then display the values of variables. | |
7266 | The | |
7267 | .B \-p | |
7268 | option will display the attributes and values of each | |
7269 | .IR name . | |
7270 | When | |
7271 | .B \-p | |
6fbe7620 CR |
7272 | is used with \fIname\fP arguments, additional options are ignored. |
7273 | When | |
7274 | .B \-p | |
7275 | is supplied without \fIname\fP arguments, it will display the attributes | |
7276 | and values of all variables having the attributes specified by the | |
7277 | additional options. | |
7278 | If no other options are supplied with \fB\-p\fP, \fBdeclare\fP will display | |
7279 | the attributes and values of all shell variables. The \fB\-f\fP option | |
7280 | will restrict the display to shell functions. | |
ccc6cda3 JA |
7281 | The |
7282 | .B \-F | |
7283 | option inhibits the display of function definitions; only the | |
7284 | function name and attributes are printed. | |
d3a24ed2 CR |
7285 | If the \fBextdebug\fP shell option is enabled using \fBshopt\fP, |
7286 | the source file name and line number where the function is defined | |
7287 | are displayed as well. The | |
ccc6cda3 JA |
7288 | .B \-F |
7289 | option implies | |
7290 | .BR \-f . | |
6faad625 CR |
7291 | The |
7292 | .B \-g | |
7293 | option forces variables to be created or modified at the global scope, | |
7294 | even when \fBdeclare\fP is executed in a shell function. | |
7295 | It is ignored in all other cases. | |
ccc6cda3 JA |
7296 | The following options can |
7297 | be used to restrict output to variables with the specified attribute or | |
7298 | to give variables attributes: | |
726f6388 JA |
7299 | .RS |
7300 | .PD 0 | |
7301 | .TP | |
ccc6cda3 | 7302 | .B \-a |
fdf670ea CR |
7303 | Each \fIname\fP is an indexed array variable (see |
7304 | .B Arrays | |
7305 | above). | |
7306 | .TP | |
7307 | .B \-A | |
7308 | Each \fIname\fP is an associative array variable (see | |
ccc6cda3 JA |
7309 | .B Arrays |
7310 | above). | |
7311 | .TP | |
726f6388 | 7312 | .B \-f |
ccc6cda3 JA |
7313 | Use function names only. |
7314 | .TP | |
7315 | .B \-i | |
7316 | The variable is treated as an integer; arithmetic evaluation (see | |
7317 | .SM | |
984a1947 CR |
7318 | .B "ARITHMETIC EVALUATION" |
7319 | above) is performed when the variable is assigned a value. | |
726f6388 | 7320 | .TP |
09767ff0 CR |
7321 | .B \-l |
7322 | When the variable is assigned a value, all upper-case characters are | |
7323 | converted to lower-case. | |
7324 | The upper-case attribute is disabled. | |
7325 | .TP | |
726f6388 JA |
7326 | .B \-r |
7327 | Make \fIname\fPs readonly. These names cannot then be assigned values | |
cce855bc | 7328 | by subsequent assignment statements or unset. |
726f6388 | 7329 | .TP |
7117c2d2 JA |
7330 | .B \-t |
7331 | Give each \fIname\fP the \fItrace\fP attribute. | |
76a8d78d CR |
7332 | Traced functions inherit the \fBDEBUG\fP and \fBRETURN\fP traps from |
7333 | the calling shell. | |
7117c2d2 JA |
7334 | The trace attribute has no special meaning for variables. |
7335 | .TP | |
09767ff0 CR |
7336 | .B \-u |
7337 | When the variable is assigned a value, all lower-case characters are | |
7338 | converted to upper-case. | |
7339 | The lower-case attribute is disabled. | |
7340 | .TP | |
726f6388 JA |
7341 | .B \-x |
7342 | Mark \fIname\fPs for export to subsequent commands via the environment. | |
726f6388 JA |
7343 | .PD |
7344 | .PP | |
7345 | Using `+' instead of `\-' | |
d3ad40de CR |
7346 | turns off the attribute instead, |
7347 | with the exceptions that \fB+a\fP | |
984a1947 | 7348 | may not be used to destroy an array variable and \fB+r\fP will not |
d3ad40de | 7349 | remove the readonly attribute. |
b28ff8c9 CR |
7350 | When used in a function, |
7351 | .B declare | |
7352 | and | |
7353 | .B typeset | |
7354 | make each | |
54a1fa7c | 7355 | \fIname\fP local, as with the |
726f6388 | 7356 | .B local |
6faad625 | 7357 | command, |
b28ff8c9 | 7358 | unless the \fB\-g\fP option is supplied. |
d3a24ed2 CR |
7359 | If a variable name is followed by =\fIvalue\fP, the value of |
7360 | the variable is set to \fIvalue\fP. | |
7361 | The return value is 0 unless an invalid option is encountered, | |
bb70624e JA |
7362 | an attempt is made to define a function using |
7363 | .if n ``\-f foo=bar'', | |
7364 | .if t \f(CW\-f foo=bar\fP, | |
ccc6cda3 JA |
7365 | an attempt is made to assign a value to a readonly variable, |
7366 | an attempt is made to assign a value to an array variable without | |
7367 | using the compound assignment syntax (see | |
7368 | .B Arrays | |
cce855bc | 7369 | above), one of the \fInames\fP is not a valid shell variable name, |
726f6388 | 7370 | an attempt is made to turn off readonly status for a readonly variable, |
ccc6cda3 | 7371 | an attempt is made to turn off array status for an array variable, |
bb70624e | 7372 | or an attempt is made to display a non-existent function with \fB\-f\fP. |
726f6388 JA |
7373 | .RE |
7374 | .TP | |
b28ff8c9 | 7375 | .B dirs [\fB\-clpv\fP] [+\fIn\fP] [\-\fIn\fP] |
ccc6cda3 JA |
7376 | Without options, displays the list of currently remembered directories. |
7377 | The default display is on a single line with directory names separated | |
7378 | by spaces. | |
7379 | Directories are added to the list with the | |
726f6388 JA |
7380 | .B pushd |
7381 | command; the | |
7382 | .B popd | |
ccc6cda3 | 7383 | command removes entries from the list. |
726f6388 JA |
7384 | .RS |
7385 | .PD 0 | |
7386 | .TP | |
ccc6cda3 JA |
7387 | .B \-c |
7388 | Clears the directory stack by deleting all of the entries. | |
7389 | .TP | |
726f6388 | 7390 | .B \-l |
b28ff8c9 CR |
7391 | Produces a listing using full pathnames; |
7392 | the default listing format uses a tilde to denote the home directory. | |
ccc6cda3 JA |
7393 | .TP |
7394 | .B \-p | |
7395 | Print the directory stack with one entry per line. | |
7396 | .TP | |
7397 | .B \-v | |
7398 | Print the directory stack with one entry per line, | |
7399 | prefixing each entry with its index in the stack. | |
b28ff8c9 CR |
7400 | .TP |
7401 | \fB+\fP\fIn\fP | |
7402 | Displays the \fIn\fPth entry counting from the left of the list | |
7403 | shown by | |
7404 | .B dirs | |
7405 | when invoked without options, starting with zero. | |
7406 | .TP | |
7407 | \fB\-\fP\fIn\fP | |
7408 | Displays the \fIn\fPth entry counting from the right of the list | |
7409 | shown by | |
7410 | .B dirs | |
7411 | when invoked without options, starting with zero. | |
726f6388 JA |
7412 | .PD |
7413 | .PP | |
7414 | The return value is 0 unless an | |
cce855bc | 7415 | invalid option is supplied or \fIn\fP indexes beyond the end |
726f6388 JA |
7416 | of the directory stack. |
7417 | .RE | |
7418 | .TP | |
cce855bc | 7419 | \fBdisown\fP [\fB\-ar\fP] [\fB\-h\fP] [\fIjobspec\fP ...] |
b28ff8c9 | 7420 | Without options, remove each |
ccc6cda3 | 7421 | .I jobspec |
b28ff8c9 | 7422 | from the table of active jobs. |
d3ad40de CR |
7423 | If |
7424 | .I jobspec | |
984a1947 | 7425 | is not present, and neither \fB\-a\fP nor \fB\-r\fP is supplied, |
d3ad40de | 7426 | the shell's notion of the \fIcurrent job\fP is used. |
cce855bc JA |
7427 | If the \fB\-h\fP option is given, each |
7428 | .I jobspec | |
7429 | is not removed from the table, but is marked so that | |
ccc6cda3 JA |
7430 | .SM |
7431 | .B SIGHUP | |
7432 | is not sent to the job if the shell receives a | |
7433 | .SM | |
7434 | .BR SIGHUP . | |
7435 | If no | |
7436 | .I jobspec | |
cce855bc JA |
7437 | is present, and neither the |
7438 | .B \-a | |
7439 | nor the | |
7440 | .B \-r | |
7441 | option is supplied, the \fIcurrent job\fP is used. | |
7442 | If no | |
7443 | .I jobspec | |
7444 | is supplied, the | |
7445 | .B \-a | |
7446 | option means to remove or mark all jobs; the | |
7447 | .B \-r | |
7448 | option without a | |
7449 | .I jobspec | |
7450 | argument restricts operation to running jobs. | |
7451 | The return value is 0 unless a | |
ccc6cda3 JA |
7452 | .I jobspec |
7453 | does not specify a valid job. | |
7454 | .TP | |
726f6388 | 7455 | \fBecho\fP [\fB\-neE\fP] [\fIarg\fP ...] |
ccc6cda3 | 7456 | Output the \fIarg\fPs, separated by spaces, followed by a newline. |
f6da9f85 | 7457 | The return status is 0 unless a write error occurs. |
ccc6cda3 | 7458 | If \fB\-n\fP is specified, the trailing newline is |
726f6388 JA |
7459 | suppressed. If the \fB\-e\fP option is given, interpretation of |
7460 | the following backslash-escaped characters is enabled. The | |
7461 | .B \-E | |
7462 | option disables the interpretation of these escape characters, | |
7463 | even on systems where they are interpreted by default. | |
28ef6c31 | 7464 | The \fBxpg_echo\fP shell option may be used to |
bb70624e JA |
7465 | dynamically determine whether or not \fBecho\fP expands these |
7466 | escape characters by default. | |
ccc6cda3 | 7467 | .B echo |
3ffb039a | 7468 | does not interpret \fB\-\-\fP to mean the end of options. |
ccc6cda3 JA |
7469 | .B echo |
7470 | interprets the following escape sequences: | |
726f6388 JA |
7471 | .RS |
7472 | .PD 0 | |
7473 | .TP | |
7474 | .B \ea | |
7475 | alert (bell) | |
7476 | .TP | |
7477 | .B \eb | |
7478 | backspace | |
7479 | .TP | |
7480 | .B \ec | |
2e4498b3 | 7481 | suppress further output |
726f6388 | 7482 | .TP |
ccc6cda3 | 7483 | .B \ee |
9ec5ed66 CR |
7484 | .TP |
7485 | .B \eE | |
ccc6cda3 JA |
7486 | an escape character |
7487 | .TP | |
726f6388 JA |
7488 | .B \ef |
7489 | form feed | |
7490 | .TP | |
7491 | .B \en | |
7492 | new line | |
7493 | .TP | |
7494 | .B \er | |
7495 | carriage return | |
7496 | .TP | |
7497 | .B \et | |
7498 | horizontal tab | |
7499 | .TP | |
7500 | .B \ev | |
7501 | vertical tab | |
7502 | .TP | |
7503 | .B \e\e | |
7504 | backslash | |
7505 | .TP | |
7117c2d2 JA |
7506 | .B \e0\fInnn\fP |
7507 | the eight-bit character whose value is the octal value \fInnn\fP | |
7508 | (zero to three octal digits) | |
7509 | .TP | |
f73dda09 JA |
7510 | .B \ex\fIHH\fP |
7511 | the eight-bit character whose value is the hexadecimal value \fIHH\fP | |
7512 | (one or two hex digits) | |
eb0b2ad8 CR |
7513 | .TP |
7514 | .B \eu\fIHHHH\fP | |
7515 | the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value | |
7516 | \fIHHHH\fP (one to four hex digits) | |
7517 | .TP | |
7518 | .B \eU\fIHHHHHHHH\fP | |
7519 | the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value | |
7520 | \fIHHHHHHHH\fP (one to eight hex digits) | |
726f6388 JA |
7521 | .PD |
7522 | .RE | |
7523 | .TP | |
d3ad40de | 7524 | \fBenable\fP [\fB\-a\fP] [\fB\-dnps\fP] [\fB\-f\fP \fIfilename\fP] [\fIname\fP ...] |
cce855bc JA |
7525 | Enable and disable builtin shell commands. |
7526 | Disabling a builtin allows a disk command which has the same name | |
bb70624e | 7527 | as a shell builtin to be executed without specifying a full pathname, |
cce855bc | 7528 | even though the shell normally searches for builtins before disk commands. |
726f6388 JA |
7529 | If \fB\-n\fP is used, each \fIname\fP |
7530 | is disabled; otherwise, | |
7531 | \fInames\fP are enabled. For example, to use the | |
7532 | .B test | |
7533 | binary found via the | |
7534 | .SM | |
7535 | .B PATH | |
ccc6cda3 | 7536 | instead of the shell builtin version, run |
28ef6c31 JA |
7537 | .if t \f(CWenable -n test\fP. |
7538 | .if n ``enable -n test''. | |
ccc6cda3 JA |
7539 | The |
7540 | .B \-f | |
7541 | option means to load the new builtin command | |
7542 | .I name | |
7543 | from shared object | |
7544 | .IR filename , | |
7545 | on systems that support dynamic loading. The | |
7546 | .B \-d | |
7547 | option will delete a builtin previously loaded with | |
7548 | .BR \-f . | |
7549 | If no \fIname\fP arguments are given, or if the | |
7550 | .B \-p | |
7551 | option is supplied, a list of shell builtins is printed. | |
7552 | With no other option arguments, the list consists of all enabled | |
7553 | shell builtins. | |
7554 | If \fB\-n\fP is supplied, only disabled builtins are printed. | |
7555 | If \fB\-a\fP is supplied, the list printed includes all builtins, with an | |
726f6388 | 7556 | indication of whether or not each is enabled. |
ccc6cda3 JA |
7557 | If \fB\-s\fP is supplied, the output is restricted to the POSIX |
7558 | \fIspecial\fP builtins. | |
726f6388 JA |
7559 | The return value is 0 unless a |
7560 | .I name | |
bb70624e | 7561 | is not a shell builtin or there is an error loading a new builtin |
ccc6cda3 | 7562 | from a shared object. |
726f6388 JA |
7563 | .TP |
7564 | \fBeval\fP [\fIarg\fP ...] | |
7565 | The \fIarg\fPs are read and concatenated together into a single | |
7566 | command. This command is then read and executed by the shell, and | |
ccc6cda3 JA |
7567 | its exit status is returned as the value of |
7568 | .BR eval . | |
7569 | If there are no | |
726f6388 JA |
7570 | .IR args , |
7571 | or only null arguments, | |
7572 | .B eval | |
ccc6cda3 | 7573 | returns 0. |
726f6388 | 7574 | .TP |
cce855bc | 7575 | \fBexec\fP [\fB\-cl\fP] [\fB\-a\fP \fIname\fP] [\fIcommand\fP [\fIarguments\fP]] |
726f6388 JA |
7576 | If |
7577 | .I command | |
7578 | is specified, it replaces the shell. | |
7579 | No new process is created. The | |
7580 | .I arguments | |
7581 | become the arguments to \fIcommand\fP. | |
ccc6cda3 JA |
7582 | If the |
7583 | .B \-l | |
7584 | option is supplied, | |
d3ad40de | 7585 | the shell places a dash at the beginning of the zeroth argument passed to |
726f6388 | 7586 | .IR command . |
ccc6cda3 JA |
7587 | This is what |
7588 | .IR login (1) | |
7589 | does. The | |
7590 | .B \-c | |
7591 | option causes | |
7592 | .I command | |
7593 | to be executed with an empty environment. If | |
7594 | .B \-a | |
7595 | is supplied, the shell passes | |
7596 | .I name | |
b28ff8c9 CR |
7597 | as the zeroth argument to the executed command. |
7598 | If | |
ccc6cda3 | 7599 | .I command |
726f6388 | 7600 | cannot be executed for some reason, a non-interactive shell exits, |
b28ff8c9 | 7601 | unless the |
ccc6cda3 | 7602 | .B execfail |
b28ff8c9 CR |
7603 | shell option |
7604 | is enabled. In that case, it returns failure. | |
ccc6cda3 | 7605 | An interactive shell returns failure if the file cannot be executed. |
726f6388 JA |
7606 | If |
7607 | .I command | |
7608 | is not specified, any redirections take effect in the current shell, | |
cce855bc JA |
7609 | and the return status is 0. If there is a redirection error, the |
7610 | return status is 1. | |
726f6388 JA |
7611 | .TP |
7612 | \fBexit\fP [\fIn\fP] | |
7613 | Cause the shell to exit | |
7614 | with a status of \fIn\fP. If | |
7615 | .I n | |
7616 | is omitted, the exit status | |
7617 | is that of the last command executed. | |
7618 | A trap on | |
7619 | .SM | |
7620 | .B EXIT | |
7621 | is executed before the shell terminates. | |
7622 | .TP | |
ccc6cda3 | 7623 | \fBexport\fP [\fB\-fn\fP\^] [\fIname\fP[=\fIword\fP]] ... |
7117c2d2 | 7624 | .PD 0 |
726f6388 JA |
7625 | .TP |
7626 | .B export \-p | |
7627 | .PD | |
7628 | The supplied | |
7629 | .I names | |
7630 | are marked for automatic export to the environment of | |
7631 | subsequently executed commands. If the | |
7632 | .B \-f | |
7633 | option is given, | |
7634 | the | |
7635 | .I names | |
7636 | refer to functions. | |
7637 | If no | |
7638 | .I names | |
7639 | are given, or if the | |
7640 | .B \-p | |
7641 | option is supplied, a list | |
b28ff8c9 | 7642 | of names of all exported variables is printed. |
726f6388 JA |
7643 | The |
7644 | .B \-n | |
5e13499c CR |
7645 | option causes the export property to be removed from each |
7646 | \fIname\fP. | |
d3a24ed2 CR |
7647 | If a variable name is followed by =\fIword\fP, the value of |
7648 | the variable is set to \fIword\fP. | |
726f6388 | 7649 | .B export |
cce855bc | 7650 | returns an exit status of 0 unless an invalid option is |
726f6388 | 7651 | encountered, |
cce855bc | 7652 | one of the \fInames\fP is not a valid shell variable name, or |
726f6388 JA |
7653 | .B \-f |
7654 | is supplied with a | |
7655 | .I name | |
7656 | that is not a function. | |
7657 | .TP | |
d3ad40de | 7658 | \fBfc\fP [\fB\-e\fP \fIename\fP] [\fB\-lnr\fP] [\fIfirst\fP] [\fIlast\fP] |
7117c2d2 | 7659 | .PD 0 |
726f6388 JA |
7660 | .TP |
7661 | \fBfc\fP \fB\-s\fP [\fIpat\fP=\fIrep\fP] [\fIcmd\fP] | |
7662 | .PD | |
b28ff8c9 | 7663 | The first form selects a range of commands from |
726f6388 JA |
7664 | .I first |
7665 | to | |
7666 | .I last | |
b28ff8c9 | 7667 | from the history list and displays or edits and re-executes them. |
726f6388 JA |
7668 | .I First |
7669 | and | |
7670 | .I last | |
7671 | may be specified as a string (to locate the last command beginning | |
7672 | with that string) or as a number (an index into the history list, | |
7673 | where a negative number is used as an offset from the current | |
7674 | command number). If | |
7675 | .I last | |
7676 | is not specified it is set to | |
7677 | the current command for listing (so that | |
bb70624e JA |
7678 | .if n ``fc \-l \-10'' |
7679 | .if t \f(CWfc \-l \-10\fP | |
726f6388 JA |
7680 | prints the last 10 commands) and to |
7681 | .I first | |
7682 | otherwise. | |
7683 | If | |
7684 | .I first | |
7685 | is not specified it is set to the previous | |
7686 | command for editing and \-16 for listing. | |
7687 | .sp 1 | |
7688 | The | |
7689 | .B \-n | |
cce855bc | 7690 | option suppresses |
726f6388 JA |
7691 | the command numbers when listing. The |
7692 | .B \-r | |
cce855bc | 7693 | option reverses the order of |
726f6388 JA |
7694 | the commands. If the |
7695 | .B \-l | |
cce855bc | 7696 | option is given, |
726f6388 JA |
7697 | the commands are listed on |
7698 | standard output. Otherwise, the editor given by | |
7699 | .I ename | |
7700 | is invoked | |
7701 | on a file containing those commands. If | |
7702 | .I ename | |
7703 | is not given, the | |
7704 | value of the | |
7705 | .SM | |
7706 | .B FCEDIT | |
7707 | variable is used, and | |
7708 | the value of | |
7709 | .SM | |
7710 | .B EDITOR | |
7711 | if | |
7712 | .SM | |
7713 | .B FCEDIT | |
7714 | is not set. If neither variable is set, | |
7715 | .FN vi | |
7716 | is used. When editing is complete, the edited commands are | |
7717 | echoed and executed. | |
7718 | .sp 1 | |
7719 | In the second form, \fIcommand\fP is re-executed after each instance | |
7720 | of \fIpat\fP is replaced by \fIrep\fP. | |
b28ff8c9 | 7721 | \fICommand\fP is intepreted the same as \fIfirst\fP above. |
ccc6cda3 | 7722 | A useful alias to use with this is |
d3a24ed2 | 7723 | .if n ``r="fc -s"'', |
ccc6cda3 JA |
7724 | .if t \f(CWr='fc \-s'\fP, |
7725 | so that typing | |
7726 | .if n ``r cc'' | |
7727 | .if t \f(CWr cc\fP | |
7728 | runs the last command beginning with | |
7729 | .if n ``cc'' | |
7730 | .if t \f(CWcc\fP | |
7731 | and typing | |
7732 | .if n ``r'' | |
7733 | .if t \f(CWr\fP | |
726f6388 JA |
7734 | re-executes the last command. |
7735 | .sp 1 | |
cce855bc | 7736 | If the first form is used, the return value is 0 unless an invalid |
726f6388 JA |
7737 | option is encountered or |
7738 | .I first | |
7739 | or | |
7740 | .I last | |
7741 | specify history lines out of range. | |
7742 | If the | |
7743 | .B \-e | |
7744 | option is supplied, the return value is the value of the last | |
7745 | command executed or failure if an error occurs with the temporary | |
7746 | file of commands. If the second form is used, the return status | |
7747 | is that of the command re-executed, unless | |
7748 | .I cmd | |
7749 | does not specify a valid history line, in which case | |
7750 | .B fc | |
7751 | returns failure. | |
7752 | .TP | |
7753 | \fBfg\fP [\fIjobspec\fP] | |
cce855bc | 7754 | Resume |
726f6388 | 7755 | .I jobspec |
cce855bc JA |
7756 | in the foreground, and make it the current job. |
7757 | If | |
726f6388 JA |
7758 | .I jobspec |
7759 | is not present, the shell's notion of the \fIcurrent job\fP is used. | |
7760 | The return value is that of the command placed into the foreground, | |
7761 | or failure if run when job control is disabled or, when run with | |
7762 | job control enabled, if | |
7763 | .I jobspec | |
7764 | does not specify a valid job or | |
7765 | .I jobspec | |
7766 | specifies a job that was started without job control. | |
7767 | .TP | |
7768 | \fBgetopts\fP \fIoptstring\fP \fIname\fP [\fIargs\fP] | |
7769 | .B getopts | |
7770 | is used by shell procedures to parse positional parameters. | |
7771 | .I optstring | |
bb70624e | 7772 | contains the option characters to be recognized; if a character |
726f6388 JA |
7773 | is followed by a colon, the option is expected to have an |
7774 | argument, which should be separated from it by white space. | |
bb70624e JA |
7775 | The colon and question mark characters may not be used as |
7776 | option characters. | |
726f6388 JA |
7777 | Each time it is invoked, |
7778 | .B getopts | |
7779 | places the next option in the shell variable | |
7780 | .IR name , | |
7781 | initializing | |
7782 | .I name | |
7783 | if it does not exist, | |
7784 | and the index of the next argument to be processed into the | |
7785 | variable | |
7786 | .SM | |
7787 | .BR OPTIND . | |
7788 | .SM | |
7789 | .B OPTIND | |
7790 | is initialized to 1 each time the shell or a shell script | |
7791 | is invoked. When an option requires an argument, | |
7792 | .B getopts | |
7793 | places that argument into the variable | |
7794 | .SM | |
7795 | .BR OPTARG . | |
7796 | The shell does not reset | |
7797 | .SM | |
7798 | .B OPTIND | |
7799 | automatically; it must be manually reset between multiple | |
7800 | calls to | |
7801 | .B getopts | |
7802 | within the same shell invocation if a new set of parameters | |
7803 | is to be used. | |
7804 | .sp 1 | |
cce855bc JA |
7805 | When the end of options is encountered, \fBgetopts\fP exits with a |
7806 | return value greater than zero. | |
984a1947 CR |
7807 | .SM |
7808 | .B OPTIND | |
7809 | is set to the index of the first non-option argument, | |
dc60d4e0 | 7810 | and \fIname\fP is set to ?. |
cce855bc JA |
7811 | .sp 1 |
7812 | .B getopts | |
7813 | normally parses the positional parameters, but if more arguments are | |
7814 | given in | |
7815 | .IR args , | |
7816 | .B getopts | |
7817 | parses those instead. | |
7818 | .sp 1 | |
726f6388 JA |
7819 | .B getopts |
7820 | can report errors in two ways. If the first character of | |
7821 | .I optstring | |
7822 | is a colon, | |
7823 | .I silent | |
b28ff8c9 | 7824 | error reporting is used. In normal operation, diagnostic messages |
cce855bc | 7825 | are printed when invalid options or missing option arguments are |
726f6388 JA |
7826 | encountered. |
7827 | If the variable | |
7828 | .SM | |
7829 | .B OPTERR | |
cce855bc | 7830 | is set to 0, no error messages will be displayed, even if the first |
726f6388 JA |
7831 | character of |
7832 | .I optstring | |
7833 | is not a colon. | |
7834 | .sp 1 | |
cce855bc | 7835 | If an invalid option is seen, |
726f6388 JA |
7836 | .B getopts |
7837 | places ? into | |
7838 | .I name | |
7839 | and, if not silent, | |
7840 | prints an error message and unsets | |
7841 | .SM | |
7842 | .BR OPTARG . | |
7843 | If | |
7844 | .B getopts | |
7845 | is silent, | |
7846 | the option character found is placed in | |
7847 | .SM | |
7848 | .B OPTARG | |
7849 | and no diagnostic message is printed. | |
7850 | .sp 1 | |
7851 | If a required argument is not found, and | |
7852 | .B getopts | |
7853 | is not silent, | |
7854 | a question mark (\^\fB?\fP\^) is placed in | |
7855 | .IR name , | |
f73dda09 | 7856 | .SM |
726f6388 JA |
7857 | .B OPTARG |
7858 | is unset, and a diagnostic message is printed. | |
7859 | If | |
7860 | .B getopts | |
7861 | is silent, then a colon (\^\fB:\fP\^) is placed in | |
7862 | .I name | |
7863 | and | |
7864 | .SM | |
7865 | .B OPTARG | |
7866 | is set to the option character found. | |
7867 | .sp 1 | |
7868 | .B getopts | |
726f6388 JA |
7869 | returns true if an option, specified or unspecified, is found. |
7870 | It returns false if the end of options is encountered or an | |
7871 | error occurs. | |
7872 | .TP | |
7117c2d2 | 7873 | \fBhash\fP [\fB\-lr\fP] [\fB\-p\fP \fIfilename\fP] [\fB\-dt\fP] [\fIname\fP] |
4691dc6b CR |
7874 | Each time \fBhash\fP is invoked, |
7875 | the full pathname of the command | |
7876 | .I name | |
7877 | is determined by searching | |
ccc6cda3 JA |
7878 | the directories in |
7879 | .B $PATH | |
4691dc6b | 7880 | and remembered. Any previously-remembered pathname is discarded. |
ccc6cda3 JA |
7881 | If the |
7882 | .B \-p | |
7883 | option is supplied, no path search is performed, and | |
7884 | .I filename | |
b28ff8c9 | 7885 | is used as the full filename of the command. |
ccc6cda3 | 7886 | The |
726f6388 JA |
7887 | .B \-r |
7888 | option causes the shell to forget all | |
f73dda09 | 7889 | remembered locations. |
7117c2d2 JA |
7890 | The |
7891 | .B \-d | |
7892 | option causes the shell to forget the remembered location of each \fIname\fP. | |
f73dda09 JA |
7893 | If the |
7894 | .B \-t | |
7895 | option is supplied, the full pathname to which each \fIname\fP corresponds | |
7896 | is printed. If multiple \fIname\fP arguments are supplied with \fB\-t\fP, | |
7897 | the \fIname\fP is printed before the hashed full pathname. | |
7117c2d2 JA |
7898 | The |
7899 | .B \-l | |
7900 | option causes output to be displayed in a format that may be reused as input. | |
7901 | If no arguments are given, or if only \fB\-l\fP is supplied, | |
7902 | information about remembered commands is printed. | |
ccc6cda3 | 7903 | The return status is true unless a |
726f6388 | 7904 | .I name |
cce855bc | 7905 | is not found or an invalid option is supplied. |
726f6388 | 7906 | .TP |
6a8fd0ed | 7907 | \fBhelp\fP [\fB\-dms\fP] [\fIpattern\fP] |
726f6388 JA |
7908 | Display helpful information about builtin commands. If |
7909 | .I pattern | |
7910 | is specified, | |
7911 | .B help | |
7912 | gives detailed help on all commands matching | |
7913 | .IR pattern ; | |
ccc6cda3 | 7914 | otherwise help for all the builtins and shell control structures |
bb70624e | 7915 | is printed. |
6a8fd0ed CR |
7916 | .RS |
7917 | .PD 0 | |
7918 | .TP | |
7919 | .B \-d | |
7920 | Display a short description of each \fIpattern\fP | |
7921 | .TP | |
6932f7f5 | 7922 | .B \-m |
6a8fd0ed CR |
7923 | Display the description of each \fIpattern\fP in a manpage-like format |
7924 | .TP | |
7925 | .B \-s | |
7926 | Display only a short usage synopsis for each \fIpattern\fP | |
7927 | .PD | |
54a1fa7c | 7928 | .PP |
bb70624e | 7929 | The return status is 0 unless no command matches |
726f6388 | 7930 | .IR pattern . |
54a1fa7c | 7931 | .RE |
726f6388 | 7932 | .TP |
bb70624e | 7933 | \fBhistory [\fIn\fP] |
7117c2d2 | 7934 | .PD 0 |
bb70624e JA |
7935 | .TP |
7936 | \fBhistory\fP \fB\-c\fP | |
7937 | .TP | |
7938 | \fBhistory \-d\fP \fIoffset\fP | |
ccc6cda3 JA |
7939 | .TP |
7940 | \fBhistory\fP \fB\-anrw\fP [\fIfilename\fP] | |
726f6388 | 7941 | .TP |
ccc6cda3 JA |
7942 | \fBhistory\fP \fB\-p\fP \fIarg\fP [\fIarg ...\fP] |
7943 | .TP | |
7944 | \fBhistory\fP \fB\-s\fP \fIarg\fP [\fIarg ...\fP] | |
726f6388 JA |
7945 | .PD |
7946 | With no options, display the command | |
7947 | history list with line numbers. Lines listed | |
7948 | with a | |
7949 | .B * | |
7950 | have been modified. An argument of | |
7951 | .I n | |
7952 | lists only the last | |
7953 | .I n | |
d3a24ed2 | 7954 | lines. |
984a1947 CR |
7955 | If the shell variable |
7956 | .SM | |
7957 | .B HISTTIMEFORMAT | |
7958 | is set and not null, | |
d3a24ed2 CR |
7959 | it is used as a format string for \fIstrftime\fP(3) to display |
7960 | the time stamp associated with each displayed history entry. | |
7961 | No intervening blank is printed between the formatted time stamp | |
7962 | and the history line. | |
7963 | If \fIfilename\fP is supplied, it is used as the | |
726f6388 JA |
7964 | name of the history file; if not, the value of |
7965 | .SM | |
7966 | .B HISTFILE | |
7967 | is used. Options, if supplied, have the following meanings: | |
7968 | .RS | |
7969 | .PD 0 | |
7970 | .TP | |
bb70624e JA |
7971 | .B \-c |
7972 | Clear the history list by deleting all the entries. | |
7973 | .TP | |
7974 | \fB\-d\fP \fIoffset\fP | |
7975 | Delete the history entry at position \fIoffset\fP. | |
7976 | .TP | |
726f6388 JA |
7977 | .B \-a |
7978 | Append the ``new'' history lines (history lines entered since the | |
ccc6cda3 | 7979 | beginning of the current \fBbash\fP session) to the history file. |
726f6388 JA |
7980 | .TP |
7981 | .B \-n | |
7982 | Read the history lines not already read from the history | |
7983 | file into the current history list. These are lines | |
7984 | appended to the history file since the beginning of the | |
7985 | current \fBbash\fP session. | |
7986 | .TP | |
7987 | .B \-r | |
7988 | Read the contents of the history file | |
b28ff8c9 | 7989 | and append them to the current history list. |
726f6388 JA |
7990 | .TP |
7991 | .B \-w | |
b28ff8c9 | 7992 | Write the current history list to the history file, overwriting the |
726f6388 | 7993 | history file's contents. |
ccc6cda3 | 7994 | .TP |
ccc6cda3 JA |
7995 | .B \-p |
7996 | Perform history substitution on the following \fIargs\fP and display | |
7997 | the result on the standard output. | |
7998 | Does not store the results in the history list. | |
7999 | Each \fIarg\fP must be quoted to disable normal history expansion. | |
8000 | .TP | |
8001 | .B \-s | |
8002 | Store the | |
8003 | .I args | |
8004 | in the history list as a single entry. The last command in the | |
8005 | history list is removed before the | |
8006 | .I args | |
8007 | are added. | |
726f6388 JA |
8008 | .PD |
8009 | .PP | |
984a1947 CR |
8010 | If the |
8011 | .SM | |
8012 | .B HISTTIMEFORMAT | |
8013 | variable is set, the time stamp information | |
d3ad40de CR |
8014 | associated with each history entry is written to the history file, |
8015 | marked with the history comment character. | |
8016 | When the history file is read, lines beginning with the history | |
8017 | comment character followed immediately by a digit are interpreted | |
8018 | as timestamps for the previous history line. | |
bb70624e JA |
8019 | The return value is 0 unless an invalid option is encountered, an |
8020 | error occurs while reading or writing the history file, an invalid | |
8021 | \fIoffset\fP is supplied as an argument to \fB\-d\fP, or the | |
8022 | history expansion supplied as an argument to \fB\-p\fP fails. | |
726f6388 JA |
8023 | .RE |
8024 | .TP | |
ccc6cda3 | 8025 | \fBjobs\fP [\fB\-lnprs\fP] [ \fIjobspec\fP ... ] |
7117c2d2 | 8026 | .PD 0 |
726f6388 JA |
8027 | .TP |
8028 | \fBjobs\fP \fB\-x\fP \fIcommand\fP [ \fIargs\fP ... ] | |
8029 | .PD | |
ccc6cda3 JA |
8030 | The first form lists the active jobs. The options have the following |
8031 | meanings: | |
8032 | .RS | |
8033 | .PD 0 | |
8034 | .TP | |
726f6388 | 8035 | .B \-l |
ccc6cda3 JA |
8036 | List process IDs |
8037 | in addition to the normal information. | |
8038 | .TP | |
726f6388 | 8039 | .B \-n |
ccc6cda3 JA |
8040 | Display information only about jobs that have changed status since |
8041 | the user was last notified of their status. | |
8042 | .TP | |
5cdaaf76 CR |
8043 | .B \-p |
8044 | List only the process ID of the job's process group | |
8045 | leader. | |
8046 | .TP | |
ccc6cda3 | 8047 | .B \-r |
b28ff8c9 | 8048 | Display only running jobs. |
ccc6cda3 JA |
8049 | .TP |
8050 | .B \-s | |
b28ff8c9 | 8051 | Display only stopped jobs. |
ccc6cda3 JA |
8052 | .PD |
8053 | .PP | |
8054 | If | |
726f6388 JA |
8055 | .I jobspec |
8056 | is given, output is restricted to information about that job. | |
cce855bc JA |
8057 | The return status is 0 unless an invalid option is encountered |
8058 | or an invalid | |
726f6388 JA |
8059 | .I jobspec |
8060 | is supplied. | |
ccc6cda3 | 8061 | .PP |
726f6388 JA |
8062 | If the |
8063 | .B \-x | |
8064 | option is supplied, | |
8065 | .B jobs | |
8066 | replaces any | |
8067 | .I jobspec | |
8068 | found in | |
8069 | .I command | |
8070 | or | |
8071 | .I args | |
8072 | with the corresponding process group ID, and executes | |
8073 | .I command | |
8074 | passing it | |
8075 | .IR args , | |
8076 | returning its exit status. | |
ccc6cda3 | 8077 | .RE |
726f6388 | 8078 | .TP |
ccc6cda3 | 8079 | \fBkill\fP [\fB\-s\fP \fIsigspec\fP | \fB\-n\fP \fIsignum\fP | \fB\-\fP\fIsigspec\fP] [\fIpid\fP | \fIjobspec\fP] ... |
7117c2d2 | 8080 | .PD 0 |
726f6388 | 8081 | .TP |
cce855bc | 8082 | \fBkill\fP \fB\-l\fP [\fIsigspec\fP | \fIexit_status\fP] |
726f6388 JA |
8083 | .PD |
8084 | Send the signal named by | |
8085 | .I sigspec | |
ccc6cda3 JA |
8086 | or |
8087 | .I signum | |
726f6388 JA |
8088 | to the processes named by |
8089 | .I pid | |
8090 | or | |
8091 | .IR jobspec . | |
8092 | .I sigspec | |
61deeb13 | 8093 | is either a case-insensitive signal name such as |
726f6388 JA |
8094 | .SM |
8095 | .B SIGKILL | |
61deeb13 | 8096 | (with or without the |
726f6388 JA |
8097 | .SM |
8098 | .B SIG | |
61deeb13 CR |
8099 | prefix) or a signal number; |
8100 | .I signum | |
8101 | is a signal number. | |
726f6388 JA |
8102 | If |
8103 | .I sigspec | |
8104 | is not present, then | |
8105 | .SM | |
8106 | .B SIGTERM | |
cce855bc JA |
8107 | is assumed. |
8108 | An argument of | |
726f6388 | 8109 | .B \-l |
cce855bc JA |
8110 | lists the signal names. |
8111 | If any arguments are supplied when | |
726f6388 | 8112 | .B \-l |
cce855bc JA |
8113 | is given, the names of the signals corresponding to the arguments are |
8114 | listed, and the return status is 0. | |
8115 | The \fIexit_status\fP argument to | |
ccc6cda3 | 8116 | .B \-l |
cce855bc JA |
8117 | is a number specifying either a signal number or the exit status of |
8118 | a process terminated by a signal. | |
726f6388 JA |
8119 | .B kill |
8120 | returns true if at least one signal was successfully sent, or false | |
cce855bc | 8121 | if an error occurs or an invalid option is encountered. |
726f6388 JA |
8122 | .TP |
8123 | \fBlet\fP \fIarg\fP [\fIarg\fP ...] | |
8124 | Each | |
8125 | .I arg | |
8126 | is an arithmetic expression to be evaluated (see | |
8127 | .SM | |
984a1947 CR |
8128 | .B "ARITHMETIC EVALUATION" |
8129 | above). | |
726f6388 JA |
8130 | If the last |
8131 | .I arg | |
8132 | evaluates to 0, | |
8133 | .B let | |
8134 | returns 1; 0 is returned otherwise. | |
8135 | .TP | |
bb70624e | 8136 | \fBlocal\fP [\fIoption\fP] [\fIname\fP[=\fIvalue\fP] ...] |
cce855bc JA |
8137 | For each argument, a local variable named |
8138 | .I name | |
8139 | is created, and assigned | |
726f6388 | 8140 | .IR value . |
bb70624e | 8141 | The \fIoption\fP can be any of the options accepted by \fBdeclare\fP. |
726f6388 JA |
8142 | When |
8143 | .B local | |
8144 | is used within a function, it causes the variable | |
8145 | .I name | |
8146 | to have a visible scope restricted to that function and its children. | |
8147 | With no operands, | |
8148 | .B local | |
8149 | writes a list of local variables to the standard output. It is | |
8150 | an error to use | |
8151 | .B local | |
8152 | when not within a function. The return status is 0 unless | |
8153 | .B local | |
bb70624e | 8154 | is used outside a function, an invalid |
726f6388 | 8155 | .I name |
bb70624e JA |
8156 | is supplied, or |
8157 | \fIname\fP is a readonly variable. | |
726f6388 JA |
8158 | .TP |
8159 | .B logout | |
8160 | Exit a login shell. | |
8161 | .TP | |
09767ff0 | 8162 | \fBmapfile\fP [\fB\-n\fP \fIcount\fP] [\fB\-O\fP \fIorigin\fP] [\fB\-s\fP \fIcount\fP] [\fB\-t\fP] [\fB\-u\fP \fIfd\fP] [\fB\-C\fP \fIcallback\fP] [\fB\-c\fP \fIquantum\fP] [\fIarray\fP] |
e141c35a CR |
8163 | .PD 0 |
8164 | .TP | |
8165 | \fBreadarray\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] | |
8166 | .PD | |
e1e48bba | 8167 | Read lines from the standard input into the indexed array variable |
6a8fd0ed CR |
8168 | .IR array , |
8169 | or from file descriptor | |
8170 | .IR fd | |
8171 | if the | |
8172 | .B \-u | |
8173 | option is supplied. | |
984a1947 CR |
8174 | The variable |
8175 | .SM | |
8176 | .B MAPFILE | |
8177 | is the default \fIarray\fP. | |
6a8fd0ed CR |
8178 | Options, if supplied, have the following meanings: |
8179 | .RS | |
8180 | .PD 0 | |
8181 | .TP | |
8182 | .B \-n | |
8183 | Copy at most | |
8184 | .I count | |
8185 | lines. If \fIcount\fP is 0, all lines are copied. | |
8186 | .TP | |
8187 | .B \-O | |
8188 | Begin assigning to | |
8189 | .I array | |
8190 | at index | |
8191 | .IR origin . | |
8192 | The default index is 0. | |
8193 | .TP | |
8194 | .B \-s | |
8195 | Discard the first \fIcount\fP lines read. | |
8196 | .TP | |
8197 | .B \-t | |
984a1947 | 8198 | Remove a trailing newline from each line read. |
6a8fd0ed CR |
8199 | .TP |
8200 | .B \-u | |
8201 | Read lines from file descriptor \fIfd\fP instead of the standard input. | |
8202 | .TP | |
8203 | .B \-C | |
8204 | Evaluate | |
8205 | .I callback | |
8206 | each time \fIquantum\fP lines are read. The \fB\-c\fP option specifies | |
8207 | .IR quantum . | |
8208 | .TP | |
8209 | .B \-c | |
8210 | Specify the number of lines read between each call to | |
8211 | .IR callback . | |
8212 | .PD | |
8213 | .PP | |
8214 | If | |
8215 | .B \-C | |
8216 | is specified without | |
8217 | .BR \-c , | |
8218 | the default quantum is 5000. | |
e141c35a | 8219 | When \fIcallback\fP is evaluated, it is supplied the index of the next |
6faad625 CR |
8220 | array element to be assigned and the line to be assigned to that element |
8221 | as additional arguments. | |
e141c35a CR |
8222 | \fIcallback\fP is evaluated after the line is read but before the |
8223 | array element is assigned. | |
6a8fd0ed CR |
8224 | .PP |
8225 | If not supplied with an explicit origin, \fBmapfile\fP will clear \fIarray\fP | |
8226 | before assigning to it. | |
8227 | .PP | |
8228 | \fBmapfile\fP returns successfully unless an invalid option or option | |
e1e48bba CR |
8229 | argument is supplied, \fIarray\fP is invalid or unassignable, or if |
8230 | \fIarray\fP is not an indexed array. | |
6a8fd0ed CR |
8231 | .RE |
8232 | .TP | |
ccc6cda3 | 8233 | \fBpopd\fP [\-\fBn\fP] [+\fIn\fP] [\-\fIn\fP] |
726f6388 JA |
8234 | Removes entries from the directory stack. With no arguments, |
8235 | removes the top directory from the stack, and performs a | |
8236 | .B cd | |
8237 | to the new top directory. | |
ccc6cda3 | 8238 | Arguments, if supplied, have the following meanings: |
726f6388 JA |
8239 | .RS |
8240 | .PD 0 | |
8241 | .TP | |
d3ad40de CR |
8242 | .B \-n |
8243 | Suppresses the normal change of directory when removing directories | |
8244 | from the stack, so that only the stack is manipulated. | |
8245 | .TP | |
ccc6cda3 JA |
8246 | \fB+\fP\fIn\fP |
8247 | Removes the \fIn\fPth entry counting from the left of the list | |
726f6388 JA |
8248 | shown by |
8249 | .BR dirs , | |
bb70624e JA |
8250 | starting with zero. For example: |
8251 | .if n ``popd +0'' | |
8252 | .if t \f(CWpopd +0\fP | |
8253 | removes the first directory, | |
8254 | .if n ``popd +1'' | |
8255 | .if t \f(CWpopd +1\fP | |
8256 | the second. | |
726f6388 | 8257 | .TP |
ccc6cda3 JA |
8258 | \fB\-\fP\fIn\fP |
8259 | Removes the \fIn\fPth entry counting from the right of the list | |
726f6388 JA |
8260 | shown by |
8261 | .BR dirs , | |
bb70624e JA |
8262 | starting with zero. For example: |
8263 | .if n ``popd -0'' | |
8264 | .if t \f(CWpopd -0\fP | |
8265 | removes the last directory, | |
8266 | .if n ``popd -1'' | |
8267 | .if t \f(CWpopd -1\fP | |
8268 | the next to last. | |
726f6388 JA |
8269 | .PD |
8270 | .PP | |
8271 | If the | |
8272 | .B popd | |
8273 | command is successful, a | |
8274 | .B dirs | |
8275 | is performed as well, and the return status is 0. | |
8276 | .B popd | |
cce855bc | 8277 | returns false if an invalid option is encountered, the directory stack |
726f6388 JA |
8278 | is empty, a non-existent directory stack entry is specified, or the |
8279 | directory change fails. | |
8280 | .RE | |
8281 | .TP | |
3ee6b87d | 8282 | \fBprintf\fP [\fB\-v\fP \fIvar\fP] \fIformat\fP [\fIarguments\fP] |
cce855bc JA |
8283 | Write the formatted \fIarguments\fP to the standard output under the |
8284 | control of the \fIformat\fP. | |
6faad625 CR |
8285 | The \fB\-v\fP option causes the output to be assigned to the variable |
8286 | \fIvar\fP rather than being printed to the standard output. | |
8287 | .sp 1 | |
cce855bc JA |
8288 | The \fIformat\fP is a character string which contains three types of objects: |
8289 | plain characters, which are simply copied to standard output, character | |
8290 | escape sequences, which are converted and copied to the standard output, and | |
8291 | format specifications, each of which causes printing of the next successive | |
8292 | \fIargument\fP. | |
6faad625 CR |
8293 | In addition to the standard \fIprintf\fP(1) format specifications, |
8294 | \fBprintf\fP interprets the following extensions: | |
8295 | .RS | |
8296 | .PD 0 | |
8297 | .TP | |
8298 | .B %b | |
8299 | causes | |
cce855bc | 8300 | \fBprintf\fP to expand backslash escape sequences in the corresponding |
5e13499c | 8301 | \fIargument\fP (except that \fB\ec\fP terminates output, backslashes in |
20587658 | 8302 | \fB\e\(aq\fP, \fB\e"\fP, and \fB\e?\fP are not removed, and octal escapes |
6faad625 CR |
8303 | beginning with \fB\e0\fP may contain up to four digits). |
8304 | .TP | |
8305 | .B %q | |
8306 | causes \fBprintf\fP to output the corresponding | |
cce855bc | 8307 | \fIargument\fP in a format that can be reused as shell input. |
6faad625 CR |
8308 | .TP |
8309 | .B %(\fIdatefmt\fP)T | |
8310 | causes \fBprintf\fP to output the date-time string resulting from using | |
8311 | \fIdatefmt\fP as a format string for \fIstrftime\fP(3). The corresponding | |
8312 | \fIargument\fP is an integer representing the number of seconds since the | |
8313 | epoch. Two special argument values may be used: -1 represents the current | |
8314 | time, and -2 represents the time the shell was invoked. | |
8315 | .PD | |
8316 | .PP | |
112ff2a6 CR |
8317 | Arguments to non-string format specifiers are treated as C constants, |
8318 | except that a leading plus or minus sign is allowed, and if the leading | |
8319 | character is a single or double quote, the value is the ASCII value of | |
8320 | the following character. | |
6faad625 | 8321 | .PP |
cce855bc JA |
8322 | The \fIformat\fP is reused as necessary to consume all of the \fIarguments\fP. |
8323 | If the \fIformat\fP requires more \fIarguments\fP than are supplied, the | |
8324 | extra format specifications behave as if a zero value or null string, as | |
6faad625 CR |
8325 | appropriate, had been supplied. |
8326 | The return value is zero on success, non-zero on failure. | |
8327 | .RE | |
cce855bc | 8328 | .TP |
d3ad40de | 8329 | \fBpushd\fP [\fB\-n\fP] [+\fIn\fP] [\-\fIn\fP] |
7117c2d2 | 8330 | .PD 0 |
726f6388 | 8331 | .TP |
d3ad40de | 8332 | \fBpushd\fP [\fB\-n\fP] [\fIdir\fP] |
726f6388 JA |
8333 | .PD |
8334 | Adds a directory to the top of the directory stack, or rotates | |
8335 | the stack, making the new top of the stack the current working | |
8336 | directory. With no arguments, exchanges the top two directories | |
8337 | and returns 0, unless the directory stack is empty. | |
ccc6cda3 | 8338 | Arguments, if supplied, have the following meanings: |
726f6388 JA |
8339 | .RS |
8340 | .PD 0 | |
8341 | .TP | |
d3ad40de CR |
8342 | .B \-n |
8343 | Suppresses the normal change of directory when adding directories | |
8344 | to the stack, so that only the stack is manipulated. | |
8345 | .TP | |
ccc6cda3 | 8346 | \fB+\fP\fIn\fP |
726f6388 JA |
8347 | Rotates the stack so that the \fIn\fPth directory |
8348 | (counting from the left of the list shown by | |
d166f048 JA |
8349 | .BR dirs , |
8350 | starting with zero) | |
726f6388 JA |
8351 | is at the top. |
8352 | .TP | |
ccc6cda3 | 8353 | \fB\-\fP\fIn\fP |
726f6388 | 8354 | Rotates the stack so that the \fIn\fPth directory |
d166f048 JA |
8355 | (counting from the right of the list shown by |
8356 | .BR dirs , | |
8357 | starting with zero) is at the top. | |
726f6388 | 8358 | .TP |
bb70624e | 8359 | .I dir |
ccc6cda3 | 8360 | Adds |
726f6388 JA |
8361 | .I dir |
8362 | to the directory stack at the top, making it the | |
19baff85 CR |
8363 | new current working directory as if it had been supplied as the argument |
8364 | to the \fBcd\fP builtin. | |
726f6388 JA |
8365 | .PD |
8366 | .PP | |
8367 | If the | |
8368 | .B pushd | |
8369 | command is successful, a | |
8370 | .B dirs | |
8371 | is performed as well. | |
8372 | If the first form is used, | |
8373 | .B pushd | |
8374 | returns 0 unless the cd to | |
8375 | .I dir | |
8376 | fails. With the second form, | |
8377 | .B pushd | |
8378 | returns 0 unless the directory stack is empty, | |
ccc6cda3 | 8379 | a non-existent directory stack element is specified, |
726f6388 JA |
8380 | or the directory change to the specified new current directory |
8381 | fails. | |
8382 | .RE | |
8383 | .TP | |
ccc6cda3 | 8384 | \fBpwd\fP [\fB\-LP\fP] |
bb70624e JA |
8385 | Print the absolute pathname of the current working directory. |
8386 | The pathname printed contains no symbolic links if the | |
726f6388 | 8387 | .B \-P |
ccc6cda3 JA |
8388 | option is supplied or the |
8389 | .B \-o physical | |
726f6388 JA |
8390 | option to the |
8391 | .B set | |
ccc6cda3 JA |
8392 | builtin command is enabled. |
8393 | If the | |
8394 | .B \-L | |
bb70624e | 8395 | option is used, the pathname printed may contain symbolic links. |
ccc6cda3 | 8396 | The return status is 0 unless an error occurs while |
cce855bc JA |
8397 | reading the name of the current directory or an |
8398 | invalid option is supplied. | |
726f6388 | 8399 | .TP |
08e72d7a | 8400 | \fBread\fP [\fB\-ers\fP] [\fB\-a\fP \fIaname\fP] [\fB\-d\fP \fIdelim\fP] [\fB\-i\fP \fItext\fP] [\fB\-n\fP \fInchars\fP] [\fB\-N\fP \fInchars\fP] [\fB\-p\fP \fIprompt\fP] [\fB\-t\fP \fItimeout\fP] [\fB\-u\fP \fIfd\fP] [\fIname\fP ...] |
7117c2d2 JA |
8401 | One line is read from the standard input, or from the file descriptor |
8402 | \fIfd\fP supplied as an argument to the \fB\-u\fP option, and the first word | |
726f6388 JA |
8403 | is assigned to the first |
8404 | .IR name , | |
8405 | the second word to the second | |
8406 | .IR name , | |
cce855bc JA |
8407 | and so on, with leftover words and their intervening separators assigned |
8408 | to the last | |
726f6388 | 8409 | .IR name . |
7117c2d2 | 8410 | If there are fewer words read from the input stream than names, |
cce855bc JA |
8411 | the remaining names are assigned empty values. |
8412 | The characters in | |
726f6388 JA |
8413 | .SM |
8414 | .B IFS | |
cce855bc | 8415 | are used to split the line into words. |
b72432fd JA |
8416 | The backslash character (\fB\e\fP) may be used to remove any special |
8417 | meaning for the next character read and for line continuation. | |
cce855bc | 8418 | Options, if supplied, have the following meanings: |
ccc6cda3 JA |
8419 | .RS |
8420 | .PD 0 | |
8421 | .TP | |
bb70624e | 8422 | .B \-a \fIaname\fP |
ccc6cda3 JA |
8423 | The words are assigned to sequential indices |
8424 | of the array variable | |
8425 | .IR aname , | |
8426 | starting at 0. | |
8427 | .I aname | |
8428 | is unset before any new values are assigned. | |
cce855bc | 8429 | Other \fIname\fP arguments are ignored. |
ccc6cda3 | 8430 | .TP |
bb70624e JA |
8431 | .B \-d \fIdelim\fP |
8432 | The first character of \fIdelim\fP is used to terminate the input line, | |
8433 | rather than newline. | |
8434 | .TP | |
ccc6cda3 JA |
8435 | .B \-e |
8436 | If the standard input | |
8437 | is coming from a terminal, | |
8438 | .B readline | |
8439 | (see | |
8440 | .SM | |
8441 | .B READLINE | |
8442 | above) is used to obtain the line. | |
14e8b2a7 CR |
8443 | Readline uses the current (or default, if line editing was not previously |
8444 | active) editing settings. | |
bb70624e | 8445 | .TP |
1d0e1a34 CR |
8446 | .B \-i \fItext\fP |
8447 | If | |
8448 | .B readline | |
8449 | is being used to read the line, \fItext\fP is placed into the editing | |
8450 | buffer before editing begins. | |
8451 | .TP | |
bb70624e JA |
8452 | .B \-n \fInchars\fP |
8453 | \fBread\fP returns after reading \fInchars\fP characters rather than | |
08e72d7a CR |
8454 | waiting for a complete line of input, but honor a delimiter if fewer |
8455 | than \fInchars\fP characters are read before the delimiter. | |
8456 | .TP | |
8457 | .B \-N \fInchars\fP | |
8458 | \fBread\fP returns after reading exactly \fInchars\fP characters rather | |
8459 | than waiting for a complete line of input, unless EOF is encountered or | |
a3143574 CR |
8460 | \fBread\fP times out. |
8461 | Delimiter characters encountered in the input are | |
8462 | not treated specially and do not cause \fBread\fP to return until | |
8463 | \fInchars\fP characters are read. | |
bb70624e JA |
8464 | .TP |
8465 | .B \-p \fIprompt\fP | |
f73dda09 | 8466 | Display \fIprompt\fP on standard error, without a |
bb70624e JA |
8467 | trailing newline, before attempting to read any input. The prompt |
8468 | is displayed only if input is coming from a terminal. | |
8469 | .TP | |
8470 | .B \-r | |
8471 | Backslash does not act as an escape character. | |
8472 | The backslash is considered to be part of the line. | |
8473 | In particular, a backslash-newline pair may not be used as a line | |
8474 | continuation. | |
8475 | .TP | |
8476 | .B \-s | |
8477 | Silent mode. If input is coming from a terminal, characters are | |
8478 | not echoed. | |
8479 | .TP | |
8480 | .B \-t \fItimeout\fP | |
8481 | Cause \fBread\fP to time out and return failure if a complete line of | |
8482 | input is not read within \fItimeout\fP seconds. | |
4ac1ff98 CR |
8483 | \fItimeout\fP may be a decimal number with a fractional portion following |
8484 | the decimal point. | |
e33f2203 CR |
8485 | This option is only effective if \fBread\fP is reading input from a |
8486 | terminal, pipe, or other special file; it has no effect when reading | |
8487 | from regular files. | |
b13b8a87 CR |
8488 | If \fItimeout\fP is 0, \fBread\fP returns immediately, without trying to |
8489 | read any data. The exit statis is 0 if input is available on | |
8490 | the specified file descriptor, non-zero otherwise. | |
e33f2203 | 8491 | The exit status is greater than 128 if the timeout is exceeded. |
7117c2d2 | 8492 | .TP |
0f445e6c | 8493 | .B \-u \fIfd\fP |
7117c2d2 | 8494 | Read input from file descriptor \fIfd\fP. |
ccc6cda3 JA |
8495 | .PD |
8496 | .PP | |
8497 | If no | |
726f6388 JA |
8498 | .I names |
8499 | are supplied, the line read is assigned to the variable | |
8500 | .SM | |
8501 | .BR REPLY . | |
7117c2d2 | 8502 | The return code is zero, unless end-of-file is encountered, \fBread\fP |
ba4ab055 CR |
8503 | times out (in which case the return code is greater than 128), |
8504 | a variable assignment error (such as assigning to a readonly variable) occurs, | |
8505 | or an invalid file descriptor is supplied as the argument to \fB\-u\fP. | |
ccc6cda3 | 8506 | .RE |
726f6388 | 8507 | .TP |
54a1fa7c | 8508 | \fBreadonly\fP [\fB\-aAf\fP] [\fB\-p\fP] [\fIname\fP[=\fIword\fP] ...] |
726f6388 JA |
8509 | .PD |
8510 | The given | |
ccc6cda3 JA |
8511 | \fInames\fP are marked readonly; the values of these |
8512 | .I names | |
726f6388 JA |
8513 | may not be changed by subsequent assignment. |
8514 | If the | |
8515 | .B \-f | |
8516 | option is supplied, the functions corresponding to the | |
8517 | \fInames\fP are so | |
ccc6cda3 JA |
8518 | marked. |
8519 | The | |
8520 | .B \-a | |
fdf670ea CR |
8521 | option restricts the variables to indexed arrays; the |
8522 | .B \-A | |
8523 | option restricts the variables to associative arrays. | |
54a1fa7c CR |
8524 | If both options are supplied, |
8525 | .B \-A | |
8526 | takes precedence. | |
ccc6cda3 JA |
8527 | If no |
8528 | .I name | |
8529 | arguments are given, or if the | |
726f6388 | 8530 | .B \-p |
ccc6cda3 | 8531 | option is supplied, a list of all readonly names is printed. |
54a1fa7c CR |
8532 | The other options may be used to restrict the output to a subset of |
8533 | the set of readonly names. | |
cce855bc JA |
8534 | The |
8535 | .B \-p | |
bb70624e JA |
8536 | option causes output to be displayed in a format that |
8537 | may be reused as input. | |
d3a24ed2 CR |
8538 | If a variable name is followed by =\fIword\fP, the value of |
8539 | the variable is set to \fIword\fP. | |
cce855bc | 8540 | The return status is 0 unless an invalid option is encountered, |
ccc6cda3 JA |
8541 | one of the |
8542 | .I names | |
cce855bc | 8543 | is not a valid shell variable name, or |
726f6388 JA |
8544 | .B \-f |
8545 | is supplied with a | |
8546 | .I name | |
8547 | that is not a function. | |
8548 | .TP | |
8549 | \fBreturn\fP [\fIn\fP] | |
b28ff8c9 CR |
8550 | Causes a function to stop executing and return the value specified by |
8551 | .I n | |
8552 | to its caller. | |
726f6388 JA |
8553 | If |
8554 | .I n | |
8555 | is omitted, the return status is that of the last command | |
b28ff8c9 CR |
8556 | executed in the function body. If |
8557 | .B return | |
8558 | is used outside a function, | |
726f6388 JA |
8559 | but during execution of a script by the |
8560 | .B . | |
8561 | (\fBsource\fP) command, it causes the shell to stop executing | |
8562 | that script and return either | |
8563 | .I n | |
8564 | or the exit status of the last command executed within the | |
b28ff8c9 | 8565 | script as the exit status of the script. |
3d4f66ca CR |
8566 | If \fIn\fP is supplied, the return value is its least significant |
8567 | 8 bits. | |
b28ff8c9 CR |
8568 | The return status is non-zero if |
8569 | .B return | |
3d4f66ca | 8570 | is supplied a non-numeric argument, or |
b28ff8c9 CR |
8571 | is used outside a |
8572 | function and not during execution of a script by \fB.\fP\^ or \fBsource\fP. | |
d3a24ed2 CR |
8573 | Any command associated with the \fBRETURN\fP trap is executed |
8574 | before execution resumes after the function or script. | |
726f6388 | 8575 | .TP |
dc60d4e0 | 8576 | \fBset\fP [\fB\-\-abefhkmnptuvxBCEHPT\fP] [\fB\-o\fP \fIoption\-name\fP] [\fIarg\fP ...] |
d3ad40de CR |
8577 | .PD 0 |
8578 | .TP | |
dc60d4e0 | 8579 | \fBset\fP [\fB+abefhkmnptuvxBCEHPT\fP] [\fB+o\fP \fIoption\-name\fP] [\fIarg\fP ...] |
d3ad40de | 8580 | .PD |
ccc6cda3 | 8581 | Without options, the name and value of each shell variable are displayed |
54cdd75a CR |
8582 | in a format that can be reused as input |
8583 | for setting or resetting the currently-set variables. | |
8584 | Read-only variables cannot be reset. | |
8585 | In \fIposix mode\fP, only shell variables are listed. | |
cce855bc | 8586 | The output is sorted according to the current locale. |
ccc6cda3 | 8587 | When options are specified, they set or unset shell attributes. |
626d0694 | 8588 | Any arguments remaining after option processing are treated |
ccc6cda3 JA |
8589 | as values for the positional parameters and are assigned, in order, to |
8590 | .BR $1 , | |
8591 | .BR $2 , | |
8592 | .B ... | |
8593 | .BR $\fIn\fP . | |
8594 | Options, if specified, have the following meanings: | |
726f6388 JA |
8595 | .RS |
8596 | .PD 0 | |
8597 | .TP 8 | |
8598 | .B \-a | |
5e13499c CR |
8599 | Automatically mark variables and functions which are modified or |
8600 | created for export to the environment of subsequent commands. | |
726f6388 JA |
8601 | .TP 8 |
8602 | .B \-b | |
ccc6cda3 JA |
8603 | Report the status of terminated background jobs |
8604 | immediately, rather than before the next primary prompt. This is | |
8605 | effective only when job control is enabled. | |
726f6388 JA |
8606 | .TP 8 |
8607 | .B \-e | |
15825757 CR |
8608 | Exit immediately if a |
8609 | \fIpipeline\fP (which may consist of a single \fIsimple command\fP), | |
8610 | a \fIlist\fP, | |
8611 | or a \fIcompound command\fP | |
8612 | (see | |
726f6388 JA |
8613 | .SM |
8614 | .B SHELL GRAMMAR | |
15825757 | 8615 | above), exits with a non-zero status. |
d3a24ed2 CR |
8616 | The shell does not exit if the |
8617 | command that fails is part of the command list immediately following a | |
8618 | .B while | |
726f6388 | 8619 | or |
d3a24ed2 CR |
8620 | .B until |
8621 | keyword, | |
4b9cc222 | 8622 | part of the test following the |
d3ad40de | 8623 | .B if |
4b9cc222 CR |
8624 | or |
8625 | .B elif | |
8626 | reserved words, part of any command executed in a | |
726f6388 JA |
8627 | .B && |
8628 | or | |
adc6cff5 CR |
8629 | .B || |
8630 | list except the command following the final \fB&&\fP or \fB||\fP, | |
d3ad40de CR |
8631 | any command in a pipeline but the last, |
8632 | or if the command's return value is | |
a05a1337 | 8633 | being inverted with |
726f6388 | 8634 | .BR ! . |
15825757 CR |
8635 | If a compound command other than a subshell |
8636 | returns a non-zero status because a command failed | |
8637 | while \fB\-e\fP was being ignored, the shell does not exit. | |
f73dda09 | 8638 | A trap on \fBERR\fP, if set, is executed before the shell exits. |
a05a1337 CR |
8639 | This option applies to the shell environment and each subshell environment |
8640 | separately (see | |
984a1947 | 8641 | .SM |
a05a1337 CR |
8642 | .B "COMMAND EXECUTION ENVIRONMENT" |
8643 | above), and may cause | |
8644 | subshells to exit before executing all the commands in the subshell. | |
726f6388 JA |
8645 | .TP 8 |
8646 | .B \-f | |
8647 | Disable pathname expansion. | |
8648 | .TP 8 | |
8649 | .B \-h | |
ccc6cda3 | 8650 | Remember the location of commands as they are looked up for execution. |
cce855bc | 8651 | This is enabled by default. |
726f6388 JA |
8652 | .TP 8 |
8653 | .B \-k | |
ccc6cda3 JA |
8654 | All arguments in the form of assignment statements |
8655 | are placed in the environment for a command, not just | |
8656 | those that precede the command name. | |
726f6388 JA |
8657 | .TP 8 |
8658 | .B \-m | |
cce855bc | 8659 | Monitor mode. Job control is enabled. This option is on |
726f6388 JA |
8660 | by default for interactive shells on systems that support |
8661 | it (see | |
8662 | .SM | |
8663 | .B JOB CONTROL | |
f6da9f85 CR |
8664 | above). |
8665 | All processes run in a separate process group. | |
8666 | When a background job completes, the shell prints a line | |
8667 | containing its exit status. | |
726f6388 JA |
8668 | .TP 8 |
8669 | .B \-n | |
8670 | Read commands but do not execute them. This may be used to | |
ccc6cda3 | 8671 | check a shell script for syntax errors. This is ignored by |
726f6388 JA |
8672 | interactive shells. |
8673 | .TP 8 | |
ccc6cda3 JA |
8674 | .B \-o \fIoption\-name\fP |
8675 | The \fIoption\-name\fP can be one of the following: | |
726f6388 JA |
8676 | .RS |
8677 | .TP 8 | |
8678 | .B allexport | |
8679 | Same as | |
8680 | .BR \-a . | |
8681 | .TP 8 | |
8682 | .B braceexpand | |
ccc6cda3 JA |
8683 | Same as |
8684 | .BR \-B . | |
726f6388 JA |
8685 | .TP 8 |
8686 | .B emacs | |
8687 | Use an emacs-style command line editing interface. This is enabled | |
8688 | by default when the shell is interactive, unless the shell is started | |
8689 | with the | |
ccc6cda3 | 8690 | .B \-\-noediting |
726f6388 | 8691 | option. |
10a4e415 | 8692 | This also affects the editing interface used for \fBread \-e\fP. |
726f6388 | 8693 | .TP 8 |
a3143574 CR |
8694 | .B errexit |
8695 | Same as | |
8696 | .BR \-e . | |
8697 | .TP 8 | |
d3a24ed2 CR |
8698 | .B errtrace |
8699 | Same as | |
8700 | .BR \-E . | |
8701 | .TP 8 | |
8702 | .B functrace | |
8703 | Same as | |
8704 | .BR \-T . | |
8705 | .TP 8 | |
ccc6cda3 JA |
8706 | .B hashall |
8707 | Same as | |
8708 | .BR \-h . | |
8709 | .TP 8 | |
726f6388 JA |
8710 | .B histexpand |
8711 | Same as | |
8712 | .BR \-H . | |
8713 | .TP 8 | |
ccc6cda3 JA |
8714 | .B history |
8715 | Enable command history, as described above under | |
8716 | .SM | |
8717 | .BR HISTORY . | |
8718 | This option is on by default in interactive shells. | |
8719 | .TP 8 | |
726f6388 | 8720 | .B ignoreeof |
28ef6c31 JA |
8721 | The effect is as if the shell command |
8722 | .if t \f(CWIGNOREEOF=10\fP | |
8723 | .if n ``IGNOREEOF=10'' | |
8724 | had been executed | |
726f6388 JA |
8725 | (see |
8726 | .B Shell Variables | |
8727 | above). | |
8728 | .TP 8 | |
ccc6cda3 JA |
8729 | .B keyword |
8730 | Same as | |
8731 | .BR \-k . | |
726f6388 JA |
8732 | .TP 8 |
8733 | .B monitor | |
8734 | Same as | |
8735 | .BR \-m . | |
8736 | .TP 8 | |
8737 | .B noclobber | |
8738 | Same as | |
8739 | .BR \-C . | |
8740 | .TP 8 | |
8741 | .B noexec | |
8742 | Same as | |
8743 | .BR \-n . | |
8744 | .TP 8 | |
8745 | .B noglob | |
8746 | Same as | |
8747 | .BR \-f . | |
57a3f689 | 8748 | .TP 8 |
f73dda09 JA |
8749 | .B nolog |
8750 | Currently ignored. | |
726f6388 | 8751 | .TP 8 |
726f6388 JA |
8752 | .B notify |
8753 | Same as | |
8754 | .BR \-b . | |
8755 | .TP 8 | |
8756 | .B nounset | |
8757 | Same as | |
8758 | .BR \-u . | |
8759 | .TP 8 | |
ccc6cda3 JA |
8760 | .B onecmd |
8761 | Same as | |
8762 | .BR \-t . | |
8763 | .TP 8 | |
726f6388 JA |
8764 | .B physical |
8765 | Same as | |
8766 | .BR \-P . | |
8767 | .TP 8 | |
d3a24ed2 CR |
8768 | .B pipefail |
8769 | If set, the return value of a pipeline is the value of the last | |
8770 | (rightmost) command to exit with a non-zero status, or zero if all | |
8771 | commands in the pipeline exit successfully. | |
8772 | This option is disabled by default. | |
8773 | .TP 8 | |
726f6388 | 8774 | .B posix |
ccc6cda3 JA |
8775 | Change the behavior of |
8776 | .B bash | |
8777 | where the default operation differs | |
ac18b312 | 8778 | from the POSIX standard to match the standard (\fIposix mode\fP). |
726f6388 JA |
8779 | .TP 8 |
8780 | .B privileged | |
8781 | Same as | |
8782 | .BR \-p . | |
8783 | .TP 8 | |
8784 | .B verbose | |
8785 | Same as | |
8786 | .BR \-v . | |
8787 | .TP 8 | |
8788 | .B vi | |
8789 | Use a vi-style command line editing interface. | |
10a4e415 | 8790 | This also affects the editing interface used for \fBread \-e\fP. |
726f6388 JA |
8791 | .TP 8 |
8792 | .B xtrace | |
8793 | Same as | |
8794 | .BR \-x . | |
ccc6cda3 | 8795 | .sp .5 |
726f6388 | 8796 | .PP |
ccc6cda3 JA |
8797 | If |
8798 | .B \-o | |
8799 | is supplied with no \fIoption\-name\fP, the values of the current options are | |
726f6388 | 8800 | printed. |
ccc6cda3 JA |
8801 | If |
8802 | .B +o | |
8803 | is supplied with no \fIoption\-name\fP, a series of | |
8804 | .B set | |
8805 | commands to recreate the current option settings is displayed on | |
8806 | the standard output. | |
726f6388 JA |
8807 | .RE |
8808 | .TP 8 | |
8809 | .B \-p | |
8810 | Turn on | |
8811 | .I privileged | |
8812 | mode. In this mode, the | |
bb70624e | 8813 | .SM |
726f6388 | 8814 | .B $ENV |
b72432fd | 8815 | and |
bb70624e | 8816 | .SM |
b72432fd JA |
8817 | .B $BASH_ENV |
8818 | files are not processed, shell functions are not inherited from the | |
bb70624e JA |
8819 | environment, and the |
8820 | .SM | |
e77a3058 | 8821 | .BR SHELLOPTS , |
984a1947 | 8822 | .SM |
691aebcb | 8823 | .BR BASHOPTS , |
984a1947 | 8824 | .SM |
e77a3058 CR |
8825 | .BR CDPATH , |
8826 | and | |
984a1947 | 8827 | .SM |
e77a3058 CR |
8828 | .B GLOBIGNORE |
8829 | variables, if they appear in the environment, are ignored. | |
b72432fd JA |
8830 | If the shell is started with the effective user (group) id not equal to the |
8831 | real user (group) id, and the \fB\-p\fP option is not supplied, these actions | |
8832 | are taken and the effective user id is set to the real user id. | |
8833 | If the \fB\-p\fP option is supplied at startup, the effective user id is | |
8834 | not reset. | |
cce855bc | 8835 | Turning this option off causes the effective user |
726f6388 JA |
8836 | and group ids to be set to the real user and group ids. |
8837 | .TP 8 | |
8838 | .B \-t | |
8839 | Exit after reading and executing one command. | |
8840 | .TP 8 | |
8841 | .B \-u | |
2c471a92 CR |
8842 | Treat unset variables and parameters other than the special |
8843 | parameters "@" and "*" as an error when performing | |
726f6388 | 8844 | parameter expansion. If expansion is attempted on an |
2c471a92 | 8845 | unset variable or parameter, the shell prints an error message, and, |
ccc6cda3 | 8846 | if not interactive, exits with a non-zero status. |
726f6388 JA |
8847 | .TP 8 |
8848 | .B \-v | |
8849 | Print shell input lines as they are read. | |
8850 | .TP 8 | |
8851 | .B \-x | |
ccc6cda3 | 8852 | After expanding each \fIsimple command\fP, |
d3a24ed2 CR |
8853 | \fBfor\fP command, \fBcase\fP command, \fBselect\fP command, or |
8854 | arithmetic \fBfor\fP command, display the expanded value of | |
726f6388 JA |
8855 | .SM |
8856 | .BR PS4 , | |
d3a24ed2 CR |
8857 | followed by the command and its expanded arguments |
8858 | or associated word list. | |
726f6388 | 8859 | .TP 8 |
ccc6cda3 JA |
8860 | .B \-B |
8861 | The shell performs brace expansion (see | |
8862 | .B Brace Expansion | |
8863 | above). This is on by default. | |
726f6388 JA |
8864 | .TP 8 |
8865 | .B \-C | |
ccc6cda3 JA |
8866 | If set, |
8867 | .B bash | |
8868 | does not overwrite an existing file with the | |
8869 | .BR > , | |
8870 | .BR >& , | |
8871 | and | |
8872 | .B <> | |
8873 | redirection operators. This may be overridden when | |
8874 | creating output files by using the redirection operator | |
8875 | .B >| | |
8876 | instead of | |
8877 | .BR > . | |
726f6388 | 8878 | .TP 8 |
d3a24ed2 CR |
8879 | .B \-E |
8880 | If set, any trap on \fBERR\fP is inherited by shell functions, command | |
8881 | substitutions, and commands executed in a subshell environment. | |
8882 | The \fBERR\fP trap is normally not inherited in such cases. | |
8883 | .TP 8 | |
726f6388 JA |
8884 | .B \-H |
8885 | Enable | |
8886 | .B ! | |
cce855bc | 8887 | style history substitution. This option is on by |
726f6388 JA |
8888 | default when the shell is interactive. |
8889 | .TP 8 | |
8890 | .B \-P | |
45c0f7f8 | 8891 | If set, the shell does not resolve symbolic links when executing |
ccc6cda3 | 8892 | commands such as |
726f6388 | 8893 | .B cd |
ccc6cda3 JA |
8894 | that change the current working directory. It uses the |
8895 | physical directory structure instead. By default, | |
8896 | .B bash | |
8897 | follows the logical chain of directories when performing commands | |
8898 | which change the current directory. | |
726f6388 | 8899 | .TP 8 |
d3a24ed2 | 8900 | .B \-T |
76a8d78d CR |
8901 | If set, any traps on \fBDEBUG\fP and \fBRETURN\fP are inherited by shell |
8902 | functions, command substitutions, and commands executed in a | |
8903 | subshell environment. | |
8904 | The \fBDEBUG\fP and \fBRETURN\fP traps are normally not inherited | |
8905 | in such cases. | |
d3a24ed2 | 8906 | .TP 8 |
726f6388 | 8907 | .B \-\- |
cce855bc | 8908 | If no arguments follow this option, then the positional parameters are |
726f6388 JA |
8909 | unset. Otherwise, the positional parameters are set to the |
8910 | \fIarg\fPs, even if some of them begin with a | |
8911 | .BR \- . | |
8912 | .TP 8 | |
8913 | .B \- | |
8914 | Signal the end of options, cause all remaining \fIarg\fPs to be | |
8915 | assigned to the positional parameters. The | |
8916 | .B \-x | |
8917 | and | |
8918 | .B \-v | |
8919 | options are turned off. | |
8920 | If there are no \fIarg\fPs, | |
8921 | the positional parameters remain unchanged. | |
8922 | .PD | |
8923 | .PP | |
cce855bc JA |
8924 | The options are off by default unless otherwise noted. |
8925 | Using + rather than \- causes these options to be turned off. | |
8926 | The options can also be specified as arguments to an invocation of | |
8927 | the shell. | |
8928 | The current set of options may be found in | |
726f6388 | 8929 | .BR $\- . |
cce855bc | 8930 | The return status is always true unless an invalid option is encountered. |
726f6388 JA |
8931 | .RE |
8932 | .TP | |
8933 | \fBshift\fP [\fIn\fP] | |
8934 | The positional parameters from \fIn\fP+1 ... are renamed to | |
8935 | .B $1 | |
8936 | .B .... | |
8937 | Parameters represented by the numbers \fB$#\fP | |
8938 | down to \fB$#\fP\-\fIn\fP+1 are unset. | |
ccc6cda3 JA |
8939 | .I n |
8940 | must be a non-negative number less than or equal to \fB$#\fP. | |
726f6388 JA |
8941 | If |
8942 | .I n | |
8943 | is 0, no parameters are changed. | |
8944 | If | |
8945 | .I n | |
8946 | is not given, it is assumed to be 1. | |
726f6388 JA |
8947 | If |
8948 | .I n | |
8949 | is greater than \fB$#\fP, the positional parameters are not changed. | |
ccc6cda3 | 8950 | The return status is greater than zero if |
726f6388 JA |
8951 | .I n |
8952 | is greater than | |
8953 | .B $# | |
ccc6cda3 JA |
8954 | or less than zero; otherwise 0. |
8955 | .TP | |
8956 | \fBshopt\fP [\fB\-pqsu\fP] [\fB\-o\fP] [\fIoptname\fP ...] | |
8957 | Toggle the values of variables controlling optional shell behavior. | |
8958 | With no options, or with the | |
8959 | .B \-p | |
8960 | option, a list of all settable options is displayed, with | |
cce855bc JA |
8961 | an indication of whether or not each is set. |
8962 | The \fB\-p\fP option causes output to be displayed in a form that | |
8963 | may be reused as input. | |
8964 | Other options have the following meanings: | |
ccc6cda3 JA |
8965 | .RS |
8966 | .PD 0 | |
8967 | .TP | |
8968 | .B \-s | |
8969 | Enable (set) each \fIoptname\fP. | |
8970 | .TP | |
8971 | .B \-u | |
8972 | Disable (unset) each \fIoptname\fP. | |
8973 | .TP | |
8974 | .B \-q | |
8975 | Suppresses normal output (quiet mode); the return status indicates | |
8976 | whether the \fIoptname\fP is set or unset. | |
8977 | If multiple \fIoptname\fP arguments are given with | |
8978 | .BR \-q , | |
8979 | the return status is zero if all \fIoptnames\fP are enabled; non-zero | |
8980 | otherwise. | |
8981 | .TP | |
8982 | .B \-o | |
8983 | Restricts the values of \fIoptname\fP to be those defined for the | |
8984 | .B \-o | |
8985 | option to the | |
8986 | .B set | |
8987 | builtin. | |
8988 | .PD | |
8989 | .PP | |
8990 | If either | |
8991 | .B \-s | |
8992 | or | |
8993 | .B \-u | |
b28ff8c9 CR |
8994 | is used with no \fIoptname\fP arguments, |
8995 | .B shopt | |
8996 | shows only those options which are set or unset, respectively. | |
ccc6cda3 JA |
8997 | Unless otherwise noted, the \fBshopt\fP options are disabled (unset) |
8998 | by default. | |
8999 | .PP | |
9000 | The return status when listing options is zero if all \fIoptnames\fP | |
9001 | are enabled, non-zero otherwise. When setting or unsetting options, | |
cce855bc | 9002 | the return status is zero unless an \fIoptname\fP is not a valid shell |
ccc6cda3 JA |
9003 | option. |
9004 | .PP | |
9005 | The list of \fBshopt\fP options is: | |
9006 | .if t .sp .5v | |
9007 | .if n .sp 1v | |
9008 | .PD 0 | |
9009 | .TP 8 | |
d3ad40de CR |
9010 | .B autocd |
9011 | If set, a command name that is the name of a directory is executed as if | |
9012 | it were the argument to the \fBcd\fP command. | |
9013 | This option is only used by interactive shells. | |
9014 | .TP 8 | |
ccc6cda3 JA |
9015 | .B cdable_vars |
9016 | If set, an argument to the | |
9017 | .B cd | |
9018 | builtin command that | |
9019 | is not a directory is assumed to be the name of a variable whose | |
9020 | value is the directory to change to. | |
9021 | .TP 8 | |
9022 | .B cdspell | |
9023 | If set, minor errors in the spelling of a directory component in a | |
9024 | .B cd | |
9025 | command will be corrected. | |
9026 | The errors checked for are transposed characters, | |
9027 | a missing character, and one character too many. | |
b28ff8c9 | 9028 | If a correction is found, the corrected filename is printed, |
ccc6cda3 | 9029 | and the command proceeds. |
d166f048 | 9030 | This option is only used by interactive shells. |
ccc6cda3 JA |
9031 | .TP 8 |
9032 | .B checkhash | |
9033 | If set, \fBbash\fP checks that a command found in the hash | |
9034 | table exists before trying to execute it. If a hashed command no | |
9035 | longer exists, a normal path search is performed. | |
9036 | .TP 8 | |
d3ad40de | 9037 | .B checkjobs |
29d25b54 | 9038 | If set, \fBbash\fP lists the status of any stopped and running jobs before |
d3ad40de CR |
9039 | exiting an interactive shell. If any jobs are running, this causes |
9040 | the exit to be deferred until a second exit is attempted without an | |
984a1947 CR |
9041 | intervening command (see |
9042 | .SM | |
9043 | .B "JOB CONTROL" | |
9044 | above). The shell always | |
d3ad40de CR |
9045 | postpones exiting if any jobs are stopped. |
9046 | .TP 8 | |
ccc6cda3 | 9047 | .B checkwinsize |
51f7ea36 | 9048 | If set, \fBbash\fP checks the window size after each command |
ccc6cda3 JA |
9049 | and, if necessary, updates the values of |
9050 | .SM | |
9051 | .B LINES | |
9052 | and | |
9053 | .SM | |
9054 | .BR COLUMNS . | |
9055 | .TP 8 | |
9056 | .B cmdhist | |
9057 | If set, | |
9058 | .B bash | |
9059 | attempts to save all lines of a multiple-line | |
9060 | command in the same history entry. This allows | |
9061 | easy re-editing of multi-line commands. | |
9062 | .TP 8 | |
35ee8ea0 CR |
9063 | .B compat31 |
9064 | If set, | |
9065 | .B bash | |
9066 | changes its behavior to that of version 3.1 with respect to quoted | |
5a318736 CR |
9067 | arguments to the \fB[[\fP conditional command's \fB=~\fP operator |
9068 | and locale-specific string comparison when using the \fB[[\fP | |
54a1fa7c CR |
9069 | conditional command's \fB<\fP and \fB>\fP operators. |
9070 | Bash versions prior to bash-4.1 use ASCII collation and | |
9071 | .IR strcmp (3); | |
5a318736 | 9072 | bash-4.1 and later use the current locale's collation sequence and |
54a1fa7c | 9073 | .IR strcoll (3). |
cd0ef727 | 9074 | .TP 8 |
5a318736 CR |
9075 | .B compat32 |
9076 | If set, | |
9077 | .B bash | |
9078 | changes its behavior to that of version 3.2 with respect to | |
9079 | locale-specific string comparison when using the \fB[[\fP | |
9080 | conditional command's \fB<\fP and \fB>\fP operators (see previous item). | |
9081 | .TP 8 | |
cd0ef727 CR |
9082 | .B compat40 |
9083 | If set, | |
9084 | .B bash | |
9085 | changes its behavior to that of version 4.0 with respect to locale-specific | |
54a1fa7c | 9086 | string comparison when using the \fB[[\fP |
5a318736 CR |
9087 | conditional command's \fB<\fP and \fB>\fP operators (see description of |
9088 | \fBcompat31\fP) | |
54a1fa7c | 9089 | and the effect of interrupting a command list. |
5a318736 CR |
9090 | Bash versions 4.0 and later interrupt the list as if the shell received the |
9091 | interrupt; previous versions continue with the next command in the list. | |
cd0ef727 | 9092 | .TP 8 |
67362c60 | 9093 | .B compat41 |
67362c60 CR |
9094 | If set, |
9095 | .BR bash , | |
9096 | when in posix mode, treats a single quote in a double-quoted | |
9097 | parameter expansion as a special character. The single quotes must match | |
9098 | (an even number) and the characters between the single quotes are considered | |
9099 | quoted. This is the behavior of posix mode through version 4.1. | |
9100 | The default bash behavior remains as in previous versions. | |
9101 | .TP 8 | |
ddef12ff CR |
9102 | .B complete_fullquote |
9103 | If set, | |
9104 | .B bash | |
9105 | quotes all shell metacharacters in filenames and directory names when | |
9106 | performing completion. | |
9107 | If not set, | |
9108 | .B bash | |
9109 | removes metacharacters such as the dollar sign from the set of | |
9110 | characters that will be quoted in completed filenames | |
9111 | when these metacharacters appear in shell variable references in words to be | |
9112 | completed. | |
9113 | This means that dollar signs in variable names that expand to directories | |
9114 | will not be quoted; | |
9115 | however, any dollar signs appearing in filenames will not be quoted, either. | |
9116 | This is active only when bash is using backslashes to quote completed | |
9117 | filenames. | |
9118 | This variable is set by default, which is the default bash behavior in | |
9119 | versions through 4.2. | |
9120 | .TP 8 | |
74d0116b CR |
9121 | .B direxpand |
9122 | If set, | |
9123 | .B bash | |
9124 | replaces directory names with the results of word expansion when performing | |
9125 | filename completion. This changes the contents of the readline editing | |
9126 | buffer. | |
9127 | If not set, | |
9128 | .B bash | |
9129 | attempts to preserve what the user typed. | |
9130 | .TP 8 | |
4ac1ff98 CR |
9131 | .B dirspell |
9132 | If set, | |
9133 | .B bash | |
9134 | attempts spelling correction on directory names during word completion | |
9135 | if the directory name initially supplied does not exist. | |
9136 | .TP 8 | |
ccc6cda3 JA |
9137 | .B dotglob |
9138 | If set, | |
9139 | .B bash | |
9140 | includes filenames beginning with a `.' in the results of pathname | |
9141 | expansion. | |
9142 | .TP 8 | |
9143 | .B execfail | |
9144 | If set, a non-interactive shell will not exit if | |
9145 | it cannot execute the file specified as an argument to the | |
9146 | .B exec | |
9147 | builtin command. An interactive shell does not exit if | |
9148 | .B exec | |
9149 | fails. | |
9150 | .TP 8 | |
9151 | .B expand_aliases | |
9152 | If set, aliases are expanded as described above under | |
9153 | .SM | |
9154 | .BR ALIASES . | |
9155 | This option is enabled by default for interactive shells. | |
9156 | .TP 8 | |
d3a24ed2 CR |
9157 | .B extdebug |
9158 | If set, behavior intended for use by debuggers is enabled: | |
9159 | .RS | |
9160 | .TP | |
9161 | .B 1. | |
9162 | The \fB\-F\fP option to the \fBdeclare\fP builtin displays the source | |
9163 | file name and line number corresponding to each function name supplied | |
9164 | as an argument. | |
9165 | .TP | |
9166 | .B 2. | |
9167 | If the command run by the \fBDEBUG\fP trap returns a non-zero value, the | |
9168 | next command is skipped and not executed. | |
9169 | .TP | |
9170 | .B 3. | |
9171 | If the command run by the \fBDEBUG\fP trap returns a value of 2, and the | |
9172 | shell is executing in a subroutine (a shell function or a shell script | |
9173 | executed by the \fB.\fP or \fBsource\fP builtins), a call to | |
9174 | \fBreturn\fP is simulated. | |
2206f89a CR |
9175 | .TP |
9176 | .B 4. | |
984a1947 CR |
9177 | .SM |
9178 | .B BASH_ARGC | |
9179 | and | |
9180 | .SM | |
9181 | .B BASH_ARGV | |
9182 | are updated as described in their descriptions above. | |
2206f89a CR |
9183 | .TP |
9184 | .B 5. | |
9185 | Function tracing is enabled: command substitution, shell functions, and | |
9186 | subshells invoked with \fB(\fP \fIcommand\fP \fB)\fP inherit the | |
9187 | \fBDEBUG\fP and \fBRETURN\fP traps. | |
9188 | .TP | |
9189 | .B 6. | |
9190 | Error tracing is enabled: command substitution, shell functions, and | |
9191 | subshells invoked with \fB(\fP \fIcommand\fP \fB)\fP inherit the | |
5cdaaf76 | 9192 | \fBERR\fP trap. |
d3a24ed2 CR |
9193 | .RE |
9194 | .TP 8 | |
cce855bc JA |
9195 | .B extglob |
9196 | If set, the extended pattern matching features described above under | |
9197 | \fBPathname Expansion\fP are enabled. | |
9198 | .TP 8 | |
d3a24ed2 | 9199 | .B extquote |
20587658 | 9200 | If set, \fB$\fP\(aq\fIstring\fP\(aq and \fB$\fP"\fIstring\fP" quoting is |
d3a24ed2 CR |
9201 | performed within \fB${\fP\fIparameter\fP\fB}\fP expansions |
9202 | enclosed in double quotes. This option is enabled by default. | |
9203 | .TP 8 | |
9204 | .B failglob | |
9205 | If set, patterns which fail to match filenames during pathname expansion | |
9206 | result in an expansion error. | |
9207 | .TP 8 | |
9208 | .B force_fignore | |
984a1947 CR |
9209 | If set, the suffixes specified by the |
9210 | .SM | |
9211 | .B FIGNORE | |
9212 | shell variable | |
d3a24ed2 CR |
9213 | cause words to be ignored when performing word completion even if |
9214 | the ignored words are the only possible completions. | |
9215 | See | |
9216 | .SM | |
9217 | \fBSHELL VARIABLES\fP | |
984a1947 CR |
9218 | above for a description of |
9219 | .SM | |
9220 | .BR FIGNORE . | |
d3a24ed2 CR |
9221 | This option is enabled by default. |
9222 | .TP 8 | |
74d0116b CR |
9223 | .B globasciiranges |
9224 | If set, range expressions used in pattern matching (see | |
9225 | .SM | |
9226 | .B Pattern Matching | |
9227 | above) behave as if in the traditional C locale when performing | |
9228 | comparisons. That is, the current locale's collating sequence | |
9229 | is not taken into account, so | |
9230 | .B b | |
9231 | will not collate between | |
9232 | .B A | |
9233 | and | |
9234 | .BR B , | |
9235 | and upper-case and lower-case ASCII characters will collate together. | |
9236 | .TP 8 | |
4ac1ff98 | 9237 | .B globstar |
d0ca3503 | 9238 | If set, the pattern \fB**\fP used in a pathname expansion context will |
54a1fa7c | 9239 | match all files and zero or more directories and subdirectories. |
4ac1ff98 CR |
9240 | If the pattern is followed by a \fB/\fP, only directories and |
9241 | subdirectories match. | |
9242 | .TP 8 | |
d3a24ed2 CR |
9243 | .B gnu_errfmt |
9244 | If set, shell error messages are written in the standard GNU error | |
9245 | message format. | |
9246 | .TP 8 | |
ccc6cda3 JA |
9247 | .B histappend |
9248 | If set, the history list is appended to the file named by the value | |
9249 | of the | |
984a1947 | 9250 | .SM |
ccc6cda3 JA |
9251 | .B HISTFILE |
9252 | variable when the shell exits, rather than overwriting the file. | |
9253 | .TP 8 | |
9254 | .B histreedit | |
9255 | If set, and | |
9256 | .B readline | |
9257 | is being used, a user is given the opportunity to re-edit a | |
9258 | failed history substitution. | |
9259 | .TP 8 | |
9260 | .B histverify | |
9261 | If set, and | |
9262 | .B readline | |
9263 | is being used, the results of history substitution are not immediately | |
9264 | passed to the shell parser. Instead, the resulting line is loaded into | |
9265 | the \fBreadline\fP editing buffer, allowing further modification. | |
9266 | .TP 8 | |
9267 | .B hostcomplete | |
9268 | If set, and | |
9269 | .B readline | |
cce855bc JA |
9270 | is being used, \fBbash\fP will attempt to perform hostname completion when a |
9271 | word containing a \fB@\fP is being completed (see | |
ccc6cda3 JA |
9272 | .B Completing |
9273 | under | |
9274 | .SM | |
9275 | .B READLINE | |
9276 | above). | |
9277 | This is enabled by default. | |
9278 | .TP 8 | |
cce855bc JA |
9279 | .B huponexit |
9280 | If set, \fBbash\fP will send | |
9281 | .SM | |
9282 | .B SIGHUP | |
9283 | to all jobs when an interactive login shell exits. | |
9284 | .TP 8 | |
ccc6cda3 JA |
9285 | .B interactive_comments |
9286 | If set, allow a word beginning with | |
9287 | .B # | |
9288 | to cause that word and all remaining characters on that | |
9289 | line to be ignored in an interactive shell (see | |
9290 | .SM | |
9291 | .B COMMENTS | |
9292 | above). This option is enabled by default. | |
9293 | .TP 8 | |
7d92f73f CR |
9294 | .B lastpipe |
9295 | If set, and job control is not active, the shell runs the last command of | |
9296 | a pipeline not executed in the background in the current shell environment. | |
9297 | .TP 8 | |
ccc6cda3 JA |
9298 | .B lithist |
9299 | If set, and the | |
9300 | .B cmdhist | |
9301 | option is enabled, multi-line commands are saved to the history with | |
9302 | embedded newlines rather than using semicolon separators where possible. | |
9303 | .TP 8 | |
f73dda09 JA |
9304 | .B login_shell |
9305 | The shell sets this option if it is started as a login shell (see | |
9306 | .SM | |
9307 | .B "INVOCATION" | |
9308 | above). | |
9309 | The value may not be changed. | |
9310 | .TP 8 | |
ccc6cda3 JA |
9311 | .B mailwarn |
9312 | If set, and a file that \fBbash\fP is checking for mail has been | |
9313 | accessed since the last time it was checked, the message ``The mail in | |
9314 | \fImailfile\fP has been read'' is displayed. | |
9315 | .TP 8 | |
bb70624e JA |
9316 | .B no_empty_cmd_completion |
9317 | If set, and | |
9318 | .B readline | |
9319 | is being used, | |
9320 | .B bash | |
984a1947 CR |
9321 | will not attempt to search the |
9322 | .SM | |
9323 | .B PATH | |
9324 | for possible completions when | |
bb70624e JA |
9325 | completion is attempted on an empty line. |
9326 | .TP 8 | |
cce855bc JA |
9327 | .B nocaseglob |
9328 | If set, | |
9329 | .B bash | |
9330 | matches filenames in a case\-insensitive fashion when performing pathname | |
9331 | expansion (see | |
9332 | .B Pathname Expansion | |
9333 | above). | |
9334 | .TP 8 | |
2206f89a CR |
9335 | .B nocasematch |
9336 | If set, | |
9337 | .B bash | |
9338 | matches patterns in a case\-insensitive fashion when performing matching | |
9339 | while executing \fBcase\fP or \fB[[\fP conditional commands. | |
9340 | .TP 8 | |
ccc6cda3 JA |
9341 | .B nullglob |
9342 | If set, | |
9343 | .B bash | |
9344 | allows patterns which match no | |
9345 | files (see | |
9346 | .B Pathname Expansion | |
9347 | above) | |
9348 | to expand to a null string, rather than themselves. | |
9349 | .TP 8 | |
bb70624e JA |
9350 | .B progcomp |
9351 | If set, the programmable completion facilities (see | |
9352 | \fBProgrammable Completion\fP above) are enabled. | |
9353 | This option is enabled by default. | |
9354 | .TP 8 | |
ccc6cda3 | 9355 | .B promptvars |
d3a24ed2 CR |
9356 | If set, prompt strings undergo |
9357 | parameter expansion, command substitution, arithmetic | |
9358 | expansion, and quote removal after being expanded as described in | |
ccc6cda3 JA |
9359 | .SM |
9360 | .B PROMPTING | |
9361 | above. This option is enabled by default. | |
9362 | .TP 8 | |
b72432fd JA |
9363 | .B restricted_shell |
9364 | The shell sets this option if it is started in restricted mode (see | |
9365 | .SM | |
9366 | .B "RESTRICTED SHELL" | |
9367 | below). | |
9368 | The value may not be changed. | |
9369 | This is not reset when the startup files are executed, allowing | |
9370 | the startup files to discover whether or not a shell is restricted. | |
9371 | .TP 8 | |
ccc6cda3 JA |
9372 | .B shift_verbose |
9373 | If set, the | |
9374 | .B shift | |
9375 | builtin prints an error message when the shift count exceeds the | |
9376 | number of positional parameters. | |
9377 | .TP 8 | |
9378 | .B sourcepath | |
9379 | If set, the | |
9380 | \fBsource\fP (\fB.\fP) builtin uses the value of | |
9381 | .SM | |
9382 | .B PATH | |
9383 | to find the directory containing the file supplied as an argument. | |
cce855bc | 9384 | This option is enabled by default. |
bb70624e JA |
9385 | .TP 8 |
9386 | .B xpg_echo | |
9387 | If set, the \fBecho\fP builtin expands backslash-escape sequences | |
9388 | by default. | |
ccc6cda3 | 9389 | .RE |
54a1fa7c | 9390 | .PD |
726f6388 JA |
9391 | .TP |
9392 | \fBsuspend\fP [\fB\-f\fP] | |
9393 | Suspend the execution of this shell until it receives a | |
9394 | .SM | |
9395 | .B SIGCONT | |
09767ff0 | 9396 | signal. A login shell cannot be suspended; the |
726f6388 | 9397 | .B \-f |
09767ff0 CR |
9398 | option can be used to override this and force the suspension. |
9399 | The return status is 0 unless the shell is a login shell and | |
726f6388 JA |
9400 | .B \-f |
9401 | is not supplied, or if job control is not enabled. | |
9402 | .TP | |
726f6388 | 9403 | \fBtest\fP \fIexpr\fP |
7117c2d2 | 9404 | .PD 0 |
726f6388 JA |
9405 | .TP |
9406 | \fB[\fP \fIexpr\fP \fB]\fP | |
b28ff8c9 | 9407 | Return a status of 0 (true) or 1 (false) depending on |
726f6388 JA |
9408 | the evaluation of the conditional expression |
9409 | .IR expr . | |
cce855bc JA |
9410 | Each operator and operand must be a separate argument. |
9411 | Expressions are composed of the primaries described above under | |
9412 | .SM | |
9413 | .BR "CONDITIONAL EXPRESSIONS" . | |
3ffb039a CR |
9414 | \fBtest\fP does not accept any options, nor does it accept and ignore |
9415 | an argument of \fB\-\-\fP as signifying the end of options. | |
cce855bc JA |
9416 | .if t .sp 0.5 |
9417 | .if n .sp 1 | |
9418 | Expressions may be combined using the following operators, listed | |
9419 | in decreasing order of precedence. | |
641d8f00 | 9420 | The evaluation depends on the number of arguments; see below. |
06dff54a | 9421 | Operator precedence is used when there are five or more arguments. |
726f6388 JA |
9422 | .RS |
9423 | .PD 0 | |
9424 | .TP | |
726f6388 JA |
9425 | .B ! \fIexpr\fP |
9426 | True if | |
9427 | .I expr | |
9428 | is false. | |
9429 | .TP | |
cce855bc JA |
9430 | .B ( \fIexpr\fP ) |
9431 | Returns the value of \fIexpr\fP. | |
9432 | This may be used to override the normal precedence of operators. | |
9433 | .TP | |
726f6388 JA |
9434 | \fIexpr1\fP \-\fBa\fP \fIexpr2\fP |
9435 | True if both | |
9436 | .I expr1 | |
cce855bc | 9437 | and |
726f6388 JA |
9438 | .I expr2 |
9439 | are true. | |
9440 | .TP | |
9441 | \fIexpr1\fP \-\fBo\fP \fIexpr2\fP | |
9442 | True if either | |
9443 | .I expr1 | |
cce855bc | 9444 | or |
726f6388 JA |
9445 | .I expr2 |
9446 | is true. | |
cce855bc JA |
9447 | .PD |
9448 | .PP | |
9449 | \fBtest\fP and \fB[\fP evaluate conditional | |
9450 | expressions using a set of rules based on the number of arguments. | |
9451 | .if t .sp 0.5 | |
9452 | .if n .sp 1 | |
9453 | .PD 0 | |
726f6388 | 9454 | .TP |
cce855bc JA |
9455 | 0 arguments |
9456 | The expression is false. | |
9457 | .TP | |
9458 | 1 argument | |
9459 | The expression is true if and only if the argument is not null. | |
9460 | .TP | |
9461 | 2 arguments | |
9462 | If the first argument is \fB!\fP, the expression is true if and | |
9463 | only if the second argument is null. | |
9464 | If the first argument is one of the unary conditional operators listed above | |
9465 | under | |
726f6388 | 9466 | .SM |
cce855bc JA |
9467 | .BR "CONDITIONAL EXPRESSIONS" , |
9468 | the expression is true if the unary test is true. | |
9469 | If the first argument is not a valid unary conditional operator, the expression | |
9470 | is false. | |
9471 | .TP | |
9472 | 3 arguments | |
adc6cff5 | 9473 | The following conditions are applied in the order listed. |
cce855bc JA |
9474 | If the second argument is one of the binary conditional operators listed above |
9475 | under | |
9476 | .SM | |
9477 | .BR "CONDITIONAL EXPRESSIONS" , | |
9478 | the result of the expression is the result of the binary test using | |
9479 | the first and third arguments as operands. | |
641d8f00 CR |
9480 | The \fB\-a\fP and \fB\-o\fP operators are considered binary operators |
9481 | when there are three arguments. | |
cce855bc JA |
9482 | If the first argument is \fB!\fP, the value is the negation of |
9483 | the two-argument test using the second and third arguments. | |
9484 | If the first argument is exactly \fB(\fP and the third argument is | |
9485 | exactly \fB)\fP, the result is the one-argument test of the second | |
9486 | argument. | |
9487 | Otherwise, the expression is false. | |
cce855bc JA |
9488 | .TP |
9489 | 4 arguments | |
9490 | If the first argument is \fB!\fP, the result is the negation of | |
9491 | the three-argument expression composed of the remaining arguments. | |
9492 | Otherwise, the expression is parsed and evaluated according to | |
9493 | precedence using the rules listed above. | |
9494 | .TP | |
9495 | 5 or more arguments | |
9496 | The expression is parsed and evaluated according to precedence | |
9497 | using the rules listed above. | |
54a1fa7c CR |
9498 | .if t .sp 0.5 |
9499 | .if n .sp 1 | |
9500 | .LP | |
9501 | When used with \fBtest\fP or \fB[\fP, the \fB<\fP and \fB>\fP operators | |
9502 | sort lexicographically using ASCII ordering. | |
726f6388 | 9503 | .RE |
cce855bc | 9504 | .PD |
726f6388 JA |
9505 | .TP |
9506 | .B times | |
9507 | Print the accumulated user and system times for the shell and | |
9508 | for processes run from the shell. The return status is 0. | |
9509 | .TP | |
61deeb13 | 9510 | \fBtrap\fP [\fB\-lp\fP] [[\fIarg\fP] \fIsigspec\fP ...] |
726f6388 JA |
9511 | The command |
9512 | .I arg | |
9513 | is to be read and executed when the shell receives | |
9514 | signal(s) | |
9515 | .IR sigspec . | |
9516 | If | |
9517 | .I arg | |
61deeb13 | 9518 | is absent (and there is a single \fIsigspec\fP) or |
726f6388 | 9519 | .BR \- , |
61deeb13 CR |
9520 | each specified signal is |
9521 | reset to its original disposition (the value it had | |
d166f048 JA |
9522 | upon entrance to the shell). |
9523 | If | |
726f6388 | 9524 | .I arg |
d166f048 JA |
9525 | is the null string the signal specified by each |
9526 | .I sigspec | |
9527 | is ignored by the shell and by the commands it invokes. | |
ccc6cda3 JA |
9528 | If |
9529 | .I arg | |
bb70624e | 9530 | is not present and |
ccc6cda3 | 9531 | .B \-p |
bb70624e | 9532 | has been supplied, then the trap commands associated with each |
ccc6cda3 | 9533 | .I sigspec |
bb70624e JA |
9534 | are displayed. |
9535 | If no arguments are supplied or if only | |
ccc6cda3 JA |
9536 | .B \-p |
9537 | is given, | |
9538 | .B trap | |
61deeb13 | 9539 | prints the list of commands associated with each signal. |
d3a24ed2 CR |
9540 | The |
9541 | .B \-l | |
9542 | option causes the shell to print a list of signal names and | |
9543 | their corresponding numbers. | |
d166f048 | 9544 | Each |
726f6388 JA |
9545 | .I sigspec |
9546 | is either | |
d166f048 | 9547 | a signal name defined in <\fIsignal.h\fP>, or a signal number. |
9c7f20c7 CR |
9548 | Signal names are case insensitive and the |
9549 | .SM | |
9550 | .B SIG | |
9551 | prefix is optional. | |
4301bca7 CR |
9552 | .if t .sp 0.5 |
9553 | .if n .sp 1 | |
d166f048 | 9554 | If a |
726f6388 JA |
9555 | .I sigspec |
9556 | is | |
9557 | .SM | |
9558 | .B EXIT | |
9559 | (0) the command | |
9560 | .I arg | |
f73dda09 JA |
9561 | is executed on exit from the shell. |
9562 | If a | |
ccc6cda3 JA |
9563 | .I sigspec |
9564 | is | |
9565 | .SM | |
9566 | .BR DEBUG , | |
9567 | the command | |
9568 | .I arg | |
d3a24ed2 CR |
9569 | is executed before every \fIsimple command\fP, \fIfor\fP command, |
9570 | \fIcase\fP command, \fIselect\fP command, every arithmetic \fIfor\fP | |
9571 | command, and before the first command executes in a shell function (see | |
ccc6cda3 JA |
9572 | .SM |
9573 | .B SHELL GRAMMAR | |
9574 | above). | |
40b074c6 | 9575 | Refer to the description of the \fBextdebug\fP option to the |
d3a24ed2 | 9576 | \fBshopt\fP builtin for details of its effect on the \fBDEBUG\fP trap. |
f73dda09 JA |
9577 | If a |
9578 | .I sigspec | |
9579 | is | |
9580 | .SM | |
4301bca7 CR |
9581 | .BR RETURN , |
9582 | the command | |
9583 | .I arg | |
e05be32d CR |
9584 | is executed each time a shell function or a script executed with |
9585 | the \fB.\fP or \fBsource\fP builtins finishes executing. | |
4301bca7 CR |
9586 | .if t .sp 0.5 |
9587 | .if n .sp 1 | |
9588 | If a | |
9589 | .I sigspec | |
9590 | is | |
9591 | .SM | |
f73dda09 JA |
9592 | .BR ERR , |
9593 | the command | |
9594 | .I arg | |
5e13499c CR |
9595 | is executed whenever a simple command has a non\-zero exit status, |
9596 | subject to the following conditions. | |
f73dda09 JA |
9597 | The |
9598 | .SM | |
d3a24ed2 CR |
9599 | .B ERR |
9600 | trap is not executed if the failed | |
9601 | command is part of the command list immediately following a | |
9602 | .B while | |
f73dda09 | 9603 | or |
d3a24ed2 CR |
9604 | .B until |
9605 | keyword, | |
9606 | part of the test in an | |
f73dda09 | 9607 | .I if |
9d85af6d | 9608 | statement, part of a command executed in a |
f73dda09 JA |
9609 | .B && |
9610 | or | |
adc6cff5 | 9611 | .B || |
f73dda09 JA |
9612 | list, or if the command's return value is |
9613 | being inverted via | |
9614 | .BR ! . | |
5e13499c | 9615 | These are the same conditions obeyed by the \fBerrexit\fP option. |
4301bca7 CR |
9616 | .if t .sp 0.5 |
9617 | .if n .sp 1 | |
726f6388 | 9618 | Signals ignored upon entry to the shell cannot be trapped or reset. |
d3ad40de | 9619 | Trapped signals that are not being ignored are reset to their original |
4301bca7 | 9620 | values in a subshell or subshell environment when one is created. |
d166f048 | 9621 | The return status is false if any |
ccc6cda3 JA |
9622 | .I sigspec |
9623 | is invalid; otherwise | |
726f6388 JA |
9624 | .B trap |
9625 | returns true. | |
9626 | .TP | |
7117c2d2 | 9627 | \fBtype\fP [\fB\-aftpP\fP] \fIname\fP [\fIname\fP ...] |
726f6388 JA |
9628 | With no options, |
9629 | indicate how each | |
9630 | .I name | |
9631 | would be interpreted if used as a command name. | |
9632 | If the | |
cce855bc JA |
9633 | .B \-t |
9634 | option is used, | |
726f6388 | 9635 | .B type |
ccc6cda3 | 9636 | prints a string which is one of |
726f6388 JA |
9637 | .IR alias , |
9638 | .IR keyword , | |
9639 | .IR function , | |
9640 | .IR builtin , | |
9641 | or | |
9642 | .I file | |
9643 | if | |
9644 | .I name | |
9645 | is an alias, shell reserved word, function, builtin, or disk file, | |
ccc6cda3 JA |
9646 | respectively. |
9647 | If the | |
9648 | .I name | |
9649 | is not found, then nothing is printed, and an exit status of false | |
9650 | is returned. | |
726f6388 | 9651 | If the |
cce855bc JA |
9652 | .B \-p |
9653 | option is used, | |
726f6388 JA |
9654 | .B type |
9655 | either returns the name of the disk file | |
9656 | that would be executed if | |
9657 | .I name | |
9658 | were specified as a command name, | |
28ef6c31 JA |
9659 | or nothing if |
9660 | .if t \f(CWtype -t name\fP | |
9661 | .if n ``type -t name'' | |
726f6388 JA |
9662 | would not return |
9663 | .IR file . | |
7117c2d2 JA |
9664 | The |
9665 | .B \-P | |
9666 | option forces a | |
9667 | .SM | |
9668 | .B PATH | |
9669 | search for each \fIname\fP, even if | |
9670 | .if t \f(CWtype -t name\fP | |
9671 | .if n ``type -t name'' | |
9672 | would not return | |
9673 | .IR file . | |
726f6388 | 9674 | If a command is hashed, |
cce855bc | 9675 | .B \-p |
7117c2d2 JA |
9676 | and |
9677 | .B \-P | |
b28ff8c9 | 9678 | print the hashed value, which is not necessarily the file that appears |
726f6388 JA |
9679 | first in |
9680 | .SM | |
9681 | .BR PATH . | |
9682 | If the | |
cce855bc JA |
9683 | .B \-a |
9684 | option is used, | |
726f6388 JA |
9685 | .B type |
9686 | prints all of the places that contain | |
9687 | an executable named | |
9688 | .IR name . | |
9689 | This includes aliases and functions, | |
9690 | if and only if the | |
cce855bc JA |
9691 | .B \-p |
9692 | option is not also used. | |
726f6388 JA |
9693 | The table of hashed commands is not consulted |
9694 | when using | |
cce855bc | 9695 | .BR \-a . |
7117c2d2 JA |
9696 | The |
9697 | .B \-f | |
9698 | option suppresses shell function lookup, as with the \fBcommand\fP builtin. | |
726f6388 | 9699 | .B type |
6a8fd0ed CR |
9700 | returns true if all of the arguments are found, false if |
9701 | any are not found. | |
726f6388 | 9702 | .TP |
6fbe7620 | 9703 | \fBulimit\fP [\fB\-HSTabcdefilmnpqrstuvx\fP [\fIlimit\fP]] |
ccc6cda3 | 9704 | Provides control over the resources available to the shell and to |
f73dda09 | 9705 | processes started by it, on systems that allow such control. |
ccc6cda3 | 9706 | The \fB\-H\fP and \fB\-S\fP options specify that the hard or soft limit is |
79e6c7dc CR |
9707 | set for the given resource. |
9708 | A hard limit cannot be increased by a non-root user once it is set; | |
9709 | a soft limit may be increased up to the value of the hard limit. | |
ccc6cda3 JA |
9710 | If neither \fB\-H\fP nor \fB\-S\fP is specified, both the soft and hard |
9711 | limits are set. | |
f73dda09 JA |
9712 | The value of |
9713 | .I limit | |
9714 | can be a number in the unit specified for the resource | |
9715 | or one of the special values | |
9716 | .BR hard , | |
9717 | .BR soft , | |
9718 | or | |
9719 | .BR unlimited , | |
9720 | which stand for the current hard limit, the current soft limit, and | |
9721 | no limit, respectively. | |
ccc6cda3 | 9722 | If |
726f6388 JA |
9723 | .I limit |
9724 | is omitted, the current value of the soft limit of the resource is | |
ccc6cda3 JA |
9725 | printed, unless the \fB\-H\fP option is given. When more than one |
9726 | resource is specified, the limit name and unit are printed before the value. | |
726f6388 JA |
9727 | Other options are interpreted as follows: |
9728 | .RS | |
9729 | .PD 0 | |
9730 | .TP | |
9731 | .B \-a | |
ccc6cda3 | 9732 | All current limits are reported |
726f6388 | 9733 | .TP |
6fbe7620 CR |
9734 | .B \-b |
9735 | The maximum socket buffer size | |
9736 | .TP | |
726f6388 | 9737 | .B \-c |
ccc6cda3 | 9738 | The maximum size of core files created |
726f6388 JA |
9739 | .TP |
9740 | .B \-d | |
ccc6cda3 | 9741 | The maximum size of a process's data segment |
726f6388 | 9742 | .TP |
dc8fbaf9 CR |
9743 | .B \-e |
9744 | The maximum scheduling priority ("nice") | |
9745 | .TP | |
726f6388 | 9746 | .B \-f |
d3ad40de | 9747 | The maximum size of files written by the shell and its children |
726f6388 | 9748 | .TP |
af12dacd CR |
9749 | .B \-i |
9750 | The maximum number of pending signals | |
9751 | .TP | |
ccc6cda3 JA |
9752 | .B \-l |
9753 | The maximum size that may be locked into memory | |
726f6388 | 9754 | .TP |
ccc6cda3 | 9755 | .B \-m |
db31fb26 | 9756 | The maximum resident set size (many systems do not honor this limit) |
726f6388 | 9757 | .TP |
ccc6cda3 JA |
9758 | .B \-n |
9759 | The maximum number of open file descriptors (most systems do not | |
9760 | allow this value to be set) | |
726f6388 JA |
9761 | .TP |
9762 | .B \-p | |
ccc6cda3 | 9763 | The pipe size in 512-byte blocks (this may not be set) |
726f6388 | 9764 | .TP |
af12dacd CR |
9765 | .B \-q |
9766 | The maximum number of bytes in POSIX message queues | |
9767 | .TP | |
dc8fbaf9 CR |
9768 | .B \-r |
9769 | The maximum real-time scheduling priority | |
9770 | .TP | |
ccc6cda3 JA |
9771 | .B \-s |
9772 | The maximum stack size | |
9773 | .TP | |
9774 | .B \-t | |
9775 | The maximum amount of cpu time in seconds | |
726f6388 JA |
9776 | .TP |
9777 | .B \-u | |
ccc6cda3 | 9778 | The maximum number of processes available to a single user |
726f6388 JA |
9779 | .TP |
9780 | .B \-v | |
68dfe178 CR |
9781 | The maximum amount of virtual memory available to the shell and, on |
9782 | some systems, to its children | |
af12dacd CR |
9783 | .TP |
9784 | .B \-x | |
9785 | The maximum number of file locks | |
6fbe7620 CR |
9786 | .TP |
9787 | .B \-T | |
9788 | The maximum number of threads | |
726f6388 JA |
9789 | .PD |
9790 | .PP | |
ccc6cda3 | 9791 | If |
726f6388 | 9792 | .I limit |
b28ff8c9 | 9793 | is given, and the |
726f6388 | 9794 | .B \-a |
b28ff8c9 CR |
9795 | option is not used, |
9796 | \fIlimit\fP is the new value of the specified resource. | |
726f6388 JA |
9797 | If no option is given, then |
9798 | .B \-f | |
9799 | is assumed. Values are in 1024-byte increments, except for | |
9800 | .BR \-t , | |
b28ff8c9 | 9801 | which is in seconds; |
726f6388 | 9802 | .BR \-p , |
b28ff8c9 | 9803 | which is in units of 512-byte blocks; |
726f6388 | 9804 | and |
6fbe7620 CR |
9805 | .BR \-T , |
9806 | .BR \-b , | |
9807 | .BR \-n , | |
726f6388 JA |
9808 | and |
9809 | .BR \-u , | |
f73dda09 JA |
9810 | which are unscaled values. |
9811 | The return status is 0 unless an invalid option or argument is supplied, | |
9812 | or an error occurs while setting a new limit. | |
726f6388 JA |
9813 | .RE |
9814 | .TP | |
cce855bc | 9815 | \fBumask\fP [\fB\-p\fP] [\fB\-S\fP] [\fImode\fP] |
726f6388 JA |
9816 | The user file-creation mask is set to |
9817 | .IR mode . | |
9818 | If | |
9819 | .I mode | |
9820 | begins with a digit, it | |
9821 | is interpreted as an octal number; otherwise | |
9822 | it is interpreted as a symbolic mode mask similar | |
9823 | to that accepted by | |
9824 | .IR chmod (1). | |
9825 | If | |
9826 | .I mode | |
bb70624e | 9827 | is omitted, the current value of the mask is printed. |
ccc6cda3 | 9828 | The |
726f6388 JA |
9829 | .B \-S |
9830 | option causes the mask to be printed in symbolic form; the | |
9831 | default output is an octal number. | |
cce855bc JA |
9832 | If the |
9833 | .B \-p | |
9834 | option is supplied, and | |
9835 | .I mode | |
9836 | is omitted, the output is in a form that may be reused as input. | |
ccc6cda3 | 9837 | The return status is 0 if the mode was successfully changed or if |
726f6388 JA |
9838 | no \fImode\fP argument was supplied, and false otherwise. |
9839 | .TP | |
9840 | \fBunalias\fP [\-\fBa\fP] [\fIname\fP ...] | |
bb70624e | 9841 | Remove each \fIname\fP from the list of defined aliases. If |
726f6388 JA |
9842 | .B \-a |
9843 | is supplied, all alias definitions are removed. The return | |
9844 | value is true unless a supplied | |
9845 | .I name | |
9846 | is not a defined alias. | |
9847 | .TP | |
9848 | \fBunset\fP [\-\fBfv\fP] [\fIname\fP ...] | |
9849 | For each | |
9850 | .IR name , | |
ccc6cda3 | 9851 | remove the corresponding variable or function. |
276cb932 | 9852 | If the |
ccc6cda3 JA |
9853 | .B \-v |
9854 | option is given, each | |
9855 | .I name | |
276cb932 | 9856 | refers to a shell variable, and that variable is removed. |
ccc6cda3 JA |
9857 | Read-only variables may not be unset. |
9858 | If | |
726f6388 | 9859 | .B \-f |
f75912ae | 9860 | is specified, each |
ccc6cda3 JA |
9861 | .I name |
9862 | refers to a shell function, and the function definition | |
9863 | is removed. | |
276cb932 CR |
9864 | If no options are supplied, each \fIname\fP refers to a variable; if |
9865 | there is no variable by that name, any function with that name is | |
9866 | unset. | |
ccc6cda3 JA |
9867 | Each unset variable or function is removed from the environment |
9868 | passed to subsequent commands. | |
9869 | If any of | |
726f6388 | 9870 | .SM |
984a1947 CR |
9871 | .BR COMP_WORDBREAKS , |
9872 | .SM | |
726f6388 JA |
9873 | .BR RANDOM , |
9874 | .SM | |
9875 | .BR SECONDS , | |
9876 | .SM | |
9877 | .BR LINENO , | |
ccc6cda3 JA |
9878 | .SM |
9879 | .BR HISTCMD , | |
bb70624e JA |
9880 | .SM |
9881 | .BR FUNCNAME , | |
9882 | .SM | |
9883 | .BR GROUPS , | |
726f6388 JA |
9884 | or |
9885 | .SM | |
ccc6cda3 | 9886 | .B DIRSTACK |
726f6388 JA |
9887 | are unset, they lose their special properties, even if they are |
9888 | subsequently reset. The exit status is true unless a | |
9889 | .I name | |
d3a24ed2 | 9890 | is readonly. |
726f6388 | 9891 | .TP |
d90269dd CR |
9892 | \fBwait\fP [\fIn ...\fP] |
9893 | Wait for each specified process and return its termination status. | |
9894 | Each | |
726f6388 JA |
9895 | .I n |
9896 | may be a process | |
9897 | ID or a job specification; if a job spec is given, all processes | |
9898 | in that job's pipeline are waited for. If | |
9899 | .I n | |
9900 | is not given, all currently active child processes | |
9901 | are waited for, and the return status is zero. If | |
9902 | .I n | |
ccc6cda3 | 9903 | specifies a non-existent process or job, the return status is |
726f6388 JA |
9904 | 127. Otherwise, the return status is the exit status of the last |
9905 | process or job waited for. | |
9906 | .\" bash_builtins | |
9907 | .if \n(zZ=1 .ig zZ | |
ccc6cda3 | 9908 | .SH "RESTRICTED SHELL" |
bb70624e JA |
9909 | .\" rbash.1 |
9910 | .zY | |
726f6388 | 9911 | .PP |
ccc6cda3 | 9912 | If |
726f6388 | 9913 | .B bash |
ccc6cda3 JA |
9914 | is started with the name |
9915 | .BR rbash , | |
9916 | or the | |
9917 | .B \-r | |
9918 | option is supplied at invocation, | |
9919 | the shell becomes restricted. | |
9920 | A restricted shell is used to | |
9921 | set up an environment more controlled than the standard shell. | |
9922 | It behaves identically to | |
9923 | .B bash | |
cce855bc | 9924 | with the exception that the following are disallowed or not performed: |
ccc6cda3 JA |
9925 | .IP \(bu |
9926 | changing directories with \fBcd\fP | |
9927 | .IP \(bu | |
9928 | setting or unsetting the values of | |
984a1947 | 9929 | .SM |
b72432fd | 9930 | .BR SHELL , |
984a1947 | 9931 | .SM |
b72432fd | 9932 | .BR PATH , |
984a1947 | 9933 | .SM |
b72432fd | 9934 | .BR ENV , |
ccc6cda3 | 9935 | or |
984a1947 | 9936 | .SM |
b72432fd | 9937 | .B BASH_ENV |
ccc6cda3 JA |
9938 | .IP \(bu |
9939 | specifying command names containing | |
9940 | .B / | |
9941 | .IP \(bu | |
b28ff8c9 | 9942 | specifying a filename containing a |
ccc6cda3 JA |
9943 | .B / |
9944 | as an argument to the | |
9945 | .B . | |
9946 | builtin command | |
9947 | .IP \(bu | |
dc60d4e0 | 9948 | specifying a filename containing a slash as an argument to the |
bb70624e JA |
9949 | .B \-p |
9950 | option to the | |
9951 | .B hash | |
9952 | builtin command | |
9953 | .IP \(bu | |
ccc6cda3 JA |
9954 | importing function definitions from the shell environment at startup |
9955 | .IP \(bu | |
984a1947 CR |
9956 | parsing the value of |
9957 | .SM | |
9958 | .B SHELLOPTS | |
9959 | from the shell environment at startup | |
cce855bc | 9960 | .IP \(bu |
ccc6cda3 JA |
9961 | redirecting output using the >, >|, <>, >&, &>, and >> redirection operators |
9962 | .IP \(bu | |
9963 | using the | |
9964 | .B exec | |
9965 | builtin command to replace the shell with another command | |
9966 | .IP \(bu | |
9967 | adding or deleting builtin commands with the | |
9968 | .B \-f | |
726f6388 | 9969 | and |
ccc6cda3 JA |
9970 | .B \-d |
9971 | options to the | |
9972 | .B enable | |
9973 | builtin command | |
9974 | .IP \(bu | |
dc60d4e0 | 9975 | using the \fBenable\fP builtin command to enable disabled shell builtins |
7117c2d2 | 9976 | .IP \(bu |
ccc6cda3 JA |
9977 | specifying the |
9978 | .B \-p | |
9979 | option to the | |
9980 | .B command | |
9981 | builtin command | |
9982 | .IP \(bu | |
9983 | turning off restricted mode with | |
cce855bc | 9984 | \fBset +r\fP or \fBset +o restricted\fP. |
726f6388 | 9985 | .PP |
ccc6cda3 JA |
9986 | These restrictions are enforced after any startup files are read. |
9987 | .PP | |
61deeb13 CR |
9988 | .ie \n(zY=1 When a command that is found to be a shell script is executed, |
9989 | .el \{ When a command that is found to be a shell script is executed | |
9990 | (see | |
ccc6cda3 JA |
9991 | .SM |
9992 | .B "COMMAND EXECUTION" | |
9993 | above), | |
61deeb13 | 9994 | \} |
ccc6cda3 JA |
9995 | .B rbash |
9996 | turns off any restrictions in the shell spawned to execute the | |
9997 | script. | |
bb70624e JA |
9998 | .\" end of rbash.1 |
9999 | .if \n(zY=1 .ig zY | |
726f6388 JA |
10000 | .SH "SEE ALSO" |
10001 | .PD 0 | |
10002 | .TP | |
bb70624e | 10003 | \fIBash Reference Manual\fP, Brian Fox and Chet Ramey |
726f6388 JA |
10004 | .TP |
10005 | \fIThe Gnu Readline Library\fP, Brian Fox and Chet Ramey | |
10006 | .TP | |
10007 | \fIThe Gnu History Library\fP, Brian Fox and Chet Ramey | |
10008 | .TP | |
726f6388 JA |
10009 | \fIPortable Operating System Interface (POSIX) Part 2: Shell and Utilities\fP, IEEE |
10010 | .TP | |
10011 | \fIsh\fP(1), \fIksh\fP(1), \fIcsh\fP(1) | |
10012 | .TP | |
10013 | \fIemacs\fP(1), \fIvi\fP(1) | |
10014 | .TP | |
10015 | \fIreadline\fP(3) | |
10016 | .PD | |
10017 | .SH FILES | |
10018 | .PD 0 | |
10019 | .TP | |
10020 | .FN /bin/bash | |
10021 | The \fBbash\fP executable | |
10022 | .TP | |
10023 | .FN /etc/profile | |
10024 | The systemwide initialization file, executed for login shells | |
10025 | .TP | |
10026 | .FN ~/.bash_profile | |
10027 | The personal initialization file, executed for login shells | |
10028 | .TP | |
10029 | .FN ~/.bashrc | |
10030 | The individual per-interactive-shell startup file | |
10031 | .TP | |
b72432fd JA |
10032 | .FN ~/.bash_logout |
10033 | The individual login shell cleanup file, executed when a login shell exits | |
10034 | .TP | |
726f6388 JA |
10035 | .FN ~/.inputrc |
10036 | Individual \fIreadline\fP initialization file | |
10037 | .PD | |
10038 | .SH AUTHORS | |
ccc6cda3 | 10039 | Brian Fox, Free Software Foundation |
726f6388 | 10040 | .br |
bb70624e | 10041 | bfox@gnu.org |
726f6388 JA |
10042 | .PP |
10043 | Chet Ramey, Case Western Reserve University | |
10044 | .br | |
db31fb26 | 10045 | chet.ramey@case.edu |
726f6388 JA |
10046 | .SH BUG REPORTS |
10047 | If you find a bug in | |
10048 | .B bash, | |
10049 | you should report it. But first, you should | |
10050 | make sure that it really is a bug, and that it appears in the latest | |
10051 | version of | |
d3a24ed2 CR |
10052 | .BR bash . |
10053 | The latest version is always available from | |
9c7f20c7 | 10054 | \fIftp://ftp.gnu.org/pub/gnu/bash/\fP. |
726f6388 JA |
10055 | .PP |
10056 | Once you have determined that a bug actually exists, use the | |
10057 | .I bashbug | |
10058 | command to submit a bug report. | |
d166f048 | 10059 | If you have a fix, you are encouraged to mail that as well! |
726f6388 | 10060 | Suggestions and `philosophical' bug reports may be mailed |
cce855bc | 10061 | to \fIbug-bash@gnu.org\fP or posted to the Usenet |
726f6388 JA |
10062 | newsgroup |
10063 | .BR gnu.bash.bug . | |
10064 | .PP | |
10065 | ALL bug reports should include: | |
10066 | .PP | |
10067 | .PD 0 | |
10068 | .TP 20 | |
10069 | The version number of \fBbash\fR | |
10070 | .TP | |
10071 | The hardware and operating system | |
10072 | .TP | |
10073 | The compiler used to compile | |
10074 | .TP | |
10075 | A description of the bug behaviour | |
10076 | .TP | |
10077 | A short script or `recipe' which exercises the bug | |
10078 | .PD | |
10079 | .PP | |
10080 | .I bashbug | |
10081 | inserts the first three items automatically into the template | |
10082 | it provides for filing a bug report. | |
10083 | .PP | |
10084 | Comments and bug reports concerning | |
10085 | this manual page should be directed to | |
54a1fa7c | 10086 | .IR chet.ramey@case.edu . |
726f6388 JA |
10087 | .SH BUGS |
10088 | .PP | |
10089 | It's too big and too slow. | |
10090 | .PP | |
10091 | There are some subtle differences between | |
10092 | .B bash | |
10093 | and traditional versions of | |
10094 | .BR sh , | |
10095 | mostly because of the | |
10096 | .SM | |
10097 | .B POSIX | |
10098 | specification. | |
10099 | .PP | |
10100 | Aliases are confusing in some uses. | |
ccc6cda3 JA |
10101 | .PP |
10102 | Shell builtin commands and functions are not stoppable/restartable. | |
10103 | .PP | |
10104 | Compound commands and command sequences of the form `a ; b ; c' | |
10105 | are not handled gracefully when process suspension is attempted. | |
10106 | When a process is stopped, the shell immediately executes the next | |
10107 | command in the sequence. | |
10108 | It suffices to place the sequence of commands between | |
10109 | parentheses to force it into a subshell, which may be stopped as | |
10110 | a unit. | |
10111 | .PP | |
ccc6cda3 | 10112 | Array variables may not (yet) be exported. |
09767ff0 CR |
10113 | .PP |
10114 | There may be only one active coprocess at a time. | |
726f6388 | 10115 | .zZ |
bb70624e | 10116 | .zY |