]>
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 | .\" |
5cdaaf76 | 8 | .\" Last Change: Fri Jan 15 10:50:42 EST 2010 |
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 |
5cdaaf76 | 13 | .TH BASH 1 "2010 January 15" "GNU Bash-4.1" |
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] | |
51 | [file] | |
52 | .SH COPYRIGHT | |
012bac39 CR |
53 | .if n Bash is Copyright (C) 1989-2009 by the Free Software Foundation, Inc. |
54 | .if t Bash is Copyright \(co 1989-2009 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 | |
78 | .BI \-c "\| string\^" | |
ccc6cda3 | 79 | If the |
726f6388 | 80 | .B \-c |
cce855bc | 81 | option is present, then commands are read from |
726f6388 JA |
82 | .IR string . |
83 | If there are arguments after the | |
84 | .IR string , | |
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. | |
297 | Tildes are expanded in file names as described below under | |
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 | |
351 | variable is not used to search for the file name. | |
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 CR |
410 | attempts to determine when it is being run with its standard input |
411 | connected to a a network connection, as if by the remote shell | |
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 | |
8943768b CR |
479 | .if t \fB\(bv\(bv & && ; ;; ( ) | |& <newline>\fP |
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). | |
8943768b CR |
533 | If \fB|&\fP is used, the standard error of \fIcommand\fP is connected to |
534 | \fIcommand2\fP's standard input through the pipe; it is shorthand for | |
535 | \fB2>&1 |\fP. | |
536 | This implicit redirection of the standard error is performed after any | |
537 | redirections specified by the command. | |
726f6388 | 538 | .PP |
d3a24ed2 CR |
539 | The return status of a pipeline is the exit status of the last |
540 | command, unless the \fBpipefail\fP option is enabled. | |
541 | If \fBpipefail\fP is enabled, the pipeline's return status is the | |
542 | value of the last (rightmost) command to exit with a non-zero status, | |
543 | or zero if all commands exit successfully. | |
726f6388 JA |
544 | If the reserved word |
545 | .B ! | |
d3a24ed2 CR |
546 | precedes a pipeline, the exit status of that pipeline is the logical |
547 | negation of the exit status as described above. | |
ccc6cda3 | 548 | The shell waits for all commands in the pipeline to |
726f6388 JA |
549 | terminate before returning a value. |
550 | .PP | |
ccc6cda3 JA |
551 | If the |
552 | .B time | |
553 | reserved word precedes a pipeline, the elapsed as well as user and | |
554 | system time consumed by its execution are reported when the pipeline | |
555 | terminates. | |
556 | The \fB\-p\fP option changes the output format to that specified by POSIX. | |
557 | The | |
558 | .SM | |
559 | .B TIMEFORMAT | |
560 | variable may be set to a format string that specifies how the timing | |
561 | information should be displayed; see the description of | |
562 | .SM | |
563 | .B TIMEFORMAT | |
564 | under | |
565 | .B "Shell Variables" | |
566 | below. | |
567 | .PP | |
726f6388 JA |
568 | Each command in a pipeline is executed as a separate process (i.e., in a |
569 | subshell). | |
570 | .SS Lists | |
571 | .PP | |
572 | A \fIlist\fP is a sequence of one or more pipelines separated by one | |
573 | of the operators | |
574 | .BR ; , | |
575 | .BR & , | |
576 | .BR && , | |
577 | or | |
ccc6cda3 JA |
578 | .BR \(bv\(bv , |
579 | and optionally terminated by one of | |
726f6388 JA |
580 | .BR ; , |
581 | .BR & , | |
582 | or | |
583 | .BR <newline> . | |
584 | .PP | |
585 | Of these list operators, | |
586 | .B && | |
587 | and | |
ccc6cda3 | 588 | .B \(bv\(bv |
726f6388 JA |
589 | have equal precedence, followed by |
590 | .B ; | |
591 | and | |
b1a26c01 | 592 | .BR & , |
726f6388 JA |
593 | which have equal precedence. |
594 | .PP | |
7117c2d2 JA |
595 | A sequence of one or more newlines may appear in a \fIlist\fP instead |
596 | of a semicolon to delimit commands. | |
597 | .PP | |
726f6388 JA |
598 | If a command is terminated by the control operator |
599 | .BR & , | |
600 | the shell executes the command in the \fIbackground\fP | |
601 | in a subshell. The shell does not wait for the command to | |
602 | finish, and the return status is 0. Commands separated by a | |
603 | .B ; | |
604 | are executed sequentially; the shell waits for each | |
605 | command to terminate in turn. The return status is the | |
606 | exit status of the last command executed. | |
607 | .PP | |
6fbe7620 CR |
608 | AND and OR lists are sequences of one of more pipelines separated by the |
609 | \fB&&\fP and \fB\(bv\(bv\fP control operators, respectively. | |
610 | AND and OR lists are executed with left associativity. | |
726f6388 JA |
611 | An AND list has the form |
612 | .RS | |
613 | .PP | |
bb70624e | 614 | \fIcommand1\fP \fB&&\fP \fIcommand2\fP |
726f6388 JA |
615 | .RE |
616 | .PP | |
617 | .I command2 | |
618 | is executed if, and only if, | |
bb70624e | 619 | .I command1 |
726f6388 JA |
620 | returns an exit status of zero. |
621 | .PP | |
622 | An OR list has the form | |
623 | .RS | |
624 | .PP | |
bb70624e | 625 | \fIcommand1\fP \fB\(bv\(bv\fP \fIcommand2\fP |
726f6388 JA |
626 | .PP |
627 | .RE | |
628 | .PP | |
629 | .I command2 | |
630 | is executed if and only if | |
bb70624e | 631 | .I command1 |
6fbe7620 CR |
632 | returns a non-zero exit status. |
633 | The return status of | |
726f6388 JA |
634 | AND and OR lists is the exit status of the last command |
635 | executed in the list. | |
636 | .SS Compound Commands | |
637 | .PP | |
638 | A \fIcompound command\fP is one of the following: | |
639 | .TP | |
640 | (\fIlist\fP) | |
d3a24ed2 CR |
641 | \fIlist\fP is executed in a subshell environment (see |
642 | .SM | |
643 | \fBCOMMAND EXECUTION ENVIRONMENT\fP | |
644 | below). | |
645 | Variable assignments and builtin | |
726f6388 JA |
646 | commands that affect the shell's environment do not remain in effect |
647 | after the command completes. The return status is the exit status of | |
648 | \fIlist\fP. | |
649 | .TP | |
650 | { \fIlist\fP; } | |
ccc6cda3 JA |
651 | \fIlist\fP is simply executed in the current shell environment. |
652 | \fIlist\fP must be terminated with a newline or semicolon. | |
653 | This is known as a \fIgroup command\fP. | |
654 | The return status is the exit status of | |
726f6388 | 655 | \fIlist\fP. |
d3a24ed2 | 656 | Note that unlike the metacharacters \fB(\fP and \fB)\fP, \fB{\fP and |
f73dda09 JA |
657 | \fB}\fP are \fIreserved words\fP and must occur where a reserved |
658 | word is permitted to be recognized. Since they do not cause a word | |
641d8f00 CR |
659 | break, they must be separated from \fIlist\fP by whitespace or another |
660 | shell metacharacter. | |
726f6388 | 661 | .TP |
ccc6cda3 JA |
662 | ((\fIexpression\fP)) |
663 | The \fIexpression\fP is evaluated according to the rules described | |
664 | below under | |
665 | .SM | |
666 | .BR "ARITHMETIC EVALUATION" . | |
667 | If the value of the expression is non-zero, the return status is 0; | |
668 | otherwise the return status is 1. This is exactly equivalent to | |
669 | \fBlet "\fIexpression\fP"\fR. | |
670 | .TP | |
cce855bc JA |
671 | \fB[[\fP \fIexpression\fP \fB]]\fP |
672 | Return a status of 0 or 1 depending on the evaluation of | |
673 | the conditional expression \fIexpression\fP. | |
674 | Expressions are composed of the primaries described below under | |
675 | .SM | |
676 | .BR "CONDITIONAL EXPRESSIONS" . | |
677 | Word splitting and pathname expansion are not performed on the words | |
678 | between the \fB[[\fP and \fB]]\fP; tilde expansion, parameter and | |
679 | variable expansion, arithmetic expansion, command substitution, process | |
680 | substitution, and quote removal are performed. | |
d3a24ed2 CR |
681 | Conditional operators such as \fB\-f\fP must be unquoted to be recognized |
682 | as primaries. | |
cce855bc JA |
683 | .if t .sp 0.5 |
684 | .if n .sp 1 | |
a8fd3f3e CR |
685 | When used with \fB[[\fP, The \fB<\fP and \fB>\fP operators sort |
686 | lexicographically using the current locale. | |
687 | .if t .sp 0.5 | |
688 | .if n .sp 1 | |
cce855bc JA |
689 | When the \fB==\fP and \fB!=\fP operators are used, the string to the |
690 | right of the operator is considered a pattern and matched according | |
691 | to the rules described below under \fBPattern Matching\fP. | |
2206f89a CR |
692 | If the shell option |
693 | .B nocasematch | |
694 | is enabled, the match is performed without regard to the case | |
695 | of alphabetic characters. | |
dc8fbaf9 CR |
696 | The return value is 0 if the string matches (\fB==\fP) or does not match |
697 | (\fB!=\fP) the pattern, and 1 otherwise. | |
cce855bc JA |
698 | Any part of the pattern may be quoted to force it to be matched as a |
699 | string. | |
700 | .if t .sp 0.5 | |
701 | .if n .sp 1 | |
d3a24ed2 CR |
702 | An additional binary operator, \fB=~\fP, is available, with the same |
703 | precedence as \fB==\fP and \fB!=\fP. | |
704 | When it is used, the string to the right of the operator is considered | |
705 | an extended regular expression and matched accordingly (as in \fIregex\fP(3)). | |
d7f49990 CR |
706 | The return value is 0 if the string matches |
707 | the pattern, and 1 otherwise. | |
d3a24ed2 CR |
708 | If the regular expression is syntactically incorrect, the conditional |
709 | expression's return value is 2. | |
710 | If the shell option | |
2206f89a | 711 | .B nocasematch |
d3a24ed2 CR |
712 | is enabled, the match is performed without regard to the case |
713 | of alphabetic characters. | |
3745eee9 CR |
714 | Any part of the pattern may be quoted to force it to be matched as a |
715 | string. | |
d3a24ed2 | 716 | Substrings matched by parenthesized subexpressions within the regular |
984a1947 CR |
717 | expression are saved in the array variable |
718 | .SM | |
719 | .BR BASH_REMATCH . | |
720 | The element of | |
721 | .SM | |
722 | .B BASH_REMATCH | |
723 | with index 0 is the portion of the string | |
d3a24ed2 | 724 | matching the entire regular expression. |
984a1947 CR |
725 | The element of |
726 | .SM | |
727 | .B BASH_REMATCH | |
728 | with index \fIn\fP is the portion of the | |
d3a24ed2 CR |
729 | string matching the \fIn\fPth parenthesized subexpression. |
730 | .if t .sp 0.5 | |
731 | .if n .sp 1 | |
cce855bc JA |
732 | Expressions may be combined using the following operators, listed |
733 | in decreasing order of precedence: | |
734 | .if t .sp 0.5 | |
735 | .if n .sp 1 | |
736 | .RS | |
737 | .PD 0 | |
738 | .TP | |
739 | .B ( \fIexpression\fP ) | |
740 | Returns the value of \fIexpression\fP. | |
741 | This may be used to override the normal precedence of operators. | |
742 | .TP | |
743 | .B ! \fIexpression\fP | |
744 | True if | |
745 | .I expression | |
746 | is false. | |
747 | .TP | |
748 | \fIexpression1\fP \fB&&\fP \fIexpression2\fP | |
749 | True if both | |
750 | .I expression1 | |
751 | and | |
752 | .I expression2 | |
753 | are true. | |
754 | .TP | |
755 | .if t \fIexpression1\fP \fB\(bv\(bv\fP \fIexpression2\fP | |
756 | .if n \fIexpression1\fP \fB||\fP \fIexpression2\fP | |
757 | True if either | |
758 | .I expression1 | |
759 | or | |
760 | .I expression2 | |
761 | is true. | |
762 | .PD | |
cce855bc JA |
763 | .LP |
764 | The \fB&&\fP and | |
765 | .if t \fB\(bv\(bv\fP | |
766 | .if n \fB||\fP | |
7117c2d2 | 767 | operators do not evaluate \fIexpression2\fP if the value of |
cce855bc JA |
768 | \fIexpression1\fP is sufficient to determine the return value of |
769 | the entire conditional expression. | |
f73dda09 | 770 | .RE |
cce855bc | 771 | .TP |
0d8616ff | 772 | \fBfor\fP \fIname\fP [ [ \fBin\fP [ \fIword ...\fP ] ] ; ] \fBdo\fP \fIlist\fP ; \fBdone\fP |
726f6388 | 773 | The list of words following \fBin\fP is expanded, generating a list |
bb70624e JA |
774 | of items. |
775 | The variable \fIname\fP is set to each element of this list | |
776 | in turn, and \fIlist\fP is executed each time. | |
777 | If the \fBin\fP \fIword\fP is omitted, the \fBfor\fP command executes | |
778 | \fIlist\fP once for each positional parameter that is set (see | |
726f6388 JA |
779 | .SM |
780 | .B PARAMETERS | |
781 | below). | |
cce855bc JA |
782 | The return status is the exit status of the last command that executes. |
783 | If the expansion of the items following \fBin\fP results in an empty | |
784 | list, no commands are executed, and the return status is 0. | |
726f6388 | 785 | .TP |
bb70624e JA |
786 | \fBfor\fP (( \fIexpr1\fP ; \fIexpr2\fP ; \fIexpr3\fP )) ; \fBdo\fP \fIlist\fP ; \fBdone\fP |
787 | First, the arithmetic expression \fIexpr1\fP is evaluated according | |
788 | to the rules described below under | |
789 | .SM | |
790 | .BR "ARITHMETIC EVALUATION" . | |
791 | The arithmetic expression \fIexpr2\fP is then evaluated repeatedly | |
792 | until it evaluates to zero. | |
793 | Each time \fIexpr2\fP evaluates to a non-zero value, \fIlist\fP is | |
794 | executed and the arithmetic expression \fIexpr3\fP is evaluated. | |
795 | If any expression is omitted, it behaves as if it evaluates to 1. | |
796 | The return value is the exit status of the last command in \fIlist\fP | |
797 | that is executed, or false if any of the expressions is invalid. | |
798 | .TP | |
b72432fd | 799 | \fBselect\fP \fIname\fP [ \fBin\fP \fIword\fP ] ; \fBdo\fP \fIlist\fP ; \fBdone\fP |
726f6388 JA |
800 | The list of words following \fBin\fP is expanded, generating a list |
801 | of items. The set of expanded words is printed on the standard | |
802 | error, each preceded by a number. If the \fBin\fP | |
803 | \fIword\fP is omitted, the positional parameters are printed (see | |
804 | .SM | |
805 | .B PARAMETERS | |
806 | below). The | |
984a1947 | 807 | .SM |
726f6388 JA |
808 | .B PS3 |
809 | prompt is then displayed and a line read from the standard input. | |
ccc6cda3 | 810 | If the line consists of a number corresponding to one of |
726f6388 JA |
811 | the displayed words, then the value of |
812 | .I name | |
813 | is set to that word. If the line is empty, the words and prompt | |
814 | are displayed again. If EOF is read, the command completes. Any | |
815 | other value read causes | |
816 | .I name | |
817 | to be set to null. The line read is saved in the variable | |
984a1947 | 818 | .SM |
726f6388 JA |
819 | .BR REPLY . |
820 | The | |
821 | .I list | |
822 | is executed after each selection until a | |
823 | .B break | |
726f6388 JA |
824 | command is executed. |
825 | The exit status of | |
826 | .B select | |
827 | is the exit status of the last command executed in | |
828 | .IR list , | |
829 | or zero if no commands were executed. | |
830 | .TP | |
bb70624e | 831 | \fBcase\fP \fIword\fP \fBin\fP [ [(] \fIpattern\fP [ \fB|\fP \fIpattern\fP ] \ |
726f6388 JA |
832 | ... ) \fIlist\fP ;; ] ... \fBesac\fP |
833 | A \fBcase\fP command first expands \fIword\fP, and tries to match | |
834 | it against each \fIpattern\fP in turn, using the same matching rules | |
835 | as for pathname expansion (see | |
836 | .B Pathname Expansion | |
2206f89a | 837 | below). |
dc8fbaf9 | 838 | The \fIword\fP is expanded using tilde |
d3ad40de | 839 | expansion, parameter and variable expansion, arithmetic substitution, |
dc8fbaf9 CR |
840 | command substitution, process substitution and quote removal. |
841 | Each \fIpattern\fP examined is expanded using tilde | |
d3ad40de | 842 | expansion, parameter and variable expansion, arithmetic substitution, |
dc8fbaf9 | 843 | command substitution, and process substitution. |
2206f89a CR |
844 | If the shell option |
845 | .B nocasematch | |
846 | is enabled, the match is performed without regard to the case | |
847 | of alphabetic characters. | |
8943768b CR |
848 | When a match is found, the corresponding \fIlist\fP is executed. |
849 | If the \fB;;\fP operator is used, no subsequent matches are attempted after | |
850 | the first pattern match. | |
851 | Using \fB;&\fP in place of \fB;;\fP causes execution to continue with | |
852 | the \fIlist\fP associated with the next set of patterns. | |
853 | Using \fB;;&\fP in place of \fB;;\fP causes the shell to test the next | |
854 | pattern list in the statement, if any, and execute any associated \fIlist\fP | |
855 | on a successful match. | |
856 | The exit status is zero if no | |
ccc6cda3 | 857 | pattern matches. Otherwise, it is the exit status of the |
726f6388 JA |
858 | last command executed in \fIlist\fP. |
859 | .TP | |
ccc6cda3 JA |
860 | \fBif\fP \fIlist\fP; \fBthen\fP \fIlist;\fP \ |
861 | [ \fBelif\fP \fIlist\fP; \fBthen\fP \fIlist\fP; ] ... \ | |
862 | [ \fBelse\fP \fIlist\fP; ] \fBfi\fP | |
726f6388 JA |
863 | The |
864 | .B if | |
865 | .I list | |
866 | is executed. If its exit status is zero, the | |
867 | \fBthen\fP \fIlist\fP is executed. Otherwise, each \fBelif\fP | |
868 | \fIlist\fP is executed in turn, and if its exit status is zero, | |
869 | the corresponding \fBthen\fP \fIlist\fP is executed and the | |
870 | command completes. Otherwise, the \fBelse\fP \fIlist\fP is | |
871 | executed, if present. The exit status is the exit status of the | |
872 | last command executed, or zero if no condition tested true. | |
873 | .TP | |
ccc6cda3 | 874 | \fBwhile\fP \fIlist\fP; \fBdo\fP \fIlist\fP; \fBdone\fP |
7117c2d2 | 875 | .PD 0 |
726f6388 | 876 | .TP |
ccc6cda3 | 877 | \fBuntil\fP \fIlist\fP; \fBdo\fP \fIlist\fP; \fBdone\fP |
726f6388 JA |
878 | .PD |
879 | The \fBwhile\fP command continuously executes the \fBdo\fP | |
880 | \fIlist\fP as long as the last command in \fIlist\fP returns | |
881 | an exit status of zero. The \fBuntil\fP command is identical | |
882 | to the \fBwhile\fP command, except that the test is negated; | |
883 | the | |
884 | .B do | |
885 | .I list | |
886 | is executed as long as the last command in | |
887 | .I list | |
ccc6cda3 | 888 | returns a non-zero exit status. |
726f6388 JA |
889 | The exit status of the \fBwhile\fP and \fBuntil\fP commands |
890 | is the exit status | |
891 | of the last \fBdo\fP \fIlist\fP command executed, or zero if | |
892 | none was executed. | |
09767ff0 CR |
893 | .SS Coprocesses |
894 | .PP | |
895 | A \fIcoprocess\fP is a shell command preceded by the \fBcoproc\fP reserved | |
896 | word. | |
897 | A coprocess is executed asynchronously in a subshell, as if the command | |
898 | had been terminated with the \fB&\fP control operator, with a two-way pipe | |
899 | established between the executing shell and the coprocess. | |
900 | .PP | |
901 | The format for a coprocess is: | |
902 | .RS | |
903 | .PP | |
904 | \fBcoproc\fP [\fINAME\fP] \fIcommand\fP [\fIredirections\fP] | |
905 | .RE | |
906 | .PP | |
907 | This creates a coprocess named \fINAME\fP. | |
908 | If \fINAME\fP is not supplied, the default name is \fICOPROC\fP. | |
e141c35a CR |
909 | \fINAME\fP must not be supplied if \fIcommand\fP is a \fIsimple |
910 | command\fP (see above); otherwise, it is interpreted as the first word | |
911 | of the simple command. | |
09767ff0 CR |
912 | When the coproc is executed, the shell creates an array variable (see |
913 | .B Arrays | |
914 | below) named \fINAME\fP in the context of the executing shell. | |
915 | The standard output of | |
916 | .I command | |
917 | is connected via a pipe to a file descriptor in the executing shell, | |
918 | and that file descriptor is assigned to \fINAME\fP[0]. | |
919 | The standard input of | |
920 | .I command | |
921 | is connected via a pipe to a file descriptor in the executing shell, | |
922 | and that file descriptor is assigned to \fINAME\fP[1]. | |
923 | This pipe is established before any redirections specified by the | |
924 | command (see | |
925 | .SM | |
926 | .B REDIRECTION | |
927 | below). | |
928 | The file descriptors can be utilized as arguments to shell commands | |
929 | and redirections using standard word expansions. | |
30915f17 CR |
930 | The process id of the shell spawned to execute the coprocess is |
931 | available as the value of the variable \fINAME\fP_PID. | |
932 | The \fBwait\fP | |
933 | builtin command may be used to wait for the coprocess to terminate. | |
09767ff0 CR |
934 | .PP |
935 | The return status of a coprocess is the exit status of \fIcommand\fP. | |
d3a24ed2 CR |
936 | .SS Shell Function Definitions |
937 | .PP | |
938 | A shell function is an object that is called like a simple command and | |
939 | executes a compound command with a new set of positional parameters. | |
940 | Shell functions are declared as follows: | |
941 | .TP | |
942 | [ \fBfunction\fP ] \fIname\fP () \fIcompound\-command\fP [\fIredirection\fP] | |
943 | This defines a function named \fIname\fP. | |
944 | The reserved word \fBfunction\fP is optional. | |
945 | If the \fBfunction\fP reserved word is supplied, the parentheses are optional. | |
946 | The \fIbody\fP of the function is the compound command | |
947 | .I compound\-command | |
948 | (see \fBCompound Commands\fP above). | |
949 | That command is usually a \fIlist\fP of commands between { and }, but | |
950 | may be any command listed under \fBCompound Commands\fP above. | |
951 | \fIcompound\-command\fP is executed whenever \fIname\fP is specified as the | |
952 | name of a simple command. | |
953 | Any redirections (see | |
954 | .SM | |
955 | .B REDIRECTION | |
956 | below) specified when a function is defined are performed | |
957 | when the function is executed. | |
958 | The exit status of a function definition is zero unless a syntax error | |
959 | occurs or a readonly function with the same name already exists. | |
960 | When executed, the exit status of a function is the exit status of the | |
961 | last command executed in the body. (See | |
726f6388 JA |
962 | .SM |
963 | .B FUNCTIONS | |
964 | below.) | |
965 | .SH COMMENTS | |
ccc6cda3 JA |
966 | In a non-interactive shell, or an interactive shell in which the |
967 | .B interactive_comments | |
968 | option to the | |
969 | .B shopt | |
970 | builtin is enabled (see | |
971 | .SM | |
972 | .B "SHELL BUILTIN COMMANDS" | |
973 | below), a word beginning with | |
726f6388 JA |
974 | .B # |
975 | causes that word and all remaining characters on that line to | |
976 | be ignored. An interactive shell without the | |
ccc6cda3 | 977 | .B interactive_comments |
ccc6cda3 JA |
978 | option enabled does not allow comments. The |
979 | .B interactive_comments | |
980 | option is on by default in interactive shells. | |
726f6388 JA |
981 | .SH QUOTING |
982 | \fIQuoting\fP is used to remove the special meaning of certain | |
983 | characters or words to the shell. Quoting can be used to | |
984 | disable special treatment for special characters, to prevent | |
985 | reserved words from being recognized as such, and to prevent | |
986 | parameter expansion. | |
987 | .PP | |
988 | Each of the \fImetacharacters\fP listed above under | |
989 | .SM | |
990 | .B DEFINITIONS | |
bb70624e JA |
991 | has special meaning to the shell and must be quoted if it is to |
992 | represent itself. | |
993 | .PP | |
5c96a638 CR |
994 | When the command history expansion facilities are being used |
995 | (see | |
996 | .SM | |
997 | .B HISTORY EXPANSION | |
998 | below), the | |
bb70624e JA |
999 | \fIhistory expansion\fP character, usually \fB!\fP, must be quoted |
1000 | to prevent history expansion. | |
1001 | .PP | |
1002 | There are three quoting mechanisms: the | |
726f6388 JA |
1003 | .IR "escape character" , |
1004 | single quotes, and double quotes. | |
1005 | .PP | |
1006 | A non-quoted backslash (\fB\e\fP) is the | |
1007 | .IR "escape character" . | |
1008 | It preserves the literal value of the next character that follows, | |
1009 | with the exception of <newline>. If a \fB\e\fP<newline> pair | |
cce855bc JA |
1010 | appears, and the backslash is not itself quoted, the \fB\e\fP<newline> |
1011 | is treated as a line continuation (that is, it is removed from the | |
1012 | input stream and effectively ignored). | |
726f6388 JA |
1013 | .PP |
1014 | Enclosing characters in single quotes preserves the literal value | |
1015 | of each character within the quotes. A single quote may not occur | |
1016 | between single quotes, even when preceded by a backslash. | |
1017 | .PP | |
1018 | Enclosing characters in double quotes preserves the literal value | |
1019 | of all characters within the quotes, with the exception of | |
1020 | .BR $ , | |
3d4e09aa | 1021 | .BR \` , |
5c96a638 CR |
1022 | .BR \e , |
1023 | and, when history expansion is enabled, | |
1024 | .BR ! . | |
726f6388 JA |
1025 | The characters |
1026 | .B $ | |
1027 | and | |
3d4e09aa | 1028 | .B \` |
726f6388 JA |
1029 | retain their special meaning within double quotes. The backslash |
1030 | retains its special meaning only when followed by one of the following | |
1031 | characters: | |
1032 | .BR $ , | |
3d4e09aa | 1033 | .BR \` , |
726f6388 JA |
1034 | \^\fB"\fP\^, |
1035 | .BR \e , | |
1036 | or | |
1037 | .BR <newline> . | |
1038 | A double quote may be quoted within double quotes by preceding it with | |
1039 | a backslash. | |
5c96a638 CR |
1040 | If enabled, history expansion will be performed unless an |
1041 | .B ! | |
1042 | appearing in double quotes is escaped using a backslash. | |
1043 | The backslash preceding the | |
1044 | .B ! | |
1045 | is not removed. | |
726f6388 JA |
1046 | .PP |
1047 | The special parameters | |
1048 | .B * | |
1049 | and | |
1050 | .B @ | |
1051 | have special meaning when in double | |
1052 | quotes (see | |
1053 | .SM | |
1054 | .B PARAMETERS | |
1055 | below). | |
ccc6cda3 | 1056 | .PP |
20587658 | 1057 | Words of the form \fB$\fP\(aq\fIstring\fP\(aq are treated specially. The |
ccc6cda3 | 1058 | word expands to \fIstring\fP, with backslash-escaped characters replaced |
f75912ae | 1059 | as specified by the ANSI C standard. Backslash escape sequences, if |
ccc6cda3 JA |
1060 | present, are decoded as follows: |
1061 | .RS | |
1062 | .PD 0 | |
1063 | .TP | |
1064 | .B \ea | |
1065 | alert (bell) | |
1066 | .TP | |
1067 | .B \eb | |
1068 | backspace | |
1069 | .TP | |
1070 | .B \ee | |
a3143574 CR |
1071 | .TP |
1072 | .B \eE | |
ccc6cda3 JA |
1073 | an escape character |
1074 | .TP | |
1075 | .B \ef | |
1076 | form feed | |
1077 | .TP | |
1078 | .B \en | |
1079 | new line | |
1080 | .TP | |
1081 | .B \er | |
1082 | carriage return | |
1083 | .TP | |
1084 | .B \et | |
1085 | horizontal tab | |
1086 | .TP | |
1087 | .B \ev | |
1088 | vertical tab | |
1089 | .TP | |
1090 | .B \e\e | |
1091 | backslash | |
bb70624e | 1092 | .TP |
20587658 | 1093 | .B \e\(aq |
bb70624e | 1094 | single quote |
a3143574 CR |
1095 | .TP |
1096 | .B \e\(dq | |
1097 | double quote | |
ccc6cda3 JA |
1098 | .TP |
1099 | .B \e\fInnn\fP | |
f73dda09 | 1100 | the eight-bit character whose value is the octal value \fInnn\fP |
cce855bc JA |
1101 | (one to three digits) |
1102 | .TP | |
f73dda09 JA |
1103 | .B \ex\fIHH\fP |
1104 | the eight-bit character whose value is the hexadecimal value \fIHH\fP | |
1105 | (one or two hex digits) | |
7117c2d2 JA |
1106 | .TP |
1107 | .B \ec\fIx\fP | |
1108 | a control-\fIx\fP character | |
ccc6cda3 JA |
1109 | .PD |
1110 | .RE | |
1111 | .LP | |
bb70624e | 1112 | The expanded result is single-quoted, as if the dollar sign had |
ccc6cda3 JA |
1113 | not been present. |
1114 | .PP | |
08e72d7a CR |
1115 | A double-quoted string preceded by a dollar sign (\fB$\fP\(dq\fIstring\fP\(dq) |
1116 | will cause the string to be translated according to the current locale. | |
ccc6cda3 JA |
1117 | If the current locale is \fBC\fP or \fBPOSIX\fP, the dollar sign |
1118 | is ignored. | |
1119 | If the string is translated and replaced, the replacement is | |
1120 | double-quoted. | |
726f6388 JA |
1121 | .SH PARAMETERS |
1122 | A | |
1123 | .I parameter | |
ccc6cda3 JA |
1124 | is an entity that stores values. |
1125 | It can be a | |
726f6388 JA |
1126 | .IR name , |
1127 | a number, or one of the special characters listed below under | |
1128 | .BR "Special Parameters" . | |
d3a24ed2 | 1129 | A |
726f6388 JA |
1130 | .I variable |
1131 | is a parameter denoted by a | |
1132 | .IR name . | |
f73dda09 JA |
1133 | A variable has a \fIvalue\fP and zero or more \fIattributes\fP. |
1134 | Attributes are assigned using the | |
1135 | .B declare | |
1136 | builtin command (see | |
1137 | .B declare | |
1138 | below in | |
1139 | .SM | |
1140 | .BR "SHELL BUILTIN COMMANDS" ). | |
726f6388 JA |
1141 | .PP |
1142 | A parameter is set if it has been assigned a value. The null string is | |
1143 | a valid value. Once a variable is set, it may be unset only by using | |
1144 | the | |
1145 | .B unset | |
1146 | builtin command (see | |
1147 | .SM | |
1148 | .B SHELL BUILTIN COMMANDS | |
1149 | below). | |
1150 | .PP | |
1151 | A | |
1152 | .I variable | |
1153 | may be assigned to by a statement of the form | |
1154 | .RS | |
1155 | .PP | |
1156 | \fIname\fP=[\fIvalue\fP] | |
1157 | .RE | |
1158 | .PP | |
1159 | If | |
1160 | .I value | |
1161 | is not given, the variable is assigned the null string. All | |
1162 | .I values | |
bb70624e JA |
1163 | undergo tilde expansion, parameter and variable expansion, |
1164 | command substitution, arithmetic expansion, and quote | |
ccc6cda3 JA |
1165 | removal (see |
1166 | .SM | |
1167 | .B EXPANSION | |
1168 | below). If the variable has its | |
cce855bc | 1169 | .B integer |
f73dda09 | 1170 | attribute set, then |
726f6388 | 1171 | .I value |
d3a24ed2 | 1172 | is evaluated as an arithmetic expression even if the $((...)) expansion is |
cce855bc | 1173 | not used (see |
ccc6cda3 JA |
1174 | .B "Arithmetic Expansion" |
1175 | below). | |
1176 | Word splitting is not performed, with the exception | |
726f6388 JA |
1177 | of \fB"$@"\fP as explained below under |
1178 | .BR "Special Parameters" . | |
1179 | Pathname expansion is not performed. | |
f73dda09 | 1180 | Assignment statements may also appear as arguments to the |
5e13499c | 1181 | .BR alias , |
f73dda09 JA |
1182 | .BR declare , |
1183 | .BR typeset , | |
1184 | .BR export , | |
1185 | .BR readonly , | |
1186 | and | |
1187 | .B local | |
1188 | builtin commands. | |
d11b8b46 CR |
1189 | .PP |
1190 | In the context where an assignment statement is assigning a value | |
1191 | to a shell variable or array index, the += operator can be used to | |
1192 | append to or add to the variable's previous value. | |
1193 | When += is applied to a variable for which the integer attribute has been | |
1194 | set, \fIvalue\fP is evaluated as an arithmetic expression and added to the | |
1195 | variable's current value, which is also evaluated. | |
1196 | When += is applied to an array variable using compound assignment (see | |
1197 | .B Arrays | |
1198 | below), the | |
1199 | variable's value is not unset (as it is when using =), and new values are | |
fdf670ea CR |
1200 | appended to the array beginning at one greater than the array's maximum index |
1201 | (for indexed arrays) or added as additional key\-value pairs in an | |
1202 | associative array. | |
d11b8b46 CR |
1203 | When applied to a string-valued variable, \fIvalue\fP is expanded and |
1204 | appended to the variable's value. | |
726f6388 JA |
1205 | .SS Positional Parameters |
1206 | .PP | |
1207 | A | |
1208 | .I positional parameter | |
1209 | is a parameter denoted by one or more | |
1210 | digits, other than the single digit 0. Positional parameters are | |
1211 | assigned from the shell's arguments when it is invoked, | |
1212 | and may be reassigned using the | |
1213 | .B set | |
1214 | builtin command. Positional parameters may not be assigned to | |
1215 | with assignment statements. The positional parameters are | |
1216 | temporarily replaced when a shell function is executed (see | |
1217 | .SM | |
1218 | .B FUNCTIONS | |
1219 | below). | |
1220 | .PP | |
1221 | When a positional parameter consisting of more than a single | |
1222 | digit is expanded, it must be enclosed in braces (see | |
1223 | .SM | |
1224 | .B EXPANSION | |
1225 | below). | |
1226 | .SS Special Parameters | |
1227 | .PP | |
1228 | The shell treats several parameters specially. These parameters may | |
1229 | only be referenced; assignment to them is not allowed. | |
1230 | .PD 0 | |
1231 | .TP | |
1232 | .B * | |
1233 | Expands to the positional parameters, starting from one. When the | |
1234 | expansion occurs within double quotes, it expands to a single word | |
1235 | with the value of each parameter separated by the first character | |
1236 | of the | |
1237 | .SM | |
1238 | .B IFS | |
cce855bc JA |
1239 | special variable. That is, "\fB$*\fP" is equivalent |
1240 | to "\fB$1\fP\fIc\fP\fB$2\fP\fIc\fP\fB...\fP", where | |
726f6388 JA |
1241 | .I c |
1242 | is the first character of the value of the | |
1243 | .SM | |
1244 | .B IFS | |
1245 | variable. If | |
1246 | .SM | |
1247 | .B IFS | |
d166f048 JA |
1248 | is unset, the parameters are separated by spaces. |
1249 | If | |
1250 | .SM | |
1251 | .B IFS | |
1252 | is null, the parameters are joined without intervening separators. | |
726f6388 JA |
1253 | .TP |
1254 | .B @ | |
1255 | Expands to the positional parameters, starting from one. When the | |
cce855bc JA |
1256 | expansion occurs within double quotes, each parameter expands to a |
1257 | separate word. That is, "\fB$@\fP" is equivalent to | |
1258 | "\fB$1\fP" "\fB$2\fP" ... | |
be7d8f2d CR |
1259 | If the double-quoted expansion occurs within a word, the expansion of |
1260 | the first parameter is joined with the beginning part of the original | |
1261 | word, and the expansion of the last parameter is joined with the last | |
1262 | part of the original word. | |
cce855bc | 1263 | When there are no positional parameters, "\fB$@\fP" and |
726f6388 JA |
1264 | .B $@ |
1265 | expand to nothing (i.e., they are removed). | |
1266 | .TP | |
1267 | .B # | |
1268 | Expands to the number of positional parameters in decimal. | |
1269 | .TP | |
1270 | .B ? | |
e882163b | 1271 | Expands to the exit status of the most recently executed foreground |
726f6388 JA |
1272 | pipeline. |
1273 | .TP | |
1274 | .B \- | |
1275 | Expands to the current option flags as specified upon invocation, | |
1276 | by the | |
1277 | .B set | |
1278 | builtin command, or those set by the shell itself | |
1279 | (such as the | |
1280 | .B \-i | |
cce855bc | 1281 | option). |
726f6388 JA |
1282 | .TP |
1283 | .B $ | |
1284 | Expands to the process ID of the shell. In a () subshell, it | |
1285 | expands to the process ID of the current shell, not the | |
1286 | subshell. | |
1287 | .TP | |
1288 | .B ! | |
1289 | Expands to the process ID of the most recently executed background | |
1290 | (asynchronous) command. | |
1291 | .TP | |
1292 | .B 0 | |
1293 | Expands to the name of the shell or shell script. This is set at | |
1294 | shell initialization. If | |
1295 | .B bash | |
1296 | is invoked with a file of commands, | |
1297 | .B $0 | |
1298 | is set to the name of that file. If | |
1299 | .B bash | |
1300 | is started with the | |
1301 | .B \-c | |
1302 | option, then | |
1303 | .B $0 | |
1304 | is set to the first argument after the string to be | |
1305 | executed, if one is present. Otherwise, it is set | |
ccc6cda3 | 1306 | to the file name used to invoke |
726f6388 JA |
1307 | .BR bash , |
1308 | as given by argument zero. | |
1309 | .TP | |
1310 | .B _ | |
cc87ba64 CR |
1311 | At shell startup, set to the absolute pathname used to invoke the |
1312 | shell or shell script being executed as passed in the environment | |
1313 | or argument list. | |
ccc6cda3 JA |
1314 | Subsequently, expands to the last argument to the previous command, |
1315 | after expansion. | |
cc87ba64 CR |
1316 | Also set to the full pathname used to invoke each command executed |
1317 | and placed in the environment exported to that command. | |
ccc6cda3 JA |
1318 | When checking mail, this parameter holds the name of the mail file |
1319 | currently being checked. | |
726f6388 JA |
1320 | .PD |
1321 | .SS Shell Variables | |
1322 | .PP | |
1323 | The following variables are set by the shell: | |
1324 | .PP | |
1325 | .PD 0 | |
1326 | .TP | |
726f6388 | 1327 | .B BASH |
ccc6cda3 | 1328 | Expands to the full file name used to invoke this instance of |
726f6388 JA |
1329 | .BR bash . |
1330 | .TP | |
691aebcb CR |
1331 | .B BASHOPTS |
1332 | A colon-separated list of enabled shell options. Each word in | |
1333 | the list is a valid argument for the | |
1334 | .B \-s | |
1335 | option to the | |
1336 | .B shopt | |
1337 | builtin command (see | |
1338 | .SM | |
1339 | .B "SHELL BUILTIN COMMANDS" | |
1340 | below). The options appearing in | |
1341 | .SM | |
1342 | .B BASHOPTS | |
1343 | are those reported as | |
1344 | .I on | |
1345 | by \fBshopt\fP. | |
1346 | If this variable is in the environment when | |
1347 | .B bash | |
1348 | starts up, each shell option in the list will be enabled before | |
1349 | reading any startup files. | |
1350 | This variable is read-only. | |
1351 | .TP | |
d3ad40de | 1352 | .B BASHPID |
29d25b54 | 1353 | Expands to the process id of the current \fBbash\fP process. |
d3ad40de | 1354 | This differs from \fB$$\fP under certain circumstances, such as subshells |
29d25b54 | 1355 | that do not require \fBbash\fP to be re-initialized. |
d3ad40de | 1356 | .TP |
fdf670ea CR |
1357 | .B BASH_ALIASES |
1358 | An associative array variable whose members correspond to the internal | |
5cdaaf76 | 1359 | list of aliases as maintained by the \fBalias\fP builtin. |
fdf670ea CR |
1360 | Elements added to this array appear in the alias list; unsetting array |
1361 | elements cause aliases to be removed from the alias list. | |
1362 | .TP | |
d3a24ed2 CR |
1363 | .B BASH_ARGC |
1364 | An array variable whose values are the number of parameters in each | |
29d25b54 | 1365 | frame of the current \fBbash\fP execution call stack. |
2206f89a | 1366 | The number of |
d3a24ed2 | 1367 | parameters to the current subroutine (shell function or script executed |
2206f89a CR |
1368 | with \fB.\fP or \fBsource\fP) is at the top of the stack. |
1369 | When a subroutine is executed, the number of parameters passed is pushed onto | |
984a1947 CR |
1370 | .SM |
1371 | .BR BASH_ARGC . | |
1372 | The shell sets | |
1373 | .SM | |
1374 | .B BASH_ARGC | |
1375 | only when in extended debugging mode (see the description of the | |
2206f89a CR |
1376 | .B extdebug |
1377 | option to the | |
1378 | .B shopt | |
1379 | builtin below) | |
d3a24ed2 CR |
1380 | .TP |
1381 | .B BASH_ARGV | |
29d25b54 | 1382 | An array variable containing all of the parameters in the current \fBbash\fP |
d3a24ed2 CR |
1383 | execution call stack. The final parameter of the last subroutine call |
1384 | is at the top of the stack; the first parameter of the initial call is | |
1385 | at the bottom. When a subroutine is executed, the parameters supplied | |
984a1947 CR |
1386 | are pushed onto |
1387 | .SM | |
1388 | .BR BASH_ARGV . | |
1389 | The shell sets | |
1390 | .SM | |
1391 | .B BASH_ARGV | |
1392 | only when in extended debugging mode | |
2206f89a CR |
1393 | (see the description of the |
1394 | .B extdebug | |
1395 | option to the | |
1396 | .B shopt | |
1397 | builtin below) | |
d3a24ed2 | 1398 | .TP |
fdf670ea CR |
1399 | .B BASH_CMDS |
1400 | An associative array variable whose members correspond to the internal | |
1401 | hash table of commands as maintained by the \fBhash\fP builtin. | |
1402 | Elements added to this array appear in the hash table; unsetting array | |
1403 | elements cause commands to be removed from the hash table. | |
1404 | .TP | |
d3a24ed2 CR |
1405 | .B BASH_COMMAND |
1406 | The command currently being executed or about to be executed, unless the | |
1407 | shell is executing a command as the result of a trap, | |
1408 | in which case it is the command executing at the time of the trap. | |
1409 | .TP | |
1410 | .B BASH_EXECUTION_STRING | |
1411 | The command argument to the \fB\-c\fP invocation option. | |
1412 | .TP | |
1413 | .B BASH_LINENO | |
1414 | An array variable whose members are the line numbers in source files | |
984a1947 CR |
1415 | corresponding to each member of |
1416 | .SM | |
1417 | .BR FUNCNAME . | |
d3a24ed2 | 1418 | \fB${BASH_LINENO[\fP\fI$i\fP\fB]}\fP is the line number in the source |
3d4e09aa CR |
1419 | file where \fB${FUNCNAME[\fP\fI$i\fP\fB]}\fP was called |
1420 | (or \fB${BASH_LINENO[\fP\fI$i-1\fP\fB]}\fP if referenced within another | |
1421 | shell function). | |
db31fb26 | 1422 | The corresponding source file name is \fB${BASH_SOURCE[\fP\fI$i\fP\fB]}\fP. |
984a1947 CR |
1423 | Use |
1424 | .SM | |
1425 | .B LINENO | |
1426 | to obtain the current line number. | |
d3a24ed2 CR |
1427 | .TP |
1428 | .B BASH_REMATCH | |
1429 | An array variable whose members are assigned by the \fB=~\fP binary | |
1430 | operator to the \fB[[\fP conditional command. | |
1431 | The element with index 0 is the portion of the string | |
1432 | matching the entire regular expression. | |
1433 | The element with index \fIn\fP is the portion of the | |
1434 | string matching the \fIn\fPth parenthesized subexpression. | |
1435 | This variable is read-only. | |
1436 | .TP | |
1437 | .B BASH_SOURCE | |
1438 | An array variable whose members are the source filenames corresponding | |
984a1947 CR |
1439 | to the elements in the |
1440 | .SM | |
1441 | .B FUNCNAME | |
1442 | array variable. | |
d3a24ed2 CR |
1443 | .TP |
1444 | .B BASH_SUBSHELL | |
1445 | Incremented by one each time a subshell or subshell environment is spawned. | |
1446 | The initial value is 0. | |
1447 | .TP | |
ccc6cda3 | 1448 | .B BASH_VERSINFO |
cce855bc JA |
1449 | A readonly array variable whose members hold version information for |
1450 | this instance of | |
ccc6cda3 JA |
1451 | .BR bash . |
1452 | The values assigned to the array members are as follows: | |
1453 | .sp .5 | |
1454 | .RS | |
1455 | .PD 0 | |
1456 | .TP 24 | |
1457 | .B BASH_VERSINFO[\fR0\fP] | |
1458 | The major version number (the \fIrelease\fP). | |
1459 | .TP | |
1460 | .B BASH_VERSINFO[\fR1\fP] | |
1461 | The minor version number (the \fIversion\fP). | |
1462 | .TP | |
1463 | .B BASH_VERSINFO[\fR2\fP] | |
1464 | The patch level. | |
1465 | .TP | |
1466 | .B BASH_VERSINFO[\fR3\fP] | |
1467 | The build version. | |
1468 | .TP | |
1469 | .B BASH_VERSINFO[\fR4\fP] | |
1470 | The release status (e.g., \fIbeta1\fP). | |
1471 | .TP | |
1472 | .B BASH_VERSINFO[\fR5\fP] | |
984a1947 CR |
1473 | The value of |
1474 | .SM | |
1475 | .BR MACHTYPE . | |
ccc6cda3 JA |
1476 | .PD |
1477 | .RE | |
1478 | .TP | |
f73dda09 JA |
1479 | .B BASH_VERSION |
1480 | Expands to a string describing the version of this instance of | |
1481 | .BR bash . | |
726f6388 | 1482 | .TP |
f73dda09 JA |
1483 | .B COMP_CWORD |
1484 | An index into \fB${COMP_WORDS}\fP of the word containing the current | |
1485 | cursor position. | |
1486 | This variable is available only in shell functions invoked by the | |
1487 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1488 | below). | |
1489 | .TP | |
d3ad40de CR |
1490 | .B COMP_KEY |
1491 | The key (or final key of a key sequence) used to invoke the current | |
1492 | completion function. | |
1493 | .TP | |
f73dda09 JA |
1494 | .B COMP_LINE |
1495 | The current command line. | |
1496 | This variable is available only in shell functions and external | |
1497 | commands invoked by the | |
1498 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1499 | below). | |
1500 | .TP | |
1501 | .B COMP_POINT | |
1502 | The index of the current cursor position relative to the beginning of | |
1503 | the current command. | |
1504 | If the current cursor position is at the end of the current command, | |
1505 | the value of this variable is equal to \fB${#COMP_LINE}\fP. | |
1506 | This variable is available only in shell functions and external | |
1507 | commands invoked by the | |
1508 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1509 | below). | |
1510 | .TP | |
d3ad40de CR |
1511 | .B COMP_TYPE |
1512 | Set to an integer value corresponding to the type of completion attempted | |
1513 | that caused a completion function to be called: | |
1514 | \fITAB\fP, for normal completion, | |
1515 | \fI?\fP, for listing completions after successive tabs, | |
1516 | \fI!\fP, for listing alternatives on partial word completion, | |
1517 | \fI@\fP, to list completions if the word is not unmodified, | |
1518 | or | |
1519 | \fI%\fP, for menu completion. | |
1520 | This variable is available only in shell functions and external | |
1521 | commands invoked by the | |
1522 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1523 | below). | |
1524 | .TP | |
d3a24ed2 | 1525 | .B COMP_WORDBREAKS |
db31fb26 | 1526 | The set of characters that the \fBreadline\fP library treats as word |
d3a24ed2 CR |
1527 | separators when performing word completion. |
1528 | If | |
1529 | .SM | |
1530 | .B COMP_WORDBREAKS | |
1531 | is unset, it loses its special properties, even if it is | |
1532 | subsequently reset. | |
1533 | .TP | |
f73dda09 JA |
1534 | .B COMP_WORDS |
1535 | An array variable (see \fBArrays\fP below) consisting of the individual | |
1536 | words in the current command line. | |
db31fb26 | 1537 | The line is split into words as \fBreadline\fP would split it, using |
984a1947 CR |
1538 | .SM |
1539 | .B COMP_WORDBREAKS | |
1540 | as described above. | |
f73dda09 JA |
1541 | This variable is available only in shell functions invoked by the |
1542 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1543 | below). | |
1544 | .TP | |
5cdaaf76 CR |
1545 | .B COPROC |
1546 | An array variable (see \fBArrays\fP below) created to hold the file descriptors | |
1547 | for output from and input to an unnamed coprocess (see \fBCoprocesses\fP | |
1548 | above). | |
1549 | .TP | |
f73dda09 JA |
1550 | .B DIRSTACK |
1551 | An array variable (see | |
1552 | .B Arrays | |
1553 | below) containing the current contents of the directory stack. | |
1554 | Directories appear in the stack in the order they are displayed by the | |
1555 | .B dirs | |
1556 | builtin. | |
1557 | Assigning to members of this array variable may be used to modify | |
1558 | directories already in the stack, but the | |
1559 | .B pushd | |
1560 | and | |
1561 | .B popd | |
1562 | builtins must be used to add and remove directories. | |
1563 | Assignment to this variable will not change the current directory. | |
726f6388 JA |
1564 | If |
1565 | .SM | |
f73dda09 | 1566 | .B DIRSTACK |
726f6388 JA |
1567 | is unset, it loses its special properties, even if it is |
1568 | subsequently reset. | |
1569 | .TP | |
f73dda09 JA |
1570 | .B EUID |
1571 | Expands to the effective user ID of the current user, initialized at | |
1572 | shell startup. This variable is readonly. | |
1573 | .TP | |
1574 | .B FUNCNAME | |
d3a24ed2 CR |
1575 | An array variable containing the names of all shell functions |
1576 | currently in the execution call stack. | |
1577 | The element with index 0 is the name of any currently-executing | |
1578 | shell function. | |
d3ad40de CR |
1579 | The bottom-most element is |
1580 | .if t \f(CW"main"\fP. | |
1581 | .if n "main". | |
f73dda09 JA |
1582 | This variable exists only when a shell function is executing. |
1583 | Assignments to | |
726f6388 | 1584 | .SM |
f73dda09 JA |
1585 | .B FUNCNAME |
1586 | have no effect and return an error status. | |
726f6388 JA |
1587 | If |
1588 | .SM | |
f73dda09 | 1589 | .B FUNCNAME |
726f6388 JA |
1590 | is unset, it loses its special properties, even if it is |
1591 | subsequently reset. | |
1592 | .TP | |
f73dda09 JA |
1593 | .B GROUPS |
1594 | An array variable containing the list of groups of which the current | |
1595 | user is a member. | |
1596 | Assignments to | |
1597 | .SM | |
1598 | .B GROUPS | |
1599 | have no effect and return an error status. | |
726f6388 JA |
1600 | If |
1601 | .SM | |
f73dda09 | 1602 | .B GROUPS |
726f6388 JA |
1603 | is unset, it loses its special properties, even if it is |
1604 | subsequently reset. | |
1605 | .TP | |
1606 | .B HISTCMD | |
1607 | The history number, or index in the history list, of the current | |
ccc6cda3 JA |
1608 | command. |
1609 | If | |
726f6388 JA |
1610 | .SM |
1611 | .B HISTCMD | |
1612 | is unset, it loses its special properties, even if it is | |
1613 | subsequently reset. | |
1614 | .TP | |
f73dda09 JA |
1615 | .B HOSTNAME |
1616 | Automatically set to the name of the current host. | |
bb70624e | 1617 | .TP |
f73dda09 JA |
1618 | .B HOSTTYPE |
1619 | Automatically set to a string that uniquely | |
1620 | describes the type of machine on which | |
1621 | .B bash | |
1622 | is executing. | |
1623 | The default is system-dependent. | |
1624 | .TP | |
1625 | .B LINENO | |
1626 | Each time this parameter is referenced, the shell substitutes | |
1627 | a decimal number representing the current sequential line number | |
1628 | (starting with 1) within a script or function. When not in a | |
1629 | script or function, the value substituted is not guaranteed to | |
1630 | be meaningful. | |
ccc6cda3 JA |
1631 | If |
1632 | .SM | |
f73dda09 | 1633 | .B LINENO |
ccc6cda3 JA |
1634 | is unset, it loses its special properties, even if it is |
1635 | subsequently reset. | |
1636 | .TP | |
f73dda09 JA |
1637 | .B MACHTYPE |
1638 | Automatically set to a string that fully describes the system | |
1639 | type on which | |
1640 | .B bash | |
1641 | is executing, in the standard GNU \fIcpu-company-system\fP format. | |
1642 | The default is system-dependent. | |
1643 | .TP | |
5cdaaf76 CR |
1644 | .B MAPFILE |
1645 | An array variable (see \fBArrays\fP below) created to hold the text | |
1646 | read by the \fBmapfile\fP builtin when no variable name is supplied. | |
1647 | .TP | |
f73dda09 JA |
1648 | .B OLDPWD |
1649 | The previous working directory as set by the | |
1650 | .B cd | |
1651 | command. | |
ccc6cda3 | 1652 | .TP |
726f6388 JA |
1653 | .B OPTARG |
1654 | The value of the last option argument processed by the | |
1655 | .B getopts | |
1656 | builtin command (see | |
1657 | .SM | |
1658 | .B SHELL BUILTIN COMMANDS | |
1659 | below). | |
1660 | .TP | |
1661 | .B OPTIND | |
1662 | The index of the next argument to be processed by the | |
1663 | .B getopts | |
1664 | builtin command (see | |
1665 | .SM | |
1666 | .B SHELL BUILTIN COMMANDS | |
1667 | below). | |
1668 | .TP | |
726f6388 JA |
1669 | .B OSTYPE |
1670 | Automatically set to a string that | |
1671 | describes the operating system on which | |
1672 | .B bash | |
ccc6cda3 JA |
1673 | is executing. |
1674 | The default is system-dependent. | |
1675 | .TP | |
f73dda09 JA |
1676 | .B PIPESTATUS |
1677 | An array variable (see | |
1678 | .B Arrays | |
1679 | below) containing a list of exit status values from the processes | |
1680 | in the most-recently-executed foreground pipeline (which may | |
1681 | contain only a single command). | |
ccc6cda3 | 1682 | .TP |
f73dda09 JA |
1683 | .B PPID |
1684 | The process ID of the shell's parent. This variable is readonly. | |
1685 | .TP | |
1686 | .B PWD | |
1687 | The current working directory as set by the | |
1688 | .B cd | |
1689 | command. | |
1690 | .TP | |
1691 | .B RANDOM | |
1692 | Each time this parameter is referenced, a random integer between | |
1693 | 0 and 32767 is | |
1694 | generated. The sequence of random numbers may be initialized by assigning | |
1695 | a value to | |
1696 | .SM | |
1697 | .BR RANDOM . | |
1698 | If | |
1699 | .SM | |
1700 | .B RANDOM | |
1701 | is unset, it loses its special properties, even if it is | |
1702 | subsequently reset. | |
1703 | .TP | |
5cdaaf76 CR |
1704 | .B READLINE_LINE |
1705 | The contents of the | |
1706 | .B readline | |
1707 | line buffer, for use with | |
1708 | .if t \f(CWbind -x\fP | |
1709 | .if n "bind -x" | |
1710 | (see | |
1711 | .SM | |
1712 | .B "SHELL BUILTIN COMMANDS" | |
1713 | below). | |
1714 | .TP | |
1715 | .B READLINE_POINT | |
1716 | The position of the insertion point in the | |
1717 | .B readline | |
1718 | line buffer, for use with | |
1719 | .if t \f(CWbind -x\fP | |
1720 | .if n "bind -x" | |
1721 | (see | |
1722 | .SM | |
1723 | .B "SHELL BUILTIN COMMANDS" | |
1724 | below). | |
1725 | .TP | |
f73dda09 JA |
1726 | .B REPLY |
1727 | Set to the line of input read by the | |
1728 | .B read | |
1729 | builtin command when no arguments are supplied. | |
1730 | .TP | |
1731 | .B SECONDS | |
1732 | Each time this parameter is | |
1733 | referenced, the number of seconds since shell invocation is returned. If a | |
1734 | value is assigned to | |
1735 | .SM | |
1736 | .BR SECONDS , | |
1737 | the value returned upon subsequent | |
1738 | references is | |
1739 | the number of seconds since the assignment plus the value assigned. | |
1740 | If | |
1741 | .SM | |
1742 | .B SECONDS | |
1743 | is unset, it loses its special properties, even if it is | |
1744 | subsequently reset. | |
1745 | .TP | |
1746 | .B SHELLOPTS | |
1747 | A colon-separated list of enabled shell options. Each word in | |
1748 | the list is a valid argument for the | |
1749 | .B \-o | |
1750 | option to the | |
1751 | .B set | |
1752 | builtin command (see | |
1753 | .SM | |
1754 | .B "SHELL BUILTIN COMMANDS" | |
1755 | below). The options appearing in | |
ccc6cda3 JA |
1756 | .SM |
1757 | .B SHELLOPTS | |
1758 | are those reported as | |
1759 | .I on | |
1760 | by \fBset \-o\fP. | |
1761 | If this variable is in the environment when | |
1762 | .B bash | |
1763 | starts up, each shell option in the list will be enabled before | |
1764 | reading any startup files. | |
1765 | This variable is read-only. | |
bb70624e | 1766 | .TP |
f73dda09 JA |
1767 | .B SHLVL |
1768 | Incremented by one each time an instance of | |
1769 | .B bash | |
1770 | is started. | |
bb70624e | 1771 | .TP |
f73dda09 JA |
1772 | .B UID |
1773 | Expands to the user ID of the current user, initialized at shell startup. | |
1774 | This variable is readonly. | |
726f6388 JA |
1775 | .PD |
1776 | .PP | |
1777 | The following variables are used by the shell. In some cases, | |
1778 | .B bash | |
1779 | assigns a default value to a variable; these cases are noted | |
1780 | below. | |
1781 | .PP | |
1782 | .PD 0 | |
1783 | .TP | |
d166f048 | 1784 | .B BASH_ENV |
726f6388 JA |
1785 | If this parameter is set when \fBbash\fP is executing a shell script, |
1786 | its value is interpreted as a filename containing commands to | |
1787 | initialize the shell, as in | |
cce855bc | 1788 | .IR ~/.bashrc . |
726f6388 JA |
1789 | The value of |
1790 | .SM | |
d166f048 | 1791 | .B BASH_ENV |
726f6388 | 1792 | is subjected to parameter expansion, command substitution, and arithmetic |
ccc6cda3 | 1793 | expansion before being interpreted as a file name. |
726f6388 JA |
1794 | .SM |
1795 | .B PATH | |
ccc6cda3 | 1796 | is not used to search for the resultant file name. |
726f6388 | 1797 | .TP |
8f714a7c CR |
1798 | .B BASH_XTRACEFD |
1799 | If set to an integer corresponding to a valid file descriptor, \fBbash\fP | |
1800 | will write the trace output generated when | |
1801 | .if t \f(CWset -x\fP | |
1802 | .if n \fIset -x\fP | |
1803 | is enabled to that file descriptor. | |
984a1947 CR |
1804 | The file descriptor is closed when |
1805 | .SM | |
1806 | .B BASH_XTRACEFD | |
1807 | is unset or assigned a new value. | |
1808 | Unsetting | |
1809 | .SM | |
1810 | .B BASH_XTRACEFD | |
1811 | or assigning it the empty string causes the | |
8f714a7c | 1812 | trace output to be sent to the standard error. |
984a1947 CR |
1813 | Note that setting |
1814 | .SM | |
1815 | .B BASH_XTRACEFD | |
1816 | to 2 (the standard error file | |
8f714a7c CR |
1817 | descriptor) and then unsetting it will result in the standard error |
1818 | being closed. | |
1819 | .TP | |
5cdaaf76 CR |
1820 | .B CDPATH |
1821 | The search path for the | |
1822 | .B cd | |
1823 | command. | |
1824 | This is a colon-separated list of directories in which the shell looks | |
1825 | for destination directories specified by the | |
1826 | .B cd | |
1827 | command. | |
1828 | A sample value is | |
1829 | .if t \f(CW".:~:/usr"\fP. | |
1830 | .if n ".:~:/usr". | |
1831 | .TP | |
f73dda09 JA |
1832 | .B COLUMNS |
1833 | Used by the \fBselect\fP builtin command to determine the terminal width | |
9c7f20c7 CR |
1834 | when printing selection lists. Automatically set upon receipt of a |
1835 | .SM | |
1836 | .BR SIGWINCH . | |
726f6388 | 1837 | .TP |
f73dda09 JA |
1838 | .B COMPREPLY |
1839 | An array variable from which \fBbash\fP reads the possible completions | |
1840 | generated by a shell function invoked by the programmable completion | |
1841 | facility (see \fBProgrammable Completion\fP below). | |
726f6388 | 1842 | .TP |
d3a24ed2 CR |
1843 | .B EMACS |
1844 | If \fBbash\fP finds this variable in the environment when the shell starts | |
1845 | with value | |
1846 | .if t \f(CWt\fP, | |
1847 | .if n "t", | |
1848 | it assumes that the shell is running in an emacs shell buffer and disables | |
1849 | line editing. | |
1850 | .TP | |
5cdaaf76 CR |
1851 | .B ENV |
1852 | Similar to | |
1853 | .SM | |
1854 | .BR BASH_ENV ; | |
1855 | used when the shell is invoked in POSIX mode. | |
1856 | .TP | |
f73dda09 JA |
1857 | .B FCEDIT |
1858 | The default editor for the | |
1859 | .B fc | |
1860 | builtin command. | |
726f6388 | 1861 | .TP |
f73dda09 JA |
1862 | .B FIGNORE |
1863 | A colon-separated list of suffixes to ignore when performing | |
1864 | filename completion (see | |
726f6388 | 1865 | .SM |
f73dda09 JA |
1866 | .B READLINE |
1867 | below). | |
1868 | A filename whose suffix matches one of the entries in | |
726f6388 | 1869 | .SM |
f73dda09 JA |
1870 | .B FIGNORE |
1871 | is excluded from the list of matched filenames. | |
7117c2d2 JA |
1872 | A sample value is |
1873 | .if t \f(CW".o:~"\fP. | |
1874 | .if n ".o:~". | |
ccc6cda3 | 1875 | .TP |
f73dda09 JA |
1876 | .B GLOBIGNORE |
1877 | A colon-separated list of patterns defining the set of filenames to | |
1878 | be ignored by pathname expansion. | |
1879 | If a filename matched by a pathname expansion pattern also matches one | |
1880 | of the patterns in | |
726f6388 | 1881 | .SM |
f73dda09 JA |
1882 | .BR GLOBIGNORE , |
1883 | it is removed from the list of matches. | |
1884 | .TP | |
1885 | .B HISTCONTROL | |
d3a24ed2 CR |
1886 | A colon-separated list of values controlling how commands are saved on |
1887 | the history list. | |
1888 | If the list of values includes | |
f73dda09 JA |
1889 | .IR ignorespace , |
1890 | lines which begin with a | |
1891 | .B space | |
d3a24ed2 CR |
1892 | character are not saved in the history list. |
1893 | A value of | |
1894 | .I ignoredups | |
1895 | causes lines matching the previous history entry to not be saved. | |
f73dda09 JA |
1896 | A value of |
1897 | .I ignoreboth | |
d3a24ed2 CR |
1898 | is shorthand for \fIignorespace\fP and \fIignoredups\fP. |
1899 | A value of | |
1900 | .IR erasedups | |
1901 | causes all previous lines matching the current line to be removed from | |
1902 | the history list before that line is saved. | |
1903 | Any value not in the above list is ignored. | |
984a1947 CR |
1904 | If |
1905 | .SM | |
1906 | .B HISTCONTROL | |
1907 | is unset, or does not include a valid value, | |
d3a24ed2 CR |
1908 | all lines read by the shell parser are saved on the history list, |
1909 | subject to the value of | |
984a1947 | 1910 | .SM |
f73dda09 JA |
1911 | .BR HISTIGNORE . |
1912 | The second and subsequent lines of a multi-line compound command are | |
1913 | not tested, and are added to the history regardless of the value of | |
984a1947 | 1914 | .SM |
f73dda09 | 1915 | .BR HISTCONTROL . |
726f6388 JA |
1916 | .TP |
1917 | .B HISTFILE | |
ccc6cda3 | 1918 | The name of the file in which command history is saved (see |
726f6388 JA |
1919 | .SM |
1920 | .B HISTORY | |
ccc6cda3 | 1921 | below). The default value is \fI~/.bash_history\fP. If unset, the |
726f6388 JA |
1922 | command history is not saved when an interactive shell exits. |
1923 | .TP | |
1924 | .B HISTFILESIZE | |
1925 | The maximum number of lines contained in the history file. When this | |
1926 | variable is assigned a value, the history file is truncated, if | |
d3ad40de CR |
1927 | necessary, by removing the oldest entries, |
1928 | to contain no more than that number of lines. The default | |
ccc6cda3 JA |
1929 | value is 500. The history file is also truncated to this size after |
1930 | writing it when an interactive shell exits. | |
726f6388 | 1931 | .TP |
f73dda09 JA |
1932 | .B HISTIGNORE |
1933 | A colon-separated list of patterns used to decide which command lines | |
1934 | should be saved on the history list. Each pattern is anchored at the | |
1935 | beginning of the line and must match the complete line (no implicit | |
1936 | `\fB*\fP' is appended). Each pattern is tested against the line | |
1937 | after the checks specified by | |
984a1947 | 1938 | .SM |
f73dda09 JA |
1939 | .B HISTCONTROL |
1940 | are applied. | |
1941 | In addition to the normal shell pattern matching characters, `\fB&\fP' | |
1942 | matches the previous history line. `\fB&\fP' may be escaped using a | |
1943 | backslash; the backslash is removed before attempting a match. | |
1944 | The second and subsequent lines of a multi-line compound command are | |
1945 | not tested, and are added to the history regardless of the value of | |
984a1947 | 1946 | .SM |
f73dda09 JA |
1947 | .BR HISTIGNORE . |
1948 | .TP | |
1949 | .B HISTSIZE | |
1950 | The number of commands to remember in the command history (see | |
1951 | .SM | |
1952 | .B HISTORY | |
1953 | below). The default value is 500. | |
1954 | .TP | |
d3a24ed2 CR |
1955 | .B HISTTIMEFORMAT |
1956 | If this variable is set and not null, its value is used as a format string | |
1957 | for \fIstrftime\fP(3) to print the time stamp associated with each history | |
1958 | entry displayed by the \fBhistory\fP builtin. | |
1959 | If this variable is set, time stamps are written to the history file so | |
1960 | they may be preserved across shell sessions. | |
d3ad40de CR |
1961 | This uses the history comment character to distinguish timestamps from |
1962 | other history lines. | |
d3a24ed2 | 1963 | .TP |
f73dda09 JA |
1964 | .B HOME |
1965 | The home directory of the current user; the default argument for the | |
1966 | \fBcd\fP builtin command. | |
1967 | The value of this variable is also used when performing tilde expansion. | |
1968 | .TP | |
1969 | .B HOSTFILE | |
1970 | Contains the name of a file in the same format as | |
1971 | .FN /etc/hosts | |
1972 | that should be read when the shell needs to complete a | |
1973 | hostname. | |
1974 | The list of possible hostname completions may be changed while the | |
1975 | shell is running; | |
1976 | the next time hostname completion is attempted after the | |
1977 | value is changed, | |
726f6388 | 1978 | .B bash |
f73dda09 JA |
1979 | adds the contents of the new file to the existing list. |
1980 | If | |
726f6388 | 1981 | .SM |
f73dda09 | 1982 | .B HOSTFILE |
9dd88db7 CR |
1983 | is set, but has no value, or does not name a readable file, |
1984 | \fBbash\fP attempts to read | |
f73dda09 JA |
1985 | .FN /etc/hosts |
1986 | to obtain the list of possible hostname completions. | |
1987 | When | |
726f6388 | 1988 | .SM |
f73dda09 JA |
1989 | .B HOSTFILE |
1990 | is unset, the hostname list is cleared. | |
1991 | .TP | |
1992 | .B IFS | |
1993 | The | |
1994 | .I Internal Field Separator | |
1995 | that is used | |
1996 | for word splitting after expansion and to | |
1997 | split lines into words with the | |
1998 | .B read | |
1999 | builtin command. The default value is | |
2000 | ``<space><tab><newline>''. | |
2001 | .TP | |
2002 | .B IGNOREEOF | |
2003 | Controls the | |
2004 | action of an interactive shell on receipt of an | |
2005 | .SM | |
2006 | .B EOF | |
2007 | character as the sole input. If set, the value is the number of | |
2008 | consecutive | |
2009 | .SM | |
2010 | .B EOF | |
2011 | characters which must be | |
2012 | typed as the first characters on an input line before | |
2013 | .B bash | |
2014 | exits. If the variable exists but does not have a numeric value, or | |
2015 | has no value, the default value is 10. If it does not exist, | |
2016 | .SM | |
2017 | .B EOF | |
2018 | signifies the end of input to the shell. | |
2019 | .TP | |
2020 | .B INPUTRC | |
2021 | The filename for the | |
2022 | .B readline | |
2023 | startup file, overriding the default of | |
2024 | .FN ~/.inputrc | |
2025 | (see | |
2026 | .SM | |
2027 | .B READLINE | |
2028 | below). | |
726f6388 | 2029 | .TP |
ccc6cda3 JA |
2030 | .B LANG |
2031 | Used to determine the locale category for any category not specifically | |
2032 | selected with a variable starting with \fBLC_\fP. | |
2033 | .TP | |
2034 | .B LC_ALL | |
984a1947 CR |
2035 | This variable overrides the value of |
2036 | .SM | |
2037 | .B LANG | |
2038 | and any other | |
ccc6cda3 JA |
2039 | \fBLC_\fP variable specifying a locale category. |
2040 | .TP | |
2041 | .B LC_COLLATE | |
2042 | This variable determines the collation order used when sorting the | |
cce855bc JA |
2043 | results of pathname expansion, and determines the behavior of range |
2044 | expressions, equivalence classes, and collating sequences within | |
2045 | pathname expansion and pattern matching. | |
2046 | .TP | |
2047 | .B LC_CTYPE | |
2048 | This variable determines the interpretation of characters and the | |
2049 | behavior of character classes within pathname expansion and pattern | |
2050 | matching. | |
ccc6cda3 JA |
2051 | .TP |
2052 | .B LC_MESSAGES | |
2053 | This variable determines the locale used to translate double-quoted | |
2054 | strings preceded by a \fB$\fP. | |
2055 | .TP | |
bb70624e JA |
2056 | .B LC_NUMERIC |
2057 | This variable determines the locale category used for number formatting. | |
2058 | .TP | |
28ef6c31 JA |
2059 | .B LINES |
2060 | Used by the \fBselect\fP builtin command to determine the column length | |
984a1947 CR |
2061 | for printing selection lists. Automatically set upon receipt of a |
2062 | .SM | |
2063 | .BR SIGWINCH . | |
28ef6c31 | 2064 | .TP |
f73dda09 JA |
2065 | .B MAIL |
2066 | If this parameter is set to a file name and the | |
726f6388 | 2067 | .SM |
f73dda09 JA |
2068 | .B MAILPATH |
2069 | variable is not set, | |
726f6388 | 2070 | .B bash |
f73dda09 | 2071 | informs the user of the arrival of mail in the specified file. |
726f6388 | 2072 | .TP |
f73dda09 JA |
2073 | .B MAILCHECK |
2074 | Specifies how | |
2075 | often (in seconds) | |
2076 | .B bash | |
2077 | checks for mail. The default is 60 seconds. When it is time to check | |
2078 | for mail, the shell does so before displaying the primary prompt. | |
2079 | If this variable is unset, or set to a value that is not a number | |
2080 | greater than or equal to zero, the shell disables mail checking. | |
726f6388 | 2081 | .TP |
f73dda09 JA |
2082 | .B MAILPATH |
2083 | A colon-separated list of file names to be checked for mail. | |
2084 | The message to be printed when mail arrives in a particular file | |
2085 | may be specified by separating the file name from the message with a `?'. | |
2086 | When used in the text of the message, \fB$_\fP expands to the name of | |
2087 | the current mailfile. | |
2088 | Example: | |
2089 | .RS | |
2090 | .PP | |
20587658 | 2091 | \fBMAILPATH\fP=\(aq/var/mail/bfox?"You have mail":~/shell\-mail?"$_ has mail!"\(aq |
f73dda09 JA |
2092 | .PP |
2093 | .B Bash | |
2094 | supplies a default value for this variable, but the location of the user | |
2095 | mail files that it uses is system dependent (e.g., /var/mail/\fB$USER\fP). | |
2096 | .RE | |
726f6388 | 2097 | .TP |
f73dda09 JA |
2098 | .B OPTERR |
2099 | If set to the value 1, | |
2100 | .B bash | |
2101 | displays error messages generated by the | |
2102 | .B getopts | |
2103 | builtin command (see | |
726f6388 | 2104 | .SM |
f73dda09 | 2105 | .B SHELL BUILTIN COMMANDS |
ccc6cda3 | 2106 | below). |
726f6388 | 2107 | .SM |
f73dda09 JA |
2108 | .B OPTERR |
2109 | is initialized to 1 each time the shell is invoked or a shell | |
2110 | script is executed. | |
ccc6cda3 | 2111 | .TP |
f73dda09 JA |
2112 | .B PATH |
2113 | The search path for commands. It | |
2114 | is a colon-separated list of directories in which | |
2115 | the shell looks for commands (see | |
ccc6cda3 | 2116 | .SM |
f73dda09 | 2117 | .B COMMAND EXECUTION |
d3a24ed2 | 2118 | below). |
984a1947 CR |
2119 | A zero-length (null) directory name in the value of |
2120 | .SM | |
2121 | .B PATH | |
2122 | indicates the current directory. | |
d3a24ed2 CR |
2123 | A null directory name may appear as two adjacent colons, or as an initial |
2124 | or trailing colon. | |
2125 | The default path is system-dependent, | |
f73dda09 JA |
2126 | and is set by the administrator who installs |
2127 | .BR bash . | |
2128 | A common value is | |
5e13499c CR |
2129 | .if t \f(CW/usr/gnu/bin:/usr/local/bin:/usr/ucb:/bin:/usr/bin\fP. |
2130 | .if n ``/usr/gnu/bin:/usr/local/bin:/usr/ucb:/bin:/usr/bin''. | |
726f6388 | 2131 | .TP |
f73dda09 JA |
2132 | .B POSIXLY_CORRECT |
2133 | If this variable is in the environment when \fBbash\fP starts, the shell | |
2134 | enters \fIposix mode\fP before reading the startup files, as if the | |
2135 | .B \-\-posix | |
2136 | invocation option had been supplied. If it is set while the shell is | |
2137 | running, \fBbash\fP enables \fIposix mode\fP, as if the command | |
2138 | .if t \f(CWset -o posix\fP | |
2139 | .if n \fIset -o posix\fP | |
2140 | had been executed. | |
726f6388 | 2141 | .TP |
f73dda09 JA |
2142 | .B PROMPT_COMMAND |
2143 | If set, the value is executed as a command prior to issuing each primary | |
2144 | prompt. | |
ccc6cda3 | 2145 | .TP |
ed35cb4a CR |
2146 | .B PROMPT_DIRTRIM |
2147 | If set to a number greater than zero, the value is used as the number of | |
d0ca3503 | 2148 | trailing directory components to retain when expanding the \fB\ew\fP and |
ed35cb4a CR |
2149 | \fB\eW\fP prompt string escapes (see |
2150 | .SM | |
2151 | .B PROMPTING | |
2152 | below). Characters removed are replaced with an ellipsis. | |
2153 | .TP | |
f73dda09 JA |
2154 | .B PS1 |
2155 | The value of this parameter is expanded (see | |
2156 | .SM | |
2157 | .B PROMPTING | |
2158 | below) and used as the primary prompt string. The default value is | |
2159 | ``\fB\es\-\ev\e$ \fP''. | |
726f6388 | 2160 | .TP |
f73dda09 JA |
2161 | .B PS2 |
2162 | The value of this parameter is expanded as with | |
984a1947 | 2163 | .SM |
f73dda09 JA |
2164 | .B PS1 |
2165 | and used as the secondary prompt string. The default is | |
2166 | ``\fB> \fP''. | |
2167 | .TP | |
2168 | .B PS3 | |
2169 | The value of this parameter is used as the prompt for the | |
2170 | .B select | |
2171 | command (see | |
726f6388 | 2172 | .SM |
f73dda09 JA |
2173 | .B SHELL GRAMMAR |
2174 | above). | |
726f6388 | 2175 | .TP |
f73dda09 JA |
2176 | .B PS4 |
2177 | The value of this parameter is expanded as with | |
984a1947 | 2178 | .SM |
f73dda09 JA |
2179 | .B PS1 |
2180 | and the value is printed before each command | |
726f6388 | 2181 | .B bash |
f73dda09 | 2182 | displays during an execution trace. The first character of |
bb70624e | 2183 | .SM |
f73dda09 JA |
2184 | .B PS4 |
2185 | is replicated multiple times, as necessary, to indicate multiple | |
2186 | levels of indirection. The default is ``\fB+ \fP''. | |
2187 | .TP | |
61deeb13 CR |
2188 | .B SHELL |
2189 | The full pathname to the shell is kept in this environment variable. | |
2190 | If it is not set when the shell starts, | |
2191 | .B bash | |
2192 | assigns to it the full pathname of the current user's login shell. | |
2193 | .TP | |
f73dda09 JA |
2194 | .B TIMEFORMAT |
2195 | The value of this parameter is used as a format string specifying | |
2196 | how the timing information for pipelines prefixed with the | |
2197 | .B time | |
2198 | reserved word should be displayed. | |
2199 | The \fB%\fP character introduces an escape sequence that is | |
2200 | expanded to a time value or other information. | |
2201 | The escape sequences and their meanings are as follows; the | |
2202 | braces denote optional portions. | |
2203 | .sp .5 | |
2204 | .RS | |
2205 | .PD 0 | |
2206 | .TP 10 | |
2207 | .B %% | |
2208 | A literal \fB%\fP. | |
2209 | .TP | |
2210 | .B %[\fIp\fP][l]R | |
2211 | The elapsed time in seconds. | |
2212 | .TP | |
2213 | .B %[\fIp\fP][l]U | |
2214 | The number of CPU seconds spent in user mode. | |
2215 | .TP | |
2216 | .B %[\fIp\fP][l]S | |
2217 | The number of CPU seconds spent in system mode. | |
2218 | .TP | |
2219 | .B %P | |
2220 | The CPU percentage, computed as (%U + %S) / %R. | |
2221 | .PD | |
2222 | .RE | |
2223 | .IP | |
2224 | The optional \fIp\fP is a digit specifying the \fIprecision\fP, | |
2225 | the number of fractional digits after a decimal point. | |
2226 | A value of 0 causes no decimal point or fraction to be output. | |
2227 | At most three places after the decimal point may be specified; | |
2228 | values of \fIp\fP greater than 3 are changed to 3. | |
2229 | If \fIp\fP is not specified, the value 3 is used. | |
2230 | .IP | |
2231 | The optional \fBl\fP specifies a longer format, including | |
2232 | minutes, of the form \fIMM\fPm\fISS\fP.\fIFF\fPs. | |
2233 | The value of \fIp\fP determines whether or not the fraction is | |
2234 | included. | |
2235 | .IP | |
2236 | If this variable is not set, \fBbash\fP acts as if it had the | |
20587658 | 2237 | value \fB$\(aq\enreal\et%3lR\enuser\et%3lU\ensys\t%3lS\(aq\fP. |
f73dda09 JA |
2238 | If the value is null, no timing information is displayed. |
2239 | A trailing newline is added when the format string is displayed. | |
2240 | .TP | |
2241 | .B TMOUT | |
984a1947 CR |
2242 | If set to a value greater than zero, |
2243 | .SM | |
2244 | .B TMOUT | |
2245 | is treated as the | |
7117c2d2 JA |
2246 | default timeout for the \fBread\fP builtin. |
2247 | The \fBselect\fP command terminates if input does not arrive | |
984a1947 CR |
2248 | after |
2249 | .SM | |
2250 | .B TMOUT | |
2251 | seconds when input is coming from a terminal. | |
7117c2d2 | 2252 | In an interactive shell, the value is interpreted as the |
f73dda09 JA |
2253 | number of seconds to wait for input after issuing the primary prompt. |
2254 | .B Bash | |
2255 | terminates after waiting for that number of seconds if input does | |
2256 | not arrive. | |
726f6388 | 2257 | .TP |
1569c106 CR |
2258 | .B TMPDIR |
2259 | If set, \fBBash\fP uses its value as the name of a directory in which | |
2260 | \fBBash\fP creates temporary files for the shell's use. | |
2261 | .TP | |
726f6388 JA |
2262 | .B auto_resume |
2263 | This variable controls how the shell interacts with the user and | |
2264 | job control. If this variable is set, single word simple | |
2265 | commands without redirections are treated as candidates for resumption | |
2266 | of an existing stopped job. There is no ambiguity allowed; if there is | |
2267 | more than one job beginning with the string typed, the job most recently | |
2268 | accessed is selected. The | |
2269 | .I name | |
2270 | of a stopped job, in this context, is the command line used to | |
2271 | start it. | |
2272 | If set to the value | |
2273 | .IR exact , | |
2274 | the string supplied must match the name of a stopped job exactly; | |
2275 | if set to | |
2276 | .IR substring , | |
2277 | the string supplied needs to match a substring of the name of a | |
2278 | stopped job. The | |
2279 | .I substring | |
2280 | value provides functionality analogous to the | |
2281 | .B %? | |
ccc6cda3 | 2282 | job identifier (see |
726f6388 JA |
2283 | .SM |
2284 | .B JOB CONTROL | |
2285 | below). If set to any other value, the supplied string must | |
2286 | be a prefix of a stopped job's name; this provides functionality | |
22e63b05 | 2287 | analogous to the \fB%\fP\fIstring\fP job identifier. |
bb70624e | 2288 | .TP |
f73dda09 JA |
2289 | .B histchars |
2290 | The two or three characters which control history expansion | |
2291 | and tokenization (see | |
2292 | .SM | |
2293 | .B HISTORY EXPANSION | |
2294 | below). The first character is the \fIhistory expansion\fP character, | |
2295 | the character which signals the start of a history | |
2296 | expansion, normally `\fB!\fP'. | |
2297 | The second character is the \fIquick substitution\fP | |
2298 | character, which is used as shorthand for re-running the previous | |
2299 | command entered, substituting one string for another in the command. | |
2300 | The default is `\fB^\fP'. | |
2301 | The optional third character is the character | |
2302 | which indicates that the remainder of the line is a comment when found | |
2303 | as the first character of a word, normally `\fB#\fP'. The history | |
2304 | comment character causes history substitution to be skipped for the | |
2305 | remaining words on the line. It does not necessarily cause the shell | |
2306 | parser to treat the rest of the line as a comment. | |
726f6388 | 2307 | .PD |
ccc6cda3 JA |
2308 | .SS Arrays |
2309 | .B Bash | |
fdf670ea | 2310 | provides one-dimensional indexed and associative array variables. |
09767ff0 | 2311 | Any variable may be used as an indexed array; the |
ccc6cda3 | 2312 | .B declare |
fdf670ea CR |
2313 | builtin will explicitly declare an array. |
2314 | There is no maximum | |
ccc6cda3 | 2315 | limit on the size of an array, nor any requirement that members |
fdf670ea CR |
2316 | be indexed or assigned contiguously. |
2317 | Indexed arrays are referenced using integers (including arithmetic | |
09767ff0 CR |
2318 | expressions) and are zero-based; associative arrays are referenced |
2319 | using arbitrary strings. | |
ccc6cda3 | 2320 | .PP |
fdf670ea CR |
2321 | An indexed array is created automatically if any variable is assigned to |
2322 | using the syntax \fIname\fP[\fIsubscript\fP]=\fIvalue\fP. The | |
ccc6cda3 JA |
2323 | .I subscript |
2324 | is treated as an arithmetic expression that must evaluate to a number | |
fdf670ea CR |
2325 | greater than or equal to zero. To explicitly declare an indexed array, |
2326 | use | |
ccc6cda3 JA |
2327 | .B declare \-a \fIname\fP |
2328 | (see | |
2329 | .SM | |
2330 | .B SHELL BUILTIN COMMANDS | |
2331 | below). | |
2332 | .B declare \-a \fIname\fP[\fIsubscript\fP] | |
09767ff0 CR |
2333 | is also accepted; the \fIsubscript\fP is ignored. |
2334 | .PP | |
2335 | Associative arrays are created using | |
2336 | .BR "declare \-A \fIname\fP" . | |
2337 | .PP | |
2338 | Attributes may be | |
ccc6cda3 JA |
2339 | specified for an array variable using the |
2340 | .B declare | |
2341 | and | |
2342 | .B readonly | |
2343 | builtins. Each attribute applies to all members of an array. | |
2344 | .PP | |
2345 | Arrays are assigned to using compound assignments of the form | |
2346 | \fIname\fP=\fB(\fPvalue\fI1\fP ... value\fIn\fP\fB)\fP, where each | |
09767ff0 CR |
2347 | \fIvalue\fP is of the form [\fIsubscript\fP]=\fIstring\fP. |
2348 | Indexed array assignments do not require the bracket and subscript. | |
2349 | When assigning to indexed arrays, if the optional brackets and subscript | |
2350 | are supplied, that index is assigned to; | |
ccc6cda3 JA |
2351 | otherwise the index of the element assigned is the last index assigned |
2352 | to by the statement plus one. Indexing starts at zero. | |
fdf670ea CR |
2353 | .PP |
2354 | When assigning to an associative array, the subscript is required. | |
2355 | .PP | |
ccc6cda3 JA |
2356 | This syntax is also accepted by the |
2357 | .B declare | |
2358 | builtin. Individual array elements may be assigned to using the | |
2359 | \fIname\fP[\fIsubscript\fP]=\fIvalue\fP syntax introduced above. | |
2360 | .PP | |
2361 | Any element of an array may be referenced using | |
2362 | ${\fIname\fP[\fIsubscript\fP]}. The braces are required to avoid | |
2363 | conflicts with pathname expansion. If | |
2364 | \fIsubscript\fP is \fB@\fP or \fB*\fP, the word expands to | |
2365 | all members of \fIname\fP. These subscripts differ only when the | |
2366 | word appears within double quotes. If the word is double-quoted, | |
2367 | ${\fIname\fP[*]} expands to a single | |
2368 | word with the value of each array member separated by the first | |
2369 | character of the | |
2370 | .SM | |
2371 | .B IFS | |
2372 | special variable, and ${\fIname\fP[@]} expands each element of | |
2373 | \fIname\fP to a separate word. When there are no array members, | |
be7d8f2d CR |
2374 | ${\fIname\fP[@]} expands to nothing. |
2375 | If the double-quoted expansion occurs within a word, the expansion of | |
2376 | the first parameter is joined with the beginning part of the original | |
2377 | word, and the expansion of the last parameter is joined with the last | |
2378 | part of the original word. | |
2379 | This is analogous to the expansion | |
ccc6cda3 JA |
2380 | of the special parameters \fB*\fP and \fB@\fP (see |
2381 | .B Special Parameters | |
2382 | above). ${#\fIname\fP[\fIsubscript\fP]} expands to the length of | |
2383 | ${\fIname\fP[\fIsubscript\fP]}. If \fIsubscript\fP is \fB*\fP or | |
2384 | \fB@\fP, the expansion is the number of elements in the array. | |
2385 | Referencing an array variable without a subscript is equivalent to | |
fdf670ea | 2386 | referencing the array with a subscript of 0. |
ccc6cda3 | 2387 | .PP |
94a5513e CR |
2388 | An array variable is considered set if a subscript has been assigned a |
2389 | value. The null string is a valid value. | |
2390 | .PP | |
ccc6cda3 JA |
2391 | The |
2392 | .B unset | |
bb70624e | 2393 | builtin is used to destroy arrays. \fBunset\fP \fIname\fP[\fIsubscript\fP] |
ccc6cda3 | 2394 | destroys the array element at index \fIsubscript\fP. |
d0ca3503 CR |
2395 | Care must be taken to avoid unwanted side effects caused by pathname |
2396 | expansion. | |
ccc6cda3 JA |
2397 | \fBunset\fP \fIname\fP, where \fIname\fP is an array, or |
2398 | \fBunset\fP \fIname\fP[\fIsubscript\fP], where | |
2399 | \fIsubscript\fP is \fB*\fP or \fB@\fP, removes the entire array. | |
2400 | .PP | |
2401 | The | |
2402 | .BR declare , | |
2403 | .BR local , | |
2404 | and | |
2405 | .B readonly | |
2406 | builtins each accept a | |
2407 | .B \-a | |
fdf670ea CR |
2408 | option to specify an indexed array and a |
2409 | .B \-A | |
2410 | option to specify an associative array. | |
2411 | The | |
ccc6cda3 JA |
2412 | .B read |
2413 | builtin accepts a | |
2414 | .B \-a | |
2415 | option to assign a list of words read from the standard input | |
2416 | to an array. The | |
2417 | .B set | |
2418 | and | |
2419 | .B declare | |
2420 | builtins display array values in a way that allows them to be | |
2421 | reused as assignments. | |
726f6388 JA |
2422 | .SH EXPANSION |
2423 | Expansion is performed on the command line after it has been split into | |
2424 | words. There are seven kinds of expansion performed: | |
2425 | .IR "brace expansion" , | |
2426 | .IR "tilde expansion" , | |
2427 | .IR "parameter and variable expansion" , | |
2428 | .IR "command substitution" , | |
2429 | .IR "arithmetic expansion" , | |
2430 | .IR "word splitting" , | |
2431 | and | |
2432 | .IR "pathname expansion" . | |
2433 | .PP | |
2434 | The order of expansions is: brace expansion, tilde expansion, | |
ccc6cda3 JA |
2435 | parameter, variable and arithmetic expansion and |
2436 | command substitution | |
2437 | (done in a left-to-right fashion), word splitting, and pathname | |
726f6388 JA |
2438 | expansion. |
2439 | .PP | |
2440 | On systems that can support it, there is an additional expansion | |
2441 | available: \fIprocess substitution\fP. | |
2442 | .PP | |
2443 | Only brace expansion, word splitting, and pathname expansion | |
2444 | can change the number of words of the expansion; other expansions | |
2445 | expand a single word to a single word. | |
ccc6cda3 | 2446 | The only exceptions to this are the expansions of |
cce855bc | 2447 | "\fB$@\fP" and "\fB${\fP\fIname\fP\fB[@]}\fP" |
ccc6cda3 | 2448 | as explained above (see |
726f6388 JA |
2449 | .SM |
2450 | .BR PARAMETERS ). | |
2451 | .SS Brace Expansion | |
2452 | .PP | |
2453 | .I "Brace expansion" | |
2454 | is a mechanism by which arbitrary strings | |
2455 | may be generated. This mechanism is similar to | |
2456 | \fIpathname expansion\fP, but the filenames generated | |
2457 | need not exist. Patterns to be brace expanded take | |
2458 | the form of an optional | |
2459 | .IR preamble , | |
d3a24ed2 CR |
2460 | followed by either a series of comma-separated strings or |
2461 | a sequence expression between a pair of braces, followed by | |
2462 | an optional | |
cce855bc | 2463 | .IR postscript . |
ccc6cda3 | 2464 | The preamble is prefixed to each string contained |
cce855bc | 2465 | within the braces, and the postscript is then appended |
726f6388 JA |
2466 | to each resulting string, expanding left to right. |
2467 | .PP | |
2468 | Brace expansions may be nested. The results of each expanded | |
2469 | string are not sorted; left to right order is preserved. | |
2470 | For example, a\fB{\fPd,c,b\fB}\fPe expands into `ade ace abe'. | |
2471 | .PP | |
8943768b | 2472 | A sequence expression takes the form |
36211029 | 2473 | \fB{\fP\fIx\fP\fB..\fP\fIy\fP\fB[..\fP\fIincr\fP\fB]}\fP, |
8943768b CR |
2474 | where \fIx\fP and \fIy\fP are either integers or single characters, |
2475 | and \fIincr\fP, an optional increment, is an integer. | |
d3a24ed2 CR |
2476 | When integers are supplied, the expression expands to each number between |
2477 | \fIx\fP and \fIy\fP, inclusive. | |
8943768b CR |
2478 | Supplied integers may be prefixed with \fI0\fP to force each term to have the |
2479 | same width. When either \fIx\fP or \fPy\fP begins with a zero, the shell | |
2480 | attempts to force all generated terms to contain the same number of digits, | |
2481 | zero-padding where necessary. | |
d3a24ed2 CR |
2482 | When characters are supplied, the expression expands to each character |
2483 | lexicographically between \fIx\fP and \fIy\fP, inclusive. Note that | |
2484 | both \fIx\fP and \fIy\fP must be of the same type. | |
8943768b CR |
2485 | When the increment is supplied, it is used as the difference between |
2486 | each term. The default increment is 1 or -1 as appropriate. | |
d3a24ed2 | 2487 | .PP |
726f6388 JA |
2488 | Brace expansion is performed before any other expansions, |
2489 | and any characters special to other expansions are preserved | |
2490 | in the result. It is strictly textual. | |
2491 | .B Bash | |
2492 | does not apply any syntactic interpretation to the context of the | |
2493 | expansion or the text between the braces. | |
2494 | .PP | |
2495 | A correctly-formed brace expansion must contain unquoted opening | |
d3a24ed2 CR |
2496 | and closing braces, and at least one unquoted comma or a valid |
2497 | sequence expression. | |
726f6388 | 2498 | Any incorrectly formed brace expansion is left unchanged. |
ccc6cda3 JA |
2499 | A \fB{\fP or \fB,\fP may be quoted with a backslash to prevent its |
2500 | being considered part of a brace expression. | |
bb70624e JA |
2501 | To avoid conflicts with parameter expansion, the string \fB${\fP |
2502 | is not considered eligible for brace expansion. | |
726f6388 JA |
2503 | .PP |
2504 | This construct is typically used as shorthand when the common | |
2505 | prefix of the strings to be generated is longer than in the | |
2506 | above example: | |
2507 | .RS | |
2508 | .PP | |
2509 | mkdir /usr/local/src/bash/{old,new,dist,bugs} | |
2510 | .RE | |
2511 | or | |
2512 | .RS | |
2513 | chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}} | |
2514 | .RE | |
2515 | .PP | |
2516 | Brace expansion introduces a slight incompatibility with | |
ccc6cda3 JA |
2517 | historical versions of |
2518 | .BR sh . | |
726f6388 JA |
2519 | .B sh |
2520 | does not treat opening or closing braces specially when they | |
2521 | appear as part of a word, and preserves them in the output. | |
2522 | .B Bash | |
2523 | removes braces from words as a consequence of brace | |
2524 | expansion. For example, a word entered to | |
2525 | .B sh | |
2526 | as \fIfile{1,2}\fP | |
2527 | appears identically in the output. The same word is | |
2528 | output as | |
2529 | .I file1 file2 | |
2530 | after expansion by | |
2531 | .BR bash . | |
2532 | If strict compatibility with | |
2533 | .B sh | |
2534 | is desired, start | |
2535 | .B bash | |
2536 | with the | |
ccc6cda3 JA |
2537 | .B +B |
2538 | option or disable brace expansion with the | |
2539 | .B +B | |
726f6388 JA |
2540 | option to the |
2541 | .B set | |
2542 | command (see | |
2543 | .SM | |
2544 | .B SHELL BUILTIN COMMANDS | |
2545 | below). | |
2546 | .SS Tilde Expansion | |
2547 | .PP | |
cce855bc JA |
2548 | If a word begins with an unquoted tilde character (`\fB~\fP'), all of |
2549 | the characters preceding the first unquoted slash (or all characters, | |
2550 | if there is no unquoted slash) are considered a \fItilde-prefix\fP. | |
2551 | If none of the characters in the tilde-prefix are quoted, the | |
2552 | characters in the tilde-prefix following the tilde are treated as a | |
2553 | possible \fIlogin name\fP. | |
2554 | If this login name is the null string, the tilde is replaced with the | |
2555 | value of the shell parameter | |
726f6388 JA |
2556 | .SM |
2557 | .BR HOME . | |
2558 | If | |
2559 | .SM | |
2560 | .B HOME | |
cce855bc JA |
2561 | is unset, the home directory of the user executing the shell is |
2562 | substituted instead. | |
2563 | Otherwise, the tilde-prefix is replaced with the home directory | |
2564 | associated with the specified login name. | |
726f6388 | 2565 | .PP |
cce855bc | 2566 | If the tilde-prefix is a `~+', the value of the shell variable |
726f6388 JA |
2567 | .SM |
2568 | .B PWD | |
cce855bc JA |
2569 | replaces the tilde-prefix. |
2570 | If the tilde-prefix is a `~\-', the value of the shell variable | |
2571 | .SM | |
2572 | .BR OLDPWD , | |
2573 | if it is set, is substituted. | |
2574 | If the characters following the tilde in the tilde-prefix consist | |
2575 | of a number \fIN\fP, optionally prefixed | |
2576 | by a `+' or a `\-', the tilde-prefix is replaced with the corresponding | |
2577 | element from the directory stack, as it would be displayed by the | |
2578 | .B dirs | |
2579 | builtin invoked with the tilde-prefix as an argument. | |
2580 | If the characters following the tilde in the tilde-prefix consist of a | |
2581 | number without a leading `+' or `\-', `+' is assumed. | |
2582 | .PP | |
2583 | If the login name is invalid, or the tilde expansion fails, the word | |
2584 | is unchanged. | |
726f6388 | 2585 | .PP |
cce855bc JA |
2586 | Each variable assignment is checked for unquoted tilde-prefixes immediately |
2587 | following a | |
726f6388 | 2588 | .B : |
43df7bbb | 2589 | or the first |
726f6388 | 2590 | .BR = . |
cce855bc JA |
2591 | In these cases, tilde expansion is also performed. |
2592 | Consequently, one may use file names with tildes in assignments to | |
726f6388 JA |
2593 | .SM |
2594 | .BR PATH , | |
2595 | .SM | |
2596 | .BR MAILPATH , | |
2597 | and | |
2598 | .SM | |
2599 | .BR CDPATH , | |
2600 | and the shell assigns the expanded value. | |
2601 | .SS Parameter Expansion | |
2602 | .PP | |
2603 | The `\fB$\fP' character introduces parameter expansion, | |
2604 | command substitution, or arithmetic expansion. The parameter name | |
2605 | or symbol to be expanded may be enclosed in braces, which | |
2606 | are optional but serve to protect the variable to be expanded from | |
2607 | characters immediately following it which could be | |
2608 | interpreted as part of the name. | |
2609 | .PP | |
cce855bc JA |
2610 | When braces are used, the matching ending brace is the first `\fB}\fP' |
2611 | not escaped by a backslash or within a quoted string, and not within an | |
f75912ae | 2612 | embedded arithmetic expansion, command substitution, or parameter |
cce855bc JA |
2613 | expansion. |
2614 | .PP | |
726f6388 JA |
2615 | .PD 0 |
2616 | .TP | |
2617 | ${\fIparameter\fP} | |
2618 | The value of \fIparameter\fP is substituted. The braces are required | |
2619 | when | |
2620 | .I parameter | |
2621 | is a positional parameter with more than one digit, | |
2622 | or when | |
2623 | .I parameter | |
2624 | is followed by a character which is not to be | |
2625 | interpreted as part of its name. | |
2626 | .PD | |
2627 | .PP | |
08e72d7a | 2628 | If the first character of \fIparameter\fP is an exclamation point (\fB!\fP), |
ccc6cda3 JA |
2629 | a level of variable indirection is introduced. |
2630 | \fBBash\fP uses the value of the variable formed from the rest of | |
2631 | \fIparameter\fP as the name of the variable; this variable is then | |
bb70624e | 2632 | expanded and that value is used in the rest of the substitution, rather |
ccc6cda3 JA |
2633 | than the value of \fIparameter\fP itself. |
2634 | This is known as \fIindirect expansion\fP. | |
d3a24ed2 CR |
2635 | The exceptions to this are the expansions of ${!\fIprefix\fP*} and |
2636 | ${\fB!\fP\fIname\fP[\fI@\fP]} described below. | |
2637 | The exclamation point must immediately follow the left brace in order to | |
2638 | introduce indirection. | |
ccc6cda3 | 2639 | .PP |
726f6388 JA |
2640 | In each of the cases below, \fIword\fP is subject to tilde expansion, |
2641 | parameter expansion, command substitution, and arithmetic expansion. | |
e141c35a CR |
2642 | .PP |
2643 | When not performing substring expansion, using the forms documented below, | |
2644 | \fBbash\fP tests for a parameter that is unset or null. Omitting the colon | |
2645 | results in a test only for a parameter that is unset. | |
726f6388 JA |
2646 | .PP |
2647 | .PD 0 | |
2648 | .TP | |
2649 | ${\fIparameter\fP\fB:\-\fP\fIword\fP} | |
2650 | \fBUse Default Values\fP. If | |
2651 | .I parameter | |
2652 | is unset or null, the expansion of | |
2653 | .I word | |
2654 | is substituted. Otherwise, the value of | |
2655 | .I parameter | |
2656 | is substituted. | |
2657 | .TP | |
2658 | ${\fIparameter\fP\fB:=\fP\fIword\fP} | |
2659 | \fBAssign Default Values\fP. | |
2660 | If | |
2661 | .I parameter | |
2662 | is unset or null, the expansion of | |
2663 | .I word | |
2664 | is assigned to | |
2665 | .IR parameter . | |
2666 | The value of | |
2667 | .I parameter | |
2668 | is then substituted. Positional parameters and special parameters may | |
2669 | not be assigned to in this way. | |
2670 | .TP | |
2671 | ${\fIparameter\fP\fB:?\fP\fIword\fP} | |
2672 | \fBDisplay Error if Null or Unset\fP. | |
2673 | If | |
2674 | .I parameter | |
2675 | is null or unset, the expansion of \fIword\fP (or a message to that effect | |
2676 | if | |
2677 | .I word | |
2678 | is not present) is written to the standard error and the shell, if it | |
2679 | is not interactive, exits. Otherwise, the value of \fIparameter\fP is | |
2680 | substituted. | |
2681 | .TP | |
2682 | ${\fIparameter\fP\fB:+\fP\fIword\fP} | |
2683 | \fBUse Alternate Value\fP. | |
2684 | If | |
2685 | .I parameter | |
2686 | is null or unset, nothing is substituted, otherwise the expansion of | |
2687 | .I word | |
2688 | is substituted. | |
2689 | .TP | |
ccc6cda3 | 2690 | ${\fIparameter\fP\fB:\fP\fIoffset\fP} |
7117c2d2 | 2691 | .PD 0 |
ccc6cda3 JA |
2692 | .TP |
2693 | ${\fIparameter\fP\fB:\fP\fIoffset\fP\fB:\fP\fIlength\fP} | |
2694 | .PD | |
2695 | \fBSubstring Expansion.\fP | |
bb70624e JA |
2696 | Expands to up to \fIlength\fP characters of \fIparameter\fP |
2697 | starting at the character specified by \fIoffset\fP. | |
ccc6cda3 | 2698 | If \fIlength\fP is omitted, expands to the substring of |
bb70624e | 2699 | \fIparameter\fP starting at the character specified by \fIoffset\fP. |
ccc6cda3 JA |
2700 | \fIlength\fP and \fIoffset\fP are arithmetic expressions (see |
2701 | .SM | |
2702 | .B | |
2703 | ARITHMETIC EVALUATION | |
2704 | below). | |
2705 | \fIlength\fP must evaluate to a number greater than or equal to zero. | |
2706 | If \fIoffset\fP evaluates to a number less than zero, the value | |
2707 | is used as an offset from the end of the value of \fIparameter\fP. | |
2708 | If \fIparameter\fP is \fB@\fP, the result is \fIlength\fP positional | |
2709 | parameters beginning at \fIoffset\fP. | |
09767ff0 | 2710 | If \fIparameter\fP is an indexed array name subscripted by @ or *, |
ccc6cda3 JA |
2711 | the result is the \fIlength\fP |
2712 | members of the array beginning with ${\fIparameter\fP[\fIoffset\fP]}. | |
ec2199bd CR |
2713 | A negative \fIoffset\fP is taken relative to one greater than the maximum |
2714 | index of the specified array. | |
09767ff0 CR |
2715 | Substring expansion applied to an associative array produces undefined |
2716 | results. | |
ec2199bd CR |
2717 | Note that a negative offset must be separated from the colon by at least |
2718 | one space to avoid being confused with the :- expansion. | |
cce855bc | 2719 | Substring indexing is zero-based unless the positional parameters |
d3ad40de CR |
2720 | are used, in which case the indexing starts at 1 by default. |
2721 | If \fIoffset\fP is 0, and the positional parameters are used, \fB$0\fP is | |
2722 | prefixed to the list. | |
ccc6cda3 | 2723 | .TP |
bb70624e | 2724 | ${\fB!\fP\fIprefix\fP\fB*\fP} |
d3a24ed2 CR |
2725 | .PD 0 |
2726 | .TP | |
2727 | ${\fB!\fP\fIprefix\fP\fB@\fP} | |
2728 | .PD | |
36211029 | 2729 | \fBNames matching prefix.\fP |
bb70624e JA |
2730 | Expands to the names of variables whose names begin with \fIprefix\fP, |
2731 | separated by the first character of the | |
2732 | .SM | |
2733 | .B IFS | |
2734 | special variable. | |
d3ad40de CR |
2735 | When \fI@\fP is used and the expansion appears within double quotes, each |
2736 | variable name expands to a separate word. | |
bb70624e | 2737 | .TP |
d3a24ed2 CR |
2738 | ${\fB!\fP\fIname\fP[\fI@\fP]} |
2739 | .PD 0 | |
2740 | .TP | |
2741 | ${\fB!\fP\fIname\fP[\fI*\fP]} | |
2742 | .PD | |
36211029 | 2743 | \fBList of array keys.\fP |
d3a24ed2 CR |
2744 | If \fIname\fP is an array variable, expands to the list of array indices |
2745 | (keys) assigned in \fIname\fP. | |
2746 | If \fIname\fP is not an array, expands to 0 if \fIname\fP is set and null | |
2747 | otherwise. | |
2748 | When \fI@\fP is used and the expansion appears within double quotes, each | |
2749 | key expands to a separate word. | |
2750 | .TP | |
726f6388 | 2751 | ${\fB#\fP\fIparameter\fP} |
36211029 | 2752 | \fBParameter length.\fP |
726f6388 | 2753 | The length in characters of the value of \fIparameter\fP is substituted. |
ccc6cda3 JA |
2754 | If |
2755 | .I parameter | |
2756 | is | |
726f6388 JA |
2757 | .B * |
2758 | or | |
2759 | .BR @ , | |
cce855bc | 2760 | the value substituted is the number of positional parameters. |
ccc6cda3 JA |
2761 | If |
2762 | .I parameter | |
2763 | is an array name subscripted by | |
726f6388 | 2764 | .B * |
ccc6cda3 JA |
2765 | or |
2766 | .BR @ , | |
cce855bc | 2767 | the value substituted is the number of elements in the array. |
726f6388 | 2768 | .TP |
726f6388 | 2769 | ${\fIparameter\fP\fB#\fP\fIword\fP} |
7117c2d2 | 2770 | .PD 0 |
726f6388 JA |
2771 | .TP |
2772 | ${\fIparameter\fP\fB##\fP\fIword\fP} | |
2773 | .PD | |
36211029 | 2774 | \fBRemove matching prefix pattern.\fP |
726f6388 JA |
2775 | The |
2776 | .I word | |
2777 | is expanded to produce a pattern just as in pathname | |
2778 | expansion. If the pattern matches the beginning of | |
2779 | the value of | |
2780 | .IR parameter , | |
cce855bc | 2781 | then the result of the expansion is the expanded value of |
726f6388 | 2782 | .I parameter |
ccc6cda3 JA |
2783 | with the shortest matching pattern (the ``\fB#\fP'' case) or the |
2784 | longest matching pattern (the ``\fB##\fP'' case) deleted. | |
2785 | If | |
2786 | .I parameter | |
2787 | is | |
2788 | .B @ | |
2789 | or | |
2790 | .BR * , | |
2791 | the pattern removal operation is applied to each positional | |
2792 | parameter in turn, and the expansion is the resultant list. | |
2793 | If | |
2794 | .I parameter | |
2795 | is an array variable subscripted with | |
2796 | .B @ | |
2797 | or | |
2798 | .BR * , | |
2799 | the pattern removal operation is applied to each member of the | |
2800 | array in turn, and the expansion is the resultant list. | |
726f6388 | 2801 | .TP |
726f6388 | 2802 | ${\fIparameter\fP\fB%\fP\fIword\fP} |
7117c2d2 | 2803 | .PD 0 |
726f6388 JA |
2804 | .TP |
2805 | ${\fIparameter\fP\fB%%\fP\fIword\fP} | |
2806 | .PD | |
36211029 | 2807 | \fBRemove matching suffix pattern.\fP |
726f6388 | 2808 | The \fIword\fP is expanded to produce a pattern just as in |
ccc6cda3 | 2809 | pathname expansion. |
cce855bc | 2810 | If the pattern matches a trailing portion of the expanded value of |
726f6388 | 2811 | .IR parameter , |
cce855bc | 2812 | then the result of the expansion is the expanded value of |
726f6388 | 2813 | .I parameter |
ccc6cda3 JA |
2814 | with the shortest matching pattern (the ``\fB%\fP'' case) or the |
2815 | longest matching pattern (the ``\fB%%\fP'' case) deleted. | |
2816 | If | |
2817 | .I parameter | |
2818 | is | |
2819 | .B @ | |
2820 | or | |
2821 | .BR * , | |
2822 | the pattern removal operation is applied to each positional | |
2823 | parameter in turn, and the expansion is the resultant list. | |
2824 | If | |
2825 | .I parameter | |
2826 | is an array variable subscripted with | |
2827 | .B @ | |
2828 | or | |
2829 | .BR * , | |
2830 | the pattern removal operation is applied to each member of the | |
2831 | array in turn, and the expansion is the resultant list. | |
2832 | .TP | |
ccc6cda3 | 2833 | ${\fIparameter\fP\fB/\fP\fIpattern\fP\fB/\fP\fIstring\fP} |
36211029 | 2834 | \fBPattern substitution.\fP |
ccc6cda3 JA |
2835 | The \fIpattern\fP is expanded to produce a pattern just as in |
2836 | pathname expansion. | |
2837 | \fIParameter\fP is expanded and the longest match of \fIpattern\fP | |
2838 | against its value is replaced with \fIstring\fP. | |
e6598ba4 | 2839 | If \fIpattern\fP begins with \fB/\fP, all matches of \fIpattern\fP are |
dc8fbaf9 | 2840 | replaced with \fIstring\fP. Normally only the first match is replaced. |
ccc6cda3 | 2841 | If \fIpattern\fP begins with \fB#\fP, it must match at the beginning |
b72432fd | 2842 | of the expanded value of \fIparameter\fP. |
ccc6cda3 | 2843 | If \fIpattern\fP begins with \fB%\fP, it must match at the end |
b72432fd | 2844 | of the expanded value of \fIparameter\fP. |
ccc6cda3 JA |
2845 | If \fIstring\fP is null, matches of \fIpattern\fP are deleted |
2846 | and the \fB/\fP following \fIpattern\fP may be omitted. | |
2847 | If | |
2848 | .I parameter | |
2849 | is | |
2850 | .B @ | |
2851 | or | |
2852 | .BR * , | |
2853 | the substitution operation is applied to each positional | |
2854 | parameter in turn, and the expansion is the resultant list. | |
2855 | If | |
2856 | .I parameter | |
2857 | is an array variable subscripted with | |
2858 | .B @ | |
2859 | or | |
2860 | .BR * , | |
2861 | the substitution operation is applied to each member of the | |
2862 | array in turn, and the expansion is the resultant list. | |
09767ff0 CR |
2863 | .TP |
2864 | ${\fIparameter\fP\fB^\fP\fIpattern\fP} | |
2865 | .PD 0 | |
2866 | .TP | |
2867 | ${\fIparameter\fP\fB^^\fP\fIpattern\fP} | |
2868 | .TP | |
2869 | ${\fIparameter\fP\fB,\fP\fIpattern\fP} | |
2870 | .TP | |
2871 | ${\fIparameter\fP\fB,,\fP\fIpattern\fP} | |
2872 | .PD | |
36211029 | 2873 | \fBCase modification.\fP |
09767ff0 CR |
2874 | This expansion modifies the case of alphabetic characters in \fIparameter\fP. |
2875 | The \fIpattern\fP is expanded to produce a pattern just as in | |
2876 | pathname expansion. | |
2877 | The \fB^\fP operator converts lowercase letters matching \fIpattern\fP | |
2878 | to uppercase; the \fB,\fP operator converts matching uppercase letters | |
2879 | to lowercase. | |
2880 | The \fB^^\fP and \fB,,\fP expansions convert each matched character in the | |
2881 | expanded value; the \fB^\fP and \fB,\fP expansions match and convert only | |
5cdaaf76 | 2882 | the first character in the expanded value. |
09767ff0 CR |
2883 | If \fIpattern\fP is omitted, it is treated like a \fB?\fP, which matches |
2884 | every character. | |
2885 | If | |
2886 | .I parameter | |
2887 | is | |
2888 | .B @ | |
2889 | or | |
2890 | .BR * , | |
2891 | the case modification operation is applied to each positional | |
2892 | parameter in turn, and the expansion is the resultant list. | |
2893 | If | |
2894 | .I parameter | |
2895 | is an array variable subscripted with | |
2896 | .B @ | |
2897 | or | |
2898 | .BR * , | |
2899 | the case modification operation is applied to each member of the | |
2900 | array in turn, and the expansion is the resultant list. | |
726f6388 JA |
2901 | .SS Command Substitution |
2902 | .PP | |
cce855bc | 2903 | \fICommand substitution\fP allows the output of a command to replace |
726f6388 JA |
2904 | the command name. There are two forms: |
2905 | .PP | |
2906 | .RS | |
2907 | .PP | |
2908 | \fB$(\fP\fIcommand\fP\|\fB)\fP | |
2909 | .RE | |
2910 | or | |
2911 | .RS | |
3d4e09aa | 2912 | \fB\`\fP\fIcommand\fP\fB\`\fP |
726f6388 JA |
2913 | .RE |
2914 | .PP | |
ccc6cda3 | 2915 | .B Bash |
726f6388 JA |
2916 | performs the expansion by executing \fIcommand\fP and |
2917 | replacing the command substitution with the standard output of the | |
2918 | command, with any trailing newlines deleted. | |
cce855bc JA |
2919 | Embedded newlines are not deleted, but they may be removed during |
2920 | word splitting. | |
2921 | The command substitution \fB$(cat \fIfile\fP)\fR can be replaced by | |
2922 | the equivalent but faster \fB$(< \fIfile\fP)\fR. | |
726f6388 | 2923 | .PP |
ccc6cda3 | 2924 | When the old-style backquote form of substitution is used, |
726f6388 JA |
2925 | backslash retains its literal meaning except when followed by |
2926 | .BR $ , | |
3d4e09aa | 2927 | .BR \` , |
726f6388 JA |
2928 | or |
2929 | .BR \e . | |
cce855bc JA |
2930 | The first backquote not preceded by a backslash terminates the |
2931 | command substitution. | |
726f6388 JA |
2932 | When using the $(\^\fIcommand\fP\|) form, all characters between the |
2933 | parentheses make up the command; none are treated specially. | |
2934 | .PP | |
cce855bc | 2935 | Command substitutions may be nested. To nest when using the backquoted form, |
726f6388 JA |
2936 | escape the inner backquotes with backslashes. |
2937 | .PP | |
2938 | If the substitution appears within double quotes, word splitting and | |
2939 | pathname expansion are not performed on the results. | |
2940 | .SS Arithmetic Expansion | |
2941 | .PP | |
2942 | Arithmetic expansion allows the evaluation of an arithmetic expression | |
ccc6cda3 | 2943 | and the substitution of the result. The format for arithmetic expansion is: |
726f6388 JA |
2944 | .RS |
2945 | .PP | |
726f6388 JA |
2946 | \fB$((\fP\fIexpression\fP\fB))\fP |
2947 | .RE | |
2948 | .PP | |
2949 | The | |
2950 | .I expression | |
2951 | is treated as if it were within double quotes, but a double quote | |
ccc6cda3 JA |
2952 | inside the parentheses is not treated specially. |
2953 | All tokens in the expression undergo parameter expansion, string | |
2954 | expansion, command substitution, and quote removal. | |
d3a24ed2 | 2955 | Arithmetic expansions may be nested. |
726f6388 JA |
2956 | .PP |
2957 | The evaluation is performed according to the rules listed below under | |
2958 | .SM | |
2959 | .BR "ARITHMETIC EVALUATION" . | |
2960 | If | |
2961 | .I expression | |
2962 | is invalid, | |
2963 | .B bash | |
2964 | prints a message indicating failure and no substitution occurs. | |
2965 | .SS Process Substitution | |
2966 | .PP | |
2967 | \fIProcess substitution\fP is supported on systems that support named | |
2968 | pipes (\fIFIFOs\fP) or the \fB/dev/fd\fP method of naming open files. | |
2969 | It takes the form of | |
2970 | \fB<(\fP\fIlist\^\fP\fB)\fP | |
2971 | or | |
2972 | \fB>(\fP\fIlist\^\fP\fB)\fP. | |
2973 | The process \fIlist\fP is run with its input or output connected to a | |
2974 | \fIFIFO\fP or some file in \fB/dev/fd\fP. The name of this file is | |
2975 | passed as an argument to the current command as the result of the | |
2976 | expansion. If the \fB>(\fP\fIlist\^\fP\fB)\fP form is used, writing to | |
2977 | the file will provide input for \fIlist\fP. If the | |
2978 | \fB<(\fP\fIlist\^\fP\fB)\fP form is used, the file passed as an | |
2979 | argument should be read to obtain the output of \fIlist\fP. | |
2980 | .PP | |
bb70624e | 2981 | When available, process substitution is performed |
ccc6cda3 JA |
2982 | simultaneously with parameter and variable expansion, |
2983 | command substitution, | |
2984 | and arithmetic expansion. | |
726f6388 JA |
2985 | .SS Word Splitting |
2986 | .PP | |
2987 | The shell scans the results of | |
2988 | parameter expansion, | |
2989 | command substitution, | |
2990 | and | |
2991 | arithmetic expansion | |
2992 | that did not occur within double quotes for | |
2993 | .IR "word splitting" . | |
2994 | .PP | |
2995 | The shell treats each character of | |
2996 | .SM | |
2997 | .B IFS | |
2998 | as a delimiter, and splits the results of the other | |
ccc6cda3 | 2999 | expansions into words on these characters. If |
726f6388 JA |
3000 | .SM |
3001 | .B IFS | |
ccc6cda3 JA |
3002 | is unset, or its |
3003 | value is exactly | |
726f6388 JA |
3004 | .BR <space><tab><newline> , |
3005 | the default, then | |
d3ad40de CR |
3006 | sequences of |
3007 | .BR <space> , | |
3008 | .BR <tab> , | |
3009 | and | |
3010 | .B <newline> | |
3011 | at the beginning and end of the results of the previous | |
3012 | expansions are ignored, and | |
726f6388 JA |
3013 | any sequence of |
3014 | .SM | |
3015 | .B IFS | |
d3ad40de CR |
3016 | characters not at the beginning or end serves to delimit words. |
3017 | If | |
726f6388 JA |
3018 | .SM |
3019 | .B IFS | |
3020 | has a value other than the default, then sequences of | |
3021 | the whitespace characters | |
3022 | .B space | |
3023 | and | |
3024 | .B tab | |
3025 | are ignored at the beginning and end of the | |
3026 | word, as long as the whitespace character is in the | |
3027 | value of | |
3028 | .SM | |
3029 | .BR IFS | |
3030 | (an | |
3031 | .SM | |
3032 | .B IFS | |
3033 | whitespace character). | |
3034 | Any character in | |
3035 | .SM | |
3036 | .B IFS | |
3037 | that is not | |
3038 | .SM | |
3039 | .B IFS | |
3040 | whitespace, along with any adjacent | |
3041 | .SM | |
3042 | .B IFS | |
3043 | whitespace characters, delimits a field. | |
3044 | A sequence of | |
3045 | .SM | |
3046 | .B IFS | |
3047 | whitespace characters is also treated as a delimiter. | |
3048 | If the value of | |
3049 | .SM | |
3050 | .B IFS | |
3051 | is null, no word splitting occurs. | |
726f6388 | 3052 | .PP |
20587658 | 3053 | Explicit null arguments (\^\f3"\^"\fP or \^\f3\(aq\^\(aq\fP\^) are retained. |
ccc6cda3 | 3054 | Unquoted implicit null arguments, resulting from the expansion of |
bb70624e | 3055 | parameters that have no values, are removed. |
ccc6cda3 JA |
3056 | If a parameter with no value is expanded within double quotes, a |
3057 | null argument results and is retained. | |
726f6388 JA |
3058 | .PP |
3059 | Note that if no expansion occurs, no splitting | |
3060 | is performed. | |
3061 | .SS Pathname Expansion | |
3062 | .PP | |
3063 | After word splitting, | |
3064 | unless the | |
3065 | .B \-f | |
3066 | option has been set, | |
3067 | .B bash | |
ccc6cda3 | 3068 | scans each word for the characters |
726f6388 JA |
3069 | .BR * , |
3070 | .BR ? , | |
3071 | and | |
3072 | .BR [ . | |
3073 | If one of these characters appears, then the word is | |
3074 | regarded as a | |
3075 | .IR pattern , | |
3076 | and replaced with an alphabetically sorted list of | |
ccc6cda3 JA |
3077 | file names matching the pattern. |
3078 | If no matching file names are found, | |
3079 | and the shell option | |
3080 | .B nullglob | |
57a3f689 | 3081 | is not enabled, the word is left unchanged. |
cce855bc JA |
3082 | If the |
3083 | .B nullglob | |
3084 | option is set, and no matches are found, | |
726f6388 | 3085 | the word is removed. |
d3a24ed2 CR |
3086 | If the |
3087 | .B failglob | |
3088 | shell option is set, and no matches are found, an error message | |
3089 | is printed and the command is not executed. | |
cce855bc JA |
3090 | If the shell option |
3091 | .B nocaseglob | |
3092 | is enabled, the match is performed without regard to the case | |
3093 | of alphabetic characters. | |
ccc6cda3 | 3094 | When a pattern is used for pathname expansion, |
726f6388 JA |
3095 | the character |
3096 | .B ``.'' | |
3097 | at the start of a name or immediately following a slash | |
ccc6cda3 JA |
3098 | must be matched explicitly, unless the shell option |
3099 | .B dotglob | |
3100 | is set. | |
cce855bc JA |
3101 | When matching a pathname, the slash character must always be |
3102 | matched explicitly. | |
ccc6cda3 | 3103 | In other cases, the |
726f6388 JA |
3104 | .B ``.'' |
3105 | character is not treated specially. | |
ccc6cda3 JA |
3106 | See the description of |
3107 | .B shopt | |
3108 | below under | |
3109 | .SM | |
3110 | .B SHELL BUILTIN COMMANDS | |
3111 | for a description of the | |
cce855bc JA |
3112 | .BR nocaseglob , |
3113 | .BR nullglob , | |
d3a24ed2 | 3114 | .BR failglob , |
ccc6cda3 JA |
3115 | and |
3116 | .B dotglob | |
3117 | shell options. | |
3118 | .PP | |
3119 | The | |
3120 | .SM | |
3121 | .B GLOBIGNORE | |
3122 | shell variable may be used to restrict the set of file names matching a | |
3123 | .IR pattern . | |
3124 | If | |
3125 | .SM | |
3126 | .B GLOBIGNORE | |
3127 | is set, each matching file name that also matches one of the patterns in | |
3128 | .SM | |
3129 | .B GLOBIGNORE | |
3130 | is removed from the list of matches. | |
3131 | The file names | |
3132 | .B ``.'' | |
3133 | and | |
3134 | .B ``..'' | |
d3a24ed2 | 3135 | are always ignored when |
ccc6cda3 JA |
3136 | .SM |
3137 | .B GLOBIGNORE | |
d3a24ed2 | 3138 | is set and not null. However, setting |
ccc6cda3 JA |
3139 | .SM |
3140 | .B GLOBIGNORE | |
d3a24ed2 | 3141 | to a non-null value has the effect of enabling the |
ccc6cda3 JA |
3142 | .B dotglob |
3143 | shell option, so all other file names beginning with a | |
3144 | .B ``.'' | |
3145 | will match. | |
3146 | To get the old behavior of ignoring file names beginning with a | |
3147 | .BR ``.'' , | |
3148 | make | |
3149 | .B ``.*'' | |
3150 | one of the patterns in | |
3151 | .SM | |
3152 | .BR GLOBIGNORE . | |
3153 | The | |
3154 | .B dotglob | |
3155 | option is disabled when | |
3156 | .SM | |
3157 | .B GLOBIGNORE | |
3158 | is unset. | |
726f6388 | 3159 | .PP |
cce855bc JA |
3160 | \fBPattern Matching\fP |
3161 | .PP | |
3162 | Any character that appears in a pattern, other than the special pattern | |
3163 | characters described below, matches itself. The NUL character may not | |
d3a24ed2 CR |
3164 | occur in a pattern. A backslash escapes the following character; the |
3165 | escaping backslash is discarded when matching. | |
3166 | The special pattern characters must be quoted if | |
cce855bc JA |
3167 | they are to be matched literally. |
3168 | .PP | |
726f6388 JA |
3169 | The special pattern characters have the following meanings: |
3170 | .PP | |
3171 | .PD 0 | |
3172 | .TP | |
3173 | .B * | |
3174 | Matches any string, including the null string. | |
4ac1ff98 | 3175 | When the \fBglobstar\fP shell option is enabled, and \fB*\fP is used in |
d0ca3503 | 3176 | a pathname expansion context, two adjacent \fB*\fPs used as a single |
4ac1ff98 CR |
3177 | pattern will match all files and zero or more directories and |
3178 | subdirectories. | |
3179 | If followed by a \fB/\fP, two adjacent \fB*\fPs will match only directories | |
3180 | and subdirectories. | |
726f6388 JA |
3181 | .TP |
3182 | .B ? | |
3183 | Matches any single character. | |
3184 | .TP | |
3185 | .B [...] | |
3186 | Matches any one of the enclosed characters. A pair of characters | |
28ef6c31 JA |
3187 | separated by a hyphen denotes a |
3188 | \fIrange expression\fP; | |
3189 | any character that sorts between those two characters, inclusive, | |
3190 | using the current locale's collating sequence and character set, | |
726f6388 JA |
3191 | is matched. If the first character following the |
3192 | .B [ | |
3193 | is a | |
3194 | .B ! | |
3195 | or a | |
3196 | .B ^ | |
ccc6cda3 | 3197 | then any character not enclosed is matched. |
28ef6c31 | 3198 | The sorting order of characters in range expressions is determined by |
984a1947 CR |
3199 | the current locale and the value of the |
3200 | .SM | |
3201 | .B LC_COLLATE | |
3202 | shell variable, | |
28ef6c31 | 3203 | if set. |
ccc6cda3 | 3204 | A |
726f6388 | 3205 | .B \- |
726f6388 JA |
3206 | may be matched by including it as the first or last character |
3207 | in the set. | |
ccc6cda3 JA |
3208 | A |
3209 | .B ] | |
3210 | may be matched by including it as the first character | |
3211 | in the set. | |
cce855bc JA |
3212 | .br |
3213 | .if t .sp 0.5 | |
3214 | .if n .sp 1 | |
3215 | Within | |
3216 | .B [ | |
3217 | and | |
3218 | .BR ] , | |
3219 | \fIcharacter classes\fP can be specified using the syntax | |
3220 | \fB[:\fP\fIclass\fP\fB:]\fP, where \fIclass\fP is one of the | |
ac18b312 | 3221 | following classes defined in the POSIX standard: |
cce855bc JA |
3222 | .PP |
3223 | .RS | |
3224 | .B | |
7117c2d2 JA |
3225 | .if n alnum alpha ascii blank cntrl digit graph lower print punct space upper word xdigit |
3226 | .if t alnum alpha ascii blank cntrl digit graph lower print punct space upper word xdigit | |
cce855bc JA |
3227 | .br |
3228 | A character class matches any character belonging to that class. | |
7117c2d2 | 3229 | The \fBword\fP character class matches letters, digits, and the character _. |
cce855bc JA |
3230 | .br |
3231 | .if t .sp 0.5 | |
3232 | .if n .sp 1 | |
3233 | Within | |
3234 | .B [ | |
3235 | and | |
3236 | .BR ] , | |
3237 | an \fIequivalence class\fP can be specified using the syntax | |
3238 | \fB[=\fP\fIc\fP\fB=]\fP, which matches all characters with the | |
3239 | same collation weight (as defined by the current locale) as | |
3240 | the character \fIc\fP. | |
3241 | .br | |
3242 | .if t .sp 0.5 | |
3243 | .if n .sp 1 | |
3244 | Within | |
3245 | .B [ | |
3246 | and | |
3247 | .BR ] , | |
3248 | the syntax \fB[.\fP\fIsymbol\fP\fB.]\fP matches the collating symbol | |
3249 | \fIsymbol\fP. | |
3250 | .RE | |
3251 | .PD | |
3252 | .PP | |
3253 | If the \fBextglob\fP shell option is enabled using the \fBshopt\fP | |
3254 | builtin, several extended pattern matching operators are recognized. | |
bb70624e | 3255 | In the following description, a \fIpattern-list\fP is a list of one |
cce855bc JA |
3256 | or more patterns separated by a \fB|\fP. |
3257 | Composite patterns may be formed using one or more of the following | |
3258 | sub-patterns: | |
3259 | .sp 1 | |
3260 | .PD 0 | |
3261 | .RS | |
3262 | .TP | |
3263 | \fB?(\fP\^\fIpattern-list\^\fP\fB)\fP | |
3264 | Matches zero or one occurrence of the given patterns | |
3265 | .TP | |
3266 | \fB*(\fP\^\fIpattern-list\^\fP\fB)\fP | |
3267 | Matches zero or more occurrences of the given patterns | |
3268 | .TP | |
3269 | \fB+(\fP\^\fIpattern-list\^\fP\fB)\fP | |
3270 | Matches one or more occurrences of the given patterns | |
3271 | .TP | |
3272 | \fB@(\fP\^\fIpattern-list\^\fP\fB)\fP | |
43df7bbb | 3273 | Matches one of the given patterns |
cce855bc JA |
3274 | .TP |
3275 | \fB!(\fP\^\fIpattern-list\^\fP\fB)\fP | |
3276 | Matches anything except one of the given patterns | |
3277 | .RE | |
726f6388 JA |
3278 | .PD |
3279 | .SS Quote Removal | |
3280 | .PP | |
3281 | After the preceding expansions, all unquoted occurrences of the | |
3282 | characters | |
3283 | .BR \e , | |
20587658 | 3284 | .BR \(aq , |
ccc6cda3 JA |
3285 | and \^\f3"\fP\^ that did not result from one of the above |
3286 | expansions are removed. | |
726f6388 JA |
3287 | .SH REDIRECTION |
3288 | Before a command is executed, its input and output | |
3289 | may be | |
3290 | .I redirected | |
3291 | using a special notation interpreted by the shell. | |
3292 | Redirection may also be used to open and close files for the | |
3293 | current shell execution environment. The following redirection | |
3294 | operators may precede or appear anywhere within a | |
3295 | .I simple command | |
3296 | or may follow a | |
3297 | .IR command . | |
3298 | Redirections are processed in the order they appear, from | |
3299 | left to right. | |
3300 | .PP | |
a8fd3f3e CR |
3301 | Each redirection that may be preceded by a file descriptor number |
3302 | may instead be preceded by a word of the form {\fIvarname\fP}. | |
3303 | In this case, for each redirection operator except | |
3304 | >&- and <&-, the shell will allocate a file descriptor greater | |
3305 | than 10 and assign it to \fIvarname\fP. If >&- or <&- is preceded | |
3306 | by {\fIvarname\fP}, the value of \fIvarname\fP defines the file | |
3307 | descriptor to close. | |
3308 | .PP | |
726f6388 JA |
3309 | In the following descriptions, if the file descriptor number is |
3310 | omitted, and the first character of the redirection operator is | |
3311 | .BR < , | |
3312 | the redirection refers to the standard input (file descriptor | |
3313 | 0). If the first character of the redirection operator is | |
3314 | .BR > , | |
3315 | the redirection refers to the standard output (file descriptor | |
3316 | 1). | |
3317 | .PP | |
cce855bc JA |
3318 | The word following the redirection operator in the following |
3319 | descriptions, unless otherwise noted, is subjected to brace expansion, | |
3320 | tilde expansion, parameter expansion, command substitution, arithmetic | |
bb70624e | 3321 | expansion, quote removal, pathname expansion, and word splitting. |
cce855bc | 3322 | If it expands to more than one word, |
726f6388 JA |
3323 | .B bash |
3324 | reports an error. | |
3325 | .PP | |
3326 | Note that the order of redirections is significant. For example, | |
3327 | the command | |
3328 | .RS | |
3329 | .PP | |
3330 | ls \fB>\fP dirlist 2\fB>&\fP1 | |
3331 | .RE | |
3332 | .PP | |
3333 | directs both standard output and standard error to the file | |
3334 | .IR dirlist , | |
3335 | while the command | |
3336 | .RS | |
3337 | .PP | |
3338 | ls 2\fB>&\fP1 \fB>\fP dirlist | |
3339 | .RE | |
3340 | .PP | |
3341 | directs only the standard output to file | |
3342 | .IR dirlist , | |
db31fb26 | 3343 | because the standard error was duplicated from the standard output |
726f6388 JA |
3344 | before the standard output was redirected to |
3345 | .IR dirlist . | |
cce855bc | 3346 | .PP |
bb70624e JA |
3347 | \fBBash\fP handles several filenames specially when they are used in |
3348 | redirections, as described in the following table: | |
3349 | .RS | |
3350 | .PP | |
3351 | .PD 0 | |
3352 | .TP | |
3353 | .B /dev/fd/\fIfd\fP | |
3354 | If \fIfd\fP is a valid integer, file descriptor \fIfd\fP is duplicated. | |
3355 | .TP | |
3356 | .B /dev/stdin | |
3357 | File descriptor 0 is duplicated. | |
3358 | .TP | |
3359 | .B /dev/stdout | |
3360 | File descriptor 1 is duplicated. | |
3361 | .TP | |
3362 | .B /dev/stderr | |
3363 | File descriptor 2 is duplicated. | |
3364 | .TP | |
3365 | .B /dev/tcp/\fIhost\fP/\fIport\fP | |
3366 | If \fIhost\fP is a valid hostname or Internet address, and \fIport\fP | |
f73dda09 JA |
3367 | is an integer port number or service name, \fBbash\fP attempts to open |
3368 | a TCP connection to the corresponding socket. | |
bb70624e JA |
3369 | .TP |
3370 | .B /dev/udp/\fIhost\fP/\fIport\fP | |
3371 | If \fIhost\fP is a valid hostname or Internet address, and \fIport\fP | |
f73dda09 JA |
3372 | is an integer port number or service name, \fBbash\fP attempts to open |
3373 | a UDP connection to the corresponding socket. | |
bb70624e JA |
3374 | .PD |
3375 | .RE | |
3376 | .PP | |
cce855bc | 3377 | A failure to open or create a file causes the redirection to fail. |
cac4cdbf CR |
3378 | .PP |
3379 | Redirections using file descriptors greater than 9 should be used with | |
3380 | care, as they may conflict with file descriptors the shell uses | |
3381 | internally. | |
726f6388 JA |
3382 | .SS Redirecting Input |
3383 | .PP | |
3384 | Redirection of input causes the file whose name results from | |
3385 | the expansion of | |
3386 | .I word | |
3387 | to be opened for reading on file descriptor | |
3388 | .IR n , | |
3389 | or the standard input (file descriptor 0) if | |
3390 | .I n | |
3391 | is not specified. | |
3392 | .PP | |
3393 | The general format for redirecting input is: | |
3394 | .RS | |
3395 | .PP | |
3396 | [\fIn\fP]\fB<\fP\fIword\fP | |
3397 | .RE | |
3398 | .SS Redirecting Output | |
3399 | .PP | |
3400 | Redirection of output causes the file whose name results from | |
3401 | the expansion of | |
3402 | .I word | |
3403 | to be opened for writing on file descriptor | |
3404 | .IR n , | |
3405 | or the standard output (file descriptor 1) if | |
3406 | .I n | |
3407 | is not specified. If the file does not exist it is created; | |
3408 | if it does exist it is truncated to zero size. | |
3409 | .PP | |
3410 | The general format for redirecting output is: | |
3411 | .RS | |
3412 | .PP | |
3413 | [\fIn\fP]\fB>\fP\fIword\fP | |
3414 | .RE | |
3415 | .PP | |
3416 | If the redirection operator is | |
ccc6cda3 JA |
3417 | .BR > , |
3418 | and the | |
cce855bc | 3419 | .B noclobber |
ccc6cda3 JA |
3420 | option to the |
3421 | .B set | |
bb70624e | 3422 | builtin has been enabled, the redirection will fail if the file |
cce855bc JA |
3423 | whose name results from the expansion of \fIword\fP exists and is |
3424 | a regular file. | |
ccc6cda3 | 3425 | If the redirection operator is |
726f6388 | 3426 | .BR >| , |
cce855bc JA |
3427 | or the redirection operator is |
3428 | .B > | |
3429 | and the | |
3430 | .B noclobber | |
726f6388 JA |
3431 | option to the |
3432 | .B set | |
cce855bc | 3433 | builtin command is not enabled, the redirection is attempted even |
ccc6cda3 | 3434 | if the file named by \fIword\fP exists. |
726f6388 JA |
3435 | .SS Appending Redirected Output |
3436 | .PP | |
3437 | Redirection of output in this fashion | |
3438 | causes the file whose name results from | |
3439 | the expansion of | |
3440 | .I word | |
3441 | to be opened for appending on file descriptor | |
3442 | .IR n , | |
3443 | or the standard output (file descriptor 1) if | |
3444 | .I n | |
3445 | is not specified. If the file does not exist it is created. | |
3446 | .PP | |
3447 | The general format for appending output is: | |
3448 | .RS | |
3449 | .PP | |
3450 | [\fIn\fP]\fB>>\fP\fIword\fP | |
3451 | .RE | |
3452 | .PP | |
3453 | .SS Redirecting Standard Output and Standard Error | |
3454 | .PP | |
8943768b | 3455 | This construct allows both the |
726f6388 JA |
3456 | standard output (file descriptor 1) and |
3457 | the standard error output (file descriptor 2) | |
3458 | to be redirected to the file whose name is the | |
3459 | expansion of | |
8943768b | 3460 | .IR word . |
726f6388 JA |
3461 | .PP |
3462 | There are two formats for redirecting standard output and | |
3463 | standard error: | |
3464 | .RS | |
3465 | .PP | |
3466 | \fB&>\fP\fIword\fP | |
3467 | .RE | |
3468 | and | |
3469 | .RS | |
3470 | \fB>&\fP\fIword\fP | |
3471 | .RE | |
3472 | .PP | |
3473 | Of the two forms, the first is preferred. | |
3474 | This is semantically equivalent to | |
3475 | .RS | |
3476 | .PP | |
3477 | \fB>\fP\fIword\fP 2\fB>&\fP1 | |
3478 | .RE | |
8943768b CR |
3479 | .PP |
3480 | .SS Appending Standard Output and Standard Error | |
3481 | .PP | |
3482 | This construct allows both the | |
3483 | standard output (file descriptor 1) and | |
3484 | the standard error output (file descriptor 2) | |
3485 | to be appended to the file whose name is the | |
3486 | expansion of | |
3487 | .IR word . | |
3488 | .PP | |
3489 | The format for appending standard output and standard error is: | |
3490 | .RS | |
3491 | .PP | |
3492 | \fB&>>\fP\fIword\fP | |
3493 | .RE | |
3494 | .PP | |
3495 | This is semantically equivalent to | |
3496 | .RS | |
3497 | .PP | |
3498 | \fB>>\fP\fIword\fP 2\fB>&\fP1 | |
3499 | .RE | |
726f6388 JA |
3500 | .SS Here Documents |
3501 | .PP | |
3502 | This type of redirection instructs the shell to read input from the | |
3503 | current source until a line containing only | |
626d0694 | 3504 | .I delimiter |
726f6388 JA |
3505 | (with no trailing blanks) |
3506 | is seen. All of | |
3507 | the lines read up to that point are then used as the standard | |
3508 | input for a command. | |
3509 | .PP | |
7117c2d2 | 3510 | The format of here-documents is: |
726f6388 JA |
3511 | .RS |
3512 | .PP | |
3513 | .nf | |
3514 | \fB<<\fP[\fB\-\fP]\fIword\fP | |
f73dda09 | 3515 | \fIhere-document\fP |
726f6388 JA |
3516 | \fIdelimiter\fP |
3517 | .fi | |
3518 | .RE | |
3519 | .PP | |
bb70624e JA |
3520 | No parameter expansion, command substitution, arithmetic expansion, |
3521 | or pathname expansion is performed on | |
726f6388 JA |
3522 | .IR word . |
3523 | If any characters in | |
3524 | .I word | |
3525 | are quoted, the | |
3526 | .I delimiter | |
3527 | is the result of quote removal on | |
3528 | .IR word , | |
cce855bc JA |
3529 | and the lines in the here-document are not expanded. |
3530 | If \fIword\fP is unquoted, | |
726f6388 JA |
3531 | all lines of the here-document are subjected to parameter expansion, |
3532 | command substitution, and arithmetic expansion. In the latter | |
bb70624e | 3533 | case, the character sequence |
726f6388 JA |
3534 | .B \e<newline> |
3535 | is ignored, and | |
3536 | .B \e | |
3537 | must be used to quote the characters | |
3538 | .BR \e , | |
3539 | .BR $ , | |
3540 | and | |
3d4e09aa | 3541 | .BR \` . |
726f6388 JA |
3542 | .PP |
3543 | If the redirection operator is | |
3544 | .BR <<\- , | |
3545 | then all leading tab characters are stripped from input lines and the | |
3546 | line containing | |
3547 | .IR delimiter . | |
3548 | This allows | |
3549 | here-documents within shell scripts to be indented in a | |
3550 | natural fashion. | |
7117c2d2 JA |
3551 | .SS "Here Strings" |
3552 | A variant of here documents, the format is: | |
3553 | .RS | |
3554 | .PP | |
3555 | .nf | |
3556 | \fB<<<\fP\fIword\fP | |
3557 | .fi | |
3558 | .RE | |
3559 | .PP | |
3560 | The \fIword\fP is expanded and supplied to the command on its standard | |
3561 | input. | |
726f6388 JA |
3562 | .SS "Duplicating File Descriptors" |
3563 | .PP | |
3564 | The redirection operator | |
3565 | .RS | |
3566 | .PP | |
3567 | [\fIn\fP]\fB<&\fP\fIword\fP | |
3568 | .RE | |
3569 | .PP | |
3570 | is used to duplicate input file descriptors. | |
3571 | If | |
3572 | .I word | |
3573 | expands to one or more digits, the file descriptor denoted by | |
3574 | .I n | |
cce855bc JA |
3575 | is made to be a copy of that file descriptor. |
3576 | If the digits in | |
3577 | .I word | |
3578 | do not specify a file descriptor open for input, a redirection error occurs. | |
3579 | If | |
726f6388 JA |
3580 | .I word |
3581 | evaluates to | |
3582 | .BR \- , | |
3583 | file descriptor | |
3584 | .I n | |
3585 | is closed. If | |
3586 | .I n | |
3587 | is not specified, the standard input (file descriptor 0) is used. | |
3588 | .PP | |
3589 | The operator | |
3590 | .RS | |
3591 | .PP | |
3592 | [\fIn\fP]\fB>&\fP\fIword\fP | |
3593 | .RE | |
3594 | .PP | |
3595 | is used similarly to duplicate output file descriptors. If | |
3596 | .I n | |
3597 | is not specified, the standard output (file descriptor 1) is used. | |
cce855bc JA |
3598 | If the digits in |
3599 | .I word | |
3600 | do not specify a file descriptor open for output, a redirection error occurs. | |
726f6388 JA |
3601 | As a special case, if \fIn\fP is omitted, and \fIword\fP does not |
3602 | expand to one or more digits, the standard output and standard | |
3603 | error are redirected as described previously. | |
7117c2d2 JA |
3604 | .SS "Moving File Descriptors" |
3605 | .PP | |
3606 | The redirection operator | |
3607 | .RS | |
3608 | .PP | |
3609 | [\fIn\fP]\fB<&\fP\fIdigit\fP\fB\-\fP | |
3610 | .RE | |
3611 | .PP | |
3612 | moves the file descriptor \fIdigit\fP to file descriptor | |
3613 | .IR n , | |
3614 | or the standard input (file descriptor 0) if \fIn\fP is not specified. | |
3615 | \fIdigit\fP is closed after being duplicated to \fIn\fP. | |
3616 | .PP | |
3617 | Similarly, the redirection operator | |
3618 | .RS | |
3619 | .PP | |
3620 | [\fIn\fP]\fB>&\fP\fIdigit\fP\fB\-\fP | |
3621 | .RE | |
3622 | .PP | |
3623 | moves the file descriptor \fIdigit\fP to file descriptor | |
3624 | .IR n , | |
3625 | or the standard output (file descriptor 1) if \fIn\fP is not specified. | |
726f6388 JA |
3626 | .SS "Opening File Descriptors for Reading and Writing" |
3627 | .PP | |
3628 | The redirection operator | |
3629 | .RS | |
3630 | .PP | |
3631 | [\fIn\fP]\fB<>\fP\fIword\fP | |
3632 | .RE | |
3633 | .PP | |
3634 | causes the file whose name is the expansion of | |
3635 | .I word | |
3636 | to be opened for both reading and writing on file descriptor | |
3637 | .IR n , | |
ccc6cda3 | 3638 | or on file descriptor 0 if |
726f6388 JA |
3639 | .I n |
3640 | is not specified. If the file does not exist, it is created. | |
726f6388 | 3641 | .SH ALIASES |
bb70624e | 3642 | \fIAliases\fP allow a string to be substituted for a word when it is used |
cce855bc | 3643 | as the first word of a simple command. |
bb70624e | 3644 | The shell maintains a list of aliases that may be set and unset with the |
726f6388 JA |
3645 | .B alias |
3646 | and | |
3647 | .B unalias | |
3648 | builtin commands (see | |
3649 | .SM | |
3650 | .B SHELL BUILTIN COMMANDS | |
3651 | below). | |
de8913bd | 3652 | The first word of each simple command, if unquoted, |
726f6388 JA |
3653 | is checked to see if it has an |
3654 | alias. If so, that word is replaced by the text of the alias. | |
3d4e09aa | 3655 | The characters \fB/\fP, \fB$\fP, \fB\`\fP, and \fB=\fP and |
de8913bd CR |
3656 | any of the shell \fImetacharacters\fP or quoting characters |
3657 | listed above may not appear in an alias name. | |
3658 | The replacement text may contain any valid shell input, | |
3659 | including shell metacharacters. | |
3660 | The first word of the replacement text is tested | |
726f6388 | 3661 | for aliases, but a word that is identical to an alias being expanded |
de8913bd CR |
3662 | is not expanded a second time. |
3663 | This means that one may alias | |
726f6388 JA |
3664 | .B ls |
3665 | to | |
3666 | .BR "ls \-F" , | |
3667 | for instance, and | |
3668 | .B bash | |
3669 | does not try to recursively expand the replacement text. | |
3670 | If the last character of the alias value is a | |
3671 | .IR blank , | |
3672 | then the next command | |
3673 | word following the alias is also checked for alias expansion. | |
3674 | .PP | |
3675 | Aliases are created and listed with the | |
3676 | .B alias | |
3677 | command, and removed with the | |
3678 | .B unalias | |
3679 | command. | |
3680 | .PP | |
ccc6cda3 | 3681 | There is no mechanism for using arguments in the replacement text. |
bb70624e JA |
3682 | If arguments are needed, a shell function should be used (see |
3683 | .SM | |
3684 | .B FUNCTIONS | |
3685 | below). | |
726f6388 | 3686 | .PP |
ccc6cda3 JA |
3687 | Aliases are not expanded when the shell is not interactive, unless |
3688 | the | |
3689 | .B expand_aliases | |
3690 | shell option is set using | |
3691 | .B shopt | |
3692 | (see the description of | |
3693 | .B shopt | |
3694 | under | |
3695 | .SM | |
3696 | \fBSHELL BUILTIN COMMANDS\fP | |
3697 | below). | |
726f6388 JA |
3698 | .PP |
3699 | The rules concerning the definition and use of aliases are | |
3700 | somewhat confusing. | |
3701 | .B Bash | |
3702 | always reads at least one complete line | |
3703 | of input before executing any | |
3704 | of the commands on that line. Aliases are expanded when a | |
3705 | command is read, not when it is executed. Therefore, an | |
3706 | alias definition appearing on the same line as another | |
3707 | command does not take effect until the next line of input is read. | |
ccc6cda3 | 3708 | The commands following the alias definition |
726f6388 JA |
3709 | on that line are not affected by the new alias. |
3710 | This behavior is also an issue when functions are executed. | |
cce855bc | 3711 | Aliases are expanded when a function definition is read, |
726f6388 JA |
3712 | not when the function is executed, because a function definition |
3713 | is itself a compound command. As a consequence, aliases | |
3714 | defined in a function are not available until after that | |
3715 | function is executed. To be safe, always put | |
3716 | alias definitions on a separate line, and do not use | |
3717 | .B alias | |
3718 | in compound commands. | |
3719 | .PP | |
cce855bc | 3720 | For almost every purpose, aliases are superseded by |
726f6388 | 3721 | shell functions. |
ccc6cda3 JA |
3722 | .SH FUNCTIONS |
3723 | A shell function, defined as described above under | |
3724 | .SM | |
3725 | .BR "SHELL GRAMMAR" , | |
3726 | stores a series of commands for later execution. | |
bb70624e JA |
3727 | When the name of a shell function is used as a simple command name, |
3728 | the list of commands associated with that function name is executed. | |
ccc6cda3 JA |
3729 | Functions are executed in the context of the |
3730 | current shell; no new process is created to interpret | |
3731 | them (contrast this with the execution of a shell script). | |
3732 | When a function is executed, the arguments to the | |
3733 | function become the positional parameters | |
bb70624e JA |
3734 | during its execution. |
3735 | The special parameter | |
ccc6cda3 | 3736 | .B # |
de8913bd | 3737 | is updated to reflect the change. Special parameter 0 |
bb70624e | 3738 | is unchanged. |
d3a24ed2 | 3739 | The first element of the |
bb70624e JA |
3740 | .SM |
3741 | .B FUNCNAME | |
3742 | variable is set to the name of the function while the function | |
3743 | is executing. | |
4301bca7 | 3744 | .PP |
bb70624e | 3745 | All other aspects of the shell execution |
ccc6cda3 | 3746 | environment are identical between a function and its caller |
4301bca7 | 3747 | with these exceptions: the |
ccc6cda3 JA |
3748 | .SM |
3749 | .B DEBUG | |
76a8d78d CR |
3750 | and |
3751 | .B RETURN | |
3752 | traps (see the description of the | |
ccc6cda3 JA |
3753 | .B trap |
3754 | builtin under | |
3755 | .SM | |
3756 | .B SHELL BUILTIN COMMANDS | |
76a8d78d | 3757 | below) are not inherited unless the function has been given the |
7117c2d2 JA |
3758 | \fBtrace\fP attribute (see the description of the |
3759 | .SM | |
3760 | .B declare | |
d3a24ed2 CR |
3761 | builtin below) or the |
3762 | \fB\-o functrace\fP shell option has been enabled with | |
3763 | the \fBset\fP builtin | |
4301bca7 CR |
3764 | (in which case all functions inherit the \fBDEBUG\fP and \fBRETURN\fP traps), |
3765 | and the | |
3766 | .SM | |
3767 | .B ERR | |
3768 | trap is not inherited unless the \fB\-o errtrace\fP shell option has | |
3769 | been enabled. | |
726f6388 | 3770 | .PP |
ccc6cda3 JA |
3771 | Variables local to the function may be declared with the |
3772 | .B local | |
3773 | builtin command. Ordinarily, variables and their values | |
3774 | are shared between the function and its caller. | |
726f6388 | 3775 | .PP |
ccc6cda3 JA |
3776 | If the builtin command |
3777 | .B return | |
3778 | is executed in a function, the function completes and | |
3779 | execution resumes with the next command after the function | |
d3a24ed2 CR |
3780 | call. |
3781 | Any command associated with the \fBRETURN\fP trap is executed | |
3782 | before execution resumes. | |
3783 | When a function completes, the values of the | |
ccc6cda3 JA |
3784 | positional parameters and the special parameter |
3785 | .B # | |
cce855bc | 3786 | are restored to the values they had prior to the function's |
ccc6cda3 | 3787 | execution. |
726f6388 | 3788 | .PP |
ccc6cda3 JA |
3789 | Function names and definitions may be listed with the |
3790 | .B \-f | |
726f6388 | 3791 | option to the |
ccc6cda3 JA |
3792 | .B declare |
3793 | or | |
3794 | .B typeset | |
3795 | builtin commands. The | |
3796 | .B \-F | |
3797 | option to | |
3798 | .B declare | |
3799 | or | |
3800 | .B typeset | |
d3a24ed2 CR |
3801 | will list the function names only |
3802 | (and optionally the source file and line number, if the \fBextdebug\fP | |
3803 | shell option is enabled). | |
ccc6cda3 JA |
3804 | Functions may be exported so that subshells |
3805 | automatically have them defined with the | |
3806 | .B \-f | |
3807 | option to the | |
3808 | .B export | |
3809 | builtin. | |
11a6f9a9 CR |
3810 | A function definition may be deleted using the \fB\-f\fP option to |
3811 | the | |
3812 | .B unset | |
3813 | builtin. | |
d3a24ed2 CR |
3814 | Note that shell functions and variables with the same name may result |
3815 | in multiple identically-named entries in the environment passed to the | |
3816 | shell's children. | |
3817 | Care should be taken in cases where this may cause a problem. | |
726f6388 | 3818 | .PP |
ccc6cda3 JA |
3819 | Functions may be recursive. No limit is imposed on the number |
3820 | of recursive calls. | |
cce855bc JA |
3821 | .SH "ARITHMETIC EVALUATION" |
3822 | The shell allows arithmetic expressions to be evaluated, under | |
d3a24ed2 CR |
3823 | certain circumstances (see the \fBlet\fP and \fBdeclare\fP builtin |
3824 | commands and \fBArithmetic Expansion\fP). | |
7117c2d2 | 3825 | Evaluation is done in fixed-width integers with no check for overflow, |
cce855bc | 3826 | though division by 0 is trapped and flagged as an error. |
d3a24ed2 CR |
3827 | The operators and their precedence, associativity, and values |
3828 | are the same as in the C language. | |
cce855bc JA |
3829 | The following list of operators is grouped into levels of |
3830 | equal-precedence operators. | |
3831 | The levels are listed in order of decreasing precedence. | |
726f6388 | 3832 | .PP |
cce855bc JA |
3833 | .PD 0 |
3834 | .TP | |
bb70624e JA |
3835 | .B \fIid\fP++ \fIid\fP\-\- |
3836 | variable post-increment and post-decrement | |
3837 | .TP | |
3838 | .B ++\fIid\fP \-\-\fIid\fP | |
3839 | variable pre-increment and pre-decrement | |
3840 | .TP | |
cce855bc JA |
3841 | .B \- + |
3842 | unary minus and plus | |
3843 | .TP | |
3844 | .B ! ~ | |
3845 | logical and bitwise negation | |
3846 | .TP | |
3847 | .B ** | |
3848 | exponentiation | |
3849 | .TP | |
3850 | .B * / % | |
3851 | multiplication, division, remainder | |
3852 | .TP | |
3853 | .B + \- | |
3854 | addition, subtraction | |
3855 | .TP | |
3856 | .B << >> | |
3857 | left and right bitwise shifts | |
3858 | .TP | |
3859 | .B <= >= < > | |
3860 | comparison | |
3861 | .TP | |
3862 | .B == != | |
3863 | equality and inequality | |
3864 | .TP | |
3865 | .B & | |
3866 | bitwise AND | |
3867 | .TP | |
3868 | .B ^ | |
3869 | bitwise exclusive OR | |
3870 | .TP | |
3871 | .B | | |
3872 | bitwise OR | |
3873 | .TP | |
3874 | .B && | |
3875 | logical AND | |
3876 | .TP | |
3877 | .B || | |
3878 | logical OR | |
3879 | .TP | |
3880 | .B \fIexpr\fP?\fIexpr\fP:\fIexpr\fP | |
d3a24ed2 | 3881 | conditional operator |
cce855bc JA |
3882 | .TP |
3883 | .B = *= /= %= += \-= <<= >>= &= ^= |= | |
3884 | assignment | |
bb70624e JA |
3885 | .TP |
3886 | .B \fIexpr1\fP , \fIexpr2\fP | |
3887 | comma | |
cce855bc | 3888 | .PD |
ccc6cda3 | 3889 | .PP |
cce855bc | 3890 | Shell variables are allowed as operands; parameter expansion is |
bb70624e JA |
3891 | performed before the expression is evaluated. |
3892 | Within an expression, shell variables may also be referenced by name | |
3893 | without using the parameter expansion syntax. | |
d3a24ed2 CR |
3894 | A shell variable that is null or unset evaluates to 0 when referenced |
3895 | by name without using the parameter expansion syntax. | |
bb70624e | 3896 | The value of a variable is evaluated as an arithmetic expression |
d3a24ed2 CR |
3897 | when it is referenced, or when a variable which has been given the |
3898 | \fIinteger\fP attribute using \fBdeclare -i\fP is assigned a value. | |
3899 | A null value evaluates to 0. | |
bb70624e | 3900 | A shell variable need not have its integer attribute |
cce855bc | 3901 | turned on to be used in an expression. |
ccc6cda3 | 3902 | .PP |
cce855bc JA |
3903 | Constants with a leading 0 are interpreted as octal numbers. |
3904 | A leading 0x or 0X denotes hexadecimal. | |
3905 | Otherwise, numbers take the form [\fIbase#\fP]n, where \fIbase\fP | |
3906 | is a decimal number between 2 and 64 representing the arithmetic | |
3907 | base, and \fIn\fP is a number in that base. | |
bb70624e | 3908 | If \fIbase#\fP is omitted, then base 10 is used. |
cce855bc | 3909 | The digits greater than 9 are represented by the lowercase letters, |
f73dda09 | 3910 | the uppercase letters, @, and _, in that order. |
cce855bc | 3911 | If \fIbase\fP is less than or equal to 36, lowercase and uppercase |
f75912ae | 3912 | letters may be used interchangeably to represent numbers between 10 |
cce855bc | 3913 | and 35. |
ccc6cda3 | 3914 | .PP |
cce855bc JA |
3915 | Operators are evaluated in order of precedence. Sub-expressions in |
3916 | parentheses are evaluated first and may override the precedence | |
3917 | rules above. | |
3918 | .SH "CONDITIONAL EXPRESSIONS" | |
3919 | Conditional expressions are used by the \fB[[\fP compound command and | |
3920 | the \fBtest\fP and \fB[\fP builtin commands to test file attributes | |
3921 | and perform string and arithmetic comparisons. | |
3922 | Expressions are formed from the following unary or binary primaries. | |
3923 | If any \fIfile\fP argument to one of the primaries is of the form | |
bb70624e JA |
3924 | \fI/dev/fd/n\fP, then file descriptor \fIn\fP is checked. |
3925 | If the \fIfile\fP argument to one of the primaries is one of | |
3926 | \fI/dev/stdin\fP, \fI/dev/stdout\fP, or \fI/dev/stderr\fP, file | |
3927 | descriptor 0, 1, or 2, respectively, is checked. | |
be7d8f2d CR |
3928 | .PP |
3929 | Unless otherwise specified, primaries that operate on files follow symbolic | |
3930 | links and operate on the target of the link, rather than the link itself. | |
6bf8a8a7 CR |
3931 | .if t .sp 0.5 |
3932 | .if n .sp 1 | |
3933 | When used with \fB[[\fP, The \fB<\fP and \fB>\fP operators sort | |
3934 | lexicographically using the current locale. | |
cce855bc JA |
3935 | .sp 1 |
3936 | .PD 0 | |
3937 | .TP | |
3938 | .B \-a \fIfile\fP | |
3939 | True if \fIfile\fP exists. | |
3940 | .TP | |
3941 | .B \-b \fIfile\fP | |
3942 | True if \fIfile\fP exists and is a block special file. | |
3943 | .TP | |
3944 | .B \-c \fIfile\fP | |
3945 | True if \fIfile\fP exists and is a character special file. | |
3946 | .TP | |
3947 | .B \-d \fIfile\fP | |
3948 | True if \fIfile\fP exists and is a directory. | |
3949 | .TP | |
3950 | .B \-e \fIfile\fP | |
3951 | True if \fIfile\fP exists. | |
3952 | .TP | |
3953 | .B \-f \fIfile\fP | |
3954 | True if \fIfile\fP exists and is a regular file. | |
3955 | .TP | |
3956 | .B \-g \fIfile\fP | |
3957 | True if \fIfile\fP exists and is set-group-id. | |
3958 | .TP | |
b72432fd JA |
3959 | .B \-h \fIfile\fP |
3960 | True if \fIfile\fP exists and is a symbolic link. | |
3961 | .TP | |
cce855bc JA |
3962 | .B \-k \fIfile\fP |
3963 | True if \fIfile\fP exists and its ``sticky'' bit is set. | |
3964 | .TP | |
3965 | .B \-p \fIfile\fP | |
3966 | True if \fIfile\fP exists and is a named pipe (FIFO). | |
3967 | .TP | |
3968 | .B \-r \fIfile\fP | |
3969 | True if \fIfile\fP exists and is readable. | |
3970 | .TP | |
3971 | .B \-s \fIfile\fP | |
3972 | True if \fIfile\fP exists and has a size greater than zero. | |
3973 | .TP | |
3974 | .B \-t \fIfd\fP | |
3975 | True if file descriptor | |
3976 | .I fd | |
3977 | is open and refers to a terminal. | |
3978 | .TP | |
3979 | .B \-u \fIfile\fP | |
3980 | True if \fIfile\fP exists and its set-user-id bit is set. | |
3981 | .TP | |
3982 | .B \-w \fIfile\fP | |
3983 | True if \fIfile\fP exists and is writable. | |
3984 | .TP | |
3985 | .B \-x \fIfile\fP | |
3986 | True if \fIfile\fP exists and is executable. | |
3987 | .TP | |
cce855bc JA |
3988 | .B \-G \fIfile\fP |
3989 | True if \fIfile\fP exists and is owned by the effective group id. | |
3990 | .TP | |
3991 | .B \-L \fIfile\fP | |
3992 | True if \fIfile\fP exists and is a symbolic link. | |
3993 | .TP | |
5cdaaf76 CR |
3994 | .B \-N \fIfile\fP |
3995 | True if \fIfile\fP exists and has been modified since it was last read. | |
3996 | .TP | |
3997 | .B \-O \fIfile\fP | |
3998 | True if \fIfile\fP exists and is owned by the effective user id. | |
3999 | .TP | |
cce855bc JA |
4000 | .B \-S \fIfile\fP |
4001 | True if \fIfile\fP exists and is a socket. | |
4002 | .TP | |
5cdaaf76 CR |
4003 | \fIfile1\fP \fB\-ef\fP \fIfile2\fP |
4004 | True if \fIfile1\fP and \fIfile2\fP refer to the same device and | |
4005 | inode numbers. | |
cce855bc JA |
4006 | .TP |
4007 | \fIfile1\fP \-\fBnt\fP \fIfile2\fP | |
7117c2d2 JA |
4008 | True if \fIfile1\fP is newer (according to modification date) than \fIfile2\fP, |
4009 | or if \fIfile1\fP exists and \fPfile2\fP does not. | |
cce855bc JA |
4010 | .TP |
4011 | \fIfile1\fP \-\fBot\fP \fIfile2\fP | |
7117c2d2 JA |
4012 | True if \fIfile1\fP is older than \fIfile2\fP, or if \fIfile2\fP exists |
4013 | and \fIfile1\fP does not. | |
cce855bc | 4014 | .TP |
cce855bc JA |
4015 | .B \-o \fIoptname\fP |
4016 | True if shell option | |
4017 | .I optname | |
4018 | is enabled. | |
4019 | See the list of options under the description of the | |
4020 | .B \-o | |
4021 | option to the | |
4022 | .B set | |
4023 | builtin below. | |
4024 | .TP | |
4025 | .B \-z \fIstring\fP | |
4026 | True if the length of \fIstring\fP is zero. | |
4027 | .TP | |
cce855bc | 4028 | \fIstring\fP |
f085a21f CR |
4029 | .PD 0 |
4030 | .TP | |
4031 | .B \-n \fIstring\fP | |
4032 | .PD | |
cce855bc JA |
4033 | True if the length of |
4034 | .I string | |
4035 | is non-zero. | |
4036 | .TP | |
4037 | \fIstring1\fP \fB==\fP \fIstring2\fP | |
a3143574 CR |
4038 | .PD 0 |
4039 | .TP | |
4040 | \fIstring1\fP \fB=\fP \fIstring2\fP | |
4041 | .PD | |
4042 | True if the strings are equal. \fB=\fP should be used | |
4043 | with the \fBtest\fP command for POSIX conformance. | |
cce855bc JA |
4044 | .TP |
4045 | \fIstring1\fP \fB!=\fP \fIstring2\fP | |
4046 | True if the strings are not equal. | |
4047 | .TP | |
4048 | \fIstring1\fP \fB<\fP \fIstring2\fP | |
0d8616ff | 4049 | True if \fIstring1\fP sorts before \fIstring2\fP lexicographically. |
cce855bc JA |
4050 | .TP |
4051 | \fIstring1\fP \fB>\fP \fIstring2\fP | |
0d8616ff | 4052 | True if \fIstring1\fP sorts after \fIstring2\fP lexicographically. |
cce855bc JA |
4053 | .TP |
4054 | .I \fIarg1\fP \fBOP\fP \fIarg2\fP | |
4055 | .SM | |
4056 | .B OP | |
4057 | is one of | |
4058 | .BR \-eq , | |
4059 | .BR \-ne , | |
4060 | .BR \-lt , | |
4061 | .BR \-le , | |
4062 | .BR \-gt , | |
4063 | or | |
4064 | .BR \-ge . | |
4065 | These arithmetic binary operators return true if \fIarg1\fP | |
4066 | is equal to, not equal to, less than, less than or equal to, | |
4067 | greater than, or greater than or equal to \fIarg2\fP, respectively. | |
4068 | .I Arg1 | |
4069 | and | |
4070 | .I arg2 | |
4071 | may be positive or negative integers. | |
4072 | .PD | |
4073 | .SH "SIMPLE COMMAND EXPANSION" | |
4074 | When a simple command is executed, the shell performs the following | |
4075 | expansions, assignments, and redirections, from left to right. | |
4076 | .IP 1. | |
4077 | The words that the parser has marked as variable assignments (those | |
4078 | preceding the command name) and redirections are saved for later | |
4079 | processing. | |
4080 | .IP 2. | |
4081 | The words that are not variable assignments or redirections are | |
4082 | expanded. If any words remain after expansion, the first word | |
4083 | is taken to be the name of the command and the remaining words are | |
4084 | the arguments. | |
4085 | .IP 3. | |
4086 | Redirections are performed as described above under | |
4087 | .SM | |
4088 | .BR REDIRECTION . | |
4089 | .IP 4. | |
4090 | The text after the \fB=\fP in each variable assignment undergoes tilde | |
4091 | expansion, parameter expansion, command substitution, arithmetic expansion, | |
4092 | and quote removal before being assigned to the variable. | |
4093 | .PP | |
4094 | If no command name results, the variable assignments affect the current | |
4095 | shell environment. Otherwise, the variables are added to the environment | |
4096 | of the executed command and do not affect the current shell environment. | |
4097 | If any of the assignments attempts to assign a value to a readonly variable, | |
4098 | an error occurs, and the command exits with a non-zero status. | |
4099 | .PP | |
4100 | If no command name results, redirections are performed, but do not | |
4101 | affect the current shell environment. A redirection error causes the | |
4102 | command to exit with a non-zero status. | |
4103 | .PP | |
4104 | If there is a command name left after expansion, execution proceeds as | |
4105 | described below. Otherwise, the command exits. If one of the expansions | |
4106 | contained a command substitution, the exit status of the command is | |
4107 | the exit status of the last command substitution performed. If there | |
4108 | were no command substitutions, the command exits with a status of zero. | |
4109 | .SH "COMMAND EXECUTION" | |
4110 | After a command has been split into words, if it results in a | |
4111 | simple command and an optional list of arguments, the following | |
4112 | actions are taken. | |
4113 | .PP | |
4114 | If the command name contains no slashes, the shell attempts to | |
4115 | locate it. If there exists a shell function by that name, that | |
4116 | function is invoked as described above in | |
4117 | .SM | |
4118 | .BR FUNCTIONS . | |
4119 | If the name does not match a function, the shell searches for | |
4120 | it in the list of shell builtins. If a match is found, that | |
4121 | builtin is invoked. | |
4122 | .PP | |
4123 | If the name is neither a shell function nor a builtin, | |
4124 | and contains no slashes, | |
4125 | .B bash | |
4126 | searches each element of the | |
4127 | .SM | |
4128 | .B PATH | |
4129 | for a directory containing an executable file by that name. | |
4130 | .B Bash | |
bb70624e | 4131 | uses a hash table to remember the full pathnames of executable |
cce855bc JA |
4132 | files (see |
4133 | .B hash | |
4134 | under | |
4135 | .SM | |
4136 | .B "SHELL BUILTIN COMMANDS" | |
4137 | below). | |
4138 | A full search of the directories in | |
4139 | .SM | |
4140 | .B PATH | |
4141 | is performed only if the command is not found in the hash table. | |
245a493c CR |
4142 | If the search is unsuccessful, the shell searches for a defined shell |
4143 | function named \fBcommand_not_found_handle\fP. | |
4144 | If that function exists, it is invoked with the original command and | |
4145 | the original command's arguments as its arguments, and the function's | |
4146 | exit status becomes the exit status of the shell. | |
4147 | If that function is not defined, the shell prints an error | |
cce855bc JA |
4148 | message and returns an exit status of 127. |
4149 | .PP | |
4150 | If the search is successful, or if the command name contains | |
4151 | one or more slashes, the shell executes the named program in a | |
4152 | separate execution environment. | |
4153 | Argument 0 is set to the name given, and the remaining arguments | |
4154 | to the command are set to the arguments given, if any. | |
4155 | .PP | |
4156 | If this execution fails because the file is not in executable | |
4157 | format, and the file is not a directory, it is assumed to be | |
4158 | a \fIshell script\fP, a file | |
4159 | containing shell commands. A subshell is spawned to execute | |
4160 | it. This subshell reinitializes itself, so | |
4161 | that the effect is as if a new shell had been invoked | |
4162 | to handle the script, with the exception that the locations of | |
4163 | commands remembered by the parent (see | |
4164 | .B hash | |
4165 | below under | |
4166 | .SM | |
4167 | \fBSHELL BUILTIN COMMANDS\fP) | |
4168 | are retained by the child. | |
4169 | .PP | |
4170 | If the program is a file beginning with | |
4171 | .BR #! , | |
4172 | the remainder of the first line specifies an interpreter | |
4173 | for the program. The shell executes the | |
4174 | specified interpreter on operating systems that do not | |
4175 | handle this executable format themselves. The arguments to the | |
4176 | interpreter consist of a single optional argument following the | |
4177 | interpreter name on the first line of the program, followed | |
4178 | by the name of the program, followed by the command | |
4179 | arguments, if any. | |
4180 | .SH COMMAND EXECUTION ENVIRONMENT | |
4181 | The shell has an \fIexecution environment\fP, which consists of the | |
4182 | following: | |
984a1947 | 4183 | .if n .sp 1 |
cce855bc JA |
4184 | .IP \(bu |
4185 | open files inherited by the shell at invocation, as modified by | |
4186 | redirections supplied to the \fBexec\fP builtin | |
4187 | .IP \(bu | |
4188 | the current working directory as set by \fBcd\fP, \fBpushd\fP, or | |
4189 | \fBpopd\fP, or inherited by the shell at invocation | |
4190 | .IP \(bu | |
4191 | the file creation mode mask as set by \fBumask\fP or inherited from | |
4192 | the shell's parent | |
4193 | .IP \(bu | |
4194 | current traps set by \fBtrap\fP | |
4195 | .IP \(bu | |
4196 | shell parameters that are set by variable assignment or with \fBset\fP | |
4197 | or inherited from the shell's parent in the environment | |
4198 | .IP \(bu | |
4199 | shell functions defined during execution or inherited from the shell's | |
4200 | parent in the environment | |
4201 | .IP \(bu | |
4202 | options enabled at invocation (either by default or with command-line | |
4203 | arguments) or by \fBset\fP | |
4204 | .IP \(bu | |
4205 | options enabled by \fBshopt\fP | |
4206 | .IP \(bu | |
4207 | shell aliases defined with \fBalias\fP | |
4208 | .IP \(bu | |
4209 | various process IDs, including those of background jobs, the value | |
984a1947 CR |
4210 | of \fB$$\fP, and the value of |
4211 | .SM | |
4212 | .B PPID | |
cce855bc JA |
4213 | .PP |
4214 | When a simple command other than a builtin or shell function | |
4215 | is to be executed, it | |
4216 | is invoked in a separate execution environment that consists of | |
4217 | the following. Unless otherwise noted, the values are inherited | |
4218 | from the shell. | |
984a1947 | 4219 | .if n .sp 1 |
cce855bc JA |
4220 | .IP \(bu |
4221 | the shell's open files, plus any modifications and additions specified | |
4222 | by redirections to the command | |
4223 | .IP \(bu | |
4224 | the current working directory | |
4225 | .IP \(bu | |
4226 | the file creation mode mask | |
4227 | .IP \(bu | |
d3a24ed2 CR |
4228 | shell variables and functions marked for export, along with variables |
4229 | exported for the command, passed in the environment | |
cce855bc | 4230 | .IP \(bu |
d3a24ed2 CR |
4231 | traps caught by the shell are reset to the values inherited from the |
4232 | shell's parent, and traps ignored by the shell are ignored | |
cce855bc JA |
4233 | .PP |
4234 | A command invoked in this separate environment cannot affect the | |
4235 | shell's execution environment. | |
4236 | .PP | |
d3a24ed2 CR |
4237 | Command substitution, commands grouped with parentheses, |
4238 | and asynchronous commands are invoked in a | |
cce855bc JA |
4239 | subshell environment that is a duplicate of the shell environment, |
4240 | except that traps caught by the shell are reset to the values | |
4241 | that the shell inherited from its parent at invocation. Builtin | |
4242 | commands that are invoked as part of a pipeline are also executed in a | |
4243 | subshell environment. Changes made to the subshell environment | |
4244 | cannot affect the shell's execution environment. | |
f73dda09 | 4245 | .PP |
012bac39 CR |
4246 | Subshells spawned to execute command substitutions inherit the value of |
4247 | the \fB\-e\fP option from the parent shell. When not in posix mode, | |
4248 | Bash clears the \fB\-e\fP option in such subshells. | |
4249 | .PP | |
f73dda09 JA |
4250 | If a command is followed by a \fB&\fP and job control is not active, the |
4251 | default standard input for the command is the empty file \fI/dev/null\fP. | |
4252 | Otherwise, the invoked command inherits the file descriptors of the calling | |
4253 | shell as modified by redirections. | |
cce855bc JA |
4254 | .SH ENVIRONMENT |
4255 | When a program is invoked it is given an array of strings | |
4256 | called the | |
4257 | .IR environment . | |
4258 | This is a list of | |
4259 | \fIname\fP\-\fIvalue\fP pairs, of the form | |
4260 | .IR "name\fR=\fPvalue" . | |
4261 | .PP | |
bb70624e JA |
4262 | The shell provides several ways to manipulate the environment. |
4263 | On invocation, the shell scans its own environment and | |
cce855bc JA |
4264 | creates a parameter for each name found, automatically marking |
4265 | it for | |
4266 | .I export | |
4267 | to child processes. Executed commands inherit the environment. | |
4268 | The | |
4269 | .B export | |
4270 | and | |
4271 | .B declare \-x | |
4272 | commands allow parameters and functions to be added to and | |
4273 | deleted from the environment. If the value of a parameter | |
4274 | in the environment is modified, the new value becomes part | |
4275 | of the environment, replacing the old. The environment | |
4276 | inherited by any executed command consists of the shell's | |
4277 | initial environment, whose values may be modified in the shell, | |
4278 | less any pairs removed by the | |
4279 | .B unset | |
4280 | command, plus any additions via the | |
4281 | .B export | |
4282 | and | |
4283 | .B declare \-x | |
4284 | commands. | |
4285 | .PP | |
4286 | The environment for any | |
4287 | .I simple command | |
4288 | or function may be augmented temporarily by prefixing it with | |
4289 | parameter assignments, as described above in | |
4290 | .SM | |
4291 | .BR PARAMETERS . | |
4292 | These assignment statements affect only the environment seen | |
4293 | by that command. | |
4294 | .PP | |
4295 | If the | |
4296 | .B \-k | |
4297 | option is set (see the | |
4298 | .B set | |
4299 | builtin command below), then | |
4300 | .I all | |
4301 | parameter assignments are placed in the environment for a command, | |
4302 | not just those that precede the command name. | |
4303 | .PP | |
4304 | When | |
4305 | .B bash | |
4306 | invokes an external command, the variable | |
4307 | .B _ | |
4308 | is set to the full file name of the command and passed to that | |
ccc6cda3 JA |
4309 | command in its environment. |
4310 | .SH "EXIT STATUS" | |
35ee8ea0 CR |
4311 | .PP |
4312 | The exit status of an executed command is the value returned by the | |
4313 | \fIwaitpid\fP system call or equivalent function. Exit statuses | |
4314 | fall between 0 and 255, though, as explained below, the shell may | |
4315 | use values above 125 specially. Exit statuses from shell builtins and | |
4316 | compound commands are also limited to this range. Under certain | |
4317 | circumstances, the shell will use special values to indicate specific | |
4318 | failure modes. | |
4319 | .PP | |
cce855bc | 4320 | For the shell's purposes, a command which exits with a |
ccc6cda3 JA |
4321 | zero exit status has succeeded. An exit status of zero |
4322 | indicates success. A non-zero exit status indicates failure. | |
bb70624e JA |
4323 | When a command terminates on a fatal signal \fIN\fP, \fBbash\fP uses |
4324 | the value of 128+\fIN\fP as the exit status. | |
ccc6cda3 JA |
4325 | .PP |
4326 | If a command is not found, the child process created to | |
4327 | execute it returns a status of 127. If a command is found | |
4328 | but is not executable, the return status is 126. | |
4329 | .PP | |
cce855bc JA |
4330 | If a command fails because of an error during expansion or redirection, |
4331 | the exit status is greater than zero. | |
4332 | .PP | |
ccc6cda3 JA |
4333 | Shell builtin commands return a status of 0 (\fItrue\fP) if |
4334 | successful, and non-zero (\fIfalse\fP) if an error occurs | |
4335 | while they execute. | |
4336 | All builtins return an exit status of 2 to indicate incorrect usage. | |
4337 | .PP | |
4338 | \fBBash\fP itself returns the exit status of the last command | |
4339 | executed, unless a syntax error occurs, in which case it exits | |
4340 | with a non-zero value. See also the \fBexit\fP builtin | |
4341 | command below. | |
4342 | .SH SIGNALS | |
cce855bc | 4343 | When \fBbash\fP is interactive, in the absence of any traps, it ignores |
ccc6cda3 JA |
4344 | .SM |
4345 | .B SIGTERM | |
4346 | (so that \fBkill 0\fP does not kill an interactive shell), | |
4347 | and | |
4348 | .SM | |
4349 | .B SIGINT | |
4350 | is caught and handled (so that the \fBwait\fP builtin is interruptible). | |
4351 | In all cases, \fBbash\fP ignores | |
4352 | .SM | |
4353 | .BR SIGQUIT . | |
4354 | If job control is in effect, | |
4355 | .B bash | |
4356 | ignores | |
4357 | .SM | |
4358 | .BR SIGTTIN , | |
4359 | .SM | |
4360 | .BR SIGTTOU , | |
4361 | and | |
4362 | .SM | |
4363 | .BR SIGTSTP . | |
4364 | .PP | |
5e13499c | 4365 | Non-builtin commands run by \fBbash\fP have signal handlers |
cce855bc JA |
4366 | set to the values inherited by the shell from its parent. |
4367 | When job control is not in effect, asynchronous commands | |
ccc6cda3 JA |
4368 | ignore |
4369 | .SM | |
4370 | .B SIGINT | |
4371 | and | |
4372 | .SM | |
cce855bc | 4373 | .B SIGQUIT |
5e13499c | 4374 | in addition to these inherited handlers. |
ccc6cda3 JA |
4375 | Commands run as a result of command substitution ignore the |
4376 | keyboard-generated job control signals | |
4377 | .SM | |
4378 | .BR SIGTTIN , | |
4379 | .SM | |
4380 | .BR SIGTTOU , | |
4381 | and | |
4382 | .SM | |
4383 | .BR SIGTSTP . | |
4384 | .PP | |
4385 | The shell exits by default upon receipt of a | |
4386 | .SM | |
4387 | .BR SIGHUP . | |
f73dda09 | 4388 | Before exiting, an interactive shell resends the |
ccc6cda3 JA |
4389 | .SM |
4390 | .B SIGHUP | |
cce855bc JA |
4391 | to all jobs, running or stopped. |
4392 | Stopped jobs are sent | |
4393 | .SM | |
4394 | .B SIGCONT | |
4395 | to ensure that they receive the | |
4396 | .SM | |
4397 | .BR SIGHUP . | |
4398 | To prevent the shell from | |
4399 | sending the signal to a particular job, it should be removed from the | |
ccc6cda3 JA |
4400 | jobs table with the |
4401 | .B disown | |
4402 | builtin (see | |
4403 | .SM | |
4404 | .B "SHELL BUILTIN COMMANDS" | |
cce855bc JA |
4405 | below) or marked |
4406 | to not receive | |
ccc6cda3 | 4407 | .SM |
cce855bc JA |
4408 | .B SIGHUP |
4409 | using | |
4410 | .BR "disown \-h" . | |
4411 | .PP | |
4412 | If the | |
4413 | .B huponexit | |
4414 | shell option has been set with | |
4415 | .BR shopt , | |
4416 | .B bash | |
4417 | sends a | |
4418 | .SM | |
4419 | .B SIGHUP | |
4420 | to all jobs when an interactive login shell exits. | |
4421 | .PP | |
b66cc816 | 4422 | If \fBbash\fP is waiting for a command to complete and receives a signal |
5e13499c CR |
4423 | for which a trap has been set, the trap will not be executed until |
4424 | the command completes. | |
cce855bc JA |
4425 | When \fBbash\fP is waiting for an asynchronous command via the \fBwait\fP |
4426 | builtin, the reception of a signal for which a trap has been set will | |
4427 | cause the \fBwait\fP builtin to return immediately with an exit status | |
4428 | greater than 128, immediately after which the trap is executed. | |
ccc6cda3 JA |
4429 | .SH "JOB CONTROL" |
4430 | .I Job control | |
4431 | refers to the ability to selectively stop (\fIsuspend\fP) | |
4432 | the execution of processes and continue (\fIresume\fP) | |
4433 | their execution at a later point. A user typically employs | |
4434 | this facility via an interactive interface supplied jointly | |
602bb739 | 4435 | by the operating system kernel's terminal driver and |
ccc6cda3 JA |
4436 | .BR bash . |
4437 | .PP | |
4438 | The shell associates a | |
4439 | .I job | |
4440 | with each pipeline. It keeps a table of currently executing | |
4441 | jobs, which may be listed with the | |
4442 | .B jobs | |
4443 | command. When | |
4444 | .B bash | |
4445 | starts a job asynchronously (in the | |
4446 | .IR background ), | |
4447 | it prints a line that looks like: | |
4448 | .RS | |
4449 | .PP | |
4450 | [1] 25647 | |
4451 | .RE | |
4452 | .PP | |
4453 | indicating that this job is job number 1 and that the process ID | |
4454 | of the last process in the pipeline associated with this job is 25647. | |
4455 | All of the processes in a single pipeline are members of the same job. | |
4456 | .B Bash | |
4457 | uses the | |
4458 | .I job | |
4459 | abstraction as the basis for job control. | |
4460 | .PP | |
4461 | To facilitate the implementation of the user interface to job | |
bb70624e | 4462 | control, the operating system maintains the notion of a \fIcurrent terminal |
ccc6cda3 JA |
4463 | process group ID\fP. Members of this process group (processes whose |
4464 | process group ID is equal to the current terminal process group ID) | |
4465 | receive keyboard-generated signals such as | |
4466 | .SM | |
4467 | .BR SIGINT . | |
4468 | These processes are said to be in the | |
4469 | .IR foreground . | |
4470 | .I Background | |
4471 | processes are those whose process group ID differs from the terminal's; | |
4472 | such processes are immune to keyboard-generated signals. | |
602bb739 CR |
4473 | Only foreground processes are allowed to read from or, if the |
4474 | user so specifies with \f(CWstty tostop\fP, write to the | |
4475 | terminal. | |
4476 | Background processes which attempt to read from (write to when | |
4477 | \f(CWstty tostop\fP is in effect) the | |
ccc6cda3 JA |
4478 | terminal are sent a |
4479 | .SM | |
4480 | .B SIGTTIN (SIGTTOU) | |
602bb739 | 4481 | signal by the kernel's terminal driver, |
ccc6cda3 JA |
4482 | which, unless caught, suspends the process. |
4483 | .PP | |
4484 | If the operating system on which | |
4485 | .B bash | |
4486 | is running supports | |
4487 | job control, | |
4488 | .B bash | |
bb70624e | 4489 | contains facilities to use it. |
ccc6cda3 JA |
4490 | Typing the |
4491 | .I suspend | |
4492 | character (typically | |
4493 | .BR ^Z , | |
4494 | Control-Z) while a process is running | |
bb70624e | 4495 | causes that process to be stopped and returns control to |
ccc6cda3 JA |
4496 | .BR bash . |
4497 | Typing the | |
4498 | .I "delayed suspend" | |
4499 | character (typically | |
4500 | .BR ^Y , | |
4501 | Control-Y) causes the process to be stopped when it | |
4502 | attempts to read input from the terminal, and control to | |
4503 | be returned to | |
4504 | .BR bash . | |
cce855bc | 4505 | The user may then manipulate the state of this job, using the |
ccc6cda3 JA |
4506 | .B bg |
4507 | command to continue it in the background, the | |
4508 | .B fg | |
4509 | command to continue it in the foreground, or | |
4510 | the | |
4511 | .B kill | |
4512 | command to kill it. A \fB^Z\fP takes effect immediately, | |
4513 | and has the additional side effect of causing pending output | |
4514 | and typeahead to be discarded. | |
4515 | .PP | |
4516 | There are a number of ways to refer to a job in the shell. | |
4517 | The character | |
4518 | .B % | |
8e1a6eaa | 4519 | introduces a job specification (\fIjobspec\fP). Job number |
ccc6cda3 JA |
4520 | .I n |
4521 | may be referred to as | |
4522 | .BR %n . | |
4523 | A job may also be referred to using a prefix of the name used to | |
4524 | start it, or using a substring that appears in its command line. | |
4525 | For example, | |
4526 | .B %ce | |
4527 | refers to a stopped | |
4528 | .B ce | |
4529 | job. If a prefix matches more than one job, | |
4530 | .B bash | |
4531 | reports an error. Using | |
4532 | .BR %?ce , | |
4533 | on the other hand, refers to any job containing the string | |
4534 | .B ce | |
4535 | in its command line. If the substring matches more than one job, | |
4536 | .B bash | |
4537 | reports an error. The symbols | |
4538 | .B %% | |
4539 | and | |
4540 | .B %+ | |
4541 | refer to the shell's notion of the | |
4542 | .IR "current job" , | |
4543 | which is the last job stopped while it was in | |
cce855bc | 4544 | the foreground or started in the background. |
ccc6cda3 JA |
4545 | The |
4546 | .I "previous job" | |
4547 | may be referenced using | |
4548 | .BR %\- . | |
e33f2203 CR |
4549 | If there is only a single job, \fB%+\fP and \fB%\-\fP can both be used |
4550 | to refer to that job. | |
ccc6cda3 JA |
4551 | In output pertaining to jobs (e.g., the output of the |
4552 | .B jobs | |
4553 | command), the current job is always flagged with a | |
4554 | .BR + , | |
4555 | and the previous job with a | |
4556 | .BR \- . | |
43df7bbb CR |
4557 | A single % (with no accompanying job specification) also refers to the |
4558 | current job. | |
726f6388 | 4559 | .PP |
ccc6cda3 JA |
4560 | Simply naming a job can be used to bring it into the |
4561 | foreground: | |
4562 | .B %1 | |
4563 | is a synonym for | |
4564 | \fB``fg %1''\fP, | |
4565 | bringing job 1 from the background into the foreground. | |
4566 | Similarly, | |
4567 | .B ``%1 &'' | |
4568 | resumes job 1 in the background, equivalent to | |
4569 | \fB``bg %1''\fP. | |
726f6388 | 4570 | .PP |
ccc6cda3 JA |
4571 | The shell learns immediately whenever a job changes state. |
4572 | Normally, | |
4573 | .B bash | |
4574 | waits until it is about to print a prompt before reporting | |
4575 | changes in a job's status so as to not interrupt | |
4576 | any other output. If the | |
4577 | .B \-b | |
4578 | option to the | |
726f6388 | 4579 | .B set |
ccc6cda3 | 4580 | builtin command |
cce855bc | 4581 | is enabled, |
726f6388 | 4582 | .B bash |
ccc6cda3 | 4583 | reports such changes immediately. |
f73dda09 JA |
4584 | Any trap on |
4585 | .SM | |
4586 | .B SIGCHLD | |
4587 | is executed for each child that exits. | |
726f6388 | 4588 | .PP |
ccc6cda3 JA |
4589 | If an attempt to exit |
4590 | .B bash | |
d3ad40de CR |
4591 | is made while jobs are stopped (or, if the \fBcheckjobs\fP shell option has |
4592 | been enabled using the \fBshopt\fP builtin, running), the shell prints a | |
4593 | warning message, and, if the \fBcheckjobs\fP option is enabled, lists the | |
4594 | jobs and their statuses. | |
4595 | The | |
ccc6cda3 | 4596 | .B jobs |
d3ad40de | 4597 | command may then be used to inspect their status. |
ccc6cda3 | 4598 | If a second attempt to exit is made without an intervening command, |
d3ad40de | 4599 | the shell does not print another warning, and any stopped |
ccc6cda3 | 4600 | jobs are terminated. |
726f6388 JA |
4601 | .SH PROMPTING |
4602 | When executing interactively, | |
4603 | .B bash | |
4604 | displays the primary prompt | |
4605 | .SM | |
4606 | .B PS1 | |
4607 | when it is ready to read a command, and the secondary prompt | |
4608 | .SM | |
4609 | .B PS2 | |
4610 | when it needs more input to complete a command. | |
4611 | .B Bash | |
4612 | allows these prompt strings to be customized by inserting a number of | |
4613 | backslash-escaped special characters that are decoded as follows: | |
4614 | .RS | |
4615 | .PD 0 | |
4616 | .TP | |
ccc6cda3 JA |
4617 | .B \ea |
4618 | an ASCII bell character (07) | |
726f6388 JA |
4619 | .TP |
4620 | .B \ed | |
4621 | the date in "Weekday Month Date" format (e.g., "Tue May 26") | |
4622 | .TP | |
7117c2d2 JA |
4623 | .B \eD{\fIformat\fP} |
4624 | the \fIformat\fP is passed to \fIstrftime\fP(3) and the result is inserted | |
4625 | into the prompt string; an empty \fIformat\fP results in a locale-specific | |
4626 | time representation. The braces are required | |
4627 | .TP | |
ccc6cda3 JA |
4628 | .B \ee |
4629 | an ASCII escape character (033) | |
4630 | .TP | |
4631 | .B \eh | |
4632 | the hostname up to the first `.' | |
4633 | .TP | |
4634 | .B \eH | |
4635 | the hostname | |
4636 | .TP | |
bb70624e JA |
4637 | .B \ej |
4638 | the number of jobs currently managed by the shell | |
4639 | .TP | |
4640 | .B \el | |
4641 | the basename of the shell's terminal device name | |
4642 | .TP | |
726f6388 JA |
4643 | .B \en |
4644 | newline | |
4645 | .TP | |
cce855bc JA |
4646 | .B \er |
4647 | carriage return | |
4648 | .TP | |
726f6388 JA |
4649 | .B \es |
4650 | the name of the shell, the basename of | |
4651 | .B $0 | |
4652 | (the portion following the final slash) | |
4653 | .TP | |
ccc6cda3 JA |
4654 | .B \et |
4655 | the current time in 24-hour HH:MM:SS format | |
726f6388 | 4656 | .TP |
ccc6cda3 JA |
4657 | .B \eT |
4658 | the current time in 12-hour HH:MM:SS format | |
4659 | .TP | |
4660 | .B \e@ | |
4661 | the current time in 12-hour am/pm format | |
726f6388 | 4662 | .TP |
f73dda09 JA |
4663 | .B \eA |
4664 | the current time in 24-hour HH:MM format | |
4665 | .TP | |
726f6388 JA |
4666 | .B \eu |
4667 | the username of the current user | |
4668 | .TP | |
ccc6cda3 JA |
4669 | .B \ev |
4670 | the version of \fBbash\fP (e.g., 2.00) | |
726f6388 | 4671 | .TP |
ccc6cda3 | 4672 | .B \eV |
a5e25162 | 4673 | the release of \fBbash\fP, version + patch level (e.g., 2.00.0) |
ccc6cda3 JA |
4674 | .TP |
4675 | .B \ew | |
984a1947 CR |
4676 | the current working directory, with |
4677 | .SM | |
4678 | .B $HOME | |
4679 | abbreviated with a tilde | |
4680 | (uses the value of the | |
4681 | .SM | |
4682 | .B PROMPT_DIRTRIM | |
4683 | variable) | |
ccc6cda3 JA |
4684 | .TP |
4685 | .B \eW | |
984a1947 CR |
4686 | the basename of the current working directory, with |
4687 | .SM | |
4688 | .B $HOME | |
12d937f9 | 4689 | abbreviated with a tilde |
726f6388 JA |
4690 | .TP |
4691 | .B \e! | |
4692 | the history number of this command | |
4693 | .TP | |
ccc6cda3 JA |
4694 | .B \e# |
4695 | the command number of this command | |
4696 | .TP | |
726f6388 JA |
4697 | .B \e$ |
4698 | if the effective UID is 0, a | |
4699 | .BR # , | |
4700 | otherwise a | |
4701 | .B $ | |
4702 | .TP | |
ccc6cda3 JA |
4703 | .B \e\fInnn\fP |
4704 | the character corresponding to the octal number \fInnn\fP | |
726f6388 JA |
4705 | .TP |
4706 | .B \e\e | |
4707 | a backslash | |
4708 | .TP | |
4709 | .B \e[ | |
4710 | begin a sequence of non-printing characters, which could be used to | |
4711 | embed a terminal control sequence into the prompt | |
4712 | .TP | |
4713 | .B \e] | |
4714 | end a sequence of non-printing characters | |
4715 | .PD | |
4716 | .RE | |
4717 | .PP | |
4718 | The command number and the history number are usually different: | |
4719 | the history number of a command is its position in the history | |
4720 | list, which may include commands restored from the history file | |
4721 | (see | |
4722 | .SM | |
4723 | .B HISTORY | |
4724 | below), while the command number is the position in the sequence | |
4725 | of commands executed during the current shell session. | |
4726 | After the string is decoded, it is expanded via | |
bb70624e JA |
4727 | parameter expansion, command substitution, arithmetic |
4728 | expansion, and quote removal, subject to the value of the | |
ccc6cda3 JA |
4729 | .B promptvars |
4730 | shell option (see the description of the | |
4731 | .B shopt | |
4732 | command under | |
4733 | .SM | |
4734 | .B "SHELL BUILTIN COMMANDS" | |
4735 | below). | |
726f6388 JA |
4736 | .SH READLINE |
4737 | This is the library that handles reading input when using an interactive | |
4738 | shell, unless the | |
d166f048 | 4739 | .B \-\-noediting |
ccc6cda3 | 4740 | option is given at shell invocation. |
14e8b2a7 CR |
4741 | Line editing is also used when using the \fB\-e\fP option to the |
4742 | \fBread\fP builtin. | |
ccc6cda3 | 4743 | By default, the line editing commands are similar to those of emacs. |
726f6388 | 4744 | A vi-style line editing interface is also available. |
14e8b2a7 CR |
4745 | Line editing can be enabled at any time using the |
4746 | .B \-o emacs | |
ccc6cda3 | 4747 | or |
14e8b2a7 | 4748 | .B \-o vi |
ccc6cda3 JA |
4749 | options to the |
4750 | .B set | |
4751 | builtin (see | |
4752 | .SM | |
4753 | .B SHELL BUILTIN COMMANDS | |
4754 | below). | |
14e8b2a7 CR |
4755 | To turn off line editing after the shell is running, use the |
4756 | .B +o emacs | |
4757 | or | |
4758 | .B +o vi | |
4759 | options to the | |
4760 | .B set | |
4761 | builtin. | |
ccc6cda3 | 4762 | .SS "Readline Notation" |
726f6388 JA |
4763 | .PP |
4764 | In this section, the emacs-style notation is used to denote | |
4765 | keystrokes. Control keys are denoted by C\-\fIkey\fR, e.g., C\-n | |
4766 | means Control\-N. Similarly, | |
4767 | .I meta | |
4768 | keys are denoted by M\-\fIkey\fR, so M\-x means Meta\-X. (On keyboards | |
4769 | without a | |
4770 | .I meta | |
4771 | key, M\-\fIx\fP means ESC \fIx\fP, i.e., press the Escape key | |
4772 | then the | |
4773 | .I x | |
4774 | key. This makes ESC the \fImeta prefix\fP. | |
4775 | The combination M\-C\-\fIx\fP means ESC\-Control\-\fIx\fP, | |
4776 | or press the Escape key | |
4777 | then hold the Control key while pressing the | |
4778 | .I x | |
4779 | key.) | |
4780 | .PP | |
ccc6cda3 JA |
4781 | Readline commands may be given numeric |
4782 | .IR arguments , | |
4783 | which normally act as a repeat count. | |
4784 | Sometimes, however, it is the sign of the argument that is significant. | |
4785 | Passing a negative argument to a command that acts in the forward | |
4786 | direction (e.g., \fBkill\-line\fP) causes that command to act in a | |
4787 | backward direction. | |
4788 | Commands whose behavior with arguments deviates from this are noted | |
4789 | below. | |
4790 | .PP | |
4791 | When a command is described as \fIkilling\fP text, the text | |
4792 | deleted is saved for possible future retrieval | |
4793 | (\fIyanking\fP). The killed text is saved in a | |
4794 | \fIkill ring\fP. Consecutive kills cause the text to be | |
4795 | accumulated into one unit, which can be yanked all at once. | |
4796 | Commands which do not kill text separate the chunks of text | |
4797 | on the kill ring. | |
4798 | .SS "Readline Initialization" | |
4799 | .PP | |
4800 | Readline is customized by putting commands in an initialization | |
4801 | file (the \fIinputrc\fP file). | |
4802 | The name of this file is taken from the value of the | |
726f6388 | 4803 | .SM |
ccc6cda3 JA |
4804 | .B INPUTRC |
4805 | variable. If that variable is unset, the default is | |
726f6388 | 4806 | .IR ~/.inputrc . |
ccc6cda3 JA |
4807 | When a program which uses the readline library starts up, the |
4808 | initialization file is read, and the key bindings and variables | |
4809 | are set. | |
4810 | There are only a few basic constructs allowed in the | |
4811 | readline initialization file. | |
4812 | Blank lines are ignored. | |
4813 | Lines beginning with a \fB#\fP are comments. | |
4814 | Lines beginning with a \fB$\fP indicate conditional constructs. | |
4815 | Other lines denote key bindings and variable settings. | |
4816 | .PP | |
4817 | The default key-bindings may be changed with an | |
4818 | .I inputrc | |
4819 | file. | |
726f6388 JA |
4820 | Other programs that use this library may add their own commands |
4821 | and bindings. | |
4822 | .PP | |
4823 | For example, placing | |
4824 | .RS | |
4825 | .PP | |
4826 | M\-Control\-u: universal\-argument | |
4827 | .RE | |
4828 | or | |
4829 | .RS | |
4830 | C\-Meta\-u: universal\-argument | |
4831 | .RE | |
4832 | into the | |
ccc6cda3 | 4833 | .I inputrc |
726f6388 JA |
4834 | would make M\-C\-u execute the readline command |
4835 | .IR universal\-argument . | |
4836 | .PP | |
4837 | The following symbolic character names are recognized: | |
4838 | .IR RUBOUT , | |
4839 | .IR DEL , | |
4840 | .IR ESC , | |
4841 | .IR LFD , | |
4842 | .IR NEWLINE , | |
4843 | .IR RET , | |
4844 | .IR RETURN , | |
4845 | .IR SPC , | |
4846 | .IR SPACE , | |
4847 | and | |
4848 | .IR TAB . | |
bb70624e | 4849 | .PP |
726f6388 JA |
4850 | In addition to command names, readline allows keys to be bound |
4851 | to a string that is inserted when the key is pressed (a \fImacro\fP). | |
ccc6cda3 | 4852 | .SS "Readline Key Bindings" |
726f6388 JA |
4853 | .PP |
4854 | The syntax for controlling key bindings in the | |
cce855bc | 4855 | .I inputrc |
726f6388 JA |
4856 | file is simple. All that is required is the name of the |
4857 | command or the text of a macro and a key sequence to which | |
4858 | it should be bound. The name may be specified in one of two ways: | |
ccc6cda3 | 4859 | as a symbolic key name, possibly with \fIMeta\-\fP or \fIControl\-\fP |
726f6388 | 4860 | prefixes, or as a key sequence. |
28ef6c31 | 4861 | .PP |
cce855bc | 4862 | When using the form \fBkeyname\fP:\^\fIfunction\-name\fP or \fImacro\fP, |
726f6388 JA |
4863 | .I keyname |
4864 | is the name of a key spelled out in English. For example: | |
4865 | .sp | |
4866 | .RS | |
4867 | Control-u: universal\-argument | |
4868 | .br | |
4869 | Meta-Rubout: backward-kill-word | |
4870 | .br | |
ccc6cda3 | 4871 | Control-o: "> output" |
726f6388 JA |
4872 | .RE |
4873 | .LP | |
4874 | In the above example, | |
ccc6cda3 | 4875 | .I C\-u |
726f6388 JA |
4876 | is bound to the function |
4877 | .BR universal\-argument , | |
ccc6cda3 | 4878 | .I M\-DEL |
726f6388 JA |
4879 | is bound to the function |
4880 | .BR backward\-kill\-word , | |
4881 | and | |
ccc6cda3 | 4882 | .I C\-o |
726f6388 JA |
4883 | is bound to run the macro |
4884 | expressed on the right hand side (that is, to insert the text | |
28ef6c31 JA |
4885 | .if t \f(CW> output\fP |
4886 | .if n ``> output'' | |
726f6388 JA |
4887 | into the line). |
4888 | .PP | |
cce855bc | 4889 | In the second form, \fB"keyseq"\fP:\^\fIfunction\-name\fP or \fImacro\fP, |
726f6388 JA |
4890 | .B keyseq |
4891 | differs from | |
4892 | .B keyname | |
4893 | above in that strings denoting | |
4894 | an entire key sequence may be specified by placing the sequence | |
4895 | within double quotes. Some GNU Emacs style key escapes can be | |
28ef6c31 JA |
4896 | used, as in the following example, but the symbolic character names |
4897 | are not recognized. | |
726f6388 JA |
4898 | .sp |
4899 | .RS | |
ccc6cda3 | 4900 | "\eC\-u": universal\-argument |
726f6388 | 4901 | .br |
ccc6cda3 | 4902 | "\eC\-x\eC\-r": re\-read\-init\-file |
726f6388 JA |
4903 | .br |
4904 | "\ee[11~": "Function Key 1" | |
4905 | .RE | |
4906 | .PP | |
4907 | In this example, | |
ccc6cda3 | 4908 | .I C\-u |
726f6388 JA |
4909 | is again bound to the function |
4910 | .BR universal\-argument . | |
ccc6cda3 | 4911 | .I "C\-x C\-r" |
726f6388 JA |
4912 | is bound to the function |
4913 | .BR re\-read\-init\-file , | |
4914 | and | |
4915 | .I "ESC [ 1 1 ~" | |
4916 | is bound to insert the text | |
28ef6c31 JA |
4917 | .if t \f(CWFunction Key 1\fP. |
4918 | .if n ``Function Key 1''. | |
4919 | .PP | |
cce855bc | 4920 | The full set of GNU Emacs style escape sequences is |
726f6388 | 4921 | .RS |
cce855bc | 4922 | .PD 0 |
726f6388 JA |
4923 | .TP |
4924 | .B \eC\- | |
4925 | control prefix | |
4926 | .TP | |
ccc6cda3 | 4927 | .B \eM\- |
726f6388 JA |
4928 | meta prefix |
4929 | .TP | |
4930 | .B \ee | |
4931 | an escape character | |
4932 | .TP | |
4933 | .B \e\e | |
4934 | backslash | |
4935 | .TP | |
4936 | .B \e" | |
4937 | literal " | |
4938 | .TP | |
20587658 CR |
4939 | .B \e\(aq |
4940 | literal \(aq | |
726f6388 | 4941 | .RE |
cce855bc JA |
4942 | .PD |
4943 | .PP | |
4944 | In addition to the GNU Emacs style escape sequences, a second | |
4945 | set of backslash escapes is available: | |
4946 | .RS | |
4947 | .PD 0 | |
4948 | .TP | |
4949 | .B \ea | |
4950 | alert (bell) | |
4951 | .TP | |
4952 | .B \eb | |
4953 | backspace | |
4954 | .TP | |
4955 | .B \ed | |
4956 | delete | |
4957 | .TP | |
4958 | .B \ef | |
4959 | form feed | |
4960 | .TP | |
4961 | .B \en | |
4962 | newline | |
4963 | .TP | |
4964 | .B \er | |
4965 | carriage return | |
4966 | .TP | |
4967 | .B \et | |
4968 | horizontal tab | |
4969 | .TP | |
4970 | .B \ev | |
4971 | vertical tab | |
4972 | .TP | |
4973 | .B \e\fInnn\fP | |
f73dda09 | 4974 | the eight-bit character whose value is the octal value \fInnn\fP |
cce855bc JA |
4975 | (one to three digits) |
4976 | .TP | |
f73dda09 JA |
4977 | .B \ex\fIHH\fP |
4978 | the eight-bit character whose value is the hexadecimal value \fIHH\fP | |
4979 | (one or two hex digits) | |
cce855bc JA |
4980 | .RE |
4981 | .PD | |
726f6388 | 4982 | .PP |
cce855bc JA |
4983 | When entering the text of a macro, single or double quotes must |
4984 | be used to indicate a macro definition. | |
4985 | Unquoted text is assumed to be a function name. | |
4986 | In the macro body, the backslash escapes described above are expanded. | |
4987 | Backslash will quote any other character in the macro text, | |
20587658 | 4988 | including " and \(aq. |
726f6388 JA |
4989 | .PP |
4990 | .B Bash | |
4991 | allows the current readline key bindings to be displayed or modified | |
4992 | with the | |
4993 | .B bind | |
4994 | builtin command. The editing mode may be switched during interactive | |
4995 | use by using the | |
4996 | .B \-o | |
4997 | option to the | |
4998 | .B set | |
4999 | builtin command (see | |
5000 | .SM | |
5001 | .B SHELL BUILTIN COMMANDS | |
5002 | below). | |
ccc6cda3 | 5003 | .SS "Readline Variables" |
726f6388 JA |
5004 | .PP |
5005 | Readline has variables that can be used to further customize its | |
5006 | behavior. A variable may be set in the | |
5007 | .I inputrc | |
5008 | file with a statement of the form | |
5009 | .RS | |
5010 | .PP | |
5011 | \fBset\fP \fIvariable\-name\fP \fIvalue\fP | |
5012 | .RE | |
5013 | .PP | |
5014 | Except where noted, readline variables can take the values | |
5015 | .B On | |
5016 | or | |
ff247e74 CR |
5017 | .B Off |
5018 | (without regard to case). | |
5019 | Unrecognized variable names are ignored. | |
5020 | When a variable value is read, empty or null values, "on" (case-insensitive), | |
5021 | and "1" are equivalent to \fBOn\fP. All other values are equivalent to | |
5022 | \fBOff\fP. | |
726f6388 JA |
5023 | The variables and their default values are: |
5024 | .PP | |
5025 | .PD 0 | |
5026 | .TP | |
726f6388 JA |
5027 | .B bell\-style (audible) |
5028 | Controls what happens when readline wants to ring the terminal bell. | |
5029 | If set to \fBnone\fP, readline never rings the bell. If set to | |
5030 | \fBvisible\fP, readline uses a visible bell if one is available. | |
5031 | If set to \fBaudible\fP, readline attempts to ring the terminal's bell. | |
5032 | .TP | |
453f278a CR |
5033 | .B bind\-tty\-special\-chars (On) |
5034 | If set to \fBOn\fP, readline attempts to bind the control characters | |
5035 | treated specially by the kernel's terminal driver to their readline | |
5036 | equivalents. | |
5037 | .TP | |
726f6388 | 5038 | .B comment\-begin (``#'') |
bb70624e | 5039 | The string that is inserted when the readline |
ccc6cda3 | 5040 | .B insert\-comment |
726f6388 | 5041 | command is executed. |
ccc6cda3 JA |
5042 | This command is bound to |
5043 | .B M\-# | |
5044 | in emacs mode and to | |
5045 | .B # | |
5046 | in vi command mode. | |
726f6388 | 5047 | .TP |
cce855bc JA |
5048 | .B completion\-ignore\-case (Off) |
5049 | If set to \fBOn\fP, readline performs filename matching and completion | |
5050 | in a case\-insensitive fashion. | |
5051 | .TP | |
f13513ff CR |
5052 | .B completion\-prefix\-display\-length (0) |
5053 | The length in characters of the common prefix of a list of possible | |
5054 | completions that is displayed without modification. When set to a | |
5055 | value greater than zero, common prefixes longer than this value are | |
5056 | replaced with an ellipsis when displaying possible completions. | |
5057 | .TP | |
726f6388 JA |
5058 | .B completion\-query\-items (100) |
5059 | This determines when the user is queried about viewing | |
5060 | the number of possible completions | |
5061 | generated by the \fBpossible\-completions\fP command. | |
5062 | It may be set to any integer value greater than or equal to | |
5063 | zero. If the number of possible completions is greater than | |
5064 | or equal to the value of this variable, the user is asked whether | |
5065 | or not he wishes to view them; otherwise they are simply listed | |
5066 | on the terminal. | |
5067 | .TP | |
ccc6cda3 JA |
5068 | .B convert\-meta (On) |
5069 | If set to \fBOn\fP, readline will convert characters with the | |
5070 | eighth bit set to an ASCII key sequence | |
bb70624e | 5071 | by stripping the eighth bit and prefixing an |
ccc6cda3 JA |
5072 | escape character (in effect, using escape as the \fImeta prefix\fP). |
5073 | .TP | |
5074 | .B disable\-completion (Off) | |
5075 | If set to \fBOn\fP, readline will inhibit word completion. Completion | |
5076 | characters will be inserted into the line as if they had been | |
5077 | mapped to \fBself-insert\fP. | |
5078 | .TP | |
5079 | .B editing\-mode (emacs) | |
5080 | Controls whether readline begins with a set of key bindings similar | |
5081 | to \fIemacs\fP or \fIvi\fP. | |
5082 | .B editing\-mode | |
5083 | can be set to either | |
5084 | .B emacs | |
5085 | or | |
5086 | .BR vi . | |
5087 | .TP | |
824dfe68 CR |
5088 | .B echo\-control\-characters (On) |
5089 | When set to \fBOn\fP, on operating systems that indicate they support it, | |
5090 | readline echoes a character corresponding to a signal generated from the | |
5091 | keyboard. | |
5092 | .TP | |
ccc6cda3 JA |
5093 | .B enable\-keypad (Off) |
5094 | When set to \fBOn\fP, readline will try to enable the application | |
5095 | keypad when it is called. Some systems need this to enable the | |
5096 | arrow keys. | |
5097 | .TP | |
08e72d7a CR |
5098 | .B enable\-meta\-key (On) |
5099 | When set to \fBOn\fP, readline will try to enable any meta modifier | |
5100 | key the terminal claims to support when it is called. On many terminals, | |
5101 | the meta key is used to send eight-bit characters. | |
5102 | .TP | |
ccc6cda3 JA |
5103 | .B expand\-tilde (Off) |
5104 | If set to \fBon\fP, tilde expansion is performed when readline | |
5105 | attempts word completion. | |
5106 | .TP | |
cdb32d45 | 5107 | .B history\-preserve\-point (Off) |
f73dda09 | 5108 | If set to \fBon\fP, the history code attempts to place point at the |
f75912ae | 5109 | same location on each history line retrieved with \fBprevious-history\fP |
f73dda09 JA |
5110 | or \fBnext-history\fP. |
5111 | .TP | |
1d0e1a34 CR |
5112 | .B history\-size (0) |
5113 | Set the maximum number of history entries saved in the history list. If | |
5114 | set to zero, the number of entries in the history list is not limited. | |
5115 | .TP | |
ccc6cda3 JA |
5116 | .B horizontal\-scroll\-mode (Off) |
5117 | When set to \fBOn\fP, makes readline use a single line for display, | |
5118 | scrolling the input horizontally on a single screen line when it | |
5119 | becomes longer than the screen width rather than wrapping to a new line. | |
5120 | .TP | |
5121 | .B input\-meta (Off) | |
5122 | If set to \fBOn\fP, readline will enable eight-bit input (that is, | |
5123 | it will not strip the high bit from the characters it reads), | |
5124 | regardless of what the terminal claims it can support. The name | |
5125 | .B meta\-flag | |
5126 | is a synonym for this variable. | |
5127 | .TP | |
b72432fd JA |
5128 | .B isearch\-terminators (``C\-[C\-J'') |
5129 | The string of characters that should terminate an incremental | |
5130 | search without subsequently executing the character as a command. | |
5131 | If this variable has not been given a value, the characters | |
5132 | \fIESC\fP and \fIC\-J\fP will terminate an incremental search. | |
5133 | .TP | |
726f6388 | 5134 | .B keymap (emacs) |
cce855bc | 5135 | Set the current readline keymap. The set of valid keymap names is |
ccc6cda3 JA |
5136 | \fIemacs, emacs\-standard, emacs\-meta, emacs\-ctlx, vi, |
5137 | vi\-command\fP, and | |
5138 | .IR vi\-insert . | |
5139 | \fIvi\fP is equivalent to \fIvi\-command\fP; \fIemacs\fP is | |
5140 | equivalent to \fIemacs\-standard\fP. The default value is | |
726f6388 JA |
5141 | .IR emacs ; |
5142 | the value of | |
5143 | .B editing\-mode | |
5144 | also affects the default keymap. | |
5145 | .TP | |
ccc6cda3 JA |
5146 | .B mark\-directories (On) |
5147 | If set to \fBOn\fP, completed directory names have a slash | |
5148 | appended. | |
5149 | .TP | |
5150 | .B mark\-modified\-lines (Off) | |
5151 | If set to \fBOn\fP, history lines that have been modified are displayed | |
5152 | with a preceding asterisk (\fB*\fP). | |
5153 | .TP | |
7117c2d2 JA |
5154 | .B mark\-symlinked\-directories (Off) |
5155 | If set to \fBOn\fP, completed names which are symbolic links to directories | |
5156 | have a slash appended (subject to the value of | |
5157 | \fBmark\-directories\fP). | |
5158 | .TP | |
f73dda09 JA |
5159 | .B match\-hidden\-files (On) |
5160 | This variable, when set to \fBOn\fP, causes readline to match files whose | |
5161 | names begin with a `.' (hidden files) when performing filename | |
5162 | completion, unless the leading `.' is | |
5163 | supplied by the user in the filename to be completed. | |
5164 | .TP | |
ccc6cda3 JA |
5165 | .B output\-meta (Off) |
5166 | If set to \fBOn\fP, readline will display characters with the | |
5167 | eighth bit set directly rather than as a meta-prefixed escape | |
5168 | sequence. | |
5169 | .TP | |
7117c2d2 JA |
5170 | .B page\-completions (On) |
5171 | If set to \fBOn\fP, readline uses an internal \fImore\fP-like pager | |
5172 | to display a screenful of possible completions at a time. | |
5173 | .TP | |
cce855bc JA |
5174 | .B print\-completions\-horizontally (Off) |
5175 | If set to \fBOn\fP, readline will display completions with matches | |
5176 | sorted horizontally in alphabetical order, rather than down the screen. | |
f13513ff CR |
5177 | .TP |
5178 | .B revert\-all\-at\-newline (Off) | |
5179 | If set to \fBon\fP, readline will undo all changes to history lines | |
5180 | before returning when \fBaccept\-line\fP is executed. By default, | |
5181 | history lines may be modified and retain individual undo lists across | |
5182 | calls to \fBreadline\fP. | |
cce855bc | 5183 | .TP |
726f6388 JA |
5184 | .B show\-all\-if\-ambiguous (Off) |
5185 | This alters the default behavior of the completion functions. If | |
5186 | set to | |
5187 | .BR on , | |
5188 | words which have more than one possible completion cause the | |
5189 | matches to be listed immediately instead of ringing the bell. | |
5190 | .TP | |
d3a24ed2 CR |
5191 | .B show\-all\-if\-unmodified (Off) |
5192 | This alters the default behavior of the completion functions in | |
5193 | a fashion similar to \fBshow\-all\-if\-ambiguous\fP. | |
5194 | If set to | |
5195 | .BR on , | |
5196 | words which have more than one possible completion without any | |
5197 | possible partial completion (the possible completions don't share | |
5198 | a common prefix) cause the matches to be listed immediately instead | |
5199 | of ringing the bell. | |
5200 | .TP | |
8f714a7c CR |
5201 | .B skip\-completed\-text (Off) |
5202 | If set to \fBOn\fP, this alters the default completion behavior when | |
5203 | inserting a single match into the line. It's only active when | |
5204 | performing completion in the middle of a word. If enabled, readline | |
5205 | does not insert characters from the completion that match characters | |
5206 | after point in the word being completed, so portions of the word | |
5207 | following the cursor are not duplicated. | |
5208 | .TP | |
ccc6cda3 JA |
5209 | .B visible\-stats (Off) |
5210 | If set to \fBOn\fP, a character denoting a file's type as reported | |
5211 | by \fIstat\fP(2) is appended to the filename when listing possible | |
5212 | completions. | |
726f6388 | 5213 | .PD |
ccc6cda3 | 5214 | .SS "Readline Conditional Constructs" |
726f6388 JA |
5215 | .PP |
5216 | Readline implements a facility similar in spirit to the conditional | |
5217 | compilation features of the C preprocessor which allows key | |
5218 | bindings and variable settings to be performed as the result | |
cce855bc | 5219 | of tests. There are four parser directives used. |
726f6388 JA |
5220 | .IP \fB$if\fP |
5221 | The | |
5222 | .B $if | |
5223 | construct allows bindings to be made based on the | |
5224 | editing mode, the terminal being used, or the application using | |
5225 | readline. The text of the test extends to the end of the line; | |
5226 | no characters are required to isolate it. | |
5227 | .RS | |
5228 | .IP \fBmode\fP | |
5229 | The \fBmode=\fP form of the \fB$if\fP directive is used to test | |
5230 | whether readline is in emacs or vi mode. | |
5231 | This may be used in conjunction | |
5232 | with the \fBset keymap\fP command, for instance, to set bindings in | |
ccc6cda3 | 5233 | the \fIemacs\-standard\fP and \fIemacs\-ctlx\fP keymaps only if |
726f6388 JA |
5234 | readline is starting out in emacs mode. |
5235 | .IP \fBterm\fP | |
5236 | The \fBterm=\fP form may be used to include terminal-specific | |
5237 | key bindings, perhaps to bind the key sequences output by the | |
5238 | terminal's function keys. The word on the right side of the | |
5239 | .B = | |
cce855bc | 5240 | is tested against the both full name of the terminal and the portion |
726f6388 JA |
5241 | of the terminal name before the first \fB\-\fP. This allows |
5242 | .I sun | |
5243 | to match both | |
5244 | .I sun | |
5245 | and | |
5246 | .IR sun\-cmd , | |
5247 | for instance. | |
5248 | .IP \fBapplication\fP | |
5249 | The \fBapplication\fP construct is used to include | |
ccc6cda3 | 5250 | application-specific settings. Each program using the readline |
726f6388 JA |
5251 | library sets the \fIapplication name\fP, and an initialization |
5252 | file can test for a particular value. | |
5253 | This could be used to bind key sequences to functions useful for | |
5254 | a specific program. For instance, the following command adds a | |
5255 | key sequence that quotes the current or previous word in Bash: | |
cce855bc | 5256 | .sp 1 |
726f6388 JA |
5257 | .RS |
5258 | .nf | |
5259 | \fB$if\fP Bash | |
5260 | # Quote the current or previous word | |
ccc6cda3 | 5261 | "\eC\-xq": "\eeb\e"\eef\e"" |
726f6388 JA |
5262 | \fB$endif\fP |
5263 | .fi | |
5264 | .RE | |
5265 | .RE | |
5266 | .IP \fB$endif\fP | |
cce855bc | 5267 | This command, as seen in the previous example, terminates an |
726f6388 JA |
5268 | \fB$if\fP command. |
5269 | .IP \fB$else\fP | |
5270 | Commands in this branch of the \fB$if\fP directive are executed if | |
5271 | the test fails. | |
cce855bc JA |
5272 | .IP \fB$include\fP |
5273 | This directive takes a single filename as an argument and reads commands | |
5274 | and bindings from that file. For example, the following directive | |
5275 | would read \fI/etc/inputrc\fP: | |
5276 | .sp 1 | |
5277 | .RS | |
5278 | .nf | |
5279 | \fB$include\fP \^ \fI/etc/inputrc\fP | |
5280 | .fi | |
5281 | .RE | |
ccc6cda3 | 5282 | .SS Searching |
726f6388 | 5283 | .PP |
ccc6cda3 JA |
5284 | Readline provides commands for searching through the command history |
5285 | (see | |
5286 | .SM | |
5287 | .B HISTORY | |
5288 | below) for lines containing a specified string. | |
5289 | There are two search modes: | |
5290 | .I incremental | |
5291 | and | |
5292 | .IR non-incremental . | |
5293 | .PP | |
5294 | Incremental searches begin before the user has finished typing the | |
5295 | search string. | |
5296 | As each character of the search string is typed, readline displays | |
5297 | the next entry from the history matching the string typed so far. | |
5298 | An incremental search requires only as many characters as needed to | |
5299 | find the desired history entry. | |
bb70624e | 5300 | The characters present in the value of the \fBisearch-terminators\fP |
b72432fd JA |
5301 | variable are used to terminate an incremental search. |
5302 | If that variable has not been assigned a value the Escape and | |
5303 | Control-J characters will terminate an incremental search. | |
ccc6cda3 JA |
5304 | Control-G will abort an incremental search and restore the original |
5305 | line. | |
5306 | When the search is terminated, the history entry containing the | |
5307 | search string becomes the current line. | |
bb70624e | 5308 | .PP |
ccc6cda3 JA |
5309 | To find other matching entries in the history list, type Control-S or |
5310 | Control-R as appropriate. | |
5311 | This will search backward or forward in the history for the next | |
5312 | entry matching the search string typed so far. | |
5313 | Any other key sequence bound to a readline command will terminate | |
5314 | the search and execute that command. | |
5315 | For instance, a \fInewline\fP will terminate the search and accept | |
5316 | the line, thereby executing the command from the history list. | |
5317 | .PP | |
f73dda09 JA |
5318 | Readline remembers the last incremental search string. If two |
5319 | Control-Rs are typed without any intervening characters defining a | |
5320 | new search string, any remembered search string is used. | |
5321 | .PP | |
ccc6cda3 JA |
5322 | Non-incremental searches read the entire search string before starting |
5323 | to search for matching history lines. The search string may be | |
cce855bc | 5324 | typed by the user or be part of the contents of the current line. |
ccc6cda3 | 5325 | .SS "Readline Command Names" |
726f6388 JA |
5326 | .PP |
5327 | The following is a list of the names of the commands and the default | |
5328 | key sequences to which they are bound. | |
ccc6cda3 | 5329 | Command names without an accompanying key sequence are unbound by default. |
bb70624e JA |
5330 | In the following descriptions, \fIpoint\fP refers to the current cursor |
5331 | position, and \fImark\fP refers to a cursor position saved by the | |
5332 | \fBset\-mark\fP command. | |
5333 | The text between the point and mark is referred to as the \fIregion\fP. | |
726f6388 JA |
5334 | .SS Commands for Moving |
5335 | .PP | |
5336 | .PD 0 | |
5337 | .TP | |
5338 | .B beginning\-of\-line (C\-a) | |
5339 | Move to the start of the current line. | |
5340 | .TP | |
5341 | .B end\-of\-line (C\-e) | |
5342 | Move to the end of the line. | |
5343 | .TP | |
5344 | .B forward\-char (C\-f) | |
5345 | Move forward a character. | |
5346 | .TP | |
5347 | .B backward\-char (C\-b) | |
5348 | Move back a character. | |
5349 | .TP | |
5350 | .B forward\-word (M\-f) | |
5351 | Move forward to the end of the next word. Words are composed of | |
5352 | alphanumeric characters (letters and digits). | |
5353 | .TP | |
5354 | .B backward\-word (M\-b) | |
8c2fef19 CR |
5355 | Move back to the start of the current or previous word. |
5356 | Words are composed of alphanumeric characters (letters and digits). | |
5357 | .TP | |
5358 | .B shell\-forward\-word | |
5359 | Move forward to the end of the next word. | |
5360 | Words are delimited by non-quoted shell metacharacters. | |
5361 | .TP | |
5362 | .B shell\-backward\-word | |
5363 | Move back to the start of the current or previous word. | |
5364 | Words are delimited by non-quoted shell metacharacters. | |
726f6388 JA |
5365 | .TP |
5366 | .B clear\-screen (C\-l) | |
5367 | Clear the screen leaving the current line at the top of the screen. | |
5368 | With an argument, refresh the current line without clearing the | |
5369 | screen. | |
5370 | .TP | |
5371 | .B redraw\-current\-line | |
ccc6cda3 | 5372 | Refresh the current line. |
726f6388 JA |
5373 | .PD |
5374 | .SS Commands for Manipulating the History | |
5375 | .PP | |
5376 | .PD 0 | |
5377 | .TP | |
5378 | .B accept\-line (Newline, Return) | |
5379 | Accept the line regardless of where the cursor is. If this line is | |
ccc6cda3 | 5380 | non-empty, add it to the history list according to the state of the |
726f6388 JA |
5381 | .SM |
5382 | .B HISTCONTROL | |
5383 | variable. If the line is a modified history | |
5384 | line, then restore the history line to its original state. | |
5385 | .TP | |
5386 | .B previous\-history (C\-p) | |
5387 | Fetch the previous command from the history list, moving back in | |
5388 | the list. | |
5389 | .TP | |
5390 | .B next\-history (C\-n) | |
5391 | Fetch the next command from the history list, moving forward in the | |
5392 | list. | |
5393 | .TP | |
5394 | .B beginning\-of\-history (M\-<) | |
5395 | Move to the first line in the history. | |
5396 | .TP | |
5397 | .B end\-of\-history (M\->) | |
5398 | Move to the end of the input history, i.e., the line currently being | |
5399 | entered. | |
5400 | .TP | |
5401 | .B reverse\-search\-history (C\-r) | |
5402 | Search backward starting at the current line and moving `up' through | |
5403 | the history as necessary. This is an incremental search. | |
5404 | .TP | |
5405 | .B forward\-search\-history (C\-s) | |
5406 | Search forward starting at the current line and moving `down' through | |
5407 | the history as necessary. This is an incremental search. | |
5408 | .TP | |
5409 | .B non\-incremental\-reverse\-search\-history (M\-p) | |
5410 | Search backward through the history starting at the current line | |
ccc6cda3 | 5411 | using a non-incremental search for a string supplied by the user. |
726f6388 JA |
5412 | .TP |
5413 | .B non\-incremental\-forward\-search\-history (M\-n) | |
ccc6cda3 | 5414 | Search forward through the history using a non-incremental search for |
726f6388 JA |
5415 | a string supplied by the user. |
5416 | .TP | |
5417 | .B history\-search\-forward | |
5418 | Search forward through the history for the string of characters | |
bb70624e | 5419 | between the start of the current line and the point. |
ccc6cda3 | 5420 | This is a non-incremental search. |
726f6388 JA |
5421 | .TP |
5422 | .B history\-search\-backward | |
5423 | Search backward through the history for the string of characters | |
ccc6cda3 JA |
5424 | between the start of the current line and the point. |
5425 | This is a non-incremental search. | |
726f6388 JA |
5426 | .TP |
5427 | .B yank\-nth\-arg (M\-C\-y) | |
5428 | Insert the first argument to the previous command (usually | |
28ef6c31 JA |
5429 | the second word on the previous line) at point. |
5430 | With an argument | |
726f6388 JA |
5431 | .IR n , |
5432 | insert the \fIn\fPth word from the previous command (the words | |
5433 | in the previous command begin with word 0). A negative argument | |
5434 | inserts the \fIn\fPth word from the end of the previous command. | |
eb2bb562 CR |
5435 | Once the argument \fIn\fP is computed, the argument is extracted |
5436 | as if the "!\fIn\fP" history expansion had been specified. | |
726f6388 JA |
5437 | .TP |
5438 | .B | |
5439 | yank\-last\-arg (M\-.\^, M\-_\^) | |
ccc6cda3 JA |
5440 | Insert the last argument to the previous command (the last word of |
5441 | the previous history entry). With an argument, | |
5442 | behave exactly like \fByank\-nth\-arg\fP. | |
cce855bc JA |
5443 | Successive calls to \fByank\-last\-arg\fP move back through the history |
5444 | list, inserting the last argument of each line in turn. | |
eb2bb562 CR |
5445 | The history expansion facilities are used to extract the last argument, |
5446 | as if the "!$" history expansion had been specified. | |
726f6388 JA |
5447 | .TP |
5448 | .B shell\-expand\-line (M\-C\-e) | |
cce855bc | 5449 | Expand the line as the shell does. This |
726f6388 JA |
5450 | performs alias and history expansion as well as all of the shell |
5451 | word expansions. See | |
5452 | .SM | |
5453 | .B HISTORY EXPANSION | |
5454 | below for a description of history expansion. | |
5455 | .TP | |
5456 | .B history\-expand\-line (M\-^) | |
d166f048 JA |
5457 | Perform history expansion on the current line. |
5458 | See | |
726f6388 JA |
5459 | .SM |
5460 | .B HISTORY EXPANSION | |
5461 | below for a description of history expansion. | |
5462 | .TP | |
cce855bc JA |
5463 | .B magic\-space |
5464 | Perform history expansion on the current line and insert a space. | |
5465 | See | |
5466 | .SM | |
5467 | .B HISTORY EXPANSION | |
5468 | below for a description of history expansion. | |
5469 | .TP | |
d166f048 JA |
5470 | .B alias\-expand\-line |
5471 | Perform alias expansion on the current line. | |
5472 | See | |
5473 | .SM | |
5474 | .B ALIASES | |
5475 | above for a description of alias expansion. | |
5476 | .TP | |
5477 | .B history\-and\-alias\-expand\-line | |
5478 | Perform history and alias expansion on the current line. | |
5479 | .TP | |
726f6388 JA |
5480 | .B insert\-last\-argument (M\-.\^, M\-_\^) |
5481 | A synonym for \fByank\-last\-arg\fP. | |
5482 | .TP | |
ccc6cda3 | 5483 | .B operate\-and\-get\-next (C\-o) |
726f6388 JA |
5484 | Accept the current line for execution and fetch the next line |
5485 | relative to the current line from the history for editing. Any | |
5486 | argument is ignored. | |
7117c2d2 JA |
5487 | .TP |
5488 | .B edit\-and\-execute\-command (C\-xC\-e) | |
5489 | Invoke an editor on the current command line, and execute the result as shell | |
5490 | commands. | |
5491 | \fBBash\fP attempts to invoke | |
5492 | .SM | |
dd4f3dd8 | 5493 | .BR $VISUAL , |
7117c2d2 JA |
5494 | .SM |
5495 | .BR $EDITOR , | |
5496 | and \fIemacs\fP as the editor, in that order. | |
726f6388 JA |
5497 | .PD |
5498 | .SS Commands for Changing Text | |
5499 | .PP | |
5500 | .PD 0 | |
5501 | .TP | |
5502 | .B delete\-char (C\-d) | |
28ef6c31 | 5503 | Delete the character at point. If point is at the |
726f6388 | 5504 | beginning of the line, there are no characters in the line, and |
cce855bc | 5505 | the last character typed was not bound to \fBdelete\-char\fP, |
726f6388 JA |
5506 | then return |
5507 | .SM | |
5508 | .BR EOF . | |
5509 | .TP | |
5510 | .B backward\-delete\-char (Rubout) | |
5511 | Delete the character behind the cursor. When given a numeric argument, | |
ccc6cda3 | 5512 | save the deleted text on the kill ring. |
726f6388 | 5513 | .TP |
b72432fd JA |
5514 | .B forward\-backward\-delete\-char |
5515 | Delete the character under the cursor, unless the cursor is at the | |
5516 | end of the line, in which case the character behind the cursor is | |
f73dda09 | 5517 | deleted. |
b72432fd | 5518 | .TP |
726f6388 | 5519 | .B quoted\-insert (C\-q, C\-v) |
cce855bc | 5520 | Add the next character typed to the line verbatim. This is |
726f6388 JA |
5521 | how to insert characters like \fBC\-q\fP, for example. |
5522 | .TP | |
ccc6cda3 | 5523 | .B tab\-insert (C\-v TAB) |
726f6388 JA |
5524 | Insert a tab character. |
5525 | .TP | |
5526 | .B self\-insert (a,\ b,\ A,\ 1,\ !,\ ...) | |
5527 | Insert the character typed. | |
5528 | .TP | |
5529 | .B transpose\-chars (C\-t) | |
28ef6c31 JA |
5530 | Drag the character before point forward over the character at point, |
5531 | moving point forward as well. | |
5532 | If point is at the end of the line, then this transposes | |
5533 | the two characters before point. | |
bb70624e | 5534 | Negative arguments have no effect. |
726f6388 JA |
5535 | .TP |
5536 | .B transpose\-words (M\-t) | |
bb70624e | 5537 | Drag the word before point past the word after point, |
28ef6c31 | 5538 | moving point over that word as well. |
f73dda09 JA |
5539 | If point is at the end of the line, this transposes |
5540 | the last two words on the line. | |
726f6388 JA |
5541 | .TP |
5542 | .B upcase\-word (M\-u) | |
5543 | Uppercase the current (or following) word. With a negative argument, | |
cce855bc | 5544 | uppercase the previous word, but do not move point. |
726f6388 JA |
5545 | .TP |
5546 | .B downcase\-word (M\-l) | |
5547 | Lowercase the current (or following) word. With a negative argument, | |
cce855bc | 5548 | lowercase the previous word, but do not move point. |
726f6388 JA |
5549 | .TP |
5550 | .B capitalize\-word (M\-c) | |
5551 | Capitalize the current (or following) word. With a negative argument, | |
cce855bc | 5552 | capitalize the previous word, but do not move point. |
7117c2d2 JA |
5553 | .TP |
5554 | .B overwrite\-mode | |
5555 | Toggle overwrite mode. With an explicit positive numeric argument, | |
5556 | switches to overwrite mode. With an explicit non-positive numeric | |
5557 | argument, switches to insert mode. This command affects only | |
5558 | \fBemacs\fP mode; \fBvi\fP mode does overwrite differently. | |
5559 | Each call to \fIreadline()\fP starts in insert mode. | |
5560 | In overwrite mode, characters bound to \fBself\-insert\fP replace | |
5561 | the text at point rather than pushing the text to the right. | |
5562 | Characters bound to \fBbackward\-delete\-char\fP replace the character | |
5563 | before point with a space. By default, this command is unbound. | |
726f6388 JA |
5564 | .PD |
5565 | .SS Killing and Yanking | |
5566 | .PP | |
5567 | .PD 0 | |
5568 | .TP | |
5569 | .B kill\-line (C\-k) | |
bb70624e | 5570 | Kill the text from point to the end of the line. |
726f6388 | 5571 | .TP |
ccc6cda3 | 5572 | .B backward\-kill\-line (C\-x Rubout) |
726f6388 JA |
5573 | Kill backward to the beginning of the line. |
5574 | .TP | |
5575 | .B unix\-line\-discard (C\-u) | |
5576 | Kill backward from point to the beginning of the line. | |
cce855bc | 5577 | The killed text is saved on the kill-ring. |
bb70624e | 5578 | .\" There is no real difference between this and backward-kill-line |
726f6388 JA |
5579 | .TP |
5580 | .B kill\-whole\-line | |
bb70624e | 5581 | Kill all characters on the current line, no matter where point is. |
726f6388 JA |
5582 | .TP |
5583 | .B kill\-word (M\-d) | |
bb70624e JA |
5584 | Kill from point to the end of the current word, or if between |
5585 | words, to the end of the next word. | |
5586 | Word boundaries are the same as those used by \fBforward\-word\fP. | |
726f6388 JA |
5587 | .TP |
5588 | .B backward\-kill\-word (M\-Rubout) | |
bb70624e JA |
5589 | Kill the word behind point. |
5590 | Word boundaries are the same as those used by \fBbackward\-word\fP. | |
726f6388 | 5591 | .TP |
8c2fef19 CR |
5592 | .B shell\-kill\-word (M\-d) |
5593 | Kill from point to the end of the current word, or if between | |
5594 | words, to the end of the next word. | |
5595 | Word boundaries are the same as those used by \fBshell\-forward\-word\fP. | |
5596 | .TP | |
5597 | .B shell\-backward\-kill\-word (M\-Rubout) | |
5598 | Kill the word behind point. | |
5599 | Word boundaries are the same as those used by \fBshell\-backward\-word\fP. | |
5600 | .TP | |
726f6388 | 5601 | .B unix\-word\-rubout (C\-w) |
bb70624e | 5602 | Kill the word behind point, using white space as a word boundary. |
bb70624e | 5603 | The killed text is saved on the kill-ring. |
113d85a4 CR |
5604 | .TP |
5605 | .B unix\-filename\-rubout | |
5606 | Kill the word behind point, using white space and the slash character | |
5607 | as the word boundaries. | |
5608 | The killed text is saved on the kill-ring. | |
ccc6cda3 JA |
5609 | .TP |
5610 | .B delete\-horizontal\-space (M\-\e) | |
5611 | Delete all spaces and tabs around point. | |
5612 | .TP | |
5613 | .B kill\-region | |
bb70624e | 5614 | Kill the text in the current region. |
ccc6cda3 JA |
5615 | .TP |
5616 | .B copy\-region\-as\-kill | |
5617 | Copy the text in the region to the kill buffer. | |
726f6388 | 5618 | .TP |
ccc6cda3 JA |
5619 | .B copy\-backward\-word |
5620 | Copy the word before point to the kill buffer. | |
cce855bc | 5621 | The word boundaries are the same as \fBbackward\-word\fP. |
ccc6cda3 JA |
5622 | .TP |
5623 | .B copy\-forward\-word | |
5624 | Copy the word following point to the kill buffer. | |
cce855bc | 5625 | The word boundaries are the same as \fBforward\-word\fP. |
726f6388 JA |
5626 | .TP |
5627 | .B yank (C\-y) | |
28ef6c31 | 5628 | Yank the top of the kill ring into the buffer at point. |
726f6388 JA |
5629 | .TP |
5630 | .B yank\-pop (M\-y) | |
ccc6cda3 | 5631 | Rotate the kill ring, and yank the new top. Only works following |
726f6388 JA |
5632 | .B yank |
5633 | or | |
5634 | .BR yank\-pop . | |
5635 | .PD | |
5636 | .SS Numeric Arguments | |
5637 | .PP | |
5638 | .PD 0 | |
5639 | .TP | |
5640 | .B digit\-argument (M\-0, M\-1, ..., M\-\-) | |
5641 | Add this digit to the argument already accumulating, or start a new | |
5642 | argument. M\-\- starts a negative argument. | |
5643 | .TP | |
5644 | .B universal\-argument | |
d166f048 JA |
5645 | This is another way to specify an argument. |
5646 | If this command is followed by one or more digits, optionally with a | |
5647 | leading minus sign, those digits define the argument. | |
5648 | If the command is followed by digits, executing | |
5649 | .B universal\-argument | |
5650 | again ends the numeric argument, but is otherwise ignored. | |
5651 | As a special case, if this command is immediately followed by a | |
5652 | character that is neither a digit or minus sign, the argument count | |
5653 | for the next command is multiplied by four. | |
726f6388 | 5654 | The argument count is initially one, so executing this function the |
d166f048 JA |
5655 | first time makes the argument count four, a second time makes the |
5656 | argument count sixteen, and so on. | |
726f6388 JA |
5657 | .PD |
5658 | .SS Completing | |
5659 | .PP | |
5660 | .PD 0 | |
5661 | .TP | |
5662 | .B complete (TAB) | |
5663 | Attempt to perform completion on the text before point. | |
5664 | .B Bash | |
5665 | attempts completion treating the text as a variable (if the | |
5666 | text begins with \fB$\fP), username (if the text begins with | |
5667 | \fB~\fP), hostname (if the text begins with \fB@\fP), or | |
5668 | command (including aliases and functions) in turn. If none | |
5669 | of these produces a match, filename completion is attempted. | |
5670 | .TP | |
ccc6cda3 | 5671 | .B possible\-completions (M\-?) |
726f6388 JA |
5672 | List the possible completions of the text before point. |
5673 | .TP | |
ccc6cda3 | 5674 | .B insert\-completions (M\-*) |
726f6388 JA |
5675 | Insert all completions of the text before point |
5676 | that would have been generated by | |
ccc6cda3 | 5677 | \fBpossible\-completions\fP. |
726f6388 | 5678 | .TP |
cce855bc JA |
5679 | .B menu\-complete |
5680 | Similar to \fBcomplete\fP, but replaces the word to be completed | |
5681 | with a single match from the list of possible completions. | |
5682 | Repeated execution of \fBmenu\-complete\fP steps through the list | |
5683 | of possible completions, inserting each match in turn. | |
28ef6c31 | 5684 | At the end of the list of completions, the bell is rung |
f73dda09 | 5685 | (subject to the setting of \fBbell\-style\fP) |
28ef6c31 | 5686 | and the original text is restored. |
cce855bc JA |
5687 | An argument of \fIn\fP moves \fIn\fP positions forward in the list |
5688 | of matches; a negative argument may be used to move backward | |
5689 | through the list. | |
5690 | This command is intended to be bound to \fBTAB\fP, but is unbound | |
5691 | by default. | |
5692 | .TP | |
9dd88db7 CR |
5693 | .B menu\-complete-\backward |
5694 | Identical to \fBmenu\-complete\fP, but moves backward through the list | |
5695 | of possible completions, as if \fBmenu\-complete\fP had been given a | |
5696 | negative argument. This command is unbound by default. | |
5697 | .TP | |
b72432fd JA |
5698 | .B delete\-char\-or\-list |
5699 | Deletes the character under the cursor if not at the beginning or | |
bb70624e | 5700 | end of the line (like \fBdelete\-char\fP). |
b72432fd | 5701 | If at the end of the line, behaves identically to |
bb70624e | 5702 | \fBpossible\-completions\fP. |
b72432fd JA |
5703 | This command is unbound by default. |
5704 | .TP | |
726f6388 JA |
5705 | .B complete\-filename (M\-/) |
5706 | Attempt filename completion on the text before point. | |
5707 | .TP | |
5708 | .B possible\-filename\-completions (C\-x /) | |
5709 | List the possible completions of the text before point, | |
5710 | treating it as a filename. | |
5711 | .TP | |
5712 | .B complete\-username (M\-~) | |
5713 | Attempt completion on the text before point, treating | |
5714 | it as a username. | |
5715 | .TP | |
5716 | .B possible\-username\-completions (C\-x ~) | |
5717 | List the possible completions of the text before point, | |
5718 | treating it as a username. | |
5719 | .TP | |
5720 | .B complete\-variable (M\-$) | |
5721 | Attempt completion on the text before point, treating | |
5722 | it as a shell variable. | |
5723 | .TP | |
5724 | .B possible\-variable\-completions (C\-x $) | |
5725 | List the possible completions of the text before point, | |
5726 | treating it as a shell variable. | |
5727 | .TP | |
5728 | .B complete\-hostname (M\-@) | |
5729 | Attempt completion on the text before point, treating | |
5730 | it as a hostname. | |
5731 | .TP | |
5732 | .B possible\-hostname\-completions (C\-x @) | |
5733 | List the possible completions of the text before point, | |
5734 | treating it as a hostname. | |
5735 | .TP | |
5736 | .B complete\-command (M\-!) | |
5737 | Attempt completion on the text before point, treating | |
5738 | it as a command name. Command completion attempts to | |
5739 | match the text against aliases, reserved words, shell | |
cce855bc | 5740 | functions, shell builtins, and finally executable filenames, |
726f6388 JA |
5741 | in that order. |
5742 | .TP | |
5743 | .B possible\-command\-completions (C\-x !) | |
5744 | List the possible completions of the text before point, | |
5745 | treating it as a command name. | |
5746 | .TP | |
ccc6cda3 | 5747 | .B dynamic\-complete\-history (M\-TAB) |
726f6388 JA |
5748 | Attempt completion on the text before point, comparing |
5749 | the text against lines from the history list for possible | |
5750 | completion matches. | |
5751 | .TP | |
8943768b CR |
5752 | .B dabbrev\-expand |
5753 | Attempt menu completion on the text before point, comparing | |
5754 | the text against lines from the history list for possible | |
5755 | completion matches. | |
5756 | .TP | |
726f6388 | 5757 | .B complete\-into\-braces (M\-{) |
bb70624e | 5758 | Perform filename completion and insert the list of possible completions |
726f6388 JA |
5759 | enclosed within braces so the list is available to the shell (see |
5760 | .B Brace Expansion | |
5761 | above). | |
5762 | .PD | |
5763 | .SS Keyboard Macros | |
5764 | .PP | |
5765 | .PD 0 | |
5766 | .TP | |
ccc6cda3 | 5767 | .B start\-kbd\-macro (C\-x (\^) |
726f6388 JA |
5768 | Begin saving the characters typed into the current keyboard macro. |
5769 | .TP | |
ccc6cda3 | 5770 | .B end\-kbd\-macro (C\-x )\^) |
726f6388 | 5771 | Stop saving the characters typed into the current keyboard macro |
ccc6cda3 | 5772 | and store the definition. |
726f6388 | 5773 | .TP |
ccc6cda3 | 5774 | .B call\-last\-kbd\-macro (C\-x e) |
726f6388 JA |
5775 | Re-execute the last keyboard macro defined, by making the characters |
5776 | in the macro appear as if typed at the keyboard. | |
5777 | .PD | |
5778 | .SS Miscellaneous | |
5779 | .PP | |
5780 | .PD 0 | |
5781 | .TP | |
5782 | .B re\-read\-init\-file (C\-x C\-r) | |
ccc6cda3 | 5783 | Read in the contents of the \fIinputrc\fP file, and incorporate |
726f6388 JA |
5784 | any bindings or variable assignments found there. |
5785 | .TP | |
5786 | .B abort (C\-g) | |
5787 | Abort the current editing command and | |
5788 | ring the terminal's bell (subject to the setting of | |
5789 | .BR bell\-style ). | |
5790 | .TP | |
ccc6cda3 JA |
5791 | .B do\-uppercase\-version (M\-a, M\-b, M\-\fIx\fP, ...) |
5792 | If the metafied character \fIx\fP is lowercase, run the command | |
5793 | that is bound to the corresponding uppercase character. | |
726f6388 JA |
5794 | .TP |
5795 | .B prefix\-meta (ESC) | |
5796 | Metafy the next character typed. | |
5797 | .SM | |
5798 | .B ESC | |
5799 | .B f | |
5800 | is equivalent to | |
5801 | .BR Meta\-f . | |
5802 | .TP | |
5803 | .B undo (C\-_, C\-x C\-u) | |
5804 | Incremental undo, separately remembered for each line. | |
5805 | .TP | |
5806 | .B revert\-line (M\-r) | |
cce855bc | 5807 | Undo all changes made to this line. This is like executing the |
726f6388 JA |
5808 | .B undo |
5809 | command enough times to return the line to its initial state. | |
5810 | .TP | |
b72432fd | 5811 | .B tilde\-expand (M\-&) |
726f6388 JA |
5812 | Perform tilde expansion on the current word. |
5813 | .TP | |
ccc6cda3 | 5814 | .B set\-mark (C\-@, M\-<space>) |
28ef6c31 | 5815 | Set the mark to the point. If a |
ccc6cda3 JA |
5816 | numeric argument is supplied, the mark is set to that position. |
5817 | .TP | |
5818 | .B exchange\-point\-and\-mark (C\-x C\-x) | |
5819 | Swap the point with the mark. The current cursor position is set to | |
5820 | the saved position, and the old cursor position is saved as the mark. | |
5821 | .TP | |
5822 | .B character\-search (C\-]) | |
5823 | A character is read and point is moved to the next occurrence of that | |
5824 | character. A negative count searches for previous occurrences. | |
5825 | .TP | |
5826 | .B character\-search\-backward (M\-C\-]) | |
5827 | A character is read and point is moved to the previous occurrence of that | |
5828 | character. A negative count searches for subsequent occurrences. | |
5829 | .TP | |
691aebcb CR |
5830 | .B skip\-csi\-sequence () |
5831 | Read enough characters to consume a multi-key sequence such as those | |
5832 | defined for keys like Home and End. Such sequences begin with a | |
5833 | Control Sequence Indicator (CSI), usually ESC\-[. If this sequence is | |
5834 | bound to "\e[", keys producing such sequences will have no effect | |
5835 | unless explicitly bound to a readline command, instead of inserting | |
5836 | stray characters into the editing buffer. This is unbound by default, | |
5837 | but usually bound to ESC\-[. | |
5838 | .TP | |
ccc6cda3 | 5839 | .B insert\-comment (M\-#) |
7117c2d2 | 5840 | Without a numeric argument, the value of the readline |
ccc6cda3 | 5841 | .B comment\-begin |
7117c2d2 JA |
5842 | variable is inserted at the beginning of the current line. |
5843 | If a numeric argument is supplied, this command acts as a toggle: if | |
5844 | the characters at the beginning of the line do not match the value | |
5845 | of \fBcomment\-begin\fP, the value is inserted, otherwise | |
db31fb26 | 5846 | the characters in \fBcomment\-begin\fP are deleted from the beginning of |
7117c2d2 JA |
5847 | the line. |
5848 | In either case, the line is accepted as if a newline had been typed. | |
5849 | The default value of | |
bb70624e | 5850 | \fBcomment\-begin\fP causes this command to make the current line |
ccc6cda3 | 5851 | a shell comment. |
7117c2d2 JA |
5852 | If a numeric argument causes the comment character to be removed, the line |
5853 | will be executed by the shell. | |
5854 | .TP | |
5855 | .B glob\-complete\-word (M\-g) | |
5856 | The word before point is treated as a pattern for pathname expansion, | |
5857 | with an asterisk implicitly appended. This pattern is used to | |
5858 | generate a list of matching file names for possible completions. | |
ccc6cda3 JA |
5859 | .TP |
5860 | .B glob\-expand\-word (C\-x *) | |
5861 | The word before point is treated as a pattern for pathname expansion, | |
5862 | and the list of matching file names is inserted, replacing the word. | |
7117c2d2 JA |
5863 | If a numeric argument is supplied, an asterisk is appended before |
5864 | pathname expansion. | |
ccc6cda3 JA |
5865 | .TP |
5866 | .B glob\-list\-expansions (C\-x g) | |
5867 | The list of expansions that would have been generated by | |
5868 | .B glob\-expand\-word | |
5869 | is displayed, and the line is redrawn. | |
7117c2d2 JA |
5870 | If a numeric argument is supplied, an asterisk is appended before |
5871 | pathname expansion. | |
ccc6cda3 | 5872 | .TP |
726f6388 JA |
5873 | .B dump\-functions |
5874 | Print all of the functions and their key bindings to the | |
5875 | readline output stream. If a numeric argument is supplied, | |
5876 | the output is formatted in such a way that it can be made part | |
5877 | of an \fIinputrc\fP file. | |
5878 | .TP | |
ccc6cda3 JA |
5879 | .B dump\-variables |
5880 | Print all of the settable readline variables and their values to the | |
5881 | readline output stream. If a numeric argument is supplied, | |
5882 | the output is formatted in such a way that it can be made part | |
5883 | of an \fIinputrc\fP file. | |
5884 | .TP | |
5885 | .B dump\-macros | |
5886 | Print all of the readline key sequences bound to macros and the | |
22e63b05 | 5887 | strings they output. If a numeric argument is supplied, |
ccc6cda3 JA |
5888 | the output is formatted in such a way that it can be made part |
5889 | of an \fIinputrc\fP file. | |
5890 | .TP | |
726f6388 JA |
5891 | .B display\-shell\-version (C\-x C\-v) |
5892 | Display version information about the current instance of | |
5893 | .BR bash . | |
5894 | .PD | |
bb70624e JA |
5895 | .SS Programmable Completion |
5896 | .PP | |
5897 | When word completion is attempted for an argument to a command for | |
5898 | which a completion specification (a \fIcompspec\fP) has been defined | |
5899 | using the \fBcomplete\fP builtin (see | |
5900 | .SM | |
5901 | .B "SHELL BUILTIN COMMANDS" | |
5902 | below), the programmable completion facilities are invoked. | |
5903 | .PP | |
5904 | First, the command name is identified. | |
3eb2d94a CR |
5905 | If the command word is the empty string (completion attempted at the |
5906 | beginning of an empty line), any compspec defined with | |
5907 | the \fB\-E\fP option to \fBcomplete\fP is used. | |
bb70624e JA |
5908 | If a compspec has been defined for that command, the |
5909 | compspec is used to generate the list of possible completions for the word. | |
5910 | If the command word is a full pathname, a compspec for the full | |
5911 | pathname is searched for first. | |
5912 | If no compspec is found for the full pathname, an attempt is made to | |
5913 | find a compspec for the portion following the final slash. | |
3eb2d94a CR |
5914 | If those searches to not result in a compspec, any compspec defined with |
5915 | the \fB\-D\fP option to \fBcomplete\fP is used as the default. | |
bb70624e JA |
5916 | .PP |
5917 | Once a compspec has been found, it is used to generate the list of | |
5918 | matching words. | |
5919 | If a compspec is not found, the default \fBbash\fP completion as | |
5920 | described above under \fBCompleting\fP is performed. | |
5921 | .PP | |
5922 | First, the actions specified by the compspec are used. | |
5923 | Only matches which are prefixed by the word being completed are | |
5924 | returned. | |
5925 | When the | |
5926 | .B \-f | |
5927 | or | |
5928 | .B \-d | |
5929 | option is used for filename or directory name completion, the shell | |
5930 | variable | |
5931 | .SM | |
5932 | .B FIGNORE | |
5933 | is used to filter the matches. | |
5934 | .PP | |
d0ca3503 | 5935 | Any completions specified by a pathname expansion pattern to the |
bb70624e JA |
5936 | \fB\-G\fP option are generated next. |
5937 | The words generated by the pattern need not match the word | |
5938 | being completed. | |
5939 | The | |
5940 | .SM | |
5941 | .B GLOBIGNORE | |
5942 | shell variable is not used to filter the matches, but the | |
5943 | .SM | |
5944 | .B FIGNORE | |
5945 | variable is used. | |
5946 | .PP | |
5947 | Next, the string specified as the argument to the \fB\-W\fP option | |
5948 | is considered. | |
5949 | The string is first split using the characters in the | |
5950 | .SM | |
5951 | .B IFS | |
5952 | special variable as delimiters. | |
5953 | Shell quoting is honored. | |
5954 | Each word is then expanded using | |
5955 | brace expansion, tilde expansion, parameter and variable expansion, | |
6e70dbff | 5956 | command substitution, and arithmetic expansion, |
bb70624e JA |
5957 | as described above under |
5958 | .SM | |
5959 | .BR EXPANSION . | |
5960 | The results are split using the rules described above under | |
5961 | \fBWord Splitting\fP. | |
5962 | The results of the expansion are prefix-matched against the word being | |
5963 | completed, and the matching words become the possible completions. | |
5964 | .PP | |
5965 | After these matches have been generated, any shell function or command | |
5966 | specified with the \fB\-F\fP and \fB\-C\fP options is invoked. | |
5967 | When the command or function is invoked, the | |
5968 | .SM | |
d3ad40de CR |
5969 | .BR COMP_LINE , |
5970 | .SM | |
5971 | .BR COMP_POINT , | |
5972 | .SM | |
5973 | .BR COMP_KEY , | |
bb70624e JA |
5974 | and |
5975 | .SM | |
d3ad40de | 5976 | .B COMP_TYPE |
bb70624e JA |
5977 | variables are assigned values as described above under |
5978 | \fBShell Variables\fP. | |
5979 | If a shell function is being invoked, the | |
5980 | .SM | |
5981 | .B COMP_WORDS | |
5982 | and | |
5983 | .SM | |
5984 | .B COMP_CWORD | |
5985 | variables are also set. | |
5986 | When the function or command is invoked, the first argument is the | |
5987 | name of the command whose arguments are being completed, the | |
5988 | second argument is the word being completed, and the third argument | |
5989 | is the word preceding the word being completed on the current command line. | |
5990 | No filtering of the generated completions against the word being completed | |
5991 | is performed; the function or command has complete freedom in generating | |
5992 | the matches. | |
5993 | .PP | |
5994 | Any function specified with \fB\-F\fP is invoked first. | |
5995 | The function may use any of the shell facilities, including the | |
5996 | \fBcompgen\fP builtin described below, to generate the matches. | |
5997 | It must put the possible completions in the | |
5998 | .SM | |
5999 | .B COMPREPLY | |
6000 | array variable. | |
6001 | .PP | |
6002 | Next, any command specified with the \fB\-C\fP option is invoked | |
6003 | in an environment equivalent to command substitution. | |
6004 | It should print a list of completions, one per line, to the | |
6005 | standard output. | |
6006 | Backslash may be used to escape a newline, if necessary. | |
6007 | .PP | |
6008 | After all of the possible completions are generated, any filter | |
6009 | specified with the \fB\-X\fP option is applied to the list. | |
6010 | The filter is a pattern as used for pathname expansion; a \fB&\fP | |
6011 | in the pattern is replaced with the text of the word being completed. | |
6012 | A literal \fB&\fP may be escaped with a backslash; the backslash | |
6013 | is removed before attempting a match. | |
6014 | Any completion that matches the pattern will be removed from the list. | |
6015 | A leading \fB!\fP negates the pattern; in this case any completion | |
6016 | not matching the pattern will be removed. | |
6017 | .PP | |
6018 | Finally, any prefix and suffix specified with the \fB\-P\fP and \fB\-S\fP | |
6019 | options are added to each member of the completion list, and the result is | |
6020 | returned to the readline completion code as the list of possible | |
6021 | completions. | |
6022 | .PP | |
28ef6c31 JA |
6023 | If the previously-applied actions do not generate any matches, and the |
6024 | \fB\-o dirnames\fP option was supplied to \fBcomplete\fP when the | |
6025 | compspec was defined, directory name completion is attempted. | |
6026 | .PP | |
d3a24ed2 CR |
6027 | If the \fB\-o plusdirs\fP option was supplied to \fBcomplete\fP when the |
6028 | compspec was defined, directory name completion is attempted and any | |
6029 | matches are added to the results of the other actions. | |
6030 | .PP | |
28ef6c31 JA |
6031 | By default, if a compspec is found, whatever it generates is returned |
6032 | to the completion code as the full set of possible completions. | |
bb70624e JA |
6033 | The default \fBbash\fP completions are not attempted, and the readline |
6034 | default of filename completion is disabled. | |
d3a24ed2 CR |
6035 | If the \fB\-o bashdefault\fP option was supplied to \fBcomplete\fP when |
6036 | the compspec was defined, the \fBbash\fP default completions are attempted | |
28ef6c31 | 6037 | if the compspec generates no matches. |
d3a24ed2 CR |
6038 | If the \fB\-o default\fP option was supplied to \fBcomplete\fP when the |
6039 | compspec was defined, readline's default completion will be performed | |
6040 | if the compspec (and, if attempted, the default \fBbash\fP completions) | |
6041 | generate no matches. | |
7117c2d2 JA |
6042 | .PP |
6043 | When a compspec indicates that directory name completion is desired, | |
6044 | the programmable completion functions force readline to append a slash | |
6045 | to completed names which are symbolic links to directories, subject to | |
6046 | the value of the \fBmark\-directories\fP readline variable, regardless | |
6047 | of the setting of the \fBmark-symlinked\-directories\fP readline variable. | |
3eb2d94a CR |
6048 | .PP |
6049 | There is some support for dynamically modifying completions. This is | |
6050 | most useful when used in combination with a default completion specified | |
6051 | with \fBcomplete -D\fP. | |
6052 | It's possible for shell functions executed as completion | |
6053 | handlers to indicate that completion should be retried by returning an | |
6054 | exit status of 124. If a shell function returns 124, and changes | |
6055 | the compspec associated with the command on which completion is being | |
6056 | attempted (supplied as the first argument when the function is executed), | |
6057 | programmable completion restarts from the beginning, with an | |
3d8cce26 | 6058 | attempt to find a new compspec for that command. This allows a set of |
3eb2d94a CR |
6059 | completions to be built dynamically as completion is attempted, rather than |
6060 | being loaded all at once. | |
6061 | .PP | |
6062 | For instance, assuming that there is a library of compspecs, each kept in a | |
6063 | file corresponding to the name of the command, the following default | |
6064 | completion function would load completions dynamically: | |
6065 | .PP | |
6066 | \f(CW_completion_loader() | |
6067 | .br | |
6068 | { | |
6069 | .br | |
6070 | . "/etc/bash_completion.d/$1.sh" >/dev/null 2>&1 && return 124 | |
6071 | .br | |
6072 | } | |
6073 | .br | |
6074 | complete -D -F _completion_loader | |
6075 | .br | |
6076 | \fP | |
726f6388 | 6077 | .SH HISTORY |
ccc6cda3 | 6078 | When the |
d166f048 | 6079 | .B \-o history |
ccc6cda3 JA |
6080 | option to the |
6081 | .B set | |
6082 | builtin is enabled, the shell provides access to the | |
6083 | \fIcommand history\fP, | |
bb70624e | 6084 | the list of commands previously typed. |
984a1947 CR |
6085 | The value of the |
6086 | .SM | |
6087 | .B HISTSIZE | |
6088 | variable is used as the | |
bb70624e JA |
6089 | number of commands to save in a history list. |
6090 | The text of the last | |
726f6388 JA |
6091 | .SM |
6092 | .B HISTSIZE | |
bb70624e | 6093 | commands (default 500) is saved. The shell |
726f6388 JA |
6094 | stores each command in the history list prior to parameter and |
6095 | variable expansion (see | |
6096 | .SM | |
6097 | .B EXPANSION | |
6098 | above) but after history expansion is performed, subject to the | |
6099 | values of the shell variables | |
ccc6cda3 JA |
6100 | .SM |
6101 | .B HISTIGNORE | |
726f6388 JA |
6102 | and |
6103 | .SM | |
6104 | .BR HISTCONTROL . | |
bb70624e | 6105 | .PP |
726f6388 JA |
6106 | On startup, the history is initialized from the file named by |
6107 | the variable | |
6108 | .SM | |
6109 | .B HISTFILE | |
6110 | (default \fI~/.bash_history\fP). | |
bb70624e | 6111 | The file named by the value of |
726f6388 JA |
6112 | .SM |
6113 | .B HISTFILE | |
6114 | is truncated, if necessary, to contain no more than | |
bb70624e | 6115 | the number of lines specified by the value of |
726f6388 | 6116 | .SM |
bb70624e | 6117 | .BR HISTFILESIZE . |
d3ad40de CR |
6118 | When the history file is read, |
6119 | lines beginning with the history comment character followed immediately | |
6120 | by a digit are interpreted as timestamps for the preceding history line. | |
6121 | These timestamps are optionally displayed depending on the value of the | |
6122 | .SM | |
6123 | .B HISTTIMEFORMAT | |
6124 | variable. | |
ccc6cda3 JA |
6125 | When an interactive shell exits, the last |
6126 | .SM | |
bb70624e | 6127 | .B $HISTSIZE |
ccc6cda3 JA |
6128 | lines are copied from the history list to |
6129 | .SM | |
bb70624e | 6130 | .BR $HISTFILE . |
ccc6cda3 JA |
6131 | If the |
6132 | .B histappend | |
6133 | shell option is enabled | |
6134 | (see the description of | |
6135 | .B shopt | |
6136 | under | |
6137 | .SM | |
6138 | .B "SHELL BUILTIN COMMANDS" | |
6139 | below), the lines are appended to the history file, | |
6140 | otherwise the history file is overwritten. | |
6141 | If | |
6142 | .SM | |
6143 | .B HISTFILE | |
6144 | is unset, or if the history file is unwritable, the history is | |
d3ad40de CR |
6145 | not saved. |
6146 | If the | |
6147 | .SM | |
984a1947 | 6148 | .B HISTTIMEFORMAT |
d3ad40de CR |
6149 | variable is set, time stamps are written to the history file, marked |
6150 | with the history comment character, so | |
6151 | they may be preserved across shell sessions. | |
6152 | This uses the history comment character to distinguish timestamps from | |
6153 | other history lines. | |
6154 | After saving the history, the history file is truncated | |
ccc6cda3 JA |
6155 | to contain no more than |
6156 | .SM | |
6157 | .B HISTFILESIZE | |
6158 | lines. If | |
6159 | .SM | |
6160 | .B HISTFILESIZE | |
6161 | is not set, no truncation is performed. | |
6162 | .PP | |
726f6388 JA |
6163 | The builtin command |
6164 | .B fc | |
6165 | (see | |
6166 | .SM | |
6167 | .B SHELL BUILTIN COMMANDS | |
6168 | below) may be used to list or edit and re-execute a portion of | |
6169 | the history list. | |
6170 | The | |
6171 | .B history | |
bb70624e | 6172 | builtin may be used to display or modify the history list and |
ccc6cda3 | 6173 | manipulate the history file. |
bb70624e | 6174 | When using command-line editing, search commands |
726f6388 | 6175 | are available in each editing mode that provide access to the |
ccc6cda3 JA |
6176 | history list. |
6177 | .PP | |
6178 | The shell allows control over which commands are saved on the history | |
6179 | list. The | |
726f6388 | 6180 | .SM |
ccc6cda3 JA |
6181 | .B HISTCONTROL |
6182 | and | |
726f6388 | 6183 | .SM |
ccc6cda3 JA |
6184 | .B HISTIGNORE |
6185 | variables may be set to cause the shell to save only a subset of the | |
6186 | commands entered. | |
6187 | The | |
6188 | .B cmdhist | |
6189 | shell option, if enabled, causes the shell to attempt to save each | |
6190 | line of a multi-line command in the same history entry, adding | |
6191 | semicolons where necessary to preserve syntactic correctness. | |
6192 | The | |
6193 | .B lithist | |
6194 | shell option causes the shell to save the command with embedded newlines | |
6195 | instead of semicolons. See the description of the | |
6196 | .B shopt | |
6197 | builtin below under | |
6198 | .SM | |
6199 | .B "SHELL BUILTIN COMMANDS" | |
6200 | for information on setting and unsetting shell options. | |
726f6388 JA |
6201 | .SH "HISTORY EXPANSION" |
6202 | .PP | |
6203 | The shell supports a history expansion feature that | |
6204 | is similar to the history expansion in | |
6205 | .BR csh. | |
6206 | This section describes what syntax features are available. This | |
6207 | feature is enabled by default for interactive shells, and can be | |
6208 | disabled using the | |
6209 | .B \+H | |
6210 | option to the | |
6211 | .B set | |
6212 | builtin command (see | |
6213 | .SM | |
6214 | .B SHELL BUILTIN COMMANDS | |
ccc6cda3 JA |
6215 | below). Non-interactive shells do not perform history expansion |
6216 | by default. | |
6217 | .PP | |
6218 | History expansions introduce words from the history list into | |
6219 | the input stream, making it easy to repeat commands, insert the | |
6220 | arguments to a previous command into the current input line, or | |
6221 | fix errors in previous commands quickly. | |
726f6388 JA |
6222 | .PP |
6223 | History expansion is performed immediately after a complete line | |
6224 | is read, before the shell breaks it into words. | |
ccc6cda3 | 6225 | It takes place in two parts. |
cce855bc | 6226 | The first is to determine which line from the history list |
ccc6cda3 JA |
6227 | to use during substitution. |
6228 | The second is to select portions of that line for inclusion into | |
6229 | the current one. | |
cce855bc | 6230 | The line selected from the history is the \fIevent\fP, |
ccc6cda3 JA |
6231 | and the portions of that line that are acted upon are \fIwords\fP. |
6232 | Various \fImodifiers\fP are available to manipulate the selected words. | |
6233 | The line is broken into words in the same fashion as when reading input, | |
6234 | so that several \fImetacharacter\fP-separated words surrounded by | |
cce855bc | 6235 | quotes are considered one word. |
ccc6cda3 JA |
6236 | History expansions are introduced by the appearance of the |
6237 | history expansion character, which is \^\fB!\fP\^ by default. | |
6238 | Only backslash (\^\fB\e\fP\^) and single quotes can quote | |
6239 | the history expansion character. | |
6240 | .PP | |
d3a24ed2 CR |
6241 | Several characters inhibit history expansion if found immediately |
6242 | following the history expansion character, even if it is unquoted: | |
6243 | space, tab, newline, carriage return, and \fB=\fP. | |
6244 | If the \fBextglob\fP shell option is enabled, \fB(\fP will also | |
6245 | inhibit expansion. | |
6246 | .PP | |
ccc6cda3 JA |
6247 | Several shell options settable with the |
6248 | .B shopt | |
6249 | builtin may be used to tailor the behavior of history expansion. | |
6250 | If the | |
6251 | .B histverify | |
6252 | shell option is enabled (see the description of the | |
6253 | .B shopt | |
984a1947 | 6254 | builtin below), and |
ccc6cda3 JA |
6255 | .B readline |
6256 | is being used, history substitutions are not immediately passed to | |
6257 | the shell parser. | |
6258 | Instead, the expanded line is reloaded into the | |
6259 | .B readline | |
6260 | editing buffer for further modification. | |
6261 | If | |
6262 | .B readline | |
6263 | is being used, and the | |
6264 | .B histreedit | |
6265 | shell option is enabled, a failed history substitution will be reloaded | |
6266 | into the | |
6267 | .B readline | |
6268 | editing buffer for correction. | |
6269 | The | |
6270 | .B \-p | |
6271 | option to the | |
6272 | .B history | |
6273 | builtin command may be used to see what a history expansion will | |
6274 | do before using it. | |
6275 | The | |
6276 | .B \-s | |
6277 | option to the | |
6278 | .B history | |
6279 | builtin may be used to add commands to the end of the history list | |
6280 | without actually executing them, so that they are available for | |
6281 | subsequent recall. | |
726f6388 JA |
6282 | .PP |
6283 | The shell allows control of the various characters used by the | |
6284 | history expansion mechanism (see the description of | |
6285 | .B histchars | |
6286 | above under | |
6287 | .BR "Shell Variables" ). | |
d3ad40de CR |
6288 | The shell uses |
6289 | the history comment character to mark history timestamps when | |
6290 | writing the history file. | |
726f6388 JA |
6291 | .SS Event Designators |
6292 | .PP | |
6293 | An event designator is a reference to a command line entry in the | |
6294 | history list. | |
6295 | .PP | |
6296 | .PD 0 | |
6297 | .TP | |
6298 | .B ! | |
6299 | Start a history substitution, except when followed by a | |
6300 | .BR blank , | |
d3a24ed2 CR |
6301 | newline, carriage return, = |
6302 | or ( (when the \fBextglob\fP shell option is enabled using | |
6303 | the \fBshopt\fP builtin). | |
726f6388 | 6304 | .TP |
726f6388 JA |
6305 | .B !\fIn\fR |
6306 | Refer to command line | |
6307 | .IR n . | |
6308 | .TP | |
6309 | .B !\-\fIn\fR | |
6310 | Refer to the current command line minus | |
6311 | .IR n . | |
6312 | .TP | |
ccc6cda3 JA |
6313 | .B !! |
6314 | Refer to the previous command. This is a synonym for `!\-1'. | |
6315 | .TP | |
726f6388 JA |
6316 | .B !\fIstring\fR |
6317 | Refer to the most recent command starting with | |
6318 | .IR string . | |
6319 | .TP | |
6320 | .B !?\fIstring\fR\fB[?]\fR | |
6321 | Refer to the most recent command containing | |
6322 | .IR string . | |
ccc6cda3 JA |
6323 | The trailing \fB?\fP may be omitted if |
6324 | .I string | |
6325 | is followed immediately by a newline. | |
726f6388 JA |
6326 | .TP |
6327 | .B \d\s+2^\s-2\u\fIstring1\fP\d\s+2^\s-2\u\fIstring2\fP\d\s+2^\s-2\u | |
6328 | Quick substitution. Repeat the last command, replacing | |
6329 | .I string1 | |
6330 | with | |
6331 | .IR string2 . | |
6332 | Equivalent to | |
6333 | ``!!:s/\fIstring1\fP/\fIstring2\fP/'' | |
6334 | (see \fBModifiers\fP below). | |
6335 | .TP | |
6336 | .B !# | |
6337 | The entire command line typed so far. | |
6338 | .PD | |
6339 | .SS Word Designators | |
6340 | .PP | |
ccc6cda3 | 6341 | Word designators are used to select desired words from the event. |
726f6388 JA |
6342 | A |
6343 | .B : | |
ccc6cda3 | 6344 | separates the event specification from the word designator. |
cce855bc | 6345 | It may be omitted if the word designator begins with a |
726f6388 JA |
6346 | .BR ^ , |
6347 | .BR $ , | |
6348 | .BR * , | |
ccc6cda3 | 6349 | .BR \- , |
726f6388 JA |
6350 | or |
6351 | .BR % . | |
6352 | Words are numbered from the beginning of the line, | |
ccc6cda3 JA |
6353 | with the first word being denoted by 0 (zero). |
6354 | Words are inserted into the current line separated by single spaces. | |
726f6388 JA |
6355 | .PP |
6356 | .PD 0 | |
6357 | .TP | |
6358 | .B 0 (zero) | |
6359 | The zeroth word. For the shell, this is the command | |
6360 | word. | |
6361 | .TP | |
6362 | .I n | |
6363 | The \fIn\fRth word. | |
6364 | .TP | |
6365 | .B ^ | |
6366 | The first argument. That is, word 1. | |
6367 | .TP | |
6368 | .B $ | |
6369 | The last argument. | |
6370 | .TP | |
6371 | .B % | |
6372 | The word matched by the most recent `?\fIstring\fR?' search. | |
6373 | .TP | |
6374 | .I x\fB\-\fPy | |
6375 | A range of words; `\-\fIy\fR' abbreviates `0\-\fIy\fR'. | |
6376 | .TP | |
6377 | .B * | |
6378 | All of the words but the zeroth. This is a synonym | |
6379 | for `\fI1\-$\fP'. It is not an error to use | |
6380 | .B * | |
6381 | if there is just one | |
6382 | word in the event; the empty string is returned in that case. | |
6383 | .TP | |
6384 | .B x* | |
6385 | Abbreviates \fIx\-$\fP. | |
6386 | .TP | |
6387 | .B x\- | |
6388 | Abbreviates \fIx\-$\fP like \fBx*\fP, but omits the last word. | |
6389 | .PD | |
ccc6cda3 JA |
6390 | .PP |
6391 | If a word designator is supplied without an event specification, the | |
6392 | previous command is used as the event. | |
726f6388 JA |
6393 | .SS Modifiers |
6394 | .PP | |
ccc6cda3 JA |
6395 | After the optional word designator, there may appear a sequence of |
6396 | one or more of the following modifiers, each preceded by a `:'. | |
726f6388 JA |
6397 | .PP |
6398 | .PD 0 | |
6399 | .PP | |
6400 | .TP | |
6401 | .B h | |
ccc6cda3 JA |
6402 | Remove a trailing file name component, leaving only the head. |
6403 | .TP | |
6404 | .B t | |
6405 | Remove all leading file name components, leaving the tail. | |
726f6388 JA |
6406 | .TP |
6407 | .B r | |
6408 | Remove a trailing suffix of the form \fI.xxx\fP, leaving the | |
6409 | basename. | |
6410 | .TP | |
6411 | .B e | |
6412 | Remove all but the trailing suffix. | |
6413 | .TP | |
726f6388 JA |
6414 | .B p |
6415 | Print the new command but do not execute it. | |
6416 | .TP | |
6417 | .B q | |
6418 | Quote the substituted words, escaping further substitutions. | |
6419 | .TP | |
cce855bc JA |
6420 | .B x |
6421 | Quote the substituted words as with | |
6422 | .BR q , | |
6423 | but break into words at | |
6424 | .B blanks | |
6425 | and newlines. | |
726f6388 | 6426 | .TP |
cce855bc JA |
6427 | .B s/\fIold\fP/\fInew\fP/ |
6428 | Substitute | |
6429 | .I new | |
6430 | for the first occurrence of | |
6431 | .I old | |
6432 | in the event line. Any delimiter can be used in place of /. The | |
6433 | final delimiter is optional if it is the last character of the | |
6434 | event line. The delimiter may be quoted in | |
6435 | .I old | |
6436 | and | |
6437 | .I new | |
6438 | with a single backslash. If & appears in | |
6439 | .IR new , | |
6440 | it is replaced by | |
6441 | .IR old . | |
6442 | A single backslash will quote the &. If | |
6443 | .I old | |
6444 | is null, it is set to the last | |
6445 | .I old | |
6446 | substituted, or, if no previous history substitutions took place, | |
6447 | the last | |
6448 | .I string | |
6449 | in a | |
6450 | .B !?\fIstring\fR\fB[?]\fR | |
6451 | search. | |
ccc6cda3 | 6452 | .TP |
cce855bc JA |
6453 | .B & |
6454 | Repeat the previous substitution. | |
6455 | .TP | |
6456 | .B g | |
6457 | Cause changes to be applied over the entire event line. This is | |
6458 | used in conjunction with `\fB:s\fP' (e.g., `\fB:gs/\fIold\fP/\fInew\fP/\fR') | |
6459 | or `\fB:&\fP'. If used with | |
6460 | `\fB:s\fP', any delimiter can be used | |
6461 | in place of /, and the final delimiter is optional | |
6462 | if it is the last character of the event line. | |
d3a24ed2 CR |
6463 | An \fBa\fP may be used as a synonym for \fBg\fP. |
6464 | .TP | |
6465 | .B G | |
6466 | Apply the following `\fBs\fP' modifier once to each word in the event line. | |
726f6388 | 6467 | .PD |
726f6388 JA |
6468 | .SH "SHELL BUILTIN COMMANDS" |
6469 | .\" start of bash_builtins | |
6470 | .zZ | |
ccc6cda3 JA |
6471 | .PP |
6472 | Unless otherwise noted, each builtin command documented in this | |
6473 | section as accepting options preceded by | |
6474 | .B \- | |
6475 | accepts | |
6476 | .B \-\- | |
6477 | to signify the end of the options. | |
6932f7f5 CR |
6478 | The \fB:\fP, \fBtrue\fP, \fBfalse\fP, and \fBtest\fP builtins |
6479 | do not accept options and do not treat \fB\-\-\fP specially. | |
6480 | The \fBexit\fP, \fBlogout\fP, \fBbreak\fP, \fBcontinue\fP, \fBlet\fP, | |
6481 | and \fBshift\fP builtins accept and process arguments beginning with | |
6482 | \fB\-\fP without requiring \fB\-\-\fP. | |
6483 | Other builtins that accept arguments but are not specified as accepting | |
6484 | options interpret arguments beginning with \fB\-\fP as invalid options and | |
6485 | require \fB\-\-\fP to prevent this interpretation. | |
ccc6cda3 | 6486 | .sp .5 |
726f6388 JA |
6487 | .PD 0 |
6488 | .TP | |
6489 | \fB:\fP [\fIarguments\fP] | |
6490 | .PD | |
6491 | No effect; the command does nothing beyond expanding | |
6492 | .I arguments | |
6493 | and performing any specified | |
6494 | redirections. A zero exit code is returned. | |
6495 | .TP | |
726f6388 | 6496 | \fB .\| \fP \fIfilename\fP [\fIarguments\fP] |
7117c2d2 | 6497 | .PD 0 |
726f6388 JA |
6498 | .TP |
6499 | \fBsource\fP \fIfilename\fP [\fIarguments\fP] | |
6500 | .PD | |
6501 | Read and execute commands from | |
6502 | .I filename | |
6503 | in the current | |
6504 | shell environment and return the exit status of the last command | |
6505 | executed from | |
6506 | .IR filename . | |
6507 | If | |
6508 | .I filename | |
ccc6cda3 | 6509 | does not contain a slash, file names in |
726f6388 JA |
6510 | .SM |
6511 | .B PATH | |
6512 | are used to find the directory containing | |
6513 | .IR filename . | |
6514 | The file searched for in | |
6515 | .SM | |
6516 | .B PATH | |
28ef6c31 JA |
6517 | need not be executable. |
6518 | When \fBbash\fP is not in \fIposix mode\fP, the current directory is | |
726f6388 JA |
6519 | searched if no file is found in |
6520 | .SM | |
6521 | .BR PATH . | |
ccc6cda3 JA |
6522 | If the |
6523 | .B sourcepath | |
6524 | option to the | |
6525 | .B shopt | |
6526 | builtin command is turned off, the | |
6527 | .SM | |
6528 | .B PATH | |
6529 | is not searched. | |
726f6388 | 6530 | If any \fIarguments\fP are supplied, they become the positional |
ccc6cda3 | 6531 | parameters when \fIfilename\fP is executed. Otherwise the positional |
726f6388 JA |
6532 | parameters are unchanged. |
6533 | The return status is the status of the last command exited within | |
6534 | the script (0 if no commands are executed), and false if | |
6535 | .I filename | |
cce855bc | 6536 | is not found or cannot be read. |
726f6388 | 6537 | .TP |
ccc6cda3 JA |
6538 | \fBalias\fP [\fB\-p\fP] [\fIname\fP[=\fIvalue\fP] ...] |
6539 | \fBAlias\fP with no arguments or with the | |
6540 | .B \-p | |
6541 | option prints the list of aliases in the form | |
6542 | \fBalias\fP \fIname\fP=\fIvalue\fP on standard output. | |
6543 | When arguments are supplied, an alias is defined for | |
6544 | each \fIname\fP whose \fIvalue\fP is given. | |
6545 | A trailing space in \fIvalue\fP causes the next word to be | |
6546 | checked for alias substitution when the alias is expanded. | |
6547 | For each \fIname\fP in the argument list for which no \fIvalue\fP | |
6548 | is supplied, the name and value of the alias is printed. | |
6549 | \fBAlias\fP returns true unless a \fIname\fP is given for which | |
6550 | no alias has been defined. | |
726f6388 | 6551 | .TP |
de3341d1 CR |
6552 | \fBbg\fP [\fIjobspec\fP ...] |
6553 | Resume each suspended job \fIjobspec\fP in the background, as if it | |
cce855bc | 6554 | had been started with |
726f6388 | 6555 | .BR & . |
d3ad40de CR |
6556 | If |
6557 | .I jobspec | |
6558 | is not present, the shell's notion of the \fIcurrent job\fP is used. | |
726f6388 JA |
6559 | .B bg |
6560 | .I jobspec | |
6561 | returns 0 unless run when job control is disabled or, when run with | |
ff247e74 CR |
6562 | job control enabled, any specified \fIjobspec\fP was not found |
6563 | or was started without job control. | |
726f6388 | 6564 | .TP |
cce855bc | 6565 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] [\fB\-lpsvPSV\fP] |
7117c2d2 | 6566 | .PD 0 |
cce855bc JA |
6567 | .TP |
6568 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] [\fB\-q\fP \fIfunction\fP] [\fB\-u\fP \fIfunction\fP] [\fB\-r\fP \fIkeyseq\fP] | |
726f6388 | 6569 | .TP |
ccc6cda3 | 6570 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fB\-f\fP \fIfilename\fP |
726f6388 | 6571 | .TP |
bb70624e JA |
6572 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fB\-x\fP \fIkeyseq\fP:\fIshell\-command\fP |
6573 | .TP | |
ccc6cda3 | 6574 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fIkeyseq\fP:\fIfunction\-name\fP |
7117c2d2 JA |
6575 | .TP |
6576 | \fBbind\fP \fIreadline\-command\fP | |
726f6388 JA |
6577 | .PD |
6578 | Display current | |
6579 | .B readline | |
7117c2d2 | 6580 | key and function bindings, bind a key sequence to a |
726f6388 | 6581 | .B readline |
7117c2d2 JA |
6582 | function or macro, or set a |
6583 | .B readline | |
6584 | variable. | |
6585 | Each non-option argument is a command as it would appear in | |
726f6388 | 6586 | .IR .inputrc , |
7117c2d2 JA |
6587 | but each binding or command must be passed as a separate argument; |
6588 | e.g., '"\eC\-x\eC\-r": re\-read\-init\-file'. | |
6589 | Options, if supplied, have the following meanings: | |
726f6388 JA |
6590 | .RS |
6591 | .PD 0 | |
6592 | .TP | |
6593 | .B \-m \fIkeymap\fP | |
6594 | Use | |
6595 | .I keymap | |
6596 | as the keymap to be affected by the subsequent bindings. | |
6597 | Acceptable | |
6598 | .I keymap | |
6599 | names are | |
ccc6cda3 | 6600 | \fIemacs, emacs\-standard, emacs\-meta, emacs\-ctlx, vi, |
28ef6c31 | 6601 | vi\-move, vi\-command\fP, and |
ccc6cda3 JA |
6602 | .IR vi\-insert . |
6603 | \fIvi\fP is equivalent to \fIvi\-command\fP; \fIemacs\fP is | |
6604 | equivalent to \fIemacs\-standard\fP. | |
726f6388 JA |
6605 | .TP |
6606 | .B \-l | |
ccc6cda3 JA |
6607 | List the names of all \fBreadline\fP functions. |
6608 | .TP | |
6609 | .B \-p | |
6610 | Display \fBreadline\fP function names and bindings in such a way | |
6611 | that they can be re-read. | |
6612 | .TP | |
6613 | .B \-P | |
6614 | List current \fBreadline\fP function names and bindings. | |
726f6388 | 6615 | .TP |
ccc6cda3 JA |
6616 | .B \-s |
6617 | Display \fBreadline\fP key sequences bound to macros and the strings | |
6618 | they output in such a way that they can be re-read. | |
6619 | .TP | |
6620 | .B \-S | |
6621 | Display \fBreadline\fP key sequences bound to macros and the strings | |
6622 | they output. | |
726f6388 | 6623 | .TP |
d3ad40de CR |
6624 | .B \-v |
6625 | Display \fBreadline\fP variable names and values in such a way that they | |
6626 | can be re-read. | |
6627 | .TP | |
6628 | .B \-V | |
6629 | List current \fBreadline\fP variable names and values. | |
6630 | .TP | |
726f6388 | 6631 | .B \-f \fIfilename\fP |
ccc6cda3 | 6632 | Read key bindings from \fIfilename\fP. |
726f6388 JA |
6633 | .TP |
6634 | .B \-q \fIfunction\fP | |
ccc6cda3 JA |
6635 | Query about which keys invoke the named \fIfunction\fP. |
6636 | .TP | |
cce855bc JA |
6637 | .B \-u \fIfunction\fP |
6638 | Unbind all keys bound to the named \fIfunction\fP. | |
6639 | .TP | |
ccc6cda3 JA |
6640 | .B \-r \fIkeyseq\fP |
6641 | Remove any current binding for \fIkeyseq\fP. | |
bb70624e JA |
6642 | .TP |
6643 | .B \-x \fIkeyseq\fP:\fIshell\-command\fP | |
6644 | Cause \fIshell\-command\fP to be executed whenever \fIkeyseq\fP is | |
6645 | entered. | |
8943768b | 6646 | When \fIshell\-command\fP is executed, the shell sets the |
984a1947 | 6647 | .SM |
8943768b CR |
6648 | .B READLINE_LINE |
6649 | variable to the contents of the \fBreadline\fP line buffer and the | |
984a1947 | 6650 | .SM |
8943768b CR |
6651 | .B READLINE_POINT |
6652 | variable to the current location of the insertion point. | |
6653 | If the executed command changes the value of | |
984a1947 | 6654 | .SM |
8943768b CR |
6655 | .B READLINE_LINE |
6656 | or | |
984a1947 | 6657 | .SM |
8943768b CR |
6658 | .BR READLINE_POINT , |
6659 | those new values will be reflected in the editing state. | |
726f6388 JA |
6660 | .PD |
6661 | .PP | |
6662 | The return value is 0 unless an unrecognized option is given or an | |
6663 | error occurred. | |
6664 | .RE | |
6665 | .TP | |
6666 | \fBbreak\fP [\fIn\fP] | |
6667 | Exit from within a | |
6668 | .BR for , | |
6669 | .BR while , | |
ccc6cda3 | 6670 | .BR until , |
726f6388 | 6671 | or |
ccc6cda3 | 6672 | .B select |
726f6388 JA |
6673 | loop. If \fIn\fP is specified, break \fIn\fP levels. |
6674 | .I n | |
6675 | must be \(>= 1. If | |
6676 | .I n | |
6677 | is greater than the number of enclosing loops, all enclosing loops | |
33fe8777 CR |
6678 | are exited. |
6679 | The return value is 0 unless \fIn\fP is not greater than or equal to 1. | |
726f6388 JA |
6680 | .TP |
6681 | \fBbuiltin\fP \fIshell\-builtin\fP [\fIarguments\fP] | |
6682 | Execute the specified shell builtin, passing it | |
6683 | .IR arguments , | |
6684 | and return its exit status. | |
cce855bc | 6685 | This is useful when defining a |
726f6388 | 6686 | function whose name is the same as a shell builtin, |
cce855bc JA |
6687 | retaining the functionality of the builtin within the function. |
6688 | The \fBcd\fP builtin is commonly redefined this way. | |
6689 | The return status is false if | |
726f6388 JA |
6690 | .I shell\-builtin |
6691 | is not a shell builtin command. | |
6692 | .TP | |
6a8fd0ed CR |
6693 | \fBcaller\fP [\fIexpr\fP] |
6694 | Returns the context of any active subroutine call (a shell function or | |
5cdaaf76 | 6695 | a script executed with the \fB.\fP or \fBsource\fP builtins). |
6a8fd0ed CR |
6696 | Without \fIexpr\fP, \fBcaller\fP displays the line number and source |
6697 | filename of the current subroutine call. | |
6698 | If a non-negative integer is supplied as \fIexpr\fP, \fBcaller\fP | |
6699 | displays the line number, subroutine name, and source file corresponding | |
6700 | to that position in the current execution call stack. This extra | |
6701 | information may be used, for example, to print a stack trace. The | |
6702 | current frame is frame 0. | |
6703 | The return value is 0 unless the shell is not executing a subroutine | |
6704 | call or \fIexpr\fP does not correspond to a valid position in the | |
6705 | call stack. | |
6706 | .TP | |
7117c2d2 | 6707 | \fBcd\fP [\fB\-L|-P\fP] [\fIdir\fP] |
726f6388 JA |
6708 | Change the current directory to \fIdir\fP. The variable |
6709 | .SM | |
6710 | .B HOME | |
6711 | is the | |
6712 | default | |
6713 | .IR dir . | |
6714 | The variable | |
6715 | .SM | |
6716 | .B CDPATH | |
ccc6cda3 | 6717 | defines the search path for the directory containing |
726f6388 | 6718 | .IR dir . |
ccc6cda3 JA |
6719 | Alternative directory names in |
6720 | .SM | |
6721 | .B CDPATH | |
6722 | are separated by a colon (:). A null directory name in | |
726f6388 JA |
6723 | .SM |
6724 | .B CDPATH | |
ccc6cda3 | 6725 | is the same as the current directory, i.e., ``\fB.\fP''. If |
726f6388 JA |
6726 | .I dir |
6727 | begins with a slash (/), | |
6728 | then | |
6729 | .SM | |
6730 | .B CDPATH | |
ccc6cda3 JA |
6731 | is not used. The |
6732 | .B \-P | |
6733 | option says to use the physical directory structure instead of | |
6734 | following symbolic links (see also the | |
6735 | .B \-P | |
6736 | option to the | |
6737 | .B set | |
6738 | builtin command); the | |
6739 | .B \-L | |
6740 | option forces symbolic links to be followed. An argument of | |
726f6388 JA |
6741 | .B \- |
6742 | is equivalent to | |
6743 | .SM | |
6744 | .BR $OLDPWD . | |
984a1947 CR |
6745 | If a non-empty directory name from |
6746 | .SM | |
6747 | .B CDPATH | |
6748 | is used, or if | |
d3a24ed2 CR |
6749 | \fB\-\fP is the first argument, and the directory change is |
6750 | successful, the absolute pathname of the new working directory is | |
6751 | written to the standard output. | |
726f6388 JA |
6752 | The return value is true if the directory was successfully changed; |
6753 | false otherwise. | |
6754 | .TP | |
ccc6cda3 | 6755 | \fBcommand\fP [\fB\-pVv\fP] \fIcommand\fP [\fIarg\fP ...] |
726f6388 JA |
6756 | Run |
6757 | .I command | |
6758 | with | |
6759 | .I args | |
6760 | suppressing the normal shell function lookup. Only builtin | |
6761 | commands or commands found in the | |
6762 | .SM | |
6763 | .B PATH | |
6764 | are executed. If the | |
6765 | .B \-p | |
6766 | option is given, the search for | |
6767 | .I command | |
6768 | is performed using a default value for | |
984a1947 | 6769 | .SM |
726f6388 JA |
6770 | .B PATH |
6771 | that is guaranteed to find all of the standard utilities. | |
6772 | If either the | |
6773 | .B \-V | |
6774 | or | |
6775 | .B \-v | |
6776 | option is supplied, a description of | |
6777 | .I command | |
6778 | is printed. The | |
6779 | .B \-v | |
ccc6cda3 | 6780 | option causes a single word indicating the command or file name |
726f6388 JA |
6781 | used to invoke |
6782 | .I command | |
cce855bc | 6783 | to be displayed; the |
726f6388 JA |
6784 | .B \-V |
6785 | option produces a more verbose description. | |
726f6388 JA |
6786 | If the |
6787 | .B \-V | |
6788 | or | |
6789 | .B \-v | |
6790 | option is supplied, the exit status is 0 if | |
6791 | .I command | |
6792 | was found, and 1 if not. If neither option is supplied and | |
6793 | an error occurred or | |
6794 | .I command | |
6795 | cannot be found, the exit status is 127. Otherwise, the exit status of the | |
6796 | .B command | |
6797 | builtin is the exit status of | |
6798 | .IR command . | |
6799 | .TP | |
bb70624e JA |
6800 | \fBcompgen\fP [\fIoption\fP] [\fIword\fP] |
6801 | Generate possible completion matches for \fIword\fP according to | |
6802 | the \fIoption\fPs, which may be any option accepted by the | |
6803 | .B complete | |
6804 | builtin with the exception of \fB\-p\fP and \fB\-r\fP, and write | |
6805 | the matches to the standard output. | |
6806 | When using the \fB\-F\fP or \fB\-C\fP options, the various shell variables | |
6807 | set by the programmable completion facilities, while available, will not | |
6808 | have useful values. | |
6809 | .sp 1 | |
6810 | The matches will be generated in the same way as if the programmable | |
6811 | completion code had generated them directly from a completion specification | |
6812 | with the same flags. | |
6813 | If \fIword\fP is specified, only those completions matching \fIword\fP | |
6814 | will be displayed. | |
6815 | .sp 1 | |
6816 | The return value is true unless an invalid option is supplied, or no | |
6817 | matches were generated. | |
6818 | .TP | |
3eb2d94a | 6819 | \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 | 6820 | .br |
d3ad40de | 6821 | [\fB\-X\fP \fIfilterpat\fP] [\fB\-P\fP \fIprefix\fP] [\fB\-S\fP \fIsuffix\fP] \fIname\fP [\fIname ...\fP] |
7117c2d2 | 6822 | .PD 0 |
bb70624e | 6823 | .TP |
3eb2d94a | 6824 | \fBcomplete\fP \fB\-pr\fP [\fB\-DE\fP] [\fIname\fP ...] |
bb70624e JA |
6825 | .PD |
6826 | Specify how arguments to each \fIname\fP should be completed. | |
6827 | If the \fB\-p\fP option is supplied, or if no options are supplied, | |
6828 | existing completion specifications are printed in a way that allows | |
6829 | them to be reused as input. | |
6830 | The \fB\-r\fP option removes a completion specification for | |
6831 | each \fIname\fP, or, if no \fIname\fPs are supplied, all | |
6832 | completion specifications. | |
3eb2d94a CR |
6833 | The \fB\-D\fP option indicates that the remaining options and actions should |
6834 | apply to the ``default'' command completion; that is, completion attempted | |
6835 | on a command for which no completion has previously been defined. | |
6a8fd0ed CR |
6836 | The \fB\-E\fP option indicates that the remaining options and actions should |
6837 | apply to ``empty'' command completion; that is, completion attempted on a | |
6838 | blank line. | |
bb70624e JA |
6839 | .sp 1 |
6840 | The process of applying these completion specifications when word completion | |
6841 | is attempted is described above under \fBProgrammable Completion\fP. | |
6842 | .sp 1 | |
6843 | Other options, if specified, have the following meanings. | |
6844 | The arguments to the \fB\-G\fP, \fB\-W\fP, and \fB\-X\fP options | |
6845 | (and, if necessary, the \fB\-P\fP and \fB\-S\fP options) | |
6846 | should be quoted to protect them from expansion before the | |
6847 | .B complete | |
6848 | builtin is invoked. | |
6849 | .RS | |
6850 | .PD 0 | |
6851 | .TP 8 | |
28ef6c31 JA |
6852 | \fB\-o\fP \fIcomp-option\fP |
6853 | The \fIcomp-option\fP controls several aspects of the compspec's behavior | |
6854 | beyond the simple generation of completions. | |
6855 | \fIcomp-option\fP may be one of: | |
6856 | .RS | |
6857 | .TP 8 | |
d3a24ed2 CR |
6858 | .B bashdefault |
6859 | Perform the rest of the default \fBbash\fP completions if the compspec | |
6860 | generates no matches. | |
6861 | .TP 8 | |
28ef6c31 | 6862 | .B default |
7117c2d2 JA |
6863 | Use readline's default filename completion if the compspec generates |
6864 | no matches. | |
28ef6c31 JA |
6865 | .TP 8 |
6866 | .B dirnames | |
6867 | Perform directory name completion if the compspec generates no matches. | |
6868 | .TP 8 | |
6869 | .B filenames | |
6870 | Tell readline that the compspec generates filenames, so it can perform any | |
e77a3058 CR |
6871 | filename\-specific processing (like adding a slash to directory names, |
6872 | quoting special characters, or suppressing trailing spaces). | |
6873 | Intended to be used with shell functions. | |
7117c2d2 JA |
6874 | .TP 8 |
6875 | .B nospace | |
6876 | Tell readline not to append a space (the default) to words completed at | |
6877 | the end of the line. | |
301e2142 CR |
6878 | .TP 8 |
6879 | .B plusdirs | |
6880 | After any matches defined by the compspec are generated, | |
6881 | directory name completion is attempted and any | |
6882 | matches are added to the results of the other actions. | |
28ef6c31 JA |
6883 | .RE |
6884 | .TP 8 | |
bb70624e JA |
6885 | \fB\-A\fP \fIaction\fP |
6886 | The \fIaction\fP may be one of the following to generate a list of possible | |
6887 | completions: | |
6888 | .RS | |
6889 | .TP 8 | |
6890 | .B alias | |
6891 | Alias names. May also be specified as \fB\-a\fP. | |
6892 | .TP 8 | |
6893 | .B arrayvar | |
6894 | Array variable names. | |
6895 | .TP 8 | |
6896 | .B binding | |
6897 | \fBReadline\fP key binding names. | |
6898 | .TP 8 | |
6899 | .B builtin | |
6900 | Names of shell builtin commands. May also be specified as \fB\-b\fP. | |
6901 | .TP 8 | |
6902 | .B command | |
6903 | Command names. May also be specified as \fB\-c\fP. | |
6904 | .TP 8 | |
6905 | .B directory | |
6906 | Directory names. May also be specified as \fB\-d\fP. | |
6907 | .TP 8 | |
6908 | .B disabled | |
6909 | Names of disabled shell builtins. | |
6910 | .TP 8 | |
6911 | .B enabled | |
6912 | Names of enabled shell builtins. | |
6913 | .TP 8 | |
6914 | .B export | |
6915 | Names of exported shell variables. May also be specified as \fB\-e\fP. | |
6916 | .TP 8 | |
6917 | .B file | |
6918 | File names. May also be specified as \fB\-f\fP. | |
6919 | .TP 8 | |
6920 | .B function | |
6921 | Names of shell functions. | |
6922 | .TP 8 | |
f73dda09 JA |
6923 | .B group |
6924 | Group names. May also be specified as \fB\-g\fP. | |
6925 | .TP 8 | |
bb70624e JA |
6926 | .B helptopic |
6927 | Help topics as accepted by the \fBhelp\fP builtin. | |
6928 | .TP 8 | |
6929 | .B hostname | |
6930 | Hostnames, as taken from the file specified by the | |
6931 | .SM | |
6932 | .B HOSTFILE | |
6933 | shell variable. | |
6934 | .TP 8 | |
6935 | .B job | |
6936 | Job names, if job control is active. May also be specified as \fB\-j\fP. | |
6937 | .TP 8 | |
6938 | .B keyword | |
6939 | Shell reserved words. May also be specified as \fB\-k\fP. | |
6940 | .TP 8 | |
6941 | .B running | |
6942 | Names of running jobs, if job control is active. | |
6943 | .TP 8 | |
7117c2d2 JA |
6944 | .B service |
6945 | Service names. May also be specified as \fB\-s\fP. | |
6946 | .TP 8 | |
bb70624e JA |
6947 | .B setopt |
6948 | Valid arguments for the \fB\-o\fP option to the \fBset\fP builtin. | |
6949 | .TP 8 | |
6950 | .B shopt | |
6951 | Shell option names as accepted by the \fBshopt\fP builtin. | |
6952 | .TP 8 | |
6953 | .B signal | |
6954 | Signal names. | |
6955 | .TP 8 | |
6956 | .B stopped | |
6957 | Names of stopped jobs, if job control is active. | |
6958 | .TP 8 | |
6959 | .B user | |
6960 | User names. May also be specified as \fB\-u\fP. | |
6961 | .TP 8 | |
6962 | .B variable | |
6963 | Names of all shell variables. May also be specified as \fB\-v\fP. | |
6964 | .RE | |
6965 | .TP 8 | |
bb70624e JA |
6966 | \fB\-C\fP \fIcommand\fP |
6967 | \fIcommand\fP is executed in a subshell environment, and its output is | |
6968 | used as the possible completions. | |
6969 | .TP 8 | |
6970 | \fB\-F\fP \fIfunction\fP | |
6971 | The shell function \fIfunction\fP is executed in the current shell | |
6972 | environment. | |
6973 | When it finishes, the possible completions are retrieved from the value | |
6974 | of the | |
6975 | .SM | |
6976 | .B COMPREPLY | |
6977 | array variable. | |
6978 | .TP 8 | |
5cdaaf76 CR |
6979 | \fB\-G\fP \fIglobpat\fP |
6980 | The pathname expansion pattern \fIglobpat\fP is expanded to generate | |
6981 | the possible completions. | |
bb70624e JA |
6982 | .TP 8 |
6983 | \fB\-P\fP \fIprefix\fP | |
6984 | \fIprefix\fP is added at the beginning of each possible completion | |
6985 | after all other options have been applied. | |
6986 | .TP 8 | |
6987 | \fB\-S\fP \fIsuffix\fP | |
6988 | \fIsuffix\fP is appended to each possible completion | |
6989 | after all other options have been applied. | |
5cdaaf76 CR |
6990 | .TP 8 |
6991 | \fB\-W\fP \fIwordlist\fP | |
6992 | The \fIwordlist\fP is split using the characters in the | |
6993 | .SM | |
6994 | .B IFS | |
6995 | special variable as delimiters, and each resultant word is expanded. | |
6996 | The possible completions are the members of the resultant list which | |
6997 | match the word being completed. | |
6998 | .TP 8 | |
6999 | \fB\-X\fP \fIfilterpat\fP | |
7000 | \fIfilterpat\fP is a pattern as used for pathname expansion. | |
7001 | It is applied to the list of possible completions generated by the | |
7002 | preceding options and arguments, and each completion matching | |
7003 | \fIfilterpat\fP is removed from the list. | |
7004 | A leading \fB!\fP in \fIfilterpat\fP negates the pattern; in this | |
7005 | case, any completion not matching \fIfilterpat\fP is removed. | |
bb70624e JA |
7006 | .PD |
7007 | .PP | |
7008 | The return value is true unless an invalid option is supplied, an option | |
7009 | other than \fB\-p\fP or \fB\-r\fP is supplied without a \fIname\fP | |
7010 | argument, an attempt is made to remove a completion specification for | |
7011 | a \fIname\fP for which no specification exists, or | |
7012 | an error occurs adding a completion specification. | |
7013 | .RE | |
7014 | .TP | |
3eb2d94a | 7015 | \fBcompopt\fP [\fB\-o\fP \fIoption\fP] [\fB\-DE\fP] [\fB+o\fP \fIoption\fP] [\fIname\fP] |
6fbe7620 CR |
7016 | Modify completion options for each \fIname\fP according to the |
7017 | \fIoption\fPs, or for the | |
5cdaaf76 | 7018 | currently-executing completion if no \fIname\fPs are supplied. |
6fbe7620 CR |
7019 | If no \fIoption\fPs are given, display the completion options for each |
7020 | \fIname\fP or the current completion. | |
7021 | The possible values of \fIoption\fP are those valid for the \fBcomplete\fP | |
7022 | builtin described above. | |
3eb2d94a CR |
7023 | The \fB\-D\fP option indicates that the remaining options should |
7024 | apply to the ``default'' command completion; that is, completion attempted | |
7025 | on a command for which no completion has previously been defined. | |
7026 | The \fB\-E\fP option indicates that the remaining options should | |
7027 | apply to ``empty'' command completion; that is, completion attempted on a | |
7028 | blank line. | |
9c7f20c7 | 7029 | .sp 1 |
6fbe7620 CR |
7030 | The return value is true unless an invalid option is supplied, an attempt |
7031 | is made to modify the options for a \fIname\fP for which no completion | |
7032 | specification exists, or an output error occurs. | |
7033 | .TP | |
726f6388 JA |
7034 | \fBcontinue\fP [\fIn\fP] |
7035 | Resume the next iteration of the enclosing | |
7036 | .BR for , | |
7037 | .BR while , | |
ccc6cda3 | 7038 | .BR until , |
726f6388 | 7039 | or |
ccc6cda3 | 7040 | .B select |
726f6388 JA |
7041 | loop. |
7042 | If | |
7043 | .I n | |
7044 | is specified, resume at the \fIn\fPth enclosing loop. | |
7045 | .I n | |
7046 | must be \(>= 1. If | |
7047 | .I n | |
7048 | is greater than the number of enclosing loops, the last enclosing loop | |
33fe8777 CR |
7049 | (the ``top-level'' loop) is resumed. |
7050 | The return value is 0 unless \fIn\fP is not greater than or equal to 1. | |
726f6388 | 7051 | .TP |
09767ff0 | 7052 | \fBdeclare\fP [\fB\-aAfFilrtux\fP] [\fB\-p\fP] [\fIname\fP[=\fIvalue\fP] ...] |
726f6388 | 7053 | .PD 0 |
726f6388 | 7054 | .TP |
09767ff0 | 7055 | \fBtypeset\fP [\fB\-aAfFilrtux\fP] [\fB\-p\fP] [\fIname\fP[=\fIvalue\fP] ...] |
726f6388 | 7056 | .PD |
ccc6cda3 JA |
7057 | Declare variables and/or give them attributes. |
7058 | If no \fIname\fPs are given then display the values of variables. | |
7059 | The | |
7060 | .B \-p | |
7061 | option will display the attributes and values of each | |
7062 | .IR name . | |
7063 | When | |
7064 | .B \-p | |
6fbe7620 CR |
7065 | is used with \fIname\fP arguments, additional options are ignored. |
7066 | When | |
7067 | .B \-p | |
7068 | is supplied without \fIname\fP arguments, it will display the attributes | |
7069 | and values of all variables having the attributes specified by the | |
7070 | additional options. | |
7071 | If no other options are supplied with \fB\-p\fP, \fBdeclare\fP will display | |
7072 | the attributes and values of all shell variables. The \fB\-f\fP option | |
7073 | will restrict the display to shell functions. | |
ccc6cda3 JA |
7074 | The |
7075 | .B \-F | |
7076 | option inhibits the display of function definitions; only the | |
7077 | function name and attributes are printed. | |
d3a24ed2 CR |
7078 | If the \fBextdebug\fP shell option is enabled using \fBshopt\fP, |
7079 | the source file name and line number where the function is defined | |
7080 | are displayed as well. The | |
ccc6cda3 JA |
7081 | .B \-F |
7082 | option implies | |
7083 | .BR \-f . | |
7084 | The following options can | |
7085 | be used to restrict output to variables with the specified attribute or | |
7086 | to give variables attributes: | |
726f6388 JA |
7087 | .RS |
7088 | .PD 0 | |
7089 | .TP | |
ccc6cda3 | 7090 | .B \-a |
fdf670ea CR |
7091 | Each \fIname\fP is an indexed array variable (see |
7092 | .B Arrays | |
7093 | above). | |
7094 | .TP | |
7095 | .B \-A | |
7096 | Each \fIname\fP is an associative array variable (see | |
ccc6cda3 JA |
7097 | .B Arrays |
7098 | above). | |
7099 | .TP | |
726f6388 | 7100 | .B \-f |
ccc6cda3 JA |
7101 | Use function names only. |
7102 | .TP | |
7103 | .B \-i | |
7104 | The variable is treated as an integer; arithmetic evaluation (see | |
7105 | .SM | |
984a1947 CR |
7106 | .B "ARITHMETIC EVALUATION" |
7107 | above) is performed when the variable is assigned a value. | |
726f6388 | 7108 | .TP |
09767ff0 CR |
7109 | .B \-l |
7110 | When the variable is assigned a value, all upper-case characters are | |
7111 | converted to lower-case. | |
7112 | The upper-case attribute is disabled. | |
7113 | .TP | |
726f6388 JA |
7114 | .B \-r |
7115 | Make \fIname\fPs readonly. These names cannot then be assigned values | |
cce855bc | 7116 | by subsequent assignment statements or unset. |
726f6388 | 7117 | .TP |
7117c2d2 JA |
7118 | .B \-t |
7119 | Give each \fIname\fP the \fItrace\fP attribute. | |
76a8d78d CR |
7120 | Traced functions inherit the \fBDEBUG\fP and \fBRETURN\fP traps from |
7121 | the calling shell. | |
7117c2d2 JA |
7122 | The trace attribute has no special meaning for variables. |
7123 | .TP | |
09767ff0 CR |
7124 | .B \-u |
7125 | When the variable is assigned a value, all lower-case characters are | |
7126 | converted to upper-case. | |
7127 | The lower-case attribute is disabled. | |
7128 | .TP | |
726f6388 JA |
7129 | .B \-x |
7130 | Mark \fIname\fPs for export to subsequent commands via the environment. | |
726f6388 JA |
7131 | .PD |
7132 | .PP | |
7133 | Using `+' instead of `\-' | |
d3ad40de CR |
7134 | turns off the attribute instead, |
7135 | with the exceptions that \fB+a\fP | |
984a1947 | 7136 | may not be used to destroy an array variable and \fB+r\fP will not |
d3ad40de CR |
7137 | remove the readonly attribute. |
7138 | When used in a function, | |
ccc6cda3 JA |
7139 | makes each |
7140 | \fIname\fP local, as with the | |
726f6388 | 7141 | .B local |
d3a24ed2 CR |
7142 | command. |
7143 | If a variable name is followed by =\fIvalue\fP, the value of | |
7144 | the variable is set to \fIvalue\fP. | |
7145 | The return value is 0 unless an invalid option is encountered, | |
bb70624e JA |
7146 | an attempt is made to define a function using |
7147 | .if n ``\-f foo=bar'', | |
7148 | .if t \f(CW\-f foo=bar\fP, | |
ccc6cda3 JA |
7149 | an attempt is made to assign a value to a readonly variable, |
7150 | an attempt is made to assign a value to an array variable without | |
7151 | using the compound assignment syntax (see | |
7152 | .B Arrays | |
cce855bc | 7153 | above), one of the \fInames\fP is not a valid shell variable name, |
726f6388 | 7154 | an attempt is made to turn off readonly status for a readonly variable, |
ccc6cda3 | 7155 | an attempt is made to turn off array status for an array variable, |
bb70624e | 7156 | or an attempt is made to display a non-existent function with \fB\-f\fP. |
726f6388 JA |
7157 | .RE |
7158 | .TP | |
5cdaaf76 | 7159 | .B dirs [+\fIn\fP] [\-\fIn\fP] [\fB\-clpv\fP] |
ccc6cda3 JA |
7160 | Without options, displays the list of currently remembered directories. |
7161 | The default display is on a single line with directory names separated | |
7162 | by spaces. | |
7163 | Directories are added to the list with the | |
726f6388 JA |
7164 | .B pushd |
7165 | command; the | |
7166 | .B popd | |
ccc6cda3 | 7167 | command removes entries from the list. |
726f6388 JA |
7168 | .RS |
7169 | .PD 0 | |
7170 | .TP | |
ccc6cda3 JA |
7171 | \fB+\fP\fIn\fP |
7172 | Displays the \fIn\fPth entry counting from the left of the list | |
726f6388 JA |
7173 | shown by |
7174 | .B dirs | |
7175 | when invoked without options, starting with zero. | |
7176 | .TP | |
ccc6cda3 JA |
7177 | \fB\-\fP\fIn\fP |
7178 | Displays the \fIn\fPth entry counting from the right of the list | |
726f6388 JA |
7179 | shown by |
7180 | .B dirs | |
7181 | when invoked without options, starting with zero. | |
7182 | .TP | |
ccc6cda3 JA |
7183 | .B \-c |
7184 | Clears the directory stack by deleting all of the entries. | |
7185 | .TP | |
726f6388 | 7186 | .B \-l |
ccc6cda3 | 7187 | Produces a longer listing; the default listing format uses a |
726f6388 | 7188 | tilde to denote the home directory. |
ccc6cda3 JA |
7189 | .TP |
7190 | .B \-p | |
7191 | Print the directory stack with one entry per line. | |
7192 | .TP | |
7193 | .B \-v | |
7194 | Print the directory stack with one entry per line, | |
7195 | prefixing each entry with its index in the stack. | |
726f6388 JA |
7196 | .PD |
7197 | .PP | |
7198 | The return value is 0 unless an | |
cce855bc | 7199 | invalid option is supplied or \fIn\fP indexes beyond the end |
726f6388 JA |
7200 | of the directory stack. |
7201 | .RE | |
7202 | .TP | |
cce855bc | 7203 | \fBdisown\fP [\fB\-ar\fP] [\fB\-h\fP] [\fIjobspec\fP ...] |
ccc6cda3 JA |
7204 | Without options, each |
7205 | .I jobspec | |
7206 | is removed from the table of active jobs. | |
d3ad40de CR |
7207 | If |
7208 | .I jobspec | |
984a1947 | 7209 | is not present, and neither \fB\-a\fP nor \fB\-r\fP is supplied, |
d3ad40de | 7210 | the shell's notion of the \fIcurrent job\fP is used. |
cce855bc JA |
7211 | If the \fB\-h\fP option is given, each |
7212 | .I jobspec | |
7213 | is not removed from the table, but is marked so that | |
ccc6cda3 JA |
7214 | .SM |
7215 | .B SIGHUP | |
7216 | is not sent to the job if the shell receives a | |
7217 | .SM | |
7218 | .BR SIGHUP . | |
7219 | If no | |
7220 | .I jobspec | |
cce855bc JA |
7221 | is present, and neither the |
7222 | .B \-a | |
7223 | nor the | |
7224 | .B \-r | |
7225 | option is supplied, the \fIcurrent job\fP is used. | |
7226 | If no | |
7227 | .I jobspec | |
7228 | is supplied, the | |
7229 | .B \-a | |
7230 | option means to remove or mark all jobs; the | |
7231 | .B \-r | |
7232 | option without a | |
7233 | .I jobspec | |
7234 | argument restricts operation to running jobs. | |
7235 | The return value is 0 unless a | |
ccc6cda3 JA |
7236 | .I jobspec |
7237 | does not specify a valid job. | |
7238 | .TP | |
726f6388 | 7239 | \fBecho\fP [\fB\-neE\fP] [\fIarg\fP ...] |
ccc6cda3 JA |
7240 | Output the \fIarg\fPs, separated by spaces, followed by a newline. |
7241 | The return status is always 0. | |
7242 | If \fB\-n\fP is specified, the trailing newline is | |
726f6388 JA |
7243 | suppressed. If the \fB\-e\fP option is given, interpretation of |
7244 | the following backslash-escaped characters is enabled. The | |
7245 | .B \-E | |
7246 | option disables the interpretation of these escape characters, | |
7247 | even on systems where they are interpreted by default. | |
28ef6c31 | 7248 | The \fBxpg_echo\fP shell option may be used to |
bb70624e JA |
7249 | dynamically determine whether or not \fBecho\fP expands these |
7250 | escape characters by default. | |
ccc6cda3 | 7251 | .B echo |
3ffb039a | 7252 | does not interpret \fB\-\-\fP to mean the end of options. |
ccc6cda3 JA |
7253 | .B echo |
7254 | interprets the following escape sequences: | |
726f6388 JA |
7255 | .RS |
7256 | .PD 0 | |
7257 | .TP | |
7258 | .B \ea | |
7259 | alert (bell) | |
7260 | .TP | |
7261 | .B \eb | |
7262 | backspace | |
7263 | .TP | |
7264 | .B \ec | |
2e4498b3 | 7265 | suppress further output |
726f6388 | 7266 | .TP |
ccc6cda3 JA |
7267 | .B \ee |
7268 | an escape character | |
7269 | .TP | |
726f6388 JA |
7270 | .B \ef |
7271 | form feed | |
7272 | .TP | |
7273 | .B \en | |
7274 | new line | |
7275 | .TP | |
7276 | .B \er | |
7277 | carriage return | |
7278 | .TP | |
7279 | .B \et | |
7280 | horizontal tab | |
7281 | .TP | |
7282 | .B \ev | |
7283 | vertical tab | |
7284 | .TP | |
7285 | .B \e\e | |
7286 | backslash | |
7287 | .TP | |
7117c2d2 JA |
7288 | .B \e0\fInnn\fP |
7289 | the eight-bit character whose value is the octal value \fInnn\fP | |
7290 | (zero to three octal digits) | |
7291 | .TP | |
f73dda09 JA |
7292 | .B \ex\fIHH\fP |
7293 | the eight-bit character whose value is the hexadecimal value \fIHH\fP | |
7294 | (one or two hex digits) | |
726f6388 JA |
7295 | .PD |
7296 | .RE | |
7297 | .TP | |
d3ad40de | 7298 | \fBenable\fP [\fB\-a\fP] [\fB\-dnps\fP] [\fB\-f\fP \fIfilename\fP] [\fIname\fP ...] |
cce855bc JA |
7299 | Enable and disable builtin shell commands. |
7300 | Disabling a builtin allows a disk command which has the same name | |
bb70624e | 7301 | as a shell builtin to be executed without specifying a full pathname, |
cce855bc | 7302 | even though the shell normally searches for builtins before disk commands. |
726f6388 JA |
7303 | If \fB\-n\fP is used, each \fIname\fP |
7304 | is disabled; otherwise, | |
7305 | \fInames\fP are enabled. For example, to use the | |
7306 | .B test | |
7307 | binary found via the | |
7308 | .SM | |
7309 | .B PATH | |
ccc6cda3 | 7310 | instead of the shell builtin version, run |
28ef6c31 JA |
7311 | .if t \f(CWenable -n test\fP. |
7312 | .if n ``enable -n test''. | |
ccc6cda3 JA |
7313 | The |
7314 | .B \-f | |
7315 | option means to load the new builtin command | |
7316 | .I name | |
7317 | from shared object | |
7318 | .IR filename , | |
7319 | on systems that support dynamic loading. The | |
7320 | .B \-d | |
7321 | option will delete a builtin previously loaded with | |
7322 | .BR \-f . | |
7323 | If no \fIname\fP arguments are given, or if the | |
7324 | .B \-p | |
7325 | option is supplied, a list of shell builtins is printed. | |
7326 | With no other option arguments, the list consists of all enabled | |
7327 | shell builtins. | |
7328 | If \fB\-n\fP is supplied, only disabled builtins are printed. | |
7329 | If \fB\-a\fP is supplied, the list printed includes all builtins, with an | |
726f6388 | 7330 | indication of whether or not each is enabled. |
ccc6cda3 JA |
7331 | If \fB\-s\fP is supplied, the output is restricted to the POSIX |
7332 | \fIspecial\fP builtins. | |
726f6388 JA |
7333 | The return value is 0 unless a |
7334 | .I name | |
bb70624e | 7335 | is not a shell builtin or there is an error loading a new builtin |
ccc6cda3 | 7336 | from a shared object. |
726f6388 JA |
7337 | .TP |
7338 | \fBeval\fP [\fIarg\fP ...] | |
7339 | The \fIarg\fPs are read and concatenated together into a single | |
7340 | command. This command is then read and executed by the shell, and | |
ccc6cda3 JA |
7341 | its exit status is returned as the value of |
7342 | .BR eval . | |
7343 | If there are no | |
726f6388 JA |
7344 | .IR args , |
7345 | or only null arguments, | |
7346 | .B eval | |
ccc6cda3 | 7347 | returns 0. |
726f6388 | 7348 | .TP |
cce855bc | 7349 | \fBexec\fP [\fB\-cl\fP] [\fB\-a\fP \fIname\fP] [\fIcommand\fP [\fIarguments\fP]] |
726f6388 JA |
7350 | If |
7351 | .I command | |
7352 | is specified, it replaces the shell. | |
7353 | No new process is created. The | |
7354 | .I arguments | |
7355 | become the arguments to \fIcommand\fP. | |
ccc6cda3 JA |
7356 | If the |
7357 | .B \-l | |
7358 | option is supplied, | |
d3ad40de | 7359 | the shell places a dash at the beginning of the zeroth argument passed to |
726f6388 | 7360 | .IR command . |
ccc6cda3 JA |
7361 | This is what |
7362 | .IR login (1) | |
7363 | does. The | |
7364 | .B \-c | |
7365 | option causes | |
7366 | .I command | |
7367 | to be executed with an empty environment. If | |
7368 | .B \-a | |
7369 | is supplied, the shell passes | |
7370 | .I name | |
7371 | as the zeroth argument to the executed command. If | |
7372 | .I command | |
726f6388 | 7373 | cannot be executed for some reason, a non-interactive shell exits, |
ccc6cda3 JA |
7374 | unless the shell option |
7375 | .B execfail | |
7376 | is enabled, in which case it returns failure. | |
7377 | An interactive shell returns failure if the file cannot be executed. | |
726f6388 JA |
7378 | If |
7379 | .I command | |
7380 | is not specified, any redirections take effect in the current shell, | |
cce855bc JA |
7381 | and the return status is 0. If there is a redirection error, the |
7382 | return status is 1. | |
726f6388 JA |
7383 | .TP |
7384 | \fBexit\fP [\fIn\fP] | |
7385 | Cause the shell to exit | |
7386 | with a status of \fIn\fP. If | |
7387 | .I n | |
7388 | is omitted, the exit status | |
7389 | is that of the last command executed. | |
7390 | A trap on | |
7391 | .SM | |
7392 | .B EXIT | |
7393 | is executed before the shell terminates. | |
7394 | .TP | |
ccc6cda3 | 7395 | \fBexport\fP [\fB\-fn\fP\^] [\fIname\fP[=\fIword\fP]] ... |
7117c2d2 | 7396 | .PD 0 |
726f6388 JA |
7397 | .TP |
7398 | .B export \-p | |
7399 | .PD | |
7400 | The supplied | |
7401 | .I names | |
7402 | are marked for automatic export to the environment of | |
7403 | subsequently executed commands. If the | |
7404 | .B \-f | |
7405 | option is given, | |
7406 | the | |
7407 | .I names | |
7408 | refer to functions. | |
7409 | If no | |
7410 | .I names | |
7411 | are given, or if the | |
7412 | .B \-p | |
7413 | option is supplied, a list | |
7414 | of all names that are exported in this shell is printed. | |
7415 | The | |
7416 | .B \-n | |
5e13499c CR |
7417 | option causes the export property to be removed from each |
7418 | \fIname\fP. | |
d3a24ed2 CR |
7419 | If a variable name is followed by =\fIword\fP, the value of |
7420 | the variable is set to \fIword\fP. | |
726f6388 | 7421 | .B export |
cce855bc | 7422 | returns an exit status of 0 unless an invalid option is |
726f6388 | 7423 | encountered, |
cce855bc | 7424 | one of the \fInames\fP is not a valid shell variable name, or |
726f6388 JA |
7425 | .B \-f |
7426 | is supplied with a | |
7427 | .I name | |
7428 | that is not a function. | |
7429 | .TP | |
d3ad40de | 7430 | \fBfc\fP [\fB\-e\fP \fIename\fP] [\fB\-lnr\fP] [\fIfirst\fP] [\fIlast\fP] |
7117c2d2 | 7431 | .PD 0 |
726f6388 JA |
7432 | .TP |
7433 | \fBfc\fP \fB\-s\fP [\fIpat\fP=\fIrep\fP] [\fIcmd\fP] | |
7434 | .PD | |
7435 | Fix Command. In the first form, a range of commands from | |
7436 | .I first | |
7437 | to | |
7438 | .I last | |
7439 | is selected from the history list. | |
7440 | .I First | |
7441 | and | |
7442 | .I last | |
7443 | may be specified as a string (to locate the last command beginning | |
7444 | with that string) or as a number (an index into the history list, | |
7445 | where a negative number is used as an offset from the current | |
7446 | command number). If | |
7447 | .I last | |
7448 | is not specified it is set to | |
7449 | the current command for listing (so that | |
bb70624e JA |
7450 | .if n ``fc \-l \-10'' |
7451 | .if t \f(CWfc \-l \-10\fP | |
726f6388 JA |
7452 | prints the last 10 commands) and to |
7453 | .I first | |
7454 | otherwise. | |
7455 | If | |
7456 | .I first | |
7457 | is not specified it is set to the previous | |
7458 | command for editing and \-16 for listing. | |
7459 | .sp 1 | |
7460 | The | |
7461 | .B \-n | |
cce855bc | 7462 | option suppresses |
726f6388 JA |
7463 | the command numbers when listing. The |
7464 | .B \-r | |
cce855bc | 7465 | option reverses the order of |
726f6388 JA |
7466 | the commands. If the |
7467 | .B \-l | |
cce855bc | 7468 | option is given, |
726f6388 JA |
7469 | the commands are listed on |
7470 | standard output. Otherwise, the editor given by | |
7471 | .I ename | |
7472 | is invoked | |
7473 | on a file containing those commands. If | |
7474 | .I ename | |
7475 | is not given, the | |
7476 | value of the | |
7477 | .SM | |
7478 | .B FCEDIT | |
7479 | variable is used, and | |
7480 | the value of | |
7481 | .SM | |
7482 | .B EDITOR | |
7483 | if | |
7484 | .SM | |
7485 | .B FCEDIT | |
7486 | is not set. If neither variable is set, | |
7487 | .FN vi | |
7488 | is used. When editing is complete, the edited commands are | |
7489 | echoed and executed. | |
7490 | .sp 1 | |
7491 | In the second form, \fIcommand\fP is re-executed after each instance | |
7492 | of \fIpat\fP is replaced by \fIrep\fP. | |
ccc6cda3 | 7493 | A useful alias to use with this is |
d3a24ed2 | 7494 | .if n ``r="fc -s"'', |
ccc6cda3 JA |
7495 | .if t \f(CWr='fc \-s'\fP, |
7496 | so that typing | |
7497 | .if n ``r cc'' | |
7498 | .if t \f(CWr cc\fP | |
7499 | runs the last command beginning with | |
7500 | .if n ``cc'' | |
7501 | .if t \f(CWcc\fP | |
7502 | and typing | |
7503 | .if n ``r'' | |
7504 | .if t \f(CWr\fP | |
726f6388 JA |
7505 | re-executes the last command. |
7506 | .sp 1 | |
cce855bc | 7507 | If the first form is used, the return value is 0 unless an invalid |
726f6388 JA |
7508 | option is encountered or |
7509 | .I first | |
7510 | or | |
7511 | .I last | |
7512 | specify history lines out of range. | |
7513 | If the | |
7514 | .B \-e | |
7515 | option is supplied, the return value is the value of the last | |
7516 | command executed or failure if an error occurs with the temporary | |
7517 | file of commands. If the second form is used, the return status | |
7518 | is that of the command re-executed, unless | |
7519 | .I cmd | |
7520 | does not specify a valid history line, in which case | |
7521 | .B fc | |
7522 | returns failure. | |
7523 | .TP | |
7524 | \fBfg\fP [\fIjobspec\fP] | |
cce855bc | 7525 | Resume |
726f6388 | 7526 | .I jobspec |
cce855bc JA |
7527 | in the foreground, and make it the current job. |
7528 | If | |
726f6388 JA |
7529 | .I jobspec |
7530 | is not present, the shell's notion of the \fIcurrent job\fP is used. | |
7531 | The return value is that of the command placed into the foreground, | |
7532 | or failure if run when job control is disabled or, when run with | |
7533 | job control enabled, if | |
7534 | .I jobspec | |
7535 | does not specify a valid job or | |
7536 | .I jobspec | |
7537 | specifies a job that was started without job control. | |
7538 | .TP | |
7539 | \fBgetopts\fP \fIoptstring\fP \fIname\fP [\fIargs\fP] | |
7540 | .B getopts | |
7541 | is used by shell procedures to parse positional parameters. | |
7542 | .I optstring | |
bb70624e | 7543 | contains the option characters to be recognized; if a character |
726f6388 JA |
7544 | is followed by a colon, the option is expected to have an |
7545 | argument, which should be separated from it by white space. | |
bb70624e JA |
7546 | The colon and question mark characters may not be used as |
7547 | option characters. | |
726f6388 JA |
7548 | Each time it is invoked, |
7549 | .B getopts | |
7550 | places the next option in the shell variable | |
7551 | .IR name , | |
7552 | initializing | |
7553 | .I name | |
7554 | if it does not exist, | |
7555 | and the index of the next argument to be processed into the | |
7556 | variable | |
7557 | .SM | |
7558 | .BR OPTIND . | |
7559 | .SM | |
7560 | .B OPTIND | |
7561 | is initialized to 1 each time the shell or a shell script | |
7562 | is invoked. When an option requires an argument, | |
7563 | .B getopts | |
7564 | places that argument into the variable | |
7565 | .SM | |
7566 | .BR OPTARG . | |
7567 | The shell does not reset | |
7568 | .SM | |
7569 | .B OPTIND | |
7570 | automatically; it must be manually reset between multiple | |
7571 | calls to | |
7572 | .B getopts | |
7573 | within the same shell invocation if a new set of parameters | |
7574 | is to be used. | |
7575 | .sp 1 | |
cce855bc JA |
7576 | When the end of options is encountered, \fBgetopts\fP exits with a |
7577 | return value greater than zero. | |
984a1947 CR |
7578 | .SM |
7579 | .B OPTIND | |
7580 | is set to the index of the first non-option argument, | |
cce855bc JA |
7581 | and \fBname\fP is set to ?. |
7582 | .sp 1 | |
7583 | .B getopts | |
7584 | normally parses the positional parameters, but if more arguments are | |
7585 | given in | |
7586 | .IR args , | |
7587 | .B getopts | |
7588 | parses those instead. | |
7589 | .sp 1 | |
726f6388 JA |
7590 | .B getopts |
7591 | can report errors in two ways. If the first character of | |
7592 | .I optstring | |
7593 | is a colon, | |
7594 | .I silent | |
7595 | error reporting is used. In normal operation diagnostic messages | |
cce855bc | 7596 | are printed when invalid options or missing option arguments are |
726f6388 JA |
7597 | encountered. |
7598 | If the variable | |
7599 | .SM | |
7600 | .B OPTERR | |
cce855bc | 7601 | is set to 0, no error messages will be displayed, even if the first |
726f6388 JA |
7602 | character of |
7603 | .I optstring | |
7604 | is not a colon. | |
7605 | .sp 1 | |
cce855bc | 7606 | If an invalid option is seen, |
726f6388 JA |
7607 | .B getopts |
7608 | places ? into | |
7609 | .I name | |
7610 | and, if not silent, | |
7611 | prints an error message and unsets | |
7612 | .SM | |
7613 | .BR OPTARG . | |
7614 | If | |
7615 | .B getopts | |
7616 | is silent, | |
7617 | the option character found is placed in | |
7618 | .SM | |
7619 | .B OPTARG | |
7620 | and no diagnostic message is printed. | |
7621 | .sp 1 | |
7622 | If a required argument is not found, and | |
7623 | .B getopts | |
7624 | is not silent, | |
7625 | a question mark (\^\fB?\fP\^) is placed in | |
7626 | .IR name , | |
f73dda09 | 7627 | .SM |
726f6388 JA |
7628 | .B OPTARG |
7629 | is unset, and a diagnostic message is printed. | |
7630 | If | |
7631 | .B getopts | |
7632 | is silent, then a colon (\^\fB:\fP\^) is placed in | |
7633 | .I name | |
7634 | and | |
7635 | .SM | |
7636 | .B OPTARG | |
7637 | is set to the option character found. | |
7638 | .sp 1 | |
7639 | .B getopts | |
726f6388 JA |
7640 | returns true if an option, specified or unspecified, is found. |
7641 | It returns false if the end of options is encountered or an | |
7642 | error occurs. | |
7643 | .TP | |
7117c2d2 | 7644 | \fBhash\fP [\fB\-lr\fP] [\fB\-p\fP \fIfilename\fP] [\fB\-dt\fP] [\fIname\fP] |
726f6388 JA |
7645 | For each |
7646 | .IR name , | |
ccc6cda3 JA |
7647 | the full file name of the command is determined by searching |
7648 | the directories in | |
7649 | .B $PATH | |
7650 | and remembered. | |
7651 | If the | |
7652 | .B \-p | |
7653 | option is supplied, no path search is performed, and | |
7654 | .I filename | |
7655 | is used as the full file name of the command. | |
7656 | The | |
726f6388 JA |
7657 | .B \-r |
7658 | option causes the shell to forget all | |
f73dda09 | 7659 | remembered locations. |
7117c2d2 JA |
7660 | The |
7661 | .B \-d | |
7662 | option causes the shell to forget the remembered location of each \fIname\fP. | |
f73dda09 JA |
7663 | If the |
7664 | .B \-t | |
7665 | option is supplied, the full pathname to which each \fIname\fP corresponds | |
7666 | is printed. If multiple \fIname\fP arguments are supplied with \fB\-t\fP, | |
7667 | the \fIname\fP is printed before the hashed full pathname. | |
7117c2d2 JA |
7668 | The |
7669 | .B \-l | |
7670 | option causes output to be displayed in a format that may be reused as input. | |
7671 | If no arguments are given, or if only \fB\-l\fP is supplied, | |
7672 | information about remembered commands is printed. | |
ccc6cda3 | 7673 | The return status is true unless a |
726f6388 | 7674 | .I name |
cce855bc | 7675 | is not found or an invalid option is supplied. |
726f6388 | 7676 | .TP |
6a8fd0ed | 7677 | \fBhelp\fP [\fB\-dms\fP] [\fIpattern\fP] |
726f6388 JA |
7678 | Display helpful information about builtin commands. If |
7679 | .I pattern | |
7680 | is specified, | |
7681 | .B help | |
7682 | gives detailed help on all commands matching | |
7683 | .IR pattern ; | |
ccc6cda3 | 7684 | otherwise help for all the builtins and shell control structures |
bb70624e | 7685 | is printed. |
6a8fd0ed CR |
7686 | .RS |
7687 | .PD 0 | |
7688 | .TP | |
7689 | .B \-d | |
7690 | Display a short description of each \fIpattern\fP | |
7691 | .TP | |
6932f7f5 | 7692 | .B \-m |
6a8fd0ed CR |
7693 | Display the description of each \fIpattern\fP in a manpage-like format |
7694 | .TP | |
7695 | .B \-s | |
7696 | Display only a short usage synopsis for each \fIpattern\fP | |
7697 | .PD | |
7698 | .RE | |
bb70624e | 7699 | The return status is 0 unless no command matches |
726f6388 JA |
7700 | .IR pattern . |
7701 | .TP | |
bb70624e | 7702 | \fBhistory [\fIn\fP] |
7117c2d2 | 7703 | .PD 0 |
bb70624e JA |
7704 | .TP |
7705 | \fBhistory\fP \fB\-c\fP | |
7706 | .TP | |
7707 | \fBhistory \-d\fP \fIoffset\fP | |
ccc6cda3 JA |
7708 | .TP |
7709 | \fBhistory\fP \fB\-anrw\fP [\fIfilename\fP] | |
726f6388 | 7710 | .TP |
ccc6cda3 JA |
7711 | \fBhistory\fP \fB\-p\fP \fIarg\fP [\fIarg ...\fP] |
7712 | .TP | |
7713 | \fBhistory\fP \fB\-s\fP \fIarg\fP [\fIarg ...\fP] | |
726f6388 JA |
7714 | .PD |
7715 | With no options, display the command | |
7716 | history list with line numbers. Lines listed | |
7717 | with a | |
7718 | .B * | |
7719 | have been modified. An argument of | |
7720 | .I n | |
7721 | lists only the last | |
7722 | .I n | |
d3a24ed2 | 7723 | lines. |
984a1947 CR |
7724 | If the shell variable |
7725 | .SM | |
7726 | .B HISTTIMEFORMAT | |
7727 | is set and not null, | |
d3a24ed2 CR |
7728 | it is used as a format string for \fIstrftime\fP(3) to display |
7729 | the time stamp associated with each displayed history entry. | |
7730 | No intervening blank is printed between the formatted time stamp | |
7731 | and the history line. | |
7732 | If \fIfilename\fP is supplied, it is used as the | |
726f6388 JA |
7733 | name of the history file; if not, the value of |
7734 | .SM | |
7735 | .B HISTFILE | |
7736 | is used. Options, if supplied, have the following meanings: | |
7737 | .RS | |
7738 | .PD 0 | |
7739 | .TP | |
bb70624e JA |
7740 | .B \-c |
7741 | Clear the history list by deleting all the entries. | |
7742 | .TP | |
7743 | \fB\-d\fP \fIoffset\fP | |
7744 | Delete the history entry at position \fIoffset\fP. | |
7745 | .TP | |
726f6388 JA |
7746 | .B \-a |
7747 | Append the ``new'' history lines (history lines entered since the | |
ccc6cda3 | 7748 | beginning of the current \fBbash\fP session) to the history file. |
726f6388 JA |
7749 | .TP |
7750 | .B \-n | |
7751 | Read the history lines not already read from the history | |
7752 | file into the current history list. These are lines | |
7753 | appended to the history file since the beginning of the | |
7754 | current \fBbash\fP session. | |
7755 | .TP | |
7756 | .B \-r | |
7757 | Read the contents of the history file | |
ccc6cda3 | 7758 | and use them as the current history. |
726f6388 JA |
7759 | .TP |
7760 | .B \-w | |
7761 | Write the current history to the history file, overwriting the | |
7762 | history file's contents. | |
ccc6cda3 | 7763 | .TP |
ccc6cda3 JA |
7764 | .B \-p |
7765 | Perform history substitution on the following \fIargs\fP and display | |
7766 | the result on the standard output. | |
7767 | Does not store the results in the history list. | |
7768 | Each \fIarg\fP must be quoted to disable normal history expansion. | |
7769 | .TP | |
7770 | .B \-s | |
7771 | Store the | |
7772 | .I args | |
7773 | in the history list as a single entry. The last command in the | |
7774 | history list is removed before the | |
7775 | .I args | |
7776 | are added. | |
726f6388 JA |
7777 | .PD |
7778 | .PP | |
984a1947 CR |
7779 | If the |
7780 | .SM | |
7781 | .B HISTTIMEFORMAT | |
7782 | variable is set, the time stamp information | |
d3ad40de CR |
7783 | associated with each history entry is written to the history file, |
7784 | marked with the history comment character. | |
7785 | When the history file is read, lines beginning with the history | |
7786 | comment character followed immediately by a digit are interpreted | |
7787 | as timestamps for the previous history line. | |
bb70624e JA |
7788 | The return value is 0 unless an invalid option is encountered, an |
7789 | error occurs while reading or writing the history file, an invalid | |
7790 | \fIoffset\fP is supplied as an argument to \fB\-d\fP, or the | |
7791 | history expansion supplied as an argument to \fB\-p\fP fails. | |
726f6388 JA |
7792 | .RE |
7793 | .TP | |
ccc6cda3 | 7794 | \fBjobs\fP [\fB\-lnprs\fP] [ \fIjobspec\fP ... ] |
7117c2d2 | 7795 | .PD 0 |
726f6388 JA |
7796 | .TP |
7797 | \fBjobs\fP \fB\-x\fP \fIcommand\fP [ \fIargs\fP ... ] | |
7798 | .PD | |
ccc6cda3 JA |
7799 | The first form lists the active jobs. The options have the following |
7800 | meanings: | |
7801 | .RS | |
7802 | .PD 0 | |
7803 | .TP | |
726f6388 | 7804 | .B \-l |
ccc6cda3 JA |
7805 | List process IDs |
7806 | in addition to the normal information. | |
7807 | .TP | |
726f6388 | 7808 | .B \-n |
ccc6cda3 JA |
7809 | Display information only about jobs that have changed status since |
7810 | the user was last notified of their status. | |
7811 | .TP | |
5cdaaf76 CR |
7812 | .B \-p |
7813 | List only the process ID of the job's process group | |
7814 | leader. | |
7815 | .TP | |
ccc6cda3 JA |
7816 | .B \-r |
7817 | Restrict output to running jobs. | |
7818 | .TP | |
7819 | .B \-s | |
7820 | Restrict output to stopped jobs. | |
7821 | .PD | |
7822 | .PP | |
7823 | If | |
726f6388 JA |
7824 | .I jobspec |
7825 | is given, output is restricted to information about that job. | |
cce855bc JA |
7826 | The return status is 0 unless an invalid option is encountered |
7827 | or an invalid | |
726f6388 JA |
7828 | .I jobspec |
7829 | is supplied. | |
ccc6cda3 | 7830 | .PP |
726f6388 JA |
7831 | If the |
7832 | .B \-x | |
7833 | option is supplied, | |
7834 | .B jobs | |
7835 | replaces any | |
7836 | .I jobspec | |
7837 | found in | |
7838 | .I command | |
7839 | or | |
7840 | .I args | |
7841 | with the corresponding process group ID, and executes | |
7842 | .I command | |
7843 | passing it | |
7844 | .IR args , | |
7845 | returning its exit status. | |
ccc6cda3 | 7846 | .RE |
726f6388 | 7847 | .TP |
ccc6cda3 | 7848 | \fBkill\fP [\fB\-s\fP \fIsigspec\fP | \fB\-n\fP \fIsignum\fP | \fB\-\fP\fIsigspec\fP] [\fIpid\fP | \fIjobspec\fP] ... |
7117c2d2 | 7849 | .PD 0 |
726f6388 | 7850 | .TP |
cce855bc | 7851 | \fBkill\fP \fB\-l\fP [\fIsigspec\fP | \fIexit_status\fP] |
726f6388 JA |
7852 | .PD |
7853 | Send the signal named by | |
7854 | .I sigspec | |
ccc6cda3 JA |
7855 | or |
7856 | .I signum | |
726f6388 JA |
7857 | to the processes named by |
7858 | .I pid | |
7859 | or | |
7860 | .IR jobspec . | |
7861 | .I sigspec | |
61deeb13 | 7862 | is either a case-insensitive signal name such as |
726f6388 JA |
7863 | .SM |
7864 | .B SIGKILL | |
61deeb13 | 7865 | (with or without the |
726f6388 JA |
7866 | .SM |
7867 | .B SIG | |
61deeb13 CR |
7868 | prefix) or a signal number; |
7869 | .I signum | |
7870 | is a signal number. | |
726f6388 JA |
7871 | If |
7872 | .I sigspec | |
7873 | is not present, then | |
7874 | .SM | |
7875 | .B SIGTERM | |
cce855bc JA |
7876 | is assumed. |
7877 | An argument of | |
726f6388 | 7878 | .B \-l |
cce855bc JA |
7879 | lists the signal names. |
7880 | If any arguments are supplied when | |
726f6388 | 7881 | .B \-l |
cce855bc JA |
7882 | is given, the names of the signals corresponding to the arguments are |
7883 | listed, and the return status is 0. | |
7884 | The \fIexit_status\fP argument to | |
ccc6cda3 | 7885 | .B \-l |
cce855bc JA |
7886 | is a number specifying either a signal number or the exit status of |
7887 | a process terminated by a signal. | |
726f6388 JA |
7888 | .B kill |
7889 | returns true if at least one signal was successfully sent, or false | |
cce855bc | 7890 | if an error occurs or an invalid option is encountered. |
726f6388 JA |
7891 | .TP |
7892 | \fBlet\fP \fIarg\fP [\fIarg\fP ...] | |
7893 | Each | |
7894 | .I arg | |
7895 | is an arithmetic expression to be evaluated (see | |
7896 | .SM | |
984a1947 CR |
7897 | .B "ARITHMETIC EVALUATION" |
7898 | above). | |
726f6388 JA |
7899 | If the last |
7900 | .I arg | |
7901 | evaluates to 0, | |
7902 | .B let | |
7903 | returns 1; 0 is returned otherwise. | |
7904 | .TP | |
bb70624e | 7905 | \fBlocal\fP [\fIoption\fP] [\fIname\fP[=\fIvalue\fP] ...] |
cce855bc JA |
7906 | For each argument, a local variable named |
7907 | .I name | |
7908 | is created, and assigned | |
726f6388 | 7909 | .IR value . |
bb70624e | 7910 | The \fIoption\fP can be any of the options accepted by \fBdeclare\fP. |
726f6388 JA |
7911 | When |
7912 | .B local | |
7913 | is used within a function, it causes the variable | |
7914 | .I name | |
7915 | to have a visible scope restricted to that function and its children. | |
7916 | With no operands, | |
7917 | .B local | |
7918 | writes a list of local variables to the standard output. It is | |
7919 | an error to use | |
7920 | .B local | |
7921 | when not within a function. The return status is 0 unless | |
7922 | .B local | |
bb70624e | 7923 | is used outside a function, an invalid |
726f6388 | 7924 | .I name |
bb70624e JA |
7925 | is supplied, or |
7926 | \fIname\fP is a readonly variable. | |
726f6388 JA |
7927 | .TP |
7928 | .B logout | |
7929 | Exit a login shell. | |
7930 | .TP | |
09767ff0 | 7931 | \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 |
7932 | .PD 0 |
7933 | .TP | |
7934 | \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] | |
7935 | .PD | |
e1e48bba | 7936 | Read lines from the standard input into the indexed array variable |
6a8fd0ed CR |
7937 | .IR array , |
7938 | or from file descriptor | |
7939 | .IR fd | |
7940 | if the | |
7941 | .B \-u | |
7942 | option is supplied. | |
984a1947 CR |
7943 | The variable |
7944 | .SM | |
7945 | .B MAPFILE | |
7946 | is the default \fIarray\fP. | |
6a8fd0ed CR |
7947 | Options, if supplied, have the following meanings: |
7948 | .RS | |
7949 | .PD 0 | |
7950 | .TP | |
7951 | .B \-n | |
7952 | Copy at most | |
7953 | .I count | |
7954 | lines. If \fIcount\fP is 0, all lines are copied. | |
7955 | .TP | |
7956 | .B \-O | |
7957 | Begin assigning to | |
7958 | .I array | |
7959 | at index | |
7960 | .IR origin . | |
7961 | The default index is 0. | |
7962 | .TP | |
7963 | .B \-s | |
7964 | Discard the first \fIcount\fP lines read. | |
7965 | .TP | |
7966 | .B \-t | |
984a1947 | 7967 | Remove a trailing newline from each line read. |
6a8fd0ed CR |
7968 | .TP |
7969 | .B \-u | |
7970 | Read lines from file descriptor \fIfd\fP instead of the standard input. | |
7971 | .TP | |
7972 | .B \-C | |
7973 | Evaluate | |
7974 | .I callback | |
7975 | each time \fIquantum\fP lines are read. The \fB\-c\fP option specifies | |
7976 | .IR quantum . | |
7977 | .TP | |
7978 | .B \-c | |
7979 | Specify the number of lines read between each call to | |
7980 | .IR callback . | |
7981 | .PD | |
7982 | .PP | |
7983 | If | |
7984 | .B \-C | |
7985 | is specified without | |
7986 | .BR \-c , | |
7987 | the default quantum is 5000. | |
e141c35a CR |
7988 | When \fIcallback\fP is evaluated, it is supplied the index of the next |
7989 | array element to be assigned as an additional argument. | |
7990 | \fIcallback\fP is evaluated after the line is read but before the | |
7991 | array element is assigned. | |
6a8fd0ed CR |
7992 | .PP |
7993 | If not supplied with an explicit origin, \fBmapfile\fP will clear \fIarray\fP | |
7994 | before assigning to it. | |
7995 | .PP | |
7996 | \fBmapfile\fP returns successfully unless an invalid option or option | |
e1e48bba CR |
7997 | argument is supplied, \fIarray\fP is invalid or unassignable, or if |
7998 | \fIarray\fP is not an indexed array. | |
6a8fd0ed CR |
7999 | .RE |
8000 | .TP | |
ccc6cda3 | 8001 | \fBpopd\fP [\-\fBn\fP] [+\fIn\fP] [\-\fIn\fP] |
726f6388 JA |
8002 | Removes entries from the directory stack. With no arguments, |
8003 | removes the top directory from the stack, and performs a | |
8004 | .B cd | |
8005 | to the new top directory. | |
ccc6cda3 | 8006 | Arguments, if supplied, have the following meanings: |
726f6388 JA |
8007 | .RS |
8008 | .PD 0 | |
8009 | .TP | |
d3ad40de CR |
8010 | .B \-n |
8011 | Suppresses the normal change of directory when removing directories | |
8012 | from the stack, so that only the stack is manipulated. | |
8013 | .TP | |
ccc6cda3 JA |
8014 | \fB+\fP\fIn\fP |
8015 | Removes the \fIn\fPth entry counting from the left of the list | |
726f6388 JA |
8016 | shown by |
8017 | .BR dirs , | |
bb70624e JA |
8018 | starting with zero. For example: |
8019 | .if n ``popd +0'' | |
8020 | .if t \f(CWpopd +0\fP | |
8021 | removes the first directory, | |
8022 | .if n ``popd +1'' | |
8023 | .if t \f(CWpopd +1\fP | |
8024 | the second. | |
726f6388 | 8025 | .TP |
ccc6cda3 JA |
8026 | \fB\-\fP\fIn\fP |
8027 | Removes the \fIn\fPth entry counting from the right of the list | |
726f6388 JA |
8028 | shown by |
8029 | .BR dirs , | |
bb70624e JA |
8030 | starting with zero. For example: |
8031 | .if n ``popd -0'' | |
8032 | .if t \f(CWpopd -0\fP | |
8033 | removes the last directory, | |
8034 | .if n ``popd -1'' | |
8035 | .if t \f(CWpopd -1\fP | |
8036 | the next to last. | |
726f6388 JA |
8037 | .PD |
8038 | .PP | |
8039 | If the | |
8040 | .B popd | |
8041 | command is successful, a | |
8042 | .B dirs | |
8043 | is performed as well, and the return status is 0. | |
8044 | .B popd | |
cce855bc | 8045 | returns false if an invalid option is encountered, the directory stack |
726f6388 JA |
8046 | is empty, a non-existent directory stack entry is specified, or the |
8047 | directory change fails. | |
8048 | .RE | |
8049 | .TP | |
3ee6b87d | 8050 | \fBprintf\fP [\fB\-v\fP \fIvar\fP] \fIformat\fP [\fIarguments\fP] |
cce855bc JA |
8051 | Write the formatted \fIarguments\fP to the standard output under the |
8052 | control of the \fIformat\fP. | |
8053 | The \fIformat\fP is a character string which contains three types of objects: | |
8054 | plain characters, which are simply copied to standard output, character | |
8055 | escape sequences, which are converted and copied to the standard output, and | |
8056 | format specifications, each of which causes printing of the next successive | |
8057 | \fIargument\fP. | |
f73dda09 | 8058 | In addition to the standard \fIprintf\fP(1) formats, \fB%b\fP causes |
cce855bc | 8059 | \fBprintf\fP to expand backslash escape sequences in the corresponding |
5e13499c | 8060 | \fIargument\fP (except that \fB\ec\fP terminates output, backslashes in |
20587658 | 8061 | \fB\e\(aq\fP, \fB\e"\fP, and \fB\e?\fP are not removed, and octal escapes |
5e13499c CR |
8062 | beginning with \fB\e0\fP may contain up to four digits), |
8063 | and \fB%q\fP causes \fBprintf\fP to output the corresponding | |
cce855bc JA |
8064 | \fIargument\fP in a format that can be reused as shell input. |
8065 | .sp 1 | |
3ee6b87d CR |
8066 | The \fB\-v\fP option causes the output to be assigned to the variable |
8067 | \fIvar\fP rather than being printed to the standard output. | |
8068 | .sp 1 | |
cce855bc JA |
8069 | The \fIformat\fP is reused as necessary to consume all of the \fIarguments\fP. |
8070 | If the \fIformat\fP requires more \fIarguments\fP than are supplied, the | |
8071 | extra format specifications behave as if a zero value or null string, as | |
bb70624e JA |
8072 | appropriate, had been supplied. The return value is zero on success, |
8073 | non-zero on failure. | |
cce855bc | 8074 | .TP |
d3ad40de | 8075 | \fBpushd\fP [\fB\-n\fP] [+\fIn\fP] [\-\fIn\fP] |
7117c2d2 | 8076 | .PD 0 |
726f6388 | 8077 | .TP |
d3ad40de | 8078 | \fBpushd\fP [\fB\-n\fP] [\fIdir\fP] |
726f6388 JA |
8079 | .PD |
8080 | Adds a directory to the top of the directory stack, or rotates | |
8081 | the stack, making the new top of the stack the current working | |
8082 | directory. With no arguments, exchanges the top two directories | |
8083 | and returns 0, unless the directory stack is empty. | |
ccc6cda3 | 8084 | Arguments, if supplied, have the following meanings: |
726f6388 JA |
8085 | .RS |
8086 | .PD 0 | |
8087 | .TP | |
d3ad40de CR |
8088 | .B \-n |
8089 | Suppresses the normal change of directory when adding directories | |
8090 | to the stack, so that only the stack is manipulated. | |
8091 | .TP | |
ccc6cda3 | 8092 | \fB+\fP\fIn\fP |
726f6388 JA |
8093 | Rotates the stack so that the \fIn\fPth directory |
8094 | (counting from the left of the list shown by | |
d166f048 JA |
8095 | .BR dirs , |
8096 | starting with zero) | |
726f6388 JA |
8097 | is at the top. |
8098 | .TP | |
ccc6cda3 | 8099 | \fB\-\fP\fIn\fP |
726f6388 | 8100 | Rotates the stack so that the \fIn\fPth directory |
d166f048 JA |
8101 | (counting from the right of the list shown by |
8102 | .BR dirs , | |
8103 | starting with zero) is at the top. | |
726f6388 | 8104 | .TP |
bb70624e | 8105 | .I dir |
ccc6cda3 | 8106 | Adds |
726f6388 JA |
8107 | .I dir |
8108 | to the directory stack at the top, making it the | |
8109 | new current working directory. | |
8110 | .PD | |
8111 | .PP | |
8112 | If the | |
8113 | .B pushd | |
8114 | command is successful, a | |
8115 | .B dirs | |
8116 | is performed as well. | |
8117 | If the first form is used, | |
8118 | .B pushd | |
8119 | returns 0 unless the cd to | |
8120 | .I dir | |
8121 | fails. With the second form, | |
8122 | .B pushd | |
8123 | returns 0 unless the directory stack is empty, | |
ccc6cda3 | 8124 | a non-existent directory stack element is specified, |
726f6388 JA |
8125 | or the directory change to the specified new current directory |
8126 | fails. | |
8127 | .RE | |
8128 | .TP | |
ccc6cda3 | 8129 | \fBpwd\fP [\fB\-LP\fP] |
bb70624e JA |
8130 | Print the absolute pathname of the current working directory. |
8131 | The pathname printed contains no symbolic links if the | |
726f6388 | 8132 | .B \-P |
ccc6cda3 JA |
8133 | option is supplied or the |
8134 | .B \-o physical | |
726f6388 JA |
8135 | option to the |
8136 | .B set | |
ccc6cda3 JA |
8137 | builtin command is enabled. |
8138 | If the | |
8139 | .B \-L | |
bb70624e | 8140 | option is used, the pathname printed may contain symbolic links. |
ccc6cda3 | 8141 | The return status is 0 unless an error occurs while |
cce855bc JA |
8142 | reading the name of the current directory or an |
8143 | invalid option is supplied. | |
726f6388 | 8144 | .TP |
08e72d7a | 8145 | \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 |
8146 | One line is read from the standard input, or from the file descriptor |
8147 | \fIfd\fP supplied as an argument to the \fB\-u\fP option, and the first word | |
726f6388 JA |
8148 | is assigned to the first |
8149 | .IR name , | |
8150 | the second word to the second | |
8151 | .IR name , | |
cce855bc JA |
8152 | and so on, with leftover words and their intervening separators assigned |
8153 | to the last | |
726f6388 | 8154 | .IR name . |
7117c2d2 | 8155 | If there are fewer words read from the input stream than names, |
cce855bc JA |
8156 | the remaining names are assigned empty values. |
8157 | The characters in | |
726f6388 JA |
8158 | .SM |
8159 | .B IFS | |
cce855bc | 8160 | are used to split the line into words. |
b72432fd JA |
8161 | The backslash character (\fB\e\fP) may be used to remove any special |
8162 | meaning for the next character read and for line continuation. | |
cce855bc | 8163 | Options, if supplied, have the following meanings: |
ccc6cda3 JA |
8164 | .RS |
8165 | .PD 0 | |
8166 | .TP | |
bb70624e | 8167 | .B \-a \fIaname\fP |
ccc6cda3 JA |
8168 | The words are assigned to sequential indices |
8169 | of the array variable | |
8170 | .IR aname , | |
8171 | starting at 0. | |
8172 | .I aname | |
8173 | is unset before any new values are assigned. | |
cce855bc | 8174 | Other \fIname\fP arguments are ignored. |
ccc6cda3 | 8175 | .TP |
bb70624e JA |
8176 | .B \-d \fIdelim\fP |
8177 | The first character of \fIdelim\fP is used to terminate the input line, | |
8178 | rather than newline. | |
8179 | .TP | |
ccc6cda3 JA |
8180 | .B \-e |
8181 | If the standard input | |
8182 | is coming from a terminal, | |
8183 | .B readline | |
8184 | (see | |
8185 | .SM | |
8186 | .B READLINE | |
8187 | above) is used to obtain the line. | |
14e8b2a7 CR |
8188 | Readline uses the current (or default, if line editing was not previously |
8189 | active) editing settings. | |
bb70624e | 8190 | .TP |
1d0e1a34 CR |
8191 | .B \-i \fItext\fP |
8192 | If | |
8193 | .B readline | |
8194 | is being used to read the line, \fItext\fP is placed into the editing | |
8195 | buffer before editing begins. | |
8196 | .TP | |
bb70624e JA |
8197 | .B \-n \fInchars\fP |
8198 | \fBread\fP returns after reading \fInchars\fP characters rather than | |
08e72d7a CR |
8199 | waiting for a complete line of input, but honor a delimiter if fewer |
8200 | than \fInchars\fP characters are read before the delimiter. | |
8201 | .TP | |
8202 | .B \-N \fInchars\fP | |
8203 | \fBread\fP returns after reading exactly \fInchars\fP characters rather | |
8204 | than waiting for a complete line of input, unless EOF is encountered or | |
a3143574 CR |
8205 | \fBread\fP times out. |
8206 | Delimiter characters encountered in the input are | |
8207 | not treated specially and do not cause \fBread\fP to return until | |
8208 | \fInchars\fP characters are read. | |
bb70624e JA |
8209 | .TP |
8210 | .B \-p \fIprompt\fP | |
f73dda09 | 8211 | Display \fIprompt\fP on standard error, without a |
bb70624e JA |
8212 | trailing newline, before attempting to read any input. The prompt |
8213 | is displayed only if input is coming from a terminal. | |
8214 | .TP | |
8215 | .B \-r | |
8216 | Backslash does not act as an escape character. | |
8217 | The backslash is considered to be part of the line. | |
8218 | In particular, a backslash-newline pair may not be used as a line | |
8219 | continuation. | |
8220 | .TP | |
8221 | .B \-s | |
8222 | Silent mode. If input is coming from a terminal, characters are | |
8223 | not echoed. | |
8224 | .TP | |
8225 | .B \-t \fItimeout\fP | |
8226 | Cause \fBread\fP to time out and return failure if a complete line of | |
8227 | input is not read within \fItimeout\fP seconds. | |
4ac1ff98 CR |
8228 | \fItimeout\fP may be a decimal number with a fractional portion following |
8229 | the decimal point. | |
e33f2203 CR |
8230 | This option is only effective if \fBread\fP is reading input from a |
8231 | terminal, pipe, or other special file; it has no effect when reading | |
8232 | from regular files. | |
48ff5447 CR |
8233 | If \fItimeout\fP is 0, \fBread\fP returns success if input is available on |
8234 | the specified file descriptor, failure otherwise. | |
e33f2203 | 8235 | The exit status is greater than 128 if the timeout is exceeded. |
7117c2d2 | 8236 | .TP |
0f445e6c | 8237 | .B \-u \fIfd\fP |
7117c2d2 | 8238 | Read input from file descriptor \fIfd\fP. |
ccc6cda3 JA |
8239 | .PD |
8240 | .PP | |
8241 | If no | |
726f6388 JA |
8242 | .I names |
8243 | are supplied, the line read is assigned to the variable | |
8244 | .SM | |
8245 | .BR REPLY . | |
7117c2d2 | 8246 | The return code is zero, unless end-of-file is encountered, \fBread\fP |
09767ff0 CR |
8247 | times out (in which case the return code is greater than 128), or an |
8248 | invalid file descriptor is supplied as the argument to \fB\-u\fP. | |
ccc6cda3 | 8249 | .RE |
726f6388 | 8250 | .TP |
fdf670ea | 8251 | \fBreadonly\fP [\fB\-aApf\fP] [\fIname\fP[=\fIword\fP] ...] |
726f6388 JA |
8252 | .PD |
8253 | The given | |
ccc6cda3 JA |
8254 | \fInames\fP are marked readonly; the values of these |
8255 | .I names | |
726f6388 JA |
8256 | may not be changed by subsequent assignment. |
8257 | If the | |
8258 | .B \-f | |
8259 | option is supplied, the functions corresponding to the | |
8260 | \fInames\fP are so | |
ccc6cda3 JA |
8261 | marked. |
8262 | The | |
8263 | .B \-a | |
fdf670ea CR |
8264 | option restricts the variables to indexed arrays; the |
8265 | .B \-A | |
8266 | option restricts the variables to associative arrays. | |
ccc6cda3 JA |
8267 | If no |
8268 | .I name | |
8269 | arguments are given, or if the | |
726f6388 | 8270 | .B \-p |
ccc6cda3 | 8271 | option is supplied, a list of all readonly names is printed. |
cce855bc JA |
8272 | The |
8273 | .B \-p | |
bb70624e JA |
8274 | option causes output to be displayed in a format that |
8275 | may be reused as input. | |
d3a24ed2 CR |
8276 | If a variable name is followed by =\fIword\fP, the value of |
8277 | the variable is set to \fIword\fP. | |
cce855bc | 8278 | The return status is 0 unless an invalid option is encountered, |
ccc6cda3 JA |
8279 | one of the |
8280 | .I names | |
cce855bc | 8281 | is not a valid shell variable name, or |
726f6388 JA |
8282 | .B \-f |
8283 | is supplied with a | |
8284 | .I name | |
8285 | that is not a function. | |
8286 | .TP | |
8287 | \fBreturn\fP [\fIn\fP] | |
8288 | Causes a function to exit with the return value specified by | |
8289 | .IR n . | |
8290 | If | |
8291 | .I n | |
8292 | is omitted, the return status is that of the last command | |
8293 | executed in the function body. If used outside a function, | |
8294 | but during execution of a script by the | |
8295 | .B . | |
8296 | (\fBsource\fP) command, it causes the shell to stop executing | |
8297 | that script and return either | |
8298 | .I n | |
8299 | or the exit status of the last command executed within the | |
8300 | script as the exit status of the script. If used outside a | |
8301 | function and not during execution of a script by \fB.\fP\^, | |
8302 | the return status is false. | |
d3a24ed2 CR |
8303 | Any command associated with the \fBRETURN\fP trap is executed |
8304 | before execution resumes after the function or script. | |
726f6388 | 8305 | .TP |
d3ad40de CR |
8306 | \fBset\fP [\fB\-\-abefhkmnptuvxBCEHPT\fP] [\fB\-o\fP \fIoption\fP] [\fIarg\fP ...] |
8307 | .PD 0 | |
8308 | .TP | |
8309 | \fBset\fP [\fB+abefhkmnptuvxBCEHPT\fP] [\fB+o\fP \fIoption\fP] [\fIarg\fP ...] | |
8310 | .PD | |
ccc6cda3 | 8311 | Without options, the name and value of each shell variable are displayed |
54cdd75a CR |
8312 | in a format that can be reused as input |
8313 | for setting or resetting the currently-set variables. | |
8314 | Read-only variables cannot be reset. | |
8315 | In \fIposix mode\fP, only shell variables are listed. | |
cce855bc | 8316 | The output is sorted according to the current locale. |
ccc6cda3 | 8317 | When options are specified, they set or unset shell attributes. |
626d0694 | 8318 | Any arguments remaining after option processing are treated |
ccc6cda3 JA |
8319 | as values for the positional parameters and are assigned, in order, to |
8320 | .BR $1 , | |
8321 | .BR $2 , | |
8322 | .B ... | |
8323 | .BR $\fIn\fP . | |
8324 | Options, if specified, have the following meanings: | |
726f6388 JA |
8325 | .RS |
8326 | .PD 0 | |
8327 | .TP 8 | |
8328 | .B \-a | |
5e13499c CR |
8329 | Automatically mark variables and functions which are modified or |
8330 | created for export to the environment of subsequent commands. | |
726f6388 JA |
8331 | .TP 8 |
8332 | .B \-b | |
ccc6cda3 JA |
8333 | Report the status of terminated background jobs |
8334 | immediately, rather than before the next primary prompt. This is | |
8335 | effective only when job control is enabled. | |
726f6388 JA |
8336 | .TP 8 |
8337 | .B \-e | |
a05a1337 CR |
8338 | Exit immediately if a \fIpipeline\fP (which may consist of a single |
8339 | \fIsimple command\fP), a \fIsubshell\fP command enclosed in parentheses, | |
8340 | or one of the commands executed as part of a command list enclosed | |
8341 | by braces (see | |
726f6388 JA |
8342 | .SM |
8343 | .B SHELL GRAMMAR | |
d3a24ed2 CR |
8344 | above) exits with a non-zero status. |
8345 | The shell does not exit if the | |
8346 | command that fails is part of the command list immediately following a | |
8347 | .B while | |
726f6388 | 8348 | or |
d3a24ed2 CR |
8349 | .B until |
8350 | keyword, | |
4b9cc222 | 8351 | part of the test following the |
d3ad40de | 8352 | .B if |
4b9cc222 CR |
8353 | or |
8354 | .B elif | |
8355 | reserved words, part of any command executed in a | |
726f6388 JA |
8356 | .B && |
8357 | or | |
ccc6cda3 | 8358 | .B \(bv\(bv |
a05a1337 | 8359 | list except the command following the final \fB&&\fP or \fB\(bv\(bv\fP, |
d3ad40de CR |
8360 | any command in a pipeline but the last, |
8361 | or if the command's return value is | |
a05a1337 | 8362 | being inverted with |
726f6388 | 8363 | .BR ! . |
f73dda09 | 8364 | A trap on \fBERR\fP, if set, is executed before the shell exits. |
a05a1337 CR |
8365 | This option applies to the shell environment and each subshell environment |
8366 | separately (see | |
984a1947 | 8367 | .SM |
a05a1337 CR |
8368 | .B "COMMAND EXECUTION ENVIRONMENT" |
8369 | above), and may cause | |
8370 | subshells to exit before executing all the commands in the subshell. | |
726f6388 JA |
8371 | .TP 8 |
8372 | .B \-f | |
8373 | Disable pathname expansion. | |
8374 | .TP 8 | |
8375 | .B \-h | |
ccc6cda3 | 8376 | Remember the location of commands as they are looked up for execution. |
cce855bc | 8377 | This is enabled by default. |
726f6388 JA |
8378 | .TP 8 |
8379 | .B \-k | |
ccc6cda3 JA |
8380 | All arguments in the form of assignment statements |
8381 | are placed in the environment for a command, not just | |
8382 | those that precede the command name. | |
726f6388 JA |
8383 | .TP 8 |
8384 | .B \-m | |
cce855bc | 8385 | Monitor mode. Job control is enabled. This option is on |
726f6388 JA |
8386 | by default for interactive shells on systems that support |
8387 | it (see | |
8388 | .SM | |
8389 | .B JOB CONTROL | |
8390 | above). Background processes run in a separate process | |
8391 | group and a line containing their exit status is printed | |
8392 | upon their completion. | |
8393 | .TP 8 | |
8394 | .B \-n | |
8395 | Read commands but do not execute them. This may be used to | |
ccc6cda3 | 8396 | check a shell script for syntax errors. This is ignored by |
726f6388 JA |
8397 | interactive shells. |
8398 | .TP 8 | |
ccc6cda3 JA |
8399 | .B \-o \fIoption\-name\fP |
8400 | The \fIoption\-name\fP can be one of the following: | |
726f6388 JA |
8401 | .RS |
8402 | .TP 8 | |
8403 | .B allexport | |
8404 | Same as | |
8405 | .BR \-a . | |
8406 | .TP 8 | |
8407 | .B braceexpand | |
ccc6cda3 JA |
8408 | Same as |
8409 | .BR \-B . | |
726f6388 JA |
8410 | .TP 8 |
8411 | .B emacs | |
8412 | Use an emacs-style command line editing interface. This is enabled | |
8413 | by default when the shell is interactive, unless the shell is started | |
8414 | with the | |
ccc6cda3 | 8415 | .B \-\-noediting |
726f6388 | 8416 | option. |
10a4e415 | 8417 | This also affects the editing interface used for \fBread \-e\fP. |
726f6388 | 8418 | .TP 8 |
a3143574 CR |
8419 | .B errexit |
8420 | Same as | |
8421 | .BR \-e . | |
8422 | .TP 8 | |
d3a24ed2 CR |
8423 | .B errtrace |
8424 | Same as | |
8425 | .BR \-E . | |
8426 | .TP 8 | |
8427 | .B functrace | |
8428 | Same as | |
8429 | .BR \-T . | |
8430 | .TP 8 | |
ccc6cda3 JA |
8431 | .B hashall |
8432 | Same as | |
8433 | .BR \-h . | |
8434 | .TP 8 | |
726f6388 JA |
8435 | .B histexpand |
8436 | Same as | |
8437 | .BR \-H . | |
8438 | .TP 8 | |
ccc6cda3 JA |
8439 | .B history |
8440 | Enable command history, as described above under | |
8441 | .SM | |
8442 | .BR HISTORY . | |
8443 | This option is on by default in interactive shells. | |
8444 | .TP 8 | |
726f6388 | 8445 | .B ignoreeof |
28ef6c31 JA |
8446 | The effect is as if the shell command |
8447 | .if t \f(CWIGNOREEOF=10\fP | |
8448 | .if n ``IGNOREEOF=10'' | |
8449 | had been executed | |
726f6388 JA |
8450 | (see |
8451 | .B Shell Variables | |
8452 | above). | |
8453 | .TP 8 | |
ccc6cda3 JA |
8454 | .B keyword |
8455 | Same as | |
8456 | .BR \-k . | |
726f6388 JA |
8457 | .TP 8 |
8458 | .B monitor | |
8459 | Same as | |
8460 | .BR \-m . | |
8461 | .TP 8 | |
8462 | .B noclobber | |
8463 | Same as | |
8464 | .BR \-C . | |
8465 | .TP 8 | |
8466 | .B noexec | |
8467 | Same as | |
8468 | .BR \-n . | |
8469 | .TP 8 | |
8470 | .B noglob | |
8471 | Same as | |
8472 | .BR \-f . | |
57a3f689 | 8473 | .TP 8 |
f73dda09 JA |
8474 | .B nolog |
8475 | Currently ignored. | |
726f6388 | 8476 | .TP 8 |
726f6388 JA |
8477 | .B notify |
8478 | Same as | |
8479 | .BR \-b . | |
8480 | .TP 8 | |
8481 | .B nounset | |
8482 | Same as | |
8483 | .BR \-u . | |
8484 | .TP 8 | |
ccc6cda3 JA |
8485 | .B onecmd |
8486 | Same as | |
8487 | .BR \-t . | |
8488 | .TP 8 | |
726f6388 JA |
8489 | .B physical |
8490 | Same as | |
8491 | .BR \-P . | |
8492 | .TP 8 | |
d3a24ed2 CR |
8493 | .B pipefail |
8494 | If set, the return value of a pipeline is the value of the last | |
8495 | (rightmost) command to exit with a non-zero status, or zero if all | |
8496 | commands in the pipeline exit successfully. | |
8497 | This option is disabled by default. | |
8498 | .TP 8 | |
726f6388 | 8499 | .B posix |
ccc6cda3 JA |
8500 | Change the behavior of |
8501 | .B bash | |
8502 | where the default operation differs | |
ac18b312 | 8503 | from the POSIX standard to match the standard (\fIposix mode\fP). |
726f6388 JA |
8504 | .TP 8 |
8505 | .B privileged | |
8506 | Same as | |
8507 | .BR \-p . | |
8508 | .TP 8 | |
8509 | .B verbose | |
8510 | Same as | |
8511 | .BR \-v . | |
8512 | .TP 8 | |
8513 | .B vi | |
8514 | Use a vi-style command line editing interface. | |
10a4e415 | 8515 | This also affects the editing interface used for \fBread \-e\fP. |
726f6388 JA |
8516 | .TP 8 |
8517 | .B xtrace | |
8518 | Same as | |
8519 | .BR \-x . | |
ccc6cda3 | 8520 | .sp .5 |
726f6388 | 8521 | .PP |
ccc6cda3 JA |
8522 | If |
8523 | .B \-o | |
8524 | is supplied with no \fIoption\-name\fP, the values of the current options are | |
726f6388 | 8525 | printed. |
ccc6cda3 JA |
8526 | If |
8527 | .B +o | |
8528 | is supplied with no \fIoption\-name\fP, a series of | |
8529 | .B set | |
8530 | commands to recreate the current option settings is displayed on | |
8531 | the standard output. | |
726f6388 JA |
8532 | .RE |
8533 | .TP 8 | |
8534 | .B \-p | |
8535 | Turn on | |
8536 | .I privileged | |
8537 | mode. In this mode, the | |
bb70624e | 8538 | .SM |
726f6388 | 8539 | .B $ENV |
b72432fd | 8540 | and |
bb70624e | 8541 | .SM |
b72432fd JA |
8542 | .B $BASH_ENV |
8543 | files are not processed, shell functions are not inherited from the | |
bb70624e JA |
8544 | environment, and the |
8545 | .SM | |
e77a3058 | 8546 | .BR SHELLOPTS , |
984a1947 | 8547 | .SM |
691aebcb | 8548 | .BR BASHOPTS , |
984a1947 | 8549 | .SM |
e77a3058 CR |
8550 | .BR CDPATH , |
8551 | and | |
984a1947 | 8552 | .SM |
e77a3058 CR |
8553 | .B GLOBIGNORE |
8554 | variables, if they appear in the environment, are ignored. | |
b72432fd JA |
8555 | If the shell is started with the effective user (group) id not equal to the |
8556 | real user (group) id, and the \fB\-p\fP option is not supplied, these actions | |
8557 | are taken and the effective user id is set to the real user id. | |
8558 | If the \fB\-p\fP option is supplied at startup, the effective user id is | |
8559 | not reset. | |
cce855bc | 8560 | Turning this option off causes the effective user |
726f6388 JA |
8561 | and group ids to be set to the real user and group ids. |
8562 | .TP 8 | |
8563 | .B \-t | |
8564 | Exit after reading and executing one command. | |
8565 | .TP 8 | |
8566 | .B \-u | |
2c471a92 CR |
8567 | Treat unset variables and parameters other than the special |
8568 | parameters "@" and "*" as an error when performing | |
726f6388 | 8569 | parameter expansion. If expansion is attempted on an |
2c471a92 | 8570 | unset variable or parameter, the shell prints an error message, and, |
ccc6cda3 | 8571 | if not interactive, exits with a non-zero status. |
726f6388 JA |
8572 | .TP 8 |
8573 | .B \-v | |
8574 | Print shell input lines as they are read. | |
8575 | .TP 8 | |
8576 | .B \-x | |
ccc6cda3 | 8577 | After expanding each \fIsimple command\fP, |
d3a24ed2 CR |
8578 | \fBfor\fP command, \fBcase\fP command, \fBselect\fP command, or |
8579 | arithmetic \fBfor\fP command, display the expanded value of | |
726f6388 JA |
8580 | .SM |
8581 | .BR PS4 , | |
d3a24ed2 CR |
8582 | followed by the command and its expanded arguments |
8583 | or associated word list. | |
726f6388 | 8584 | .TP 8 |
ccc6cda3 JA |
8585 | .B \-B |
8586 | The shell performs brace expansion (see | |
8587 | .B Brace Expansion | |
8588 | above). This is on by default. | |
726f6388 JA |
8589 | .TP 8 |
8590 | .B \-C | |
ccc6cda3 JA |
8591 | If set, |
8592 | .B bash | |
8593 | does not overwrite an existing file with the | |
8594 | .BR > , | |
8595 | .BR >& , | |
8596 | and | |
8597 | .B <> | |
8598 | redirection operators. This may be overridden when | |
8599 | creating output files by using the redirection operator | |
8600 | .B >| | |
8601 | instead of | |
8602 | .BR > . | |
726f6388 | 8603 | .TP 8 |
d3a24ed2 CR |
8604 | .B \-E |
8605 | If set, any trap on \fBERR\fP is inherited by shell functions, command | |
8606 | substitutions, and commands executed in a subshell environment. | |
8607 | The \fBERR\fP trap is normally not inherited in such cases. | |
8608 | .TP 8 | |
726f6388 JA |
8609 | .B \-H |
8610 | Enable | |
8611 | .B ! | |
cce855bc | 8612 | style history substitution. This option is on by |
726f6388 JA |
8613 | default when the shell is interactive. |
8614 | .TP 8 | |
8615 | .B \-P | |
ccc6cda3 JA |
8616 | If set, the shell does not follow symbolic links when executing |
8617 | commands such as | |
726f6388 | 8618 | .B cd |
ccc6cda3 JA |
8619 | that change the current working directory. It uses the |
8620 | physical directory structure instead. By default, | |
8621 | .B bash | |
8622 | follows the logical chain of directories when performing commands | |
8623 | which change the current directory. | |
726f6388 | 8624 | .TP 8 |
d3a24ed2 | 8625 | .B \-T |
76a8d78d CR |
8626 | If set, any traps on \fBDEBUG\fP and \fBRETURN\fP are inherited by shell |
8627 | functions, command substitutions, and commands executed in a | |
8628 | subshell environment. | |
8629 | The \fBDEBUG\fP and \fBRETURN\fP traps are normally not inherited | |
8630 | in such cases. | |
d3a24ed2 | 8631 | .TP 8 |
726f6388 | 8632 | .B \-\- |
cce855bc | 8633 | If no arguments follow this option, then the positional parameters are |
726f6388 JA |
8634 | unset. Otherwise, the positional parameters are set to the |
8635 | \fIarg\fPs, even if some of them begin with a | |
8636 | .BR \- . | |
8637 | .TP 8 | |
8638 | .B \- | |
8639 | Signal the end of options, cause all remaining \fIarg\fPs to be | |
8640 | assigned to the positional parameters. The | |
8641 | .B \-x | |
8642 | and | |
8643 | .B \-v | |
8644 | options are turned off. | |
8645 | If there are no \fIarg\fPs, | |
8646 | the positional parameters remain unchanged. | |
8647 | .PD | |
8648 | .PP | |
cce855bc JA |
8649 | The options are off by default unless otherwise noted. |
8650 | Using + rather than \- causes these options to be turned off. | |
8651 | The options can also be specified as arguments to an invocation of | |
8652 | the shell. | |
8653 | The current set of options may be found in | |
726f6388 | 8654 | .BR $\- . |
cce855bc | 8655 | The return status is always true unless an invalid option is encountered. |
726f6388 JA |
8656 | .RE |
8657 | .TP | |
8658 | \fBshift\fP [\fIn\fP] | |
8659 | The positional parameters from \fIn\fP+1 ... are renamed to | |
8660 | .B $1 | |
8661 | .B .... | |
8662 | Parameters represented by the numbers \fB$#\fP | |
8663 | down to \fB$#\fP\-\fIn\fP+1 are unset. | |
ccc6cda3 JA |
8664 | .I n |
8665 | must be a non-negative number less than or equal to \fB$#\fP. | |
726f6388 JA |
8666 | If |
8667 | .I n | |
8668 | is 0, no parameters are changed. | |
8669 | If | |
8670 | .I n | |
8671 | is not given, it is assumed to be 1. | |
726f6388 JA |
8672 | If |
8673 | .I n | |
8674 | is greater than \fB$#\fP, the positional parameters are not changed. | |
ccc6cda3 | 8675 | The return status is greater than zero if |
726f6388 JA |
8676 | .I n |
8677 | is greater than | |
8678 | .B $# | |
ccc6cda3 JA |
8679 | or less than zero; otherwise 0. |
8680 | .TP | |
8681 | \fBshopt\fP [\fB\-pqsu\fP] [\fB\-o\fP] [\fIoptname\fP ...] | |
8682 | Toggle the values of variables controlling optional shell behavior. | |
8683 | With no options, or with the | |
8684 | .B \-p | |
8685 | option, a list of all settable options is displayed, with | |
cce855bc JA |
8686 | an indication of whether or not each is set. |
8687 | The \fB\-p\fP option causes output to be displayed in a form that | |
8688 | may be reused as input. | |
8689 | Other options have the following meanings: | |
ccc6cda3 JA |
8690 | .RS |
8691 | .PD 0 | |
8692 | .TP | |
8693 | .B \-s | |
8694 | Enable (set) each \fIoptname\fP. | |
8695 | .TP | |
8696 | .B \-u | |
8697 | Disable (unset) each \fIoptname\fP. | |
8698 | .TP | |
8699 | .B \-q | |
8700 | Suppresses normal output (quiet mode); the return status indicates | |
8701 | whether the \fIoptname\fP is set or unset. | |
8702 | If multiple \fIoptname\fP arguments are given with | |
8703 | .BR \-q , | |
8704 | the return status is zero if all \fIoptnames\fP are enabled; non-zero | |
8705 | otherwise. | |
8706 | .TP | |
8707 | .B \-o | |
8708 | Restricts the values of \fIoptname\fP to be those defined for the | |
8709 | .B \-o | |
8710 | option to the | |
8711 | .B set | |
8712 | builtin. | |
8713 | .PD | |
8714 | .PP | |
8715 | If either | |
8716 | .B \-s | |
8717 | or | |
8718 | .B \-u | |
8719 | is used with no \fIoptname\fP arguments, the display is limited to | |
8720 | those options which are set or unset, respectively. | |
8721 | Unless otherwise noted, the \fBshopt\fP options are disabled (unset) | |
8722 | by default. | |
8723 | .PP | |
8724 | The return status when listing options is zero if all \fIoptnames\fP | |
8725 | are enabled, non-zero otherwise. When setting or unsetting options, | |
cce855bc | 8726 | the return status is zero unless an \fIoptname\fP is not a valid shell |
ccc6cda3 JA |
8727 | option. |
8728 | .PP | |
8729 | The list of \fBshopt\fP options is: | |
8730 | .if t .sp .5v | |
8731 | .if n .sp 1v | |
8732 | .PD 0 | |
8733 | .TP 8 | |
d3ad40de CR |
8734 | .B autocd |
8735 | If set, a command name that is the name of a directory is executed as if | |
8736 | it were the argument to the \fBcd\fP command. | |
8737 | This option is only used by interactive shells. | |
8738 | .TP 8 | |
ccc6cda3 JA |
8739 | .B cdable_vars |
8740 | If set, an argument to the | |
8741 | .B cd | |
8742 | builtin command that | |
8743 | is not a directory is assumed to be the name of a variable whose | |
8744 | value is the directory to change to. | |
8745 | .TP 8 | |
8746 | .B cdspell | |
8747 | If set, minor errors in the spelling of a directory component in a | |
8748 | .B cd | |
8749 | command will be corrected. | |
8750 | The errors checked for are transposed characters, | |
8751 | a missing character, and one character too many. | |
8752 | If a correction is found, the corrected file name is printed, | |
8753 | and the command proceeds. | |
d166f048 | 8754 | This option is only used by interactive shells. |
ccc6cda3 JA |
8755 | .TP 8 |
8756 | .B checkhash | |
8757 | If set, \fBbash\fP checks that a command found in the hash | |
8758 | table exists before trying to execute it. If a hashed command no | |
8759 | longer exists, a normal path search is performed. | |
8760 | .TP 8 | |
d3ad40de | 8761 | .B checkjobs |
29d25b54 | 8762 | If set, \fBbash\fP lists the status of any stopped and running jobs before |
d3ad40de CR |
8763 | exiting an interactive shell. If any jobs are running, this causes |
8764 | the exit to be deferred until a second exit is attempted without an | |
984a1947 CR |
8765 | intervening command (see |
8766 | .SM | |
8767 | .B "JOB CONTROL" | |
8768 | above). The shell always | |
d3ad40de CR |
8769 | postpones exiting if any jobs are stopped. |
8770 | .TP 8 | |
ccc6cda3 JA |
8771 | .B checkwinsize |
8772 | If set, \fBbash\fP checks the window size after each command | |
8773 | and, if necessary, updates the values of | |
8774 | .SM | |
8775 | .B LINES | |
8776 | and | |
8777 | .SM | |
8778 | .BR COLUMNS . | |
8779 | .TP 8 | |
8780 | .B cmdhist | |
8781 | If set, | |
8782 | .B bash | |
8783 | attempts to save all lines of a multiple-line | |
8784 | command in the same history entry. This allows | |
8785 | easy re-editing of multi-line commands. | |
8786 | .TP 8 | |
35ee8ea0 CR |
8787 | .B compat31 |
8788 | If set, | |
8789 | .B bash | |
8790 | changes its behavior to that of version 3.1 with respect to quoted | |
8791 | arguments to the conditional command's =~ operator. | |
8792 | .TP 8 | |
cd0ef727 CR |
8793 | .B compat32 |
8794 | If set, | |
8795 | .B bash | |
8796 | changes its behavior to that of version 3.2 with respect to locale-specific | |
8797 | string comparison when using the conditional command's < and > operators. | |
8798 | .TP 8 | |
8799 | .B compat40 | |
8800 | If set, | |
8801 | .B bash | |
8802 | changes its behavior to that of version 4.0 with respect to locale-specific | |
8803 | string comparison when using the conditional command's < and > operators | |
8804 | and the effect of interrupting a command list. | |
8805 | .TP 8 | |
4ac1ff98 CR |
8806 | .B dirspell |
8807 | If set, | |
8808 | .B bash | |
8809 | attempts spelling correction on directory names during word completion | |
8810 | if the directory name initially supplied does not exist. | |
8811 | .TP 8 | |
ccc6cda3 JA |
8812 | .B dotglob |
8813 | If set, | |
8814 | .B bash | |
8815 | includes filenames beginning with a `.' in the results of pathname | |
8816 | expansion. | |
8817 | .TP 8 | |
8818 | .B execfail | |
8819 | If set, a non-interactive shell will not exit if | |
8820 | it cannot execute the file specified as an argument to the | |
8821 | .B exec | |
8822 | builtin command. An interactive shell does not exit if | |
8823 | .B exec | |
8824 | fails. | |
8825 | .TP 8 | |
8826 | .B expand_aliases | |
8827 | If set, aliases are expanded as described above under | |
8828 | .SM | |
8829 | .BR ALIASES . | |
8830 | This option is enabled by default for interactive shells. | |
8831 | .TP 8 | |
d3a24ed2 CR |
8832 | .B extdebug |
8833 | If set, behavior intended for use by debuggers is enabled: | |
8834 | .RS | |
8835 | .TP | |
8836 | .B 1. | |
8837 | The \fB\-F\fP option to the \fBdeclare\fP builtin displays the source | |
8838 | file name and line number corresponding to each function name supplied | |
8839 | as an argument. | |
8840 | .TP | |
8841 | .B 2. | |
8842 | If the command run by the \fBDEBUG\fP trap returns a non-zero value, the | |
8843 | next command is skipped and not executed. | |
8844 | .TP | |
8845 | .B 3. | |
8846 | If the command run by the \fBDEBUG\fP trap returns a value of 2, and the | |
8847 | shell is executing in a subroutine (a shell function or a shell script | |
8848 | executed by the \fB.\fP or \fBsource\fP builtins), a call to | |
8849 | \fBreturn\fP is simulated. | |
2206f89a CR |
8850 | .TP |
8851 | .B 4. | |
984a1947 CR |
8852 | .SM |
8853 | .B BASH_ARGC | |
8854 | and | |
8855 | .SM | |
8856 | .B BASH_ARGV | |
8857 | are updated as described in their descriptions above. | |
2206f89a CR |
8858 | .TP |
8859 | .B 5. | |
8860 | Function tracing is enabled: command substitution, shell functions, and | |
8861 | subshells invoked with \fB(\fP \fIcommand\fP \fB)\fP inherit the | |
8862 | \fBDEBUG\fP and \fBRETURN\fP traps. | |
8863 | .TP | |
8864 | .B 6. | |
8865 | Error tracing is enabled: command substitution, shell functions, and | |
8866 | subshells invoked with \fB(\fP \fIcommand\fP \fB)\fP inherit the | |
5cdaaf76 | 8867 | \fBERR\fP trap. |
d3a24ed2 CR |
8868 | .RE |
8869 | .TP 8 | |
cce855bc JA |
8870 | .B extglob |
8871 | If set, the extended pattern matching features described above under | |
8872 | \fBPathname Expansion\fP are enabled. | |
8873 | .TP 8 | |
d3a24ed2 | 8874 | .B extquote |
20587658 | 8875 | If set, \fB$\fP\(aq\fIstring\fP\(aq and \fB$\fP"\fIstring\fP" quoting is |
d3a24ed2 CR |
8876 | performed within \fB${\fP\fIparameter\fP\fB}\fP expansions |
8877 | enclosed in double quotes. This option is enabled by default. | |
8878 | .TP 8 | |
8879 | .B failglob | |
8880 | If set, patterns which fail to match filenames during pathname expansion | |
8881 | result in an expansion error. | |
8882 | .TP 8 | |
8883 | .B force_fignore | |
984a1947 CR |
8884 | If set, the suffixes specified by the |
8885 | .SM | |
8886 | .B FIGNORE | |
8887 | shell variable | |
d3a24ed2 CR |
8888 | cause words to be ignored when performing word completion even if |
8889 | the ignored words are the only possible completions. | |
8890 | See | |
8891 | .SM | |
8892 | \fBSHELL VARIABLES\fP | |
984a1947 CR |
8893 | above for a description of |
8894 | .SM | |
8895 | .BR FIGNORE . | |
d3a24ed2 CR |
8896 | This option is enabled by default. |
8897 | .TP 8 | |
4ac1ff98 | 8898 | .B globstar |
d0ca3503 | 8899 | If set, the pattern \fB**\fP used in a pathname expansion context will |
4ac1ff98 CR |
8900 | match a files and zero or more directories and subdirectories. |
8901 | If the pattern is followed by a \fB/\fP, only directories and | |
8902 | subdirectories match. | |
8903 | .TP 8 | |
d3a24ed2 CR |
8904 | .B gnu_errfmt |
8905 | If set, shell error messages are written in the standard GNU error | |
8906 | message format. | |
8907 | .TP 8 | |
ccc6cda3 JA |
8908 | .B histappend |
8909 | If set, the history list is appended to the file named by the value | |
8910 | of the | |
984a1947 | 8911 | .SM |
ccc6cda3 JA |
8912 | .B HISTFILE |
8913 | variable when the shell exits, rather than overwriting the file. | |
8914 | .TP 8 | |
8915 | .B histreedit | |
8916 | If set, and | |
8917 | .B readline | |
8918 | is being used, a user is given the opportunity to re-edit a | |
8919 | failed history substitution. | |
8920 | .TP 8 | |
8921 | .B histverify | |
8922 | If set, and | |
8923 | .B readline | |
8924 | is being used, the results of history substitution are not immediately | |
8925 | passed to the shell parser. Instead, the resulting line is loaded into | |
8926 | the \fBreadline\fP editing buffer, allowing further modification. | |
8927 | .TP 8 | |
8928 | .B hostcomplete | |
8929 | If set, and | |
8930 | .B readline | |
cce855bc JA |
8931 | is being used, \fBbash\fP will attempt to perform hostname completion when a |
8932 | word containing a \fB@\fP is being completed (see | |
ccc6cda3 JA |
8933 | .B Completing |
8934 | under | |
8935 | .SM | |
8936 | .B READLINE | |
8937 | above). | |
8938 | This is enabled by default. | |
8939 | .TP 8 | |
cce855bc JA |
8940 | .B huponexit |
8941 | If set, \fBbash\fP will send | |
8942 | .SM | |
8943 | .B SIGHUP | |
8944 | to all jobs when an interactive login shell exits. | |
8945 | .TP 8 | |
ccc6cda3 JA |
8946 | .B interactive_comments |
8947 | If set, allow a word beginning with | |
8948 | .B # | |
8949 | to cause that word and all remaining characters on that | |
8950 | line to be ignored in an interactive shell (see | |
8951 | .SM | |
8952 | .B COMMENTS | |
8953 | above). This option is enabled by default. | |
8954 | .TP 8 | |
8955 | .B lithist | |
8956 | If set, and the | |
8957 | .B cmdhist | |
8958 | option is enabled, multi-line commands are saved to the history with | |
8959 | embedded newlines rather than using semicolon separators where possible. | |
8960 | .TP 8 | |
f73dda09 JA |
8961 | .B login_shell |
8962 | The shell sets this option if it is started as a login shell (see | |
8963 | .SM | |
8964 | .B "INVOCATION" | |
8965 | above). | |
8966 | The value may not be changed. | |
8967 | .TP 8 | |
ccc6cda3 JA |
8968 | .B mailwarn |
8969 | If set, and a file that \fBbash\fP is checking for mail has been | |
8970 | accessed since the last time it was checked, the message ``The mail in | |
8971 | \fImailfile\fP has been read'' is displayed. | |
8972 | .TP 8 | |
bb70624e JA |
8973 | .B no_empty_cmd_completion |
8974 | If set, and | |
8975 | .B readline | |
8976 | is being used, | |
8977 | .B bash | |
984a1947 CR |
8978 | will not attempt to search the |
8979 | .SM | |
8980 | .B PATH | |
8981 | for possible completions when | |
bb70624e JA |
8982 | completion is attempted on an empty line. |
8983 | .TP 8 | |
cce855bc JA |
8984 | .B nocaseglob |
8985 | If set, | |
8986 | .B bash | |
8987 | matches filenames in a case\-insensitive fashion when performing pathname | |
8988 | expansion (see | |
8989 | .B Pathname Expansion | |
8990 | above). | |
8991 | .TP 8 | |
2206f89a CR |
8992 | .B nocasematch |
8993 | If set, | |
8994 | .B bash | |
8995 | matches patterns in a case\-insensitive fashion when performing matching | |
8996 | while executing \fBcase\fP or \fB[[\fP conditional commands. | |
8997 | .TP 8 | |
ccc6cda3 JA |
8998 | .B nullglob |
8999 | If set, | |
9000 | .B bash | |
9001 | allows patterns which match no | |
9002 | files (see | |
9003 | .B Pathname Expansion | |
9004 | above) | |
9005 | to expand to a null string, rather than themselves. | |
9006 | .TP 8 | |
bb70624e JA |
9007 | .B progcomp |
9008 | If set, the programmable completion facilities (see | |
9009 | \fBProgrammable Completion\fP above) are enabled. | |
9010 | This option is enabled by default. | |
9011 | .TP 8 | |
ccc6cda3 | 9012 | .B promptvars |
d3a24ed2 CR |
9013 | If set, prompt strings undergo |
9014 | parameter expansion, command substitution, arithmetic | |
9015 | expansion, and quote removal after being expanded as described in | |
ccc6cda3 JA |
9016 | .SM |
9017 | .B PROMPTING | |
9018 | above. This option is enabled by default. | |
9019 | .TP 8 | |
b72432fd JA |
9020 | .B restricted_shell |
9021 | The shell sets this option if it is started in restricted mode (see | |
9022 | .SM | |
9023 | .B "RESTRICTED SHELL" | |
9024 | below). | |
9025 | The value may not be changed. | |
9026 | This is not reset when the startup files are executed, allowing | |
9027 | the startup files to discover whether or not a shell is restricted. | |
9028 | .TP 8 | |
ccc6cda3 JA |
9029 | .B shift_verbose |
9030 | If set, the | |
9031 | .B shift | |
9032 | builtin prints an error message when the shift count exceeds the | |
9033 | number of positional parameters. | |
9034 | .TP 8 | |
9035 | .B sourcepath | |
9036 | If set, the | |
9037 | \fBsource\fP (\fB.\fP) builtin uses the value of | |
9038 | .SM | |
9039 | .B PATH | |
9040 | to find the directory containing the file supplied as an argument. | |
cce855bc | 9041 | This option is enabled by default. |
bb70624e JA |
9042 | .TP 8 |
9043 | .B xpg_echo | |
9044 | If set, the \fBecho\fP builtin expands backslash-escape sequences | |
9045 | by default. | |
ccc6cda3 | 9046 | .RE |
726f6388 JA |
9047 | .TP |
9048 | \fBsuspend\fP [\fB\-f\fP] | |
9049 | Suspend the execution of this shell until it receives a | |
9050 | .SM | |
9051 | .B SIGCONT | |
09767ff0 | 9052 | signal. A login shell cannot be suspended; the |
726f6388 | 9053 | .B \-f |
09767ff0 CR |
9054 | option can be used to override this and force the suspension. |
9055 | The return status is 0 unless the shell is a login shell and | |
726f6388 JA |
9056 | .B \-f |
9057 | is not supplied, or if job control is not enabled. | |
9058 | .TP | |
726f6388 | 9059 | \fBtest\fP \fIexpr\fP |
7117c2d2 | 9060 | .PD 0 |
726f6388 JA |
9061 | .TP |
9062 | \fB[\fP \fIexpr\fP \fB]\fP | |
ccc6cda3 | 9063 | Return a status of 0 or 1 depending on |
726f6388 JA |
9064 | the evaluation of the conditional expression |
9065 | .IR expr . | |
cce855bc JA |
9066 | Each operator and operand must be a separate argument. |
9067 | Expressions are composed of the primaries described above under | |
9068 | .SM | |
9069 | .BR "CONDITIONAL EXPRESSIONS" . | |
3ffb039a CR |
9070 | \fBtest\fP does not accept any options, nor does it accept and ignore |
9071 | an argument of \fB\-\-\fP as signifying the end of options. | |
cce855bc JA |
9072 | .if t .sp 0.5 |
9073 | .if n .sp 1 | |
9074 | Expressions may be combined using the following operators, listed | |
9075 | in decreasing order of precedence. | |
641d8f00 | 9076 | The evaluation depends on the number of arguments; see below. |
726f6388 JA |
9077 | .RS |
9078 | .PD 0 | |
9079 | .TP | |
726f6388 JA |
9080 | .B ! \fIexpr\fP |
9081 | True if | |
9082 | .I expr | |
9083 | is false. | |
9084 | .TP | |
cce855bc JA |
9085 | .B ( \fIexpr\fP ) |
9086 | Returns the value of \fIexpr\fP. | |
9087 | This may be used to override the normal precedence of operators. | |
9088 | .TP | |
726f6388 JA |
9089 | \fIexpr1\fP \-\fBa\fP \fIexpr2\fP |
9090 | True if both | |
9091 | .I expr1 | |
cce855bc | 9092 | and |
726f6388 JA |
9093 | .I expr2 |
9094 | are true. | |
9095 | .TP | |
9096 | \fIexpr1\fP \-\fBo\fP \fIexpr2\fP | |
9097 | True if either | |
9098 | .I expr1 | |
cce855bc | 9099 | or |
726f6388 JA |
9100 | .I expr2 |
9101 | is true. | |
cce855bc JA |
9102 | .PD |
9103 | .PP | |
9104 | \fBtest\fP and \fB[\fP evaluate conditional | |
9105 | expressions using a set of rules based on the number of arguments. | |
9106 | .if t .sp 0.5 | |
9107 | .if n .sp 1 | |
9108 | .PD 0 | |
726f6388 | 9109 | .TP |
cce855bc JA |
9110 | 0 arguments |
9111 | The expression is false. | |
9112 | .TP | |
9113 | 1 argument | |
9114 | The expression is true if and only if the argument is not null. | |
9115 | .TP | |
9116 | 2 arguments | |
9117 | If the first argument is \fB!\fP, the expression is true if and | |
9118 | only if the second argument is null. | |
9119 | If the first argument is one of the unary conditional operators listed above | |
9120 | under | |
726f6388 | 9121 | .SM |
cce855bc JA |
9122 | .BR "CONDITIONAL EXPRESSIONS" , |
9123 | the expression is true if the unary test is true. | |
9124 | If the first argument is not a valid unary conditional operator, the expression | |
9125 | is false. | |
9126 | .TP | |
9127 | 3 arguments | |
9128 | If the second argument is one of the binary conditional operators listed above | |
9129 | under | |
9130 | .SM | |
9131 | .BR "CONDITIONAL EXPRESSIONS" , | |
9132 | the result of the expression is the result of the binary test using | |
9133 | the first and third arguments as operands. | |
641d8f00 CR |
9134 | The \fB\-a\fP and \fB\-o\fP operators are considered binary operators |
9135 | when there are three arguments. | |
cce855bc JA |
9136 | If the first argument is \fB!\fP, the value is the negation of |
9137 | the two-argument test using the second and third arguments. | |
9138 | If the first argument is exactly \fB(\fP and the third argument is | |
9139 | exactly \fB)\fP, the result is the one-argument test of the second | |
9140 | argument. | |
9141 | Otherwise, the expression is false. | |
cce855bc JA |
9142 | .TP |
9143 | 4 arguments | |
9144 | If the first argument is \fB!\fP, the result is the negation of | |
9145 | the three-argument expression composed of the remaining arguments. | |
9146 | Otherwise, the expression is parsed and evaluated according to | |
9147 | precedence using the rules listed above. | |
9148 | .TP | |
9149 | 5 or more arguments | |
9150 | The expression is parsed and evaluated according to precedence | |
9151 | using the rules listed above. | |
726f6388 | 9152 | .RE |
cce855bc | 9153 | .PD |
726f6388 JA |
9154 | .TP |
9155 | .B times | |
9156 | Print the accumulated user and system times for the shell and | |
9157 | for processes run from the shell. The return status is 0. | |
9158 | .TP | |
61deeb13 | 9159 | \fBtrap\fP [\fB\-lp\fP] [[\fIarg\fP] \fIsigspec\fP ...] |
726f6388 JA |
9160 | The command |
9161 | .I arg | |
9162 | is to be read and executed when the shell receives | |
9163 | signal(s) | |
9164 | .IR sigspec . | |
9165 | If | |
9166 | .I arg | |
61deeb13 | 9167 | is absent (and there is a single \fIsigspec\fP) or |
726f6388 | 9168 | .BR \- , |
61deeb13 CR |
9169 | each specified signal is |
9170 | reset to its original disposition (the value it had | |
d166f048 JA |
9171 | upon entrance to the shell). |
9172 | If | |
726f6388 | 9173 | .I arg |
d166f048 JA |
9174 | is the null string the signal specified by each |
9175 | .I sigspec | |
9176 | is ignored by the shell and by the commands it invokes. | |
ccc6cda3 JA |
9177 | If |
9178 | .I arg | |
bb70624e | 9179 | is not present and |
ccc6cda3 | 9180 | .B \-p |
bb70624e | 9181 | has been supplied, then the trap commands associated with each |
ccc6cda3 | 9182 | .I sigspec |
bb70624e JA |
9183 | are displayed. |
9184 | If no arguments are supplied or if only | |
ccc6cda3 JA |
9185 | .B \-p |
9186 | is given, | |
9187 | .B trap | |
61deeb13 | 9188 | prints the list of commands associated with each signal. |
d3a24ed2 CR |
9189 | The |
9190 | .B \-l | |
9191 | option causes the shell to print a list of signal names and | |
9192 | their corresponding numbers. | |
d166f048 | 9193 | Each |
726f6388 JA |
9194 | .I sigspec |
9195 | is either | |
d166f048 | 9196 | a signal name defined in <\fIsignal.h\fP>, or a signal number. |
9c7f20c7 CR |
9197 | Signal names are case insensitive and the |
9198 | .SM | |
9199 | .B SIG | |
9200 | prefix is optional. | |
4301bca7 CR |
9201 | .if t .sp 0.5 |
9202 | .if n .sp 1 | |
d166f048 | 9203 | If a |
726f6388 JA |
9204 | .I sigspec |
9205 | is | |
9206 | .SM | |
9207 | .B EXIT | |
9208 | (0) the command | |
9209 | .I arg | |
f73dda09 JA |
9210 | is executed on exit from the shell. |
9211 | If a | |
ccc6cda3 JA |
9212 | .I sigspec |
9213 | is | |
9214 | .SM | |
9215 | .BR DEBUG , | |
9216 | the command | |
9217 | .I arg | |
d3a24ed2 CR |
9218 | is executed before every \fIsimple command\fP, \fIfor\fP command, |
9219 | \fIcase\fP command, \fIselect\fP command, every arithmetic \fIfor\fP | |
9220 | command, and before the first command executes in a shell function (see | |
ccc6cda3 JA |
9221 | .SM |
9222 | .B SHELL GRAMMAR | |
9223 | above). | |
40b074c6 | 9224 | Refer to the description of the \fBextdebug\fP option to the |
d3a24ed2 | 9225 | \fBshopt\fP builtin for details of its effect on the \fBDEBUG\fP trap. |
f73dda09 JA |
9226 | If a |
9227 | .I sigspec | |
9228 | is | |
9229 | .SM | |
4301bca7 CR |
9230 | .BR RETURN , |
9231 | the command | |
9232 | .I arg | |
9233 | is executed each time a shell function or a script executed with the | |
9234 | \fB.\fP or \fBsource\fP builtins finishes executing. | |
9235 | .if t .sp 0.5 | |
9236 | .if n .sp 1 | |
9237 | If a | |
9238 | .I sigspec | |
9239 | is | |
9240 | .SM | |
f73dda09 JA |
9241 | .BR ERR , |
9242 | the command | |
9243 | .I arg | |
5e13499c CR |
9244 | is executed whenever a simple command has a non\-zero exit status, |
9245 | subject to the following conditions. | |
f73dda09 JA |
9246 | The |
9247 | .SM | |
d3a24ed2 CR |
9248 | .B ERR |
9249 | trap is not executed if the failed | |
9250 | command is part of the command list immediately following a | |
9251 | .B while | |
f73dda09 | 9252 | or |
d3a24ed2 CR |
9253 | .B until |
9254 | keyword, | |
9255 | part of the test in an | |
f73dda09 | 9256 | .I if |
9d85af6d | 9257 | statement, part of a command executed in a |
f73dda09 JA |
9258 | .B && |
9259 | or | |
9260 | .B \(bv\(bv | |
9261 | list, or if the command's return value is | |
9262 | being inverted via | |
9263 | .BR ! . | |
5e13499c | 9264 | These are the same conditions obeyed by the \fBerrexit\fP option. |
4301bca7 CR |
9265 | .if t .sp 0.5 |
9266 | .if n .sp 1 | |
726f6388 | 9267 | Signals ignored upon entry to the shell cannot be trapped or reset. |
d3ad40de | 9268 | Trapped signals that are not being ignored are reset to their original |
4301bca7 | 9269 | values in a subshell or subshell environment when one is created. |
d166f048 | 9270 | The return status is false if any |
ccc6cda3 JA |
9271 | .I sigspec |
9272 | is invalid; otherwise | |
726f6388 JA |
9273 | .B trap |
9274 | returns true. | |
9275 | .TP | |
7117c2d2 | 9276 | \fBtype\fP [\fB\-aftpP\fP] \fIname\fP [\fIname\fP ...] |
726f6388 JA |
9277 | With no options, |
9278 | indicate how each | |
9279 | .I name | |
9280 | would be interpreted if used as a command name. | |
9281 | If the | |
cce855bc JA |
9282 | .B \-t |
9283 | option is used, | |
726f6388 | 9284 | .B type |
ccc6cda3 | 9285 | prints a string which is one of |
726f6388 JA |
9286 | .IR alias , |
9287 | .IR keyword , | |
9288 | .IR function , | |
9289 | .IR builtin , | |
9290 | or | |
9291 | .I file | |
9292 | if | |
9293 | .I name | |
9294 | is an alias, shell reserved word, function, builtin, or disk file, | |
ccc6cda3 JA |
9295 | respectively. |
9296 | If the | |
9297 | .I name | |
9298 | is not found, then nothing is printed, and an exit status of false | |
9299 | is returned. | |
726f6388 | 9300 | If the |
cce855bc JA |
9301 | .B \-p |
9302 | option is used, | |
726f6388 JA |
9303 | .B type |
9304 | either returns the name of the disk file | |
9305 | that would be executed if | |
9306 | .I name | |
9307 | were specified as a command name, | |
28ef6c31 JA |
9308 | or nothing if |
9309 | .if t \f(CWtype -t name\fP | |
9310 | .if n ``type -t name'' | |
726f6388 JA |
9311 | would not return |
9312 | .IR file . | |
7117c2d2 JA |
9313 | The |
9314 | .B \-P | |
9315 | option forces a | |
9316 | .SM | |
9317 | .B PATH | |
9318 | search for each \fIname\fP, even if | |
9319 | .if t \f(CWtype -t name\fP | |
9320 | .if n ``type -t name'' | |
9321 | would not return | |
9322 | .IR file . | |
726f6388 | 9323 | If a command is hashed, |
cce855bc | 9324 | .B \-p |
7117c2d2 JA |
9325 | and |
9326 | .B \-P | |
9327 | print the hashed value, not necessarily the file that appears | |
726f6388 JA |
9328 | first in |
9329 | .SM | |
9330 | .BR PATH . | |
9331 | If the | |
cce855bc JA |
9332 | .B \-a |
9333 | option is used, | |
726f6388 JA |
9334 | .B type |
9335 | prints all of the places that contain | |
9336 | an executable named | |
9337 | .IR name . | |
9338 | This includes aliases and functions, | |
9339 | if and only if the | |
cce855bc JA |
9340 | .B \-p |
9341 | option is not also used. | |
726f6388 JA |
9342 | The table of hashed commands is not consulted |
9343 | when using | |
cce855bc | 9344 | .BR \-a . |
7117c2d2 JA |
9345 | The |
9346 | .B \-f | |
9347 | option suppresses shell function lookup, as with the \fBcommand\fP builtin. | |
726f6388 | 9348 | .B type |
6a8fd0ed CR |
9349 | returns true if all of the arguments are found, false if |
9350 | any are not found. | |
726f6388 | 9351 | .TP |
6fbe7620 | 9352 | \fBulimit\fP [\fB\-HSTabcdefilmnpqrstuvx\fP [\fIlimit\fP]] |
ccc6cda3 | 9353 | Provides control over the resources available to the shell and to |
f73dda09 | 9354 | processes started by it, on systems that allow such control. |
ccc6cda3 | 9355 | The \fB\-H\fP and \fB\-S\fP options specify that the hard or soft limit is |
79e6c7dc CR |
9356 | set for the given resource. |
9357 | A hard limit cannot be increased by a non-root user once it is set; | |
9358 | a soft limit may be increased up to the value of the hard limit. | |
ccc6cda3 JA |
9359 | If neither \fB\-H\fP nor \fB\-S\fP is specified, both the soft and hard |
9360 | limits are set. | |
f73dda09 JA |
9361 | The value of |
9362 | .I limit | |
9363 | can be a number in the unit specified for the resource | |
9364 | or one of the special values | |
9365 | .BR hard , | |
9366 | .BR soft , | |
9367 | or | |
9368 | .BR unlimited , | |
9369 | which stand for the current hard limit, the current soft limit, and | |
9370 | no limit, respectively. | |
ccc6cda3 | 9371 | If |
726f6388 JA |
9372 | .I limit |
9373 | is omitted, the current value of the soft limit of the resource is | |
ccc6cda3 JA |
9374 | printed, unless the \fB\-H\fP option is given. When more than one |
9375 | resource is specified, the limit name and unit are printed before the value. | |
726f6388 JA |
9376 | Other options are interpreted as follows: |
9377 | .RS | |
9378 | .PD 0 | |
9379 | .TP | |
9380 | .B \-a | |
ccc6cda3 | 9381 | All current limits are reported |
726f6388 | 9382 | .TP |
6fbe7620 CR |
9383 | .B \-b |
9384 | The maximum socket buffer size | |
9385 | .TP | |
726f6388 | 9386 | .B \-c |
ccc6cda3 | 9387 | The maximum size of core files created |
726f6388 JA |
9388 | .TP |
9389 | .B \-d | |
ccc6cda3 | 9390 | The maximum size of a process's data segment |
726f6388 | 9391 | .TP |
dc8fbaf9 CR |
9392 | .B \-e |
9393 | The maximum scheduling priority ("nice") | |
9394 | .TP | |
726f6388 | 9395 | .B \-f |
d3ad40de | 9396 | The maximum size of files written by the shell and its children |
726f6388 | 9397 | .TP |
af12dacd CR |
9398 | .B \-i |
9399 | The maximum number of pending signals | |
9400 | .TP | |
ccc6cda3 JA |
9401 | .B \-l |
9402 | The maximum size that may be locked into memory | |
726f6388 | 9403 | .TP |
ccc6cda3 | 9404 | .B \-m |
db31fb26 | 9405 | The maximum resident set size (many systems do not honor this limit) |
726f6388 | 9406 | .TP |
ccc6cda3 JA |
9407 | .B \-n |
9408 | The maximum number of open file descriptors (most systems do not | |
9409 | allow this value to be set) | |
726f6388 JA |
9410 | .TP |
9411 | .B \-p | |
ccc6cda3 | 9412 | The pipe size in 512-byte blocks (this may not be set) |
726f6388 | 9413 | .TP |
af12dacd CR |
9414 | .B \-q |
9415 | The maximum number of bytes in POSIX message queues | |
9416 | .TP | |
dc8fbaf9 CR |
9417 | .B \-r |
9418 | The maximum real-time scheduling priority | |
9419 | .TP | |
ccc6cda3 JA |
9420 | .B \-s |
9421 | The maximum stack size | |
9422 | .TP | |
9423 | .B \-t | |
9424 | The maximum amount of cpu time in seconds | |
726f6388 JA |
9425 | .TP |
9426 | .B \-u | |
ccc6cda3 | 9427 | The maximum number of processes available to a single user |
726f6388 JA |
9428 | .TP |
9429 | .B \-v | |
68dfe178 CR |
9430 | The maximum amount of virtual memory available to the shell and, on |
9431 | some systems, to its children | |
af12dacd CR |
9432 | .TP |
9433 | .B \-x | |
9434 | The maximum number of file locks | |
6fbe7620 CR |
9435 | .TP |
9436 | .B \-T | |
9437 | The maximum number of threads | |
726f6388 JA |
9438 | .PD |
9439 | .PP | |
ccc6cda3 | 9440 | If |
726f6388 JA |
9441 | .I limit |
9442 | is given, it is the new value of the specified resource (the | |
9443 | .B \-a | |
9444 | option is display only). | |
9445 | If no option is given, then | |
9446 | .B \-f | |
9447 | is assumed. Values are in 1024-byte increments, except for | |
9448 | .BR \-t , | |
9449 | which is in seconds, | |
9450 | .BR \-p , | |
9451 | which is in units of 512-byte blocks, | |
9452 | and | |
6fbe7620 CR |
9453 | .BR \-T , |
9454 | .BR \-b , | |
9455 | .BR \-n , | |
726f6388 JA |
9456 | and |
9457 | .BR \-u , | |
f73dda09 JA |
9458 | which are unscaled values. |
9459 | The return status is 0 unless an invalid option or argument is supplied, | |
9460 | or an error occurs while setting a new limit. | |
726f6388 JA |
9461 | .RE |
9462 | .TP | |
cce855bc | 9463 | \fBumask\fP [\fB\-p\fP] [\fB\-S\fP] [\fImode\fP] |
726f6388 JA |
9464 | The user file-creation mask is set to |
9465 | .IR mode . | |
9466 | If | |
9467 | .I mode | |
9468 | begins with a digit, it | |
9469 | is interpreted as an octal number; otherwise | |
9470 | it is interpreted as a symbolic mode mask similar | |
9471 | to that accepted by | |
9472 | .IR chmod (1). | |
9473 | If | |
9474 | .I mode | |
bb70624e | 9475 | is omitted, the current value of the mask is printed. |
ccc6cda3 | 9476 | The |
726f6388 JA |
9477 | .B \-S |
9478 | option causes the mask to be printed in symbolic form; the | |
9479 | default output is an octal number. | |
cce855bc JA |
9480 | If the |
9481 | .B \-p | |
9482 | option is supplied, and | |
9483 | .I mode | |
9484 | is omitted, the output is in a form that may be reused as input. | |
ccc6cda3 | 9485 | The return status is 0 if the mode was successfully changed or if |
726f6388 JA |
9486 | no \fImode\fP argument was supplied, and false otherwise. |
9487 | .TP | |
9488 | \fBunalias\fP [\-\fBa\fP] [\fIname\fP ...] | |
bb70624e | 9489 | Remove each \fIname\fP from the list of defined aliases. If |
726f6388 JA |
9490 | .B \-a |
9491 | is supplied, all alias definitions are removed. The return | |
9492 | value is true unless a supplied | |
9493 | .I name | |
9494 | is not a defined alias. | |
9495 | .TP | |
9496 | \fBunset\fP [\-\fBfv\fP] [\fIname\fP ...] | |
9497 | For each | |
9498 | .IR name , | |
ccc6cda3 JA |
9499 | remove the corresponding variable or function. |
9500 | If no options are supplied, or the | |
9501 | .B \-v | |
9502 | option is given, each | |
9503 | .I name | |
9504 | refers to a shell variable. | |
9505 | Read-only variables may not be unset. | |
9506 | If | |
726f6388 | 9507 | .B \-f |
f75912ae | 9508 | is specified, each |
ccc6cda3 JA |
9509 | .I name |
9510 | refers to a shell function, and the function definition | |
9511 | is removed. | |
9512 | Each unset variable or function is removed from the environment | |
9513 | passed to subsequent commands. | |
9514 | If any of | |
726f6388 | 9515 | .SM |
984a1947 CR |
9516 | .BR COMP_WORDBREAKS , |
9517 | .SM | |
726f6388 JA |
9518 | .BR RANDOM , |
9519 | .SM | |
9520 | .BR SECONDS , | |
9521 | .SM | |
9522 | .BR LINENO , | |
ccc6cda3 JA |
9523 | .SM |
9524 | .BR HISTCMD , | |
bb70624e JA |
9525 | .SM |
9526 | .BR FUNCNAME , | |
9527 | .SM | |
9528 | .BR GROUPS , | |
726f6388 JA |
9529 | or |
9530 | .SM | |
ccc6cda3 | 9531 | .B DIRSTACK |
726f6388 JA |
9532 | are unset, they lose their special properties, even if they are |
9533 | subsequently reset. The exit status is true unless a | |
9534 | .I name | |
d3a24ed2 | 9535 | is readonly. |
726f6388 | 9536 | .TP |
d90269dd CR |
9537 | \fBwait\fP [\fIn ...\fP] |
9538 | Wait for each specified process and return its termination status. | |
9539 | Each | |
726f6388 JA |
9540 | .I n |
9541 | may be a process | |
9542 | ID or a job specification; if a job spec is given, all processes | |
9543 | in that job's pipeline are waited for. If | |
9544 | .I n | |
9545 | is not given, all currently active child processes | |
9546 | are waited for, and the return status is zero. If | |
9547 | .I n | |
ccc6cda3 | 9548 | specifies a non-existent process or job, the return status is |
726f6388 JA |
9549 | 127. Otherwise, the return status is the exit status of the last |
9550 | process or job waited for. | |
9551 | .\" bash_builtins | |
9552 | .if \n(zZ=1 .ig zZ | |
ccc6cda3 | 9553 | .SH "RESTRICTED SHELL" |
bb70624e JA |
9554 | .\" rbash.1 |
9555 | .zY | |
726f6388 | 9556 | .PP |
ccc6cda3 | 9557 | If |
726f6388 | 9558 | .B bash |
ccc6cda3 JA |
9559 | is started with the name |
9560 | .BR rbash , | |
9561 | or the | |
9562 | .B \-r | |
9563 | option is supplied at invocation, | |
9564 | the shell becomes restricted. | |
9565 | A restricted shell is used to | |
9566 | set up an environment more controlled than the standard shell. | |
9567 | It behaves identically to | |
9568 | .B bash | |
cce855bc | 9569 | with the exception that the following are disallowed or not performed: |
ccc6cda3 JA |
9570 | .IP \(bu |
9571 | changing directories with \fBcd\fP | |
9572 | .IP \(bu | |
9573 | setting or unsetting the values of | |
984a1947 | 9574 | .SM |
b72432fd | 9575 | .BR SHELL , |
984a1947 | 9576 | .SM |
b72432fd | 9577 | .BR PATH , |
984a1947 | 9578 | .SM |
b72432fd | 9579 | .BR ENV , |
ccc6cda3 | 9580 | or |
984a1947 | 9581 | .SM |
b72432fd | 9582 | .B BASH_ENV |
ccc6cda3 JA |
9583 | .IP \(bu |
9584 | specifying command names containing | |
9585 | .B / | |
9586 | .IP \(bu | |
9587 | specifying a file name containing a | |
9588 | .B / | |
9589 | as an argument to the | |
9590 | .B . | |
9591 | builtin command | |
9592 | .IP \(bu | |
bb70624e JA |
9593 | Specifying a filename containing a slash as an argument to the |
9594 | .B \-p | |
9595 | option to the | |
9596 | .B hash | |
9597 | builtin command | |
9598 | .IP \(bu | |
ccc6cda3 JA |
9599 | importing function definitions from the shell environment at startup |
9600 | .IP \(bu | |
984a1947 CR |
9601 | parsing the value of |
9602 | .SM | |
9603 | .B SHELLOPTS | |
9604 | from the shell environment at startup | |
cce855bc | 9605 | .IP \(bu |
ccc6cda3 JA |
9606 | redirecting output using the >, >|, <>, >&, &>, and >> redirection operators |
9607 | .IP \(bu | |
9608 | using the | |
9609 | .B exec | |
9610 | builtin command to replace the shell with another command | |
9611 | .IP \(bu | |
9612 | adding or deleting builtin commands with the | |
9613 | .B \-f | |
726f6388 | 9614 | and |
ccc6cda3 JA |
9615 | .B \-d |
9616 | options to the | |
9617 | .B enable | |
9618 | builtin command | |
9619 | .IP \(bu | |
7117c2d2 JA |
9620 | Using the \fBenable\fP builtin command to enable disabled shell builtins |
9621 | .IP \(bu | |
ccc6cda3 JA |
9622 | specifying the |
9623 | .B \-p | |
9624 | option to the | |
9625 | .B command | |
9626 | builtin command | |
9627 | .IP \(bu | |
9628 | turning off restricted mode with | |
cce855bc | 9629 | \fBset +r\fP or \fBset +o restricted\fP. |
726f6388 | 9630 | .PP |
ccc6cda3 JA |
9631 | These restrictions are enforced after any startup files are read. |
9632 | .PP | |
61deeb13 CR |
9633 | .ie \n(zY=1 When a command that is found to be a shell script is executed, |
9634 | .el \{ When a command that is found to be a shell script is executed | |
9635 | (see | |
ccc6cda3 JA |
9636 | .SM |
9637 | .B "COMMAND EXECUTION" | |
9638 | above), | |
61deeb13 | 9639 | \} |
ccc6cda3 JA |
9640 | .B rbash |
9641 | turns off any restrictions in the shell spawned to execute the | |
9642 | script. | |
bb70624e JA |
9643 | .\" end of rbash.1 |
9644 | .if \n(zY=1 .ig zY | |
726f6388 JA |
9645 | .SH "SEE ALSO" |
9646 | .PD 0 | |
9647 | .TP | |
bb70624e | 9648 | \fIBash Reference Manual\fP, Brian Fox and Chet Ramey |
726f6388 JA |
9649 | .TP |
9650 | \fIThe Gnu Readline Library\fP, Brian Fox and Chet Ramey | |
9651 | .TP | |
9652 | \fIThe Gnu History Library\fP, Brian Fox and Chet Ramey | |
9653 | .TP | |
726f6388 JA |
9654 | \fIPortable Operating System Interface (POSIX) Part 2: Shell and Utilities\fP, IEEE |
9655 | .TP | |
9656 | \fIsh\fP(1), \fIksh\fP(1), \fIcsh\fP(1) | |
9657 | .TP | |
9658 | \fIemacs\fP(1), \fIvi\fP(1) | |
9659 | .TP | |
9660 | \fIreadline\fP(3) | |
9661 | .PD | |
9662 | .SH FILES | |
9663 | .PD 0 | |
9664 | .TP | |
9665 | .FN /bin/bash | |
9666 | The \fBbash\fP executable | |
9667 | .TP | |
9668 | .FN /etc/profile | |
9669 | The systemwide initialization file, executed for login shells | |
9670 | .TP | |
9671 | .FN ~/.bash_profile | |
9672 | The personal initialization file, executed for login shells | |
9673 | .TP | |
9674 | .FN ~/.bashrc | |
9675 | The individual per-interactive-shell startup file | |
9676 | .TP | |
b72432fd JA |
9677 | .FN ~/.bash_logout |
9678 | The individual login shell cleanup file, executed when a login shell exits | |
9679 | .TP | |
726f6388 JA |
9680 | .FN ~/.inputrc |
9681 | Individual \fIreadline\fP initialization file | |
9682 | .PD | |
9683 | .SH AUTHORS | |
ccc6cda3 | 9684 | Brian Fox, Free Software Foundation |
726f6388 | 9685 | .br |
bb70624e | 9686 | bfox@gnu.org |
726f6388 JA |
9687 | .PP |
9688 | Chet Ramey, Case Western Reserve University | |
9689 | .br | |
db31fb26 | 9690 | chet.ramey@case.edu |
726f6388 JA |
9691 | .SH BUG REPORTS |
9692 | If you find a bug in | |
9693 | .B bash, | |
9694 | you should report it. But first, you should | |
9695 | make sure that it really is a bug, and that it appears in the latest | |
9696 | version of | |
d3a24ed2 CR |
9697 | .BR bash . |
9698 | The latest version is always available from | |
9c7f20c7 | 9699 | \fIftp://ftp.gnu.org/pub/gnu/bash/\fP. |
726f6388 JA |
9700 | .PP |
9701 | Once you have determined that a bug actually exists, use the | |
9702 | .I bashbug | |
9703 | command to submit a bug report. | |
d166f048 | 9704 | If you have a fix, you are encouraged to mail that as well! |
726f6388 | 9705 | Suggestions and `philosophical' bug reports may be mailed |
cce855bc | 9706 | to \fIbug-bash@gnu.org\fP or posted to the Usenet |
726f6388 JA |
9707 | newsgroup |
9708 | .BR gnu.bash.bug . | |
9709 | .PP | |
9710 | ALL bug reports should include: | |
9711 | .PP | |
9712 | .PD 0 | |
9713 | .TP 20 | |
9714 | The version number of \fBbash\fR | |
9715 | .TP | |
9716 | The hardware and operating system | |
9717 | .TP | |
9718 | The compiler used to compile | |
9719 | .TP | |
9720 | A description of the bug behaviour | |
9721 | .TP | |
9722 | A short script or `recipe' which exercises the bug | |
9723 | .PD | |
9724 | .PP | |
9725 | .I bashbug | |
9726 | inserts the first three items automatically into the template | |
9727 | it provides for filing a bug report. | |
9728 | .PP | |
9729 | Comments and bug reports concerning | |
9730 | this manual page should be directed to | |
e225d5a9 | 9731 | .IR chet@po.cwru.edu . |
726f6388 JA |
9732 | .SH BUGS |
9733 | .PP | |
9734 | It's too big and too slow. | |
9735 | .PP | |
9736 | There are some subtle differences between | |
9737 | .B bash | |
9738 | and traditional versions of | |
9739 | .BR sh , | |
9740 | mostly because of the | |
9741 | .SM | |
9742 | .B POSIX | |
9743 | specification. | |
9744 | .PP | |
9745 | Aliases are confusing in some uses. | |
ccc6cda3 JA |
9746 | .PP |
9747 | Shell builtin commands and functions are not stoppable/restartable. | |
9748 | .PP | |
9749 | Compound commands and command sequences of the form `a ; b ; c' | |
9750 | are not handled gracefully when process suspension is attempted. | |
9751 | When a process is stopped, the shell immediately executes the next | |
9752 | command in the sequence. | |
9753 | It suffices to place the sequence of commands between | |
9754 | parentheses to force it into a subshell, which may be stopped as | |
9755 | a unit. | |
9756 | .PP | |
ccc6cda3 | 9757 | Array variables may not (yet) be exported. |
09767ff0 CR |
9758 | .PP |
9759 | There may be only one active coprocess at a time. | |
726f6388 | 9760 | .zZ |
bb70624e | 9761 | .zY |