]>
Commit | Line | Data |
---|---|---|
6e70dbff | 1 | \" |
726f6388 JA |
2 | .\" MAN PAGE COMMENTS to |
3 | .\" | |
4 | .\" Chet Ramey | |
5 | .\" Information Network Services | |
6 | .\" Case Western Reserve University | |
e225d5a9 | 7 | .\" chet@po.cwru.edu |
726f6388 | 8 | .\" |
dc8fbaf9 | 9 | .\" Last Change: Wed Dec 28 19:58:45 EST 2005 |
726f6388 JA |
10 | .\" |
11 | .\" bash_builtins, strip all but Built-Ins section | |
12 | .if \n(zZ=1 .ig zZ | |
bb70624e | 13 | .if \n(zY=1 .ig zY |
dc8fbaf9 | 14 | .TH BASH 1 "2005 Dec 28" "GNU Bash-3.1" |
726f6388 JA |
15 | .\" |
16 | .\" There's some problem with having a `@' | |
17 | .\" in a tagged paragraph with the BSD man macros. | |
18 | .\" It has to do with `@' appearing in the }1 macro. | |
19 | .\" This is a problem on 4.3 BSD and Ultrix, but Sun | |
20 | .\" appears to have fixed it. | |
21 | .\" If you're seeing the characters | |
22 | .\" `@u-3p' appearing before the lines reading | |
23 | .\" `possible-hostname-completions | |
24 | .\" and `complete-hostname' down in READLINE, | |
25 | .\" then uncomment this redefinition. | |
26 | .\" | |
27 | .de }1 | |
28 | .ds ]X \&\\*(]B\\ | |
29 | .nr )E 0 | |
30 | .if !"\\$1"" .nr )I \\$1n | |
31 | .}f | |
32 | .ll \\n(LLu | |
33 | .in \\n()Ru+\\n(INu+\\n()Iu | |
34 | .ti \\n(INu | |
35 | .ie !\\n()Iu+\\n()Ru-\w\a\\*(]X\au-3p \{\\*(]X | |
36 | .br\} | |
37 | .el \\*(]X\h\a|\\n()Iu+\\n()Ru\a\c | |
38 | .}f | |
39 | .. | |
40 | .\" | |
41 | .\" File Name macro. This used to be `.PN', for Path Name, | |
42 | .\" but Sun doesn't seem to like that very much. | |
43 | .\" | |
44 | .de FN | |
45 | \fI\|\\$1\|\fP | |
46 | .. | |
47 | .SH NAME | |
ccc6cda3 | 48 | bash \- GNU Bourne-Again SHell |
726f6388 JA |
49 | .SH SYNOPSIS |
50 | .B bash | |
51 | [options] | |
52 | [file] | |
53 | .SH COPYRIGHT | |
6e70dbff CR |
54 | .if n Bash is Copyright (C) 1989-2005 by the Free Software Foundation, Inc. |
55 | .if t Bash is Copyright \(co 1989-2005 by the Free Software Foundation, Inc. | |
726f6388 JA |
56 | .SH DESCRIPTION |
57 | .B Bash | |
ccc6cda3 | 58 | is an \fBsh\fR-compatible command language interpreter that |
726f6388 JA |
59 | executes commands read from the standard input or from a file. |
60 | .B Bash | |
61 | also incorporates useful features from the \fIKorn\fP and \fIC\fP | |
62 | shells (\fBksh\fP and \fBcsh\fP). | |
63 | .PP | |
64 | .B Bash | |
cce855bc | 65 | is intended to be a conformant implementation of the IEEE |
ccc6cda3 | 66 | POSIX Shell and Tools specification (IEEE Working Group 1003\.2). |
7790f917 CR |
67 | .B Bash |
68 | can be configured to be POSIX-conformant by default. | |
726f6388 | 69 | .SH OPTIONS |
ccc6cda3 | 70 | In addition to the single-character shell options documented in the |
726f6388 | 71 | description of the \fBset\fR builtin command, \fBbash\fR |
cce855bc | 72 | interprets the following options when it is invoked: |
726f6388 JA |
73 | .PP |
74 | .PD 0 | |
75 | .TP 10 | |
76 | .BI \-c "\| string\^" | |
ccc6cda3 | 77 | If the |
726f6388 | 78 | .B \-c |
cce855bc | 79 | option is present, then commands are read from |
726f6388 JA |
80 | .IR string . |
81 | If there are arguments after the | |
82 | .IR string , | |
83 | they are assigned to the positional parameters, starting with | |
84 | .BR $0 . | |
85 | .TP | |
7117c2d2 JA |
86 | .B \-i |
87 | If the | |
88 | .B \-i | |
89 | option is present, the shell is | |
90 | .IR interactive . | |
91 | .TP | |
92 | .B \-l | |
93 | Make | |
94 | .B bash | |
95 | act as if it had been invoked as a login shell (see | |
96 | .SM | |
97 | .B INVOCATION | |
98 | below). | |
99 | .TP | |
ccc6cda3 JA |
100 | .B \-r |
101 | If the | |
102 | .B \-r | |
cce855bc | 103 | option is present, the shell becomes |
ccc6cda3 JA |
104 | .I restricted |
105 | (see | |
106 | .SM | |
107 | .B "RESTRICTED SHELL" | |
108 | below). | |
109 | .TP | |
726f6388 JA |
110 | .B \-s |
111 | If the | |
112 | .B \-s | |
cce855bc | 113 | option is present, or if no arguments remain after option |
726f6388 JA |
114 | processing, then commands are read from the standard input. |
115 | This option allows the positional parameters to be set | |
116 | when invoking an interactive shell. | |
117 | .TP | |
ccc6cda3 JA |
118 | .B \-D |
119 | A list of all double-quoted strings preceded by \fB$\fP | |
22e63b05 | 120 | is printed on the standard output. |
ccc6cda3 JA |
121 | These are the strings that |
122 | are subject to language translation when the current locale | |
28ef6c31 | 123 | is not \fBC\fP or \fBPOSIX\fP. |
ccc6cda3 JA |
124 | This implies the \fB\-n\fP option; no commands will be executed. |
125 | .TP | |
f73dda09 JA |
126 | .B [\-+]O [\fIshopt_option\fP] |
127 | \fIshopt_option\fP is one of the shell options accepted by the | |
128 | \fBshopt\fP builtin (see | |
129 | .SM | |
130 | .B SHELL BUILTIN COMMANDS | |
131 | below). | |
132 | If \fIshopt_option\fP is present, \fB\-O\fP sets the value of that option; | |
133 | \fB+O\fP unsets it. | |
134 | If \fIshopt_option\fP is not supplied, the names and values of the shell | |
135 | options accepted by \fBshopt\fP are printed on the standard output. | |
136 | If the invocation option is \fB+O\fP, the output is displayed in a format | |
137 | that may be reused as input. | |
138 | .TP | |
ccc6cda3 JA |
139 | .B \-\- |
140 | A | |
141 | .B \-\- | |
726f6388 JA |
142 | signals the end of options and disables further option processing. |
143 | Any arguments after the | |
726f6388 | 144 | .B \-\- |
ccc6cda3 JA |
145 | are treated as filenames and arguments. An argument of |
146 | .B \- | |
147 | is equivalent to \fB\-\-\fP. | |
726f6388 JA |
148 | .PD |
149 | .PP | |
150 | .B Bash | |
ccc6cda3 JA |
151 | also interprets a number of multi-character options. |
152 | These options must appear on the command line before the | |
7117c2d2 | 153 | single-character options to be recognized. |
726f6388 JA |
154 | .PP |
155 | .PD 0 | |
726f6388 | 156 | .TP |
d3a24ed2 CR |
157 | .B \-\-debugger |
158 | Arrange for the debugger profile to be executed before the shell | |
2206f89a CR |
159 | starts. |
160 | Turns on extended debugging mode (see the description of the | |
d3a24ed2 CR |
161 | .B extdebug |
162 | option to the | |
163 | .B shopt | |
2206f89a CR |
164 | builtin below) |
165 | and shell function tracing (see the description of the | |
d3a24ed2 CR |
166 | \fB\-o functrace\fP option to the |
167 | .B set | |
168 | builtin below). | |
169 | .TP | |
cce855bc JA |
170 | .B \-\-dump\-po\-strings |
171 | Equivalent to \fB\-D\fP, but the output is in the GNU \fIgettext\fP | |
172 | \fBpo\fP (portable object) file format. | |
173 | .TP | |
ccc6cda3 JA |
174 | .B \-\-dump\-strings |
175 | Equivalent to \fB\-D\fP. | |
176 | .TP | |
177 | .B \-\-help | |
178 | Display a usage message on standard output and exit successfully. | |
179 | .TP | |
28ef6c31 | 180 | \fB\-\-init\-file\fP \fIfile\fP |
7117c2d2 | 181 | .PD 0 |
28ef6c31 JA |
182 | .TP |
183 | \fB\-\-rcfile\fP \fIfile\fP | |
184 | .PD | |
185 | Execute commands from | |
186 | .I file | |
187 | instead of the standard personal initialization file | |
188 | .I ~/.bashrc | |
189 | if the shell is interactive (see | |
190 | .SM | |
191 | .B INVOCATION | |
192 | below). | |
193 | .TP | |
ccc6cda3 | 194 | .B \-\-login |
7117c2d2 | 195 | Equivalent to \fB\-l\fP. |
ccc6cda3 JA |
196 | .TP |
197 | .B \-\-noediting | |
198 | Do not use the GNU | |
199 | .B readline | |
bb70624e | 200 | library to read command lines when the shell is interactive. |
ccc6cda3 JA |
201 | .TP |
202 | .B \-\-noprofile | |
203 | Do not read either the system-wide startup file | |
726f6388 JA |
204 | .FN /etc/profile |
205 | or any of the personal initialization files | |
206 | .IR ~/.bash_profile , | |
207 | .IR ~/.bash_login , | |
208 | or | |
209 | .IR ~/.profile . | |
210 | By default, | |
211 | .B bash | |
ccc6cda3 | 212 | reads these files when it is invoked as a login shell (see |
726f6388 JA |
213 | .SM |
214 | .B INVOCATION | |
215 | below). | |
216 | .TP | |
ccc6cda3 JA |
217 | .B \-\-norc |
218 | Do not read and execute the personal initialization file | |
219 | .I ~/.bashrc | |
220 | if the shell is interactive. | |
221 | This option is on by default if the shell is invoked as | |
222 | .BR sh . | |
223 | .TP | |
224 | .B \-\-posix | |
225 | Change the behavior of \fBbash\fP where the default operation differs | |
28ef6c31 | 226 | from the POSIX 1003.2 standard to match the standard (\fIposix mode\fP). |
726f6388 | 227 | .TP |
ccc6cda3 JA |
228 | .B \-\-restricted |
229 | The shell becomes restricted (see | |
230 | .SM | |
231 | .B "RESTRICTED SHELL" | |
726f6388 JA |
232 | below). |
233 | .TP | |
ccc6cda3 JA |
234 | .B \-\-verbose |
235 | Equivalent to \fB\-v\fP. | |
726f6388 | 236 | .TP |
ccc6cda3 JA |
237 | .B \-\-version |
238 | Show version information for this instance of | |
239 | .B bash | |
240 | on the standard output and exit successfully. | |
726f6388 JA |
241 | .PD |
242 | .SH ARGUMENTS | |
243 | If arguments remain after option processing, and neither the | |
244 | .B \-c | |
245 | nor the | |
246 | .B \-s | |
247 | option has been supplied, the first argument is assumed to | |
ccc6cda3 JA |
248 | be the name of a file containing shell commands. |
249 | If | |
726f6388 JA |
250 | .B bash |
251 | is invoked in this fashion, | |
252 | .B $0 | |
253 | is set to the name of the file, and the positional parameters | |
254 | are set to the remaining arguments. | |
255 | .B Bash | |
256 | reads and executes commands from this file, then exits. | |
ccc6cda3 JA |
257 | \fBBash\fP's exit status is the exit status of the last command |
258 | executed in the script. | |
259 | If no commands are executed, the exit status is 0. | |
f73dda09 JA |
260 | An attempt is first made to open the file in the current directory, and, |
261 | if no file is found, then the shell searches the directories in | |
262 | .SM | |
263 | .B PATH | |
264 | for the script. | |
ccc6cda3 JA |
265 | .SH INVOCATION |
266 | A \fIlogin shell\fP is one whose first character of argument zero is a | |
267 | .BR \- , | |
268 | or one started with the | |
269 | .B \-\-login | |
270 | option. | |
271 | .PP | |
bb70624e JA |
272 | An \fIinteractive\fP shell is one started without non-option arguments |
273 | and without the | |
274 | .B \-c | |
275 | option | |
da5b17cd | 276 | whose standard input and error are |
ccc6cda3 JA |
277 | both connected to terminals (as determined by |
278 | .IR isatty (3)), | |
279 | or one started with the | |
280 | .B \-i | |
281 | option. | |
282 | .SM | |
283 | .B PS1 | |
284 | is set and | |
285 | .B $\- | |
286 | includes | |
287 | .B i | |
288 | if | |
289 | .B bash | |
290 | is interactive, | |
291 | allowing a shell script or a startup file to test this state. | |
292 | .PP | |
293 | The following paragraphs describe how | |
294 | .B bash | |
295 | executes its startup files. | |
296 | If any of the files exist but cannot be read, | |
297 | .B bash | |
298 | reports an error. | |
299 | Tildes are expanded in file names as described below under | |
300 | .B "Tilde Expansion" | |
301 | in the | |
302 | .SM | |
303 | .B EXPANSION | |
304 | section. | |
305 | .PP | |
306 | When | |
307 | .B bash | |
b72432fd JA |
308 | is invoked as an interactive login shell, or as a non-interactive shell |
309 | with the \fB\-\-login\fP option, it first reads and | |
d166f048 JA |
310 | executes commands from the file \fI/etc/profile\fP, if that |
311 | file exists. | |
ccc6cda3 JA |
312 | After reading that file, it looks for \fI~/.bash_profile\fP, |
313 | \fI~/.bash_login\fP, and \fI~/.profile\fP, in that order, and reads | |
314 | and executes commands from the first one that exists and is readable. | |
315 | The | |
316 | .B \-\-noprofile | |
317 | option may be used when the shell is started to inhibit this behavior. | |
318 | .PP | |
319 | When a login shell exits, | |
320 | .B bash | |
321 | reads and executes commands from the file \fI~/.bash_logout\fP, if it | |
322 | exists. | |
323 | .PP | |
324 | When an interactive shell that is not a login shell is started, | |
325 | .B bash | |
326 | reads and executes commands from \fI~/.bashrc\fP, if that file exists. | |
327 | This may be inhibited by using the | |
328 | .B \-\-norc | |
329 | option. | |
330 | The \fB\-\-rcfile\fP \fIfile\fP option will force | |
331 | .B bash | |
332 | to read and execute commands from \fIfile\fP instead of \fI~/.bashrc\fP. | |
333 | .PP | |
334 | When | |
335 | .B bash | |
336 | is started non-interactively, to run a shell script, for example, it | |
337 | looks for the variable | |
338 | .SM | |
339 | .B BASH_ENV | |
340 | in the environment, expands its value if it appears there, and uses the | |
341 | expanded value as the name of a file to read and execute. | |
342 | .B Bash | |
343 | behaves as if the following command were executed: | |
344 | .sp .5 | |
345 | .RS | |
28ef6c31 JA |
346 | .if t \f(CWif [ \-n "$BASH_ENV" ]; then . "$BASH_ENV"; fi\fP |
347 | .if n if [ \-n "$BASH_ENV" ]; then . "$BASH_ENV"; fi | |
ccc6cda3 JA |
348 | .RE |
349 | .sp .5 | |
350 | but the value of the | |
351 | .SM | |
352 | .B PATH | |
353 | variable is not used to search for the file name. | |
354 | .PP | |
355 | If | |
356 | .B bash | |
357 | is invoked with the name | |
358 | .BR sh , | |
359 | it tries to mimic the startup behavior of historical versions of | |
360 | .B sh | |
361 | as closely as possible, | |
362 | while conforming to the POSIX standard as well. | |
b72432fd JA |
363 | When invoked as an interactive login shell, or a non-interactive |
364 | shell with the \fB\-\-login\fP option, it first attempts to | |
cce855bc | 365 | read and execute commands from |
ccc6cda3 JA |
366 | .I /etc/profile |
367 | and | |
368 | .IR ~/.profile , | |
369 | in that order. | |
370 | The | |
371 | .B \-\-noprofile | |
372 | option may be used to inhibit this behavior. | |
373 | When invoked as an interactive shell with the name | |
374 | .BR sh , | |
375 | .B bash | |
376 | looks for the variable | |
377 | .SM | |
378 | .BR ENV , | |
379 | expands its value if it is defined, and uses the | |
380 | expanded value as the name of a file to read and execute. | |
381 | Since a shell invoked as | |
382 | .B sh | |
383 | does not attempt to read and execute commands from any other startup | |
384 | files, the | |
385 | .B \-\-rcfile | |
386 | option has no effect. | |
387 | A non-interactive shell invoked with the name | |
388 | .B sh | |
b72432fd | 389 | does not attempt to read any other startup files. |
ccc6cda3 JA |
390 | When invoked as |
391 | .BR sh , | |
392 | .B bash | |
393 | enters | |
394 | .I posix | |
395 | mode after the startup files are read. | |
396 | .PP | |
397 | When | |
398 | .B bash | |
399 | is started in | |
400 | .I posix | |
401 | mode, as with the | |
402 | .B \-\-posix | |
403 | command line option, it follows the POSIX standard for startup files. | |
cce855bc | 404 | In this mode, interactive shells expand the |
ccc6cda3 JA |
405 | .SM |
406 | .B ENV | |
cce855bc | 407 | variable and commands are read and executed from the file |
ccc6cda3 JA |
408 | whose name is the expanded value. |
409 | No other startup files are read. | |
ccc6cda3 JA |
410 | .PP |
411 | .B Bash | |
412 | attempts to determine when it is being run by the remote shell | |
413 | daemon, usually \fIrshd\fP. | |
414 | If | |
415 | .B bash | |
416 | determines it is being run by \fIrshd\fP, it reads and executes | |
417 | commands from \fI~/.bashrc\fP, if that file exists and is readable. | |
418 | It will not do this if invoked as \fBsh\fP. | |
419 | The | |
420 | .B \-\-norc | |
421 | option may be used to inhibit this behavior, and the | |
422 | .B \-\-rcfile | |
423 | option may be used to force another file to be read, but | |
424 | \fIrshd\fP does not generally invoke the shell with those options | |
425 | or allow them to be specified. | |
b72432fd JA |
426 | .PP |
427 | If the shell is started with the effective user (group) id not equal to the | |
428 | real user (group) id, and the \fB\-p\fP option is not supplied, no startup | |
f73dda09 JA |
429 | files are read, shell functions are not inherited from the environment, the |
430 | .SM | |
431 | .B SHELLOPTS | |
432 | variable, if it appears in the environment, is ignored, | |
b72432fd JA |
433 | and the effective user id is set to the real user id. |
434 | If the \fB\-p\fP option is supplied at invocation, the startup behavior is | |
435 | the same, but the effective user id is not reset. | |
726f6388 | 436 | .SH DEFINITIONS |
ccc6cda3 JA |
437 | .PP |
438 | The following definitions are used throughout the rest of this | |
439 | document. | |
726f6388 JA |
440 | .PD 0 |
441 | .TP | |
442 | .B blank | |
443 | A space or tab. | |
444 | .TP | |
445 | .B word | |
446 | A sequence of characters considered as a single unit by the shell. | |
447 | Also known as a | |
448 | .BR token . | |
449 | .TP | |
450 | .B name | |
451 | A | |
452 | .I word | |
453 | consisting only of alphanumeric characters and underscores, and | |
454 | beginning with an alphabetic character or an underscore. Also | |
455 | referred to as an | |
456 | .BR identifier . | |
457 | .TP | |
458 | .B metacharacter | |
459 | A character that, when unquoted, separates words. One of the following: | |
460 | .br | |
461 | .RS | |
462 | .PP | |
463 | .if t \fB| & ; ( ) < > space tab\fP | |
464 | .if n \fB| & ; ( ) < > space tab\fP | |
465 | .RE | |
466 | .PP | |
467 | .TP | |
468 | .B control operator | |
469 | A \fItoken\fP that performs a control function. It is one of the following | |
470 | symbols: | |
471 | .RS | |
472 | .PP | |
ccc6cda3 | 473 | .if t \fB\(bv\(bv & && ; ;; ( ) | <newline>\fP |
726f6388 JA |
474 | .if n \fB|| & && ; ;; ( ) | <newline>\fP |
475 | .RE | |
476 | .PD | |
477 | .SH "RESERVED WORDS" | |
478 | \fIReserved words\fP are words that have a special meaning to the shell. | |
479 | The following words are recognized as reserved when unquoted and either | |
480 | the first word of a simple command (see | |
481 | .SM | |
482 | .B SHELL GRAMMAR | |
483 | below) or the third word of a | |
484 | .B case | |
485 | or | |
486 | .B for | |
487 | command: | |
488 | .if t .RS | |
489 | .PP | |
490 | .B | |
cce855bc JA |
491 | .if n ! case do done elif else esac fi for function if in select then until while { } time [[ ]] |
492 | .if t ! case do done elif else esac fi for function if in select then until while { } time [[ ]] | |
726f6388 | 493 | .if t .RE |
726f6388 JA |
494 | .SH "SHELL GRAMMAR" |
495 | .SS Simple Commands | |
496 | .PP | |
497 | A \fIsimple command\fP is a sequence of optional variable assignments | |
ccc6cda3 | 498 | followed by \fBblank\fP-separated words and redirections, and |
726f6388 | 499 | terminated by a \fIcontrol operator\fP. The first word |
f73dda09 JA |
500 | specifies the command to be executed, and is passed as argument zero. |
501 | The remaining words are passed as arguments to the invoked command. | |
726f6388 JA |
502 | .PP |
503 | The return value of a \fIsimple command\fP is its exit status, or | |
504 | 128+\fIn\^\fP if the command is terminated by signal | |
505 | .IR n . | |
506 | .SS Pipelines | |
507 | .PP | |
508 | A \fIpipeline\fP is a sequence of one or more commands separated by | |
509 | the character | |
510 | .BR | . | |
511 | The format for a pipeline is: | |
512 | .RS | |
513 | .PP | |
ccc6cda3 | 514 | [\fBtime\fP [\fB\-p\fP]] [ ! ] \fIcommand\fP [ \fB|\fP \fIcommand2\fP ... ] |
726f6388 JA |
515 | .RE |
516 | .PP | |
517 | The standard output of | |
518 | .I command | |
f73dda09 | 519 | is connected via a pipe to the standard input of |
726f6388 JA |
520 | .IR command2 . |
521 | This connection is performed before any redirections specified by the | |
522 | command (see | |
523 | .SM | |
524 | .B REDIRECTION | |
525 | below). | |
526 | .PP | |
d3a24ed2 CR |
527 | The return status of a pipeline is the exit status of the last |
528 | command, unless the \fBpipefail\fP option is enabled. | |
529 | If \fBpipefail\fP is enabled, the pipeline's return status is the | |
530 | value of the last (rightmost) command to exit with a non-zero status, | |
531 | or zero if all commands exit successfully. | |
726f6388 JA |
532 | If the reserved word |
533 | .B ! | |
d3a24ed2 CR |
534 | precedes a pipeline, the exit status of that pipeline is the logical |
535 | negation of the exit status as described above. | |
ccc6cda3 | 536 | The shell waits for all commands in the pipeline to |
726f6388 JA |
537 | terminate before returning a value. |
538 | .PP | |
ccc6cda3 JA |
539 | If the |
540 | .B time | |
541 | reserved word precedes a pipeline, the elapsed as well as user and | |
542 | system time consumed by its execution are reported when the pipeline | |
543 | terminates. | |
544 | The \fB\-p\fP option changes the output format to that specified by POSIX. | |
545 | The | |
546 | .SM | |
547 | .B TIMEFORMAT | |
548 | variable may be set to a format string that specifies how the timing | |
549 | information should be displayed; see the description of | |
550 | .SM | |
551 | .B TIMEFORMAT | |
552 | under | |
553 | .B "Shell Variables" | |
554 | below. | |
555 | .PP | |
726f6388 JA |
556 | Each command in a pipeline is executed as a separate process (i.e., in a |
557 | subshell). | |
558 | .SS Lists | |
559 | .PP | |
560 | A \fIlist\fP is a sequence of one or more pipelines separated by one | |
561 | of the operators | |
562 | .BR ; , | |
563 | .BR & , | |
564 | .BR && , | |
565 | or | |
ccc6cda3 JA |
566 | .BR \(bv\(bv , |
567 | and optionally terminated by one of | |
726f6388 JA |
568 | .BR ; , |
569 | .BR & , | |
570 | or | |
571 | .BR <newline> . | |
572 | .PP | |
573 | Of these list operators, | |
574 | .B && | |
575 | and | |
ccc6cda3 | 576 | .B \(bv\(bv |
726f6388 JA |
577 | have equal precedence, followed by |
578 | .B ; | |
579 | and | |
580 | .BR &, | |
581 | which have equal precedence. | |
582 | .PP | |
7117c2d2 JA |
583 | A sequence of one or more newlines may appear in a \fIlist\fP instead |
584 | of a semicolon to delimit commands. | |
585 | .PP | |
726f6388 JA |
586 | If a command is terminated by the control operator |
587 | .BR & , | |
588 | the shell executes the command in the \fIbackground\fP | |
589 | in a subshell. The shell does not wait for the command to | |
590 | finish, and the return status is 0. Commands separated by a | |
591 | .B ; | |
592 | are executed sequentially; the shell waits for each | |
593 | command to terminate in turn. The return status is the | |
594 | exit status of the last command executed. | |
595 | .PP | |
596 | The control operators | |
597 | .B && | |
598 | and | |
ccc6cda3 | 599 | .B \(bv\(bv |
726f6388 JA |
600 | denote AND lists and OR lists, respectively. |
601 | An AND list has the form | |
602 | .RS | |
603 | .PP | |
bb70624e | 604 | \fIcommand1\fP \fB&&\fP \fIcommand2\fP |
726f6388 JA |
605 | .RE |
606 | .PP | |
607 | .I command2 | |
608 | is executed if, and only if, | |
bb70624e | 609 | .I command1 |
726f6388 JA |
610 | returns an exit status of zero. |
611 | .PP | |
612 | An OR list has the form | |
613 | .RS | |
614 | .PP | |
bb70624e | 615 | \fIcommand1\fP \fB\(bv\(bv\fP \fIcommand2\fP |
726f6388 JA |
616 | .PP |
617 | .RE | |
618 | .PP | |
619 | .I command2 | |
620 | is executed if and only if | |
bb70624e | 621 | .I command1 |
ccc6cda3 | 622 | returns a non-zero exit status. The return status of |
726f6388 JA |
623 | AND and OR lists is the exit status of the last command |
624 | executed in the list. | |
625 | .SS Compound Commands | |
626 | .PP | |
627 | A \fIcompound command\fP is one of the following: | |
628 | .TP | |
629 | (\fIlist\fP) | |
d3a24ed2 CR |
630 | \fIlist\fP is executed in a subshell environment (see |
631 | .SM | |
632 | \fBCOMMAND EXECUTION ENVIRONMENT\fP | |
633 | below). | |
634 | Variable assignments and builtin | |
726f6388 JA |
635 | commands that affect the shell's environment do not remain in effect |
636 | after the command completes. The return status is the exit status of | |
637 | \fIlist\fP. | |
638 | .TP | |
639 | { \fIlist\fP; } | |
ccc6cda3 JA |
640 | \fIlist\fP is simply executed in the current shell environment. |
641 | \fIlist\fP must be terminated with a newline or semicolon. | |
642 | This is known as a \fIgroup command\fP. | |
643 | The return status is the exit status of | |
726f6388 | 644 | \fIlist\fP. |
d3a24ed2 | 645 | Note that unlike the metacharacters \fB(\fP and \fB)\fP, \fB{\fP and |
f73dda09 JA |
646 | \fB}\fP are \fIreserved words\fP and must occur where a reserved |
647 | word is permitted to be recognized. Since they do not cause a word | |
648 | break, they must be separated from \fIlist\fP by whitespace. | |
726f6388 | 649 | .TP |
ccc6cda3 JA |
650 | ((\fIexpression\fP)) |
651 | The \fIexpression\fP is evaluated according to the rules described | |
652 | below under | |
653 | .SM | |
654 | .BR "ARITHMETIC EVALUATION" . | |
655 | If the value of the expression is non-zero, the return status is 0; | |
656 | otherwise the return status is 1. This is exactly equivalent to | |
657 | \fBlet "\fIexpression\fP"\fR. | |
658 | .TP | |
cce855bc JA |
659 | \fB[[\fP \fIexpression\fP \fB]]\fP |
660 | Return a status of 0 or 1 depending on the evaluation of | |
661 | the conditional expression \fIexpression\fP. | |
662 | Expressions are composed of the primaries described below under | |
663 | .SM | |
664 | .BR "CONDITIONAL EXPRESSIONS" . | |
665 | Word splitting and pathname expansion are not performed on the words | |
666 | between the \fB[[\fP and \fB]]\fP; tilde expansion, parameter and | |
667 | variable expansion, arithmetic expansion, command substitution, process | |
668 | substitution, and quote removal are performed. | |
d3a24ed2 CR |
669 | Conditional operators such as \fB\-f\fP must be unquoted to be recognized |
670 | as primaries. | |
cce855bc JA |
671 | .if t .sp 0.5 |
672 | .if n .sp 1 | |
673 | When the \fB==\fP and \fB!=\fP operators are used, the string to the | |
674 | right of the operator is considered a pattern and matched according | |
675 | to the rules described below under \fBPattern Matching\fP. | |
2206f89a CR |
676 | If the shell option |
677 | .B nocasematch | |
678 | is enabled, the match is performed without regard to the case | |
679 | of alphabetic characters. | |
dc8fbaf9 CR |
680 | The return value is 0 if the string matches (\fB==\fP) or does not match |
681 | (\fB!=\fP) the pattern, and 1 otherwise. | |
cce855bc JA |
682 | Any part of the pattern may be quoted to force it to be matched as a |
683 | string. | |
684 | .if t .sp 0.5 | |
685 | .if n .sp 1 | |
d3a24ed2 CR |
686 | An additional binary operator, \fB=~\fP, is available, with the same |
687 | precedence as \fB==\fP and \fB!=\fP. | |
688 | When it is used, the string to the right of the operator is considered | |
689 | an extended regular expression and matched accordingly (as in \fIregex\fP(3)). | |
690 | The return value is 0 if the string matches | |
691 | the pattern, and 1 otherwise. | |
692 | If the regular expression is syntactically incorrect, the conditional | |
693 | expression's return value is 2. | |
694 | If the shell option | |
2206f89a | 695 | .B nocasematch |
d3a24ed2 CR |
696 | is enabled, the match is performed without regard to the case |
697 | of alphabetic characters. | |
698 | Substrings matched by parenthesized subexpressions within the regular | |
699 | expression are saved in the array variable \fBBASH_REMATCH\fP. | |
700 | The element of \fBBASH_REMATCH\fP with index 0 is the portion of the string | |
701 | matching the entire regular expression. | |
702 | The element of \fBBASH_REMATCH\fP with index \fIn\fP is the portion of the | |
703 | string matching the \fIn\fPth parenthesized subexpression. | |
704 | .if t .sp 0.5 | |
705 | .if n .sp 1 | |
cce855bc JA |
706 | Expressions may be combined using the following operators, listed |
707 | in decreasing order of precedence: | |
708 | .if t .sp 0.5 | |
709 | .if n .sp 1 | |
710 | .RS | |
711 | .PD 0 | |
712 | .TP | |
713 | .B ( \fIexpression\fP ) | |
714 | Returns the value of \fIexpression\fP. | |
715 | This may be used to override the normal precedence of operators. | |
716 | .TP | |
717 | .B ! \fIexpression\fP | |
718 | True if | |
719 | .I expression | |
720 | is false. | |
721 | .TP | |
722 | \fIexpression1\fP \fB&&\fP \fIexpression2\fP | |
723 | True if both | |
724 | .I expression1 | |
725 | and | |
726 | .I expression2 | |
727 | are true. | |
728 | .TP | |
729 | .if t \fIexpression1\fP \fB\(bv\(bv\fP \fIexpression2\fP | |
730 | .if n \fIexpression1\fP \fB||\fP \fIexpression2\fP | |
731 | True if either | |
732 | .I expression1 | |
733 | or | |
734 | .I expression2 | |
735 | is true. | |
736 | .PD | |
cce855bc JA |
737 | .LP |
738 | The \fB&&\fP and | |
739 | .if t \fB\(bv\(bv\fP | |
740 | .if n \fB||\fP | |
7117c2d2 | 741 | operators do not evaluate \fIexpression2\fP if the value of |
cce855bc JA |
742 | \fIexpression1\fP is sufficient to determine the return value of |
743 | the entire conditional expression. | |
f73dda09 | 744 | .RE |
cce855bc | 745 | .TP |
b72432fd | 746 | \fBfor\fP \fIname\fP [ \fBin\fP \fIword\fP ] ; \fBdo\fP \fIlist\fP ; \fBdone\fP |
726f6388 | 747 | The list of words following \fBin\fP is expanded, generating a list |
bb70624e JA |
748 | of items. |
749 | The variable \fIname\fP is set to each element of this list | |
750 | in turn, and \fIlist\fP is executed each time. | |
751 | If the \fBin\fP \fIword\fP is omitted, the \fBfor\fP command executes | |
752 | \fIlist\fP once for each positional parameter that is set (see | |
726f6388 JA |
753 | .SM |
754 | .B PARAMETERS | |
755 | below). | |
cce855bc JA |
756 | The return status is the exit status of the last command that executes. |
757 | If the expansion of the items following \fBin\fP results in an empty | |
758 | list, no commands are executed, and the return status is 0. | |
726f6388 | 759 | .TP |
bb70624e JA |
760 | \fBfor\fP (( \fIexpr1\fP ; \fIexpr2\fP ; \fIexpr3\fP )) ; \fBdo\fP \fIlist\fP ; \fBdone\fP |
761 | First, the arithmetic expression \fIexpr1\fP is evaluated according | |
762 | to the rules described below under | |
763 | .SM | |
764 | .BR "ARITHMETIC EVALUATION" . | |
765 | The arithmetic expression \fIexpr2\fP is then evaluated repeatedly | |
766 | until it evaluates to zero. | |
767 | Each time \fIexpr2\fP evaluates to a non-zero value, \fIlist\fP is | |
768 | executed and the arithmetic expression \fIexpr3\fP is evaluated. | |
769 | If any expression is omitted, it behaves as if it evaluates to 1. | |
770 | The return value is the exit status of the last command in \fIlist\fP | |
771 | that is executed, or false if any of the expressions is invalid. | |
772 | .TP | |
b72432fd | 773 | \fBselect\fP \fIname\fP [ \fBin\fP \fIword\fP ] ; \fBdo\fP \fIlist\fP ; \fBdone\fP |
726f6388 JA |
774 | The list of words following \fBin\fP is expanded, generating a list |
775 | of items. The set of expanded words is printed on the standard | |
776 | error, each preceded by a number. If the \fBin\fP | |
777 | \fIword\fP is omitted, the positional parameters are printed (see | |
778 | .SM | |
779 | .B PARAMETERS | |
780 | below). The | |
781 | .B PS3 | |
782 | prompt is then displayed and a line read from the standard input. | |
ccc6cda3 | 783 | If the line consists of a number corresponding to one of |
726f6388 JA |
784 | the displayed words, then the value of |
785 | .I name | |
786 | is set to that word. If the line is empty, the words and prompt | |
787 | are displayed again. If EOF is read, the command completes. Any | |
788 | other value read causes | |
789 | .I name | |
790 | to be set to null. The line read is saved in the variable | |
791 | .BR REPLY . | |
792 | The | |
793 | .I list | |
794 | is executed after each selection until a | |
795 | .B break | |
726f6388 JA |
796 | command is executed. |
797 | The exit status of | |
798 | .B select | |
799 | is the exit status of the last command executed in | |
800 | .IR list , | |
801 | or zero if no commands were executed. | |
802 | .TP | |
bb70624e | 803 | \fBcase\fP \fIword\fP \fBin\fP [ [(] \fIpattern\fP [ \fB|\fP \fIpattern\fP ] \ |
726f6388 JA |
804 | ... ) \fIlist\fP ;; ] ... \fBesac\fP |
805 | A \fBcase\fP command first expands \fIword\fP, and tries to match | |
806 | it against each \fIpattern\fP in turn, using the same matching rules | |
807 | as for pathname expansion (see | |
808 | .B Pathname Expansion | |
2206f89a | 809 | below). |
dc8fbaf9 CR |
810 | The \fIword\fP is expanded using tilde |
811 | expansion, parameter and variable expansion, arithmetic substituion, | |
812 | command substitution, process substitution and quote removal. | |
813 | Each \fIpattern\fP examined is expanded using tilde | |
814 | expansion, parameter and variable expansion, arithmetic substituion, | |
815 | command substitution, and process substitution. | |
2206f89a CR |
816 | If the shell option |
817 | .B nocasematch | |
818 | is enabled, the match is performed without regard to the case | |
819 | of alphabetic characters. | |
820 | When a match is found, the | |
726f6388 JA |
821 | corresponding \fIlist\fP is executed. After the first match, no |
822 | subsequent matches are attempted. The exit status is zero if no | |
ccc6cda3 | 823 | pattern matches. Otherwise, it is the exit status of the |
726f6388 JA |
824 | last command executed in \fIlist\fP. |
825 | .TP | |
ccc6cda3 JA |
826 | \fBif\fP \fIlist\fP; \fBthen\fP \fIlist;\fP \ |
827 | [ \fBelif\fP \fIlist\fP; \fBthen\fP \fIlist\fP; ] ... \ | |
828 | [ \fBelse\fP \fIlist\fP; ] \fBfi\fP | |
726f6388 JA |
829 | The |
830 | .B if | |
831 | .I list | |
832 | is executed. If its exit status is zero, the | |
833 | \fBthen\fP \fIlist\fP is executed. Otherwise, each \fBelif\fP | |
834 | \fIlist\fP is executed in turn, and if its exit status is zero, | |
835 | the corresponding \fBthen\fP \fIlist\fP is executed and the | |
836 | command completes. Otherwise, the \fBelse\fP \fIlist\fP is | |
837 | executed, if present. The exit status is the exit status of the | |
838 | last command executed, or zero if no condition tested true. | |
839 | .TP | |
ccc6cda3 | 840 | \fBwhile\fP \fIlist\fP; \fBdo\fP \fIlist\fP; \fBdone\fP |
7117c2d2 | 841 | .PD 0 |
726f6388 | 842 | .TP |
ccc6cda3 | 843 | \fBuntil\fP \fIlist\fP; \fBdo\fP \fIlist\fP; \fBdone\fP |
726f6388 JA |
844 | .PD |
845 | The \fBwhile\fP command continuously executes the \fBdo\fP | |
846 | \fIlist\fP as long as the last command in \fIlist\fP returns | |
847 | an exit status of zero. The \fBuntil\fP command is identical | |
848 | to the \fBwhile\fP command, except that the test is negated; | |
849 | the | |
850 | .B do | |
851 | .I list | |
852 | is executed as long as the last command in | |
853 | .I list | |
ccc6cda3 | 854 | returns a non-zero exit status. |
726f6388 JA |
855 | The exit status of the \fBwhile\fP and \fBuntil\fP commands |
856 | is the exit status | |
857 | of the last \fBdo\fP \fIlist\fP command executed, or zero if | |
858 | none was executed. | |
d3a24ed2 CR |
859 | .SS Shell Function Definitions |
860 | .PP | |
861 | A shell function is an object that is called like a simple command and | |
862 | executes a compound command with a new set of positional parameters. | |
863 | Shell functions are declared as follows: | |
864 | .TP | |
865 | [ \fBfunction\fP ] \fIname\fP () \fIcompound\-command\fP [\fIredirection\fP] | |
866 | This defines a function named \fIname\fP. | |
867 | The reserved word \fBfunction\fP is optional. | |
868 | If the \fBfunction\fP reserved word is supplied, the parentheses are optional. | |
869 | The \fIbody\fP of the function is the compound command | |
870 | .I compound\-command | |
871 | (see \fBCompound Commands\fP above). | |
872 | That command is usually a \fIlist\fP of commands between { and }, but | |
873 | may be any command listed under \fBCompound Commands\fP above. | |
874 | \fIcompound\-command\fP is executed whenever \fIname\fP is specified as the | |
875 | name of a simple command. | |
876 | Any redirections (see | |
877 | .SM | |
878 | .B REDIRECTION | |
879 | below) specified when a function is defined are performed | |
880 | when the function is executed. | |
881 | The exit status of a function definition is zero unless a syntax error | |
882 | occurs or a readonly function with the same name already exists. | |
883 | When executed, the exit status of a function is the exit status of the | |
884 | last command executed in the body. (See | |
726f6388 JA |
885 | .SM |
886 | .B FUNCTIONS | |
887 | below.) | |
888 | .SH COMMENTS | |
ccc6cda3 JA |
889 | In a non-interactive shell, or an interactive shell in which the |
890 | .B interactive_comments | |
891 | option to the | |
892 | .B shopt | |
893 | builtin is enabled (see | |
894 | .SM | |
895 | .B "SHELL BUILTIN COMMANDS" | |
896 | below), a word beginning with | |
726f6388 JA |
897 | .B # |
898 | causes that word and all remaining characters on that line to | |
899 | be ignored. An interactive shell without the | |
ccc6cda3 | 900 | .B interactive_comments |
ccc6cda3 JA |
901 | option enabled does not allow comments. The |
902 | .B interactive_comments | |
903 | option is on by default in interactive shells. | |
726f6388 JA |
904 | .SH QUOTING |
905 | \fIQuoting\fP is used to remove the special meaning of certain | |
906 | characters or words to the shell. Quoting can be used to | |
907 | disable special treatment for special characters, to prevent | |
908 | reserved words from being recognized as such, and to prevent | |
909 | parameter expansion. | |
910 | .PP | |
911 | Each of the \fImetacharacters\fP listed above under | |
912 | .SM | |
913 | .B DEFINITIONS | |
bb70624e JA |
914 | has special meaning to the shell and must be quoted if it is to |
915 | represent itself. | |
916 | .PP | |
5c96a638 CR |
917 | When the command history expansion facilities are being used |
918 | (see | |
919 | .SM | |
920 | .B HISTORY EXPANSION | |
921 | below), the | |
bb70624e JA |
922 | \fIhistory expansion\fP character, usually \fB!\fP, must be quoted |
923 | to prevent history expansion. | |
924 | .PP | |
925 | There are three quoting mechanisms: the | |
726f6388 JA |
926 | .IR "escape character" , |
927 | single quotes, and double quotes. | |
928 | .PP | |
929 | A non-quoted backslash (\fB\e\fP) is the | |
930 | .IR "escape character" . | |
931 | It preserves the literal value of the next character that follows, | |
932 | with the exception of <newline>. If a \fB\e\fP<newline> pair | |
cce855bc JA |
933 | appears, and the backslash is not itself quoted, the \fB\e\fP<newline> |
934 | is treated as a line continuation (that is, it is removed from the | |
935 | input stream and effectively ignored). | |
726f6388 JA |
936 | .PP |
937 | Enclosing characters in single quotes preserves the literal value | |
938 | of each character within the quotes. A single quote may not occur | |
939 | between single quotes, even when preceded by a backslash. | |
940 | .PP | |
941 | Enclosing characters in double quotes preserves the literal value | |
942 | of all characters within the quotes, with the exception of | |
943 | .BR $ , | |
944 | .BR ` , | |
5c96a638 CR |
945 | .BR \e , |
946 | and, when history expansion is enabled, | |
947 | .BR ! . | |
726f6388 JA |
948 | The characters |
949 | .B $ | |
950 | and | |
951 | .B ` | |
952 | retain their special meaning within double quotes. The backslash | |
953 | retains its special meaning only when followed by one of the following | |
954 | characters: | |
955 | .BR $ , | |
956 | .BR ` , | |
957 | \^\fB"\fP\^, | |
958 | .BR \e , | |
959 | or | |
960 | .BR <newline> . | |
961 | A double quote may be quoted within double quotes by preceding it with | |
962 | a backslash. | |
5c96a638 CR |
963 | If enabled, history expansion will be performed unless an |
964 | .B ! | |
965 | appearing in double quotes is escaped using a backslash. | |
966 | The backslash preceding the | |
967 | .B ! | |
968 | is not removed. | |
726f6388 JA |
969 | .PP |
970 | The special parameters | |
971 | .B * | |
972 | and | |
973 | .B @ | |
974 | have special meaning when in double | |
975 | quotes (see | |
976 | .SM | |
977 | .B PARAMETERS | |
978 | below). | |
ccc6cda3 | 979 | .PP |
20587658 | 980 | Words of the form \fB$\fP\(aq\fIstring\fP\(aq are treated specially. The |
ccc6cda3 | 981 | word expands to \fIstring\fP, with backslash-escaped characters replaced |
f75912ae | 982 | as specified by the ANSI C standard. Backslash escape sequences, if |
ccc6cda3 JA |
983 | present, are decoded as follows: |
984 | .RS | |
985 | .PD 0 | |
986 | .TP | |
987 | .B \ea | |
988 | alert (bell) | |
989 | .TP | |
990 | .B \eb | |
991 | backspace | |
992 | .TP | |
993 | .B \ee | |
994 | an escape character | |
995 | .TP | |
996 | .B \ef | |
997 | form feed | |
998 | .TP | |
999 | .B \en | |
1000 | new line | |
1001 | .TP | |
1002 | .B \er | |
1003 | carriage return | |
1004 | .TP | |
1005 | .B \et | |
1006 | horizontal tab | |
1007 | .TP | |
1008 | .B \ev | |
1009 | vertical tab | |
1010 | .TP | |
1011 | .B \e\e | |
1012 | backslash | |
bb70624e | 1013 | .TP |
20587658 | 1014 | .B \e\(aq |
bb70624e | 1015 | single quote |
ccc6cda3 JA |
1016 | .TP |
1017 | .B \e\fInnn\fP | |
f73dda09 | 1018 | the eight-bit character whose value is the octal value \fInnn\fP |
cce855bc JA |
1019 | (one to three digits) |
1020 | .TP | |
f73dda09 JA |
1021 | .B \ex\fIHH\fP |
1022 | the eight-bit character whose value is the hexadecimal value \fIHH\fP | |
1023 | (one or two hex digits) | |
7117c2d2 JA |
1024 | .TP |
1025 | .B \ec\fIx\fP | |
1026 | a control-\fIx\fP character | |
ccc6cda3 JA |
1027 | .PD |
1028 | .RE | |
1029 | .LP | |
bb70624e | 1030 | The expanded result is single-quoted, as if the dollar sign had |
ccc6cda3 JA |
1031 | not been present. |
1032 | .PP | |
1033 | A double-quoted string preceded by a dollar sign (\fB$\fP) will cause | |
1034 | the string to be translated according to the current locale. | |
1035 | If the current locale is \fBC\fP or \fBPOSIX\fP, the dollar sign | |
1036 | is ignored. | |
1037 | If the string is translated and replaced, the replacement is | |
1038 | double-quoted. | |
726f6388 JA |
1039 | .SH PARAMETERS |
1040 | A | |
1041 | .I parameter | |
ccc6cda3 JA |
1042 | is an entity that stores values. |
1043 | It can be a | |
726f6388 JA |
1044 | .IR name , |
1045 | a number, or one of the special characters listed below under | |
1046 | .BR "Special Parameters" . | |
d3a24ed2 | 1047 | A |
726f6388 JA |
1048 | .I variable |
1049 | is a parameter denoted by a | |
1050 | .IR name . | |
f73dda09 JA |
1051 | A variable has a \fIvalue\fP and zero or more \fIattributes\fP. |
1052 | Attributes are assigned using the | |
1053 | .B declare | |
1054 | builtin command (see | |
1055 | .B declare | |
1056 | below in | |
1057 | .SM | |
1058 | .BR "SHELL BUILTIN COMMANDS" ). | |
726f6388 JA |
1059 | .PP |
1060 | A parameter is set if it has been assigned a value. The null string is | |
1061 | a valid value. Once a variable is set, it may be unset only by using | |
1062 | the | |
1063 | .B unset | |
1064 | builtin command (see | |
1065 | .SM | |
1066 | .B SHELL BUILTIN COMMANDS | |
1067 | below). | |
1068 | .PP | |
1069 | A | |
1070 | .I variable | |
1071 | may be assigned to by a statement of the form | |
1072 | .RS | |
1073 | .PP | |
1074 | \fIname\fP=[\fIvalue\fP] | |
1075 | .RE | |
1076 | .PP | |
1077 | If | |
1078 | .I value | |
1079 | is not given, the variable is assigned the null string. All | |
1080 | .I values | |
bb70624e JA |
1081 | undergo tilde expansion, parameter and variable expansion, |
1082 | command substitution, arithmetic expansion, and quote | |
ccc6cda3 JA |
1083 | removal (see |
1084 | .SM | |
1085 | .B EXPANSION | |
1086 | below). If the variable has its | |
cce855bc | 1087 | .B integer |
f73dda09 | 1088 | attribute set, then |
726f6388 | 1089 | .I value |
d3a24ed2 | 1090 | is evaluated as an arithmetic expression even if the $((...)) expansion is |
cce855bc | 1091 | not used (see |
ccc6cda3 JA |
1092 | .B "Arithmetic Expansion" |
1093 | below). | |
1094 | Word splitting is not performed, with the exception | |
726f6388 JA |
1095 | of \fB"$@"\fP as explained below under |
1096 | .BR "Special Parameters" . | |
1097 | Pathname expansion is not performed. | |
f73dda09 | 1098 | Assignment statements may also appear as arguments to the |
5e13499c | 1099 | .BR alias , |
f73dda09 JA |
1100 | .BR declare , |
1101 | .BR typeset , | |
1102 | .BR export , | |
1103 | .BR readonly , | |
1104 | and | |
1105 | .B local | |
1106 | builtin commands. | |
d11b8b46 CR |
1107 | .PP |
1108 | In the context where an assignment statement is assigning a value | |
1109 | to a shell variable or array index, the += operator can be used to | |
1110 | append to or add to the variable's previous value. | |
1111 | When += is applied to a variable for which the integer attribute has been | |
1112 | set, \fIvalue\fP is evaluated as an arithmetic expression and added to the | |
1113 | variable's current value, which is also evaluated. | |
1114 | When += is applied to an array variable using compound assignment (see | |
1115 | .B Arrays | |
1116 | below), the | |
1117 | variable's value is not unset (as it is when using =), and new values are | |
1118 | appended to the array beginning at one greater than the array's maximum index. | |
1119 | When applied to a string-valued variable, \fIvalue\fP is expanded and | |
1120 | appended to the variable's value. | |
726f6388 JA |
1121 | .SS Positional Parameters |
1122 | .PP | |
1123 | A | |
1124 | .I positional parameter | |
1125 | is a parameter denoted by one or more | |
1126 | digits, other than the single digit 0. Positional parameters are | |
1127 | assigned from the shell's arguments when it is invoked, | |
1128 | and may be reassigned using the | |
1129 | .B set | |
1130 | builtin command. Positional parameters may not be assigned to | |
1131 | with assignment statements. The positional parameters are | |
1132 | temporarily replaced when a shell function is executed (see | |
1133 | .SM | |
1134 | .B FUNCTIONS | |
1135 | below). | |
1136 | .PP | |
1137 | When a positional parameter consisting of more than a single | |
1138 | digit is expanded, it must be enclosed in braces (see | |
1139 | .SM | |
1140 | .B EXPANSION | |
1141 | below). | |
1142 | .SS Special Parameters | |
1143 | .PP | |
1144 | The shell treats several parameters specially. These parameters may | |
1145 | only be referenced; assignment to them is not allowed. | |
1146 | .PD 0 | |
1147 | .TP | |
1148 | .B * | |
1149 | Expands to the positional parameters, starting from one. When the | |
1150 | expansion occurs within double quotes, it expands to a single word | |
1151 | with the value of each parameter separated by the first character | |
1152 | of the | |
1153 | .SM | |
1154 | .B IFS | |
cce855bc JA |
1155 | special variable. That is, "\fB$*\fP" is equivalent |
1156 | to "\fB$1\fP\fIc\fP\fB$2\fP\fIc\fP\fB...\fP", where | |
726f6388 JA |
1157 | .I c |
1158 | is the first character of the value of the | |
1159 | .SM | |
1160 | .B IFS | |
1161 | variable. If | |
1162 | .SM | |
1163 | .B IFS | |
d166f048 JA |
1164 | is unset, the parameters are separated by spaces. |
1165 | If | |
1166 | .SM | |
1167 | .B IFS | |
1168 | is null, the parameters are joined without intervening separators. | |
726f6388 JA |
1169 | .TP |
1170 | .B @ | |
1171 | Expands to the positional parameters, starting from one. When the | |
cce855bc JA |
1172 | expansion occurs within double quotes, each parameter expands to a |
1173 | separate word. That is, "\fB$@\fP" is equivalent to | |
1174 | "\fB$1\fP" "\fB$2\fP" ... | |
be7d8f2d CR |
1175 | If the double-quoted expansion occurs within a word, the expansion of |
1176 | the first parameter is joined with the beginning part of the original | |
1177 | word, and the expansion of the last parameter is joined with the last | |
1178 | part of the original word. | |
cce855bc | 1179 | When there are no positional parameters, "\fB$@\fP" and |
726f6388 JA |
1180 | .B $@ |
1181 | expand to nothing (i.e., they are removed). | |
1182 | .TP | |
1183 | .B # | |
1184 | Expands to the number of positional parameters in decimal. | |
1185 | .TP | |
1186 | .B ? | |
1187 | Expands to the status of the most recently executed foreground | |
1188 | pipeline. | |
1189 | .TP | |
1190 | .B \- | |
1191 | Expands to the current option flags as specified upon invocation, | |
1192 | by the | |
1193 | .B set | |
1194 | builtin command, or those set by the shell itself | |
1195 | (such as the | |
1196 | .B \-i | |
cce855bc | 1197 | option). |
726f6388 JA |
1198 | .TP |
1199 | .B $ | |
1200 | Expands to the process ID of the shell. In a () subshell, it | |
1201 | expands to the process ID of the current shell, not the | |
1202 | subshell. | |
1203 | .TP | |
1204 | .B ! | |
1205 | Expands to the process ID of the most recently executed background | |
1206 | (asynchronous) command. | |
1207 | .TP | |
1208 | .B 0 | |
1209 | Expands to the name of the shell or shell script. This is set at | |
1210 | shell initialization. If | |
1211 | .B bash | |
1212 | is invoked with a file of commands, | |
1213 | .B $0 | |
1214 | is set to the name of that file. If | |
1215 | .B bash | |
1216 | is started with the | |
1217 | .B \-c | |
1218 | option, then | |
1219 | .B $0 | |
1220 | is set to the first argument after the string to be | |
1221 | executed, if one is present. Otherwise, it is set | |
ccc6cda3 | 1222 | to the file name used to invoke |
726f6388 JA |
1223 | .BR bash , |
1224 | as given by argument zero. | |
1225 | .TP | |
1226 | .B _ | |
cc87ba64 CR |
1227 | At shell startup, set to the absolute pathname used to invoke the |
1228 | shell or shell script being executed as passed in the environment | |
1229 | or argument list. | |
ccc6cda3 JA |
1230 | Subsequently, expands to the last argument to the previous command, |
1231 | after expansion. | |
cc87ba64 CR |
1232 | Also set to the full pathname used to invoke each command executed |
1233 | and placed in the environment exported to that command. | |
ccc6cda3 JA |
1234 | When checking mail, this parameter holds the name of the mail file |
1235 | currently being checked. | |
726f6388 JA |
1236 | .PD |
1237 | .SS Shell Variables | |
1238 | .PP | |
1239 | The following variables are set by the shell: | |
1240 | .PP | |
1241 | .PD 0 | |
1242 | .TP | |
726f6388 | 1243 | .B BASH |
ccc6cda3 | 1244 | Expands to the full file name used to invoke this instance of |
726f6388 JA |
1245 | .BR bash . |
1246 | .TP | |
d3a24ed2 CR |
1247 | .B BASH_ARGC |
1248 | An array variable whose values are the number of parameters in each | |
2206f89a CR |
1249 | frame of the current bash execution call stack. |
1250 | The number of | |
d3a24ed2 | 1251 | parameters to the current subroutine (shell function or script executed |
2206f89a CR |
1252 | with \fB.\fP or \fBsource\fP) is at the top of the stack. |
1253 | When a subroutine is executed, the number of parameters passed is pushed onto | |
d3a24ed2 | 1254 | \fBBASH_ARGC\fP. |
2206f89a CR |
1255 | The shell sets \fBBASH_ARGC\fP only when in extended debugging mode |
1256 | (see the description of the | |
1257 | .B extdebug | |
1258 | option to the | |
1259 | .B shopt | |
1260 | builtin below) | |
d3a24ed2 CR |
1261 | .TP |
1262 | .B BASH_ARGV | |
1263 | An array variable containing all of the parameters in the current bash | |
1264 | execution call stack. The final parameter of the last subroutine call | |
1265 | is at the top of the stack; the first parameter of the initial call is | |
1266 | at the bottom. When a subroutine is executed, the parameters supplied | |
1267 | are pushed onto \fBBASH_ARGV\fP. | |
2206f89a CR |
1268 | The shell sets \fBBASH_ARGV\fP only when in extended debugging mode |
1269 | (see the description of the | |
1270 | .B extdebug | |
1271 | option to the | |
1272 | .B shopt | |
1273 | builtin below) | |
d3a24ed2 CR |
1274 | .TP |
1275 | .B BASH_COMMAND | |
1276 | The command currently being executed or about to be executed, unless the | |
1277 | shell is executing a command as the result of a trap, | |
1278 | in which case it is the command executing at the time of the trap. | |
1279 | .TP | |
1280 | .B BASH_EXECUTION_STRING | |
1281 | The command argument to the \fB\-c\fP invocation option. | |
1282 | .TP | |
1283 | .B BASH_LINENO | |
1284 | An array variable whose members are the line numbers in source files | |
be7d8f2d | 1285 | corresponding to each member of \fBFUNCNAME\fP. |
d3a24ed2 | 1286 | \fB${BASH_LINENO[\fP\fI$i\fP\fB]}\fP is the line number in the source |
633e5c6d CR |
1287 | file where \fB${FUNCNAME[\fP\fI$ifP\fB]}\fP was called. |
1288 | The corresponding source file name is \fB${BASH_SOURCE[\fP\fI$i\fP\fB]}\fB. | |
d3a24ed2 CR |
1289 | Use \fBLINENO\fP to obtain the current line number. |
1290 | .TP | |
1291 | .B BASH_REMATCH | |
1292 | An array variable whose members are assigned by the \fB=~\fP binary | |
1293 | operator to the \fB[[\fP conditional command. | |
1294 | The element with index 0 is the portion of the string | |
1295 | matching the entire regular expression. | |
1296 | The element with index \fIn\fP is the portion of the | |
1297 | string matching the \fIn\fPth parenthesized subexpression. | |
1298 | This variable is read-only. | |
1299 | .TP | |
1300 | .B BASH_SOURCE | |
1301 | An array variable whose members are the source filenames corresponding | |
1302 | to the elements in the \fBFUNCNAME\fP array variable. | |
1303 | .TP | |
1304 | .B BASH_SUBSHELL | |
1305 | Incremented by one each time a subshell or subshell environment is spawned. | |
1306 | The initial value is 0. | |
1307 | .TP | |
ccc6cda3 | 1308 | .B BASH_VERSINFO |
cce855bc JA |
1309 | A readonly array variable whose members hold version information for |
1310 | this instance of | |
ccc6cda3 JA |
1311 | .BR bash . |
1312 | The values assigned to the array members are as follows: | |
1313 | .sp .5 | |
1314 | .RS | |
1315 | .PD 0 | |
1316 | .TP 24 | |
1317 | .B BASH_VERSINFO[\fR0\fP] | |
1318 | The major version number (the \fIrelease\fP). | |
1319 | .TP | |
1320 | .B BASH_VERSINFO[\fR1\fP] | |
1321 | The minor version number (the \fIversion\fP). | |
1322 | .TP | |
1323 | .B BASH_VERSINFO[\fR2\fP] | |
1324 | The patch level. | |
1325 | .TP | |
1326 | .B BASH_VERSINFO[\fR3\fP] | |
1327 | The build version. | |
1328 | .TP | |
1329 | .B BASH_VERSINFO[\fR4\fP] | |
1330 | The release status (e.g., \fIbeta1\fP). | |
1331 | .TP | |
1332 | .B BASH_VERSINFO[\fR5\fP] | |
1333 | The value of \fBMACHTYPE\fP. | |
1334 | .PD | |
1335 | .RE | |
1336 | .TP | |
f73dda09 JA |
1337 | .B BASH_VERSION |
1338 | Expands to a string describing the version of this instance of | |
1339 | .BR bash . | |
726f6388 | 1340 | .TP |
f73dda09 JA |
1341 | .B COMP_CWORD |
1342 | An index into \fB${COMP_WORDS}\fP of the word containing the current | |
1343 | cursor position. | |
1344 | This variable is available only in shell functions invoked by the | |
1345 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1346 | below). | |
1347 | .TP | |
1348 | .B COMP_LINE | |
1349 | The current command line. | |
1350 | This variable is available only in shell functions and external | |
1351 | commands invoked by the | |
1352 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1353 | below). | |
1354 | .TP | |
1355 | .B COMP_POINT | |
1356 | The index of the current cursor position relative to the beginning of | |
1357 | the current command. | |
1358 | If the current cursor position is at the end of the current command, | |
1359 | the value of this variable is equal to \fB${#COMP_LINE}\fP. | |
1360 | This variable is available only in shell functions and external | |
1361 | commands invoked by the | |
1362 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1363 | below). | |
1364 | .TP | |
d3a24ed2 CR |
1365 | .B COMP_WORDBREAKS |
1366 | The set of characters that the Readline library treats as word | |
1367 | separators when performing word completion. | |
1368 | If | |
1369 | .SM | |
1370 | .B COMP_WORDBREAKS | |
1371 | is unset, it loses its special properties, even if it is | |
1372 | subsequently reset. | |
1373 | .TP | |
f73dda09 JA |
1374 | .B COMP_WORDS |
1375 | An array variable (see \fBArrays\fP below) consisting of the individual | |
1376 | words in the current command line. | |
1377 | This variable is available only in shell functions invoked by the | |
1378 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1379 | below). | |
1380 | .TP | |
1381 | .B DIRSTACK | |
1382 | An array variable (see | |
1383 | .B Arrays | |
1384 | below) containing the current contents of the directory stack. | |
1385 | Directories appear in the stack in the order they are displayed by the | |
1386 | .B dirs | |
1387 | builtin. | |
1388 | Assigning to members of this array variable may be used to modify | |
1389 | directories already in the stack, but the | |
1390 | .B pushd | |
1391 | and | |
1392 | .B popd | |
1393 | builtins must be used to add and remove directories. | |
1394 | Assignment to this variable will not change the current directory. | |
726f6388 JA |
1395 | If |
1396 | .SM | |
f73dda09 | 1397 | .B DIRSTACK |
726f6388 JA |
1398 | is unset, it loses its special properties, even if it is |
1399 | subsequently reset. | |
1400 | .TP | |
f73dda09 JA |
1401 | .B EUID |
1402 | Expands to the effective user ID of the current user, initialized at | |
1403 | shell startup. This variable is readonly. | |
1404 | .TP | |
1405 | .B FUNCNAME | |
d3a24ed2 CR |
1406 | An array variable containing the names of all shell functions |
1407 | currently in the execution call stack. | |
1408 | The element with index 0 is the name of any currently-executing | |
1409 | shell function. | |
1410 | The bottom-most element is "main". | |
f73dda09 JA |
1411 | This variable exists only when a shell function is executing. |
1412 | Assignments to | |
726f6388 | 1413 | .SM |
f73dda09 JA |
1414 | .B FUNCNAME |
1415 | have no effect and return an error status. | |
726f6388 JA |
1416 | If |
1417 | .SM | |
f73dda09 | 1418 | .B FUNCNAME |
726f6388 JA |
1419 | is unset, it loses its special properties, even if it is |
1420 | subsequently reset. | |
1421 | .TP | |
f73dda09 JA |
1422 | .B GROUPS |
1423 | An array variable containing the list of groups of which the current | |
1424 | user is a member. | |
1425 | Assignments to | |
1426 | .SM | |
1427 | .B GROUPS | |
1428 | have no effect and return an error status. | |
726f6388 JA |
1429 | If |
1430 | .SM | |
f73dda09 | 1431 | .B GROUPS |
726f6388 JA |
1432 | is unset, it loses its special properties, even if it is |
1433 | subsequently reset. | |
1434 | .TP | |
1435 | .B HISTCMD | |
1436 | The history number, or index in the history list, of the current | |
ccc6cda3 JA |
1437 | command. |
1438 | If | |
726f6388 JA |
1439 | .SM |
1440 | .B HISTCMD | |
1441 | is unset, it loses its special properties, even if it is | |
1442 | subsequently reset. | |
1443 | .TP | |
f73dda09 JA |
1444 | .B HOSTNAME |
1445 | Automatically set to the name of the current host. | |
bb70624e | 1446 | .TP |
f73dda09 JA |
1447 | .B HOSTTYPE |
1448 | Automatically set to a string that uniquely | |
1449 | describes the type of machine on which | |
1450 | .B bash | |
1451 | is executing. | |
1452 | The default is system-dependent. | |
1453 | .TP | |
1454 | .B LINENO | |
1455 | Each time this parameter is referenced, the shell substitutes | |
1456 | a decimal number representing the current sequential line number | |
1457 | (starting with 1) within a script or function. When not in a | |
1458 | script or function, the value substituted is not guaranteed to | |
1459 | be meaningful. | |
ccc6cda3 JA |
1460 | If |
1461 | .SM | |
f73dda09 | 1462 | .B LINENO |
ccc6cda3 JA |
1463 | is unset, it loses its special properties, even if it is |
1464 | subsequently reset. | |
1465 | .TP | |
f73dda09 JA |
1466 | .B MACHTYPE |
1467 | Automatically set to a string that fully describes the system | |
1468 | type on which | |
1469 | .B bash | |
1470 | is executing, in the standard GNU \fIcpu-company-system\fP format. | |
1471 | The default is system-dependent. | |
1472 | .TP | |
1473 | .B OLDPWD | |
1474 | The previous working directory as set by the | |
1475 | .B cd | |
1476 | command. | |
ccc6cda3 | 1477 | .TP |
726f6388 JA |
1478 | .B OPTARG |
1479 | The value of the last option argument processed by the | |
1480 | .B getopts | |
1481 | builtin command (see | |
1482 | .SM | |
1483 | .B SHELL BUILTIN COMMANDS | |
1484 | below). | |
1485 | .TP | |
1486 | .B OPTIND | |
1487 | The index of the next argument to be processed by the | |
1488 | .B getopts | |
1489 | builtin command (see | |
1490 | .SM | |
1491 | .B SHELL BUILTIN COMMANDS | |
1492 | below). | |
1493 | .TP | |
726f6388 JA |
1494 | .B OSTYPE |
1495 | Automatically set to a string that | |
1496 | describes the operating system on which | |
1497 | .B bash | |
ccc6cda3 JA |
1498 | is executing. |
1499 | The default is system-dependent. | |
1500 | .TP | |
f73dda09 JA |
1501 | .B PIPESTATUS |
1502 | An array variable (see | |
1503 | .B Arrays | |
1504 | below) containing a list of exit status values from the processes | |
1505 | in the most-recently-executed foreground pipeline (which may | |
1506 | contain only a single command). | |
ccc6cda3 | 1507 | .TP |
f73dda09 JA |
1508 | .B PPID |
1509 | The process ID of the shell's parent. This variable is readonly. | |
1510 | .TP | |
1511 | .B PWD | |
1512 | The current working directory as set by the | |
1513 | .B cd | |
1514 | command. | |
1515 | .TP | |
1516 | .B RANDOM | |
1517 | Each time this parameter is referenced, a random integer between | |
1518 | 0 and 32767 is | |
1519 | generated. The sequence of random numbers may be initialized by assigning | |
1520 | a value to | |
1521 | .SM | |
1522 | .BR RANDOM . | |
1523 | If | |
1524 | .SM | |
1525 | .B RANDOM | |
1526 | is unset, it loses its special properties, even if it is | |
1527 | subsequently reset. | |
1528 | .TP | |
1529 | .B REPLY | |
1530 | Set to the line of input read by the | |
1531 | .B read | |
1532 | builtin command when no arguments are supplied. | |
1533 | .TP | |
1534 | .B SECONDS | |
1535 | Each time this parameter is | |
1536 | referenced, the number of seconds since shell invocation is returned. If a | |
1537 | value is assigned to | |
1538 | .SM | |
1539 | .BR SECONDS , | |
1540 | the value returned upon subsequent | |
1541 | references is | |
1542 | the number of seconds since the assignment plus the value assigned. | |
1543 | If | |
1544 | .SM | |
1545 | .B SECONDS | |
1546 | is unset, it loses its special properties, even if it is | |
1547 | subsequently reset. | |
1548 | .TP | |
1549 | .B SHELLOPTS | |
1550 | A colon-separated list of enabled shell options. Each word in | |
1551 | the list is a valid argument for the | |
1552 | .B \-o | |
1553 | option to the | |
1554 | .B set | |
1555 | builtin command (see | |
1556 | .SM | |
1557 | .B "SHELL BUILTIN COMMANDS" | |
1558 | below). The options appearing in | |
ccc6cda3 JA |
1559 | .SM |
1560 | .B SHELLOPTS | |
1561 | are those reported as | |
1562 | .I on | |
1563 | by \fBset \-o\fP. | |
1564 | If this variable is in the environment when | |
1565 | .B bash | |
1566 | starts up, each shell option in the list will be enabled before | |
1567 | reading any startup files. | |
1568 | This variable is read-only. | |
bb70624e | 1569 | .TP |
f73dda09 JA |
1570 | .B SHLVL |
1571 | Incremented by one each time an instance of | |
1572 | .B bash | |
1573 | is started. | |
bb70624e | 1574 | .TP |
f73dda09 JA |
1575 | .B UID |
1576 | Expands to the user ID of the current user, initialized at shell startup. | |
1577 | This variable is readonly. | |
726f6388 JA |
1578 | .PD |
1579 | .PP | |
1580 | The following variables are used by the shell. In some cases, | |
1581 | .B bash | |
1582 | assigns a default value to a variable; these cases are noted | |
1583 | below. | |
1584 | .PP | |
1585 | .PD 0 | |
1586 | .TP | |
d166f048 | 1587 | .B BASH_ENV |
726f6388 JA |
1588 | If this parameter is set when \fBbash\fP is executing a shell script, |
1589 | its value is interpreted as a filename containing commands to | |
1590 | initialize the shell, as in | |
cce855bc | 1591 | .IR ~/.bashrc . |
726f6388 JA |
1592 | The value of |
1593 | .SM | |
d166f048 | 1594 | .B BASH_ENV |
726f6388 | 1595 | is subjected to parameter expansion, command substitution, and arithmetic |
ccc6cda3 | 1596 | expansion before being interpreted as a file name. |
726f6388 JA |
1597 | .SM |
1598 | .B PATH | |
ccc6cda3 | 1599 | is not used to search for the resultant file name. |
726f6388 | 1600 | .TP |
f73dda09 JA |
1601 | .B CDPATH |
1602 | The search path for the | |
1603 | .B cd | |
1604 | command. | |
1605 | This is a colon-separated list of directories in which the shell looks | |
1606 | for destination directories specified by the | |
1607 | .B cd | |
1608 | command. | |
7117c2d2 JA |
1609 | A sample value is |
1610 | .if t \f(CW".:~:/usr"\fP. | |
1611 | .if n ".:~:/usr". | |
726f6388 | 1612 | .TP |
f73dda09 JA |
1613 | .B COLUMNS |
1614 | Used by the \fBselect\fP builtin command to determine the terminal width | |
1615 | when printing selection lists. Automatically set upon receipt of a SIGWINCH. | |
726f6388 | 1616 | .TP |
f73dda09 JA |
1617 | .B COMPREPLY |
1618 | An array variable from which \fBbash\fP reads the possible completions | |
1619 | generated by a shell function invoked by the programmable completion | |
1620 | facility (see \fBProgrammable Completion\fP below). | |
726f6388 | 1621 | .TP |
d3a24ed2 CR |
1622 | .B EMACS |
1623 | If \fBbash\fP finds this variable in the environment when the shell starts | |
1624 | with value | |
1625 | .if t \f(CWt\fP, | |
1626 | .if n "t", | |
1627 | it assumes that the shell is running in an emacs shell buffer and disables | |
1628 | line editing. | |
1629 | .TP | |
f73dda09 JA |
1630 | .B FCEDIT |
1631 | The default editor for the | |
1632 | .B fc | |
1633 | builtin command. | |
726f6388 | 1634 | .TP |
f73dda09 JA |
1635 | .B FIGNORE |
1636 | A colon-separated list of suffixes to ignore when performing | |
1637 | filename completion (see | |
726f6388 | 1638 | .SM |
f73dda09 JA |
1639 | .B READLINE |
1640 | below). | |
1641 | A filename whose suffix matches one of the entries in | |
726f6388 | 1642 | .SM |
f73dda09 JA |
1643 | .B FIGNORE |
1644 | is excluded from the list of matched filenames. | |
7117c2d2 JA |
1645 | A sample value is |
1646 | .if t \f(CW".o:~"\fP. | |
1647 | .if n ".o:~". | |
ccc6cda3 | 1648 | .TP |
f73dda09 JA |
1649 | .B GLOBIGNORE |
1650 | A colon-separated list of patterns defining the set of filenames to | |
1651 | be ignored by pathname expansion. | |
1652 | If a filename matched by a pathname expansion pattern also matches one | |
1653 | of the patterns in | |
726f6388 | 1654 | .SM |
f73dda09 JA |
1655 | .BR GLOBIGNORE , |
1656 | it is removed from the list of matches. | |
1657 | .TP | |
1658 | .B HISTCONTROL | |
d3a24ed2 CR |
1659 | A colon-separated list of values controlling how commands are saved on |
1660 | the history list. | |
1661 | If the list of values includes | |
f73dda09 JA |
1662 | .IR ignorespace , |
1663 | lines which begin with a | |
1664 | .B space | |
d3a24ed2 CR |
1665 | character are not saved in the history list. |
1666 | A value of | |
1667 | .I ignoredups | |
1668 | causes lines matching the previous history entry to not be saved. | |
f73dda09 JA |
1669 | A value of |
1670 | .I ignoreboth | |
d3a24ed2 CR |
1671 | is shorthand for \fIignorespace\fP and \fIignoredups\fP. |
1672 | A value of | |
1673 | .IR erasedups | |
1674 | causes all previous lines matching the current line to be removed from | |
1675 | the history list before that line is saved. | |
1676 | Any value not in the above list is ignored. | |
1677 | If \fBHISTCONTROL\fP is unset, or does not include a valid value, | |
1678 | all lines read by the shell parser are saved on the history list, | |
1679 | subject to the value of | |
f73dda09 JA |
1680 | .BR HISTIGNORE . |
1681 | The second and subsequent lines of a multi-line compound command are | |
1682 | not tested, and are added to the history regardless of the value of | |
1683 | .BR HISTCONTROL . | |
726f6388 JA |
1684 | .TP |
1685 | .B HISTFILE | |
ccc6cda3 | 1686 | The name of the file in which command history is saved (see |
726f6388 JA |
1687 | .SM |
1688 | .B HISTORY | |
ccc6cda3 | 1689 | below). The default value is \fI~/.bash_history\fP. If unset, the |
726f6388 JA |
1690 | command history is not saved when an interactive shell exits. |
1691 | .TP | |
1692 | .B HISTFILESIZE | |
1693 | The maximum number of lines contained in the history file. When this | |
1694 | variable is assigned a value, the history file is truncated, if | |
1695 | necessary, to contain no more than that number of lines. The default | |
ccc6cda3 JA |
1696 | value is 500. The history file is also truncated to this size after |
1697 | writing it when an interactive shell exits. | |
726f6388 | 1698 | .TP |
f73dda09 JA |
1699 | .B HISTIGNORE |
1700 | A colon-separated list of patterns used to decide which command lines | |
1701 | should be saved on the history list. Each pattern is anchored at the | |
1702 | beginning of the line and must match the complete line (no implicit | |
1703 | `\fB*\fP' is appended). Each pattern is tested against the line | |
1704 | after the checks specified by | |
1705 | .B HISTCONTROL | |
1706 | are applied. | |
1707 | In addition to the normal shell pattern matching characters, `\fB&\fP' | |
1708 | matches the previous history line. `\fB&\fP' may be escaped using a | |
1709 | backslash; the backslash is removed before attempting a match. | |
1710 | The second and subsequent lines of a multi-line compound command are | |
1711 | not tested, and are added to the history regardless of the value of | |
1712 | .BR HISTIGNORE . | |
1713 | .TP | |
1714 | .B HISTSIZE | |
1715 | The number of commands to remember in the command history (see | |
1716 | .SM | |
1717 | .B HISTORY | |
1718 | below). The default value is 500. | |
1719 | .TP | |
d3a24ed2 CR |
1720 | .B HISTTIMEFORMAT |
1721 | If this variable is set and not null, its value is used as a format string | |
1722 | for \fIstrftime\fP(3) to print the time stamp associated with each history | |
1723 | entry displayed by the \fBhistory\fP builtin. | |
1724 | If this variable is set, time stamps are written to the history file so | |
1725 | they may be preserved across shell sessions. | |
1726 | .TP | |
f73dda09 JA |
1727 | .B HOME |
1728 | The home directory of the current user; the default argument for the | |
1729 | \fBcd\fP builtin command. | |
1730 | The value of this variable is also used when performing tilde expansion. | |
1731 | .TP | |
1732 | .B HOSTFILE | |
1733 | Contains the name of a file in the same format as | |
1734 | .FN /etc/hosts | |
1735 | that should be read when the shell needs to complete a | |
1736 | hostname. | |
1737 | The list of possible hostname completions may be changed while the | |
1738 | shell is running; | |
1739 | the next time hostname completion is attempted after the | |
1740 | value is changed, | |
726f6388 | 1741 | .B bash |
f73dda09 JA |
1742 | adds the contents of the new file to the existing list. |
1743 | If | |
726f6388 | 1744 | .SM |
f73dda09 JA |
1745 | .B HOSTFILE |
1746 | is set, but has no value, \fBbash\fP attempts to read | |
1747 | .FN /etc/hosts | |
1748 | to obtain the list of possible hostname completions. | |
1749 | When | |
726f6388 | 1750 | .SM |
f73dda09 JA |
1751 | .B HOSTFILE |
1752 | is unset, the hostname list is cleared. | |
1753 | .TP | |
1754 | .B IFS | |
1755 | The | |
1756 | .I Internal Field Separator | |
1757 | that is used | |
1758 | for word splitting after expansion and to | |
1759 | split lines into words with the | |
1760 | .B read | |
1761 | builtin command. The default value is | |
1762 | ``<space><tab><newline>''. | |
1763 | .TP | |
1764 | .B IGNOREEOF | |
1765 | Controls the | |
1766 | action of an interactive shell on receipt of an | |
1767 | .SM | |
1768 | .B EOF | |
1769 | character as the sole input. If set, the value is the number of | |
1770 | consecutive | |
1771 | .SM | |
1772 | .B EOF | |
1773 | characters which must be | |
1774 | typed as the first characters on an input line before | |
1775 | .B bash | |
1776 | exits. If the variable exists but does not have a numeric value, or | |
1777 | has no value, the default value is 10. If it does not exist, | |
1778 | .SM | |
1779 | .B EOF | |
1780 | signifies the end of input to the shell. | |
1781 | .TP | |
1782 | .B INPUTRC | |
1783 | The filename for the | |
1784 | .B readline | |
1785 | startup file, overriding the default of | |
1786 | .FN ~/.inputrc | |
1787 | (see | |
1788 | .SM | |
1789 | .B READLINE | |
1790 | below). | |
726f6388 | 1791 | .TP |
ccc6cda3 JA |
1792 | .B LANG |
1793 | Used to determine the locale category for any category not specifically | |
1794 | selected with a variable starting with \fBLC_\fP. | |
1795 | .TP | |
1796 | .B LC_ALL | |
1797 | This variable overrides the value of \fBLANG\fP and any other | |
1798 | \fBLC_\fP variable specifying a locale category. | |
1799 | .TP | |
1800 | .B LC_COLLATE | |
1801 | This variable determines the collation order used when sorting the | |
cce855bc JA |
1802 | results of pathname expansion, and determines the behavior of range |
1803 | expressions, equivalence classes, and collating sequences within | |
1804 | pathname expansion and pattern matching. | |
1805 | .TP | |
1806 | .B LC_CTYPE | |
1807 | This variable determines the interpretation of characters and the | |
1808 | behavior of character classes within pathname expansion and pattern | |
1809 | matching. | |
ccc6cda3 JA |
1810 | .TP |
1811 | .B LC_MESSAGES | |
1812 | This variable determines the locale used to translate double-quoted | |
1813 | strings preceded by a \fB$\fP. | |
1814 | .TP | |
bb70624e JA |
1815 | .B LC_NUMERIC |
1816 | This variable determines the locale category used for number formatting. | |
1817 | .TP | |
28ef6c31 JA |
1818 | .B LINES |
1819 | Used by the \fBselect\fP builtin command to determine the column length | |
1820 | for printing selection lists. Automatically set upon receipt of a SIGWINCH. | |
1821 | .TP | |
f73dda09 JA |
1822 | .B MAIL |
1823 | If this parameter is set to a file name and the | |
726f6388 | 1824 | .SM |
f73dda09 JA |
1825 | .B MAILPATH |
1826 | variable is not set, | |
726f6388 | 1827 | .B bash |
f73dda09 | 1828 | informs the user of the arrival of mail in the specified file. |
726f6388 | 1829 | .TP |
f73dda09 JA |
1830 | .B MAILCHECK |
1831 | Specifies how | |
1832 | often (in seconds) | |
1833 | .B bash | |
1834 | checks for mail. The default is 60 seconds. When it is time to check | |
1835 | for mail, the shell does so before displaying the primary prompt. | |
1836 | If this variable is unset, or set to a value that is not a number | |
1837 | greater than or equal to zero, the shell disables mail checking. | |
726f6388 | 1838 | .TP |
f73dda09 JA |
1839 | .B MAILPATH |
1840 | A colon-separated list of file names to be checked for mail. | |
1841 | The message to be printed when mail arrives in a particular file | |
1842 | may be specified by separating the file name from the message with a `?'. | |
1843 | When used in the text of the message, \fB$_\fP expands to the name of | |
1844 | the current mailfile. | |
1845 | Example: | |
1846 | .RS | |
1847 | .PP | |
20587658 | 1848 | \fBMAILPATH\fP=\(aq/var/mail/bfox?"You have mail":~/shell\-mail?"$_ has mail!"\(aq |
f73dda09 JA |
1849 | .PP |
1850 | .B Bash | |
1851 | supplies a default value for this variable, but the location of the user | |
1852 | mail files that it uses is system dependent (e.g., /var/mail/\fB$USER\fP). | |
1853 | .RE | |
726f6388 | 1854 | .TP |
f73dda09 JA |
1855 | .B OPTERR |
1856 | If set to the value 1, | |
1857 | .B bash | |
1858 | displays error messages generated by the | |
1859 | .B getopts | |
1860 | builtin command (see | |
726f6388 | 1861 | .SM |
f73dda09 | 1862 | .B SHELL BUILTIN COMMANDS |
ccc6cda3 | 1863 | below). |
726f6388 | 1864 | .SM |
f73dda09 JA |
1865 | .B OPTERR |
1866 | is initialized to 1 each time the shell is invoked or a shell | |
1867 | script is executed. | |
ccc6cda3 | 1868 | .TP |
f73dda09 JA |
1869 | .B PATH |
1870 | The search path for commands. It | |
1871 | is a colon-separated list of directories in which | |
1872 | the shell looks for commands (see | |
ccc6cda3 | 1873 | .SM |
f73dda09 | 1874 | .B COMMAND EXECUTION |
d3a24ed2 CR |
1875 | below). |
1876 | A zero-length (null) directory name in the value of \fBPATH\fP indicates the | |
1877 | current directory. | |
1878 | A null directory name may appear as two adjacent colons, or as an initial | |
1879 | or trailing colon. | |
1880 | The default path is system-dependent, | |
f73dda09 JA |
1881 | and is set by the administrator who installs |
1882 | .BR bash . | |
1883 | A common value is | |
5e13499c CR |
1884 | .if t \f(CW/usr/gnu/bin:/usr/local/bin:/usr/ucb:/bin:/usr/bin\fP. |
1885 | .if n ``/usr/gnu/bin:/usr/local/bin:/usr/ucb:/bin:/usr/bin''. | |
726f6388 | 1886 | .TP |
f73dda09 JA |
1887 | .B POSIXLY_CORRECT |
1888 | If this variable is in the environment when \fBbash\fP starts, the shell | |
1889 | enters \fIposix mode\fP before reading the startup files, as if the | |
1890 | .B \-\-posix | |
1891 | invocation option had been supplied. If it is set while the shell is | |
1892 | running, \fBbash\fP enables \fIposix mode\fP, as if the command | |
1893 | .if t \f(CWset -o posix\fP | |
1894 | .if n \fIset -o posix\fP | |
1895 | had been executed. | |
726f6388 | 1896 | .TP |
f73dda09 JA |
1897 | .B PROMPT_COMMAND |
1898 | If set, the value is executed as a command prior to issuing each primary | |
1899 | prompt. | |
ccc6cda3 | 1900 | .TP |
f73dda09 JA |
1901 | .B PS1 |
1902 | The value of this parameter is expanded (see | |
1903 | .SM | |
1904 | .B PROMPTING | |
1905 | below) and used as the primary prompt string. The default value is | |
1906 | ``\fB\es\-\ev\e$ \fP''. | |
726f6388 | 1907 | .TP |
f73dda09 JA |
1908 | .B PS2 |
1909 | The value of this parameter is expanded as with | |
1910 | .B PS1 | |
1911 | and used as the secondary prompt string. The default is | |
1912 | ``\fB> \fP''. | |
1913 | .TP | |
1914 | .B PS3 | |
1915 | The value of this parameter is used as the prompt for the | |
1916 | .B select | |
1917 | command (see | |
726f6388 | 1918 | .SM |
f73dda09 JA |
1919 | .B SHELL GRAMMAR |
1920 | above). | |
726f6388 | 1921 | .TP |
f73dda09 JA |
1922 | .B PS4 |
1923 | The value of this parameter is expanded as with | |
1924 | .B PS1 | |
1925 | and the value is printed before each command | |
726f6388 | 1926 | .B bash |
f73dda09 | 1927 | displays during an execution trace. The first character of |
bb70624e | 1928 | .SM |
f73dda09 JA |
1929 | .B PS4 |
1930 | is replicated multiple times, as necessary, to indicate multiple | |
1931 | levels of indirection. The default is ``\fB+ \fP''. | |
1932 | .TP | |
61deeb13 CR |
1933 | .B SHELL |
1934 | The full pathname to the shell is kept in this environment variable. | |
1935 | If it is not set when the shell starts, | |
1936 | .B bash | |
1937 | assigns to it the full pathname of the current user's login shell. | |
1938 | .TP | |
f73dda09 JA |
1939 | .B TIMEFORMAT |
1940 | The value of this parameter is used as a format string specifying | |
1941 | how the timing information for pipelines prefixed with the | |
1942 | .B time | |
1943 | reserved word should be displayed. | |
1944 | The \fB%\fP character introduces an escape sequence that is | |
1945 | expanded to a time value or other information. | |
1946 | The escape sequences and their meanings are as follows; the | |
1947 | braces denote optional portions. | |
1948 | .sp .5 | |
1949 | .RS | |
1950 | .PD 0 | |
1951 | .TP 10 | |
1952 | .B %% | |
1953 | A literal \fB%\fP. | |
1954 | .TP | |
1955 | .B %[\fIp\fP][l]R | |
1956 | The elapsed time in seconds. | |
1957 | .TP | |
1958 | .B %[\fIp\fP][l]U | |
1959 | The number of CPU seconds spent in user mode. | |
1960 | .TP | |
1961 | .B %[\fIp\fP][l]S | |
1962 | The number of CPU seconds spent in system mode. | |
1963 | .TP | |
1964 | .B %P | |
1965 | The CPU percentage, computed as (%U + %S) / %R. | |
1966 | .PD | |
1967 | .RE | |
1968 | .IP | |
1969 | The optional \fIp\fP is a digit specifying the \fIprecision\fP, | |
1970 | the number of fractional digits after a decimal point. | |
1971 | A value of 0 causes no decimal point or fraction to be output. | |
1972 | At most three places after the decimal point may be specified; | |
1973 | values of \fIp\fP greater than 3 are changed to 3. | |
1974 | If \fIp\fP is not specified, the value 3 is used. | |
1975 | .IP | |
1976 | The optional \fBl\fP specifies a longer format, including | |
1977 | minutes, of the form \fIMM\fPm\fISS\fP.\fIFF\fPs. | |
1978 | The value of \fIp\fP determines whether or not the fraction is | |
1979 | included. | |
1980 | .IP | |
1981 | If this variable is not set, \fBbash\fP acts as if it had the | |
20587658 | 1982 | value \fB$\(aq\enreal\et%3lR\enuser\et%3lU\ensys\t%3lS\(aq\fP. |
f73dda09 JA |
1983 | If the value is null, no timing information is displayed. |
1984 | A trailing newline is added when the format string is displayed. | |
1985 | .TP | |
1986 | .B TMOUT | |
7117c2d2 JA |
1987 | If set to a value greater than zero, \fBTMOUT\fP is treated as the |
1988 | default timeout for the \fBread\fP builtin. | |
1989 | The \fBselect\fP command terminates if input does not arrive | |
1990 | after \fBTMOUT\fP seconds when input is coming from a terminal. | |
1991 | In an interactive shell, the value is interpreted as the | |
f73dda09 JA |
1992 | number of seconds to wait for input after issuing the primary prompt. |
1993 | .B Bash | |
1994 | terminates after waiting for that number of seconds if input does | |
1995 | not arrive. | |
726f6388 | 1996 | .TP |
1569c106 CR |
1997 | .B TMPDIR |
1998 | If set, \fBBash\fP uses its value as the name of a directory in which | |
1999 | \fBBash\fP creates temporary files for the shell's use. | |
2000 | .TP | |
726f6388 JA |
2001 | .B auto_resume |
2002 | This variable controls how the shell interacts with the user and | |
2003 | job control. If this variable is set, single word simple | |
2004 | commands without redirections are treated as candidates for resumption | |
2005 | of an existing stopped job. There is no ambiguity allowed; if there is | |
2006 | more than one job beginning with the string typed, the job most recently | |
2007 | accessed is selected. The | |
2008 | .I name | |
2009 | of a stopped job, in this context, is the command line used to | |
2010 | start it. | |
2011 | If set to the value | |
2012 | .IR exact , | |
2013 | the string supplied must match the name of a stopped job exactly; | |
2014 | if set to | |
2015 | .IR substring , | |
2016 | the string supplied needs to match a substring of the name of a | |
2017 | stopped job. The | |
2018 | .I substring | |
2019 | value provides functionality analogous to the | |
2020 | .B %? | |
ccc6cda3 | 2021 | job identifier (see |
726f6388 JA |
2022 | .SM |
2023 | .B JOB CONTROL | |
2024 | below). If set to any other value, the supplied string must | |
2025 | be a prefix of a stopped job's name; this provides functionality | |
22e63b05 | 2026 | analogous to the \fB%\fP\fIstring\fP job identifier. |
bb70624e | 2027 | .TP |
f73dda09 JA |
2028 | .B histchars |
2029 | The two or three characters which control history expansion | |
2030 | and tokenization (see | |
2031 | .SM | |
2032 | .B HISTORY EXPANSION | |
2033 | below). The first character is the \fIhistory expansion\fP character, | |
2034 | the character which signals the start of a history | |
2035 | expansion, normally `\fB!\fP'. | |
2036 | The second character is the \fIquick substitution\fP | |
2037 | character, which is used as shorthand for re-running the previous | |
2038 | command entered, substituting one string for another in the command. | |
2039 | The default is `\fB^\fP'. | |
2040 | The optional third character is the character | |
2041 | which indicates that the remainder of the line is a comment when found | |
2042 | as the first character of a word, normally `\fB#\fP'. The history | |
2043 | comment character causes history substitution to be skipped for the | |
2044 | remaining words on the line. It does not necessarily cause the shell | |
2045 | parser to treat the rest of the line as a comment. | |
726f6388 | 2046 | .PD |
ccc6cda3 JA |
2047 | .SS Arrays |
2048 | .B Bash | |
2049 | provides one-dimensional array variables. Any variable may be used as | |
2050 | an array; the | |
2051 | .B declare | |
2052 | builtin will explicitly declare an array. There is no maximum | |
2053 | limit on the size of an array, nor any requirement that members | |
2054 | be indexed or assigned contiguously. Arrays are indexed using | |
2055 | integers and are zero-based. | |
2056 | .PP | |
2057 | An array is created automatically if any variable is assigned to using | |
2058 | the syntax \fIname\fP[\fIsubscript\fP]=\fIvalue\fP. The | |
2059 | .I subscript | |
2060 | is treated as an arithmetic expression that must evaluate to a number | |
2061 | greater than or equal to zero. To explicitly declare an array, use | |
2062 | .B declare \-a \fIname\fP | |
2063 | (see | |
2064 | .SM | |
2065 | .B SHELL BUILTIN COMMANDS | |
2066 | below). | |
2067 | .B declare \-a \fIname\fP[\fIsubscript\fP] | |
2068 | is also accepted; the \fIsubscript\fP is ignored. Attributes may be | |
2069 | specified for an array variable using the | |
2070 | .B declare | |
2071 | and | |
2072 | .B readonly | |
2073 | builtins. Each attribute applies to all members of an array. | |
2074 | .PP | |
2075 | Arrays are assigned to using compound assignments of the form | |
2076 | \fIname\fP=\fB(\fPvalue\fI1\fP ... value\fIn\fP\fB)\fP, where each | |
2077 | \fIvalue\fP is of the form [\fIsubscript\fP]=\fIstring\fP. Only | |
2078 | \fIstring\fP is required. If | |
2079 | the optional brackets and subscript are supplied, that index is assigned to; | |
2080 | otherwise the index of the element assigned is the last index assigned | |
2081 | to by the statement plus one. Indexing starts at zero. | |
2082 | This syntax is also accepted by the | |
2083 | .B declare | |
2084 | builtin. Individual array elements may be assigned to using the | |
2085 | \fIname\fP[\fIsubscript\fP]=\fIvalue\fP syntax introduced above. | |
2086 | .PP | |
2087 | Any element of an array may be referenced using | |
2088 | ${\fIname\fP[\fIsubscript\fP]}. The braces are required to avoid | |
2089 | conflicts with pathname expansion. If | |
2090 | \fIsubscript\fP is \fB@\fP or \fB*\fP, the word expands to | |
2091 | all members of \fIname\fP. These subscripts differ only when the | |
2092 | word appears within double quotes. If the word is double-quoted, | |
2093 | ${\fIname\fP[*]} expands to a single | |
2094 | word with the value of each array member separated by the first | |
2095 | character of the | |
2096 | .SM | |
2097 | .B IFS | |
2098 | special variable, and ${\fIname\fP[@]} expands each element of | |
2099 | \fIname\fP to a separate word. When there are no array members, | |
be7d8f2d CR |
2100 | ${\fIname\fP[@]} expands to nothing. |
2101 | If the double-quoted expansion occurs within a word, the expansion of | |
2102 | the first parameter is joined with the beginning part of the original | |
2103 | word, and the expansion of the last parameter is joined with the last | |
2104 | part of the original word. | |
2105 | This is analogous to the expansion | |
ccc6cda3 JA |
2106 | of the special parameters \fB*\fP and \fB@\fP (see |
2107 | .B Special Parameters | |
2108 | above). ${#\fIname\fP[\fIsubscript\fP]} expands to the length of | |
2109 | ${\fIname\fP[\fIsubscript\fP]}. If \fIsubscript\fP is \fB*\fP or | |
2110 | \fB@\fP, the expansion is the number of elements in the array. | |
2111 | Referencing an array variable without a subscript is equivalent to | |
2112 | referencing element zero. | |
2113 | .PP | |
2114 | The | |
2115 | .B unset | |
bb70624e | 2116 | builtin is used to destroy arrays. \fBunset\fP \fIname\fP[\fIsubscript\fP] |
ccc6cda3 | 2117 | destroys the array element at index \fIsubscript\fP. |
a82a04b3 CR |
2118 | Care must be taken to avoid unwanted side effects caused by filename |
2119 | generation. | |
ccc6cda3 JA |
2120 | \fBunset\fP \fIname\fP, where \fIname\fP is an array, or |
2121 | \fBunset\fP \fIname\fP[\fIsubscript\fP], where | |
2122 | \fIsubscript\fP is \fB*\fP or \fB@\fP, removes the entire array. | |
2123 | .PP | |
2124 | The | |
2125 | .BR declare , | |
2126 | .BR local , | |
2127 | and | |
2128 | .B readonly | |
2129 | builtins each accept a | |
2130 | .B \-a | |
2131 | option to specify an array. The | |
2132 | .B read | |
2133 | builtin accepts a | |
2134 | .B \-a | |
2135 | option to assign a list of words read from the standard input | |
2136 | to an array. The | |
2137 | .B set | |
2138 | and | |
2139 | .B declare | |
2140 | builtins display array values in a way that allows them to be | |
2141 | reused as assignments. | |
726f6388 JA |
2142 | .SH EXPANSION |
2143 | Expansion is performed on the command line after it has been split into | |
2144 | words. There are seven kinds of expansion performed: | |
2145 | .IR "brace expansion" , | |
2146 | .IR "tilde expansion" , | |
2147 | .IR "parameter and variable expansion" , | |
2148 | .IR "command substitution" , | |
2149 | .IR "arithmetic expansion" , | |
2150 | .IR "word splitting" , | |
2151 | and | |
2152 | .IR "pathname expansion" . | |
2153 | .PP | |
2154 | The order of expansions is: brace expansion, tilde expansion, | |
ccc6cda3 JA |
2155 | parameter, variable and arithmetic expansion and |
2156 | command substitution | |
2157 | (done in a left-to-right fashion), word splitting, and pathname | |
726f6388 JA |
2158 | expansion. |
2159 | .PP | |
2160 | On systems that can support it, there is an additional expansion | |
2161 | available: \fIprocess substitution\fP. | |
2162 | .PP | |
2163 | Only brace expansion, word splitting, and pathname expansion | |
2164 | can change the number of words of the expansion; other expansions | |
2165 | expand a single word to a single word. | |
ccc6cda3 | 2166 | The only exceptions to this are the expansions of |
cce855bc | 2167 | "\fB$@\fP" and "\fB${\fP\fIname\fP\fB[@]}\fP" |
ccc6cda3 | 2168 | as explained above (see |
726f6388 JA |
2169 | .SM |
2170 | .BR PARAMETERS ). | |
2171 | .SS Brace Expansion | |
2172 | .PP | |
2173 | .I "Brace expansion" | |
2174 | is a mechanism by which arbitrary strings | |
2175 | may be generated. This mechanism is similar to | |
2176 | \fIpathname expansion\fP, but the filenames generated | |
2177 | need not exist. Patterns to be brace expanded take | |
2178 | the form of an optional | |
2179 | .IR preamble , | |
d3a24ed2 CR |
2180 | followed by either a series of comma-separated strings or |
2181 | a sequence expression between a pair of braces, followed by | |
2182 | an optional | |
cce855bc | 2183 | .IR postscript . |
ccc6cda3 | 2184 | The preamble is prefixed to each string contained |
cce855bc | 2185 | within the braces, and the postscript is then appended |
726f6388 JA |
2186 | to each resulting string, expanding left to right. |
2187 | .PP | |
2188 | Brace expansions may be nested. The results of each expanded | |
2189 | string are not sorted; left to right order is preserved. | |
2190 | For example, a\fB{\fPd,c,b\fB}\fPe expands into `ade ace abe'. | |
2191 | .PP | |
d3a24ed2 CR |
2192 | A sequence expression takes the form \fB{\fP\fIx\fP\fB..\fP\fIy\fP\fB}\fP, |
2193 | where \fIx\fP and \fIy\fP are either integers or single characters. | |
2194 | When integers are supplied, the expression expands to each number between | |
2195 | \fIx\fP and \fIy\fP, inclusive. | |
2196 | When characters are supplied, the expression expands to each character | |
2197 | lexicographically between \fIx\fP and \fIy\fP, inclusive. Note that | |
2198 | both \fIx\fP and \fIy\fP must be of the same type. | |
2199 | .PP | |
726f6388 JA |
2200 | Brace expansion is performed before any other expansions, |
2201 | and any characters special to other expansions are preserved | |
2202 | in the result. It is strictly textual. | |
2203 | .B Bash | |
2204 | does not apply any syntactic interpretation to the context of the | |
2205 | expansion or the text between the braces. | |
2206 | .PP | |
2207 | A correctly-formed brace expansion must contain unquoted opening | |
d3a24ed2 CR |
2208 | and closing braces, and at least one unquoted comma or a valid |
2209 | sequence expression. | |
726f6388 | 2210 | Any incorrectly formed brace expansion is left unchanged. |
ccc6cda3 JA |
2211 | A \fB{\fP or \fB,\fP may be quoted with a backslash to prevent its |
2212 | being considered part of a brace expression. | |
bb70624e JA |
2213 | To avoid conflicts with parameter expansion, the string \fB${\fP |
2214 | is not considered eligible for brace expansion. | |
726f6388 JA |
2215 | .PP |
2216 | This construct is typically used as shorthand when the common | |
2217 | prefix of the strings to be generated is longer than in the | |
2218 | above example: | |
2219 | .RS | |
2220 | .PP | |
2221 | mkdir /usr/local/src/bash/{old,new,dist,bugs} | |
2222 | .RE | |
2223 | or | |
2224 | .RS | |
2225 | chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}} | |
2226 | .RE | |
2227 | .PP | |
2228 | Brace expansion introduces a slight incompatibility with | |
ccc6cda3 JA |
2229 | historical versions of |
2230 | .BR sh . | |
726f6388 JA |
2231 | .B sh |
2232 | does not treat opening or closing braces specially when they | |
2233 | appear as part of a word, and preserves them in the output. | |
2234 | .B Bash | |
2235 | removes braces from words as a consequence of brace | |
2236 | expansion. For example, a word entered to | |
2237 | .B sh | |
2238 | as \fIfile{1,2}\fP | |
2239 | appears identically in the output. The same word is | |
2240 | output as | |
2241 | .I file1 file2 | |
2242 | after expansion by | |
2243 | .BR bash . | |
2244 | If strict compatibility with | |
2245 | .B sh | |
2246 | is desired, start | |
2247 | .B bash | |
2248 | with the | |
ccc6cda3 JA |
2249 | .B +B |
2250 | option or disable brace expansion with the | |
2251 | .B +B | |
726f6388 JA |
2252 | option to the |
2253 | .B set | |
2254 | command (see | |
2255 | .SM | |
2256 | .B SHELL BUILTIN COMMANDS | |
2257 | below). | |
2258 | .SS Tilde Expansion | |
2259 | .PP | |
cce855bc JA |
2260 | If a word begins with an unquoted tilde character (`\fB~\fP'), all of |
2261 | the characters preceding the first unquoted slash (or all characters, | |
2262 | if there is no unquoted slash) are considered a \fItilde-prefix\fP. | |
2263 | If none of the characters in the tilde-prefix are quoted, the | |
2264 | characters in the tilde-prefix following the tilde are treated as a | |
2265 | possible \fIlogin name\fP. | |
2266 | If this login name is the null string, the tilde is replaced with the | |
2267 | value of the shell parameter | |
726f6388 JA |
2268 | .SM |
2269 | .BR HOME . | |
2270 | If | |
2271 | .SM | |
2272 | .B HOME | |
cce855bc JA |
2273 | is unset, the home directory of the user executing the shell is |
2274 | substituted instead. | |
2275 | Otherwise, the tilde-prefix is replaced with the home directory | |
2276 | associated with the specified login name. | |
726f6388 | 2277 | .PP |
cce855bc | 2278 | If the tilde-prefix is a `~+', the value of the shell variable |
726f6388 JA |
2279 | .SM |
2280 | .B PWD | |
cce855bc JA |
2281 | replaces the tilde-prefix. |
2282 | If the tilde-prefix is a `~\-', the value of the shell variable | |
2283 | .SM | |
2284 | .BR OLDPWD , | |
2285 | if it is set, is substituted. | |
2286 | If the characters following the tilde in the tilde-prefix consist | |
2287 | of a number \fIN\fP, optionally prefixed | |
2288 | by a `+' or a `\-', the tilde-prefix is replaced with the corresponding | |
2289 | element from the directory stack, as it would be displayed by the | |
2290 | .B dirs | |
2291 | builtin invoked with the tilde-prefix as an argument. | |
2292 | If the characters following the tilde in the tilde-prefix consist of a | |
2293 | number without a leading `+' or `\-', `+' is assumed. | |
2294 | .PP | |
2295 | If the login name is invalid, or the tilde expansion fails, the word | |
2296 | is unchanged. | |
726f6388 | 2297 | .PP |
cce855bc JA |
2298 | Each variable assignment is checked for unquoted tilde-prefixes immediately |
2299 | following a | |
726f6388 | 2300 | .B : |
43df7bbb | 2301 | or the first |
726f6388 | 2302 | .BR = . |
cce855bc JA |
2303 | In these cases, tilde expansion is also performed. |
2304 | Consequently, one may use file names with tildes in assignments to | |
726f6388 JA |
2305 | .SM |
2306 | .BR PATH , | |
2307 | .SM | |
2308 | .BR MAILPATH , | |
2309 | and | |
2310 | .SM | |
2311 | .BR CDPATH , | |
2312 | and the shell assigns the expanded value. | |
2313 | .SS Parameter Expansion | |
2314 | .PP | |
2315 | The `\fB$\fP' character introduces parameter expansion, | |
2316 | command substitution, or arithmetic expansion. The parameter name | |
2317 | or symbol to be expanded may be enclosed in braces, which | |
2318 | are optional but serve to protect the variable to be expanded from | |
2319 | characters immediately following it which could be | |
2320 | interpreted as part of the name. | |
2321 | .PP | |
cce855bc JA |
2322 | When braces are used, the matching ending brace is the first `\fB}\fP' |
2323 | not escaped by a backslash or within a quoted string, and not within an | |
f75912ae | 2324 | embedded arithmetic expansion, command substitution, or parameter |
cce855bc JA |
2325 | expansion. |
2326 | .PP | |
726f6388 JA |
2327 | .PD 0 |
2328 | .TP | |
2329 | ${\fIparameter\fP} | |
2330 | The value of \fIparameter\fP is substituted. The braces are required | |
2331 | when | |
2332 | .I parameter | |
2333 | is a positional parameter with more than one digit, | |
2334 | or when | |
2335 | .I parameter | |
2336 | is followed by a character which is not to be | |
2337 | interpreted as part of its name. | |
2338 | .PD | |
2339 | .PP | |
ccc6cda3 JA |
2340 | If the first character of \fIparameter\fP is an exclamation point, |
2341 | a level of variable indirection is introduced. | |
2342 | \fBBash\fP uses the value of the variable formed from the rest of | |
2343 | \fIparameter\fP as the name of the variable; this variable is then | |
bb70624e | 2344 | expanded and that value is used in the rest of the substitution, rather |
ccc6cda3 JA |
2345 | than the value of \fIparameter\fP itself. |
2346 | This is known as \fIindirect expansion\fP. | |
d3a24ed2 CR |
2347 | The exceptions to this are the expansions of ${!\fIprefix\fP*} and |
2348 | ${\fB!\fP\fIname\fP[\fI@\fP]} described below. | |
2349 | The exclamation point must immediately follow the left brace in order to | |
2350 | introduce indirection. | |
ccc6cda3 | 2351 | .PP |
726f6388 JA |
2352 | In each of the cases below, \fIword\fP is subject to tilde expansion, |
2353 | parameter expansion, command substitution, and arithmetic expansion. | |
ccc6cda3 JA |
2354 | When not performing substring expansion, \fBbash\fP tests for a parameter |
2355 | that is unset or null; omitting the colon results in a test only for a | |
2356 | parameter that is unset. | |
726f6388 JA |
2357 | .PP |
2358 | .PD 0 | |
2359 | .TP | |
2360 | ${\fIparameter\fP\fB:\-\fP\fIword\fP} | |
2361 | \fBUse Default Values\fP. If | |
2362 | .I parameter | |
2363 | is unset or null, the expansion of | |
2364 | .I word | |
2365 | is substituted. Otherwise, the value of | |
2366 | .I parameter | |
2367 | is substituted. | |
2368 | .TP | |
2369 | ${\fIparameter\fP\fB:=\fP\fIword\fP} | |
2370 | \fBAssign Default Values\fP. | |
2371 | If | |
2372 | .I parameter | |
2373 | is unset or null, the expansion of | |
2374 | .I word | |
2375 | is assigned to | |
2376 | .IR parameter . | |
2377 | The value of | |
2378 | .I parameter | |
2379 | is then substituted. Positional parameters and special parameters may | |
2380 | not be assigned to in this way. | |
2381 | .TP | |
2382 | ${\fIparameter\fP\fB:?\fP\fIword\fP} | |
2383 | \fBDisplay Error if Null or Unset\fP. | |
2384 | If | |
2385 | .I parameter | |
2386 | is null or unset, the expansion of \fIword\fP (or a message to that effect | |
2387 | if | |
2388 | .I word | |
2389 | is not present) is written to the standard error and the shell, if it | |
2390 | is not interactive, exits. Otherwise, the value of \fIparameter\fP is | |
2391 | substituted. | |
2392 | .TP | |
2393 | ${\fIparameter\fP\fB:+\fP\fIword\fP} | |
2394 | \fBUse Alternate Value\fP. | |
2395 | If | |
2396 | .I parameter | |
2397 | is null or unset, nothing is substituted, otherwise the expansion of | |
2398 | .I word | |
2399 | is substituted. | |
2400 | .TP | |
ccc6cda3 | 2401 | ${\fIparameter\fP\fB:\fP\fIoffset\fP} |
7117c2d2 | 2402 | .PD 0 |
ccc6cda3 JA |
2403 | .TP |
2404 | ${\fIparameter\fP\fB:\fP\fIoffset\fP\fB:\fP\fIlength\fP} | |
2405 | .PD | |
2406 | \fBSubstring Expansion.\fP | |
bb70624e JA |
2407 | Expands to up to \fIlength\fP characters of \fIparameter\fP |
2408 | starting at the character specified by \fIoffset\fP. | |
ccc6cda3 | 2409 | If \fIlength\fP is omitted, expands to the substring of |
bb70624e | 2410 | \fIparameter\fP starting at the character specified by \fIoffset\fP. |
ccc6cda3 JA |
2411 | \fIlength\fP and \fIoffset\fP are arithmetic expressions (see |
2412 | .SM | |
2413 | .B | |
2414 | ARITHMETIC EVALUATION | |
2415 | below). | |
2416 | \fIlength\fP must evaluate to a number greater than or equal to zero. | |
2417 | If \fIoffset\fP evaluates to a number less than zero, the value | |
2418 | is used as an offset from the end of the value of \fIparameter\fP. | |
2419 | If \fIparameter\fP is \fB@\fP, the result is \fIlength\fP positional | |
2420 | parameters beginning at \fIoffset\fP. | |
2421 | If \fIparameter\fP is an array name indexed by @ or *, | |
2422 | the result is the \fIlength\fP | |
2423 | members of the array beginning with ${\fIparameter\fP[\fIoffset\fP]}. | |
ec2199bd CR |
2424 | A negative \fIoffset\fP is taken relative to one greater than the maximum |
2425 | index of the specified array. | |
2426 | Note that a negative offset must be separated from the colon by at least | |
2427 | one space to avoid being confused with the :- expansion. | |
cce855bc JA |
2428 | Substring indexing is zero-based unless the positional parameters |
2429 | are used, in which case the indexing starts at 1. | |
ccc6cda3 | 2430 | .TP |
bb70624e | 2431 | ${\fB!\fP\fIprefix\fP\fB*\fP} |
d3a24ed2 CR |
2432 | .PD 0 |
2433 | .TP | |
2434 | ${\fB!\fP\fIprefix\fP\fB@\fP} | |
2435 | .PD | |
bb70624e JA |
2436 | Expands to the names of variables whose names begin with \fIprefix\fP, |
2437 | separated by the first character of the | |
2438 | .SM | |
2439 | .B IFS | |
2440 | special variable. | |
2441 | .TP | |
d3a24ed2 CR |
2442 | ${\fB!\fP\fIname\fP[\fI@\fP]} |
2443 | .PD 0 | |
2444 | .TP | |
2445 | ${\fB!\fP\fIname\fP[\fI*\fP]} | |
2446 | .PD | |
2447 | If \fIname\fP is an array variable, expands to the list of array indices | |
2448 | (keys) assigned in \fIname\fP. | |
2449 | If \fIname\fP is not an array, expands to 0 if \fIname\fP is set and null | |
2450 | otherwise. | |
2451 | When \fI@\fP is used and the expansion appears within double quotes, each | |
2452 | key expands to a separate word. | |
2453 | .TP | |
726f6388 JA |
2454 | ${\fB#\fP\fIparameter\fP} |
2455 | The length in characters of the value of \fIparameter\fP is substituted. | |
ccc6cda3 JA |
2456 | If |
2457 | .I parameter | |
2458 | is | |
726f6388 JA |
2459 | .B * |
2460 | or | |
2461 | .BR @ , | |
cce855bc | 2462 | the value substituted is the number of positional parameters. |
ccc6cda3 JA |
2463 | If |
2464 | .I parameter | |
2465 | is an array name subscripted by | |
726f6388 | 2466 | .B * |
ccc6cda3 JA |
2467 | or |
2468 | .BR @ , | |
cce855bc | 2469 | the value substituted is the number of elements in the array. |
726f6388 | 2470 | .TP |
726f6388 | 2471 | ${\fIparameter\fP\fB#\fP\fIword\fP} |
7117c2d2 | 2472 | .PD 0 |
726f6388 JA |
2473 | .TP |
2474 | ${\fIparameter\fP\fB##\fP\fIword\fP} | |
2475 | .PD | |
2476 | The | |
2477 | .I word | |
2478 | is expanded to produce a pattern just as in pathname | |
2479 | expansion. If the pattern matches the beginning of | |
2480 | the value of | |
2481 | .IR parameter , | |
cce855bc | 2482 | then the result of the expansion is the expanded value of |
726f6388 | 2483 | .I parameter |
ccc6cda3 JA |
2484 | with the shortest matching pattern (the ``\fB#\fP'' case) or the |
2485 | longest matching pattern (the ``\fB##\fP'' case) deleted. | |
2486 | If | |
2487 | .I parameter | |
2488 | is | |
2489 | .B @ | |
2490 | or | |
2491 | .BR * , | |
2492 | the pattern removal operation is applied to each positional | |
2493 | parameter in turn, and the expansion is the resultant list. | |
2494 | If | |
2495 | .I parameter | |
2496 | is an array variable subscripted with | |
2497 | .B @ | |
2498 | or | |
2499 | .BR * , | |
2500 | the pattern removal operation is applied to each member of the | |
2501 | array in turn, and the expansion is the resultant list. | |
726f6388 | 2502 | .TP |
726f6388 | 2503 | ${\fIparameter\fP\fB%\fP\fIword\fP} |
7117c2d2 | 2504 | .PD 0 |
726f6388 JA |
2505 | .TP |
2506 | ${\fIparameter\fP\fB%%\fP\fIword\fP} | |
2507 | .PD | |
2508 | The \fIword\fP is expanded to produce a pattern just as in | |
ccc6cda3 | 2509 | pathname expansion. |
cce855bc | 2510 | If the pattern matches a trailing portion of the expanded value of |
726f6388 | 2511 | .IR parameter , |
cce855bc | 2512 | then the result of the expansion is the expanded value of |
726f6388 | 2513 | .I parameter |
ccc6cda3 JA |
2514 | with the shortest matching pattern (the ``\fB%\fP'' case) or the |
2515 | longest matching pattern (the ``\fB%%\fP'' case) deleted. | |
2516 | If | |
2517 | .I parameter | |
2518 | is | |
2519 | .B @ | |
2520 | or | |
2521 | .BR * , | |
2522 | the pattern removal operation is applied to each positional | |
2523 | parameter in turn, and the expansion is the resultant list. | |
2524 | If | |
2525 | .I parameter | |
2526 | is an array variable subscripted with | |
2527 | .B @ | |
2528 | or | |
2529 | .BR * , | |
2530 | the pattern removal operation is applied to each member of the | |
2531 | array in turn, and the expansion is the resultant list. | |
2532 | .TP | |
ccc6cda3 | 2533 | ${\fIparameter\fP\fB/\fP\fIpattern\fP\fB/\fP\fIstring\fP} |
ccc6cda3 JA |
2534 | The \fIpattern\fP is expanded to produce a pattern just as in |
2535 | pathname expansion. | |
2536 | \fIParameter\fP is expanded and the longest match of \fIpattern\fP | |
2537 | against its value is replaced with \fIstring\fP. | |
dc8fbaf9 CR |
2538 | If \Ipattern\fP begins with \fB/\fP, all matches of \fIpattern\fP are |
2539 | replaced with \fIstring\fP. Normally only the first match is replaced. | |
ccc6cda3 | 2540 | If \fIpattern\fP begins with \fB#\fP, it must match at the beginning |
b72432fd | 2541 | of the expanded value of \fIparameter\fP. |
ccc6cda3 | 2542 | If \fIpattern\fP begins with \fB%\fP, it must match at the end |
b72432fd | 2543 | of the expanded value of \fIparameter\fP. |
ccc6cda3 JA |
2544 | If \fIstring\fP is null, matches of \fIpattern\fP are deleted |
2545 | and the \fB/\fP following \fIpattern\fP may be omitted. | |
2546 | If | |
2547 | .I parameter | |
2548 | is | |
2549 | .B @ | |
2550 | or | |
2551 | .BR * , | |
2552 | the substitution operation is applied to each positional | |
2553 | parameter in turn, and the expansion is the resultant list. | |
2554 | If | |
2555 | .I parameter | |
2556 | is an array variable subscripted with | |
2557 | .B @ | |
2558 | or | |
2559 | .BR * , | |
2560 | the substitution operation is applied to each member of the | |
2561 | array in turn, and the expansion is the resultant list. | |
726f6388 JA |
2562 | .SS Command Substitution |
2563 | .PP | |
cce855bc | 2564 | \fICommand substitution\fP allows the output of a command to replace |
726f6388 JA |
2565 | the command name. There are two forms: |
2566 | .PP | |
2567 | .RS | |
2568 | .PP | |
2569 | \fB$(\fP\fIcommand\fP\|\fB)\fP | |
2570 | .RE | |
2571 | or | |
2572 | .RS | |
2573 | \fB`\fP\fIcommand\fP\fB`\fP | |
2574 | .RE | |
2575 | .PP | |
ccc6cda3 | 2576 | .B Bash |
726f6388 JA |
2577 | performs the expansion by executing \fIcommand\fP and |
2578 | replacing the command substitution with the standard output of the | |
2579 | command, with any trailing newlines deleted. | |
cce855bc JA |
2580 | Embedded newlines are not deleted, but they may be removed during |
2581 | word splitting. | |
2582 | The command substitution \fB$(cat \fIfile\fP)\fR can be replaced by | |
2583 | the equivalent but faster \fB$(< \fIfile\fP)\fR. | |
726f6388 | 2584 | .PP |
ccc6cda3 | 2585 | When the old-style backquote form of substitution is used, |
726f6388 JA |
2586 | backslash retains its literal meaning except when followed by |
2587 | .BR $ , | |
2588 | .BR ` , | |
2589 | or | |
2590 | .BR \e . | |
cce855bc JA |
2591 | The first backquote not preceded by a backslash terminates the |
2592 | command substitution. | |
726f6388 JA |
2593 | When using the $(\^\fIcommand\fP\|) form, all characters between the |
2594 | parentheses make up the command; none are treated specially. | |
2595 | .PP | |
cce855bc | 2596 | Command substitutions may be nested. To nest when using the backquoted form, |
726f6388 JA |
2597 | escape the inner backquotes with backslashes. |
2598 | .PP | |
2599 | If the substitution appears within double quotes, word splitting and | |
2600 | pathname expansion are not performed on the results. | |
2601 | .SS Arithmetic Expansion | |
2602 | .PP | |
2603 | Arithmetic expansion allows the evaluation of an arithmetic expression | |
ccc6cda3 | 2604 | and the substitution of the result. The format for arithmetic expansion is: |
726f6388 JA |
2605 | .RS |
2606 | .PP | |
726f6388 JA |
2607 | \fB$((\fP\fIexpression\fP\fB))\fP |
2608 | .RE | |
2609 | .PP | |
2610 | The | |
2611 | .I expression | |
2612 | is treated as if it were within double quotes, but a double quote | |
ccc6cda3 JA |
2613 | inside the parentheses is not treated specially. |
2614 | All tokens in the expression undergo parameter expansion, string | |
2615 | expansion, command substitution, and quote removal. | |
d3a24ed2 | 2616 | Arithmetic expansions may be nested. |
726f6388 JA |
2617 | .PP |
2618 | The evaluation is performed according to the rules listed below under | |
2619 | .SM | |
2620 | .BR "ARITHMETIC EVALUATION" . | |
2621 | If | |
2622 | .I expression | |
2623 | is invalid, | |
2624 | .B bash | |
2625 | prints a message indicating failure and no substitution occurs. | |
2626 | .SS Process Substitution | |
2627 | .PP | |
2628 | \fIProcess substitution\fP is supported on systems that support named | |
2629 | pipes (\fIFIFOs\fP) or the \fB/dev/fd\fP method of naming open files. | |
2630 | It takes the form of | |
2631 | \fB<(\fP\fIlist\^\fP\fB)\fP | |
2632 | or | |
2633 | \fB>(\fP\fIlist\^\fP\fB)\fP. | |
2634 | The process \fIlist\fP is run with its input or output connected to a | |
2635 | \fIFIFO\fP or some file in \fB/dev/fd\fP. The name of this file is | |
2636 | passed as an argument to the current command as the result of the | |
2637 | expansion. If the \fB>(\fP\fIlist\^\fP\fB)\fP form is used, writing to | |
2638 | the file will provide input for \fIlist\fP. If the | |
2639 | \fB<(\fP\fIlist\^\fP\fB)\fP form is used, the file passed as an | |
2640 | argument should be read to obtain the output of \fIlist\fP. | |
2641 | .PP | |
bb70624e | 2642 | When available, process substitution is performed |
ccc6cda3 JA |
2643 | simultaneously with parameter and variable expansion, |
2644 | command substitution, | |
2645 | and arithmetic expansion. | |
726f6388 JA |
2646 | .SS Word Splitting |
2647 | .PP | |
2648 | The shell scans the results of | |
2649 | parameter expansion, | |
2650 | command substitution, | |
2651 | and | |
2652 | arithmetic expansion | |
2653 | that did not occur within double quotes for | |
2654 | .IR "word splitting" . | |
2655 | .PP | |
2656 | The shell treats each character of | |
2657 | .SM | |
2658 | .B IFS | |
2659 | as a delimiter, and splits the results of the other | |
ccc6cda3 | 2660 | expansions into words on these characters. If |
726f6388 JA |
2661 | .SM |
2662 | .B IFS | |
ccc6cda3 JA |
2663 | is unset, or its |
2664 | value is exactly | |
726f6388 JA |
2665 | .BR <space><tab><newline> , |
2666 | the default, then | |
2667 | any sequence of | |
2668 | .SM | |
2669 | .B IFS | |
2670 | characters serves to delimit words. If | |
2671 | .SM | |
2672 | .B IFS | |
2673 | has a value other than the default, then sequences of | |
2674 | the whitespace characters | |
2675 | .B space | |
2676 | and | |
2677 | .B tab | |
2678 | are ignored at the beginning and end of the | |
2679 | word, as long as the whitespace character is in the | |
2680 | value of | |
2681 | .SM | |
2682 | .BR IFS | |
2683 | (an | |
2684 | .SM | |
2685 | .B IFS | |
2686 | whitespace character). | |
2687 | Any character in | |
2688 | .SM | |
2689 | .B IFS | |
2690 | that is not | |
2691 | .SM | |
2692 | .B IFS | |
2693 | whitespace, along with any adjacent | |
2694 | .SM | |
2695 | .B IFS | |
2696 | whitespace characters, delimits a field. | |
2697 | A sequence of | |
2698 | .SM | |
2699 | .B IFS | |
2700 | whitespace characters is also treated as a delimiter. | |
2701 | If the value of | |
2702 | .SM | |
2703 | .B IFS | |
2704 | is null, no word splitting occurs. | |
726f6388 | 2705 | .PP |
20587658 | 2706 | Explicit null arguments (\^\f3"\^"\fP or \^\f3\(aq\^\(aq\fP\^) are retained. |
ccc6cda3 | 2707 | Unquoted implicit null arguments, resulting from the expansion of |
bb70624e | 2708 | parameters that have no values, are removed. |
ccc6cda3 JA |
2709 | If a parameter with no value is expanded within double quotes, a |
2710 | null argument results and is retained. | |
726f6388 JA |
2711 | .PP |
2712 | Note that if no expansion occurs, no splitting | |
2713 | is performed. | |
2714 | .SS Pathname Expansion | |
2715 | .PP | |
2716 | After word splitting, | |
2717 | unless the | |
2718 | .B \-f | |
2719 | option has been set, | |
2720 | .B bash | |
ccc6cda3 | 2721 | scans each word for the characters |
726f6388 JA |
2722 | .BR * , |
2723 | .BR ? , | |
2724 | and | |
2725 | .BR [ . | |
2726 | If one of these characters appears, then the word is | |
2727 | regarded as a | |
2728 | .IR pattern , | |
2729 | and replaced with an alphabetically sorted list of | |
ccc6cda3 JA |
2730 | file names matching the pattern. |
2731 | If no matching file names are found, | |
2732 | and the shell option | |
2733 | .B nullglob | |
2734 | is disabled, the word is left unchanged. | |
cce855bc JA |
2735 | If the |
2736 | .B nullglob | |
2737 | option is set, and no matches are found, | |
726f6388 | 2738 | the word is removed. |
d3a24ed2 CR |
2739 | If the |
2740 | .B failglob | |
2741 | shell option is set, and no matches are found, an error message | |
2742 | is printed and the command is not executed. | |
cce855bc JA |
2743 | If the shell option |
2744 | .B nocaseglob | |
2745 | is enabled, the match is performed without regard to the case | |
2746 | of alphabetic characters. | |
ccc6cda3 | 2747 | When a pattern is used for pathname expansion, |
726f6388 JA |
2748 | the character |
2749 | .B ``.'' | |
2750 | at the start of a name or immediately following a slash | |
ccc6cda3 JA |
2751 | must be matched explicitly, unless the shell option |
2752 | .B dotglob | |
2753 | is set. | |
cce855bc JA |
2754 | When matching a pathname, the slash character must always be |
2755 | matched explicitly. | |
ccc6cda3 | 2756 | In other cases, the |
726f6388 JA |
2757 | .B ``.'' |
2758 | character is not treated specially. | |
ccc6cda3 JA |
2759 | See the description of |
2760 | .B shopt | |
2761 | below under | |
2762 | .SM | |
2763 | .B SHELL BUILTIN COMMANDS | |
2764 | for a description of the | |
cce855bc JA |
2765 | .BR nocaseglob , |
2766 | .BR nullglob , | |
d3a24ed2 | 2767 | .BR failglob , |
ccc6cda3 JA |
2768 | and |
2769 | .B dotglob | |
2770 | shell options. | |
2771 | .PP | |
2772 | The | |
2773 | .SM | |
2774 | .B GLOBIGNORE | |
2775 | shell variable may be used to restrict the set of file names matching a | |
2776 | .IR pattern . | |
2777 | If | |
2778 | .SM | |
2779 | .B GLOBIGNORE | |
2780 | is set, each matching file name that also matches one of the patterns in | |
2781 | .SM | |
2782 | .B GLOBIGNORE | |
2783 | is removed from the list of matches. | |
2784 | The file names | |
2785 | .B ``.'' | |
2786 | and | |
2787 | .B ``..'' | |
d3a24ed2 | 2788 | are always ignored when |
ccc6cda3 JA |
2789 | .SM |
2790 | .B GLOBIGNORE | |
d3a24ed2 | 2791 | is set and not null. However, setting |
ccc6cda3 JA |
2792 | .SM |
2793 | .B GLOBIGNORE | |
d3a24ed2 | 2794 | to a non-null value has the effect of enabling the |
ccc6cda3 JA |
2795 | .B dotglob |
2796 | shell option, so all other file names beginning with a | |
2797 | .B ``.'' | |
2798 | will match. | |
2799 | To get the old behavior of ignoring file names beginning with a | |
2800 | .BR ``.'' , | |
2801 | make | |
2802 | .B ``.*'' | |
2803 | one of the patterns in | |
2804 | .SM | |
2805 | .BR GLOBIGNORE . | |
2806 | The | |
2807 | .B dotglob | |
2808 | option is disabled when | |
2809 | .SM | |
2810 | .B GLOBIGNORE | |
2811 | is unset. | |
726f6388 | 2812 | .PP |
cce855bc JA |
2813 | \fBPattern Matching\fP |
2814 | .PP | |
2815 | Any character that appears in a pattern, other than the special pattern | |
2816 | characters described below, matches itself. The NUL character may not | |
d3a24ed2 CR |
2817 | occur in a pattern. A backslash escapes the following character; the |
2818 | escaping backslash is discarded when matching. | |
2819 | The special pattern characters must be quoted if | |
cce855bc JA |
2820 | they are to be matched literally. |
2821 | .PP | |
726f6388 JA |
2822 | The special pattern characters have the following meanings: |
2823 | .PP | |
2824 | .PD 0 | |
2825 | .TP | |
2826 | .B * | |
2827 | Matches any string, including the null string. | |
2828 | .TP | |
2829 | .B ? | |
2830 | Matches any single character. | |
2831 | .TP | |
2832 | .B [...] | |
2833 | Matches any one of the enclosed characters. A pair of characters | |
28ef6c31 JA |
2834 | separated by a hyphen denotes a |
2835 | \fIrange expression\fP; | |
2836 | any character that sorts between those two characters, inclusive, | |
2837 | using the current locale's collating sequence and character set, | |
726f6388 JA |
2838 | is matched. If the first character following the |
2839 | .B [ | |
2840 | is a | |
2841 | .B ! | |
2842 | or a | |
2843 | .B ^ | |
ccc6cda3 | 2844 | then any character not enclosed is matched. |
28ef6c31 JA |
2845 | The sorting order of characters in range expressions is determined by |
2846 | the current locale and the value of the \fBLC_COLLATE\fP shell variable, | |
2847 | if set. | |
ccc6cda3 | 2848 | A |
726f6388 | 2849 | .B \- |
726f6388 JA |
2850 | may be matched by including it as the first or last character |
2851 | in the set. | |
ccc6cda3 JA |
2852 | A |
2853 | .B ] | |
2854 | may be matched by including it as the first character | |
2855 | in the set. | |
cce855bc JA |
2856 | .br |
2857 | .if t .sp 0.5 | |
2858 | .if n .sp 1 | |
2859 | Within | |
2860 | .B [ | |
2861 | and | |
2862 | .BR ] , | |
2863 | \fIcharacter classes\fP can be specified using the syntax | |
2864 | \fB[:\fP\fIclass\fP\fB:]\fP, where \fIclass\fP is one of the | |
2865 | following classes defined in the POSIX.2 standard: | |
2866 | .PP | |
2867 | .RS | |
2868 | .B | |
7117c2d2 JA |
2869 | .if n alnum alpha ascii blank cntrl digit graph lower print punct space upper word xdigit |
2870 | .if t alnum alpha ascii blank cntrl digit graph lower print punct space upper word xdigit | |
cce855bc JA |
2871 | .br |
2872 | A character class matches any character belonging to that class. | |
7117c2d2 | 2873 | The \fBword\fP character class matches letters, digits, and the character _. |
cce855bc JA |
2874 | .br |
2875 | .if t .sp 0.5 | |
2876 | .if n .sp 1 | |
2877 | Within | |
2878 | .B [ | |
2879 | and | |
2880 | .BR ] , | |
2881 | an \fIequivalence class\fP can be specified using the syntax | |
2882 | \fB[=\fP\fIc\fP\fB=]\fP, which matches all characters with the | |
2883 | same collation weight (as defined by the current locale) as | |
2884 | the character \fIc\fP. | |
2885 | .br | |
2886 | .if t .sp 0.5 | |
2887 | .if n .sp 1 | |
2888 | Within | |
2889 | .B [ | |
2890 | and | |
2891 | .BR ] , | |
2892 | the syntax \fB[.\fP\fIsymbol\fP\fB.]\fP matches the collating symbol | |
2893 | \fIsymbol\fP. | |
2894 | .RE | |
2895 | .PD | |
2896 | .PP | |
2897 | If the \fBextglob\fP shell option is enabled using the \fBshopt\fP | |
2898 | builtin, several extended pattern matching operators are recognized. | |
bb70624e | 2899 | In the following description, a \fIpattern-list\fP is a list of one |
cce855bc JA |
2900 | or more patterns separated by a \fB|\fP. |
2901 | Composite patterns may be formed using one or more of the following | |
2902 | sub-patterns: | |
2903 | .sp 1 | |
2904 | .PD 0 | |
2905 | .RS | |
2906 | .TP | |
2907 | \fB?(\fP\^\fIpattern-list\^\fP\fB)\fP | |
2908 | Matches zero or one occurrence of the given patterns | |
2909 | .TP | |
2910 | \fB*(\fP\^\fIpattern-list\^\fP\fB)\fP | |
2911 | Matches zero or more occurrences of the given patterns | |
2912 | .TP | |
2913 | \fB+(\fP\^\fIpattern-list\^\fP\fB)\fP | |
2914 | Matches one or more occurrences of the given patterns | |
2915 | .TP | |
2916 | \fB@(\fP\^\fIpattern-list\^\fP\fB)\fP | |
43df7bbb | 2917 | Matches one of the given patterns |
cce855bc JA |
2918 | .TP |
2919 | \fB!(\fP\^\fIpattern-list\^\fP\fB)\fP | |
2920 | Matches anything except one of the given patterns | |
2921 | .RE | |
726f6388 JA |
2922 | .PD |
2923 | .SS Quote Removal | |
2924 | .PP | |
2925 | After the preceding expansions, all unquoted occurrences of the | |
2926 | characters | |
2927 | .BR \e , | |
20587658 | 2928 | .BR \(aq , |
ccc6cda3 JA |
2929 | and \^\f3"\fP\^ that did not result from one of the above |
2930 | expansions are removed. | |
726f6388 JA |
2931 | .SH REDIRECTION |
2932 | Before a command is executed, its input and output | |
2933 | may be | |
2934 | .I redirected | |
2935 | using a special notation interpreted by the shell. | |
2936 | Redirection may also be used to open and close files for the | |
2937 | current shell execution environment. The following redirection | |
2938 | operators may precede or appear anywhere within a | |
2939 | .I simple command | |
2940 | or may follow a | |
2941 | .IR command . | |
2942 | Redirections are processed in the order they appear, from | |
2943 | left to right. | |
2944 | .PP | |
2945 | In the following descriptions, if the file descriptor number is | |
2946 | omitted, and the first character of the redirection operator is | |
2947 | .BR < , | |
2948 | the redirection refers to the standard input (file descriptor | |
2949 | 0). If the first character of the redirection operator is | |
2950 | .BR > , | |
2951 | the redirection refers to the standard output (file descriptor | |
2952 | 1). | |
2953 | .PP | |
cce855bc JA |
2954 | The word following the redirection operator in the following |
2955 | descriptions, unless otherwise noted, is subjected to brace expansion, | |
2956 | tilde expansion, parameter expansion, command substitution, arithmetic | |
bb70624e | 2957 | expansion, quote removal, pathname expansion, and word splitting. |
cce855bc | 2958 | If it expands to more than one word, |
726f6388 JA |
2959 | .B bash |
2960 | reports an error. | |
2961 | .PP | |
2962 | Note that the order of redirections is significant. For example, | |
2963 | the command | |
2964 | .RS | |
2965 | .PP | |
2966 | ls \fB>\fP dirlist 2\fB>&\fP1 | |
2967 | .RE | |
2968 | .PP | |
2969 | directs both standard output and standard error to the file | |
2970 | .IR dirlist , | |
2971 | while the command | |
2972 | .RS | |
2973 | .PP | |
2974 | ls 2\fB>&\fP1 \fB>\fP dirlist | |
2975 | .RE | |
2976 | .PP | |
2977 | directs only the standard output to file | |
2978 | .IR dirlist , | |
2979 | because the standard error was duplicated as standard output | |
2980 | before the standard output was redirected to | |
2981 | .IR dirlist . | |
cce855bc | 2982 | .PP |
bb70624e JA |
2983 | \fBBash\fP handles several filenames specially when they are used in |
2984 | redirections, as described in the following table: | |
2985 | .RS | |
2986 | .PP | |
2987 | .PD 0 | |
2988 | .TP | |
2989 | .B /dev/fd/\fIfd\fP | |
2990 | If \fIfd\fP is a valid integer, file descriptor \fIfd\fP is duplicated. | |
2991 | .TP | |
2992 | .B /dev/stdin | |
2993 | File descriptor 0 is duplicated. | |
2994 | .TP | |
2995 | .B /dev/stdout | |
2996 | File descriptor 1 is duplicated. | |
2997 | .TP | |
2998 | .B /dev/stderr | |
2999 | File descriptor 2 is duplicated. | |
3000 | .TP | |
3001 | .B /dev/tcp/\fIhost\fP/\fIport\fP | |
3002 | If \fIhost\fP is a valid hostname or Internet address, and \fIport\fP | |
f73dda09 JA |
3003 | is an integer port number or service name, \fBbash\fP attempts to open |
3004 | a TCP connection to the corresponding socket. | |
bb70624e JA |
3005 | .TP |
3006 | .B /dev/udp/\fIhost\fP/\fIport\fP | |
3007 | If \fIhost\fP is a valid hostname or Internet address, and \fIport\fP | |
f73dda09 JA |
3008 | is an integer port number or service name, \fBbash\fP attempts to open |
3009 | a UDP connection to the corresponding socket. | |
bb70624e JA |
3010 | .PD |
3011 | .RE | |
3012 | .PP | |
cce855bc | 3013 | A failure to open or create a file causes the redirection to fail. |
cac4cdbf CR |
3014 | .PP |
3015 | Redirections using file descriptors greater than 9 should be used with | |
3016 | care, as they may conflict with file descriptors the shell uses | |
3017 | internally. | |
726f6388 JA |
3018 | .SS Redirecting Input |
3019 | .PP | |
3020 | Redirection of input causes the file whose name results from | |
3021 | the expansion of | |
3022 | .I word | |
3023 | to be opened for reading on file descriptor | |
3024 | .IR n , | |
3025 | or the standard input (file descriptor 0) if | |
3026 | .I n | |
3027 | is not specified. | |
3028 | .PP | |
3029 | The general format for redirecting input is: | |
3030 | .RS | |
3031 | .PP | |
3032 | [\fIn\fP]\fB<\fP\fIword\fP | |
3033 | .RE | |
3034 | .SS Redirecting Output | |
3035 | .PP | |
3036 | Redirection of output causes the file whose name results from | |
3037 | the expansion of | |
3038 | .I word | |
3039 | to be opened for writing on file descriptor | |
3040 | .IR n , | |
3041 | or the standard output (file descriptor 1) if | |
3042 | .I n | |
3043 | is not specified. If the file does not exist it is created; | |
3044 | if it does exist it is truncated to zero size. | |
3045 | .PP | |
3046 | The general format for redirecting output is: | |
3047 | .RS | |
3048 | .PP | |
3049 | [\fIn\fP]\fB>\fP\fIword\fP | |
3050 | .RE | |
3051 | .PP | |
3052 | If the redirection operator is | |
ccc6cda3 JA |
3053 | .BR > , |
3054 | and the | |
cce855bc | 3055 | .B noclobber |
ccc6cda3 JA |
3056 | option to the |
3057 | .B set | |
bb70624e | 3058 | builtin has been enabled, the redirection will fail if the file |
cce855bc JA |
3059 | whose name results from the expansion of \fIword\fP exists and is |
3060 | a regular file. | |
ccc6cda3 | 3061 | If the redirection operator is |
726f6388 | 3062 | .BR >| , |
cce855bc JA |
3063 | or the redirection operator is |
3064 | .B > | |
3065 | and the | |
3066 | .B noclobber | |
726f6388 JA |
3067 | option to the |
3068 | .B set | |
cce855bc | 3069 | builtin command is not enabled, the redirection is attempted even |
ccc6cda3 | 3070 | if the file named by \fIword\fP exists. |
726f6388 JA |
3071 | .SS Appending Redirected Output |
3072 | .PP | |
3073 | Redirection of output in this fashion | |
3074 | causes the file whose name results from | |
3075 | the expansion of | |
3076 | .I word | |
3077 | to be opened for appending on file descriptor | |
3078 | .IR n , | |
3079 | or the standard output (file descriptor 1) if | |
3080 | .I n | |
3081 | is not specified. If the file does not exist it is created. | |
3082 | .PP | |
3083 | The general format for appending output is: | |
3084 | .RS | |
3085 | .PP | |
3086 | [\fIn\fP]\fB>>\fP\fIword\fP | |
3087 | .RE | |
3088 | .PP | |
3089 | .SS Redirecting Standard Output and Standard Error | |
3090 | .PP | |
3091 | .B Bash | |
3092 | allows both the | |
3093 | standard output (file descriptor 1) and | |
3094 | the standard error output (file descriptor 2) | |
3095 | to be redirected to the file whose name is the | |
3096 | expansion of | |
3097 | .I word | |
3098 | with this construct. | |
3099 | .PP | |
3100 | There are two formats for redirecting standard output and | |
3101 | standard error: | |
3102 | .RS | |
3103 | .PP | |
3104 | \fB&>\fP\fIword\fP | |
3105 | .RE | |
3106 | and | |
3107 | .RS | |
3108 | \fB>&\fP\fIword\fP | |
3109 | .RE | |
3110 | .PP | |
3111 | Of the two forms, the first is preferred. | |
3112 | This is semantically equivalent to | |
3113 | .RS | |
3114 | .PP | |
3115 | \fB>\fP\fIword\fP 2\fB>&\fP1 | |
3116 | .RE | |
3117 | .SS Here Documents | |
3118 | .PP | |
3119 | This type of redirection instructs the shell to read input from the | |
3120 | current source until a line containing only | |
3121 | .I word | |
3122 | (with no trailing blanks) | |
3123 | is seen. All of | |
3124 | the lines read up to that point are then used as the standard | |
3125 | input for a command. | |
3126 | .PP | |
7117c2d2 | 3127 | The format of here-documents is: |
726f6388 JA |
3128 | .RS |
3129 | .PP | |
3130 | .nf | |
3131 | \fB<<\fP[\fB\-\fP]\fIword\fP | |
f73dda09 | 3132 | \fIhere-document\fP |
726f6388 JA |
3133 | \fIdelimiter\fP |
3134 | .fi | |
3135 | .RE | |
3136 | .PP | |
bb70624e JA |
3137 | No parameter expansion, command substitution, arithmetic expansion, |
3138 | or pathname expansion is performed on | |
726f6388 JA |
3139 | .IR word . |
3140 | If any characters in | |
3141 | .I word | |
3142 | are quoted, the | |
3143 | .I delimiter | |
3144 | is the result of quote removal on | |
3145 | .IR word , | |
cce855bc JA |
3146 | and the lines in the here-document are not expanded. |
3147 | If \fIword\fP is unquoted, | |
726f6388 JA |
3148 | all lines of the here-document are subjected to parameter expansion, |
3149 | command substitution, and arithmetic expansion. In the latter | |
bb70624e | 3150 | case, the character sequence |
726f6388 JA |
3151 | .B \e<newline> |
3152 | is ignored, and | |
3153 | .B \e | |
3154 | must be used to quote the characters | |
3155 | .BR \e , | |
3156 | .BR $ , | |
3157 | and | |
3158 | .BR ` . | |
3159 | .PP | |
3160 | If the redirection operator is | |
3161 | .BR <<\- , | |
3162 | then all leading tab characters are stripped from input lines and the | |
3163 | line containing | |
3164 | .IR delimiter . | |
3165 | This allows | |
3166 | here-documents within shell scripts to be indented in a | |
3167 | natural fashion. | |
7117c2d2 JA |
3168 | .SS "Here Strings" |
3169 | A variant of here documents, the format is: | |
3170 | .RS | |
3171 | .PP | |
3172 | .nf | |
3173 | \fB<<<\fP\fIword\fP | |
3174 | .fi | |
3175 | .RE | |
3176 | .PP | |
3177 | The \fIword\fP is expanded and supplied to the command on its standard | |
3178 | input. | |
726f6388 JA |
3179 | .SS "Duplicating File Descriptors" |
3180 | .PP | |
3181 | The redirection operator | |
3182 | .RS | |
3183 | .PP | |
3184 | [\fIn\fP]\fB<&\fP\fIword\fP | |
3185 | .RE | |
3186 | .PP | |
3187 | is used to duplicate input file descriptors. | |
3188 | If | |
3189 | .I word | |
3190 | expands to one or more digits, the file descriptor denoted by | |
3191 | .I n | |
cce855bc JA |
3192 | is made to be a copy of that file descriptor. |
3193 | If the digits in | |
3194 | .I word | |
3195 | do not specify a file descriptor open for input, a redirection error occurs. | |
3196 | If | |
726f6388 JA |
3197 | .I word |
3198 | evaluates to | |
3199 | .BR \- , | |
3200 | file descriptor | |
3201 | .I n | |
3202 | is closed. If | |
3203 | .I n | |
3204 | is not specified, the standard input (file descriptor 0) is used. | |
3205 | .PP | |
3206 | The operator | |
3207 | .RS | |
3208 | .PP | |
3209 | [\fIn\fP]\fB>&\fP\fIword\fP | |
3210 | .RE | |
3211 | .PP | |
3212 | is used similarly to duplicate output file descriptors. If | |
3213 | .I n | |
3214 | is not specified, the standard output (file descriptor 1) is used. | |
cce855bc JA |
3215 | If the digits in |
3216 | .I word | |
3217 | do not specify a file descriptor open for output, a redirection error occurs. | |
726f6388 JA |
3218 | As a special case, if \fIn\fP is omitted, and \fIword\fP does not |
3219 | expand to one or more digits, the standard output and standard | |
3220 | error are redirected as described previously. | |
7117c2d2 JA |
3221 | .SS "Moving File Descriptors" |
3222 | .PP | |
3223 | The redirection operator | |
3224 | .RS | |
3225 | .PP | |
3226 | [\fIn\fP]\fB<&\fP\fIdigit\fP\fB\-\fP | |
3227 | .RE | |
3228 | .PP | |
3229 | moves the file descriptor \fIdigit\fP to file descriptor | |
3230 | .IR n , | |
3231 | or the standard input (file descriptor 0) if \fIn\fP is not specified. | |
3232 | \fIdigit\fP is closed after being duplicated to \fIn\fP. | |
3233 | .PP | |
3234 | Similarly, the redirection operator | |
3235 | .RS | |
3236 | .PP | |
3237 | [\fIn\fP]\fB>&\fP\fIdigit\fP\fB\-\fP | |
3238 | .RE | |
3239 | .PP | |
3240 | moves the file descriptor \fIdigit\fP to file descriptor | |
3241 | .IR n , | |
3242 | or the standard output (file descriptor 1) if \fIn\fP is not specified. | |
726f6388 JA |
3243 | .SS "Opening File Descriptors for Reading and Writing" |
3244 | .PP | |
3245 | The redirection operator | |
3246 | .RS | |
3247 | .PP | |
3248 | [\fIn\fP]\fB<>\fP\fIword\fP | |
3249 | .RE | |
3250 | .PP | |
3251 | causes the file whose name is the expansion of | |
3252 | .I word | |
3253 | to be opened for both reading and writing on file descriptor | |
3254 | .IR n , | |
ccc6cda3 | 3255 | or on file descriptor 0 if |
726f6388 JA |
3256 | .I n |
3257 | is not specified. If the file does not exist, it is created. | |
726f6388 | 3258 | .SH ALIASES |
bb70624e | 3259 | \fIAliases\fP allow a string to be substituted for a word when it is used |
cce855bc | 3260 | as the first word of a simple command. |
bb70624e | 3261 | The shell maintains a list of aliases that may be set and unset with the |
726f6388 JA |
3262 | .B alias |
3263 | and | |
3264 | .B unalias | |
3265 | builtin commands (see | |
3266 | .SM | |
3267 | .B SHELL BUILTIN COMMANDS | |
3268 | below). | |
de8913bd | 3269 | The first word of each simple command, if unquoted, |
726f6388 JA |
3270 | is checked to see if it has an |
3271 | alias. If so, that word is replaced by the text of the alias. | |
de8913bd CR |
3272 | The characters \fB/\fP, \fB$\fP, \fB`\fP, and \fB=\fP and |
3273 | any of the shell \fImetacharacters\fP or quoting characters | |
3274 | listed above may not appear in an alias name. | |
3275 | The replacement text may contain any valid shell input, | |
3276 | including shell metacharacters. | |
3277 | The first word of the replacement text is tested | |
726f6388 | 3278 | for aliases, but a word that is identical to an alias being expanded |
de8913bd CR |
3279 | is not expanded a second time. |
3280 | This means that one may alias | |
726f6388 JA |
3281 | .B ls |
3282 | to | |
3283 | .BR "ls \-F" , | |
3284 | for instance, and | |
3285 | .B bash | |
3286 | does not try to recursively expand the replacement text. | |
3287 | If the last character of the alias value is a | |
3288 | .IR blank , | |
3289 | then the next command | |
3290 | word following the alias is also checked for alias expansion. | |
3291 | .PP | |
3292 | Aliases are created and listed with the | |
3293 | .B alias | |
3294 | command, and removed with the | |
3295 | .B unalias | |
3296 | command. | |
3297 | .PP | |
ccc6cda3 | 3298 | There is no mechanism for using arguments in the replacement text. |
bb70624e JA |
3299 | If arguments are needed, a shell function should be used (see |
3300 | .SM | |
3301 | .B FUNCTIONS | |
3302 | below). | |
726f6388 | 3303 | .PP |
ccc6cda3 JA |
3304 | Aliases are not expanded when the shell is not interactive, unless |
3305 | the | |
3306 | .B expand_aliases | |
3307 | shell option is set using | |
3308 | .B shopt | |
3309 | (see the description of | |
3310 | .B shopt | |
3311 | under | |
3312 | .SM | |
3313 | \fBSHELL BUILTIN COMMANDS\fP | |
3314 | below). | |
726f6388 JA |
3315 | .PP |
3316 | The rules concerning the definition and use of aliases are | |
3317 | somewhat confusing. | |
3318 | .B Bash | |
3319 | always reads at least one complete line | |
3320 | of input before executing any | |
3321 | of the commands on that line. Aliases are expanded when a | |
3322 | command is read, not when it is executed. Therefore, an | |
3323 | alias definition appearing on the same line as another | |
3324 | command does not take effect until the next line of input is read. | |
ccc6cda3 | 3325 | The commands following the alias definition |
726f6388 JA |
3326 | on that line are not affected by the new alias. |
3327 | This behavior is also an issue when functions are executed. | |
cce855bc | 3328 | Aliases are expanded when a function definition is read, |
726f6388 JA |
3329 | not when the function is executed, because a function definition |
3330 | is itself a compound command. As a consequence, aliases | |
3331 | defined in a function are not available until after that | |
3332 | function is executed. To be safe, always put | |
3333 | alias definitions on a separate line, and do not use | |
3334 | .B alias | |
3335 | in compound commands. | |
3336 | .PP | |
cce855bc | 3337 | For almost every purpose, aliases are superseded by |
726f6388 | 3338 | shell functions. |
ccc6cda3 JA |
3339 | .SH FUNCTIONS |
3340 | A shell function, defined as described above under | |
3341 | .SM | |
3342 | .BR "SHELL GRAMMAR" , | |
3343 | stores a series of commands for later execution. | |
bb70624e JA |
3344 | When the name of a shell function is used as a simple command name, |
3345 | the list of commands associated with that function name is executed. | |
ccc6cda3 JA |
3346 | Functions are executed in the context of the |
3347 | current shell; no new process is created to interpret | |
3348 | them (contrast this with the execution of a shell script). | |
3349 | When a function is executed, the arguments to the | |
3350 | function become the positional parameters | |
bb70624e JA |
3351 | during its execution. |
3352 | The special parameter | |
ccc6cda3 | 3353 | .B # |
de8913bd | 3354 | is updated to reflect the change. Special parameter 0 |
bb70624e | 3355 | is unchanged. |
d3a24ed2 | 3356 | The first element of the |
bb70624e JA |
3357 | .SM |
3358 | .B FUNCNAME | |
3359 | variable is set to the name of the function while the function | |
3360 | is executing. | |
3361 | All other aspects of the shell execution | |
ccc6cda3 JA |
3362 | environment are identical between a function and its caller |
3363 | with the exception that the | |
3364 | .SM | |
3365 | .B DEBUG | |
76a8d78d CR |
3366 | and |
3367 | .B RETURN | |
3368 | traps (see the description of the | |
ccc6cda3 JA |
3369 | .B trap |
3370 | builtin under | |
3371 | .SM | |
3372 | .B SHELL BUILTIN COMMANDS | |
76a8d78d | 3373 | below) are not inherited unless the function has been given the |
7117c2d2 JA |
3374 | \fBtrace\fP attribute (see the description of the |
3375 | .SM | |
3376 | .B declare | |
d3a24ed2 CR |
3377 | builtin below) or the |
3378 | \fB\-o functrace\fP shell option has been enabled with | |
3379 | the \fBset\fP builtin | |
76a8d78d | 3380 | (in which case all functions inherit the \fBDEBUG\fP and \fBRETURN\fP traps). |
726f6388 | 3381 | .PP |
ccc6cda3 JA |
3382 | Variables local to the function may be declared with the |
3383 | .B local | |
3384 | builtin command. Ordinarily, variables and their values | |
3385 | are shared between the function and its caller. | |
726f6388 | 3386 | .PP |
ccc6cda3 JA |
3387 | If the builtin command |
3388 | .B return | |
3389 | is executed in a function, the function completes and | |
3390 | execution resumes with the next command after the function | |
d3a24ed2 CR |
3391 | call. |
3392 | Any command associated with the \fBRETURN\fP trap is executed | |
3393 | before execution resumes. | |
3394 | When a function completes, the values of the | |
ccc6cda3 JA |
3395 | positional parameters and the special parameter |
3396 | .B # | |
cce855bc | 3397 | are restored to the values they had prior to the function's |
ccc6cda3 | 3398 | execution. |
726f6388 | 3399 | .PP |
ccc6cda3 JA |
3400 | Function names and definitions may be listed with the |
3401 | .B \-f | |
726f6388 | 3402 | option to the |
ccc6cda3 JA |
3403 | .B declare |
3404 | or | |
3405 | .B typeset | |
3406 | builtin commands. The | |
3407 | .B \-F | |
3408 | option to | |
3409 | .B declare | |
3410 | or | |
3411 | .B typeset | |
d3a24ed2 CR |
3412 | will list the function names only |
3413 | (and optionally the source file and line number, if the \fBextdebug\fP | |
3414 | shell option is enabled). | |
ccc6cda3 JA |
3415 | Functions may be exported so that subshells |
3416 | automatically have them defined with the | |
3417 | .B \-f | |
3418 | option to the | |
3419 | .B export | |
3420 | builtin. | |
d3a24ed2 CR |
3421 | Note that shell functions and variables with the same name may result |
3422 | in multiple identically-named entries in the environment passed to the | |
3423 | shell's children. | |
3424 | Care should be taken in cases where this may cause a problem. | |
726f6388 | 3425 | .PP |
ccc6cda3 JA |
3426 | Functions may be recursive. No limit is imposed on the number |
3427 | of recursive calls. | |
cce855bc JA |
3428 | .SH "ARITHMETIC EVALUATION" |
3429 | The shell allows arithmetic expressions to be evaluated, under | |
d3a24ed2 CR |
3430 | certain circumstances (see the \fBlet\fP and \fBdeclare\fP builtin |
3431 | commands and \fBArithmetic Expansion\fP). | |
7117c2d2 | 3432 | Evaluation is done in fixed-width integers with no check for overflow, |
cce855bc | 3433 | though division by 0 is trapped and flagged as an error. |
d3a24ed2 CR |
3434 | The operators and their precedence, associativity, and values |
3435 | are the same as in the C language. | |
cce855bc JA |
3436 | The following list of operators is grouped into levels of |
3437 | equal-precedence operators. | |
3438 | The levels are listed in order of decreasing precedence. | |
726f6388 | 3439 | .PP |
cce855bc JA |
3440 | .PD 0 |
3441 | .TP | |
bb70624e JA |
3442 | .B \fIid\fP++ \fIid\fP\-\- |
3443 | variable post-increment and post-decrement | |
3444 | .TP | |
3445 | .B ++\fIid\fP \-\-\fIid\fP | |
3446 | variable pre-increment and pre-decrement | |
3447 | .TP | |
cce855bc JA |
3448 | .B \- + |
3449 | unary minus and plus | |
3450 | .TP | |
3451 | .B ! ~ | |
3452 | logical and bitwise negation | |
3453 | .TP | |
3454 | .B ** | |
3455 | exponentiation | |
3456 | .TP | |
3457 | .B * / % | |
3458 | multiplication, division, remainder | |
3459 | .TP | |
3460 | .B + \- | |
3461 | addition, subtraction | |
3462 | .TP | |
3463 | .B << >> | |
3464 | left and right bitwise shifts | |
3465 | .TP | |
3466 | .B <= >= < > | |
3467 | comparison | |
3468 | .TP | |
3469 | .B == != | |
3470 | equality and inequality | |
3471 | .TP | |
3472 | .B & | |
3473 | bitwise AND | |
3474 | .TP | |
3475 | .B ^ | |
3476 | bitwise exclusive OR | |
3477 | .TP | |
3478 | .B | | |
3479 | bitwise OR | |
3480 | .TP | |
3481 | .B && | |
3482 | logical AND | |
3483 | .TP | |
3484 | .B || | |
3485 | logical OR | |
3486 | .TP | |
3487 | .B \fIexpr\fP?\fIexpr\fP:\fIexpr\fP | |
d3a24ed2 | 3488 | conditional operator |
cce855bc JA |
3489 | .TP |
3490 | .B = *= /= %= += \-= <<= >>= &= ^= |= | |
3491 | assignment | |
bb70624e JA |
3492 | .TP |
3493 | .B \fIexpr1\fP , \fIexpr2\fP | |
3494 | comma | |
cce855bc | 3495 | .PD |
ccc6cda3 | 3496 | .PP |
cce855bc | 3497 | Shell variables are allowed as operands; parameter expansion is |
bb70624e JA |
3498 | performed before the expression is evaluated. |
3499 | Within an expression, shell variables may also be referenced by name | |
3500 | without using the parameter expansion syntax. | |
d3a24ed2 CR |
3501 | A shell variable that is null or unset evaluates to 0 when referenced |
3502 | by name without using the parameter expansion syntax. | |
bb70624e | 3503 | The value of a variable is evaluated as an arithmetic expression |
d3a24ed2 CR |
3504 | when it is referenced, or when a variable which has been given the |
3505 | \fIinteger\fP attribute using \fBdeclare -i\fP is assigned a value. | |
3506 | A null value evaluates to 0. | |
bb70624e | 3507 | A shell variable need not have its integer attribute |
cce855bc | 3508 | turned on to be used in an expression. |
ccc6cda3 | 3509 | .PP |
cce855bc JA |
3510 | Constants with a leading 0 are interpreted as octal numbers. |
3511 | A leading 0x or 0X denotes hexadecimal. | |
3512 | Otherwise, numbers take the form [\fIbase#\fP]n, where \fIbase\fP | |
3513 | is a decimal number between 2 and 64 representing the arithmetic | |
3514 | base, and \fIn\fP is a number in that base. | |
bb70624e | 3515 | If \fIbase#\fP is omitted, then base 10 is used. |
cce855bc | 3516 | The digits greater than 9 are represented by the lowercase letters, |
f73dda09 | 3517 | the uppercase letters, @, and _, in that order. |
cce855bc | 3518 | If \fIbase\fP is less than or equal to 36, lowercase and uppercase |
f75912ae | 3519 | letters may be used interchangeably to represent numbers between 10 |
cce855bc | 3520 | and 35. |
ccc6cda3 | 3521 | .PP |
cce855bc JA |
3522 | Operators are evaluated in order of precedence. Sub-expressions in |
3523 | parentheses are evaluated first and may override the precedence | |
3524 | rules above. | |
3525 | .SH "CONDITIONAL EXPRESSIONS" | |
3526 | Conditional expressions are used by the \fB[[\fP compound command and | |
3527 | the \fBtest\fP and \fB[\fP builtin commands to test file attributes | |
3528 | and perform string and arithmetic comparisons. | |
3529 | Expressions are formed from the following unary or binary primaries. | |
3530 | If any \fIfile\fP argument to one of the primaries is of the form | |
bb70624e JA |
3531 | \fI/dev/fd/n\fP, then file descriptor \fIn\fP is checked. |
3532 | If the \fIfile\fP argument to one of the primaries is one of | |
3533 | \fI/dev/stdin\fP, \fI/dev/stdout\fP, or \fI/dev/stderr\fP, file | |
3534 | descriptor 0, 1, or 2, respectively, is checked. | |
be7d8f2d CR |
3535 | .PP |
3536 | Unless otherwise specified, primaries that operate on files follow symbolic | |
3537 | links and operate on the target of the link, rather than the link itself. | |
cce855bc JA |
3538 | .sp 1 |
3539 | .PD 0 | |
3540 | .TP | |
3541 | .B \-a \fIfile\fP | |
3542 | True if \fIfile\fP exists. | |
3543 | .TP | |
3544 | .B \-b \fIfile\fP | |
3545 | True if \fIfile\fP exists and is a block special file. | |
3546 | .TP | |
3547 | .B \-c \fIfile\fP | |
3548 | True if \fIfile\fP exists and is a character special file. | |
3549 | .TP | |
3550 | .B \-d \fIfile\fP | |
3551 | True if \fIfile\fP exists and is a directory. | |
3552 | .TP | |
3553 | .B \-e \fIfile\fP | |
3554 | True if \fIfile\fP exists. | |
3555 | .TP | |
3556 | .B \-f \fIfile\fP | |
3557 | True if \fIfile\fP exists and is a regular file. | |
3558 | .TP | |
3559 | .B \-g \fIfile\fP | |
3560 | True if \fIfile\fP exists and is set-group-id. | |
3561 | .TP | |
b72432fd JA |
3562 | .B \-h \fIfile\fP |
3563 | True if \fIfile\fP exists and is a symbolic link. | |
3564 | .TP | |
cce855bc JA |
3565 | .B \-k \fIfile\fP |
3566 | True if \fIfile\fP exists and its ``sticky'' bit is set. | |
3567 | .TP | |
3568 | .B \-p \fIfile\fP | |
3569 | True if \fIfile\fP exists and is a named pipe (FIFO). | |
3570 | .TP | |
3571 | .B \-r \fIfile\fP | |
3572 | True if \fIfile\fP exists and is readable. | |
3573 | .TP | |
3574 | .B \-s \fIfile\fP | |
3575 | True if \fIfile\fP exists and has a size greater than zero. | |
3576 | .TP | |
3577 | .B \-t \fIfd\fP | |
3578 | True if file descriptor | |
3579 | .I fd | |
3580 | is open and refers to a terminal. | |
3581 | .TP | |
3582 | .B \-u \fIfile\fP | |
3583 | True if \fIfile\fP exists and its set-user-id bit is set. | |
3584 | .TP | |
3585 | .B \-w \fIfile\fP | |
3586 | True if \fIfile\fP exists and is writable. | |
3587 | .TP | |
3588 | .B \-x \fIfile\fP | |
3589 | True if \fIfile\fP exists and is executable. | |
3590 | .TP | |
3591 | .B \-O \fIfile\fP | |
3592 | True if \fIfile\fP exists and is owned by the effective user id. | |
3593 | .TP | |
3594 | .B \-G \fIfile\fP | |
3595 | True if \fIfile\fP exists and is owned by the effective group id. | |
3596 | .TP | |
3597 | .B \-L \fIfile\fP | |
3598 | True if \fIfile\fP exists and is a symbolic link. | |
3599 | .TP | |
3600 | .B \-S \fIfile\fP | |
3601 | True if \fIfile\fP exists and is a socket. | |
3602 | .TP | |
3603 | .B \-N \fIfile\fP | |
3604 | True if \fIfile\fP exists and has been modified since it was last read. | |
3605 | .TP | |
3606 | \fIfile1\fP \-\fBnt\fP \fIfile2\fP | |
7117c2d2 JA |
3607 | True if \fIfile1\fP is newer (according to modification date) than \fIfile2\fP, |
3608 | or if \fIfile1\fP exists and \fPfile2\fP does not. | |
cce855bc JA |
3609 | .TP |
3610 | \fIfile1\fP \-\fBot\fP \fIfile2\fP | |
7117c2d2 JA |
3611 | True if \fIfile1\fP is older than \fIfile2\fP, or if \fIfile2\fP exists |
3612 | and \fIfile1\fP does not. | |
cce855bc JA |
3613 | .TP |
3614 | \fIfile1\fP \fB\-ef\fP \fIfile2\fP | |
7117c2d2 | 3615 | True if \fIfile1\fP and \fIfile2\fP refer to the same device and |
cce855bc JA |
3616 | inode numbers. |
3617 | .TP | |
3618 | .B \-o \fIoptname\fP | |
3619 | True if shell option | |
3620 | .I optname | |
3621 | is enabled. | |
3622 | See the list of options under the description of the | |
3623 | .B \-o | |
3624 | option to the | |
3625 | .B set | |
3626 | builtin below. | |
3627 | .TP | |
3628 | .B \-z \fIstring\fP | |
3629 | True if the length of \fIstring\fP is zero. | |
3630 | .TP | |
cce855bc | 3631 | \fIstring\fP |
f085a21f CR |
3632 | .PD 0 |
3633 | .TP | |
3634 | .B \-n \fIstring\fP | |
3635 | .PD | |
cce855bc JA |
3636 | True if the length of |
3637 | .I string | |
3638 | is non-zero. | |
3639 | .TP | |
3640 | \fIstring1\fP \fB==\fP \fIstring2\fP | |
3641 | True if the strings are equal. \fB=\fP may be used in place of | |
7117c2d2 | 3642 | \fB==\fP for strict POSIX compliance. |
cce855bc JA |
3643 | .TP |
3644 | \fIstring1\fP \fB!=\fP \fIstring2\fP | |
3645 | True if the strings are not equal. | |
3646 | .TP | |
3647 | \fIstring1\fP \fB<\fP \fIstring2\fP | |
3648 | True if \fIstring1\fP sorts before \fIstring2\fP lexicographically | |
3649 | in the current locale. | |
3650 | .TP | |
3651 | \fIstring1\fP \fB>\fP \fIstring2\fP | |
3652 | True if \fIstring1\fP sorts after \fIstring2\fP lexicographically | |
3653 | in the current locale. | |
3654 | .TP | |
3655 | .I \fIarg1\fP \fBOP\fP \fIarg2\fP | |
3656 | .SM | |
3657 | .B OP | |
3658 | is one of | |
3659 | .BR \-eq , | |
3660 | .BR \-ne , | |
3661 | .BR \-lt , | |
3662 | .BR \-le , | |
3663 | .BR \-gt , | |
3664 | or | |
3665 | .BR \-ge . | |
3666 | These arithmetic binary operators return true if \fIarg1\fP | |
3667 | is equal to, not equal to, less than, less than or equal to, | |
3668 | greater than, or greater than or equal to \fIarg2\fP, respectively. | |
3669 | .I Arg1 | |
3670 | and | |
3671 | .I arg2 | |
3672 | may be positive or negative integers. | |
3673 | .PD | |
3674 | .SH "SIMPLE COMMAND EXPANSION" | |
3675 | When a simple command is executed, the shell performs the following | |
3676 | expansions, assignments, and redirections, from left to right. | |
3677 | .IP 1. | |
3678 | The words that the parser has marked as variable assignments (those | |
3679 | preceding the command name) and redirections are saved for later | |
3680 | processing. | |
3681 | .IP 2. | |
3682 | The words that are not variable assignments or redirections are | |
3683 | expanded. If any words remain after expansion, the first word | |
3684 | is taken to be the name of the command and the remaining words are | |
3685 | the arguments. | |
3686 | .IP 3. | |
3687 | Redirections are performed as described above under | |
3688 | .SM | |
3689 | .BR REDIRECTION . | |
3690 | .IP 4. | |
3691 | The text after the \fB=\fP in each variable assignment undergoes tilde | |
3692 | expansion, parameter expansion, command substitution, arithmetic expansion, | |
3693 | and quote removal before being assigned to the variable. | |
3694 | .PP | |
3695 | If no command name results, the variable assignments affect the current | |
3696 | shell environment. Otherwise, the variables are added to the environment | |
3697 | of the executed command and do not affect the current shell environment. | |
3698 | If any of the assignments attempts to assign a value to a readonly variable, | |
3699 | an error occurs, and the command exits with a non-zero status. | |
3700 | .PP | |
3701 | If no command name results, redirections are performed, but do not | |
3702 | affect the current shell environment. A redirection error causes the | |
3703 | command to exit with a non-zero status. | |
3704 | .PP | |
3705 | If there is a command name left after expansion, execution proceeds as | |
3706 | described below. Otherwise, the command exits. If one of the expansions | |
3707 | contained a command substitution, the exit status of the command is | |
3708 | the exit status of the last command substitution performed. If there | |
3709 | were no command substitutions, the command exits with a status of zero. | |
3710 | .SH "COMMAND EXECUTION" | |
3711 | After a command has been split into words, if it results in a | |
3712 | simple command and an optional list of arguments, the following | |
3713 | actions are taken. | |
3714 | .PP | |
3715 | If the command name contains no slashes, the shell attempts to | |
3716 | locate it. If there exists a shell function by that name, that | |
3717 | function is invoked as described above in | |
3718 | .SM | |
3719 | .BR FUNCTIONS . | |
3720 | If the name does not match a function, the shell searches for | |
3721 | it in the list of shell builtins. If a match is found, that | |
3722 | builtin is invoked. | |
3723 | .PP | |
3724 | If the name is neither a shell function nor a builtin, | |
3725 | and contains no slashes, | |
3726 | .B bash | |
3727 | searches each element of the | |
3728 | .SM | |
3729 | .B PATH | |
3730 | for a directory containing an executable file by that name. | |
3731 | .B Bash | |
bb70624e | 3732 | uses a hash table to remember the full pathnames of executable |
cce855bc JA |
3733 | files (see |
3734 | .B hash | |
3735 | under | |
3736 | .SM | |
3737 | .B "SHELL BUILTIN COMMANDS" | |
3738 | below). | |
3739 | A full search of the directories in | |
3740 | .SM | |
3741 | .B PATH | |
3742 | is performed only if the command is not found in the hash table. | |
3743 | If the search is unsuccessful, the shell prints an error | |
3744 | message and returns an exit status of 127. | |
3745 | .PP | |
3746 | If the search is successful, or if the command name contains | |
3747 | one or more slashes, the shell executes the named program in a | |
3748 | separate execution environment. | |
3749 | Argument 0 is set to the name given, and the remaining arguments | |
3750 | to the command are set to the arguments given, if any. | |
3751 | .PP | |
3752 | If this execution fails because the file is not in executable | |
3753 | format, and the file is not a directory, it is assumed to be | |
3754 | a \fIshell script\fP, a file | |
3755 | containing shell commands. A subshell is spawned to execute | |
3756 | it. This subshell reinitializes itself, so | |
3757 | that the effect is as if a new shell had been invoked | |
3758 | to handle the script, with the exception that the locations of | |
3759 | commands remembered by the parent (see | |
3760 | .B hash | |
3761 | below under | |
3762 | .SM | |
3763 | \fBSHELL BUILTIN COMMANDS\fP) | |
3764 | are retained by the child. | |
3765 | .PP | |
3766 | If the program is a file beginning with | |
3767 | .BR #! , | |
3768 | the remainder of the first line specifies an interpreter | |
3769 | for the program. The shell executes the | |
3770 | specified interpreter on operating systems that do not | |
3771 | handle this executable format themselves. The arguments to the | |
3772 | interpreter consist of a single optional argument following the | |
3773 | interpreter name on the first line of the program, followed | |
3774 | by the name of the program, followed by the command | |
3775 | arguments, if any. | |
3776 | .SH COMMAND EXECUTION ENVIRONMENT | |
3777 | The shell has an \fIexecution environment\fP, which consists of the | |
3778 | following: | |
3779 | .sp 1 | |
3780 | .IP \(bu | |
3781 | open files inherited by the shell at invocation, as modified by | |
3782 | redirections supplied to the \fBexec\fP builtin | |
3783 | .IP \(bu | |
3784 | the current working directory as set by \fBcd\fP, \fBpushd\fP, or | |
3785 | \fBpopd\fP, or inherited by the shell at invocation | |
3786 | .IP \(bu | |
3787 | the file creation mode mask as set by \fBumask\fP or inherited from | |
3788 | the shell's parent | |
3789 | .IP \(bu | |
3790 | current traps set by \fBtrap\fP | |
3791 | .IP \(bu | |
3792 | shell parameters that are set by variable assignment or with \fBset\fP | |
3793 | or inherited from the shell's parent in the environment | |
3794 | .IP \(bu | |
3795 | shell functions defined during execution or inherited from the shell's | |
3796 | parent in the environment | |
3797 | .IP \(bu | |
3798 | options enabled at invocation (either by default or with command-line | |
3799 | arguments) or by \fBset\fP | |
3800 | .IP \(bu | |
3801 | options enabled by \fBshopt\fP | |
3802 | .IP \(bu | |
3803 | shell aliases defined with \fBalias\fP | |
3804 | .IP \(bu | |
3805 | various process IDs, including those of background jobs, the value | |
3806 | of \fB$$\fP, and the value of \fB$PPID\fP | |
3807 | .PP | |
3808 | When a simple command other than a builtin or shell function | |
3809 | is to be executed, it | |
3810 | is invoked in a separate execution environment that consists of | |
3811 | the following. Unless otherwise noted, the values are inherited | |
3812 | from the shell. | |
3813 | .sp 1 | |
3814 | .IP \(bu | |
3815 | the shell's open files, plus any modifications and additions specified | |
3816 | by redirections to the command | |
3817 | .IP \(bu | |
3818 | the current working directory | |
3819 | .IP \(bu | |
3820 | the file creation mode mask | |
3821 | .IP \(bu | |
d3a24ed2 CR |
3822 | shell variables and functions marked for export, along with variables |
3823 | exported for the command, passed in the environment | |
cce855bc | 3824 | .IP \(bu |
d3a24ed2 CR |
3825 | traps caught by the shell are reset to the values inherited from the |
3826 | shell's parent, and traps ignored by the shell are ignored | |
cce855bc JA |
3827 | .PP |
3828 | A command invoked in this separate environment cannot affect the | |
3829 | shell's execution environment. | |
3830 | .PP | |
d3a24ed2 CR |
3831 | Command substitution, commands grouped with parentheses, |
3832 | and asynchronous commands are invoked in a | |
cce855bc JA |
3833 | subshell environment that is a duplicate of the shell environment, |
3834 | except that traps caught by the shell are reset to the values | |
3835 | that the shell inherited from its parent at invocation. Builtin | |
3836 | commands that are invoked as part of a pipeline are also executed in a | |
3837 | subshell environment. Changes made to the subshell environment | |
3838 | cannot affect the shell's execution environment. | |
f73dda09 JA |
3839 | .PP |
3840 | If a command is followed by a \fB&\fP and job control is not active, the | |
3841 | default standard input for the command is the empty file \fI/dev/null\fP. | |
3842 | Otherwise, the invoked command inherits the file descriptors of the calling | |
3843 | shell as modified by redirections. | |
cce855bc JA |
3844 | .SH ENVIRONMENT |
3845 | When a program is invoked it is given an array of strings | |
3846 | called the | |
3847 | .IR environment . | |
3848 | This is a list of | |
3849 | \fIname\fP\-\fIvalue\fP pairs, of the form | |
3850 | .IR "name\fR=\fPvalue" . | |
3851 | .PP | |
bb70624e JA |
3852 | The shell provides several ways to manipulate the environment. |
3853 | On invocation, the shell scans its own environment and | |
cce855bc JA |
3854 | creates a parameter for each name found, automatically marking |
3855 | it for | |
3856 | .I export | |
3857 | to child processes. Executed commands inherit the environment. | |
3858 | The | |
3859 | .B export | |
3860 | and | |
3861 | .B declare \-x | |
3862 | commands allow parameters and functions to be added to and | |
3863 | deleted from the environment. If the value of a parameter | |
3864 | in the environment is modified, the new value becomes part | |
3865 | of the environment, replacing the old. The environment | |
3866 | inherited by any executed command consists of the shell's | |
3867 | initial environment, whose values may be modified in the shell, | |
3868 | less any pairs removed by the | |
3869 | .B unset | |
3870 | command, plus any additions via the | |
3871 | .B export | |
3872 | and | |
3873 | .B declare \-x | |
3874 | commands. | |
3875 | .PP | |
3876 | The environment for any | |
3877 | .I simple command | |
3878 | or function may be augmented temporarily by prefixing it with | |
3879 | parameter assignments, as described above in | |
3880 | .SM | |
3881 | .BR PARAMETERS . | |
3882 | These assignment statements affect only the environment seen | |
3883 | by that command. | |
3884 | .PP | |
3885 | If the | |
3886 | .B \-k | |
3887 | option is set (see the | |
3888 | .B set | |
3889 | builtin command below), then | |
3890 | .I all | |
3891 | parameter assignments are placed in the environment for a command, | |
3892 | not just those that precede the command name. | |
3893 | .PP | |
3894 | When | |
3895 | .B bash | |
3896 | invokes an external command, the variable | |
3897 | .B _ | |
3898 | is set to the full file name of the command and passed to that | |
ccc6cda3 JA |
3899 | command in its environment. |
3900 | .SH "EXIT STATUS" | |
cce855bc | 3901 | For the shell's purposes, a command which exits with a |
ccc6cda3 JA |
3902 | zero exit status has succeeded. An exit status of zero |
3903 | indicates success. A non-zero exit status indicates failure. | |
bb70624e JA |
3904 | When a command terminates on a fatal signal \fIN\fP, \fBbash\fP uses |
3905 | the value of 128+\fIN\fP as the exit status. | |
ccc6cda3 JA |
3906 | .PP |
3907 | If a command is not found, the child process created to | |
3908 | execute it returns a status of 127. If a command is found | |
3909 | but is not executable, the return status is 126. | |
3910 | .PP | |
cce855bc JA |
3911 | If a command fails because of an error during expansion or redirection, |
3912 | the exit status is greater than zero. | |
3913 | .PP | |
ccc6cda3 JA |
3914 | Shell builtin commands return a status of 0 (\fItrue\fP) if |
3915 | successful, and non-zero (\fIfalse\fP) if an error occurs | |
3916 | while they execute. | |
3917 | All builtins return an exit status of 2 to indicate incorrect usage. | |
3918 | .PP | |
3919 | \fBBash\fP itself returns the exit status of the last command | |
3920 | executed, unless a syntax error occurs, in which case it exits | |
3921 | with a non-zero value. See also the \fBexit\fP builtin | |
3922 | command below. | |
3923 | .SH SIGNALS | |
cce855bc | 3924 | When \fBbash\fP is interactive, in the absence of any traps, it ignores |
ccc6cda3 JA |
3925 | .SM |
3926 | .B SIGTERM | |
3927 | (so that \fBkill 0\fP does not kill an interactive shell), | |
3928 | and | |
3929 | .SM | |
3930 | .B SIGINT | |
3931 | is caught and handled (so that the \fBwait\fP builtin is interruptible). | |
3932 | In all cases, \fBbash\fP ignores | |
3933 | .SM | |
3934 | .BR SIGQUIT . | |
3935 | If job control is in effect, | |
3936 | .B bash | |
3937 | ignores | |
3938 | .SM | |
3939 | .BR SIGTTIN , | |
3940 | .SM | |
3941 | .BR SIGTTOU , | |
3942 | and | |
3943 | .SM | |
3944 | .BR SIGTSTP . | |
3945 | .PP | |
5e13499c | 3946 | Non-builtin commands run by \fBbash\fP have signal handlers |
cce855bc JA |
3947 | set to the values inherited by the shell from its parent. |
3948 | When job control is not in effect, asynchronous commands | |
ccc6cda3 JA |
3949 | ignore |
3950 | .SM | |
3951 | .B SIGINT | |
3952 | and | |
3953 | .SM | |
cce855bc | 3954 | .B SIGQUIT |
5e13499c | 3955 | in addition to these inherited handlers. |
ccc6cda3 JA |
3956 | Commands run as a result of command substitution ignore the |
3957 | keyboard-generated job control signals | |
3958 | .SM | |
3959 | .BR SIGTTIN , | |
3960 | .SM | |
3961 | .BR SIGTTOU , | |
3962 | and | |
3963 | .SM | |
3964 | .BR SIGTSTP . | |
3965 | .PP | |
3966 | The shell exits by default upon receipt of a | |
3967 | .SM | |
3968 | .BR SIGHUP . | |
f73dda09 | 3969 | Before exiting, an interactive shell resends the |
ccc6cda3 JA |
3970 | .SM |
3971 | .B SIGHUP | |
cce855bc JA |
3972 | to all jobs, running or stopped. |
3973 | Stopped jobs are sent | |
3974 | .SM | |
3975 | .B SIGCONT | |
3976 | to ensure that they receive the | |
3977 | .SM | |
3978 | .BR SIGHUP . | |
3979 | To prevent the shell from | |
3980 | sending the signal to a particular job, it should be removed from the | |
ccc6cda3 JA |
3981 | jobs table with the |
3982 | .B disown | |
3983 | builtin (see | |
3984 | .SM | |
3985 | .B "SHELL BUILTIN COMMANDS" | |
cce855bc JA |
3986 | below) or marked |
3987 | to not receive | |
ccc6cda3 | 3988 | .SM |
cce855bc JA |
3989 | .B SIGHUP |
3990 | using | |
3991 | .BR "disown \-h" . | |
3992 | .PP | |
3993 | If the | |
3994 | .B huponexit | |
3995 | shell option has been set with | |
3996 | .BR shopt , | |
3997 | .B bash | |
3998 | sends a | |
3999 | .SM | |
4000 | .B SIGHUP | |
4001 | to all jobs when an interactive login shell exits. | |
4002 | .PP | |
b66cc816 | 4003 | If \fBbash\fP is waiting for a command to complete and receives a signal |
5e13499c CR |
4004 | for which a trap has been set, the trap will not be executed until |
4005 | the command completes. | |
cce855bc JA |
4006 | When \fBbash\fP is waiting for an asynchronous command via the \fBwait\fP |
4007 | builtin, the reception of a signal for which a trap has been set will | |
4008 | cause the \fBwait\fP builtin to return immediately with an exit status | |
4009 | greater than 128, immediately after which the trap is executed. | |
ccc6cda3 JA |
4010 | .SH "JOB CONTROL" |
4011 | .I Job control | |
4012 | refers to the ability to selectively stop (\fIsuspend\fP) | |
4013 | the execution of processes and continue (\fIresume\fP) | |
4014 | their execution at a later point. A user typically employs | |
4015 | this facility via an interactive interface supplied jointly | |
4016 | by the system's terminal driver and | |
4017 | .BR bash . | |
4018 | .PP | |
4019 | The shell associates a | |
4020 | .I job | |
4021 | with each pipeline. It keeps a table of currently executing | |
4022 | jobs, which may be listed with the | |
4023 | .B jobs | |
4024 | command. When | |
4025 | .B bash | |
4026 | starts a job asynchronously (in the | |
4027 | .IR background ), | |
4028 | it prints a line that looks like: | |
4029 | .RS | |
4030 | .PP | |
4031 | [1] 25647 | |
4032 | .RE | |
4033 | .PP | |
4034 | indicating that this job is job number 1 and that the process ID | |
4035 | of the last process in the pipeline associated with this job is 25647. | |
4036 | All of the processes in a single pipeline are members of the same job. | |
4037 | .B Bash | |
4038 | uses the | |
4039 | .I job | |
4040 | abstraction as the basis for job control. | |
4041 | .PP | |
4042 | To facilitate the implementation of the user interface to job | |
bb70624e | 4043 | control, the operating system maintains the notion of a \fIcurrent terminal |
ccc6cda3 JA |
4044 | process group ID\fP. Members of this process group (processes whose |
4045 | process group ID is equal to the current terminal process group ID) | |
4046 | receive keyboard-generated signals such as | |
4047 | .SM | |
4048 | .BR SIGINT . | |
4049 | These processes are said to be in the | |
4050 | .IR foreground . | |
4051 | .I Background | |
4052 | processes are those whose process group ID differs from the terminal's; | |
4053 | such processes are immune to keyboard-generated signals. | |
4054 | Only foreground processes are allowed to read from or write to the | |
4055 | terminal. Background processes which attempt to read from (write to) the | |
4056 | terminal are sent a | |
4057 | .SM | |
4058 | .B SIGTTIN (SIGTTOU) | |
4059 | signal by the terminal driver, | |
4060 | which, unless caught, suspends the process. | |
4061 | .PP | |
4062 | If the operating system on which | |
4063 | .B bash | |
4064 | is running supports | |
4065 | job control, | |
4066 | .B bash | |
bb70624e | 4067 | contains facilities to use it. |
ccc6cda3 JA |
4068 | Typing the |
4069 | .I suspend | |
4070 | character (typically | |
4071 | .BR ^Z , | |
4072 | Control-Z) while a process is running | |
bb70624e | 4073 | causes that process to be stopped and returns control to |
ccc6cda3 JA |
4074 | .BR bash . |
4075 | Typing the | |
4076 | .I "delayed suspend" | |
4077 | character (typically | |
4078 | .BR ^Y , | |
4079 | Control-Y) causes the process to be stopped when it | |
4080 | attempts to read input from the terminal, and control to | |
4081 | be returned to | |
4082 | .BR bash . | |
cce855bc | 4083 | The user may then manipulate the state of this job, using the |
ccc6cda3 JA |
4084 | .B bg |
4085 | command to continue it in the background, the | |
4086 | .B fg | |
4087 | command to continue it in the foreground, or | |
4088 | the | |
4089 | .B kill | |
4090 | command to kill it. A \fB^Z\fP takes effect immediately, | |
4091 | and has the additional side effect of causing pending output | |
4092 | and typeahead to be discarded. | |
4093 | .PP | |
4094 | There are a number of ways to refer to a job in the shell. | |
4095 | The character | |
4096 | .B % | |
4097 | introduces a job name. Job number | |
4098 | .I n | |
4099 | may be referred to as | |
4100 | .BR %n . | |
4101 | A job may also be referred to using a prefix of the name used to | |
4102 | start it, or using a substring that appears in its command line. | |
4103 | For example, | |
4104 | .B %ce | |
4105 | refers to a stopped | |
4106 | .B ce | |
4107 | job. If a prefix matches more than one job, | |
4108 | .B bash | |
4109 | reports an error. Using | |
4110 | .BR %?ce , | |
4111 | on the other hand, refers to any job containing the string | |
4112 | .B ce | |
4113 | in its command line. If the substring matches more than one job, | |
4114 | .B bash | |
4115 | reports an error. The symbols | |
4116 | .B %% | |
4117 | and | |
4118 | .B %+ | |
4119 | refer to the shell's notion of the | |
4120 | .IR "current job" , | |
4121 | which is the last job stopped while it was in | |
cce855bc | 4122 | the foreground or started in the background. |
ccc6cda3 JA |
4123 | The |
4124 | .I "previous job" | |
4125 | may be referenced using | |
4126 | .BR %\- . | |
4127 | In output pertaining to jobs (e.g., the output of the | |
4128 | .B jobs | |
4129 | command), the current job is always flagged with a | |
4130 | .BR + , | |
4131 | and the previous job with a | |
4132 | .BR \- . | |
43df7bbb CR |
4133 | A single % (with no accompanying job specification) also refers to the |
4134 | current job. | |
726f6388 | 4135 | .PP |
ccc6cda3 JA |
4136 | Simply naming a job can be used to bring it into the |
4137 | foreground: | |
4138 | .B %1 | |
4139 | is a synonym for | |
4140 | \fB``fg %1''\fP, | |
4141 | bringing job 1 from the background into the foreground. | |
4142 | Similarly, | |
4143 | .B ``%1 &'' | |
4144 | resumes job 1 in the background, equivalent to | |
4145 | \fB``bg %1''\fP. | |
726f6388 | 4146 | .PP |
ccc6cda3 JA |
4147 | The shell learns immediately whenever a job changes state. |
4148 | Normally, | |
4149 | .B bash | |
4150 | waits until it is about to print a prompt before reporting | |
4151 | changes in a job's status so as to not interrupt | |
4152 | any other output. If the | |
4153 | .B \-b | |
4154 | option to the | |
726f6388 | 4155 | .B set |
ccc6cda3 | 4156 | builtin command |
cce855bc | 4157 | is enabled, |
726f6388 | 4158 | .B bash |
ccc6cda3 | 4159 | reports such changes immediately. |
f73dda09 JA |
4160 | Any trap on |
4161 | .SM | |
4162 | .B SIGCHLD | |
4163 | is executed for each child that exits. | |
726f6388 | 4164 | .PP |
ccc6cda3 JA |
4165 | If an attempt to exit |
4166 | .B bash | |
4167 | is made while jobs are stopped, the shell prints a warning message. The | |
4168 | .B jobs | |
4169 | command may then be used to inspect their status. | |
4170 | If a second attempt to exit is made without an intervening command, | |
4171 | the shell does not print another warning, and the stopped | |
4172 | jobs are terminated. | |
726f6388 JA |
4173 | .SH PROMPTING |
4174 | When executing interactively, | |
4175 | .B bash | |
4176 | displays the primary prompt | |
4177 | .SM | |
4178 | .B PS1 | |
4179 | when it is ready to read a command, and the secondary prompt | |
4180 | .SM | |
4181 | .B PS2 | |
4182 | when it needs more input to complete a command. | |
4183 | .B Bash | |
4184 | allows these prompt strings to be customized by inserting a number of | |
4185 | backslash-escaped special characters that are decoded as follows: | |
4186 | .RS | |
4187 | .PD 0 | |
4188 | .TP | |
ccc6cda3 JA |
4189 | .B \ea |
4190 | an ASCII bell character (07) | |
726f6388 JA |
4191 | .TP |
4192 | .B \ed | |
4193 | the date in "Weekday Month Date" format (e.g., "Tue May 26") | |
4194 | .TP | |
7117c2d2 JA |
4195 | .B \eD{\fIformat\fP} |
4196 | the \fIformat\fP is passed to \fIstrftime\fP(3) and the result is inserted | |
4197 | into the prompt string; an empty \fIformat\fP results in a locale-specific | |
4198 | time representation. The braces are required | |
4199 | .TP | |
ccc6cda3 JA |
4200 | .B \ee |
4201 | an ASCII escape character (033) | |
4202 | .TP | |
4203 | .B \eh | |
4204 | the hostname up to the first `.' | |
4205 | .TP | |
4206 | .B \eH | |
4207 | the hostname | |
4208 | .TP | |
bb70624e JA |
4209 | .B \ej |
4210 | the number of jobs currently managed by the shell | |
4211 | .TP | |
4212 | .B \el | |
4213 | the basename of the shell's terminal device name | |
4214 | .TP | |
726f6388 JA |
4215 | .B \en |
4216 | newline | |
4217 | .TP | |
cce855bc JA |
4218 | .B \er |
4219 | carriage return | |
4220 | .TP | |
726f6388 JA |
4221 | .B \es |
4222 | the name of the shell, the basename of | |
4223 | .B $0 | |
4224 | (the portion following the final slash) | |
4225 | .TP | |
ccc6cda3 JA |
4226 | .B \et |
4227 | the current time in 24-hour HH:MM:SS format | |
726f6388 | 4228 | .TP |
ccc6cda3 JA |
4229 | .B \eT |
4230 | the current time in 12-hour HH:MM:SS format | |
4231 | .TP | |
4232 | .B \e@ | |
4233 | the current time in 12-hour am/pm format | |
726f6388 | 4234 | .TP |
f73dda09 JA |
4235 | .B \eA |
4236 | the current time in 24-hour HH:MM format | |
4237 | .TP | |
726f6388 JA |
4238 | .B \eu |
4239 | the username of the current user | |
4240 | .TP | |
ccc6cda3 JA |
4241 | .B \ev |
4242 | the version of \fBbash\fP (e.g., 2.00) | |
726f6388 | 4243 | .TP |
ccc6cda3 | 4244 | .B \eV |
a5e25162 | 4245 | the release of \fBbash\fP, version + patch level (e.g., 2.00.0) |
ccc6cda3 JA |
4246 | .TP |
4247 | .B \ew | |
12d937f9 | 4248 | the current working directory, with \fB$HOME\fP abbreviated with a tilde |
ccc6cda3 JA |
4249 | .TP |
4250 | .B \eW | |
12d937f9 CR |
4251 | the basename of the current working directory, with \fB$HOME\fP |
4252 | abbreviated with a tilde | |
726f6388 JA |
4253 | .TP |
4254 | .B \e! | |
4255 | the history number of this command | |
4256 | .TP | |
ccc6cda3 JA |
4257 | .B \e# |
4258 | the command number of this command | |
4259 | .TP | |
726f6388 JA |
4260 | .B \e$ |
4261 | if the effective UID is 0, a | |
4262 | .BR # , | |
4263 | otherwise a | |
4264 | .B $ | |
4265 | .TP | |
ccc6cda3 JA |
4266 | .B \e\fInnn\fP |
4267 | the character corresponding to the octal number \fInnn\fP | |
726f6388 JA |
4268 | .TP |
4269 | .B \e\e | |
4270 | a backslash | |
4271 | .TP | |
4272 | .B \e[ | |
4273 | begin a sequence of non-printing characters, which could be used to | |
4274 | embed a terminal control sequence into the prompt | |
4275 | .TP | |
4276 | .B \e] | |
4277 | end a sequence of non-printing characters | |
4278 | .PD | |
4279 | .RE | |
4280 | .PP | |
4281 | The command number and the history number are usually different: | |
4282 | the history number of a command is its position in the history | |
4283 | list, which may include commands restored from the history file | |
4284 | (see | |
4285 | .SM | |
4286 | .B HISTORY | |
4287 | below), while the command number is the position in the sequence | |
4288 | of commands executed during the current shell session. | |
4289 | After the string is decoded, it is expanded via | |
bb70624e JA |
4290 | parameter expansion, command substitution, arithmetic |
4291 | expansion, and quote removal, subject to the value of the | |
ccc6cda3 JA |
4292 | .B promptvars |
4293 | shell option (see the description of the | |
4294 | .B shopt | |
4295 | command under | |
4296 | .SM | |
4297 | .B "SHELL BUILTIN COMMANDS" | |
4298 | below). | |
726f6388 JA |
4299 | .SH READLINE |
4300 | This is the library that handles reading input when using an interactive | |
4301 | shell, unless the | |
d166f048 | 4302 | .B \-\-noediting |
ccc6cda3 JA |
4303 | option is given at shell invocation. |
4304 | By default, the line editing commands are similar to those of emacs. | |
726f6388 | 4305 | A vi-style line editing interface is also available. |
ccc6cda3 JA |
4306 | To turn off line editing after the shell is running, use the |
4307 | .B +o emacs | |
4308 | or | |
4309 | .B +o vi | |
4310 | options to the | |
4311 | .B set | |
4312 | builtin (see | |
4313 | .SM | |
4314 | .B SHELL BUILTIN COMMANDS | |
4315 | below). | |
4316 | .SS "Readline Notation" | |
726f6388 JA |
4317 | .PP |
4318 | In this section, the emacs-style notation is used to denote | |
4319 | keystrokes. Control keys are denoted by C\-\fIkey\fR, e.g., C\-n | |
4320 | means Control\-N. Similarly, | |
4321 | .I meta | |
4322 | keys are denoted by M\-\fIkey\fR, so M\-x means Meta\-X. (On keyboards | |
4323 | without a | |
4324 | .I meta | |
4325 | key, M\-\fIx\fP means ESC \fIx\fP, i.e., press the Escape key | |
4326 | then the | |
4327 | .I x | |
4328 | key. This makes ESC the \fImeta prefix\fP. | |
4329 | The combination M\-C\-\fIx\fP means ESC\-Control\-\fIx\fP, | |
4330 | or press the Escape key | |
4331 | then hold the Control key while pressing the | |
4332 | .I x | |
4333 | key.) | |
4334 | .PP | |
ccc6cda3 JA |
4335 | Readline commands may be given numeric |
4336 | .IR arguments , | |
4337 | which normally act as a repeat count. | |
4338 | Sometimes, however, it is the sign of the argument that is significant. | |
4339 | Passing a negative argument to a command that acts in the forward | |
4340 | direction (e.g., \fBkill\-line\fP) causes that command to act in a | |
4341 | backward direction. | |
4342 | Commands whose behavior with arguments deviates from this are noted | |
4343 | below. | |
4344 | .PP | |
4345 | When a command is described as \fIkilling\fP text, the text | |
4346 | deleted is saved for possible future retrieval | |
4347 | (\fIyanking\fP). The killed text is saved in a | |
4348 | \fIkill ring\fP. Consecutive kills cause the text to be | |
4349 | accumulated into one unit, which can be yanked all at once. | |
4350 | Commands which do not kill text separate the chunks of text | |
4351 | on the kill ring. | |
4352 | .SS "Readline Initialization" | |
4353 | .PP | |
4354 | Readline is customized by putting commands in an initialization | |
4355 | file (the \fIinputrc\fP file). | |
4356 | The name of this file is taken from the value of the | |
726f6388 | 4357 | .SM |
ccc6cda3 JA |
4358 | .B INPUTRC |
4359 | variable. If that variable is unset, the default is | |
726f6388 | 4360 | .IR ~/.inputrc . |
ccc6cda3 JA |
4361 | When a program which uses the readline library starts up, the |
4362 | initialization file is read, and the key bindings and variables | |
4363 | are set. | |
4364 | There are only a few basic constructs allowed in the | |
4365 | readline initialization file. | |
4366 | Blank lines are ignored. | |
4367 | Lines beginning with a \fB#\fP are comments. | |
4368 | Lines beginning with a \fB$\fP indicate conditional constructs. | |
4369 | Other lines denote key bindings and variable settings. | |
4370 | .PP | |
4371 | The default key-bindings may be changed with an | |
4372 | .I inputrc | |
4373 | file. | |
726f6388 JA |
4374 | Other programs that use this library may add their own commands |
4375 | and bindings. | |
4376 | .PP | |
4377 | For example, placing | |
4378 | .RS | |
4379 | .PP | |
4380 | M\-Control\-u: universal\-argument | |
4381 | .RE | |
4382 | or | |
4383 | .RS | |
4384 | C\-Meta\-u: universal\-argument | |
4385 | .RE | |
4386 | into the | |
ccc6cda3 | 4387 | .I inputrc |
726f6388 JA |
4388 | would make M\-C\-u execute the readline command |
4389 | .IR universal\-argument . | |
4390 | .PP | |
4391 | The following symbolic character names are recognized: | |
4392 | .IR RUBOUT , | |
4393 | .IR DEL , | |
4394 | .IR ESC , | |
4395 | .IR LFD , | |
4396 | .IR NEWLINE , | |
4397 | .IR RET , | |
4398 | .IR RETURN , | |
4399 | .IR SPC , | |
4400 | .IR SPACE , | |
4401 | and | |
4402 | .IR TAB . | |
bb70624e | 4403 | .PP |
726f6388 JA |
4404 | In addition to command names, readline allows keys to be bound |
4405 | to a string that is inserted when the key is pressed (a \fImacro\fP). | |
ccc6cda3 | 4406 | .SS "Readline Key Bindings" |
726f6388 JA |
4407 | .PP |
4408 | The syntax for controlling key bindings in the | |
cce855bc | 4409 | .I inputrc |
726f6388 JA |
4410 | file is simple. All that is required is the name of the |
4411 | command or the text of a macro and a key sequence to which | |
4412 | it should be bound. The name may be specified in one of two ways: | |
ccc6cda3 | 4413 | as a symbolic key name, possibly with \fIMeta\-\fP or \fIControl\-\fP |
726f6388 | 4414 | prefixes, or as a key sequence. |
28ef6c31 | 4415 | .PP |
cce855bc | 4416 | When using the form \fBkeyname\fP:\^\fIfunction\-name\fP or \fImacro\fP, |
726f6388 JA |
4417 | .I keyname |
4418 | is the name of a key spelled out in English. For example: | |
4419 | .sp | |
4420 | .RS | |
4421 | Control-u: universal\-argument | |
4422 | .br | |
4423 | Meta-Rubout: backward-kill-word | |
4424 | .br | |
ccc6cda3 | 4425 | Control-o: "> output" |
726f6388 JA |
4426 | .RE |
4427 | .LP | |
4428 | In the above example, | |
ccc6cda3 | 4429 | .I C\-u |
726f6388 JA |
4430 | is bound to the function |
4431 | .BR universal\-argument , | |
ccc6cda3 | 4432 | .I M\-DEL |
726f6388 JA |
4433 | is bound to the function |
4434 | .BR backward\-kill\-word , | |
4435 | and | |
ccc6cda3 | 4436 | .I C\-o |
726f6388 JA |
4437 | is bound to run the macro |
4438 | expressed on the right hand side (that is, to insert the text | |
28ef6c31 JA |
4439 | .if t \f(CW> output\fP |
4440 | .if n ``> output'' | |
726f6388 JA |
4441 | into the line). |
4442 | .PP | |
cce855bc | 4443 | In the second form, \fB"keyseq"\fP:\^\fIfunction\-name\fP or \fImacro\fP, |
726f6388 JA |
4444 | .B keyseq |
4445 | differs from | |
4446 | .B keyname | |
4447 | above in that strings denoting | |
4448 | an entire key sequence may be specified by placing the sequence | |
4449 | within double quotes. Some GNU Emacs style key escapes can be | |
28ef6c31 JA |
4450 | used, as in the following example, but the symbolic character names |
4451 | are not recognized. | |
726f6388 JA |
4452 | .sp |
4453 | .RS | |
ccc6cda3 | 4454 | "\eC\-u": universal\-argument |
726f6388 | 4455 | .br |
ccc6cda3 | 4456 | "\eC\-x\eC\-r": re\-read\-init\-file |
726f6388 JA |
4457 | .br |
4458 | "\ee[11~": "Function Key 1" | |
4459 | .RE | |
4460 | .PP | |
4461 | In this example, | |
ccc6cda3 | 4462 | .I C\-u |
726f6388 JA |
4463 | is again bound to the function |
4464 | .BR universal\-argument . | |
ccc6cda3 | 4465 | .I "C\-x C\-r" |
726f6388 JA |
4466 | is bound to the function |
4467 | .BR re\-read\-init\-file , | |
4468 | and | |
4469 | .I "ESC [ 1 1 ~" | |
4470 | is bound to insert the text | |
28ef6c31 JA |
4471 | .if t \f(CWFunction Key 1\fP. |
4472 | .if n ``Function Key 1''. | |
4473 | .PP | |
cce855bc | 4474 | The full set of GNU Emacs style escape sequences is |
726f6388 | 4475 | .RS |
cce855bc | 4476 | .PD 0 |
726f6388 JA |
4477 | .TP |
4478 | .B \eC\- | |
4479 | control prefix | |
4480 | .TP | |
ccc6cda3 | 4481 | .B \eM\- |
726f6388 JA |
4482 | meta prefix |
4483 | .TP | |
4484 | .B \ee | |
4485 | an escape character | |
4486 | .TP | |
4487 | .B \e\e | |
4488 | backslash | |
4489 | .TP | |
4490 | .B \e" | |
4491 | literal " | |
4492 | .TP | |
20587658 CR |
4493 | .B \e\(aq |
4494 | literal \(aq | |
726f6388 | 4495 | .RE |
cce855bc JA |
4496 | .PD |
4497 | .PP | |
4498 | In addition to the GNU Emacs style escape sequences, a second | |
4499 | set of backslash escapes is available: | |
4500 | .RS | |
4501 | .PD 0 | |
4502 | .TP | |
4503 | .B \ea | |
4504 | alert (bell) | |
4505 | .TP | |
4506 | .B \eb | |
4507 | backspace | |
4508 | .TP | |
4509 | .B \ed | |
4510 | delete | |
4511 | .TP | |
4512 | .B \ef | |
4513 | form feed | |
4514 | .TP | |
4515 | .B \en | |
4516 | newline | |
4517 | .TP | |
4518 | .B \er | |
4519 | carriage return | |
4520 | .TP | |
4521 | .B \et | |
4522 | horizontal tab | |
4523 | .TP | |
4524 | .B \ev | |
4525 | vertical tab | |
4526 | .TP | |
4527 | .B \e\fInnn\fP | |
f73dda09 | 4528 | the eight-bit character whose value is the octal value \fInnn\fP |
cce855bc JA |
4529 | (one to three digits) |
4530 | .TP | |
f73dda09 JA |
4531 | .B \ex\fIHH\fP |
4532 | the eight-bit character whose value is the hexadecimal value \fIHH\fP | |
4533 | (one or two hex digits) | |
cce855bc JA |
4534 | .RE |
4535 | .PD | |
726f6388 | 4536 | .PP |
cce855bc JA |
4537 | When entering the text of a macro, single or double quotes must |
4538 | be used to indicate a macro definition. | |
4539 | Unquoted text is assumed to be a function name. | |
4540 | In the macro body, the backslash escapes described above are expanded. | |
4541 | Backslash will quote any other character in the macro text, | |
20587658 | 4542 | including " and \(aq. |
726f6388 JA |
4543 | .PP |
4544 | .B Bash | |
4545 | allows the current readline key bindings to be displayed or modified | |
4546 | with the | |
4547 | .B bind | |
4548 | builtin command. The editing mode may be switched during interactive | |
4549 | use by using the | |
4550 | .B \-o | |
4551 | option to the | |
4552 | .B set | |
4553 | builtin command (see | |
4554 | .SM | |
4555 | .B SHELL BUILTIN COMMANDS | |
4556 | below). | |
ccc6cda3 | 4557 | .SS "Readline Variables" |
726f6388 JA |
4558 | .PP |
4559 | Readline has variables that can be used to further customize its | |
4560 | behavior. A variable may be set in the | |
4561 | .I inputrc | |
4562 | file with a statement of the form | |
4563 | .RS | |
4564 | .PP | |
4565 | \fBset\fP \fIvariable\-name\fP \fIvalue\fP | |
4566 | .RE | |
4567 | .PP | |
4568 | Except where noted, readline variables can take the values | |
4569 | .B On | |
4570 | or | |
ff247e74 CR |
4571 | .B Off |
4572 | (without regard to case). | |
4573 | Unrecognized variable names are ignored. | |
4574 | When a variable value is read, empty or null values, "on" (case-insensitive), | |
4575 | and "1" are equivalent to \fBOn\fP. All other values are equivalent to | |
4576 | \fBOff\fP. | |
726f6388 JA |
4577 | The variables and their default values are: |
4578 | .PP | |
4579 | .PD 0 | |
4580 | .TP | |
726f6388 JA |
4581 | .B bell\-style (audible) |
4582 | Controls what happens when readline wants to ring the terminal bell. | |
4583 | If set to \fBnone\fP, readline never rings the bell. If set to | |
4584 | \fBvisible\fP, readline uses a visible bell if one is available. | |
4585 | If set to \fBaudible\fP, readline attempts to ring the terminal's bell. | |
4586 | .TP | |
453f278a CR |
4587 | .B bind\-tty\-special\-chars (On) |
4588 | If set to \fBOn\fP, readline attempts to bind the control characters | |
4589 | treated specially by the kernel's terminal driver to their readline | |
4590 | equivalents. | |
4591 | .TP | |
726f6388 | 4592 | .B comment\-begin (``#'') |
bb70624e | 4593 | The string that is inserted when the readline |
ccc6cda3 | 4594 | .B insert\-comment |
726f6388 | 4595 | command is executed. |
ccc6cda3 JA |
4596 | This command is bound to |
4597 | .B M\-# | |
4598 | in emacs mode and to | |
4599 | .B # | |
4600 | in vi command mode. | |
726f6388 | 4601 | .TP |
cce855bc JA |
4602 | .B completion\-ignore\-case (Off) |
4603 | If set to \fBOn\fP, readline performs filename matching and completion | |
4604 | in a case\-insensitive fashion. | |
4605 | .TP | |
726f6388 JA |
4606 | .B completion\-query\-items (100) |
4607 | This determines when the user is queried about viewing | |
4608 | the number of possible completions | |
4609 | generated by the \fBpossible\-completions\fP command. | |
4610 | It may be set to any integer value greater than or equal to | |
4611 | zero. If the number of possible completions is greater than | |
4612 | or equal to the value of this variable, the user is asked whether | |
4613 | or not he wishes to view them; otherwise they are simply listed | |
4614 | on the terminal. | |
4615 | .TP | |
ccc6cda3 JA |
4616 | .B convert\-meta (On) |
4617 | If set to \fBOn\fP, readline will convert characters with the | |
4618 | eighth bit set to an ASCII key sequence | |
bb70624e | 4619 | by stripping the eighth bit and prefixing an |
ccc6cda3 JA |
4620 | escape character (in effect, using escape as the \fImeta prefix\fP). |
4621 | .TP | |
4622 | .B disable\-completion (Off) | |
4623 | If set to \fBOn\fP, readline will inhibit word completion. Completion | |
4624 | characters will be inserted into the line as if they had been | |
4625 | mapped to \fBself-insert\fP. | |
4626 | .TP | |
4627 | .B editing\-mode (emacs) | |
4628 | Controls whether readline begins with a set of key bindings similar | |
4629 | to \fIemacs\fP or \fIvi\fP. | |
4630 | .B editing\-mode | |
4631 | can be set to either | |
4632 | .B emacs | |
4633 | or | |
4634 | .BR vi . | |
4635 | .TP | |
4636 | .B enable\-keypad (Off) | |
4637 | When set to \fBOn\fP, readline will try to enable the application | |
4638 | keypad when it is called. Some systems need this to enable the | |
4639 | arrow keys. | |
4640 | .TP | |
4641 | .B expand\-tilde (Off) | |
4642 | If set to \fBon\fP, tilde expansion is performed when readline | |
4643 | attempts word completion. | |
4644 | .TP | |
cdb32d45 | 4645 | .B history\-preserve\-point (Off) |
f73dda09 | 4646 | If set to \fBon\fP, the history code attempts to place point at the |
f75912ae | 4647 | same location on each history line retrieved with \fBprevious-history\fP |
f73dda09 JA |
4648 | or \fBnext-history\fP. |
4649 | .TP | |
ccc6cda3 JA |
4650 | .B horizontal\-scroll\-mode (Off) |
4651 | When set to \fBOn\fP, makes readline use a single line for display, | |
4652 | scrolling the input horizontally on a single screen line when it | |
4653 | becomes longer than the screen width rather than wrapping to a new line. | |
4654 | .TP | |
4655 | .B input\-meta (Off) | |
4656 | If set to \fBOn\fP, readline will enable eight-bit input (that is, | |
4657 | it will not strip the high bit from the characters it reads), | |
4658 | regardless of what the terminal claims it can support. The name | |
4659 | .B meta\-flag | |
4660 | is a synonym for this variable. | |
4661 | .TP | |
b72432fd JA |
4662 | .B isearch\-terminators (``C\-[C\-J'') |
4663 | The string of characters that should terminate an incremental | |
4664 | search without subsequently executing the character as a command. | |
4665 | If this variable has not been given a value, the characters | |
4666 | \fIESC\fP and \fIC\-J\fP will terminate an incremental search. | |
4667 | .TP | |
726f6388 | 4668 | .B keymap (emacs) |
cce855bc | 4669 | Set the current readline keymap. The set of valid keymap names is |
ccc6cda3 JA |
4670 | \fIemacs, emacs\-standard, emacs\-meta, emacs\-ctlx, vi, |
4671 | vi\-command\fP, and | |
4672 | .IR vi\-insert . | |
4673 | \fIvi\fP is equivalent to \fIvi\-command\fP; \fIemacs\fP is | |
4674 | equivalent to \fIemacs\-standard\fP. The default value is | |
726f6388 JA |
4675 | .IR emacs ; |
4676 | the value of | |
4677 | .B editing\-mode | |
4678 | also affects the default keymap. | |
4679 | .TP | |
ccc6cda3 JA |
4680 | .B mark\-directories (On) |
4681 | If set to \fBOn\fP, completed directory names have a slash | |
4682 | appended. | |
4683 | .TP | |
4684 | .B mark\-modified\-lines (Off) | |
4685 | If set to \fBOn\fP, history lines that have been modified are displayed | |
4686 | with a preceding asterisk (\fB*\fP). | |
4687 | .TP | |
7117c2d2 JA |
4688 | .B mark\-symlinked\-directories (Off) |
4689 | If set to \fBOn\fP, completed names which are symbolic links to directories | |
4690 | have a slash appended (subject to the value of | |
4691 | \fBmark\-directories\fP). | |
4692 | .TP | |
f73dda09 JA |
4693 | .B match\-hidden\-files (On) |
4694 | This variable, when set to \fBOn\fP, causes readline to match files whose | |
4695 | names begin with a `.' (hidden files) when performing filename | |
4696 | completion, unless the leading `.' is | |
4697 | supplied by the user in the filename to be completed. | |
4698 | .TP | |
ccc6cda3 JA |
4699 | .B output\-meta (Off) |
4700 | If set to \fBOn\fP, readline will display characters with the | |
4701 | eighth bit set directly rather than as a meta-prefixed escape | |
4702 | sequence. | |
4703 | .TP | |
7117c2d2 JA |
4704 | .B page\-completions (On) |
4705 | If set to \fBOn\fP, readline uses an internal \fImore\fP-like pager | |
4706 | to display a screenful of possible completions at a time. | |
4707 | .TP | |
cce855bc JA |
4708 | .B print\-completions\-horizontally (Off) |
4709 | If set to \fBOn\fP, readline will display completions with matches | |
4710 | sorted horizontally in alphabetical order, rather than down the screen. | |
4711 | .TP | |
726f6388 JA |
4712 | .B show\-all\-if\-ambiguous (Off) |
4713 | This alters the default behavior of the completion functions. If | |
4714 | set to | |
4715 | .BR on , | |
4716 | words which have more than one possible completion cause the | |
4717 | matches to be listed immediately instead of ringing the bell. | |
4718 | .TP | |
d3a24ed2 CR |
4719 | .B show\-all\-if\-unmodified (Off) |
4720 | This alters the default behavior of the completion functions in | |
4721 | a fashion similar to \fBshow\-all\-if\-ambiguous\fP. | |
4722 | If set to | |
4723 | .BR on , | |
4724 | words which have more than one possible completion without any | |
4725 | possible partial completion (the possible completions don't share | |
4726 | a common prefix) cause the matches to be listed immediately instead | |
4727 | of ringing the bell. | |
4728 | .TP | |
ccc6cda3 JA |
4729 | .B visible\-stats (Off) |
4730 | If set to \fBOn\fP, a character denoting a file's type as reported | |
4731 | by \fIstat\fP(2) is appended to the filename when listing possible | |
4732 | completions. | |
726f6388 | 4733 | .PD |
ccc6cda3 | 4734 | .SS "Readline Conditional Constructs" |
726f6388 JA |
4735 | .PP |
4736 | Readline implements a facility similar in spirit to the conditional | |
4737 | compilation features of the C preprocessor which allows key | |
4738 | bindings and variable settings to be performed as the result | |
cce855bc | 4739 | of tests. There are four parser directives used. |
726f6388 JA |
4740 | .IP \fB$if\fP |
4741 | The | |
4742 | .B $if | |
4743 | construct allows bindings to be made based on the | |
4744 | editing mode, the terminal being used, or the application using | |
4745 | readline. The text of the test extends to the end of the line; | |
4746 | no characters are required to isolate it. | |
4747 | .RS | |
4748 | .IP \fBmode\fP | |
4749 | The \fBmode=\fP form of the \fB$if\fP directive is used to test | |
4750 | whether readline is in emacs or vi mode. | |
4751 | This may be used in conjunction | |
4752 | with the \fBset keymap\fP command, for instance, to set bindings in | |
ccc6cda3 | 4753 | the \fIemacs\-standard\fP and \fIemacs\-ctlx\fP keymaps only if |
726f6388 JA |
4754 | readline is starting out in emacs mode. |
4755 | .IP \fBterm\fP | |
4756 | The \fBterm=\fP form may be used to include terminal-specific | |
4757 | key bindings, perhaps to bind the key sequences output by the | |
4758 | terminal's function keys. The word on the right side of the | |
4759 | .B = | |
cce855bc | 4760 | is tested against the both full name of the terminal and the portion |
726f6388 JA |
4761 | of the terminal name before the first \fB\-\fP. This allows |
4762 | .I sun | |
4763 | to match both | |
4764 | .I sun | |
4765 | and | |
4766 | .IR sun\-cmd , | |
4767 | for instance. | |
4768 | .IP \fBapplication\fP | |
4769 | The \fBapplication\fP construct is used to include | |
ccc6cda3 | 4770 | application-specific settings. Each program using the readline |
726f6388 JA |
4771 | library sets the \fIapplication name\fP, and an initialization |
4772 | file can test for a particular value. | |
4773 | This could be used to bind key sequences to functions useful for | |
4774 | a specific program. For instance, the following command adds a | |
4775 | key sequence that quotes the current or previous word in Bash: | |
cce855bc | 4776 | .sp 1 |
726f6388 JA |
4777 | .RS |
4778 | .nf | |
4779 | \fB$if\fP Bash | |
4780 | # Quote the current or previous word | |
ccc6cda3 | 4781 | "\eC\-xq": "\eeb\e"\eef\e"" |
726f6388 JA |
4782 | \fB$endif\fP |
4783 | .fi | |
4784 | .RE | |
4785 | .RE | |
4786 | .IP \fB$endif\fP | |
cce855bc | 4787 | This command, as seen in the previous example, terminates an |
726f6388 JA |
4788 | \fB$if\fP command. |
4789 | .IP \fB$else\fP | |
4790 | Commands in this branch of the \fB$if\fP directive are executed if | |
4791 | the test fails. | |
cce855bc JA |
4792 | .IP \fB$include\fP |
4793 | This directive takes a single filename as an argument and reads commands | |
4794 | and bindings from that file. For example, the following directive | |
4795 | would read \fI/etc/inputrc\fP: | |
4796 | .sp 1 | |
4797 | .RS | |
4798 | .nf | |
4799 | \fB$include\fP \^ \fI/etc/inputrc\fP | |
4800 | .fi | |
4801 | .RE | |
ccc6cda3 | 4802 | .SS Searching |
726f6388 | 4803 | .PP |
ccc6cda3 JA |
4804 | Readline provides commands for searching through the command history |
4805 | (see | |
4806 | .SM | |
4807 | .B HISTORY | |
4808 | below) for lines containing a specified string. | |
4809 | There are two search modes: | |
4810 | .I incremental | |
4811 | and | |
4812 | .IR non-incremental . | |
4813 | .PP | |
4814 | Incremental searches begin before the user has finished typing the | |
4815 | search string. | |
4816 | As each character of the search string is typed, readline displays | |
4817 | the next entry from the history matching the string typed so far. | |
4818 | An incremental search requires only as many characters as needed to | |
4819 | find the desired history entry. | |
bb70624e | 4820 | The characters present in the value of the \fBisearch-terminators\fP |
b72432fd JA |
4821 | variable are used to terminate an incremental search. |
4822 | If that variable has not been assigned a value the Escape and | |
4823 | Control-J characters will terminate an incremental search. | |
ccc6cda3 JA |
4824 | Control-G will abort an incremental search and restore the original |
4825 | line. | |
4826 | When the search is terminated, the history entry containing the | |
4827 | search string becomes the current line. | |
bb70624e | 4828 | .PP |
ccc6cda3 JA |
4829 | To find other matching entries in the history list, type Control-S or |
4830 | Control-R as appropriate. | |
4831 | This will search backward or forward in the history for the next | |
4832 | entry matching the search string typed so far. | |
4833 | Any other key sequence bound to a readline command will terminate | |
4834 | the search and execute that command. | |
4835 | For instance, a \fInewline\fP will terminate the search and accept | |
4836 | the line, thereby executing the command from the history list. | |
4837 | .PP | |
f73dda09 JA |
4838 | Readline remembers the last incremental search string. If two |
4839 | Control-Rs are typed without any intervening characters defining a | |
4840 | new search string, any remembered search string is used. | |
4841 | .PP | |
ccc6cda3 JA |
4842 | Non-incremental searches read the entire search string before starting |
4843 | to search for matching history lines. The search string may be | |
cce855bc | 4844 | typed by the user or be part of the contents of the current line. |
ccc6cda3 | 4845 | .SS "Readline Command Names" |
726f6388 JA |
4846 | .PP |
4847 | The following is a list of the names of the commands and the default | |
4848 | key sequences to which they are bound. | |
ccc6cda3 | 4849 | Command names without an accompanying key sequence are unbound by default. |
bb70624e JA |
4850 | In the following descriptions, \fIpoint\fP refers to the current cursor |
4851 | position, and \fImark\fP refers to a cursor position saved by the | |
4852 | \fBset\-mark\fP command. | |
4853 | The text between the point and mark is referred to as the \fIregion\fP. | |
726f6388 JA |
4854 | .SS Commands for Moving |
4855 | .PP | |
4856 | .PD 0 | |
4857 | .TP | |
4858 | .B beginning\-of\-line (C\-a) | |
4859 | Move to the start of the current line. | |
4860 | .TP | |
4861 | .B end\-of\-line (C\-e) | |
4862 | Move to the end of the line. | |
4863 | .TP | |
4864 | .B forward\-char (C\-f) | |
4865 | Move forward a character. | |
4866 | .TP | |
4867 | .B backward\-char (C\-b) | |
4868 | Move back a character. | |
4869 | .TP | |
4870 | .B forward\-word (M\-f) | |
4871 | Move forward to the end of the next word. Words are composed of | |
4872 | alphanumeric characters (letters and digits). | |
4873 | .TP | |
4874 | .B backward\-word (M\-b) | |
bb70624e | 4875 | Move back to the start of the current or previous word. Words are |
726f6388 JA |
4876 | composed of alphanumeric characters (letters and digits). |
4877 | .TP | |
4878 | .B clear\-screen (C\-l) | |
4879 | Clear the screen leaving the current line at the top of the screen. | |
4880 | With an argument, refresh the current line without clearing the | |
4881 | screen. | |
4882 | .TP | |
4883 | .B redraw\-current\-line | |
ccc6cda3 | 4884 | Refresh the current line. |
726f6388 JA |
4885 | .PD |
4886 | .SS Commands for Manipulating the History | |
4887 | .PP | |
4888 | .PD 0 | |
4889 | .TP | |
4890 | .B accept\-line (Newline, Return) | |
4891 | Accept the line regardless of where the cursor is. If this line is | |
ccc6cda3 | 4892 | non-empty, add it to the history list according to the state of the |
726f6388 JA |
4893 | .SM |
4894 | .B HISTCONTROL | |
4895 | variable. If the line is a modified history | |
4896 | line, then restore the history line to its original state. | |
4897 | .TP | |
4898 | .B previous\-history (C\-p) | |
4899 | Fetch the previous command from the history list, moving back in | |
4900 | the list. | |
4901 | .TP | |
4902 | .B next\-history (C\-n) | |
4903 | Fetch the next command from the history list, moving forward in the | |
4904 | list. | |
4905 | .TP | |
4906 | .B beginning\-of\-history (M\-<) | |
4907 | Move to the first line in the history. | |
4908 | .TP | |
4909 | .B end\-of\-history (M\->) | |
4910 | Move to the end of the input history, i.e., the line currently being | |
4911 | entered. | |
4912 | .TP | |
4913 | .B reverse\-search\-history (C\-r) | |
4914 | Search backward starting at the current line and moving `up' through | |
4915 | the history as necessary. This is an incremental search. | |
4916 | .TP | |
4917 | .B forward\-search\-history (C\-s) | |
4918 | Search forward starting at the current line and moving `down' through | |
4919 | the history as necessary. This is an incremental search. | |
4920 | .TP | |
4921 | .B non\-incremental\-reverse\-search\-history (M\-p) | |
4922 | Search backward through the history starting at the current line | |
ccc6cda3 | 4923 | using a non-incremental search for a string supplied by the user. |
726f6388 JA |
4924 | .TP |
4925 | .B non\-incremental\-forward\-search\-history (M\-n) | |
ccc6cda3 | 4926 | Search forward through the history using a non-incremental search for |
726f6388 JA |
4927 | a string supplied by the user. |
4928 | .TP | |
4929 | .B history\-search\-forward | |
4930 | Search forward through the history for the string of characters | |
bb70624e | 4931 | between the start of the current line and the point. |
ccc6cda3 | 4932 | This is a non-incremental search. |
726f6388 JA |
4933 | .TP |
4934 | .B history\-search\-backward | |
4935 | Search backward through the history for the string of characters | |
ccc6cda3 JA |
4936 | between the start of the current line and the point. |
4937 | This is a non-incremental search. | |
726f6388 JA |
4938 | .TP |
4939 | .B yank\-nth\-arg (M\-C\-y) | |
4940 | Insert the first argument to the previous command (usually | |
28ef6c31 JA |
4941 | the second word on the previous line) at point. |
4942 | With an argument | |
726f6388 JA |
4943 | .IR n , |
4944 | insert the \fIn\fPth word from the previous command (the words | |
4945 | in the previous command begin with word 0). A negative argument | |
4946 | inserts the \fIn\fPth word from the end of the previous command. | |
eb2bb562 CR |
4947 | Once the argument \fIn\fP is computed, the argument is extracted |
4948 | as if the "!\fIn\fP" history expansion had been specified. | |
726f6388 JA |
4949 | .TP |
4950 | .B | |
4951 | yank\-last\-arg (M\-.\^, M\-_\^) | |
ccc6cda3 JA |
4952 | Insert the last argument to the previous command (the last word of |
4953 | the previous history entry). With an argument, | |
4954 | behave exactly like \fByank\-nth\-arg\fP. | |
cce855bc JA |
4955 | Successive calls to \fByank\-last\-arg\fP move back through the history |
4956 | list, inserting the last argument of each line in turn. | |
eb2bb562 CR |
4957 | The history expansion facilities are used to extract the last argument, |
4958 | as if the "!$" history expansion had been specified. | |
726f6388 JA |
4959 | .TP |
4960 | .B shell\-expand\-line (M\-C\-e) | |
cce855bc | 4961 | Expand the line as the shell does. This |
726f6388 JA |
4962 | performs alias and history expansion as well as all of the shell |
4963 | word expansions. See | |
4964 | .SM | |
4965 | .B HISTORY EXPANSION | |
4966 | below for a description of history expansion. | |
4967 | .TP | |
4968 | .B history\-expand\-line (M\-^) | |
d166f048 JA |
4969 | Perform history expansion on the current line. |
4970 | See | |
726f6388 JA |
4971 | .SM |
4972 | .B HISTORY EXPANSION | |
4973 | below for a description of history expansion. | |
4974 | .TP | |
cce855bc JA |
4975 | .B magic\-space |
4976 | Perform history expansion on the current line and insert a space. | |
4977 | See | |
4978 | .SM | |
4979 | .B HISTORY EXPANSION | |
4980 | below for a description of history expansion. | |
4981 | .TP | |
d166f048 JA |
4982 | .B alias\-expand\-line |
4983 | Perform alias expansion on the current line. | |
4984 | See | |
4985 | .SM | |
4986 | .B ALIASES | |
4987 | above for a description of alias expansion. | |
4988 | .TP | |
4989 | .B history\-and\-alias\-expand\-line | |
4990 | Perform history and alias expansion on the current line. | |
4991 | .TP | |
726f6388 JA |
4992 | .B insert\-last\-argument (M\-.\^, M\-_\^) |
4993 | A synonym for \fByank\-last\-arg\fP. | |
4994 | .TP | |
ccc6cda3 | 4995 | .B operate\-and\-get\-next (C\-o) |
726f6388 JA |
4996 | Accept the current line for execution and fetch the next line |
4997 | relative to the current line from the history for editing. Any | |
4998 | argument is ignored. | |
7117c2d2 JA |
4999 | .TP |
5000 | .B edit\-and\-execute\-command (C\-xC\-e) | |
5001 | Invoke an editor on the current command line, and execute the result as shell | |
5002 | commands. | |
5003 | \fBBash\fP attempts to invoke | |
5004 | .SM | |
5005 | .BR $FCEDIT , | |
5006 | .SM | |
5007 | .BR $EDITOR , | |
5008 | and \fIemacs\fP as the editor, in that order. | |
726f6388 JA |
5009 | .PD |
5010 | .SS Commands for Changing Text | |
5011 | .PP | |
5012 | .PD 0 | |
5013 | .TP | |
5014 | .B delete\-char (C\-d) | |
28ef6c31 | 5015 | Delete the character at point. If point is at the |
726f6388 | 5016 | beginning of the line, there are no characters in the line, and |
cce855bc | 5017 | the last character typed was not bound to \fBdelete\-char\fP, |
726f6388 JA |
5018 | then return |
5019 | .SM | |
5020 | .BR EOF . | |
5021 | .TP | |
5022 | .B backward\-delete\-char (Rubout) | |
5023 | Delete the character behind the cursor. When given a numeric argument, | |
ccc6cda3 | 5024 | save the deleted text on the kill ring. |
726f6388 | 5025 | .TP |
b72432fd JA |
5026 | .B forward\-backward\-delete\-char |
5027 | Delete the character under the cursor, unless the cursor is at the | |
5028 | end of the line, in which case the character behind the cursor is | |
f73dda09 | 5029 | deleted. |
b72432fd | 5030 | .TP |
726f6388 | 5031 | .B quoted\-insert (C\-q, C\-v) |
cce855bc | 5032 | Add the next character typed to the line verbatim. This is |
726f6388 JA |
5033 | how to insert characters like \fBC\-q\fP, for example. |
5034 | .TP | |
ccc6cda3 | 5035 | .B tab\-insert (C\-v TAB) |
726f6388 JA |
5036 | Insert a tab character. |
5037 | .TP | |
5038 | .B self\-insert (a,\ b,\ A,\ 1,\ !,\ ...) | |
5039 | Insert the character typed. | |
5040 | .TP | |
5041 | .B transpose\-chars (C\-t) | |
28ef6c31 JA |
5042 | Drag the character before point forward over the character at point, |
5043 | moving point forward as well. | |
5044 | If point is at the end of the line, then this transposes | |
5045 | the two characters before point. | |
bb70624e | 5046 | Negative arguments have no effect. |
726f6388 JA |
5047 | .TP |
5048 | .B transpose\-words (M\-t) | |
bb70624e | 5049 | Drag the word before point past the word after point, |
28ef6c31 | 5050 | moving point over that word as well. |
f73dda09 JA |
5051 | If point is at the end of the line, this transposes |
5052 | the last two words on the line. | |
726f6388 JA |
5053 | .TP |
5054 | .B upcase\-word (M\-u) | |
5055 | Uppercase the current (or following) word. With a negative argument, | |
cce855bc | 5056 | uppercase the previous word, but do not move point. |
726f6388 JA |
5057 | .TP |
5058 | .B downcase\-word (M\-l) | |
5059 | Lowercase the current (or following) word. With a negative argument, | |
cce855bc | 5060 | lowercase the previous word, but do not move point. |
726f6388 JA |
5061 | .TP |
5062 | .B capitalize\-word (M\-c) | |
5063 | Capitalize the current (or following) word. With a negative argument, | |
cce855bc | 5064 | capitalize the previous word, but do not move point. |
7117c2d2 JA |
5065 | .TP |
5066 | .B overwrite\-mode | |
5067 | Toggle overwrite mode. With an explicit positive numeric argument, | |
5068 | switches to overwrite mode. With an explicit non-positive numeric | |
5069 | argument, switches to insert mode. This command affects only | |
5070 | \fBemacs\fP mode; \fBvi\fP mode does overwrite differently. | |
5071 | Each call to \fIreadline()\fP starts in insert mode. | |
5072 | In overwrite mode, characters bound to \fBself\-insert\fP replace | |
5073 | the text at point rather than pushing the text to the right. | |
5074 | Characters bound to \fBbackward\-delete\-char\fP replace the character | |
5075 | before point with a space. By default, this command is unbound. | |
726f6388 JA |
5076 | .PD |
5077 | .SS Killing and Yanking | |
5078 | .PP | |
5079 | .PD 0 | |
5080 | .TP | |
5081 | .B kill\-line (C\-k) | |
bb70624e | 5082 | Kill the text from point to the end of the line. |
726f6388 | 5083 | .TP |
ccc6cda3 | 5084 | .B backward\-kill\-line (C\-x Rubout) |
726f6388 JA |
5085 | Kill backward to the beginning of the line. |
5086 | .TP | |
5087 | .B unix\-line\-discard (C\-u) | |
5088 | Kill backward from point to the beginning of the line. | |
cce855bc | 5089 | The killed text is saved on the kill-ring. |
bb70624e | 5090 | .\" There is no real difference between this and backward-kill-line |
726f6388 JA |
5091 | .TP |
5092 | .B kill\-whole\-line | |
bb70624e | 5093 | Kill all characters on the current line, no matter where point is. |
726f6388 JA |
5094 | .TP |
5095 | .B kill\-word (M\-d) | |
bb70624e JA |
5096 | Kill from point to the end of the current word, or if between |
5097 | words, to the end of the next word. | |
5098 | Word boundaries are the same as those used by \fBforward\-word\fP. | |
726f6388 JA |
5099 | .TP |
5100 | .B backward\-kill\-word (M\-Rubout) | |
bb70624e JA |
5101 | Kill the word behind point. |
5102 | Word boundaries are the same as those used by \fBbackward\-word\fP. | |
726f6388 JA |
5103 | .TP |
5104 | .B unix\-word\-rubout (C\-w) | |
bb70624e | 5105 | Kill the word behind point, using white space as a word boundary. |
bb70624e | 5106 | The killed text is saved on the kill-ring. |
113d85a4 CR |
5107 | .TP |
5108 | .B unix\-filename\-rubout | |
5109 | Kill the word behind point, using white space and the slash character | |
5110 | as the word boundaries. | |
5111 | The killed text is saved on the kill-ring. | |
ccc6cda3 JA |
5112 | .TP |
5113 | .B delete\-horizontal\-space (M\-\e) | |
5114 | Delete all spaces and tabs around point. | |
5115 | .TP | |
5116 | .B kill\-region | |
bb70624e | 5117 | Kill the text in the current region. |
ccc6cda3 JA |
5118 | .TP |
5119 | .B copy\-region\-as\-kill | |
5120 | Copy the text in the region to the kill buffer. | |
726f6388 | 5121 | .TP |
ccc6cda3 JA |
5122 | .B copy\-backward\-word |
5123 | Copy the word before point to the kill buffer. | |
cce855bc | 5124 | The word boundaries are the same as \fBbackward\-word\fP. |
ccc6cda3 JA |
5125 | .TP |
5126 | .B copy\-forward\-word | |
5127 | Copy the word following point to the kill buffer. | |
cce855bc | 5128 | The word boundaries are the same as \fBforward\-word\fP. |
726f6388 JA |
5129 | .TP |
5130 | .B yank (C\-y) | |
28ef6c31 | 5131 | Yank the top of the kill ring into the buffer at point. |
726f6388 JA |
5132 | .TP |
5133 | .B yank\-pop (M\-y) | |
ccc6cda3 | 5134 | Rotate the kill ring, and yank the new top. Only works following |
726f6388 JA |
5135 | .B yank |
5136 | or | |
5137 | .BR yank\-pop . | |
5138 | .PD | |
5139 | .SS Numeric Arguments | |
5140 | .PP | |
5141 | .PD 0 | |
5142 | .TP | |
5143 | .B digit\-argument (M\-0, M\-1, ..., M\-\-) | |
5144 | Add this digit to the argument already accumulating, or start a new | |
5145 | argument. M\-\- starts a negative argument. | |
5146 | .TP | |
5147 | .B universal\-argument | |
d166f048 JA |
5148 | This is another way to specify an argument. |
5149 | If this command is followed by one or more digits, optionally with a | |
5150 | leading minus sign, those digits define the argument. | |
5151 | If the command is followed by digits, executing | |
5152 | .B universal\-argument | |
5153 | again ends the numeric argument, but is otherwise ignored. | |
5154 | As a special case, if this command is immediately followed by a | |
5155 | character that is neither a digit or minus sign, the argument count | |
5156 | for the next command is multiplied by four. | |
726f6388 | 5157 | The argument count is initially one, so executing this function the |
d166f048 JA |
5158 | first time makes the argument count four, a second time makes the |
5159 | argument count sixteen, and so on. | |
726f6388 JA |
5160 | .PD |
5161 | .SS Completing | |
5162 | .PP | |
5163 | .PD 0 | |
5164 | .TP | |
5165 | .B complete (TAB) | |
5166 | Attempt to perform completion on the text before point. | |
5167 | .B Bash | |
5168 | attempts completion treating the text as a variable (if the | |
5169 | text begins with \fB$\fP), username (if the text begins with | |
5170 | \fB~\fP), hostname (if the text begins with \fB@\fP), or | |
5171 | command (including aliases and functions) in turn. If none | |
5172 | of these produces a match, filename completion is attempted. | |
5173 | .TP | |
ccc6cda3 | 5174 | .B possible\-completions (M\-?) |
726f6388 JA |
5175 | List the possible completions of the text before point. |
5176 | .TP | |
ccc6cda3 | 5177 | .B insert\-completions (M\-*) |
726f6388 JA |
5178 | Insert all completions of the text before point |
5179 | that would have been generated by | |
ccc6cda3 | 5180 | \fBpossible\-completions\fP. |
726f6388 | 5181 | .TP |
cce855bc JA |
5182 | .B menu\-complete |
5183 | Similar to \fBcomplete\fP, but replaces the word to be completed | |
5184 | with a single match from the list of possible completions. | |
5185 | Repeated execution of \fBmenu\-complete\fP steps through the list | |
5186 | of possible completions, inserting each match in turn. | |
28ef6c31 | 5187 | At the end of the list of completions, the bell is rung |
f73dda09 | 5188 | (subject to the setting of \fBbell\-style\fP) |
28ef6c31 | 5189 | and the original text is restored. |
cce855bc JA |
5190 | An argument of \fIn\fP moves \fIn\fP positions forward in the list |
5191 | of matches; a negative argument may be used to move backward | |
5192 | through the list. | |
5193 | This command is intended to be bound to \fBTAB\fP, but is unbound | |
5194 | by default. | |
5195 | .TP | |
b72432fd JA |
5196 | .B delete\-char\-or\-list |
5197 | Deletes the character under the cursor if not at the beginning or | |
bb70624e | 5198 | end of the line (like \fBdelete\-char\fP). |
b72432fd | 5199 | If at the end of the line, behaves identically to |
bb70624e | 5200 | \fBpossible\-completions\fP. |
b72432fd JA |
5201 | This command is unbound by default. |
5202 | .TP | |
726f6388 JA |
5203 | .B complete\-filename (M\-/) |
5204 | Attempt filename completion on the text before point. | |
5205 | .TP | |
5206 | .B possible\-filename\-completions (C\-x /) | |
5207 | List the possible completions of the text before point, | |
5208 | treating it as a filename. | |
5209 | .TP | |
5210 | .B complete\-username (M\-~) | |
5211 | Attempt completion on the text before point, treating | |
5212 | it as a username. | |
5213 | .TP | |
5214 | .B possible\-username\-completions (C\-x ~) | |
5215 | List the possible completions of the text before point, | |
5216 | treating it as a username. | |
5217 | .TP | |
5218 | .B complete\-variable (M\-$) | |
5219 | Attempt completion on the text before point, treating | |
5220 | it as a shell variable. | |
5221 | .TP | |
5222 | .B possible\-variable\-completions (C\-x $) | |
5223 | List the possible completions of the text before point, | |
5224 | treating it as a shell variable. | |
5225 | .TP | |
5226 | .B complete\-hostname (M\-@) | |
5227 | Attempt completion on the text before point, treating | |
5228 | it as a hostname. | |
5229 | .TP | |
5230 | .B possible\-hostname\-completions (C\-x @) | |
5231 | List the possible completions of the text before point, | |
5232 | treating it as a hostname. | |
5233 | .TP | |
5234 | .B complete\-command (M\-!) | |
5235 | Attempt completion on the text before point, treating | |
5236 | it as a command name. Command completion attempts to | |
5237 | match the text against aliases, reserved words, shell | |
cce855bc | 5238 | functions, shell builtins, and finally executable filenames, |
726f6388 JA |
5239 | in that order. |
5240 | .TP | |
5241 | .B possible\-command\-completions (C\-x !) | |
5242 | List the possible completions of the text before point, | |
5243 | treating it as a command name. | |
5244 | .TP | |
ccc6cda3 | 5245 | .B dynamic\-complete\-history (M\-TAB) |
726f6388 JA |
5246 | Attempt completion on the text before point, comparing |
5247 | the text against lines from the history list for possible | |
5248 | completion matches. | |
5249 | .TP | |
5250 | .B complete\-into\-braces (M\-{) | |
bb70624e | 5251 | Perform filename completion and insert the list of possible completions |
726f6388 JA |
5252 | enclosed within braces so the list is available to the shell (see |
5253 | .B Brace Expansion | |
5254 | above). | |
5255 | .PD | |
5256 | .SS Keyboard Macros | |
5257 | .PP | |
5258 | .PD 0 | |
5259 | .TP | |
ccc6cda3 | 5260 | .B start\-kbd\-macro (C\-x (\^) |
726f6388 JA |
5261 | Begin saving the characters typed into the current keyboard macro. |
5262 | .TP | |
ccc6cda3 | 5263 | .B end\-kbd\-macro (C\-x )\^) |
726f6388 | 5264 | Stop saving the characters typed into the current keyboard macro |
ccc6cda3 | 5265 | and store the definition. |
726f6388 | 5266 | .TP |
ccc6cda3 | 5267 | .B call\-last\-kbd\-macro (C\-x e) |
726f6388 JA |
5268 | Re-execute the last keyboard macro defined, by making the characters |
5269 | in the macro appear as if typed at the keyboard. | |
5270 | .PD | |
5271 | .SS Miscellaneous | |
5272 | .PP | |
5273 | .PD 0 | |
5274 | .TP | |
5275 | .B re\-read\-init\-file (C\-x C\-r) | |
ccc6cda3 | 5276 | Read in the contents of the \fIinputrc\fP file, and incorporate |
726f6388 JA |
5277 | any bindings or variable assignments found there. |
5278 | .TP | |
5279 | .B abort (C\-g) | |
5280 | Abort the current editing command and | |
5281 | ring the terminal's bell (subject to the setting of | |
5282 | .BR bell\-style ). | |
5283 | .TP | |
ccc6cda3 JA |
5284 | .B do\-uppercase\-version (M\-a, M\-b, M\-\fIx\fP, ...) |
5285 | If the metafied character \fIx\fP is lowercase, run the command | |
5286 | that is bound to the corresponding uppercase character. | |
726f6388 JA |
5287 | .TP |
5288 | .B prefix\-meta (ESC) | |
5289 | Metafy the next character typed. | |
5290 | .SM | |
5291 | .B ESC | |
5292 | .B f | |
5293 | is equivalent to | |
5294 | .BR Meta\-f . | |
5295 | .TP | |
5296 | .B undo (C\-_, C\-x C\-u) | |
5297 | Incremental undo, separately remembered for each line. | |
5298 | .TP | |
5299 | .B revert\-line (M\-r) | |
cce855bc | 5300 | Undo all changes made to this line. This is like executing the |
726f6388 JA |
5301 | .B undo |
5302 | command enough times to return the line to its initial state. | |
5303 | .TP | |
b72432fd | 5304 | .B tilde\-expand (M\-&) |
726f6388 JA |
5305 | Perform tilde expansion on the current word. |
5306 | .TP | |
ccc6cda3 | 5307 | .B set\-mark (C\-@, M\-<space>) |
28ef6c31 | 5308 | Set the mark to the point. If a |
ccc6cda3 JA |
5309 | numeric argument is supplied, the mark is set to that position. |
5310 | .TP | |
5311 | .B exchange\-point\-and\-mark (C\-x C\-x) | |
5312 | Swap the point with the mark. The current cursor position is set to | |
5313 | the saved position, and the old cursor position is saved as the mark. | |
5314 | .TP | |
5315 | .B character\-search (C\-]) | |
5316 | A character is read and point is moved to the next occurrence of that | |
5317 | character. A negative count searches for previous occurrences. | |
5318 | .TP | |
5319 | .B character\-search\-backward (M\-C\-]) | |
5320 | A character is read and point is moved to the previous occurrence of that | |
5321 | character. A negative count searches for subsequent occurrences. | |
5322 | .TP | |
5323 | .B insert\-comment (M\-#) | |
7117c2d2 | 5324 | Without a numeric argument, the value of the readline |
ccc6cda3 | 5325 | .B comment\-begin |
7117c2d2 JA |
5326 | variable is inserted at the beginning of the current line. |
5327 | If a numeric argument is supplied, this command acts as a toggle: if | |
5328 | the characters at the beginning of the line do not match the value | |
5329 | of \fBcomment\-begin\fP, the value is inserted, otherwise | |
5330 | the characters in \fBcomment-begin\fP are deleted from the beginning of | |
5331 | the line. | |
5332 | In either case, the line is accepted as if a newline had been typed. | |
5333 | The default value of | |
bb70624e | 5334 | \fBcomment\-begin\fP causes this command to make the current line |
ccc6cda3 | 5335 | a shell comment. |
7117c2d2 JA |
5336 | If a numeric argument causes the comment character to be removed, the line |
5337 | will be executed by the shell. | |
5338 | .TP | |
5339 | .B glob\-complete\-word (M\-g) | |
5340 | The word before point is treated as a pattern for pathname expansion, | |
5341 | with an asterisk implicitly appended. This pattern is used to | |
5342 | generate a list of matching file names for possible completions. | |
ccc6cda3 JA |
5343 | .TP |
5344 | .B glob\-expand\-word (C\-x *) | |
5345 | The word before point is treated as a pattern for pathname expansion, | |
5346 | and the list of matching file names is inserted, replacing the word. | |
7117c2d2 JA |
5347 | If a numeric argument is supplied, an asterisk is appended before |
5348 | pathname expansion. | |
ccc6cda3 JA |
5349 | .TP |
5350 | .B glob\-list\-expansions (C\-x g) | |
5351 | The list of expansions that would have been generated by | |
5352 | .B glob\-expand\-word | |
5353 | is displayed, and the line is redrawn. | |
7117c2d2 JA |
5354 | If a numeric argument is supplied, an asterisk is appended before |
5355 | pathname expansion. | |
ccc6cda3 | 5356 | .TP |
726f6388 JA |
5357 | .B dump\-functions |
5358 | Print all of the functions and their key bindings to the | |
5359 | readline output stream. If a numeric argument is supplied, | |
5360 | the output is formatted in such a way that it can be made part | |
5361 | of an \fIinputrc\fP file. | |
5362 | .TP | |
ccc6cda3 JA |
5363 | .B dump\-variables |
5364 | Print all of the settable readline variables and their values to the | |
5365 | readline output stream. If a numeric argument is supplied, | |
5366 | the output is formatted in such a way that it can be made part | |
5367 | of an \fIinputrc\fP file. | |
5368 | .TP | |
5369 | .B dump\-macros | |
5370 | Print all of the readline key sequences bound to macros and the | |
22e63b05 | 5371 | strings they output. If a numeric argument is supplied, |
ccc6cda3 JA |
5372 | the output is formatted in such a way that it can be made part |
5373 | of an \fIinputrc\fP file. | |
5374 | .TP | |
726f6388 JA |
5375 | .B display\-shell\-version (C\-x C\-v) |
5376 | Display version information about the current instance of | |
5377 | .BR bash . | |
5378 | .PD | |
bb70624e JA |
5379 | .SS Programmable Completion |
5380 | .PP | |
5381 | When word completion is attempted for an argument to a command for | |
5382 | which a completion specification (a \fIcompspec\fP) has been defined | |
5383 | using the \fBcomplete\fP builtin (see | |
5384 | .SM | |
5385 | .B "SHELL BUILTIN COMMANDS" | |
5386 | below), the programmable completion facilities are invoked. | |
5387 | .PP | |
5388 | First, the command name is identified. | |
5389 | If a compspec has been defined for that command, the | |
5390 | compspec is used to generate the list of possible completions for the word. | |
5391 | If the command word is a full pathname, a compspec for the full | |
5392 | pathname is searched for first. | |
5393 | If no compspec is found for the full pathname, an attempt is made to | |
5394 | find a compspec for the portion following the final slash. | |
5395 | .PP | |
5396 | Once a compspec has been found, it is used to generate the list of | |
5397 | matching words. | |
5398 | If a compspec is not found, the default \fBbash\fP completion as | |
5399 | described above under \fBCompleting\fP is performed. | |
5400 | .PP | |
5401 | First, the actions specified by the compspec are used. | |
5402 | Only matches which are prefixed by the word being completed are | |
5403 | returned. | |
5404 | When the | |
5405 | .B \-f | |
5406 | or | |
5407 | .B \-d | |
5408 | option is used for filename or directory name completion, the shell | |
5409 | variable | |
5410 | .SM | |
5411 | .B FIGNORE | |
5412 | is used to filter the matches. | |
5413 | .PP | |
5414 | Any completions specified by a filename expansion pattern to the | |
5415 | \fB\-G\fP option are generated next. | |
5416 | The words generated by the pattern need not match the word | |
5417 | being completed. | |
5418 | The | |
5419 | .SM | |
5420 | .B GLOBIGNORE | |
5421 | shell variable is not used to filter the matches, but the | |
5422 | .SM | |
5423 | .B FIGNORE | |
5424 | variable is used. | |
5425 | .PP | |
5426 | Next, the string specified as the argument to the \fB\-W\fP option | |
5427 | is considered. | |
5428 | The string is first split using the characters in the | |
5429 | .SM | |
5430 | .B IFS | |
5431 | special variable as delimiters. | |
5432 | Shell quoting is honored. | |
5433 | Each word is then expanded using | |
5434 | brace expansion, tilde expansion, parameter and variable expansion, | |
6e70dbff | 5435 | command substitution, and arithmetic expansion, |
bb70624e JA |
5436 | as described above under |
5437 | .SM | |
5438 | .BR EXPANSION . | |
5439 | The results are split using the rules described above under | |
5440 | \fBWord Splitting\fP. | |
5441 | The results of the expansion are prefix-matched against the word being | |
5442 | completed, and the matching words become the possible completions. | |
5443 | .PP | |
5444 | After these matches have been generated, any shell function or command | |
5445 | specified with the \fB\-F\fP and \fB\-C\fP options is invoked. | |
5446 | When the command or function is invoked, the | |
5447 | .SM | |
5448 | .B COMP_LINE | |
5449 | and | |
5450 | .SM | |
5451 | .B COMP_POINT | |
5452 | variables are assigned values as described above under | |
5453 | \fBShell Variables\fP. | |
5454 | If a shell function is being invoked, the | |
5455 | .SM | |
5456 | .B COMP_WORDS | |
5457 | and | |
5458 | .SM | |
5459 | .B COMP_CWORD | |
5460 | variables are also set. | |
5461 | When the function or command is invoked, the first argument is the | |
5462 | name of the command whose arguments are being completed, the | |
5463 | second argument is the word being completed, and the third argument | |
5464 | is the word preceding the word being completed on the current command line. | |
5465 | No filtering of the generated completions against the word being completed | |
5466 | is performed; the function or command has complete freedom in generating | |
5467 | the matches. | |
5468 | .PP | |
5469 | Any function specified with \fB\-F\fP is invoked first. | |
5470 | The function may use any of the shell facilities, including the | |
5471 | \fBcompgen\fP builtin described below, to generate the matches. | |
5472 | It must put the possible completions in the | |
5473 | .SM | |
5474 | .B COMPREPLY | |
5475 | array variable. | |
5476 | .PP | |
5477 | Next, any command specified with the \fB\-C\fP option is invoked | |
5478 | in an environment equivalent to command substitution. | |
5479 | It should print a list of completions, one per line, to the | |
5480 | standard output. | |
5481 | Backslash may be used to escape a newline, if necessary. | |
5482 | .PP | |
5483 | After all of the possible completions are generated, any filter | |
5484 | specified with the \fB\-X\fP option is applied to the list. | |
5485 | The filter is a pattern as used for pathname expansion; a \fB&\fP | |
5486 | in the pattern is replaced with the text of the word being completed. | |
5487 | A literal \fB&\fP may be escaped with a backslash; the backslash | |
5488 | is removed before attempting a match. | |
5489 | Any completion that matches the pattern will be removed from the list. | |
5490 | A leading \fB!\fP negates the pattern; in this case any completion | |
5491 | not matching the pattern will be removed. | |
5492 | .PP | |
5493 | Finally, any prefix and suffix specified with the \fB\-P\fP and \fB\-S\fP | |
5494 | options are added to each member of the completion list, and the result is | |
5495 | returned to the readline completion code as the list of possible | |
5496 | completions. | |
5497 | .PP | |
28ef6c31 JA |
5498 | If the previously-applied actions do not generate any matches, and the |
5499 | \fB\-o dirnames\fP option was supplied to \fBcomplete\fP when the | |
5500 | compspec was defined, directory name completion is attempted. | |
5501 | .PP | |
d3a24ed2 CR |
5502 | If the \fB\-o plusdirs\fP option was supplied to \fBcomplete\fP when the |
5503 | compspec was defined, directory name completion is attempted and any | |
5504 | matches are added to the results of the other actions. | |
5505 | .PP | |
28ef6c31 JA |
5506 | By default, if a compspec is found, whatever it generates is returned |
5507 | to the completion code as the full set of possible completions. | |
bb70624e JA |
5508 | The default \fBbash\fP completions are not attempted, and the readline |
5509 | default of filename completion is disabled. | |
d3a24ed2 CR |
5510 | If the \fB\-o bashdefault\fP option was supplied to \fBcomplete\fP when |
5511 | the compspec was defined, the \fBbash\fP default completions are attempted | |
28ef6c31 | 5512 | if the compspec generates no matches. |
d3a24ed2 CR |
5513 | If the \fB\-o default\fP option was supplied to \fBcomplete\fP when the |
5514 | compspec was defined, readline's default completion will be performed | |
5515 | if the compspec (and, if attempted, the default \fBbash\fP completions) | |
5516 | generate no matches. | |
7117c2d2 JA |
5517 | .PP |
5518 | When a compspec indicates that directory name completion is desired, | |
5519 | the programmable completion functions force readline to append a slash | |
5520 | to completed names which are symbolic links to directories, subject to | |
5521 | the value of the \fBmark\-directories\fP readline variable, regardless | |
5522 | of the setting of the \fBmark-symlinked\-directories\fP readline variable. | |
726f6388 | 5523 | .SH HISTORY |
ccc6cda3 | 5524 | When the |
d166f048 | 5525 | .B \-o history |
ccc6cda3 JA |
5526 | option to the |
5527 | .B set | |
5528 | builtin is enabled, the shell provides access to the | |
5529 | \fIcommand history\fP, | |
bb70624e JA |
5530 | the list of commands previously typed. |
5531 | The value of the \fBHISTSIZE\fP variable is used as the | |
5532 | number of commands to save in a history list. | |
5533 | The text of the last | |
726f6388 JA |
5534 | .SM |
5535 | .B HISTSIZE | |
bb70624e | 5536 | commands (default 500) is saved. The shell |
726f6388 JA |
5537 | stores each command in the history list prior to parameter and |
5538 | variable expansion (see | |
5539 | .SM | |
5540 | .B EXPANSION | |
5541 | above) but after history expansion is performed, subject to the | |
5542 | values of the shell variables | |
ccc6cda3 JA |
5543 | .SM |
5544 | .B HISTIGNORE | |
726f6388 JA |
5545 | and |
5546 | .SM | |
5547 | .BR HISTCONTROL . | |
bb70624e | 5548 | .PP |
726f6388 JA |
5549 | On startup, the history is initialized from the file named by |
5550 | the variable | |
5551 | .SM | |
5552 | .B HISTFILE | |
5553 | (default \fI~/.bash_history\fP). | |
bb70624e | 5554 | The file named by the value of |
726f6388 JA |
5555 | .SM |
5556 | .B HISTFILE | |
5557 | is truncated, if necessary, to contain no more than | |
bb70624e | 5558 | the number of lines specified by the value of |
726f6388 | 5559 | .SM |
bb70624e | 5560 | .BR HISTFILESIZE . |
ccc6cda3 JA |
5561 | When an interactive shell exits, the last |
5562 | .SM | |
bb70624e | 5563 | .B $HISTSIZE |
ccc6cda3 JA |
5564 | lines are copied from the history list to |
5565 | .SM | |
bb70624e | 5566 | .BR $HISTFILE . |
ccc6cda3 JA |
5567 | If the |
5568 | .B histappend | |
5569 | shell option is enabled | |
5570 | (see the description of | |
5571 | .B shopt | |
5572 | under | |
5573 | .SM | |
5574 | .B "SHELL BUILTIN COMMANDS" | |
5575 | below), the lines are appended to the history file, | |
5576 | otherwise the history file is overwritten. | |
5577 | If | |
5578 | .SM | |
5579 | .B HISTFILE | |
5580 | is unset, or if the history file is unwritable, the history is | |
5581 | not saved. After saving the history, the history file is truncated | |
5582 | to contain no more than | |
5583 | .SM | |
5584 | .B HISTFILESIZE | |
5585 | lines. If | |
5586 | .SM | |
5587 | .B HISTFILESIZE | |
5588 | is not set, no truncation is performed. | |
5589 | .PP | |
726f6388 JA |
5590 | The builtin command |
5591 | .B fc | |
5592 | (see | |
5593 | .SM | |
5594 | .B SHELL BUILTIN COMMANDS | |
5595 | below) may be used to list or edit and re-execute a portion of | |
5596 | the history list. | |
5597 | The | |
5598 | .B history | |
bb70624e | 5599 | builtin may be used to display or modify the history list and |
ccc6cda3 | 5600 | manipulate the history file. |
bb70624e | 5601 | When using command-line editing, search commands |
726f6388 | 5602 | are available in each editing mode that provide access to the |
ccc6cda3 JA |
5603 | history list. |
5604 | .PP | |
5605 | The shell allows control over which commands are saved on the history | |
5606 | list. The | |
726f6388 | 5607 | .SM |
ccc6cda3 JA |
5608 | .B HISTCONTROL |
5609 | and | |
726f6388 | 5610 | .SM |
ccc6cda3 JA |
5611 | .B HISTIGNORE |
5612 | variables may be set to cause the shell to save only a subset of the | |
5613 | commands entered. | |
5614 | The | |
5615 | .B cmdhist | |
5616 | shell option, if enabled, causes the shell to attempt to save each | |
5617 | line of a multi-line command in the same history entry, adding | |
5618 | semicolons where necessary to preserve syntactic correctness. | |
5619 | The | |
5620 | .B lithist | |
5621 | shell option causes the shell to save the command with embedded newlines | |
5622 | instead of semicolons. See the description of the | |
5623 | .B shopt | |
5624 | builtin below under | |
5625 | .SM | |
5626 | .B "SHELL BUILTIN COMMANDS" | |
5627 | for information on setting and unsetting shell options. | |
726f6388 JA |
5628 | .SH "HISTORY EXPANSION" |
5629 | .PP | |
5630 | The shell supports a history expansion feature that | |
5631 | is similar to the history expansion in | |
5632 | .BR csh. | |
5633 | This section describes what syntax features are available. This | |
5634 | feature is enabled by default for interactive shells, and can be | |
5635 | disabled using the | |
5636 | .B \+H | |
5637 | option to the | |
5638 | .B set | |
5639 | builtin command (see | |
5640 | .SM | |
5641 | .B SHELL BUILTIN COMMANDS | |
ccc6cda3 JA |
5642 | below). Non-interactive shells do not perform history expansion |
5643 | by default. | |
5644 | .PP | |
5645 | History expansions introduce words from the history list into | |
5646 | the input stream, making it easy to repeat commands, insert the | |
5647 | arguments to a previous command into the current input line, or | |
5648 | fix errors in previous commands quickly. | |
726f6388 JA |
5649 | .PP |
5650 | History expansion is performed immediately after a complete line | |
5651 | is read, before the shell breaks it into words. | |
ccc6cda3 | 5652 | It takes place in two parts. |
cce855bc | 5653 | The first is to determine which line from the history list |
ccc6cda3 JA |
5654 | to use during substitution. |
5655 | The second is to select portions of that line for inclusion into | |
5656 | the current one. | |
cce855bc | 5657 | The line selected from the history is the \fIevent\fP, |
ccc6cda3 JA |
5658 | and the portions of that line that are acted upon are \fIwords\fP. |
5659 | Various \fImodifiers\fP are available to manipulate the selected words. | |
5660 | The line is broken into words in the same fashion as when reading input, | |
5661 | so that several \fImetacharacter\fP-separated words surrounded by | |
cce855bc | 5662 | quotes are considered one word. |
ccc6cda3 JA |
5663 | History expansions are introduced by the appearance of the |
5664 | history expansion character, which is \^\fB!\fP\^ by default. | |
5665 | Only backslash (\^\fB\e\fP\^) and single quotes can quote | |
5666 | the history expansion character. | |
5667 | .PP | |
d3a24ed2 CR |
5668 | Several characters inhibit history expansion if found immediately |
5669 | following the history expansion character, even if it is unquoted: | |
5670 | space, tab, newline, carriage return, and \fB=\fP. | |
5671 | If the \fBextglob\fP shell option is enabled, \fB(\fP will also | |
5672 | inhibit expansion. | |
5673 | .PP | |
ccc6cda3 JA |
5674 | Several shell options settable with the |
5675 | .B shopt | |
5676 | builtin may be used to tailor the behavior of history expansion. | |
5677 | If the | |
5678 | .B histverify | |
5679 | shell option is enabled (see the description of the | |
5680 | .B shopt | |
5681 | builtin), and | |
5682 | .B readline | |
5683 | is being used, history substitutions are not immediately passed to | |
5684 | the shell parser. | |
5685 | Instead, the expanded line is reloaded into the | |
5686 | .B readline | |
5687 | editing buffer for further modification. | |
5688 | If | |
5689 | .B readline | |
5690 | is being used, and the | |
5691 | .B histreedit | |
5692 | shell option is enabled, a failed history substitution will be reloaded | |
5693 | into the | |
5694 | .B readline | |
5695 | editing buffer for correction. | |
5696 | The | |
5697 | .B \-p | |
5698 | option to the | |
5699 | .B history | |
5700 | builtin command may be used to see what a history expansion will | |
5701 | do before using it. | |
5702 | The | |
5703 | .B \-s | |
5704 | option to the | |
5705 | .B history | |
5706 | builtin may be used to add commands to the end of the history list | |
5707 | without actually executing them, so that they are available for | |
5708 | subsequent recall. | |
726f6388 JA |
5709 | .PP |
5710 | The shell allows control of the various characters used by the | |
5711 | history expansion mechanism (see the description of | |
5712 | .B histchars | |
5713 | above under | |
5714 | .BR "Shell Variables" ). | |
5715 | .SS Event Designators | |
5716 | .PP | |
5717 | An event designator is a reference to a command line entry in the | |
5718 | history list. | |
5719 | .PP | |
5720 | .PD 0 | |
5721 | .TP | |
5722 | .B ! | |
5723 | Start a history substitution, except when followed by a | |
5724 | .BR blank , | |
d3a24ed2 CR |
5725 | newline, carriage return, = |
5726 | or ( (when the \fBextglob\fP shell option is enabled using | |
5727 | the \fBshopt\fP builtin). | |
726f6388 | 5728 | .TP |
726f6388 JA |
5729 | .B !\fIn\fR |
5730 | Refer to command line | |
5731 | .IR n . | |
5732 | .TP | |
5733 | .B !\-\fIn\fR | |
5734 | Refer to the current command line minus | |
5735 | .IR n . | |
5736 | .TP | |
ccc6cda3 JA |
5737 | .B !! |
5738 | Refer to the previous command. This is a synonym for `!\-1'. | |
5739 | .TP | |
726f6388 JA |
5740 | .B !\fIstring\fR |
5741 | Refer to the most recent command starting with | |
5742 | .IR string . | |
5743 | .TP | |
5744 | .B !?\fIstring\fR\fB[?]\fR | |
5745 | Refer to the most recent command containing | |
5746 | .IR string . | |
ccc6cda3 JA |
5747 | The trailing \fB?\fP may be omitted if |
5748 | .I string | |
5749 | is followed immediately by a newline. | |
726f6388 JA |
5750 | .TP |
5751 | .B \d\s+2^\s-2\u\fIstring1\fP\d\s+2^\s-2\u\fIstring2\fP\d\s+2^\s-2\u | |
5752 | Quick substitution. Repeat the last command, replacing | |
5753 | .I string1 | |
5754 | with | |
5755 | .IR string2 . | |
5756 | Equivalent to | |
5757 | ``!!:s/\fIstring1\fP/\fIstring2\fP/'' | |
5758 | (see \fBModifiers\fP below). | |
5759 | .TP | |
5760 | .B !# | |
5761 | The entire command line typed so far. | |
5762 | .PD | |
5763 | .SS Word Designators | |
5764 | .PP | |
ccc6cda3 | 5765 | Word designators are used to select desired words from the event. |
726f6388 JA |
5766 | A |
5767 | .B : | |
ccc6cda3 | 5768 | separates the event specification from the word designator. |
cce855bc | 5769 | It may be omitted if the word designator begins with a |
726f6388 JA |
5770 | .BR ^ , |
5771 | .BR $ , | |
5772 | .BR * , | |
ccc6cda3 | 5773 | .BR \- , |
726f6388 JA |
5774 | or |
5775 | .BR % . | |
5776 | Words are numbered from the beginning of the line, | |
ccc6cda3 JA |
5777 | with the first word being denoted by 0 (zero). |
5778 | Words are inserted into the current line separated by single spaces. | |
726f6388 JA |
5779 | .PP |
5780 | .PD 0 | |
5781 | .TP | |
5782 | .B 0 (zero) | |
5783 | The zeroth word. For the shell, this is the command | |
5784 | word. | |
5785 | .TP | |
5786 | .I n | |
5787 | The \fIn\fRth word. | |
5788 | .TP | |
5789 | .B ^ | |
5790 | The first argument. That is, word 1. | |
5791 | .TP | |
5792 | .B $ | |
5793 | The last argument. | |
5794 | .TP | |
5795 | .B % | |
5796 | The word matched by the most recent `?\fIstring\fR?' search. | |
5797 | .TP | |
5798 | .I x\fB\-\fPy | |
5799 | A range of words; `\-\fIy\fR' abbreviates `0\-\fIy\fR'. | |
5800 | .TP | |
5801 | .B * | |
5802 | All of the words but the zeroth. This is a synonym | |
5803 | for `\fI1\-$\fP'. It is not an error to use | |
5804 | .B * | |
5805 | if there is just one | |
5806 | word in the event; the empty string is returned in that case. | |
5807 | .TP | |
5808 | .B x* | |
5809 | Abbreviates \fIx\-$\fP. | |
5810 | .TP | |
5811 | .B x\- | |
5812 | Abbreviates \fIx\-$\fP like \fBx*\fP, but omits the last word. | |
5813 | .PD | |
ccc6cda3 JA |
5814 | .PP |
5815 | If a word designator is supplied without an event specification, the | |
5816 | previous command is used as the event. | |
726f6388 JA |
5817 | .SS Modifiers |
5818 | .PP | |
ccc6cda3 JA |
5819 | After the optional word designator, there may appear a sequence of |
5820 | one or more of the following modifiers, each preceded by a `:'. | |
726f6388 JA |
5821 | .PP |
5822 | .PD 0 | |
5823 | .PP | |
5824 | .TP | |
5825 | .B h | |
ccc6cda3 JA |
5826 | Remove a trailing file name component, leaving only the head. |
5827 | .TP | |
5828 | .B t | |
5829 | Remove all leading file name components, leaving the tail. | |
726f6388 JA |
5830 | .TP |
5831 | .B r | |
5832 | Remove a trailing suffix of the form \fI.xxx\fP, leaving the | |
5833 | basename. | |
5834 | .TP | |
5835 | .B e | |
5836 | Remove all but the trailing suffix. | |
5837 | .TP | |
726f6388 JA |
5838 | .B p |
5839 | Print the new command but do not execute it. | |
5840 | .TP | |
5841 | .B q | |
5842 | Quote the substituted words, escaping further substitutions. | |
5843 | .TP | |
cce855bc JA |
5844 | .B x |
5845 | Quote the substituted words as with | |
5846 | .BR q , | |
5847 | but break into words at | |
5848 | .B blanks | |
5849 | and newlines. | |
726f6388 | 5850 | .TP |
cce855bc JA |
5851 | .B s/\fIold\fP/\fInew\fP/ |
5852 | Substitute | |
5853 | .I new | |
5854 | for the first occurrence of | |
5855 | .I old | |
5856 | in the event line. Any delimiter can be used in place of /. The | |
5857 | final delimiter is optional if it is the last character of the | |
5858 | event line. The delimiter may be quoted in | |
5859 | .I old | |
5860 | and | |
5861 | .I new | |
5862 | with a single backslash. If & appears in | |
5863 | .IR new , | |
5864 | it is replaced by | |
5865 | .IR old . | |
5866 | A single backslash will quote the &. If | |
5867 | .I old | |
5868 | is null, it is set to the last | |
5869 | .I old | |
5870 | substituted, or, if no previous history substitutions took place, | |
5871 | the last | |
5872 | .I string | |
5873 | in a | |
5874 | .B !?\fIstring\fR\fB[?]\fR | |
5875 | search. | |
ccc6cda3 | 5876 | .TP |
cce855bc JA |
5877 | .B & |
5878 | Repeat the previous substitution. | |
5879 | .TP | |
5880 | .B g | |
5881 | Cause changes to be applied over the entire event line. This is | |
5882 | used in conjunction with `\fB:s\fP' (e.g., `\fB:gs/\fIold\fP/\fInew\fP/\fR') | |
5883 | or `\fB:&\fP'. If used with | |
5884 | `\fB:s\fP', any delimiter can be used | |
5885 | in place of /, and the final delimiter is optional | |
5886 | if it is the last character of the event line. | |
d3a24ed2 CR |
5887 | An \fBa\fP may be used as a synonym for \fBg\fP. |
5888 | .TP | |
5889 | .B G | |
5890 | Apply the following `\fBs\fP' modifier once to each word in the event line. | |
726f6388 | 5891 | .PD |
726f6388 JA |
5892 | .SH "SHELL BUILTIN COMMANDS" |
5893 | .\" start of bash_builtins | |
5894 | .zZ | |
ccc6cda3 JA |
5895 | .PP |
5896 | Unless otherwise noted, each builtin command documented in this | |
5897 | section as accepting options preceded by | |
5898 | .B \- | |
5899 | accepts | |
5900 | .B \-\- | |
5901 | to signify the end of the options. | |
3ffb039a CR |
5902 | For example, the \fB:\fP, \fBtrue\fP, \fBfalse\fP, and \fBtest\fP builtins |
5903 | do not accept options. | |
ccc6cda3 | 5904 | .sp .5 |
726f6388 JA |
5905 | .PD 0 |
5906 | .TP | |
5907 | \fB:\fP [\fIarguments\fP] | |
5908 | .PD | |
5909 | No effect; the command does nothing beyond expanding | |
5910 | .I arguments | |
5911 | and performing any specified | |
5912 | redirections. A zero exit code is returned. | |
5913 | .TP | |
726f6388 | 5914 | \fB .\| \fP \fIfilename\fP [\fIarguments\fP] |
7117c2d2 | 5915 | .PD 0 |
726f6388 JA |
5916 | .TP |
5917 | \fBsource\fP \fIfilename\fP [\fIarguments\fP] | |
5918 | .PD | |
5919 | Read and execute commands from | |
5920 | .I filename | |
5921 | in the current | |
5922 | shell environment and return the exit status of the last command | |
5923 | executed from | |
5924 | .IR filename . | |
5925 | If | |
5926 | .I filename | |
ccc6cda3 | 5927 | does not contain a slash, file names in |
726f6388 JA |
5928 | .SM |
5929 | .B PATH | |
5930 | are used to find the directory containing | |
5931 | .IR filename . | |
5932 | The file searched for in | |
5933 | .SM | |
5934 | .B PATH | |
28ef6c31 JA |
5935 | need not be executable. |
5936 | When \fBbash\fP is not in \fIposix mode\fP, the current directory is | |
726f6388 JA |
5937 | searched if no file is found in |
5938 | .SM | |
5939 | .BR PATH . | |
ccc6cda3 JA |
5940 | If the |
5941 | .B sourcepath | |
5942 | option to the | |
5943 | .B shopt | |
5944 | builtin command is turned off, the | |
5945 | .SM | |
5946 | .B PATH | |
5947 | is not searched. | |
726f6388 | 5948 | If any \fIarguments\fP are supplied, they become the positional |
ccc6cda3 | 5949 | parameters when \fIfilename\fP is executed. Otherwise the positional |
726f6388 JA |
5950 | parameters are unchanged. |
5951 | The return status is the status of the last command exited within | |
5952 | the script (0 if no commands are executed), and false if | |
5953 | .I filename | |
cce855bc | 5954 | is not found or cannot be read. |
726f6388 | 5955 | .TP |
ccc6cda3 JA |
5956 | \fBalias\fP [\fB\-p\fP] [\fIname\fP[=\fIvalue\fP] ...] |
5957 | \fBAlias\fP with no arguments or with the | |
5958 | .B \-p | |
5959 | option prints the list of aliases in the form | |
5960 | \fBalias\fP \fIname\fP=\fIvalue\fP on standard output. | |
5961 | When arguments are supplied, an alias is defined for | |
5962 | each \fIname\fP whose \fIvalue\fP is given. | |
5963 | A trailing space in \fIvalue\fP causes the next word to be | |
5964 | checked for alias substitution when the alias is expanded. | |
5965 | For each \fIname\fP in the argument list for which no \fIvalue\fP | |
5966 | is supplied, the name and value of the alias is printed. | |
5967 | \fBAlias\fP returns true unless a \fIname\fP is given for which | |
5968 | no alias has been defined. | |
726f6388 | 5969 | .TP |
de3341d1 CR |
5970 | \fBbg\fP [\fIjobspec\fP ...] |
5971 | Resume each suspended job \fIjobspec\fP in the background, as if it | |
cce855bc | 5972 | had been started with |
726f6388 JA |
5973 | .BR & . |
5974 | If \fIjobspec\fP is not present, the shell's notion of the | |
5975 | \fIcurrent job\fP is used. | |
5976 | .B bg | |
5977 | .I jobspec | |
5978 | returns 0 unless run when job control is disabled or, when run with | |
ff247e74 CR |
5979 | job control enabled, any specified \fIjobspec\fP was not found |
5980 | or was started without job control. | |
726f6388 | 5981 | .TP |
cce855bc | 5982 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] [\fB\-lpsvPSV\fP] |
7117c2d2 | 5983 | .PD 0 |
cce855bc JA |
5984 | .TP |
5985 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] [\fB\-q\fP \fIfunction\fP] [\fB\-u\fP \fIfunction\fP] [\fB\-r\fP \fIkeyseq\fP] | |
726f6388 | 5986 | .TP |
ccc6cda3 | 5987 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fB\-f\fP \fIfilename\fP |
726f6388 | 5988 | .TP |
bb70624e JA |
5989 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fB\-x\fP \fIkeyseq\fP:\fIshell\-command\fP |
5990 | .TP | |
ccc6cda3 | 5991 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fIkeyseq\fP:\fIfunction\-name\fP |
7117c2d2 JA |
5992 | .TP |
5993 | \fBbind\fP \fIreadline\-command\fP | |
726f6388 JA |
5994 | .PD |
5995 | Display current | |
5996 | .B readline | |
7117c2d2 | 5997 | key and function bindings, bind a key sequence to a |
726f6388 | 5998 | .B readline |
7117c2d2 JA |
5999 | function or macro, or set a |
6000 | .B readline | |
6001 | variable. | |
6002 | Each non-option argument is a command as it would appear in | |
726f6388 | 6003 | .IR .inputrc , |
7117c2d2 JA |
6004 | but each binding or command must be passed as a separate argument; |
6005 | e.g., '"\eC\-x\eC\-r": re\-read\-init\-file'. | |
6006 | Options, if supplied, have the following meanings: | |
726f6388 JA |
6007 | .RS |
6008 | .PD 0 | |
6009 | .TP | |
6010 | .B \-m \fIkeymap\fP | |
6011 | Use | |
6012 | .I keymap | |
6013 | as the keymap to be affected by the subsequent bindings. | |
6014 | Acceptable | |
6015 | .I keymap | |
6016 | names are | |
ccc6cda3 | 6017 | \fIemacs, emacs\-standard, emacs\-meta, emacs\-ctlx, vi, |
28ef6c31 | 6018 | vi\-move, vi\-command\fP, and |
ccc6cda3 JA |
6019 | .IR vi\-insert . |
6020 | \fIvi\fP is equivalent to \fIvi\-command\fP; \fIemacs\fP is | |
6021 | equivalent to \fIemacs\-standard\fP. | |
726f6388 JA |
6022 | .TP |
6023 | .B \-l | |
ccc6cda3 JA |
6024 | List the names of all \fBreadline\fP functions. |
6025 | .TP | |
6026 | .B \-p | |
6027 | Display \fBreadline\fP function names and bindings in such a way | |
6028 | that they can be re-read. | |
6029 | .TP | |
6030 | .B \-P | |
6031 | List current \fBreadline\fP function names and bindings. | |
726f6388 JA |
6032 | .TP |
6033 | .B \-v | |
ccc6cda3 JA |
6034 | Display \fBreadline\fP variable names and values in such a way that they |
6035 | can be re-read. | |
726f6388 | 6036 | .TP |
ccc6cda3 JA |
6037 | .B \-V |
6038 | List current \fBreadline\fP variable names and values. | |
6039 | .TP | |
6040 | .B \-s | |
6041 | Display \fBreadline\fP key sequences bound to macros and the strings | |
6042 | they output in such a way that they can be re-read. | |
6043 | .TP | |
6044 | .B \-S | |
6045 | Display \fBreadline\fP key sequences bound to macros and the strings | |
6046 | they output. | |
726f6388 JA |
6047 | .TP |
6048 | .B \-f \fIfilename\fP | |
ccc6cda3 | 6049 | Read key bindings from \fIfilename\fP. |
726f6388 JA |
6050 | .TP |
6051 | .B \-q \fIfunction\fP | |
ccc6cda3 JA |
6052 | Query about which keys invoke the named \fIfunction\fP. |
6053 | .TP | |
cce855bc JA |
6054 | .B \-u \fIfunction\fP |
6055 | Unbind all keys bound to the named \fIfunction\fP. | |
6056 | .TP | |
ccc6cda3 JA |
6057 | .B \-r \fIkeyseq\fP |
6058 | Remove any current binding for \fIkeyseq\fP. | |
bb70624e JA |
6059 | .TP |
6060 | .B \-x \fIkeyseq\fP:\fIshell\-command\fP | |
6061 | Cause \fIshell\-command\fP to be executed whenever \fIkeyseq\fP is | |
6062 | entered. | |
726f6388 JA |
6063 | .PD |
6064 | .PP | |
6065 | The return value is 0 unless an unrecognized option is given or an | |
6066 | error occurred. | |
6067 | .RE | |
6068 | .TP | |
6069 | \fBbreak\fP [\fIn\fP] | |
6070 | Exit from within a | |
6071 | .BR for , | |
6072 | .BR while , | |
ccc6cda3 | 6073 | .BR until , |
726f6388 | 6074 | or |
ccc6cda3 | 6075 | .B select |
726f6388 JA |
6076 | loop. If \fIn\fP is specified, break \fIn\fP levels. |
6077 | .I n | |
6078 | must be \(>= 1. If | |
6079 | .I n | |
6080 | is greater than the number of enclosing loops, all enclosing loops | |
6081 | are exited. The return value is 0 unless the shell is not executing | |
6082 | a loop when | |
6083 | .B break | |
6084 | is executed. | |
6085 | .TP | |
6086 | \fBbuiltin\fP \fIshell\-builtin\fP [\fIarguments\fP] | |
6087 | Execute the specified shell builtin, passing it | |
6088 | .IR arguments , | |
6089 | and return its exit status. | |
cce855bc | 6090 | This is useful when defining a |
726f6388 | 6091 | function whose name is the same as a shell builtin, |
cce855bc JA |
6092 | retaining the functionality of the builtin within the function. |
6093 | The \fBcd\fP builtin is commonly redefined this way. | |
6094 | The return status is false if | |
726f6388 JA |
6095 | .I shell\-builtin |
6096 | is not a shell builtin command. | |
6097 | .TP | |
7117c2d2 | 6098 | \fBcd\fP [\fB\-L|-P\fP] [\fIdir\fP] |
726f6388 JA |
6099 | Change the current directory to \fIdir\fP. The variable |
6100 | .SM | |
6101 | .B HOME | |
6102 | is the | |
6103 | default | |
6104 | .IR dir . | |
6105 | The variable | |
6106 | .SM | |
6107 | .B CDPATH | |
ccc6cda3 | 6108 | defines the search path for the directory containing |
726f6388 | 6109 | .IR dir . |
ccc6cda3 JA |
6110 | Alternative directory names in |
6111 | .SM | |
6112 | .B CDPATH | |
6113 | are separated by a colon (:). A null directory name in | |
726f6388 JA |
6114 | .SM |
6115 | .B CDPATH | |
ccc6cda3 | 6116 | is the same as the current directory, i.e., ``\fB.\fP''. If |
726f6388 JA |
6117 | .I dir |
6118 | begins with a slash (/), | |
6119 | then | |
6120 | .SM | |
6121 | .B CDPATH | |
ccc6cda3 JA |
6122 | is not used. The |
6123 | .B \-P | |
6124 | option says to use the physical directory structure instead of | |
6125 | following symbolic links (see also the | |
6126 | .B \-P | |
6127 | option to the | |
6128 | .B set | |
6129 | builtin command); the | |
6130 | .B \-L | |
6131 | option forces symbolic links to be followed. An argument of | |
726f6388 JA |
6132 | .B \- |
6133 | is equivalent to | |
6134 | .SM | |
6135 | .BR $OLDPWD . | |
d3a24ed2 CR |
6136 | If a non-empty directory name from \fBCDPATH\fP is used, or if |
6137 | \fB\-\fP is the first argument, and the directory change is | |
6138 | successful, the absolute pathname of the new working directory is | |
6139 | written to the standard output. | |
726f6388 JA |
6140 | The return value is true if the directory was successfully changed; |
6141 | false otherwise. | |
6142 | .TP | |
d3a24ed2 CR |
6143 | \fBcaller\fP [\fIexpr\fP] |
6144 | Returns the context of any active subroutine call (a shell function or | |
6145 | a script executed with the \fB.\fP or \fBsource\fP builtins. | |
6146 | Without \fIexpr\fP, \fBcaller\fP displays the line number and source | |
6147 | filename of the current subroutine call. | |
6148 | If a non-negative integer is supplied as \fIexpr\fP, \fBcaller\fP | |
6149 | displays the line number, subroutine name, and source file corresponding | |
6150 | to that position in the current execution call stack. This extra | |
6151 | information may be used, for example, to print a stack trace. The | |
6152 | current frame is frame 0. | |
6153 | The return value is 0 unless the shell is not executing a subroutine | |
6154 | call or \fIexpr\fP does not correspond to a valid position in the | |
6155 | call stack. | |
6156 | .TP | |
ccc6cda3 | 6157 | \fBcommand\fP [\fB\-pVv\fP] \fIcommand\fP [\fIarg\fP ...] |
726f6388 JA |
6158 | Run |
6159 | .I command | |
6160 | with | |
6161 | .I args | |
6162 | suppressing the normal shell function lookup. Only builtin | |
6163 | commands or commands found in the | |
6164 | .SM | |
6165 | .B PATH | |
6166 | are executed. If the | |
6167 | .B \-p | |
6168 | option is given, the search for | |
6169 | .I command | |
6170 | is performed using a default value for | |
6171 | .B PATH | |
6172 | that is guaranteed to find all of the standard utilities. | |
6173 | If either the | |
6174 | .B \-V | |
6175 | or | |
6176 | .B \-v | |
6177 | option is supplied, a description of | |
6178 | .I command | |
6179 | is printed. The | |
6180 | .B \-v | |
ccc6cda3 | 6181 | option causes a single word indicating the command or file name |
726f6388 JA |
6182 | used to invoke |
6183 | .I command | |
cce855bc | 6184 | to be displayed; the |
726f6388 JA |
6185 | .B \-V |
6186 | option produces a more verbose description. | |
726f6388 JA |
6187 | If the |
6188 | .B \-V | |
6189 | or | |
6190 | .B \-v | |
6191 | option is supplied, the exit status is 0 if | |
6192 | .I command | |
6193 | was found, and 1 if not. If neither option is supplied and | |
6194 | an error occurred or | |
6195 | .I command | |
6196 | cannot be found, the exit status is 127. Otherwise, the exit status of the | |
6197 | .B command | |
6198 | builtin is the exit status of | |
6199 | .IR command . | |
6200 | .TP | |
bb70624e JA |
6201 | \fBcompgen\fP [\fIoption\fP] [\fIword\fP] |
6202 | Generate possible completion matches for \fIword\fP according to | |
6203 | the \fIoption\fPs, which may be any option accepted by the | |
6204 | .B complete | |
6205 | builtin with the exception of \fB\-p\fP and \fB\-r\fP, and write | |
6206 | the matches to the standard output. | |
6207 | When using the \fB\-F\fP or \fB\-C\fP options, the various shell variables | |
6208 | set by the programmable completion facilities, while available, will not | |
6209 | have useful values. | |
6210 | .sp 1 | |
6211 | The matches will be generated in the same way as if the programmable | |
6212 | completion code had generated them directly from a completion specification | |
6213 | with the same flags. | |
6214 | If \fIword\fP is specified, only those completions matching \fIword\fP | |
6215 | will be displayed. | |
6216 | .sp 1 | |
6217 | The return value is true unless an invalid option is supplied, or no | |
6218 | matches were generated. | |
6219 | .TP | |
7117c2d2 | 6220 | \fBcomplete\fP [\fB\-abcdefgjksuv\fP] [\fB\-o\fP \fIcomp-option\fP] [\fB\-A\fP \fIaction\fP] [\fB\-G\fP \fIglobpat\fP] [\fB\-W\fP \fIwordlist\fP] [\fB\-P\fP \fIprefix\fP] [\fB\-S\fP \fIsuffix\fP] |
bb70624e JA |
6221 | .br |
6222 | [\fB\-X\fP \fIfilterpat\fP] [\fB\-F\fP \fIfunction\fP] [\fB\-C\fP \fIcommand\fP] \fIname\fP [\fIname ...\fP] | |
7117c2d2 | 6223 | .PD 0 |
bb70624e JA |
6224 | .TP |
6225 | \fBcomplete\fP \fB\-pr\fP [\fIname\fP ...] | |
6226 | .PD | |
6227 | Specify how arguments to each \fIname\fP should be completed. | |
6228 | If the \fB\-p\fP option is supplied, or if no options are supplied, | |
6229 | existing completion specifications are printed in a way that allows | |
6230 | them to be reused as input. | |
6231 | The \fB\-r\fP option removes a completion specification for | |
6232 | each \fIname\fP, or, if no \fIname\fPs are supplied, all | |
6233 | completion specifications. | |
6234 | .sp 1 | |
6235 | The process of applying these completion specifications when word completion | |
6236 | is attempted is described above under \fBProgrammable Completion\fP. | |
6237 | .sp 1 | |
6238 | Other options, if specified, have the following meanings. | |
6239 | The arguments to the \fB\-G\fP, \fB\-W\fP, and \fB\-X\fP options | |
6240 | (and, if necessary, the \fB\-P\fP and \fB\-S\fP options) | |
6241 | should be quoted to protect them from expansion before the | |
6242 | .B complete | |
6243 | builtin is invoked. | |
6244 | .RS | |
6245 | .PD 0 | |
6246 | .TP 8 | |
28ef6c31 JA |
6247 | \fB\-o\fP \fIcomp-option\fP |
6248 | The \fIcomp-option\fP controls several aspects of the compspec's behavior | |
6249 | beyond the simple generation of completions. | |
6250 | \fIcomp-option\fP may be one of: | |
6251 | .RS | |
6252 | .TP 8 | |
d3a24ed2 CR |
6253 | .B bashdefault |
6254 | Perform the rest of the default \fBbash\fP completions if the compspec | |
6255 | generates no matches. | |
6256 | .TP 8 | |
28ef6c31 | 6257 | .B default |
7117c2d2 JA |
6258 | Use readline's default filename completion if the compspec generates |
6259 | no matches. | |
28ef6c31 JA |
6260 | .TP 8 |
6261 | .B dirnames | |
6262 | Perform directory name completion if the compspec generates no matches. | |
6263 | .TP 8 | |
6264 | .B filenames | |
6265 | Tell readline that the compspec generates filenames, so it can perform any | |
6266 | filename\-specific processing (like adding a slash to directory names or | |
6267 | suppressing trailing spaces). Intended to be used with shell functions. | |
7117c2d2 JA |
6268 | .TP 8 |
6269 | .B nospace | |
6270 | Tell readline not to append a space (the default) to words completed at | |
6271 | the end of the line. | |
301e2142 CR |
6272 | .TP 8 |
6273 | .B plusdirs | |
6274 | After any matches defined by the compspec are generated, | |
6275 | directory name completion is attempted and any | |
6276 | matches are added to the results of the other actions. | |
28ef6c31 JA |
6277 | .RE |
6278 | .TP 8 | |
bb70624e JA |
6279 | \fB\-A\fP \fIaction\fP |
6280 | The \fIaction\fP may be one of the following to generate a list of possible | |
6281 | completions: | |
6282 | .RS | |
6283 | .TP 8 | |
6284 | .B alias | |
6285 | Alias names. May also be specified as \fB\-a\fP. | |
6286 | .TP 8 | |
6287 | .B arrayvar | |
6288 | Array variable names. | |
6289 | .TP 8 | |
6290 | .B binding | |
6291 | \fBReadline\fP key binding names. | |
6292 | .TP 8 | |
6293 | .B builtin | |
6294 | Names of shell builtin commands. May also be specified as \fB\-b\fP. | |
6295 | .TP 8 | |
6296 | .B command | |
6297 | Command names. May also be specified as \fB\-c\fP. | |
6298 | .TP 8 | |
6299 | .B directory | |
6300 | Directory names. May also be specified as \fB\-d\fP. | |
6301 | .TP 8 | |
6302 | .B disabled | |
6303 | Names of disabled shell builtins. | |
6304 | .TP 8 | |
6305 | .B enabled | |
6306 | Names of enabled shell builtins. | |
6307 | .TP 8 | |
6308 | .B export | |
6309 | Names of exported shell variables. May also be specified as \fB\-e\fP. | |
6310 | .TP 8 | |
6311 | .B file | |
6312 | File names. May also be specified as \fB\-f\fP. | |
6313 | .TP 8 | |
6314 | .B function | |
6315 | Names of shell functions. | |
6316 | .TP 8 | |
f73dda09 JA |
6317 | .B group |
6318 | Group names. May also be specified as \fB\-g\fP. | |
6319 | .TP 8 | |
bb70624e JA |
6320 | .B helptopic |
6321 | Help topics as accepted by the \fBhelp\fP builtin. | |
6322 | .TP 8 | |
6323 | .B hostname | |
6324 | Hostnames, as taken from the file specified by the | |
6325 | .SM | |
6326 | .B HOSTFILE | |
6327 | shell variable. | |
6328 | .TP 8 | |
6329 | .B job | |
6330 | Job names, if job control is active. May also be specified as \fB\-j\fP. | |
6331 | .TP 8 | |
6332 | .B keyword | |
6333 | Shell reserved words. May also be specified as \fB\-k\fP. | |
6334 | .TP 8 | |
6335 | .B running | |
6336 | Names of running jobs, if job control is active. | |
6337 | .TP 8 | |
7117c2d2 JA |
6338 | .B service |
6339 | Service names. May also be specified as \fB\-s\fP. | |
6340 | .TP 8 | |
bb70624e JA |
6341 | .B setopt |
6342 | Valid arguments for the \fB\-o\fP option to the \fBset\fP builtin. | |
6343 | .TP 8 | |
6344 | .B shopt | |
6345 | Shell option names as accepted by the \fBshopt\fP builtin. | |
6346 | .TP 8 | |
6347 | .B signal | |
6348 | Signal names. | |
6349 | .TP 8 | |
6350 | .B stopped | |
6351 | Names of stopped jobs, if job control is active. | |
6352 | .TP 8 | |
6353 | .B user | |
6354 | User names. May also be specified as \fB\-u\fP. | |
6355 | .TP 8 | |
6356 | .B variable | |
6357 | Names of all shell variables. May also be specified as \fB\-v\fP. | |
6358 | .RE | |
6359 | .TP 8 | |
6360 | \fB\-G\fP \fIglobpat\fP | |
6361 | The filename expansion pattern \fIglobpat\fP is expanded to generate | |
6362 | the possible completions. | |
6363 | .TP 8 | |
6364 | \fB\-W\fP \fIwordlist\fP | |
6365 | The \fIwordlist\fP is split using the characters in the | |
6366 | .SM | |
6367 | .B IFS | |
6368 | special variable as delimiters, and each resultant word is expanded. | |
6369 | The possible completions are the members of the resultant list which | |
6370 | match the word being completed. | |
6371 | .TP 8 | |
6372 | \fB\-C\fP \fIcommand\fP | |
6373 | \fIcommand\fP is executed in a subshell environment, and its output is | |
6374 | used as the possible completions. | |
6375 | .TP 8 | |
6376 | \fB\-F\fP \fIfunction\fP | |
6377 | The shell function \fIfunction\fP is executed in the current shell | |
6378 | environment. | |
6379 | When it finishes, the possible completions are retrieved from the value | |
6380 | of the | |
6381 | .SM | |
6382 | .B COMPREPLY | |
6383 | array variable. | |
6384 | .TP 8 | |
6385 | \fB\-X\fP \fIfilterpat\fP | |
6386 | \fIfilterpat\fP is a pattern as used for filename expansion. | |
6387 | It is applied to the list of possible completions generated by the | |
6388 | preceding options and arguments, and each completion matching | |
6389 | \fIfilterpat\fP is removed from the list. | |
6390 | A leading \fB!\fP in \fIfilterpat\fP negates the pattern; in this | |
6391 | case, any completion not matching \fIfilterpat\fP is removed. | |
6392 | .TP 8 | |
6393 | \fB\-P\fP \fIprefix\fP | |
6394 | \fIprefix\fP is added at the beginning of each possible completion | |
6395 | after all other options have been applied. | |
6396 | .TP 8 | |
6397 | \fB\-S\fP \fIsuffix\fP | |
6398 | \fIsuffix\fP is appended to each possible completion | |
6399 | after all other options have been applied. | |
6400 | .PD | |
6401 | .PP | |
6402 | The return value is true unless an invalid option is supplied, an option | |
6403 | other than \fB\-p\fP or \fB\-r\fP is supplied without a \fIname\fP | |
6404 | argument, an attempt is made to remove a completion specification for | |
6405 | a \fIname\fP for which no specification exists, or | |
6406 | an error occurs adding a completion specification. | |
6407 | .RE | |
6408 | .TP | |
726f6388 JA |
6409 | \fBcontinue\fP [\fIn\fP] |
6410 | Resume the next iteration of the enclosing | |
6411 | .BR for , | |
6412 | .BR while , | |
ccc6cda3 | 6413 | .BR until , |
726f6388 | 6414 | or |
ccc6cda3 | 6415 | .B select |
726f6388 JA |
6416 | loop. |
6417 | If | |
6418 | .I n | |
6419 | is specified, resume at the \fIn\fPth enclosing loop. | |
6420 | .I n | |
6421 | must be \(>= 1. If | |
6422 | .I n | |
6423 | is greater than the number of enclosing loops, the last enclosing loop | |
ccc6cda3 | 6424 | (the ``top-level'' loop) is resumed. The return value is 0 unless the |
726f6388 JA |
6425 | shell is not executing a loop when |
6426 | .B continue | |
6427 | is executed. | |
6428 | .TP | |
d3a24ed2 | 6429 | \fBdeclare\fP [\fB\-afFirtx\fP] [\fB\-p\fP] [\fIname\fP[=\fIvalue\fP] ...] |
726f6388 | 6430 | .PD 0 |
726f6388 | 6431 | .TP |
d3a24ed2 | 6432 | \fBtypeset\fP [\fB\-afFirtx\fP] [\fB\-p\fP] [\fIname\fP[=\fIvalue\fP] ...] |
726f6388 | 6433 | .PD |
ccc6cda3 JA |
6434 | Declare variables and/or give them attributes. |
6435 | If no \fIname\fPs are given then display the values of variables. | |
6436 | The | |
6437 | .B \-p | |
6438 | option will display the attributes and values of each | |
6439 | .IR name . | |
6440 | When | |
6441 | .B \-p | |
6442 | is used, additional options are ignored. | |
6443 | The | |
6444 | .B \-F | |
6445 | option inhibits the display of function definitions; only the | |
6446 | function name and attributes are printed. | |
d3a24ed2 CR |
6447 | If the \fBextdebug\fP shell option is enabled using \fBshopt\fP, |
6448 | the source file name and line number where the function is defined | |
6449 | are displayed as well. The | |
ccc6cda3 JA |
6450 | .B \-F |
6451 | option implies | |
6452 | .BR \-f . | |
6453 | The following options can | |
6454 | be used to restrict output to variables with the specified attribute or | |
6455 | to give variables attributes: | |
726f6388 JA |
6456 | .RS |
6457 | .PD 0 | |
6458 | .TP | |
ccc6cda3 JA |
6459 | .B \-a |
6460 | Each \fIname\fP is an array variable (see | |
6461 | .B Arrays | |
6462 | above). | |
6463 | .TP | |
726f6388 | 6464 | .B \-f |
ccc6cda3 JA |
6465 | Use function names only. |
6466 | .TP | |
6467 | .B \-i | |
6468 | The variable is treated as an integer; arithmetic evaluation (see | |
6469 | .SM | |
6470 | .B "ARITHMETIC EVALUATION" ") " | |
6471 | is performed when the variable is assigned a value. | |
726f6388 JA |
6472 | .TP |
6473 | .B \-r | |
6474 | Make \fIname\fPs readonly. These names cannot then be assigned values | |
cce855bc | 6475 | by subsequent assignment statements or unset. |
726f6388 | 6476 | .TP |
7117c2d2 JA |
6477 | .B \-t |
6478 | Give each \fIname\fP the \fItrace\fP attribute. | |
76a8d78d CR |
6479 | Traced functions inherit the \fBDEBUG\fP and \fBRETURN\fP traps from |
6480 | the calling shell. | |
7117c2d2 JA |
6481 | The trace attribute has no special meaning for variables. |
6482 | .TP | |
726f6388 JA |
6483 | .B \-x |
6484 | Mark \fIname\fPs for export to subsequent commands via the environment. | |
726f6388 JA |
6485 | .PD |
6486 | .PP | |
6487 | Using `+' instead of `\-' | |
ccc6cda3 JA |
6488 | turns off the attribute instead, with the exception that \fB+a\fP |
6489 | may not be used to destroy an array variable. When used in a function, | |
6490 | makes each | |
6491 | \fIname\fP local, as with the | |
726f6388 | 6492 | .B local |
d3a24ed2 CR |
6493 | command. |
6494 | If a variable name is followed by =\fIvalue\fP, the value of | |
6495 | the variable is set to \fIvalue\fP. | |
6496 | The return value is 0 unless an invalid option is encountered, | |
bb70624e JA |
6497 | an attempt is made to define a function using |
6498 | .if n ``\-f foo=bar'', | |
6499 | .if t \f(CW\-f foo=bar\fP, | |
ccc6cda3 JA |
6500 | an attempt is made to assign a value to a readonly variable, |
6501 | an attempt is made to assign a value to an array variable without | |
6502 | using the compound assignment syntax (see | |
6503 | .B Arrays | |
cce855bc | 6504 | above), one of the \fInames\fP is not a valid shell variable name, |
726f6388 | 6505 | an attempt is made to turn off readonly status for a readonly variable, |
ccc6cda3 | 6506 | an attempt is made to turn off array status for an array variable, |
bb70624e | 6507 | or an attempt is made to display a non-existent function with \fB\-f\fP. |
726f6388 JA |
6508 | .RE |
6509 | .TP | |
ccc6cda3 JA |
6510 | .B dirs [\fB\-clpv\fP] [+\fIn\fP] [\-\fIn\fP] |
6511 | Without options, displays the list of currently remembered directories. | |
6512 | The default display is on a single line with directory names separated | |
6513 | by spaces. | |
6514 | Directories are added to the list with the | |
726f6388 JA |
6515 | .B pushd |
6516 | command; the | |
6517 | .B popd | |
ccc6cda3 | 6518 | command removes entries from the list. |
726f6388 JA |
6519 | .RS |
6520 | .PD 0 | |
6521 | .TP | |
ccc6cda3 JA |
6522 | \fB+\fP\fIn\fP |
6523 | Displays the \fIn\fPth entry counting from the left of the list | |
726f6388 JA |
6524 | shown by |
6525 | .B dirs | |
6526 | when invoked without options, starting with zero. | |
6527 | .TP | |
ccc6cda3 JA |
6528 | \fB\-\fP\fIn\fP |
6529 | Displays the \fIn\fPth entry counting from the right of the list | |
726f6388 JA |
6530 | shown by |
6531 | .B dirs | |
6532 | when invoked without options, starting with zero. | |
6533 | .TP | |
ccc6cda3 JA |
6534 | .B \-c |
6535 | Clears the directory stack by deleting all of the entries. | |
6536 | .TP | |
726f6388 | 6537 | .B \-l |
ccc6cda3 | 6538 | Produces a longer listing; the default listing format uses a |
726f6388 | 6539 | tilde to denote the home directory. |
ccc6cda3 JA |
6540 | .TP |
6541 | .B \-p | |
6542 | Print the directory stack with one entry per line. | |
6543 | .TP | |
6544 | .B \-v | |
6545 | Print the directory stack with one entry per line, | |
6546 | prefixing each entry with its index in the stack. | |
726f6388 JA |
6547 | .PD |
6548 | .PP | |
6549 | The return value is 0 unless an | |
cce855bc | 6550 | invalid option is supplied or \fIn\fP indexes beyond the end |
726f6388 JA |
6551 | of the directory stack. |
6552 | .RE | |
6553 | .TP | |
cce855bc | 6554 | \fBdisown\fP [\fB\-ar\fP] [\fB\-h\fP] [\fIjobspec\fP ...] |
ccc6cda3 JA |
6555 | Without options, each |
6556 | .I jobspec | |
6557 | is removed from the table of active jobs. | |
cce855bc JA |
6558 | If the \fB\-h\fP option is given, each |
6559 | .I jobspec | |
6560 | is not removed from the table, but is marked so that | |
ccc6cda3 JA |
6561 | .SM |
6562 | .B SIGHUP | |
6563 | is not sent to the job if the shell receives a | |
6564 | .SM | |
6565 | .BR SIGHUP . | |
6566 | If no | |
6567 | .I jobspec | |
cce855bc JA |
6568 | is present, and neither the |
6569 | .B \-a | |
6570 | nor the | |
6571 | .B \-r | |
6572 | option is supplied, the \fIcurrent job\fP is used. | |
6573 | If no | |
6574 | .I jobspec | |
6575 | is supplied, the | |
6576 | .B \-a | |
6577 | option means to remove or mark all jobs; the | |
6578 | .B \-r | |
6579 | option without a | |
6580 | .I jobspec | |
6581 | argument restricts operation to running jobs. | |
6582 | The return value is 0 unless a | |
ccc6cda3 JA |
6583 | .I jobspec |
6584 | does not specify a valid job. | |
6585 | .TP | |
726f6388 | 6586 | \fBecho\fP [\fB\-neE\fP] [\fIarg\fP ...] |
ccc6cda3 JA |
6587 | Output the \fIarg\fPs, separated by spaces, followed by a newline. |
6588 | The return status is always 0. | |
6589 | If \fB\-n\fP is specified, the trailing newline is | |
726f6388 JA |
6590 | suppressed. If the \fB\-e\fP option is given, interpretation of |
6591 | the following backslash-escaped characters is enabled. The | |
6592 | .B \-E | |
6593 | option disables the interpretation of these escape characters, | |
6594 | even on systems where they are interpreted by default. | |
28ef6c31 | 6595 | The \fBxpg_echo\fP shell option may be used to |
bb70624e JA |
6596 | dynamically determine whether or not \fBecho\fP expands these |
6597 | escape characters by default. | |
ccc6cda3 | 6598 | .B echo |
3ffb039a | 6599 | does not interpret \fB\-\-\fP to mean the end of options. |
ccc6cda3 JA |
6600 | .B echo |
6601 | interprets the following escape sequences: | |
726f6388 JA |
6602 | .RS |
6603 | .PD 0 | |
6604 | .TP | |
6605 | .B \ea | |
6606 | alert (bell) | |
6607 | .TP | |
6608 | .B \eb | |
6609 | backspace | |
6610 | .TP | |
6611 | .B \ec | |
6612 | suppress trailing newline | |
6613 | .TP | |
ccc6cda3 JA |
6614 | .B \ee |
6615 | an escape character | |
6616 | .TP | |
726f6388 JA |
6617 | .B \ef |
6618 | form feed | |
6619 | .TP | |
6620 | .B \en | |
6621 | new line | |
6622 | .TP | |
6623 | .B \er | |
6624 | carriage return | |
6625 | .TP | |
6626 | .B \et | |
6627 | horizontal tab | |
6628 | .TP | |
6629 | .B \ev | |
6630 | vertical tab | |
6631 | .TP | |
6632 | .B \e\e | |
6633 | backslash | |
6634 | .TP | |
7117c2d2 JA |
6635 | .B \e0\fInnn\fP |
6636 | the eight-bit character whose value is the octal value \fInnn\fP | |
6637 | (zero to three octal digits) | |
6638 | .TP | |
cce855bc | 6639 | .B \e\fInnn\fP |
f73dda09 | 6640 | the eight-bit character whose value is the octal value \fInnn\fP |
7117c2d2 | 6641 | (one to three octal digits) |
cce855bc | 6642 | .TP |
f73dda09 JA |
6643 | .B \ex\fIHH\fP |
6644 | the eight-bit character whose value is the hexadecimal value \fIHH\fP | |
6645 | (one or two hex digits) | |
726f6388 JA |
6646 | .PD |
6647 | .RE | |
6648 | .TP | |
ccc6cda3 | 6649 | \fBenable\fP [\fB\-adnps\fP] [\fB\-f\fP \fIfilename\fP] [\fIname\fP ...] |
cce855bc JA |
6650 | Enable and disable builtin shell commands. |
6651 | Disabling a builtin allows a disk command which has the same name | |
bb70624e | 6652 | as a shell builtin to be executed without specifying a full pathname, |
cce855bc | 6653 | even though the shell normally searches for builtins before disk commands. |
726f6388 JA |
6654 | If \fB\-n\fP is used, each \fIname\fP |
6655 | is disabled; otherwise, | |
6656 | \fInames\fP are enabled. For example, to use the | |
6657 | .B test | |
6658 | binary found via the | |
6659 | .SM | |
6660 | .B PATH | |
ccc6cda3 | 6661 | instead of the shell builtin version, run |
28ef6c31 JA |
6662 | .if t \f(CWenable -n test\fP. |
6663 | .if n ``enable -n test''. | |
ccc6cda3 JA |
6664 | The |
6665 | .B \-f | |
6666 | option means to load the new builtin command | |
6667 | .I name | |
6668 | from shared object | |
6669 | .IR filename , | |
6670 | on systems that support dynamic loading. The | |
6671 | .B \-d | |
6672 | option will delete a builtin previously loaded with | |
6673 | .BR \-f . | |
6674 | If no \fIname\fP arguments are given, or if the | |
6675 | .B \-p | |
6676 | option is supplied, a list of shell builtins is printed. | |
6677 | With no other option arguments, the list consists of all enabled | |
6678 | shell builtins. | |
6679 | If \fB\-n\fP is supplied, only disabled builtins are printed. | |
6680 | If \fB\-a\fP is supplied, the list printed includes all builtins, with an | |
726f6388 | 6681 | indication of whether or not each is enabled. |
ccc6cda3 JA |
6682 | If \fB\-s\fP is supplied, the output is restricted to the POSIX |
6683 | \fIspecial\fP builtins. | |
726f6388 JA |
6684 | The return value is 0 unless a |
6685 | .I name | |
bb70624e | 6686 | is not a shell builtin or there is an error loading a new builtin |
ccc6cda3 | 6687 | from a shared object. |
726f6388 JA |
6688 | .TP |
6689 | \fBeval\fP [\fIarg\fP ...] | |
6690 | The \fIarg\fPs are read and concatenated together into a single | |
6691 | command. This command is then read and executed by the shell, and | |
ccc6cda3 JA |
6692 | its exit status is returned as the value of |
6693 | .BR eval . | |
6694 | If there are no | |
726f6388 JA |
6695 | .IR args , |
6696 | or only null arguments, | |
6697 | .B eval | |
ccc6cda3 | 6698 | returns 0. |
726f6388 | 6699 | .TP |
cce855bc | 6700 | \fBexec\fP [\fB\-cl\fP] [\fB\-a\fP \fIname\fP] [\fIcommand\fP [\fIarguments\fP]] |
726f6388 JA |
6701 | If |
6702 | .I command | |
6703 | is specified, it replaces the shell. | |
6704 | No new process is created. The | |
6705 | .I arguments | |
6706 | become the arguments to \fIcommand\fP. | |
ccc6cda3 JA |
6707 | If the |
6708 | .B \-l | |
6709 | option is supplied, | |
bb70624e | 6710 | the shell places a dash at the beginning of the zeroth arg passed to |
726f6388 | 6711 | .IR command . |
ccc6cda3 JA |
6712 | This is what |
6713 | .IR login (1) | |
6714 | does. The | |
6715 | .B \-c | |
6716 | option causes | |
6717 | .I command | |
6718 | to be executed with an empty environment. If | |
6719 | .B \-a | |
6720 | is supplied, the shell passes | |
6721 | .I name | |
6722 | as the zeroth argument to the executed command. If | |
6723 | .I command | |
726f6388 | 6724 | cannot be executed for some reason, a non-interactive shell exits, |
ccc6cda3 JA |
6725 | unless the shell option |
6726 | .B execfail | |
6727 | is enabled, in which case it returns failure. | |
6728 | An interactive shell returns failure if the file cannot be executed. | |
726f6388 JA |
6729 | If |
6730 | .I command | |
6731 | is not specified, any redirections take effect in the current shell, | |
cce855bc JA |
6732 | and the return status is 0. If there is a redirection error, the |
6733 | return status is 1. | |
726f6388 JA |
6734 | .TP |
6735 | \fBexit\fP [\fIn\fP] | |
6736 | Cause the shell to exit | |
6737 | with a status of \fIn\fP. If | |
6738 | .I n | |
6739 | is omitted, the exit status | |
6740 | is that of the last command executed. | |
6741 | A trap on | |
6742 | .SM | |
6743 | .B EXIT | |
6744 | is executed before the shell terminates. | |
6745 | .TP | |
ccc6cda3 | 6746 | \fBexport\fP [\fB\-fn\fP\^] [\fIname\fP[=\fIword\fP]] ... |
7117c2d2 | 6747 | .PD 0 |
726f6388 JA |
6748 | .TP |
6749 | .B export \-p | |
6750 | .PD | |
6751 | The supplied | |
6752 | .I names | |
6753 | are marked for automatic export to the environment of | |
6754 | subsequently executed commands. If the | |
6755 | .B \-f | |
6756 | option is given, | |
6757 | the | |
6758 | .I names | |
6759 | refer to functions. | |
6760 | If no | |
6761 | .I names | |
6762 | are given, or if the | |
6763 | .B \-p | |
6764 | option is supplied, a list | |
6765 | of all names that are exported in this shell is printed. | |
6766 | The | |
6767 | .B \-n | |
5e13499c CR |
6768 | option causes the export property to be removed from each |
6769 | \fIname\fP. | |
d3a24ed2 CR |
6770 | If a variable name is followed by =\fIword\fP, the value of |
6771 | the variable is set to \fIword\fP. | |
726f6388 | 6772 | .B export |
cce855bc | 6773 | returns an exit status of 0 unless an invalid option is |
726f6388 | 6774 | encountered, |
cce855bc | 6775 | one of the \fInames\fP is not a valid shell variable name, or |
726f6388 JA |
6776 | .B \-f |
6777 | is supplied with a | |
6778 | .I name | |
6779 | that is not a function. | |
6780 | .TP | |
726f6388 | 6781 | \fBfc\fP [\fB\-e\fP \fIename\fP] [\fB\-nlr\fP] [\fIfirst\fP] [\fIlast\fP] |
7117c2d2 | 6782 | .PD 0 |
726f6388 JA |
6783 | .TP |
6784 | \fBfc\fP \fB\-s\fP [\fIpat\fP=\fIrep\fP] [\fIcmd\fP] | |
6785 | .PD | |
6786 | Fix Command. In the first form, a range of commands from | |
6787 | .I first | |
6788 | to | |
6789 | .I last | |
6790 | is selected from the history list. | |
6791 | .I First | |
6792 | and | |
6793 | .I last | |
6794 | may be specified as a string (to locate the last command beginning | |
6795 | with that string) or as a number (an index into the history list, | |
6796 | where a negative number is used as an offset from the current | |
6797 | command number). If | |
6798 | .I last | |
6799 | is not specified it is set to | |
6800 | the current command for listing (so that | |
bb70624e JA |
6801 | .if n ``fc \-l \-10'' |
6802 | .if t \f(CWfc \-l \-10\fP | |
726f6388 JA |
6803 | prints the last 10 commands) and to |
6804 | .I first | |
6805 | otherwise. | |
6806 | If | |
6807 | .I first | |
6808 | is not specified it is set to the previous | |
6809 | command for editing and \-16 for listing. | |
6810 | .sp 1 | |
6811 | The | |
6812 | .B \-n | |
cce855bc | 6813 | option suppresses |
726f6388 JA |
6814 | the command numbers when listing. The |
6815 | .B \-r | |
cce855bc | 6816 | option reverses the order of |
726f6388 JA |
6817 | the commands. If the |
6818 | .B \-l | |
cce855bc | 6819 | option is given, |
726f6388 JA |
6820 | the commands are listed on |
6821 | standard output. Otherwise, the editor given by | |
6822 | .I ename | |
6823 | is invoked | |
6824 | on a file containing those commands. If | |
6825 | .I ename | |
6826 | is not given, the | |
6827 | value of the | |
6828 | .SM | |
6829 | .B FCEDIT | |
6830 | variable is used, and | |
6831 | the value of | |
6832 | .SM | |
6833 | .B EDITOR | |
6834 | if | |
6835 | .SM | |
6836 | .B FCEDIT | |
6837 | is not set. If neither variable is set, | |
6838 | .FN vi | |
6839 | is used. When editing is complete, the edited commands are | |
6840 | echoed and executed. | |
6841 | .sp 1 | |
6842 | In the second form, \fIcommand\fP is re-executed after each instance | |
6843 | of \fIpat\fP is replaced by \fIrep\fP. | |
ccc6cda3 | 6844 | A useful alias to use with this is |
d3a24ed2 | 6845 | .if n ``r="fc -s"'', |
ccc6cda3 JA |
6846 | .if t \f(CWr='fc \-s'\fP, |
6847 | so that typing | |
6848 | .if n ``r cc'' | |
6849 | .if t \f(CWr cc\fP | |
6850 | runs the last command beginning with | |
6851 | .if n ``cc'' | |
6852 | .if t \f(CWcc\fP | |
6853 | and typing | |
6854 | .if n ``r'' | |
6855 | .if t \f(CWr\fP | |
726f6388 JA |
6856 | re-executes the last command. |
6857 | .sp 1 | |
cce855bc | 6858 | If the first form is used, the return value is 0 unless an invalid |
726f6388 JA |
6859 | option is encountered or |
6860 | .I first | |
6861 | or | |
6862 | .I last | |
6863 | specify history lines out of range. | |
6864 | If the | |
6865 | .B \-e | |
6866 | option is supplied, the return value is the value of the last | |
6867 | command executed or failure if an error occurs with the temporary | |
6868 | file of commands. If the second form is used, the return status | |
6869 | is that of the command re-executed, unless | |
6870 | .I cmd | |
6871 | does not specify a valid history line, in which case | |
6872 | .B fc | |
6873 | returns failure. | |
6874 | .TP | |
6875 | \fBfg\fP [\fIjobspec\fP] | |
cce855bc | 6876 | Resume |
726f6388 | 6877 | .I jobspec |
cce855bc JA |
6878 | in the foreground, and make it the current job. |
6879 | If | |
726f6388 JA |
6880 | .I jobspec |
6881 | is not present, the shell's notion of the \fIcurrent job\fP is used. | |
6882 | The return value is that of the command placed into the foreground, | |
6883 | or failure if run when job control is disabled or, when run with | |
6884 | job control enabled, if | |
6885 | .I jobspec | |
6886 | does not specify a valid job or | |
6887 | .I jobspec | |
6888 | specifies a job that was started without job control. | |
6889 | .TP | |
6890 | \fBgetopts\fP \fIoptstring\fP \fIname\fP [\fIargs\fP] | |
6891 | .B getopts | |
6892 | is used by shell procedures to parse positional parameters. | |
6893 | .I optstring | |
bb70624e | 6894 | contains the option characters to be recognized; if a character |
726f6388 JA |
6895 | is followed by a colon, the option is expected to have an |
6896 | argument, which should be separated from it by white space. | |
bb70624e JA |
6897 | The colon and question mark characters may not be used as |
6898 | option characters. | |
726f6388 JA |
6899 | Each time it is invoked, |
6900 | .B getopts | |
6901 | places the next option in the shell variable | |
6902 | .IR name , | |
6903 | initializing | |
6904 | .I name | |
6905 | if it does not exist, | |
6906 | and the index of the next argument to be processed into the | |
6907 | variable | |
6908 | .SM | |
6909 | .BR OPTIND . | |
6910 | .SM | |
6911 | .B OPTIND | |
6912 | is initialized to 1 each time the shell or a shell script | |
6913 | is invoked. When an option requires an argument, | |
6914 | .B getopts | |
6915 | places that argument into the variable | |
6916 | .SM | |
6917 | .BR OPTARG . | |
6918 | The shell does not reset | |
6919 | .SM | |
6920 | .B OPTIND | |
6921 | automatically; it must be manually reset between multiple | |
6922 | calls to | |
6923 | .B getopts | |
6924 | within the same shell invocation if a new set of parameters | |
6925 | is to be used. | |
6926 | .sp 1 | |
cce855bc JA |
6927 | When the end of options is encountered, \fBgetopts\fP exits with a |
6928 | return value greater than zero. | |
6929 | \fBOPTIND\fP is set to the index of the first non-option argument, | |
6930 | and \fBname\fP is set to ?. | |
6931 | .sp 1 | |
6932 | .B getopts | |
6933 | normally parses the positional parameters, but if more arguments are | |
6934 | given in | |
6935 | .IR args , | |
6936 | .B getopts | |
6937 | parses those instead. | |
6938 | .sp 1 | |
726f6388 JA |
6939 | .B getopts |
6940 | can report errors in two ways. If the first character of | |
6941 | .I optstring | |
6942 | is a colon, | |
6943 | .I silent | |
6944 | error reporting is used. In normal operation diagnostic messages | |
cce855bc | 6945 | are printed when invalid options or missing option arguments are |
726f6388 JA |
6946 | encountered. |
6947 | If the variable | |
6948 | .SM | |
6949 | .B OPTERR | |
cce855bc | 6950 | is set to 0, no error messages will be displayed, even if the first |
726f6388 JA |
6951 | character of |
6952 | .I optstring | |
6953 | is not a colon. | |
6954 | .sp 1 | |
cce855bc | 6955 | If an invalid option is seen, |
726f6388 JA |
6956 | .B getopts |
6957 | places ? into | |
6958 | .I name | |
6959 | and, if not silent, | |
6960 | prints an error message and unsets | |
6961 | .SM | |
6962 | .BR OPTARG . | |
6963 | If | |
6964 | .B getopts | |
6965 | is silent, | |
6966 | the option character found is placed in | |
6967 | .SM | |
6968 | .B OPTARG | |
6969 | and no diagnostic message is printed. | |
6970 | .sp 1 | |
6971 | If a required argument is not found, and | |
6972 | .B getopts | |
6973 | is not silent, | |
6974 | a question mark (\^\fB?\fP\^) is placed in | |
6975 | .IR name , | |
f73dda09 | 6976 | .SM |
726f6388 JA |
6977 | .B OPTARG |
6978 | is unset, and a diagnostic message is printed. | |
6979 | If | |
6980 | .B getopts | |
6981 | is silent, then a colon (\^\fB:\fP\^) is placed in | |
6982 | .I name | |
6983 | and | |
6984 | .SM | |
6985 | .B OPTARG | |
6986 | is set to the option character found. | |
6987 | .sp 1 | |
6988 | .B getopts | |
726f6388 JA |
6989 | returns true if an option, specified or unspecified, is found. |
6990 | It returns false if the end of options is encountered or an | |
6991 | error occurs. | |
6992 | .TP | |
7117c2d2 | 6993 | \fBhash\fP [\fB\-lr\fP] [\fB\-p\fP \fIfilename\fP] [\fB\-dt\fP] [\fIname\fP] |
726f6388 JA |
6994 | For each |
6995 | .IR name , | |
ccc6cda3 JA |
6996 | the full file name of the command is determined by searching |
6997 | the directories in | |
6998 | .B $PATH | |
6999 | and remembered. | |
7000 | If the | |
7001 | .B \-p | |
7002 | option is supplied, no path search is performed, and | |
7003 | .I filename | |
7004 | is used as the full file name of the command. | |
7005 | The | |
726f6388 JA |
7006 | .B \-r |
7007 | option causes the shell to forget all | |
f73dda09 | 7008 | remembered locations. |
7117c2d2 JA |
7009 | The |
7010 | .B \-d | |
7011 | option causes the shell to forget the remembered location of each \fIname\fP. | |
f73dda09 JA |
7012 | If the |
7013 | .B \-t | |
7014 | option is supplied, the full pathname to which each \fIname\fP corresponds | |
7015 | is printed. If multiple \fIname\fP arguments are supplied with \fB\-t\fP, | |
7016 | the \fIname\fP is printed before the hashed full pathname. | |
7117c2d2 JA |
7017 | The |
7018 | .B \-l | |
7019 | option causes output to be displayed in a format that may be reused as input. | |
7020 | If no arguments are given, or if only \fB\-l\fP is supplied, | |
7021 | information about remembered commands is printed. | |
ccc6cda3 | 7022 | The return status is true unless a |
726f6388 | 7023 | .I name |
cce855bc | 7024 | is not found or an invalid option is supplied. |
726f6388 | 7025 | .TP |
bb70624e | 7026 | \fBhelp\fP [\fB\-s\fP] [\fIpattern\fP] |
726f6388 JA |
7027 | Display helpful information about builtin commands. If |
7028 | .I pattern | |
7029 | is specified, | |
7030 | .B help | |
7031 | gives detailed help on all commands matching | |
7032 | .IR pattern ; | |
ccc6cda3 | 7033 | otherwise help for all the builtins and shell control structures |
bb70624e JA |
7034 | is printed. |
7035 | The \fB\-s\fP option restricts the information displayed to a short | |
7036 | usage synopsis. | |
7037 | The return status is 0 unless no command matches | |
726f6388 JA |
7038 | .IR pattern . |
7039 | .TP | |
bb70624e | 7040 | \fBhistory [\fIn\fP] |
7117c2d2 | 7041 | .PD 0 |
bb70624e JA |
7042 | .TP |
7043 | \fBhistory\fP \fB\-c\fP | |
7044 | .TP | |
7045 | \fBhistory \-d\fP \fIoffset\fP | |
ccc6cda3 JA |
7046 | .TP |
7047 | \fBhistory\fP \fB\-anrw\fP [\fIfilename\fP] | |
726f6388 | 7048 | .TP |
ccc6cda3 JA |
7049 | \fBhistory\fP \fB\-p\fP \fIarg\fP [\fIarg ...\fP] |
7050 | .TP | |
7051 | \fBhistory\fP \fB\-s\fP \fIarg\fP [\fIarg ...\fP] | |
726f6388 JA |
7052 | .PD |
7053 | With no options, display the command | |
7054 | history list with line numbers. Lines listed | |
7055 | with a | |
7056 | .B * | |
7057 | have been modified. An argument of | |
7058 | .I n | |
7059 | lists only the last | |
7060 | .I n | |
d3a24ed2 CR |
7061 | lines. |
7062 | If the shell variable \fBHISTTIMEFORMAT\fP is set and not null, | |
7063 | it is used as a format string for \fIstrftime\fP(3) to display | |
7064 | the time stamp associated with each displayed history entry. | |
7065 | No intervening blank is printed between the formatted time stamp | |
7066 | and the history line. | |
7067 | If \fIfilename\fP is supplied, it is used as the | |
726f6388 JA |
7068 | name of the history file; if not, the value of |
7069 | .SM | |
7070 | .B HISTFILE | |
7071 | is used. Options, if supplied, have the following meanings: | |
7072 | .RS | |
7073 | .PD 0 | |
7074 | .TP | |
bb70624e JA |
7075 | .B \-c |
7076 | Clear the history list by deleting all the entries. | |
7077 | .TP | |
7078 | \fB\-d\fP \fIoffset\fP | |
7079 | Delete the history entry at position \fIoffset\fP. | |
7080 | .TP | |
726f6388 JA |
7081 | .B \-a |
7082 | Append the ``new'' history lines (history lines entered since the | |
ccc6cda3 | 7083 | beginning of the current \fBbash\fP session) to the history file. |
726f6388 JA |
7084 | .TP |
7085 | .B \-n | |
7086 | Read the history lines not already read from the history | |
7087 | file into the current history list. These are lines | |
7088 | appended to the history file since the beginning of the | |
7089 | current \fBbash\fP session. | |
7090 | .TP | |
7091 | .B \-r | |
7092 | Read the contents of the history file | |
ccc6cda3 | 7093 | and use them as the current history. |
726f6388 JA |
7094 | .TP |
7095 | .B \-w | |
7096 | Write the current history to the history file, overwriting the | |
7097 | history file's contents. | |
ccc6cda3 | 7098 | .TP |
ccc6cda3 JA |
7099 | .B \-p |
7100 | Perform history substitution on the following \fIargs\fP and display | |
7101 | the result on the standard output. | |
7102 | Does not store the results in the history list. | |
7103 | Each \fIarg\fP must be quoted to disable normal history expansion. | |
7104 | .TP | |
7105 | .B \-s | |
7106 | Store the | |
7107 | .I args | |
7108 | in the history list as a single entry. The last command in the | |
7109 | history list is removed before the | |
7110 | .I args | |
7111 | are added. | |
726f6388 JA |
7112 | .PD |
7113 | .PP | |
d3a24ed2 CR |
7114 | If the \fBHISTTIMEFORMAT\fP is set, the time stamp information |
7115 | associated with each history entry is written to the history file. | |
bb70624e JA |
7116 | The return value is 0 unless an invalid option is encountered, an |
7117 | error occurs while reading or writing the history file, an invalid | |
7118 | \fIoffset\fP is supplied as an argument to \fB\-d\fP, or the | |
7119 | history expansion supplied as an argument to \fB\-p\fP fails. | |
726f6388 JA |
7120 | .RE |
7121 | .TP | |
ccc6cda3 | 7122 | \fBjobs\fP [\fB\-lnprs\fP] [ \fIjobspec\fP ... ] |
7117c2d2 | 7123 | .PD 0 |
726f6388 JA |
7124 | .TP |
7125 | \fBjobs\fP \fB\-x\fP \fIcommand\fP [ \fIargs\fP ... ] | |
7126 | .PD | |
ccc6cda3 JA |
7127 | The first form lists the active jobs. The options have the following |
7128 | meanings: | |
7129 | .RS | |
7130 | .PD 0 | |
7131 | .TP | |
726f6388 | 7132 | .B \-l |
ccc6cda3 JA |
7133 | List process IDs |
7134 | in addition to the normal information. | |
7135 | .TP | |
726f6388 | 7136 | .B \-p |
ccc6cda3 JA |
7137 | List only the process ID of the job's process group |
7138 | leader. | |
7139 | .TP | |
726f6388 | 7140 | .B \-n |
ccc6cda3 JA |
7141 | Display information only about jobs that have changed status since |
7142 | the user was last notified of their status. | |
7143 | .TP | |
7144 | .B \-r | |
7145 | Restrict output to running jobs. | |
7146 | .TP | |
7147 | .B \-s | |
7148 | Restrict output to stopped jobs. | |
7149 | .PD | |
7150 | .PP | |
7151 | If | |
726f6388 JA |
7152 | .I jobspec |
7153 | is given, output is restricted to information about that job. | |
cce855bc JA |
7154 | The return status is 0 unless an invalid option is encountered |
7155 | or an invalid | |
726f6388 JA |
7156 | .I jobspec |
7157 | is supplied. | |
ccc6cda3 | 7158 | .PP |
726f6388 JA |
7159 | If the |
7160 | .B \-x | |
7161 | option is supplied, | |
7162 | .B jobs | |
7163 | replaces any | |
7164 | .I jobspec | |
7165 | found in | |
7166 | .I command | |
7167 | or | |
7168 | .I args | |
7169 | with the corresponding process group ID, and executes | |
7170 | .I command | |
7171 | passing it | |
7172 | .IR args , | |
7173 | returning its exit status. | |
ccc6cda3 | 7174 | .RE |
726f6388 | 7175 | .TP |
ccc6cda3 | 7176 | \fBkill\fP [\fB\-s\fP \fIsigspec\fP | \fB\-n\fP \fIsignum\fP | \fB\-\fP\fIsigspec\fP] [\fIpid\fP | \fIjobspec\fP] ... |
7117c2d2 | 7177 | .PD 0 |
726f6388 | 7178 | .TP |
cce855bc | 7179 | \fBkill\fP \fB\-l\fP [\fIsigspec\fP | \fIexit_status\fP] |
726f6388 JA |
7180 | .PD |
7181 | Send the signal named by | |
7182 | .I sigspec | |
ccc6cda3 JA |
7183 | or |
7184 | .I signum | |
726f6388 JA |
7185 | to the processes named by |
7186 | .I pid | |
7187 | or | |
7188 | .IR jobspec . | |
7189 | .I sigspec | |
61deeb13 | 7190 | is either a case-insensitive signal name such as |
726f6388 JA |
7191 | .SM |
7192 | .B SIGKILL | |
61deeb13 | 7193 | (with or without the |
726f6388 JA |
7194 | .SM |
7195 | .B SIG | |
61deeb13 CR |
7196 | prefix) or a signal number; |
7197 | .I signum | |
7198 | is a signal number. | |
726f6388 JA |
7199 | If |
7200 | .I sigspec | |
7201 | is not present, then | |
7202 | .SM | |
7203 | .B SIGTERM | |
cce855bc JA |
7204 | is assumed. |
7205 | An argument of | |
726f6388 | 7206 | .B \-l |
cce855bc JA |
7207 | lists the signal names. |
7208 | If any arguments are supplied when | |
726f6388 | 7209 | .B \-l |
cce855bc JA |
7210 | is given, the names of the signals corresponding to the arguments are |
7211 | listed, and the return status is 0. | |
7212 | The \fIexit_status\fP argument to | |
ccc6cda3 | 7213 | .B \-l |
cce855bc JA |
7214 | is a number specifying either a signal number or the exit status of |
7215 | a process terminated by a signal. | |
726f6388 JA |
7216 | .B kill |
7217 | returns true if at least one signal was successfully sent, or false | |
cce855bc | 7218 | if an error occurs or an invalid option is encountered. |
726f6388 JA |
7219 | .TP |
7220 | \fBlet\fP \fIarg\fP [\fIarg\fP ...] | |
7221 | Each | |
7222 | .I arg | |
7223 | is an arithmetic expression to be evaluated (see | |
7224 | .SM | |
7225 | .BR "ARITHMETIC EVALUATION" ). | |
7226 | If the last | |
7227 | .I arg | |
7228 | evaluates to 0, | |
7229 | .B let | |
7230 | returns 1; 0 is returned otherwise. | |
7231 | .TP | |
bb70624e | 7232 | \fBlocal\fP [\fIoption\fP] [\fIname\fP[=\fIvalue\fP] ...] |
cce855bc JA |
7233 | For each argument, a local variable named |
7234 | .I name | |
7235 | is created, and assigned | |
726f6388 | 7236 | .IR value . |
bb70624e | 7237 | The \fIoption\fP can be any of the options accepted by \fBdeclare\fP. |
726f6388 JA |
7238 | When |
7239 | .B local | |
7240 | is used within a function, it causes the variable | |
7241 | .I name | |
7242 | to have a visible scope restricted to that function and its children. | |
7243 | With no operands, | |
7244 | .B local | |
7245 | writes a list of local variables to the standard output. It is | |
7246 | an error to use | |
7247 | .B local | |
7248 | when not within a function. The return status is 0 unless | |
7249 | .B local | |
bb70624e | 7250 | is used outside a function, an invalid |
726f6388 | 7251 | .I name |
bb70624e JA |
7252 | is supplied, or |
7253 | \fIname\fP is a readonly variable. | |
726f6388 JA |
7254 | .TP |
7255 | .B logout | |
7256 | Exit a login shell. | |
7257 | .TP | |
ccc6cda3 | 7258 | \fBpopd\fP [\-\fBn\fP] [+\fIn\fP] [\-\fIn\fP] |
726f6388 JA |
7259 | Removes entries from the directory stack. With no arguments, |
7260 | removes the top directory from the stack, and performs a | |
7261 | .B cd | |
7262 | to the new top directory. | |
ccc6cda3 | 7263 | Arguments, if supplied, have the following meanings: |
726f6388 JA |
7264 | .RS |
7265 | .PD 0 | |
7266 | .TP | |
ccc6cda3 JA |
7267 | \fB+\fP\fIn\fP |
7268 | Removes the \fIn\fPth entry counting from the left of the list | |
726f6388 JA |
7269 | shown by |
7270 | .BR dirs , | |
bb70624e JA |
7271 | starting with zero. For example: |
7272 | .if n ``popd +0'' | |
7273 | .if t \f(CWpopd +0\fP | |
7274 | removes the first directory, | |
7275 | .if n ``popd +1'' | |
7276 | .if t \f(CWpopd +1\fP | |
7277 | the second. | |
726f6388 | 7278 | .TP |
ccc6cda3 JA |
7279 | \fB\-\fP\fIn\fP |
7280 | Removes the \fIn\fPth entry counting from the right of the list | |
726f6388 JA |
7281 | shown by |
7282 | .BR dirs , | |
bb70624e JA |
7283 | starting with zero. For example: |
7284 | .if n ``popd -0'' | |
7285 | .if t \f(CWpopd -0\fP | |
7286 | removes the last directory, | |
7287 | .if n ``popd -1'' | |
7288 | .if t \f(CWpopd -1\fP | |
7289 | the next to last. | |
ccc6cda3 JA |
7290 | .TP |
7291 | .B \-n | |
7292 | Suppresses the normal change of directory when removing directories | |
7293 | from the stack, so that only the stack is manipulated. | |
726f6388 JA |
7294 | .PD |
7295 | .PP | |
7296 | If the | |
7297 | .B popd | |
7298 | command is successful, a | |
7299 | .B dirs | |
7300 | is performed as well, and the return status is 0. | |
7301 | .B popd | |
cce855bc | 7302 | returns false if an invalid option is encountered, the directory stack |
726f6388 JA |
7303 | is empty, a non-existent directory stack entry is specified, or the |
7304 | directory change fails. | |
7305 | .RE | |
7306 | .TP | |
3ee6b87d | 7307 | \fBprintf\fP [\fB\-v\fP \fIvar\fP] \fIformat\fP [\fIarguments\fP] |
cce855bc JA |
7308 | Write the formatted \fIarguments\fP to the standard output under the |
7309 | control of the \fIformat\fP. | |
7310 | The \fIformat\fP is a character string which contains three types of objects: | |
7311 | plain characters, which are simply copied to standard output, character | |
7312 | escape sequences, which are converted and copied to the standard output, and | |
7313 | format specifications, each of which causes printing of the next successive | |
7314 | \fIargument\fP. | |
f73dda09 | 7315 | In addition to the standard \fIprintf\fP(1) formats, \fB%b\fP causes |
cce855bc | 7316 | \fBprintf\fP to expand backslash escape sequences in the corresponding |
5e13499c | 7317 | \fIargument\fP (except that \fB\ec\fP terminates output, backslashes in |
20587658 | 7318 | \fB\e\(aq\fP, \fB\e"\fP, and \fB\e?\fP are not removed, and octal escapes |
5e13499c CR |
7319 | beginning with \fB\e0\fP may contain up to four digits), |
7320 | and \fB%q\fP causes \fBprintf\fP to output the corresponding | |
cce855bc JA |
7321 | \fIargument\fP in a format that can be reused as shell input. |
7322 | .sp 1 | |
3ee6b87d CR |
7323 | The \fB\-v\fP option causes the output to be assigned to the variable |
7324 | \fIvar\fP rather than being printed to the standard output. | |
7325 | .sp 1 | |
cce855bc JA |
7326 | The \fIformat\fP is reused as necessary to consume all of the \fIarguments\fP. |
7327 | If the \fIformat\fP requires more \fIarguments\fP than are supplied, the | |
7328 | extra format specifications behave as if a zero value or null string, as | |
bb70624e JA |
7329 | appropriate, had been supplied. The return value is zero on success, |
7330 | non-zero on failure. | |
cce855bc | 7331 | .TP |
ccc6cda3 | 7332 | \fBpushd\fP [\fB\-n\fP] [\fIdir\fP] |
7117c2d2 | 7333 | .PD 0 |
726f6388 | 7334 | .TP |
ccc6cda3 | 7335 | \fBpushd\fP [\fB\-n\fP] [+\fIn\fP] [\-\fIn\fP] |
726f6388 JA |
7336 | .PD |
7337 | Adds a directory to the top of the directory stack, or rotates | |
7338 | the stack, making the new top of the stack the current working | |
7339 | directory. With no arguments, exchanges the top two directories | |
7340 | and returns 0, unless the directory stack is empty. | |
ccc6cda3 | 7341 | Arguments, if supplied, have the following meanings: |
726f6388 JA |
7342 | .RS |
7343 | .PD 0 | |
7344 | .TP | |
ccc6cda3 | 7345 | \fB+\fP\fIn\fP |
726f6388 JA |
7346 | Rotates the stack so that the \fIn\fPth directory |
7347 | (counting from the left of the list shown by | |
d166f048 JA |
7348 | .BR dirs , |
7349 | starting with zero) | |
726f6388 JA |
7350 | is at the top. |
7351 | .TP | |
ccc6cda3 | 7352 | \fB\-\fP\fIn\fP |
726f6388 | 7353 | Rotates the stack so that the \fIn\fPth directory |
d166f048 JA |
7354 | (counting from the right of the list shown by |
7355 | .BR dirs , | |
7356 | starting with zero) is at the top. | |
726f6388 | 7357 | .TP |
ccc6cda3 JA |
7358 | .B \-n |
7359 | Suppresses the normal change of directory when adding directories | |
7360 | to the stack, so that only the stack is manipulated. | |
7361 | .TP | |
bb70624e | 7362 | .I dir |
ccc6cda3 | 7363 | Adds |
726f6388 JA |
7364 | .I dir |
7365 | to the directory stack at the top, making it the | |
7366 | new current working directory. | |
7367 | .PD | |
7368 | .PP | |
7369 | If the | |
7370 | .B pushd | |
7371 | command is successful, a | |
7372 | .B dirs | |
7373 | is performed as well. | |
7374 | If the first form is used, | |
7375 | .B pushd | |
7376 | returns 0 unless the cd to | |
7377 | .I dir | |
7378 | fails. With the second form, | |
7379 | .B pushd | |
7380 | returns 0 unless the directory stack is empty, | |
ccc6cda3 | 7381 | a non-existent directory stack element is specified, |
726f6388 JA |
7382 | or the directory change to the specified new current directory |
7383 | fails. | |
7384 | .RE | |
7385 | .TP | |
ccc6cda3 | 7386 | \fBpwd\fP [\fB\-LP\fP] |
bb70624e JA |
7387 | Print the absolute pathname of the current working directory. |
7388 | The pathname printed contains no symbolic links if the | |
726f6388 | 7389 | .B \-P |
ccc6cda3 JA |
7390 | option is supplied or the |
7391 | .B \-o physical | |
726f6388 JA |
7392 | option to the |
7393 | .B set | |
ccc6cda3 JA |
7394 | builtin command is enabled. |
7395 | If the | |
7396 | .B \-L | |
bb70624e | 7397 | option is used, the pathname printed may contain symbolic links. |
ccc6cda3 | 7398 | The return status is 0 unless an error occurs while |
cce855bc JA |
7399 | reading the name of the current directory or an |
7400 | invalid option is supplied. | |
726f6388 | 7401 | .TP |
7117c2d2 JA |
7402 | \fBread\fP [\fB\-ers\fP] [\fB\-u\fP \fIfd\fP] [\fB\-t\fP \fItimeout\fP] [\fB\-a\fP \fIaname\fP] [\fB\-p\fP \fIprompt\fP] [\fB\-n\fP \fInchars\fP] [\fB\-d\fP \fIdelim\fP] [\fIname\fP ...] |
7403 | One line is read from the standard input, or from the file descriptor | |
7404 | \fIfd\fP supplied as an argument to the \fB\-u\fP option, and the first word | |
726f6388 JA |
7405 | is assigned to the first |
7406 | .IR name , | |
7407 | the second word to the second | |
7408 | .IR name , | |
cce855bc JA |
7409 | and so on, with leftover words and their intervening separators assigned |
7410 | to the last | |
726f6388 | 7411 | .IR name . |
7117c2d2 | 7412 | If there are fewer words read from the input stream than names, |
cce855bc JA |
7413 | the remaining names are assigned empty values. |
7414 | The characters in | |
726f6388 JA |
7415 | .SM |
7416 | .B IFS | |
cce855bc | 7417 | are used to split the line into words. |
b72432fd JA |
7418 | The backslash character (\fB\e\fP) may be used to remove any special |
7419 | meaning for the next character read and for line continuation. | |
cce855bc | 7420 | Options, if supplied, have the following meanings: |
ccc6cda3 JA |
7421 | .RS |
7422 | .PD 0 | |
7423 | .TP | |
bb70624e | 7424 | .B \-a \fIaname\fP |
ccc6cda3 JA |
7425 | The words are assigned to sequential indices |
7426 | of the array variable | |
7427 | .IR aname , | |
7428 | starting at 0. | |
7429 | .I aname | |
7430 | is unset before any new values are assigned. | |
cce855bc | 7431 | Other \fIname\fP arguments are ignored. |
ccc6cda3 | 7432 | .TP |
bb70624e JA |
7433 | .B \-d \fIdelim\fP |
7434 | The first character of \fIdelim\fP is used to terminate the input line, | |
7435 | rather than newline. | |
7436 | .TP | |
ccc6cda3 JA |
7437 | .B \-e |
7438 | If the standard input | |
7439 | is coming from a terminal, | |
7440 | .B readline | |
7441 | (see | |
7442 | .SM | |
7443 | .B READLINE | |
7444 | above) is used to obtain the line. | |
bb70624e JA |
7445 | .TP |
7446 | .B \-n \fInchars\fP | |
7447 | \fBread\fP returns after reading \fInchars\fP characters rather than | |
7448 | waiting for a complete line of input. | |
7449 | .TP | |
7450 | .B \-p \fIprompt\fP | |
f73dda09 | 7451 | Display \fIprompt\fP on standard error, without a |
bb70624e JA |
7452 | trailing newline, before attempting to read any input. The prompt |
7453 | is displayed only if input is coming from a terminal. | |
7454 | .TP | |
7455 | .B \-r | |
7456 | Backslash does not act as an escape character. | |
7457 | The backslash is considered to be part of the line. | |
7458 | In particular, a backslash-newline pair may not be used as a line | |
7459 | continuation. | |
7460 | .TP | |
7461 | .B \-s | |
7462 | Silent mode. If input is coming from a terminal, characters are | |
7463 | not echoed. | |
7464 | .TP | |
7465 | .B \-t \fItimeout\fP | |
7466 | Cause \fBread\fP to time out and return failure if a complete line of | |
7467 | input is not read within \fItimeout\fP seconds. | |
7468 | This option has no effect if \fBread\fP is not reading input from the | |
7469 | terminal or a pipe. | |
7117c2d2 | 7470 | .TP |
0f445e6c | 7471 | .B \-u \fIfd\fP |
7117c2d2 | 7472 | Read input from file descriptor \fIfd\fP. |
ccc6cda3 JA |
7473 | .PD |
7474 | .PP | |
7475 | If no | |
726f6388 JA |
7476 | .I names |
7477 | are supplied, the line read is assigned to the variable | |
7478 | .SM | |
7479 | .BR REPLY . | |
7117c2d2 JA |
7480 | The return code is zero, unless end-of-file is encountered, \fBread\fP |
7481 | times out, or an invalid file descriptor is supplied as the argument to | |
7482 | \fB\-u\fP. | |
ccc6cda3 | 7483 | .RE |
726f6388 | 7484 | .TP |
d3a24ed2 | 7485 | \fBreadonly\fP [\fB\-apf\fP] [\fIname\fP[=\fIword\fP] ...] |
726f6388 JA |
7486 | .PD |
7487 | The given | |
ccc6cda3 JA |
7488 | \fInames\fP are marked readonly; the values of these |
7489 | .I names | |
726f6388 JA |
7490 | may not be changed by subsequent assignment. |
7491 | If the | |
7492 | .B \-f | |
7493 | option is supplied, the functions corresponding to the | |
7494 | \fInames\fP are so | |
ccc6cda3 JA |
7495 | marked. |
7496 | The | |
7497 | .B \-a | |
7498 | option restricts the variables to arrays. | |
7499 | If no | |
7500 | .I name | |
7501 | arguments are given, or if the | |
726f6388 | 7502 | .B \-p |
ccc6cda3 | 7503 | option is supplied, a list of all readonly names is printed. |
cce855bc JA |
7504 | The |
7505 | .B \-p | |
bb70624e JA |
7506 | option causes output to be displayed in a format that |
7507 | may be reused as input. | |
d3a24ed2 CR |
7508 | If a variable name is followed by =\fIword\fP, the value of |
7509 | the variable is set to \fIword\fP. | |
cce855bc | 7510 | The return status is 0 unless an invalid option is encountered, |
ccc6cda3 JA |
7511 | one of the |
7512 | .I names | |
cce855bc | 7513 | is not a valid shell variable name, or |
726f6388 JA |
7514 | .B \-f |
7515 | is supplied with a | |
7516 | .I name | |
7517 | that is not a function. | |
7518 | .TP | |
7519 | \fBreturn\fP [\fIn\fP] | |
7520 | Causes a function to exit with the return value specified by | |
7521 | .IR n . | |
7522 | If | |
7523 | .I n | |
7524 | is omitted, the return status is that of the last command | |
7525 | executed in the function body. If used outside a function, | |
7526 | but during execution of a script by the | |
7527 | .B . | |
7528 | (\fBsource\fP) command, it causes the shell to stop executing | |
7529 | that script and return either | |
7530 | .I n | |
7531 | or the exit status of the last command executed within the | |
7532 | script as the exit status of the script. If used outside a | |
7533 | function and not during execution of a script by \fB.\fP\^, | |
7534 | the return status is false. | |
d3a24ed2 CR |
7535 | Any command associated with the \fBRETURN\fP trap is executed |
7536 | before execution resumes after the function or script. | |
726f6388 | 7537 | .TP |
ccc6cda3 JA |
7538 | \fBset\fP [\fB\-\-abefhkmnptuvxBCHP\fP] [\fB\-o\fP \fIoption\fP] [\fIarg\fP ...] |
7539 | Without options, the name and value of each shell variable are displayed | |
54cdd75a CR |
7540 | in a format that can be reused as input |
7541 | for setting or resetting the currently-set variables. | |
7542 | Read-only variables cannot be reset. | |
7543 | In \fIposix mode\fP, only shell variables are listed. | |
cce855bc | 7544 | The output is sorted according to the current locale. |
ccc6cda3 JA |
7545 | When options are specified, they set or unset shell attributes. |
7546 | Any arguments remaining after the options are processed are treated | |
7547 | as values for the positional parameters and are assigned, in order, to | |
7548 | .BR $1 , | |
7549 | .BR $2 , | |
7550 | .B ... | |
7551 | .BR $\fIn\fP . | |
7552 | Options, if specified, have the following meanings: | |
726f6388 JA |
7553 | .RS |
7554 | .PD 0 | |
7555 | .TP 8 | |
7556 | .B \-a | |
5e13499c CR |
7557 | Automatically mark variables and functions which are modified or |
7558 | created for export to the environment of subsequent commands. | |
726f6388 JA |
7559 | .TP 8 |
7560 | .B \-b | |
ccc6cda3 JA |
7561 | Report the status of terminated background jobs |
7562 | immediately, rather than before the next primary prompt. This is | |
7563 | effective only when job control is enabled. | |
726f6388 JA |
7564 | .TP 8 |
7565 | .B \-e | |
ccc6cda3 | 7566 | Exit immediately if a \fIsimple command\fP (see |
726f6388 JA |
7567 | .SM |
7568 | .B SHELL GRAMMAR | |
d3a24ed2 CR |
7569 | above) exits with a non-zero status. |
7570 | The shell does not exit if the | |
7571 | command that fails is part of the command list immediately following a | |
7572 | .B while | |
726f6388 | 7573 | or |
d3a24ed2 CR |
7574 | .B until |
7575 | keyword, | |
7576 | part of the test in an | |
726f6388 JA |
7577 | .I if |
7578 | statement, part of a | |
7579 | .B && | |
7580 | or | |
ccc6cda3 | 7581 | .B \(bv\(bv |
726f6388 JA |
7582 | list, or if the command's return value is |
7583 | being inverted via | |
7584 | .BR ! . | |
f73dda09 | 7585 | A trap on \fBERR\fP, if set, is executed before the shell exits. |
726f6388 JA |
7586 | .TP 8 |
7587 | .B \-f | |
7588 | Disable pathname expansion. | |
7589 | .TP 8 | |
7590 | .B \-h | |
ccc6cda3 | 7591 | Remember the location of commands as they are looked up for execution. |
cce855bc | 7592 | This is enabled by default. |
726f6388 JA |
7593 | .TP 8 |
7594 | .B \-k | |
ccc6cda3 JA |
7595 | All arguments in the form of assignment statements |
7596 | are placed in the environment for a command, not just | |
7597 | those that precede the command name. | |
726f6388 JA |
7598 | .TP 8 |
7599 | .B \-m | |
cce855bc | 7600 | Monitor mode. Job control is enabled. This option is on |
726f6388 JA |
7601 | by default for interactive shells on systems that support |
7602 | it (see | |
7603 | .SM | |
7604 | .B JOB CONTROL | |
7605 | above). Background processes run in a separate process | |
7606 | group and a line containing their exit status is printed | |
7607 | upon their completion. | |
7608 | .TP 8 | |
7609 | .B \-n | |
7610 | Read commands but do not execute them. This may be used to | |
ccc6cda3 | 7611 | check a shell script for syntax errors. This is ignored by |
726f6388 JA |
7612 | interactive shells. |
7613 | .TP 8 | |
ccc6cda3 JA |
7614 | .B \-o \fIoption\-name\fP |
7615 | The \fIoption\-name\fP can be one of the following: | |
726f6388 JA |
7616 | .RS |
7617 | .TP 8 | |
7618 | .B allexport | |
7619 | Same as | |
7620 | .BR \-a . | |
7621 | .TP 8 | |
7622 | .B braceexpand | |
ccc6cda3 JA |
7623 | Same as |
7624 | .BR \-B . | |
726f6388 JA |
7625 | .TP 8 |
7626 | .B emacs | |
7627 | Use an emacs-style command line editing interface. This is enabled | |
7628 | by default when the shell is interactive, unless the shell is started | |
7629 | with the | |
ccc6cda3 | 7630 | .B \-\-noediting |
726f6388 JA |
7631 | option. |
7632 | .TP 8 | |
d3a24ed2 CR |
7633 | .B errtrace |
7634 | Same as | |
7635 | .BR \-E . | |
7636 | .TP 8 | |
7637 | .B functrace | |
7638 | Same as | |
7639 | .BR \-T . | |
7640 | .TP 8 | |
726f6388 JA |
7641 | .B errexit |
7642 | Same as | |
7643 | .BR \-e . | |
7644 | .TP 8 | |
ccc6cda3 JA |
7645 | .B hashall |
7646 | Same as | |
7647 | .BR \-h . | |
7648 | .TP 8 | |
726f6388 JA |
7649 | .B histexpand |
7650 | Same as | |
7651 | .BR \-H . | |
7652 | .TP 8 | |
ccc6cda3 JA |
7653 | .B history |
7654 | Enable command history, as described above under | |
7655 | .SM | |
7656 | .BR HISTORY . | |
7657 | This option is on by default in interactive shells. | |
7658 | .TP 8 | |
726f6388 | 7659 | .B ignoreeof |
28ef6c31 JA |
7660 | The effect is as if the shell command |
7661 | .if t \f(CWIGNOREEOF=10\fP | |
7662 | .if n ``IGNOREEOF=10'' | |
7663 | had been executed | |
726f6388 JA |
7664 | (see |
7665 | .B Shell Variables | |
7666 | above). | |
7667 | .TP 8 | |
ccc6cda3 JA |
7668 | .B keyword |
7669 | Same as | |
7670 | .BR \-k . | |
726f6388 JA |
7671 | .TP 8 |
7672 | .B monitor | |
7673 | Same as | |
7674 | .BR \-m . | |
7675 | .TP 8 | |
7676 | .B noclobber | |
7677 | Same as | |
7678 | .BR \-C . | |
7679 | .TP 8 | |
7680 | .B noexec | |
7681 | Same as | |
7682 | .BR \-n . | |
7683 | .TP 8 | |
7684 | .B noglob | |
7685 | Same as | |
7686 | .BR \-f . | |
f73dda09 JA |
7687 | .B nolog |
7688 | Currently ignored. | |
726f6388 | 7689 | .TP 8 |
726f6388 JA |
7690 | .B notify |
7691 | Same as | |
7692 | .BR \-b . | |
7693 | .TP 8 | |
7694 | .B nounset | |
7695 | Same as | |
7696 | .BR \-u . | |
7697 | .TP 8 | |
ccc6cda3 JA |
7698 | .B onecmd |
7699 | Same as | |
7700 | .BR \-t . | |
7701 | .TP 8 | |
726f6388 JA |
7702 | .B physical |
7703 | Same as | |
7704 | .BR \-P . | |
7705 | .TP 8 | |
d3a24ed2 CR |
7706 | .B pipefail |
7707 | If set, the return value of a pipeline is the value of the last | |
7708 | (rightmost) command to exit with a non-zero status, or zero if all | |
7709 | commands in the pipeline exit successfully. | |
7710 | This option is disabled by default. | |
7711 | .TP 8 | |
726f6388 | 7712 | .B posix |
ccc6cda3 JA |
7713 | Change the behavior of |
7714 | .B bash | |
7715 | where the default operation differs | |
54cdd75a | 7716 | from the POSIX 1003.2 standard to match the standard (\fIposix mode\fP). |
726f6388 JA |
7717 | .TP 8 |
7718 | .B privileged | |
7719 | Same as | |
7720 | .BR \-p . | |
7721 | .TP 8 | |
7722 | .B verbose | |
7723 | Same as | |
7724 | .BR \-v . | |
7725 | .TP 8 | |
7726 | .B vi | |
7727 | Use a vi-style command line editing interface. | |
7728 | .TP 8 | |
7729 | .B xtrace | |
7730 | Same as | |
7731 | .BR \-x . | |
ccc6cda3 | 7732 | .sp .5 |
726f6388 | 7733 | .PP |
ccc6cda3 JA |
7734 | If |
7735 | .B \-o | |
7736 | is supplied with no \fIoption\-name\fP, the values of the current options are | |
726f6388 | 7737 | printed. |
ccc6cda3 JA |
7738 | If |
7739 | .B +o | |
7740 | is supplied with no \fIoption\-name\fP, a series of | |
7741 | .B set | |
7742 | commands to recreate the current option settings is displayed on | |
7743 | the standard output. | |
726f6388 JA |
7744 | .RE |
7745 | .TP 8 | |
7746 | .B \-p | |
7747 | Turn on | |
7748 | .I privileged | |
7749 | mode. In this mode, the | |
bb70624e | 7750 | .SM |
726f6388 | 7751 | .B $ENV |
b72432fd | 7752 | and |
bb70624e | 7753 | .SM |
b72432fd JA |
7754 | .B $BASH_ENV |
7755 | files are not processed, shell functions are not inherited from the | |
bb70624e JA |
7756 | environment, and the |
7757 | .SM | |
7758 | .B SHELLOPTS | |
7759 | variable, if it appears in the environment, is ignored. | |
b72432fd JA |
7760 | If the shell is started with the effective user (group) id not equal to the |
7761 | real user (group) id, and the \fB\-p\fP option is not supplied, these actions | |
7762 | are taken and the effective user id is set to the real user id. | |
7763 | If the \fB\-p\fP option is supplied at startup, the effective user id is | |
7764 | not reset. | |
cce855bc | 7765 | Turning this option off causes the effective user |
726f6388 JA |
7766 | and group ids to be set to the real user and group ids. |
7767 | .TP 8 | |
7768 | .B \-t | |
7769 | Exit after reading and executing one command. | |
7770 | .TP 8 | |
7771 | .B \-u | |
7772 | Treat unset variables as an error when performing | |
7773 | parameter expansion. If expansion is attempted on an | |
7774 | unset variable, the shell prints an error message, and, | |
ccc6cda3 | 7775 | if not interactive, exits with a non-zero status. |
726f6388 JA |
7776 | .TP 8 |
7777 | .B \-v | |
7778 | Print shell input lines as they are read. | |
7779 | .TP 8 | |
7780 | .B \-x | |
ccc6cda3 | 7781 | After expanding each \fIsimple command\fP, |
d3a24ed2 CR |
7782 | \fBfor\fP command, \fBcase\fP command, \fBselect\fP command, or |
7783 | arithmetic \fBfor\fP command, display the expanded value of | |
726f6388 JA |
7784 | .SM |
7785 | .BR PS4 , | |
d3a24ed2 CR |
7786 | followed by the command and its expanded arguments |
7787 | or associated word list. | |
726f6388 | 7788 | .TP 8 |
ccc6cda3 JA |
7789 | .B \-B |
7790 | The shell performs brace expansion (see | |
7791 | .B Brace Expansion | |
7792 | above). This is on by default. | |
726f6388 JA |
7793 | .TP 8 |
7794 | .B \-C | |
ccc6cda3 JA |
7795 | If set, |
7796 | .B bash | |
7797 | does not overwrite an existing file with the | |
7798 | .BR > , | |
7799 | .BR >& , | |
7800 | and | |
7801 | .B <> | |
7802 | redirection operators. This may be overridden when | |
7803 | creating output files by using the redirection operator | |
7804 | .B >| | |
7805 | instead of | |
7806 | .BR > . | |
726f6388 | 7807 | .TP 8 |
d3a24ed2 CR |
7808 | .B \-E |
7809 | If set, any trap on \fBERR\fP is inherited by shell functions, command | |
7810 | substitutions, and commands executed in a subshell environment. | |
7811 | The \fBERR\fP trap is normally not inherited in such cases. | |
7812 | .TP 8 | |
726f6388 JA |
7813 | .B \-H |
7814 | Enable | |
7815 | .B ! | |
cce855bc | 7816 | style history substitution. This option is on by |
726f6388 JA |
7817 | default when the shell is interactive. |
7818 | .TP 8 | |
7819 | .B \-P | |
ccc6cda3 JA |
7820 | If set, the shell does not follow symbolic links when executing |
7821 | commands such as | |
726f6388 | 7822 | .B cd |
ccc6cda3 JA |
7823 | that change the current working directory. It uses the |
7824 | physical directory structure instead. By default, | |
7825 | .B bash | |
7826 | follows the logical chain of directories when performing commands | |
7827 | which change the current directory. | |
726f6388 | 7828 | .TP 8 |
d3a24ed2 | 7829 | .B \-T |
76a8d78d CR |
7830 | If set, any traps on \fBDEBUG\fP and \fBRETURN\fP are inherited by shell |
7831 | functions, command substitutions, and commands executed in a | |
7832 | subshell environment. | |
7833 | The \fBDEBUG\fP and \fBRETURN\fP traps are normally not inherited | |
7834 | in such cases. | |
d3a24ed2 | 7835 | .TP 8 |
726f6388 | 7836 | .B \-\- |
cce855bc | 7837 | If no arguments follow this option, then the positional parameters are |
726f6388 JA |
7838 | unset. Otherwise, the positional parameters are set to the |
7839 | \fIarg\fPs, even if some of them begin with a | |
7840 | .BR \- . | |
7841 | .TP 8 | |
7842 | .B \- | |
7843 | Signal the end of options, cause all remaining \fIarg\fPs to be | |
7844 | assigned to the positional parameters. The | |
7845 | .B \-x | |
7846 | and | |
7847 | .B \-v | |
7848 | options are turned off. | |
7849 | If there are no \fIarg\fPs, | |
7850 | the positional parameters remain unchanged. | |
7851 | .PD | |
7852 | .PP | |
cce855bc JA |
7853 | The options are off by default unless otherwise noted. |
7854 | Using + rather than \- causes these options to be turned off. | |
7855 | The options can also be specified as arguments to an invocation of | |
7856 | the shell. | |
7857 | The current set of options may be found in | |
726f6388 | 7858 | .BR $\- . |
cce855bc | 7859 | The return status is always true unless an invalid option is encountered. |
726f6388 JA |
7860 | .RE |
7861 | .TP | |
7862 | \fBshift\fP [\fIn\fP] | |
7863 | The positional parameters from \fIn\fP+1 ... are renamed to | |
7864 | .B $1 | |
7865 | .B .... | |
7866 | Parameters represented by the numbers \fB$#\fP | |
7867 | down to \fB$#\fP\-\fIn\fP+1 are unset. | |
ccc6cda3 JA |
7868 | .I n |
7869 | must be a non-negative number less than or equal to \fB$#\fP. | |
726f6388 JA |
7870 | If |
7871 | .I n | |
7872 | is 0, no parameters are changed. | |
7873 | If | |
7874 | .I n | |
7875 | is not given, it is assumed to be 1. | |
726f6388 JA |
7876 | If |
7877 | .I n | |
7878 | is greater than \fB$#\fP, the positional parameters are not changed. | |
ccc6cda3 | 7879 | The return status is greater than zero if |
726f6388 JA |
7880 | .I n |
7881 | is greater than | |
7882 | .B $# | |
ccc6cda3 JA |
7883 | or less than zero; otherwise 0. |
7884 | .TP | |
7885 | \fBshopt\fP [\fB\-pqsu\fP] [\fB\-o\fP] [\fIoptname\fP ...] | |
7886 | Toggle the values of variables controlling optional shell behavior. | |
7887 | With no options, or with the | |
7888 | .B \-p | |
7889 | option, a list of all settable options is displayed, with | |
cce855bc JA |
7890 | an indication of whether or not each is set. |
7891 | The \fB\-p\fP option causes output to be displayed in a form that | |
7892 | may be reused as input. | |
7893 | Other options have the following meanings: | |
ccc6cda3 JA |
7894 | .RS |
7895 | .PD 0 | |
7896 | .TP | |
7897 | .B \-s | |
7898 | Enable (set) each \fIoptname\fP. | |
7899 | .TP | |
7900 | .B \-u | |
7901 | Disable (unset) each \fIoptname\fP. | |
7902 | .TP | |
7903 | .B \-q | |
7904 | Suppresses normal output (quiet mode); the return status indicates | |
7905 | whether the \fIoptname\fP is set or unset. | |
7906 | If multiple \fIoptname\fP arguments are given with | |
7907 | .BR \-q , | |
7908 | the return status is zero if all \fIoptnames\fP are enabled; non-zero | |
7909 | otherwise. | |
7910 | .TP | |
7911 | .B \-o | |
7912 | Restricts the values of \fIoptname\fP to be those defined for the | |
7913 | .B \-o | |
7914 | option to the | |
7915 | .B set | |
7916 | builtin. | |
7917 | .PD | |
7918 | .PP | |
7919 | If either | |
7920 | .B \-s | |
7921 | or | |
7922 | .B \-u | |
7923 | is used with no \fIoptname\fP arguments, the display is limited to | |
7924 | those options which are set or unset, respectively. | |
7925 | Unless otherwise noted, the \fBshopt\fP options are disabled (unset) | |
7926 | by default. | |
7927 | .PP | |
7928 | The return status when listing options is zero if all \fIoptnames\fP | |
7929 | are enabled, non-zero otherwise. When setting or unsetting options, | |
cce855bc | 7930 | the return status is zero unless an \fIoptname\fP is not a valid shell |
ccc6cda3 JA |
7931 | option. |
7932 | .PP | |
7933 | The list of \fBshopt\fP options is: | |
7934 | .if t .sp .5v | |
7935 | .if n .sp 1v | |
7936 | .PD 0 | |
7937 | .TP 8 | |
7938 | .B cdable_vars | |
7939 | If set, an argument to the | |
7940 | .B cd | |
7941 | builtin command that | |
7942 | is not a directory is assumed to be the name of a variable whose | |
7943 | value is the directory to change to. | |
7944 | .TP 8 | |
7945 | .B cdspell | |
7946 | If set, minor errors in the spelling of a directory component in a | |
7947 | .B cd | |
7948 | command will be corrected. | |
7949 | The errors checked for are transposed characters, | |
7950 | a missing character, and one character too many. | |
7951 | If a correction is found, the corrected file name is printed, | |
7952 | and the command proceeds. | |
d166f048 | 7953 | This option is only used by interactive shells. |
ccc6cda3 JA |
7954 | .TP 8 |
7955 | .B checkhash | |
7956 | If set, \fBbash\fP checks that a command found in the hash | |
7957 | table exists before trying to execute it. If a hashed command no | |
7958 | longer exists, a normal path search is performed. | |
7959 | .TP 8 | |
7960 | .B checkwinsize | |
7961 | If set, \fBbash\fP checks the window size after each command | |
7962 | and, if necessary, updates the values of | |
7963 | .SM | |
7964 | .B LINES | |
7965 | and | |
7966 | .SM | |
7967 | .BR COLUMNS . | |
7968 | .TP 8 | |
7969 | .B cmdhist | |
7970 | If set, | |
7971 | .B bash | |
7972 | attempts to save all lines of a multiple-line | |
7973 | command in the same history entry. This allows | |
7974 | easy re-editing of multi-line commands. | |
7975 | .TP 8 | |
7976 | .B dotglob | |
7977 | If set, | |
7978 | .B bash | |
7979 | includes filenames beginning with a `.' in the results of pathname | |
7980 | expansion. | |
7981 | .TP 8 | |
7982 | .B execfail | |
7983 | If set, a non-interactive shell will not exit if | |
7984 | it cannot execute the file specified as an argument to the | |
7985 | .B exec | |
7986 | builtin command. An interactive shell does not exit if | |
7987 | .B exec | |
7988 | fails. | |
7989 | .TP 8 | |
7990 | .B expand_aliases | |
7991 | If set, aliases are expanded as described above under | |
7992 | .SM | |
7993 | .BR ALIASES . | |
7994 | This option is enabled by default for interactive shells. | |
7995 | .TP 8 | |
d3a24ed2 CR |
7996 | .B extdebug |
7997 | If set, behavior intended for use by debuggers is enabled: | |
7998 | .RS | |
7999 | .TP | |
8000 | .B 1. | |
8001 | The \fB\-F\fP option to the \fBdeclare\fP builtin displays the source | |
8002 | file name and line number corresponding to each function name supplied | |
8003 | as an argument. | |
8004 | .TP | |
8005 | .B 2. | |
8006 | If the command run by the \fBDEBUG\fP trap returns a non-zero value, the | |
8007 | next command is skipped and not executed. | |
8008 | .TP | |
8009 | .B 3. | |
8010 | If the command run by the \fBDEBUG\fP trap returns a value of 2, and the | |
8011 | shell is executing in a subroutine (a shell function or a shell script | |
8012 | executed by the \fB.\fP or \fBsource\fP builtins), a call to | |
8013 | \fBreturn\fP is simulated. | |
2206f89a CR |
8014 | .TP |
8015 | .B 4. | |
8016 | \fBBASH_ARGC\fP and \fBBASH_ARGV\fP are updated as described in their | |
8017 | descriptions above. | |
8018 | .TP | |
8019 | .B 5. | |
8020 | Function tracing is enabled: command substitution, shell functions, and | |
8021 | subshells invoked with \fB(\fP \fIcommand\fP \fB)\fP inherit the | |
8022 | \fBDEBUG\fP and \fBRETURN\fP traps. | |
8023 | .TP | |
8024 | .B 6. | |
8025 | Error tracing is enabled: command substitution, shell functions, and | |
8026 | subshells invoked with \fB(\fP \fIcommand\fP \fB)\fP inherit the | |
8027 | \fBERROR\fP trap. | |
d3a24ed2 CR |
8028 | .RE |
8029 | .TP 8 | |
cce855bc JA |
8030 | .B extglob |
8031 | If set, the extended pattern matching features described above under | |
8032 | \fBPathname Expansion\fP are enabled. | |
8033 | .TP 8 | |
d3a24ed2 | 8034 | .B extquote |
20587658 | 8035 | If set, \fB$\fP\(aq\fIstring\fP\(aq and \fB$\fP"\fIstring\fP" quoting is |
d3a24ed2 CR |
8036 | performed within \fB${\fP\fIparameter\fP\fB}\fP expansions |
8037 | enclosed in double quotes. This option is enabled by default. | |
8038 | .TP 8 | |
8039 | .B failglob | |
8040 | If set, patterns which fail to match filenames during pathname expansion | |
8041 | result in an expansion error. | |
8042 | .TP 8 | |
8043 | .B force_fignore | |
8044 | If set, the suffixes specified by the \fBFIGNORE\fP shell variable | |
8045 | cause words to be ignored when performing word completion even if | |
8046 | the ignored words are the only possible completions. | |
8047 | See | |
8048 | .SM | |
8049 | \fBSHELL VARIABLES\fP | |
8050 | above for a description of \fBFIGNORE\fP. | |
8051 | This option is enabled by default. | |
8052 | .TP 8 | |
8053 | .B gnu_errfmt | |
8054 | If set, shell error messages are written in the standard GNU error | |
8055 | message format. | |
8056 | .TP 8 | |
ccc6cda3 JA |
8057 | .B histappend |
8058 | If set, the history list is appended to the file named by the value | |
8059 | of the | |
8060 | .B HISTFILE | |
8061 | variable when the shell exits, rather than overwriting the file. | |
8062 | .TP 8 | |
8063 | .B histreedit | |
8064 | If set, and | |
8065 | .B readline | |
8066 | is being used, a user is given the opportunity to re-edit a | |
8067 | failed history substitution. | |
8068 | .TP 8 | |
8069 | .B histverify | |
8070 | If set, and | |
8071 | .B readline | |
8072 | is being used, the results of history substitution are not immediately | |
8073 | passed to the shell parser. Instead, the resulting line is loaded into | |
8074 | the \fBreadline\fP editing buffer, allowing further modification. | |
8075 | .TP 8 | |
8076 | .B hostcomplete | |
8077 | If set, and | |
8078 | .B readline | |
cce855bc JA |
8079 | is being used, \fBbash\fP will attempt to perform hostname completion when a |
8080 | word containing a \fB@\fP is being completed (see | |
ccc6cda3 JA |
8081 | .B Completing |
8082 | under | |
8083 | .SM | |
8084 | .B READLINE | |
8085 | above). | |
8086 | This is enabled by default. | |
8087 | .TP 8 | |
cce855bc JA |
8088 | .B huponexit |
8089 | If set, \fBbash\fP will send | |
8090 | .SM | |
8091 | .B SIGHUP | |
8092 | to all jobs when an interactive login shell exits. | |
8093 | .TP 8 | |
ccc6cda3 JA |
8094 | .B interactive_comments |
8095 | If set, allow a word beginning with | |
8096 | .B # | |
8097 | to cause that word and all remaining characters on that | |
8098 | line to be ignored in an interactive shell (see | |
8099 | .SM | |
8100 | .B COMMENTS | |
8101 | above). This option is enabled by default. | |
8102 | .TP 8 | |
8103 | .B lithist | |
8104 | If set, and the | |
8105 | .B cmdhist | |
8106 | option is enabled, multi-line commands are saved to the history with | |
8107 | embedded newlines rather than using semicolon separators where possible. | |
8108 | .TP 8 | |
f73dda09 JA |
8109 | .B login_shell |
8110 | The shell sets this option if it is started as a login shell (see | |
8111 | .SM | |
8112 | .B "INVOCATION" | |
8113 | above). | |
8114 | The value may not be changed. | |
8115 | .TP 8 | |
ccc6cda3 JA |
8116 | .B mailwarn |
8117 | If set, and a file that \fBbash\fP is checking for mail has been | |
8118 | accessed since the last time it was checked, the message ``The mail in | |
8119 | \fImailfile\fP has been read'' is displayed. | |
8120 | .TP 8 | |
bb70624e JA |
8121 | .B no_empty_cmd_completion |
8122 | If set, and | |
8123 | .B readline | |
8124 | is being used, | |
8125 | .B bash | |
8126 | will not attempt to search the \fBPATH\fP for possible completions when | |
8127 | completion is attempted on an empty line. | |
8128 | .TP 8 | |
cce855bc JA |
8129 | .B nocaseglob |
8130 | If set, | |
8131 | .B bash | |
8132 | matches filenames in a case\-insensitive fashion when performing pathname | |
8133 | expansion (see | |
8134 | .B Pathname Expansion | |
8135 | above). | |
8136 | .TP 8 | |
2206f89a CR |
8137 | .B nocasematch |
8138 | If set, | |
8139 | .B bash | |
8140 | matches patterns in a case\-insensitive fashion when performing matching | |
8141 | while executing \fBcase\fP or \fB[[\fP conditional commands. | |
8142 | .TP 8 | |
ccc6cda3 JA |
8143 | .B nullglob |
8144 | If set, | |
8145 | .B bash | |
8146 | allows patterns which match no | |
8147 | files (see | |
8148 | .B Pathname Expansion | |
8149 | above) | |
8150 | to expand to a null string, rather than themselves. | |
8151 | .TP 8 | |
bb70624e JA |
8152 | .B progcomp |
8153 | If set, the programmable completion facilities (see | |
8154 | \fBProgrammable Completion\fP above) are enabled. | |
8155 | This option is enabled by default. | |
8156 | .TP 8 | |
ccc6cda3 | 8157 | .B promptvars |
d3a24ed2 CR |
8158 | If set, prompt strings undergo |
8159 | parameter expansion, command substitution, arithmetic | |
8160 | expansion, and quote removal after being expanded as described in | |
ccc6cda3 JA |
8161 | .SM |
8162 | .B PROMPTING | |
8163 | above. This option is enabled by default. | |
8164 | .TP 8 | |
b72432fd JA |
8165 | .B restricted_shell |
8166 | The shell sets this option if it is started in restricted mode (see | |
8167 | .SM | |
8168 | .B "RESTRICTED SHELL" | |
8169 | below). | |
8170 | The value may not be changed. | |
8171 | This is not reset when the startup files are executed, allowing | |
8172 | the startup files to discover whether or not a shell is restricted. | |
8173 | .TP 8 | |
ccc6cda3 JA |
8174 | .B shift_verbose |
8175 | If set, the | |
8176 | .B shift | |
8177 | builtin prints an error message when the shift count exceeds the | |
8178 | number of positional parameters. | |
8179 | .TP 8 | |
8180 | .B sourcepath | |
8181 | If set, the | |
8182 | \fBsource\fP (\fB.\fP) builtin uses the value of | |
8183 | .SM | |
8184 | .B PATH | |
8185 | to find the directory containing the file supplied as an argument. | |
cce855bc | 8186 | This option is enabled by default. |
bb70624e JA |
8187 | .TP 8 |
8188 | .B xpg_echo | |
8189 | If set, the \fBecho\fP builtin expands backslash-escape sequences | |
8190 | by default. | |
ccc6cda3 | 8191 | .RE |
726f6388 JA |
8192 | .TP |
8193 | \fBsuspend\fP [\fB\-f\fP] | |
8194 | Suspend the execution of this shell until it receives a | |
8195 | .SM | |
8196 | .B SIGCONT | |
8197 | signal. The | |
8198 | .B \-f | |
8199 | option says not to complain if this is | |
8200 | a login shell; just suspend anyway. The return status is 0 unless | |
8201 | the shell is a login shell and | |
8202 | .B \-f | |
8203 | is not supplied, or if job control is not enabled. | |
8204 | .TP | |
726f6388 | 8205 | \fBtest\fP \fIexpr\fP |
7117c2d2 | 8206 | .PD 0 |
726f6388 JA |
8207 | .TP |
8208 | \fB[\fP \fIexpr\fP \fB]\fP | |
ccc6cda3 | 8209 | Return a status of 0 or 1 depending on |
726f6388 JA |
8210 | the evaluation of the conditional expression |
8211 | .IR expr . | |
cce855bc JA |
8212 | Each operator and operand must be a separate argument. |
8213 | Expressions are composed of the primaries described above under | |
8214 | .SM | |
8215 | .BR "CONDITIONAL EXPRESSIONS" . | |
3ffb039a CR |
8216 | \fBtest\fP does not accept any options, nor does it accept and ignore |
8217 | an argument of \fB\-\-\fP as signifying the end of options. | |
cce855bc JA |
8218 | .if t .sp 0.5 |
8219 | .if n .sp 1 | |
8220 | Expressions may be combined using the following operators, listed | |
8221 | in decreasing order of precedence. | |
726f6388 JA |
8222 | .RS |
8223 | .PD 0 | |
8224 | .TP | |
726f6388 JA |
8225 | .B ! \fIexpr\fP |
8226 | True if | |
8227 | .I expr | |
8228 | is false. | |
8229 | .TP | |
cce855bc JA |
8230 | .B ( \fIexpr\fP ) |
8231 | Returns the value of \fIexpr\fP. | |
8232 | This may be used to override the normal precedence of operators. | |
8233 | .TP | |
726f6388 JA |
8234 | \fIexpr1\fP \-\fBa\fP \fIexpr2\fP |
8235 | True if both | |
8236 | .I expr1 | |
cce855bc | 8237 | and |
726f6388 JA |
8238 | .I expr2 |
8239 | are true. | |
8240 | .TP | |
8241 | \fIexpr1\fP \-\fBo\fP \fIexpr2\fP | |
8242 | True if either | |
8243 | .I expr1 | |
cce855bc | 8244 | or |
726f6388 JA |
8245 | .I expr2 |
8246 | is true. | |
cce855bc JA |
8247 | .PD |
8248 | .PP | |
8249 | \fBtest\fP and \fB[\fP evaluate conditional | |
8250 | expressions using a set of rules based on the number of arguments. | |
8251 | .if t .sp 0.5 | |
8252 | .if n .sp 1 | |
8253 | .PD 0 | |
726f6388 | 8254 | .TP |
cce855bc JA |
8255 | 0 arguments |
8256 | The expression is false. | |
8257 | .TP | |
8258 | 1 argument | |
8259 | The expression is true if and only if the argument is not null. | |
8260 | .TP | |
8261 | 2 arguments | |
8262 | If the first argument is \fB!\fP, the expression is true if and | |
8263 | only if the second argument is null. | |
8264 | If the first argument is one of the unary conditional operators listed above | |
8265 | under | |
726f6388 | 8266 | .SM |
cce855bc JA |
8267 | .BR "CONDITIONAL EXPRESSIONS" , |
8268 | the expression is true if the unary test is true. | |
8269 | If the first argument is not a valid unary conditional operator, the expression | |
8270 | is false. | |
8271 | .TP | |
8272 | 3 arguments | |
8273 | If the second argument is one of the binary conditional operators listed above | |
8274 | under | |
8275 | .SM | |
8276 | .BR "CONDITIONAL EXPRESSIONS" , | |
8277 | the result of the expression is the result of the binary test using | |
8278 | the first and third arguments as operands. | |
8279 | If the first argument is \fB!\fP, the value is the negation of | |
8280 | the two-argument test using the second and third arguments. | |
8281 | If the first argument is exactly \fB(\fP and the third argument is | |
8282 | exactly \fB)\fP, the result is the one-argument test of the second | |
8283 | argument. | |
8284 | Otherwise, the expression is false. | |
8285 | The \fB\-a\fP and \fB\-o\fP operators are considered binary operators | |
8286 | in this case. | |
8287 | .TP | |
8288 | 4 arguments | |
8289 | If the first argument is \fB!\fP, the result is the negation of | |
8290 | the three-argument expression composed of the remaining arguments. | |
8291 | Otherwise, the expression is parsed and evaluated according to | |
8292 | precedence using the rules listed above. | |
8293 | .TP | |
8294 | 5 or more arguments | |
8295 | The expression is parsed and evaluated according to precedence | |
8296 | using the rules listed above. | |
726f6388 | 8297 | .RE |
cce855bc | 8298 | .PD |
726f6388 JA |
8299 | .TP |
8300 | .B times | |
8301 | Print the accumulated user and system times for the shell and | |
8302 | for processes run from the shell. The return status is 0. | |
8303 | .TP | |
61deeb13 | 8304 | \fBtrap\fP [\fB\-lp\fP] [[\fIarg\fP] \fIsigspec\fP ...] |
726f6388 JA |
8305 | The command |
8306 | .I arg | |
8307 | is to be read and executed when the shell receives | |
8308 | signal(s) | |
8309 | .IR sigspec . | |
8310 | If | |
8311 | .I arg | |
61deeb13 | 8312 | is absent (and there is a single \fIsigspec\fP) or |
726f6388 | 8313 | .BR \- , |
61deeb13 CR |
8314 | each specified signal is |
8315 | reset to its original disposition (the value it had | |
d166f048 JA |
8316 | upon entrance to the shell). |
8317 | If | |
726f6388 | 8318 | .I arg |
d166f048 JA |
8319 | is the null string the signal specified by each |
8320 | .I sigspec | |
8321 | is ignored by the shell and by the commands it invokes. | |
ccc6cda3 JA |
8322 | If |
8323 | .I arg | |
bb70624e | 8324 | is not present and |
ccc6cda3 | 8325 | .B \-p |
bb70624e | 8326 | has been supplied, then the trap commands associated with each |
ccc6cda3 | 8327 | .I sigspec |
bb70624e JA |
8328 | are displayed. |
8329 | If no arguments are supplied or if only | |
ccc6cda3 JA |
8330 | .B \-p |
8331 | is given, | |
8332 | .B trap | |
61deeb13 | 8333 | prints the list of commands associated with each signal. |
d3a24ed2 CR |
8334 | The |
8335 | .B \-l | |
8336 | option causes the shell to print a list of signal names and | |
8337 | their corresponding numbers. | |
d166f048 | 8338 | Each |
726f6388 JA |
8339 | .I sigspec |
8340 | is either | |
d166f048 | 8341 | a signal name defined in <\fIsignal.h\fP>, or a signal number. |
61deeb13 | 8342 | Signal names are case insensitive and the SIG prefix is optional. |
d166f048 | 8343 | If a |
726f6388 JA |
8344 | .I sigspec |
8345 | is | |
8346 | .SM | |
8347 | .B EXIT | |
8348 | (0) the command | |
8349 | .I arg | |
f73dda09 JA |
8350 | is executed on exit from the shell. |
8351 | If a | |
ccc6cda3 JA |
8352 | .I sigspec |
8353 | is | |
8354 | .SM | |
8355 | .BR DEBUG , | |
8356 | the command | |
8357 | .I arg | |
d3a24ed2 CR |
8358 | is executed before every \fIsimple command\fP, \fIfor\fP command, |
8359 | \fIcase\fP command, \fIselect\fP command, every arithmetic \fIfor\fP | |
8360 | command, and before the first command executes in a shell function (see | |
ccc6cda3 JA |
8361 | .SM |
8362 | .B SHELL GRAMMAR | |
8363 | above). | |
40b074c6 | 8364 | Refer to the description of the \fBextdebug\fP option to the |
d3a24ed2 | 8365 | \fBshopt\fP builtin for details of its effect on the \fBDEBUG\fP trap. |
f73dda09 JA |
8366 | If a |
8367 | .I sigspec | |
8368 | is | |
8369 | .SM | |
8370 | .BR ERR , | |
8371 | the command | |
8372 | .I arg | |
5e13499c CR |
8373 | is executed whenever a simple command has a non\-zero exit status, |
8374 | subject to the following conditions. | |
f73dda09 JA |
8375 | The |
8376 | .SM | |
d3a24ed2 CR |
8377 | .B ERR |
8378 | trap is not executed if the failed | |
8379 | command is part of the command list immediately following a | |
8380 | .B while | |
f73dda09 | 8381 | or |
d3a24ed2 CR |
8382 | .B until |
8383 | keyword, | |
8384 | part of the test in an | |
f73dda09 JA |
8385 | .I if |
8386 | statement, part of a | |
8387 | .B && | |
8388 | or | |
8389 | .B \(bv\(bv | |
8390 | list, or if the command's return value is | |
8391 | being inverted via | |
8392 | .BR ! . | |
5e13499c | 8393 | These are the same conditions obeyed by the \fBerrexit\fP option. |
d3a24ed2 CR |
8394 | If a |
8395 | .I sigspec | |
8396 | is | |
8397 | .SM | |
8398 | .BR RETURN , | |
8399 | the command | |
8400 | .I arg | |
8401 | is executed each time a shell function or a script executed with the | |
8402 | \fB.\fP or \fBsource\fP builtins finishes executing. | |
726f6388 JA |
8403 | Signals ignored upon entry to the shell cannot be trapped or reset. |
8404 | Trapped signals are reset to their original values in a child | |
d166f048 JA |
8405 | process when it is created. |
8406 | The return status is false if any | |
ccc6cda3 JA |
8407 | .I sigspec |
8408 | is invalid; otherwise | |
726f6388 JA |
8409 | .B trap |
8410 | returns true. | |
8411 | .TP | |
7117c2d2 | 8412 | \fBtype\fP [\fB\-aftpP\fP] \fIname\fP [\fIname\fP ...] |
726f6388 JA |
8413 | With no options, |
8414 | indicate how each | |
8415 | .I name | |
8416 | would be interpreted if used as a command name. | |
8417 | If the | |
cce855bc JA |
8418 | .B \-t |
8419 | option is used, | |
726f6388 | 8420 | .B type |
ccc6cda3 | 8421 | prints a string which is one of |
726f6388 JA |
8422 | .IR alias , |
8423 | .IR keyword , | |
8424 | .IR function , | |
8425 | .IR builtin , | |
8426 | or | |
8427 | .I file | |
8428 | if | |
8429 | .I name | |
8430 | is an alias, shell reserved word, function, builtin, or disk file, | |
ccc6cda3 JA |
8431 | respectively. |
8432 | If the | |
8433 | .I name | |
8434 | is not found, then nothing is printed, and an exit status of false | |
8435 | is returned. | |
726f6388 | 8436 | If the |
cce855bc JA |
8437 | .B \-p |
8438 | option is used, | |
726f6388 JA |
8439 | .B type |
8440 | either returns the name of the disk file | |
8441 | that would be executed if | |
8442 | .I name | |
8443 | were specified as a command name, | |
28ef6c31 JA |
8444 | or nothing if |
8445 | .if t \f(CWtype -t name\fP | |
8446 | .if n ``type -t name'' | |
726f6388 JA |
8447 | would not return |
8448 | .IR file . | |
7117c2d2 JA |
8449 | The |
8450 | .B \-P | |
8451 | option forces a | |
8452 | .SM | |
8453 | .B PATH | |
8454 | search for each \fIname\fP, even if | |
8455 | .if t \f(CWtype -t name\fP | |
8456 | .if n ``type -t name'' | |
8457 | would not return | |
8458 | .IR file . | |
726f6388 | 8459 | If a command is hashed, |
cce855bc | 8460 | .B \-p |
7117c2d2 JA |
8461 | and |
8462 | .B \-P | |
8463 | print the hashed value, not necessarily the file that appears | |
726f6388 JA |
8464 | first in |
8465 | .SM | |
8466 | .BR PATH . | |
8467 | If the | |
cce855bc JA |
8468 | .B \-a |
8469 | option is used, | |
726f6388 JA |
8470 | .B type |
8471 | prints all of the places that contain | |
8472 | an executable named | |
8473 | .IR name . | |
8474 | This includes aliases and functions, | |
8475 | if and only if the | |
cce855bc JA |
8476 | .B \-p |
8477 | option is not also used. | |
726f6388 JA |
8478 | The table of hashed commands is not consulted |
8479 | when using | |
cce855bc | 8480 | .BR \-a . |
7117c2d2 JA |
8481 | The |
8482 | .B \-f | |
8483 | option suppresses shell function lookup, as with the \fBcommand\fP builtin. | |
726f6388 JA |
8484 | .B type |
8485 | returns true if any of the arguments are found, false if | |
8486 | none are found. | |
8487 | .TP | |
dc8fbaf9 | 8488 | \fBulimit\fP [\fB\-SHacdefilmnpqrstuvx\fP [\fIlimit\fP]] |
ccc6cda3 | 8489 | Provides control over the resources available to the shell and to |
f73dda09 | 8490 | processes started by it, on systems that allow such control. |
ccc6cda3 | 8491 | The \fB\-H\fP and \fB\-S\fP options specify that the hard or soft limit is |
726f6388 JA |
8492 | set for the given resource. A hard limit cannot be increased once it |
8493 | is set; a soft limit may be increased up to the value of the hard limit. | |
ccc6cda3 JA |
8494 | If neither \fB\-H\fP nor \fB\-S\fP is specified, both the soft and hard |
8495 | limits are set. | |
f73dda09 JA |
8496 | The value of |
8497 | .I limit | |
8498 | can be a number in the unit specified for the resource | |
8499 | or one of the special values | |
8500 | .BR hard , | |
8501 | .BR soft , | |
8502 | or | |
8503 | .BR unlimited , | |
8504 | which stand for the current hard limit, the current soft limit, and | |
8505 | no limit, respectively. | |
ccc6cda3 | 8506 | If |
726f6388 JA |
8507 | .I limit |
8508 | is omitted, the current value of the soft limit of the resource is | |
ccc6cda3 JA |
8509 | printed, unless the \fB\-H\fP option is given. When more than one |
8510 | resource is specified, the limit name and unit are printed before the value. | |
726f6388 JA |
8511 | Other options are interpreted as follows: |
8512 | .RS | |
8513 | .PD 0 | |
8514 | .TP | |
8515 | .B \-a | |
ccc6cda3 | 8516 | All current limits are reported |
726f6388 JA |
8517 | .TP |
8518 | .B \-c | |
ccc6cda3 | 8519 | The maximum size of core files created |
726f6388 JA |
8520 | .TP |
8521 | .B \-d | |
ccc6cda3 | 8522 | The maximum size of a process's data segment |
726f6388 | 8523 | .TP |
dc8fbaf9 CR |
8524 | .B \-e |
8525 | The maximum scheduling priority ("nice") | |
8526 | .TP | |
726f6388 | 8527 | .B \-f |
ccc6cda3 | 8528 | The maximum size of files created by the shell |
726f6388 | 8529 | .TP |
af12dacd CR |
8530 | .B \-i |
8531 | The maximum number of pending signals | |
8532 | .TP | |
ccc6cda3 JA |
8533 | .B \-l |
8534 | The maximum size that may be locked into memory | |
726f6388 | 8535 | .TP |
ccc6cda3 JA |
8536 | .B \-m |
8537 | The maximum resident set size | |
726f6388 | 8538 | .TP |
ccc6cda3 JA |
8539 | .B \-n |
8540 | The maximum number of open file descriptors (most systems do not | |
8541 | allow this value to be set) | |
726f6388 JA |
8542 | .TP |
8543 | .B \-p | |
ccc6cda3 | 8544 | The pipe size in 512-byte blocks (this may not be set) |
726f6388 | 8545 | .TP |
af12dacd CR |
8546 | .B \-q |
8547 | The maximum number of bytes in POSIX message queues | |
8548 | .TP | |
dc8fbaf9 CR |
8549 | .B \-r |
8550 | The maximum real-time scheduling priority | |
8551 | .TP | |
ccc6cda3 JA |
8552 | .B \-s |
8553 | The maximum stack size | |
8554 | .TP | |
8555 | .B \-t | |
8556 | The maximum amount of cpu time in seconds | |
726f6388 JA |
8557 | .TP |
8558 | .B \-u | |
ccc6cda3 | 8559 | The maximum number of processes available to a single user |
726f6388 JA |
8560 | .TP |
8561 | .B \-v | |
8562 | The maximum amount of virtual memory available to the shell | |
af12dacd CR |
8563 | .TP |
8564 | .B \-x | |
8565 | The maximum number of file locks | |
726f6388 JA |
8566 | .PD |
8567 | .PP | |
ccc6cda3 | 8568 | If |
726f6388 JA |
8569 | .I limit |
8570 | is given, it is the new value of the specified resource (the | |
8571 | .B \-a | |
8572 | option is display only). | |
8573 | If no option is given, then | |
8574 | .B \-f | |
8575 | is assumed. Values are in 1024-byte increments, except for | |
8576 | .BR \-t , | |
8577 | which is in seconds, | |
8578 | .BR \-p , | |
8579 | which is in units of 512-byte blocks, | |
8580 | and | |
8581 | .B \-n | |
8582 | and | |
8583 | .BR \-u , | |
f73dda09 JA |
8584 | which are unscaled values. |
8585 | The return status is 0 unless an invalid option or argument is supplied, | |
8586 | or an error occurs while setting a new limit. | |
726f6388 JA |
8587 | .RE |
8588 | .TP | |
cce855bc | 8589 | \fBumask\fP [\fB\-p\fP] [\fB\-S\fP] [\fImode\fP] |
726f6388 JA |
8590 | The user file-creation mask is set to |
8591 | .IR mode . | |
8592 | If | |
8593 | .I mode | |
8594 | begins with a digit, it | |
8595 | is interpreted as an octal number; otherwise | |
8596 | it is interpreted as a symbolic mode mask similar | |
8597 | to that accepted by | |
8598 | .IR chmod (1). | |
8599 | If | |
8600 | .I mode | |
bb70624e | 8601 | is omitted, the current value of the mask is printed. |
ccc6cda3 | 8602 | The |
726f6388 JA |
8603 | .B \-S |
8604 | option causes the mask to be printed in symbolic form; the | |
8605 | default output is an octal number. | |
cce855bc JA |
8606 | If the |
8607 | .B \-p | |
8608 | option is supplied, and | |
8609 | .I mode | |
8610 | is omitted, the output is in a form that may be reused as input. | |
ccc6cda3 | 8611 | The return status is 0 if the mode was successfully changed or if |
726f6388 JA |
8612 | no \fImode\fP argument was supplied, and false otherwise. |
8613 | .TP | |
8614 | \fBunalias\fP [\-\fBa\fP] [\fIname\fP ...] | |
bb70624e | 8615 | Remove each \fIname\fP from the list of defined aliases. If |
726f6388 JA |
8616 | .B \-a |
8617 | is supplied, all alias definitions are removed. The return | |
8618 | value is true unless a supplied | |
8619 | .I name | |
8620 | is not a defined alias. | |
8621 | .TP | |
8622 | \fBunset\fP [\-\fBfv\fP] [\fIname\fP ...] | |
8623 | For each | |
8624 | .IR name , | |
ccc6cda3 JA |
8625 | remove the corresponding variable or function. |
8626 | If no options are supplied, or the | |
8627 | .B \-v | |
8628 | option is given, each | |
8629 | .I name | |
8630 | refers to a shell variable. | |
8631 | Read-only variables may not be unset. | |
8632 | If | |
726f6388 | 8633 | .B \-f |
f75912ae | 8634 | is specified, each |
ccc6cda3 JA |
8635 | .I name |
8636 | refers to a shell function, and the function definition | |
8637 | is removed. | |
8638 | Each unset variable or function is removed from the environment | |
8639 | passed to subsequent commands. | |
8640 | If any of | |
726f6388 JA |
8641 | .SM |
8642 | .BR RANDOM , | |
8643 | .SM | |
8644 | .BR SECONDS , | |
8645 | .SM | |
8646 | .BR LINENO , | |
ccc6cda3 JA |
8647 | .SM |
8648 | .BR HISTCMD , | |
bb70624e JA |
8649 | .SM |
8650 | .BR FUNCNAME , | |
8651 | .SM | |
8652 | .BR GROUPS , | |
726f6388 JA |
8653 | or |
8654 | .SM | |
ccc6cda3 | 8655 | .B DIRSTACK |
726f6388 JA |
8656 | are unset, they lose their special properties, even if they are |
8657 | subsequently reset. The exit status is true unless a | |
8658 | .I name | |
d3a24ed2 | 8659 | is readonly. |
726f6388 | 8660 | .TP |
d90269dd CR |
8661 | \fBwait\fP [\fIn ...\fP] |
8662 | Wait for each specified process and return its termination status. | |
8663 | Each | |
726f6388 JA |
8664 | .I n |
8665 | may be a process | |
8666 | ID or a job specification; if a job spec is given, all processes | |
8667 | in that job's pipeline are waited for. If | |
8668 | .I n | |
8669 | is not given, all currently active child processes | |
8670 | are waited for, and the return status is zero. If | |
8671 | .I n | |
ccc6cda3 | 8672 | specifies a non-existent process or job, the return status is |
726f6388 JA |
8673 | 127. Otherwise, the return status is the exit status of the last |
8674 | process or job waited for. | |
8675 | .\" bash_builtins | |
8676 | .if \n(zZ=1 .ig zZ | |
ccc6cda3 | 8677 | .SH "RESTRICTED SHELL" |
bb70624e JA |
8678 | .\" rbash.1 |
8679 | .zY | |
726f6388 | 8680 | .PP |
ccc6cda3 | 8681 | If |
726f6388 | 8682 | .B bash |
ccc6cda3 JA |
8683 | is started with the name |
8684 | .BR rbash , | |
8685 | or the | |
8686 | .B \-r | |
8687 | option is supplied at invocation, | |
8688 | the shell becomes restricted. | |
8689 | A restricted shell is used to | |
8690 | set up an environment more controlled than the standard shell. | |
8691 | It behaves identically to | |
8692 | .B bash | |
cce855bc | 8693 | with the exception that the following are disallowed or not performed: |
ccc6cda3 JA |
8694 | .IP \(bu |
8695 | changing directories with \fBcd\fP | |
8696 | .IP \(bu | |
8697 | setting or unsetting the values of | |
b72432fd JA |
8698 | .BR SHELL , |
8699 | .BR PATH , | |
8700 | .BR ENV , | |
ccc6cda3 | 8701 | or |
b72432fd | 8702 | .B BASH_ENV |
ccc6cda3 JA |
8703 | .IP \(bu |
8704 | specifying command names containing | |
8705 | .B / | |
8706 | .IP \(bu | |
8707 | specifying a file name containing a | |
8708 | .B / | |
8709 | as an argument to the | |
8710 | .B . | |
8711 | builtin command | |
8712 | .IP \(bu | |
bb70624e JA |
8713 | Specifying a filename containing a slash as an argument to the |
8714 | .B \-p | |
8715 | option to the | |
8716 | .B hash | |
8717 | builtin command | |
8718 | .IP \(bu | |
ccc6cda3 JA |
8719 | importing function definitions from the shell environment at startup |
8720 | .IP \(bu | |
cce855bc JA |
8721 | parsing the value of \fBSHELLOPTS\fP from the shell environment at startup |
8722 | .IP \(bu | |
ccc6cda3 JA |
8723 | redirecting output using the >, >|, <>, >&, &>, and >> redirection operators |
8724 | .IP \(bu | |
8725 | using the | |
8726 | .B exec | |
8727 | builtin command to replace the shell with another command | |
8728 | .IP \(bu | |
8729 | adding or deleting builtin commands with the | |
8730 | .B \-f | |
726f6388 | 8731 | and |
ccc6cda3 JA |
8732 | .B \-d |
8733 | options to the | |
8734 | .B enable | |
8735 | builtin command | |
8736 | .IP \(bu | |
7117c2d2 JA |
8737 | Using the \fBenable\fP builtin command to enable disabled shell builtins |
8738 | .IP \(bu | |
ccc6cda3 JA |
8739 | specifying the |
8740 | .B \-p | |
8741 | option to the | |
8742 | .B command | |
8743 | builtin command | |
8744 | .IP \(bu | |
8745 | turning off restricted mode with | |
cce855bc | 8746 | \fBset +r\fP or \fBset +o restricted\fP. |
726f6388 | 8747 | .PP |
ccc6cda3 JA |
8748 | These restrictions are enforced after any startup files are read. |
8749 | .PP | |
61deeb13 CR |
8750 | .ie \n(zY=1 When a command that is found to be a shell script is executed, |
8751 | .el \{ When a command that is found to be a shell script is executed | |
8752 | (see | |
ccc6cda3 JA |
8753 | .SM |
8754 | .B "COMMAND EXECUTION" | |
8755 | above), | |
61deeb13 | 8756 | \} |
ccc6cda3 JA |
8757 | .B rbash |
8758 | turns off any restrictions in the shell spawned to execute the | |
8759 | script. | |
bb70624e JA |
8760 | .\" end of rbash.1 |
8761 | .if \n(zY=1 .ig zY | |
726f6388 JA |
8762 | .SH "SEE ALSO" |
8763 | .PD 0 | |
8764 | .TP | |
bb70624e | 8765 | \fIBash Reference Manual\fP, Brian Fox and Chet Ramey |
726f6388 JA |
8766 | .TP |
8767 | \fIThe Gnu Readline Library\fP, Brian Fox and Chet Ramey | |
8768 | .TP | |
8769 | \fIThe Gnu History Library\fP, Brian Fox and Chet Ramey | |
8770 | .TP | |
726f6388 JA |
8771 | \fIPortable Operating System Interface (POSIX) Part 2: Shell and Utilities\fP, IEEE |
8772 | .TP | |
8773 | \fIsh\fP(1), \fIksh\fP(1), \fIcsh\fP(1) | |
8774 | .TP | |
8775 | \fIemacs\fP(1), \fIvi\fP(1) | |
8776 | .TP | |
8777 | \fIreadline\fP(3) | |
8778 | .PD | |
8779 | .SH FILES | |
8780 | .PD 0 | |
8781 | .TP | |
8782 | .FN /bin/bash | |
8783 | The \fBbash\fP executable | |
8784 | .TP | |
8785 | .FN /etc/profile | |
8786 | The systemwide initialization file, executed for login shells | |
8787 | .TP | |
8788 | .FN ~/.bash_profile | |
8789 | The personal initialization file, executed for login shells | |
8790 | .TP | |
8791 | .FN ~/.bashrc | |
8792 | The individual per-interactive-shell startup file | |
8793 | .TP | |
b72432fd JA |
8794 | .FN ~/.bash_logout |
8795 | The individual login shell cleanup file, executed when a login shell exits | |
8796 | .TP | |
726f6388 JA |
8797 | .FN ~/.inputrc |
8798 | Individual \fIreadline\fP initialization file | |
8799 | .PD | |
8800 | .SH AUTHORS | |
ccc6cda3 | 8801 | Brian Fox, Free Software Foundation |
726f6388 | 8802 | .br |
bb70624e | 8803 | bfox@gnu.org |
726f6388 JA |
8804 | .PP |
8805 | Chet Ramey, Case Western Reserve University | |
8806 | .br | |
e225d5a9 | 8807 | chet@po.cwru.edu |
726f6388 JA |
8808 | .SH BUG REPORTS |
8809 | If you find a bug in | |
8810 | .B bash, | |
8811 | you should report it. But first, you should | |
8812 | make sure that it really is a bug, and that it appears in the latest | |
8813 | version of | |
d3a24ed2 CR |
8814 | .BR bash . |
8815 | The latest version is always available from | |
8816 | \fIftp://ftp.gnu.org/pub/bash/\fP. | |
726f6388 JA |
8817 | .PP |
8818 | Once you have determined that a bug actually exists, use the | |
8819 | .I bashbug | |
8820 | command to submit a bug report. | |
d166f048 | 8821 | If you have a fix, you are encouraged to mail that as well! |
726f6388 | 8822 | Suggestions and `philosophical' bug reports may be mailed |
cce855bc | 8823 | to \fIbug-bash@gnu.org\fP or posted to the Usenet |
726f6388 JA |
8824 | newsgroup |
8825 | .BR gnu.bash.bug . | |
8826 | .PP | |
8827 | ALL bug reports should include: | |
8828 | .PP | |
8829 | .PD 0 | |
8830 | .TP 20 | |
8831 | The version number of \fBbash\fR | |
8832 | .TP | |
8833 | The hardware and operating system | |
8834 | .TP | |
8835 | The compiler used to compile | |
8836 | .TP | |
8837 | A description of the bug behaviour | |
8838 | .TP | |
8839 | A short script or `recipe' which exercises the bug | |
8840 | .PD | |
8841 | .PP | |
8842 | .I bashbug | |
8843 | inserts the first three items automatically into the template | |
8844 | it provides for filing a bug report. | |
8845 | .PP | |
8846 | Comments and bug reports concerning | |
8847 | this manual page should be directed to | |
e225d5a9 | 8848 | .IR chet@po.cwru.edu . |
726f6388 JA |
8849 | .SH BUGS |
8850 | .PP | |
8851 | It's too big and too slow. | |
8852 | .PP | |
8853 | There are some subtle differences between | |
8854 | .B bash | |
8855 | and traditional versions of | |
8856 | .BR sh , | |
8857 | mostly because of the | |
8858 | .SM | |
8859 | .B POSIX | |
8860 | specification. | |
8861 | .PP | |
8862 | Aliases are confusing in some uses. | |
ccc6cda3 JA |
8863 | .PP |
8864 | Shell builtin commands and functions are not stoppable/restartable. | |
8865 | .PP | |
8866 | Compound commands and command sequences of the form `a ; b ; c' | |
8867 | are not handled gracefully when process suspension is attempted. | |
8868 | When a process is stopped, the shell immediately executes the next | |
8869 | command in the sequence. | |
8870 | It suffices to place the sequence of commands between | |
8871 | parentheses to force it into a subshell, which may be stopped as | |
8872 | a unit. | |
8873 | .PP | |
8874 | Commands inside of \fB$(\fP...\fB)\fP command substitution are not | |
8875 | parsed until substitution is attempted. This will delay error | |
704a1a2a CR |
8876 | reporting until some time after the command is entered. For example, |
8877 | unmatched parentheses, even inside shell comments, will result in | |
8878 | error messages while the construct is being read. | |
ccc6cda3 JA |
8879 | .PP |
8880 | Array variables may not (yet) be exported. | |
726f6388 | 8881 | .zZ |
bb70624e | 8882 | .zY |