]>
Commit | Line | Data |
---|---|---|
d3ad40de | 1 | .\" |
726f6388 JA |
2 | .\" MAN PAGE COMMENTS to |
3 | .\" | |
4 | .\" Chet Ramey | |
726f6388 | 5 | .\" Case Western Reserve University |
e225d5a9 | 6 | .\" chet@po.cwru.edu |
726f6388 | 7 | .\" |
9dd88db7 | 8 | .\" Last Change: Thu Jul 30 09:25:13 EDT 2009 |
726f6388 JA |
9 | .\" |
10 | .\" bash_builtins, strip all but Built-Ins section | |
11 | .if \n(zZ=1 .ig zZ | |
bb70624e | 12 | .if \n(zY=1 .ig zY |
9dd88db7 | 13 | .TH BASH 1 "2009 July 30" "GNU Bash-4.0" |
726f6388 JA |
14 | .\" |
15 | .\" There's some problem with having a `@' | |
16 | .\" in a tagged paragraph with the BSD man macros. | |
17 | .\" It has to do with `@' appearing in the }1 macro. | |
18 | .\" This is a problem on 4.3 BSD and Ultrix, but Sun | |
19 | .\" appears to have fixed it. | |
20 | .\" If you're seeing the characters | |
21 | .\" `@u-3p' appearing before the lines reading | |
22 | .\" `possible-hostname-completions | |
23 | .\" and `complete-hostname' down in READLINE, | |
24 | .\" then uncomment this redefinition. | |
25 | .\" | |
26 | .de }1 | |
27 | .ds ]X \&\\*(]B\\ | |
28 | .nr )E 0 | |
29 | .if !"\\$1"" .nr )I \\$1n | |
30 | .}f | |
31 | .ll \\n(LLu | |
32 | .in \\n()Ru+\\n(INu+\\n()Iu | |
33 | .ti \\n(INu | |
34 | .ie !\\n()Iu+\\n()Ru-\w\a\\*(]X\au-3p \{\\*(]X | |
35 | .br\} | |
36 | .el \\*(]X\h\a|\\n()Iu+\\n()Ru\a\c | |
37 | .}f | |
38 | .. | |
39 | .\" | |
40 | .\" File Name macro. This used to be `.PN', for Path Name, | |
41 | .\" but Sun doesn't seem to like that very much. | |
42 | .\" | |
43 | .de FN | |
44 | \fI\|\\$1\|\fP | |
45 | .. | |
46 | .SH NAME | |
ccc6cda3 | 47 | bash \- GNU Bourne-Again SHell |
726f6388 JA |
48 | .SH SYNOPSIS |
49 | .B bash | |
50 | [options] | |
51 | [file] | |
52 | .SH COPYRIGHT | |
012bac39 CR |
53 | .if n Bash is Copyright (C) 1989-2009 by the Free Software Foundation, Inc. |
54 | .if t Bash is Copyright \(co 1989-2009 by the Free Software Foundation, Inc. | |
726f6388 JA |
55 | .SH DESCRIPTION |
56 | .B Bash | |
ccc6cda3 | 57 | is an \fBsh\fR-compatible command language interpreter that |
726f6388 JA |
58 | executes commands read from the standard input or from a file. |
59 | .B Bash | |
60 | also incorporates useful features from the \fIKorn\fP and \fIC\fP | |
61 | shells (\fBksh\fP and \fBcsh\fP). | |
62 | .PP | |
63 | .B Bash | |
ac18b312 CR |
64 | is intended to be a conformant implementation of the |
65 | Shell and Utilities portion of the IEEE POSIX specification | |
66 | (IEEE Standard 1003.1). | |
7790f917 CR |
67 | .B Bash |
68 | can be configured to be POSIX-conformant by default. | |
726f6388 | 69 | .SH OPTIONS |
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 | |
ac18b312 | 226 | from the POSIX 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 | |
866961ad CR |
412 | attempts to determine when it is being run with its standard input |
413 | connected to a a network connection, as if by the remote shell | |
414 | daemon, usually \fIrshd\fP, or the secure shell daemon \fIsshd\fP. | |
ccc6cda3 JA |
415 | If |
416 | .B bash | |
866961ad | 417 | determines it is being run in this fashion, it reads and executes |
ccc6cda3 JA |
418 | commands from \fI~/.bashrc\fP, if that file exists and is readable. |
419 | It will not do this if invoked as \fBsh\fP. | |
420 | The | |
421 | .B \-\-norc | |
422 | option may be used to inhibit this behavior, and the | |
423 | .B \-\-rcfile | |
424 | option may be used to force another file to be read, but | |
425 | \fIrshd\fP does not generally invoke the shell with those options | |
426 | or allow them to be specified. | |
b72432fd JA |
427 | .PP |
428 | If the shell is started with the effective user (group) id not equal to the | |
429 | real user (group) id, and the \fB\-p\fP option is not supplied, no startup | |
f73dda09 JA |
430 | files are read, shell functions are not inherited from the environment, the |
431 | .SM | |
432 | .B SHELLOPTS | |
433 | variable, if it appears in the environment, is ignored, | |
b72432fd JA |
434 | and the effective user id is set to the real user id. |
435 | If the \fB\-p\fP option is supplied at invocation, the startup behavior is | |
436 | the same, but the effective user id is not reset. | |
726f6388 | 437 | .SH DEFINITIONS |
ccc6cda3 JA |
438 | .PP |
439 | The following definitions are used throughout the rest of this | |
440 | document. | |
726f6388 JA |
441 | .PD 0 |
442 | .TP | |
443 | .B blank | |
444 | A space or tab. | |
445 | .TP | |
446 | .B word | |
447 | A sequence of characters considered as a single unit by the shell. | |
448 | Also known as a | |
449 | .BR token . | |
450 | .TP | |
451 | .B name | |
452 | A | |
453 | .I word | |
454 | consisting only of alphanumeric characters and underscores, and | |
455 | beginning with an alphabetic character or an underscore. Also | |
456 | referred to as an | |
457 | .BR identifier . | |
458 | .TP | |
459 | .B metacharacter | |
460 | A character that, when unquoted, separates words. One of the following: | |
461 | .br | |
462 | .RS | |
463 | .PP | |
464 | .if t \fB| & ; ( ) < > space tab\fP | |
465 | .if n \fB| & ; ( ) < > space tab\fP | |
466 | .RE | |
467 | .PP | |
468 | .TP | |
469 | .B control operator | |
470 | A \fItoken\fP that performs a control function. It is one of the following | |
471 | symbols: | |
472 | .RS | |
473 | .PP | |
8943768b CR |
474 | .if t \fB\(bv\(bv & && ; ;; ( ) | |& <newline>\fP |
475 | .if n \fB|| & && ; ;; ( ) | |& <newline>\fP | |
726f6388 JA |
476 | .RE |
477 | .PD | |
478 | .SH "RESERVED WORDS" | |
479 | \fIReserved words\fP are words that have a special meaning to the shell. | |
480 | The following words are recognized as reserved when unquoted and either | |
481 | the first word of a simple command (see | |
482 | .SM | |
483 | .B SHELL GRAMMAR | |
484 | below) or the third word of a | |
485 | .B case | |
486 | or | |
487 | .B for | |
488 | command: | |
489 | .if t .RS | |
490 | .PP | |
491 | .B | |
cce855bc JA |
492 | .if n ! case do done elif else esac fi for function if in select then until while { } time [[ ]] |
493 | .if t ! case do done elif else esac fi for function if in select then until while { } time [[ ]] | |
726f6388 | 494 | .if t .RE |
726f6388 JA |
495 | .SH "SHELL GRAMMAR" |
496 | .SS Simple Commands | |
497 | .PP | |
498 | A \fIsimple command\fP is a sequence of optional variable assignments | |
ccc6cda3 | 499 | followed by \fBblank\fP-separated words and redirections, and |
726f6388 | 500 | terminated by a \fIcontrol operator\fP. The first word |
f73dda09 JA |
501 | specifies the command to be executed, and is passed as argument zero. |
502 | The remaining words are passed as arguments to the invoked command. | |
726f6388 JA |
503 | .PP |
504 | The return value of a \fIsimple command\fP is its exit status, or | |
505 | 128+\fIn\^\fP if the command is terminated by signal | |
506 | .IR n . | |
507 | .SS Pipelines | |
508 | .PP | |
509 | A \fIpipeline\fP is a sequence of one or more commands separated by | |
8943768b CR |
510 | one of the control operators |
511 | .B | | |
512 | or \fB|&\fP. | |
726f6388 JA |
513 | The format for a pipeline is: |
514 | .RS | |
515 | .PP | |
8943768b | 516 | [\fBtime\fP [\fB\-p\fP]] [ ! ] \fIcommand\fP [ [\fB|\fP\(bv\fB|&\fP] \fIcommand2\fP ... ] |
726f6388 JA |
517 | .RE |
518 | .PP | |
519 | The standard output of | |
520 | .I command | |
f73dda09 | 521 | is connected via a pipe to the standard input of |
726f6388 JA |
522 | .IR command2 . |
523 | This connection is performed before any redirections specified by the | |
524 | command (see | |
525 | .SM | |
526 | .B REDIRECTION | |
527 | below). | |
8943768b CR |
528 | If \fB|&\fP is used, the standard error of \fIcommand\fP is connected to |
529 | \fIcommand2\fP's standard input through the pipe; it is shorthand for | |
530 | \fB2>&1 |\fP. | |
531 | This implicit redirection of the standard error is performed after any | |
532 | redirections specified by the command. | |
726f6388 | 533 | .PP |
d3a24ed2 CR |
534 | The return status of a pipeline is the exit status of the last |
535 | command, unless the \fBpipefail\fP option is enabled. | |
536 | If \fBpipefail\fP is enabled, the pipeline's return status is the | |
537 | value of the last (rightmost) command to exit with a non-zero status, | |
538 | or zero if all commands exit successfully. | |
726f6388 JA |
539 | If the reserved word |
540 | .B ! | |
d3a24ed2 CR |
541 | precedes a pipeline, the exit status of that pipeline is the logical |
542 | negation of the exit status as described above. | |
ccc6cda3 | 543 | The shell waits for all commands in the pipeline to |
726f6388 JA |
544 | terminate before returning a value. |
545 | .PP | |
ccc6cda3 JA |
546 | If the |
547 | .B time | |
548 | reserved word precedes a pipeline, the elapsed as well as user and | |
549 | system time consumed by its execution are reported when the pipeline | |
550 | terminates. | |
551 | The \fB\-p\fP option changes the output format to that specified by POSIX. | |
552 | The | |
553 | .SM | |
554 | .B TIMEFORMAT | |
555 | variable may be set to a format string that specifies how the timing | |
556 | information should be displayed; see the description of | |
557 | .SM | |
558 | .B TIMEFORMAT | |
559 | under | |
560 | .B "Shell Variables" | |
561 | below. | |
562 | .PP | |
726f6388 JA |
563 | Each command in a pipeline is executed as a separate process (i.e., in a |
564 | subshell). | |
565 | .SS Lists | |
566 | .PP | |
567 | A \fIlist\fP is a sequence of one or more pipelines separated by one | |
568 | of the operators | |
569 | .BR ; , | |
570 | .BR & , | |
571 | .BR && , | |
572 | or | |
ccc6cda3 JA |
573 | .BR \(bv\(bv , |
574 | and optionally terminated by one of | |
726f6388 JA |
575 | .BR ; , |
576 | .BR & , | |
577 | or | |
578 | .BR <newline> . | |
579 | .PP | |
580 | Of these list operators, | |
581 | .B && | |
582 | and | |
ccc6cda3 | 583 | .B \(bv\(bv |
726f6388 JA |
584 | have equal precedence, followed by |
585 | .B ; | |
586 | and | |
b1a26c01 | 587 | .BR & , |
726f6388 JA |
588 | which have equal precedence. |
589 | .PP | |
7117c2d2 JA |
590 | A sequence of one or more newlines may appear in a \fIlist\fP instead |
591 | of a semicolon to delimit commands. | |
592 | .PP | |
726f6388 JA |
593 | If a command is terminated by the control operator |
594 | .BR & , | |
595 | the shell executes the command in the \fIbackground\fP | |
596 | in a subshell. The shell does not wait for the command to | |
597 | finish, and the return status is 0. Commands separated by a | |
598 | .B ; | |
599 | are executed sequentially; the shell waits for each | |
600 | command to terminate in turn. The return status is the | |
601 | exit status of the last command executed. | |
602 | .PP | |
6fbe7620 CR |
603 | AND and OR lists are sequences of one of more pipelines separated by the |
604 | \fB&&\fP and \fB\(bv\(bv\fP control operators, respectively. | |
605 | AND and OR lists are executed with left associativity. | |
726f6388 JA |
606 | An AND list has the form |
607 | .RS | |
608 | .PP | |
bb70624e | 609 | \fIcommand1\fP \fB&&\fP \fIcommand2\fP |
726f6388 JA |
610 | .RE |
611 | .PP | |
612 | .I command2 | |
613 | is executed if, and only if, | |
bb70624e | 614 | .I command1 |
726f6388 JA |
615 | returns an exit status of zero. |
616 | .PP | |
617 | An OR list has the form | |
618 | .RS | |
619 | .PP | |
bb70624e | 620 | \fIcommand1\fP \fB\(bv\(bv\fP \fIcommand2\fP |
726f6388 JA |
621 | .PP |
622 | .RE | |
623 | .PP | |
624 | .I command2 | |
625 | is executed if and only if | |
bb70624e | 626 | .I command1 |
6fbe7620 CR |
627 | returns a non-zero exit status. |
628 | The return status of | |
726f6388 JA |
629 | AND and OR lists is the exit status of the last command |
630 | executed in the list. | |
631 | .SS Compound Commands | |
632 | .PP | |
633 | A \fIcompound command\fP is one of the following: | |
634 | .TP | |
635 | (\fIlist\fP) | |
d3a24ed2 CR |
636 | \fIlist\fP is executed in a subshell environment (see |
637 | .SM | |
638 | \fBCOMMAND EXECUTION ENVIRONMENT\fP | |
639 | below). | |
640 | Variable assignments and builtin | |
726f6388 JA |
641 | commands that affect the shell's environment do not remain in effect |
642 | after the command completes. The return status is the exit status of | |
643 | \fIlist\fP. | |
644 | .TP | |
645 | { \fIlist\fP; } | |
ccc6cda3 JA |
646 | \fIlist\fP is simply executed in the current shell environment. |
647 | \fIlist\fP must be terminated with a newline or semicolon. | |
648 | This is known as a \fIgroup command\fP. | |
649 | The return status is the exit status of | |
726f6388 | 650 | \fIlist\fP. |
d3a24ed2 | 651 | Note that unlike the metacharacters \fB(\fP and \fB)\fP, \fB{\fP and |
f73dda09 JA |
652 | \fB}\fP are \fIreserved words\fP and must occur where a reserved |
653 | word is permitted to be recognized. Since they do not cause a word | |
641d8f00 CR |
654 | break, they must be separated from \fIlist\fP by whitespace or another |
655 | shell metacharacter. | |
726f6388 | 656 | .TP |
ccc6cda3 JA |
657 | ((\fIexpression\fP)) |
658 | The \fIexpression\fP is evaluated according to the rules described | |
659 | below under | |
660 | .SM | |
661 | .BR "ARITHMETIC EVALUATION" . | |
662 | If the value of the expression is non-zero, the return status is 0; | |
663 | otherwise the return status is 1. This is exactly equivalent to | |
664 | \fBlet "\fIexpression\fP"\fR. | |
665 | .TP | |
cce855bc JA |
666 | \fB[[\fP \fIexpression\fP \fB]]\fP |
667 | Return a status of 0 or 1 depending on the evaluation of | |
668 | the conditional expression \fIexpression\fP. | |
669 | Expressions are composed of the primaries described below under | |
670 | .SM | |
671 | .BR "CONDITIONAL EXPRESSIONS" . | |
672 | Word splitting and pathname expansion are not performed on the words | |
673 | between the \fB[[\fP and \fB]]\fP; tilde expansion, parameter and | |
674 | variable expansion, arithmetic expansion, command substitution, process | |
675 | substitution, and quote removal are performed. | |
d3a24ed2 CR |
676 | Conditional operators such as \fB\-f\fP must be unquoted to be recognized |
677 | as primaries. | |
cce855bc JA |
678 | .if t .sp 0.5 |
679 | .if n .sp 1 | |
680 | When the \fB==\fP and \fB!=\fP operators are used, the string to the | |
681 | right of the operator is considered a pattern and matched according | |
682 | to the rules described below under \fBPattern Matching\fP. | |
2206f89a CR |
683 | If the shell option |
684 | .B nocasematch | |
685 | is enabled, the match is performed without regard to the case | |
686 | of alphabetic characters. | |
dc8fbaf9 CR |
687 | The return value is 0 if the string matches (\fB==\fP) or does not match |
688 | (\fB!=\fP) the pattern, and 1 otherwise. | |
cce855bc JA |
689 | Any part of the pattern may be quoted to force it to be matched as a |
690 | string. | |
691 | .if t .sp 0.5 | |
692 | .if n .sp 1 | |
d3a24ed2 CR |
693 | An additional binary operator, \fB=~\fP, is available, with the same |
694 | precedence as \fB==\fP and \fB!=\fP. | |
695 | When it is used, the string to the right of the operator is considered | |
696 | an extended regular expression and matched accordingly (as in \fIregex\fP(3)). | |
d7f49990 CR |
697 | The return value is 0 if the string matches |
698 | the pattern, and 1 otherwise. | |
d3a24ed2 CR |
699 | If the regular expression is syntactically incorrect, the conditional |
700 | expression's return value is 2. | |
701 | If the shell option | |
2206f89a | 702 | .B nocasematch |
d3a24ed2 CR |
703 | is enabled, the match is performed without regard to the case |
704 | of alphabetic characters. | |
3745eee9 CR |
705 | Any part of the pattern may be quoted to force it to be matched as a |
706 | string. | |
d3a24ed2 CR |
707 | Substrings matched by parenthesized subexpressions within the regular |
708 | expression are saved in the array variable \fBBASH_REMATCH\fP. | |
709 | The element of \fBBASH_REMATCH\fP with index 0 is the portion of the string | |
710 | matching the entire regular expression. | |
711 | The element of \fBBASH_REMATCH\fP with index \fIn\fP is the portion of the | |
712 | string matching the \fIn\fPth parenthesized subexpression. | |
713 | .if t .sp 0.5 | |
714 | .if n .sp 1 | |
cce855bc JA |
715 | Expressions may be combined using the following operators, listed |
716 | in decreasing order of precedence: | |
717 | .if t .sp 0.5 | |
718 | .if n .sp 1 | |
719 | .RS | |
720 | .PD 0 | |
721 | .TP | |
722 | .B ( \fIexpression\fP ) | |
723 | Returns the value of \fIexpression\fP. | |
724 | This may be used to override the normal precedence of operators. | |
725 | .TP | |
726 | .B ! \fIexpression\fP | |
727 | True if | |
728 | .I expression | |
729 | is false. | |
730 | .TP | |
731 | \fIexpression1\fP \fB&&\fP \fIexpression2\fP | |
732 | True if both | |
733 | .I expression1 | |
734 | and | |
735 | .I expression2 | |
736 | are true. | |
737 | .TP | |
738 | .if t \fIexpression1\fP \fB\(bv\(bv\fP \fIexpression2\fP | |
739 | .if n \fIexpression1\fP \fB||\fP \fIexpression2\fP | |
740 | True if either | |
741 | .I expression1 | |
742 | or | |
743 | .I expression2 | |
744 | is true. | |
745 | .PD | |
cce855bc JA |
746 | .LP |
747 | The \fB&&\fP and | |
748 | .if t \fB\(bv\(bv\fP | |
749 | .if n \fB||\fP | |
7117c2d2 | 750 | operators do not evaluate \fIexpression2\fP if the value of |
cce855bc JA |
751 | \fIexpression1\fP is sufficient to determine the return value of |
752 | the entire conditional expression. | |
f73dda09 | 753 | .RE |
cce855bc | 754 | .TP |
0d8616ff | 755 | \fBfor\fP \fIname\fP [ [ \fBin\fP [ \fIword ...\fP ] ] ; ] \fBdo\fP \fIlist\fP ; \fBdone\fP |
726f6388 | 756 | The list of words following \fBin\fP is expanded, generating a list |
bb70624e JA |
757 | of items. |
758 | The variable \fIname\fP is set to each element of this list | |
759 | in turn, and \fIlist\fP is executed each time. | |
760 | If the \fBin\fP \fIword\fP is omitted, the \fBfor\fP command executes | |
761 | \fIlist\fP once for each positional parameter that is set (see | |
726f6388 JA |
762 | .SM |
763 | .B PARAMETERS | |
764 | below). | |
cce855bc JA |
765 | The return status is the exit status of the last command that executes. |
766 | If the expansion of the items following \fBin\fP results in an empty | |
767 | list, no commands are executed, and the return status is 0. | |
726f6388 | 768 | .TP |
bb70624e JA |
769 | \fBfor\fP (( \fIexpr1\fP ; \fIexpr2\fP ; \fIexpr3\fP )) ; \fBdo\fP \fIlist\fP ; \fBdone\fP |
770 | First, the arithmetic expression \fIexpr1\fP is evaluated according | |
771 | to the rules described below under | |
772 | .SM | |
773 | .BR "ARITHMETIC EVALUATION" . | |
774 | The arithmetic expression \fIexpr2\fP is then evaluated repeatedly | |
775 | until it evaluates to zero. | |
776 | Each time \fIexpr2\fP evaluates to a non-zero value, \fIlist\fP is | |
777 | executed and the arithmetic expression \fIexpr3\fP is evaluated. | |
778 | If any expression is omitted, it behaves as if it evaluates to 1. | |
779 | The return value is the exit status of the last command in \fIlist\fP | |
780 | that is executed, or false if any of the expressions is invalid. | |
781 | .TP | |
b72432fd | 782 | \fBselect\fP \fIname\fP [ \fBin\fP \fIword\fP ] ; \fBdo\fP \fIlist\fP ; \fBdone\fP |
726f6388 JA |
783 | The list of words following \fBin\fP is expanded, generating a list |
784 | of items. The set of expanded words is printed on the standard | |
785 | error, each preceded by a number. If the \fBin\fP | |
786 | \fIword\fP is omitted, the positional parameters are printed (see | |
787 | .SM | |
788 | .B PARAMETERS | |
789 | below). The | |
790 | .B PS3 | |
791 | prompt is then displayed and a line read from the standard input. | |
ccc6cda3 | 792 | If the line consists of a number corresponding to one of |
726f6388 JA |
793 | the displayed words, then the value of |
794 | .I name | |
795 | is set to that word. If the line is empty, the words and prompt | |
796 | are displayed again. If EOF is read, the command completes. Any | |
797 | other value read causes | |
798 | .I name | |
799 | to be set to null. The line read is saved in the variable | |
800 | .BR REPLY . | |
801 | The | |
802 | .I list | |
803 | is executed after each selection until a | |
804 | .B break | |
726f6388 JA |
805 | command is executed. |
806 | The exit status of | |
807 | .B select | |
808 | is the exit status of the last command executed in | |
809 | .IR list , | |
810 | or zero if no commands were executed. | |
811 | .TP | |
bb70624e | 812 | \fBcase\fP \fIword\fP \fBin\fP [ [(] \fIpattern\fP [ \fB|\fP \fIpattern\fP ] \ |
726f6388 JA |
813 | ... ) \fIlist\fP ;; ] ... \fBesac\fP |
814 | A \fBcase\fP command first expands \fIword\fP, and tries to match | |
815 | it against each \fIpattern\fP in turn, using the same matching rules | |
816 | as for pathname expansion (see | |
817 | .B Pathname Expansion | |
2206f89a | 818 | below). |
dc8fbaf9 | 819 | The \fIword\fP is expanded using tilde |
d3ad40de | 820 | expansion, parameter and variable expansion, arithmetic substitution, |
dc8fbaf9 CR |
821 | command substitution, process substitution and quote removal. |
822 | Each \fIpattern\fP examined is expanded using tilde | |
d3ad40de | 823 | expansion, parameter and variable expansion, arithmetic substitution, |
dc8fbaf9 | 824 | command substitution, and process substitution. |
2206f89a CR |
825 | If the shell option |
826 | .B nocasematch | |
827 | is enabled, the match is performed without regard to the case | |
828 | of alphabetic characters. | |
8943768b CR |
829 | When a match is found, the corresponding \fIlist\fP is executed. |
830 | If the \fB;;\fP operator is used, no subsequent matches are attempted after | |
831 | the first pattern match. | |
832 | Using \fB;&\fP in place of \fB;;\fP causes execution to continue with | |
833 | the \fIlist\fP associated with the next set of patterns. | |
834 | Using \fB;;&\fP in place of \fB;;\fP causes the shell to test the next | |
835 | pattern list in the statement, if any, and execute any associated \fIlist\fP | |
836 | on a successful match. | |
837 | The exit status is zero if no | |
ccc6cda3 | 838 | pattern matches. Otherwise, it is the exit status of the |
726f6388 JA |
839 | last command executed in \fIlist\fP. |
840 | .TP | |
ccc6cda3 JA |
841 | \fBif\fP \fIlist\fP; \fBthen\fP \fIlist;\fP \ |
842 | [ \fBelif\fP \fIlist\fP; \fBthen\fP \fIlist\fP; ] ... \ | |
843 | [ \fBelse\fP \fIlist\fP; ] \fBfi\fP | |
726f6388 JA |
844 | The |
845 | .B if | |
846 | .I list | |
847 | is executed. If its exit status is zero, the | |
848 | \fBthen\fP \fIlist\fP is executed. Otherwise, each \fBelif\fP | |
849 | \fIlist\fP is executed in turn, and if its exit status is zero, | |
850 | the corresponding \fBthen\fP \fIlist\fP is executed and the | |
851 | command completes. Otherwise, the \fBelse\fP \fIlist\fP is | |
852 | executed, if present. The exit status is the exit status of the | |
853 | last command executed, or zero if no condition tested true. | |
854 | .TP | |
ccc6cda3 | 855 | \fBwhile\fP \fIlist\fP; \fBdo\fP \fIlist\fP; \fBdone\fP |
7117c2d2 | 856 | .PD 0 |
726f6388 | 857 | .TP |
ccc6cda3 | 858 | \fBuntil\fP \fIlist\fP; \fBdo\fP \fIlist\fP; \fBdone\fP |
726f6388 JA |
859 | .PD |
860 | The \fBwhile\fP command continuously executes the \fBdo\fP | |
861 | \fIlist\fP as long as the last command in \fIlist\fP returns | |
862 | an exit status of zero. The \fBuntil\fP command is identical | |
863 | to the \fBwhile\fP command, except that the test is negated; | |
864 | the | |
865 | .B do | |
866 | .I list | |
867 | is executed as long as the last command in | |
868 | .I list | |
ccc6cda3 | 869 | returns a non-zero exit status. |
726f6388 JA |
870 | The exit status of the \fBwhile\fP and \fBuntil\fP commands |
871 | is the exit status | |
872 | of the last \fBdo\fP \fIlist\fP command executed, or zero if | |
873 | none was executed. | |
09767ff0 CR |
874 | .SS Coprocesses |
875 | .PP | |
876 | A \fIcoprocess\fP is a shell command preceded by the \fBcoproc\fP reserved | |
877 | word. | |
878 | A coprocess is executed asynchronously in a subshell, as if the command | |
879 | had been terminated with the \fB&\fP control operator, with a two-way pipe | |
880 | established between the executing shell and the coprocess. | |
881 | .PP | |
882 | The format for a coprocess is: | |
883 | .RS | |
884 | .PP | |
885 | \fBcoproc\fP [\fINAME\fP] \fIcommand\fP [\fIredirections\fP] | |
886 | .RE | |
887 | .PP | |
888 | This creates a coprocess named \fINAME\fP. | |
889 | If \fINAME\fP is not supplied, the default name is \fICOPROC\fP. | |
e141c35a CR |
890 | \fINAME\fP must not be supplied if \fIcommand\fP is a \fIsimple |
891 | command\fP (see above); otherwise, it is interpreted as the first word | |
892 | of the simple command. | |
09767ff0 CR |
893 | When the coproc is executed, the shell creates an array variable (see |
894 | .B Arrays | |
895 | below) named \fINAME\fP in the context of the executing shell. | |
896 | The standard output of | |
897 | .I command | |
898 | is connected via a pipe to a file descriptor in the executing shell, | |
899 | and that file descriptor is assigned to \fINAME\fP[0]. | |
900 | The standard input of | |
901 | .I command | |
902 | is connected via a pipe to a file descriptor in the executing shell, | |
903 | and that file descriptor is assigned to \fINAME\fP[1]. | |
904 | This pipe is established before any redirections specified by the | |
905 | command (see | |
906 | .SM | |
907 | .B REDIRECTION | |
908 | below). | |
909 | The file descriptors can be utilized as arguments to shell commands | |
910 | and redirections using standard word expansions. | |
30915f17 CR |
911 | The process id of the shell spawned to execute the coprocess is |
912 | available as the value of the variable \fINAME\fP_PID. | |
913 | The \fBwait\fP | |
914 | builtin command may be used to wait for the coprocess to terminate. | |
09767ff0 CR |
915 | .PP |
916 | The return status of a coprocess is the exit status of \fIcommand\fP. | |
d3a24ed2 CR |
917 | .SS Shell Function Definitions |
918 | .PP | |
919 | A shell function is an object that is called like a simple command and | |
920 | executes a compound command with a new set of positional parameters. | |
921 | Shell functions are declared as follows: | |
922 | .TP | |
923 | [ \fBfunction\fP ] \fIname\fP () \fIcompound\-command\fP [\fIredirection\fP] | |
924 | This defines a function named \fIname\fP. | |
925 | The reserved word \fBfunction\fP is optional. | |
926 | If the \fBfunction\fP reserved word is supplied, the parentheses are optional. | |
927 | The \fIbody\fP of the function is the compound command | |
928 | .I compound\-command | |
929 | (see \fBCompound Commands\fP above). | |
930 | That command is usually a \fIlist\fP of commands between { and }, but | |
931 | may be any command listed under \fBCompound Commands\fP above. | |
932 | \fIcompound\-command\fP is executed whenever \fIname\fP is specified as the | |
933 | name of a simple command. | |
934 | Any redirections (see | |
935 | .SM | |
936 | .B REDIRECTION | |
937 | below) specified when a function is defined are performed | |
938 | when the function is executed. | |
939 | The exit status of a function definition is zero unless a syntax error | |
940 | occurs or a readonly function with the same name already exists. | |
941 | When executed, the exit status of a function is the exit status of the | |
942 | last command executed in the body. (See | |
726f6388 JA |
943 | .SM |
944 | .B FUNCTIONS | |
945 | below.) | |
946 | .SH COMMENTS | |
ccc6cda3 JA |
947 | In a non-interactive shell, or an interactive shell in which the |
948 | .B interactive_comments | |
949 | option to the | |
950 | .B shopt | |
951 | builtin is enabled (see | |
952 | .SM | |
953 | .B "SHELL BUILTIN COMMANDS" | |
954 | below), a word beginning with | |
726f6388 JA |
955 | .B # |
956 | causes that word and all remaining characters on that line to | |
957 | be ignored. An interactive shell without the | |
ccc6cda3 | 958 | .B interactive_comments |
ccc6cda3 JA |
959 | option enabled does not allow comments. The |
960 | .B interactive_comments | |
961 | option is on by default in interactive shells. | |
726f6388 JA |
962 | .SH QUOTING |
963 | \fIQuoting\fP is used to remove the special meaning of certain | |
964 | characters or words to the shell. Quoting can be used to | |
965 | disable special treatment for special characters, to prevent | |
966 | reserved words from being recognized as such, and to prevent | |
967 | parameter expansion. | |
968 | .PP | |
969 | Each of the \fImetacharacters\fP listed above under | |
970 | .SM | |
971 | .B DEFINITIONS | |
bb70624e JA |
972 | has special meaning to the shell and must be quoted if it is to |
973 | represent itself. | |
974 | .PP | |
5c96a638 CR |
975 | When the command history expansion facilities are being used |
976 | (see | |
977 | .SM | |
978 | .B HISTORY EXPANSION | |
979 | below), the | |
bb70624e JA |
980 | \fIhistory expansion\fP character, usually \fB!\fP, must be quoted |
981 | to prevent history expansion. | |
982 | .PP | |
983 | There are three quoting mechanisms: the | |
726f6388 JA |
984 | .IR "escape character" , |
985 | single quotes, and double quotes. | |
986 | .PP | |
987 | A non-quoted backslash (\fB\e\fP) is the | |
988 | .IR "escape character" . | |
989 | It preserves the literal value of the next character that follows, | |
990 | with the exception of <newline>. If a \fB\e\fP<newline> pair | |
cce855bc JA |
991 | appears, and the backslash is not itself quoted, the \fB\e\fP<newline> |
992 | is treated as a line continuation (that is, it is removed from the | |
993 | input stream and effectively ignored). | |
726f6388 JA |
994 | .PP |
995 | Enclosing characters in single quotes preserves the literal value | |
996 | of each character within the quotes. A single quote may not occur | |
997 | between single quotes, even when preceded by a backslash. | |
998 | .PP | |
999 | Enclosing characters in double quotes preserves the literal value | |
1000 | of all characters within the quotes, with the exception of | |
1001 | .BR $ , | |
3d4e09aa | 1002 | .BR \` , |
5c96a638 CR |
1003 | .BR \e , |
1004 | and, when history expansion is enabled, | |
1005 | .BR ! . | |
726f6388 JA |
1006 | The characters |
1007 | .B $ | |
1008 | and | |
3d4e09aa | 1009 | .B \` |
726f6388 JA |
1010 | retain their special meaning within double quotes. The backslash |
1011 | retains its special meaning only when followed by one of the following | |
1012 | characters: | |
1013 | .BR $ , | |
3d4e09aa | 1014 | .BR \` , |
726f6388 JA |
1015 | \^\fB"\fP\^, |
1016 | .BR \e , | |
1017 | or | |
1018 | .BR <newline> . | |
1019 | A double quote may be quoted within double quotes by preceding it with | |
1020 | a backslash. | |
5c96a638 CR |
1021 | If enabled, history expansion will be performed unless an |
1022 | .B ! | |
1023 | appearing in double quotes is escaped using a backslash. | |
1024 | The backslash preceding the | |
1025 | .B ! | |
1026 | is not removed. | |
726f6388 JA |
1027 | .PP |
1028 | The special parameters | |
1029 | .B * | |
1030 | and | |
1031 | .B @ | |
1032 | have special meaning when in double | |
1033 | quotes (see | |
1034 | .SM | |
1035 | .B PARAMETERS | |
1036 | below). | |
ccc6cda3 | 1037 | .PP |
20587658 | 1038 | Words of the form \fB$\fP\(aq\fIstring\fP\(aq are treated specially. The |
ccc6cda3 | 1039 | word expands to \fIstring\fP, with backslash-escaped characters replaced |
f75912ae | 1040 | as specified by the ANSI C standard. Backslash escape sequences, if |
ccc6cda3 JA |
1041 | present, are decoded as follows: |
1042 | .RS | |
1043 | .PD 0 | |
1044 | .TP | |
1045 | .B \ea | |
1046 | alert (bell) | |
1047 | .TP | |
1048 | .B \eb | |
1049 | backspace | |
1050 | .TP | |
1051 | .B \ee | |
1052 | an escape character | |
1053 | .TP | |
1054 | .B \ef | |
1055 | form feed | |
1056 | .TP | |
1057 | .B \en | |
1058 | new line | |
1059 | .TP | |
1060 | .B \er | |
1061 | carriage return | |
1062 | .TP | |
1063 | .B \et | |
1064 | horizontal tab | |
1065 | .TP | |
1066 | .B \ev | |
1067 | vertical tab | |
1068 | .TP | |
1069 | .B \e\e | |
1070 | backslash | |
bb70624e | 1071 | .TP |
20587658 | 1072 | .B \e\(aq |
bb70624e | 1073 | single quote |
ccc6cda3 JA |
1074 | .TP |
1075 | .B \e\fInnn\fP | |
f73dda09 | 1076 | the eight-bit character whose value is the octal value \fInnn\fP |
cce855bc JA |
1077 | (one to three digits) |
1078 | .TP | |
f73dda09 JA |
1079 | .B \ex\fIHH\fP |
1080 | the eight-bit character whose value is the hexadecimal value \fIHH\fP | |
1081 | (one or two hex digits) | |
7117c2d2 JA |
1082 | .TP |
1083 | .B \ec\fIx\fP | |
1084 | a control-\fIx\fP character | |
ccc6cda3 JA |
1085 | .PD |
1086 | .RE | |
1087 | .LP | |
bb70624e | 1088 | The expanded result is single-quoted, as if the dollar sign had |
ccc6cda3 JA |
1089 | not been present. |
1090 | .PP | |
1091 | A double-quoted string preceded by a dollar sign (\fB$\fP) will cause | |
1092 | the string to be translated according to the current locale. | |
1093 | If the current locale is \fBC\fP or \fBPOSIX\fP, the dollar sign | |
1094 | is ignored. | |
1095 | If the string is translated and replaced, the replacement is | |
1096 | double-quoted. | |
726f6388 JA |
1097 | .SH PARAMETERS |
1098 | A | |
1099 | .I parameter | |
ccc6cda3 JA |
1100 | is an entity that stores values. |
1101 | It can be a | |
726f6388 JA |
1102 | .IR name , |
1103 | a number, or one of the special characters listed below under | |
1104 | .BR "Special Parameters" . | |
d3a24ed2 | 1105 | A |
726f6388 JA |
1106 | .I variable |
1107 | is a parameter denoted by a | |
1108 | .IR name . | |
f73dda09 JA |
1109 | A variable has a \fIvalue\fP and zero or more \fIattributes\fP. |
1110 | Attributes are assigned using the | |
1111 | .B declare | |
1112 | builtin command (see | |
1113 | .B declare | |
1114 | below in | |
1115 | .SM | |
1116 | .BR "SHELL BUILTIN COMMANDS" ). | |
726f6388 JA |
1117 | .PP |
1118 | A parameter is set if it has been assigned a value. The null string is | |
1119 | a valid value. Once a variable is set, it may be unset only by using | |
1120 | the | |
1121 | .B unset | |
1122 | builtin command (see | |
1123 | .SM | |
1124 | .B SHELL BUILTIN COMMANDS | |
1125 | below). | |
1126 | .PP | |
1127 | A | |
1128 | .I variable | |
1129 | may be assigned to by a statement of the form | |
1130 | .RS | |
1131 | .PP | |
1132 | \fIname\fP=[\fIvalue\fP] | |
1133 | .RE | |
1134 | .PP | |
1135 | If | |
1136 | .I value | |
1137 | is not given, the variable is assigned the null string. All | |
1138 | .I values | |
bb70624e JA |
1139 | undergo tilde expansion, parameter and variable expansion, |
1140 | command substitution, arithmetic expansion, and quote | |
ccc6cda3 JA |
1141 | removal (see |
1142 | .SM | |
1143 | .B EXPANSION | |
1144 | below). If the variable has its | |
cce855bc | 1145 | .B integer |
f73dda09 | 1146 | attribute set, then |
726f6388 | 1147 | .I value |
d3a24ed2 | 1148 | is evaluated as an arithmetic expression even if the $((...)) expansion is |
cce855bc | 1149 | not used (see |
ccc6cda3 JA |
1150 | .B "Arithmetic Expansion" |
1151 | below). | |
1152 | Word splitting is not performed, with the exception | |
726f6388 JA |
1153 | of \fB"$@"\fP as explained below under |
1154 | .BR "Special Parameters" . | |
1155 | Pathname expansion is not performed. | |
f73dda09 | 1156 | Assignment statements may also appear as arguments to the |
5e13499c | 1157 | .BR alias , |
f73dda09 JA |
1158 | .BR declare , |
1159 | .BR typeset , | |
1160 | .BR export , | |
1161 | .BR readonly , | |
1162 | and | |
1163 | .B local | |
1164 | builtin commands. | |
d11b8b46 CR |
1165 | .PP |
1166 | In the context where an assignment statement is assigning a value | |
1167 | to a shell variable or array index, the += operator can be used to | |
1168 | append to or add to the variable's previous value. | |
1169 | When += is applied to a variable for which the integer attribute has been | |
1170 | set, \fIvalue\fP is evaluated as an arithmetic expression and added to the | |
1171 | variable's current value, which is also evaluated. | |
1172 | When += is applied to an array variable using compound assignment (see | |
1173 | .B Arrays | |
1174 | below), the | |
1175 | variable's value is not unset (as it is when using =), and new values are | |
fdf670ea CR |
1176 | appended to the array beginning at one greater than the array's maximum index |
1177 | (for indexed arrays) or added as additional key\-value pairs in an | |
1178 | associative array. | |
d11b8b46 CR |
1179 | When applied to a string-valued variable, \fIvalue\fP is expanded and |
1180 | appended to the variable's value. | |
726f6388 JA |
1181 | .SS Positional Parameters |
1182 | .PP | |
1183 | A | |
1184 | .I positional parameter | |
1185 | is a parameter denoted by one or more | |
1186 | digits, other than the single digit 0. Positional parameters are | |
1187 | assigned from the shell's arguments when it is invoked, | |
1188 | and may be reassigned using the | |
1189 | .B set | |
1190 | builtin command. Positional parameters may not be assigned to | |
1191 | with assignment statements. The positional parameters are | |
1192 | temporarily replaced when a shell function is executed (see | |
1193 | .SM | |
1194 | .B FUNCTIONS | |
1195 | below). | |
1196 | .PP | |
1197 | When a positional parameter consisting of more than a single | |
1198 | digit is expanded, it must be enclosed in braces (see | |
1199 | .SM | |
1200 | .B EXPANSION | |
1201 | below). | |
1202 | .SS Special Parameters | |
1203 | .PP | |
1204 | The shell treats several parameters specially. These parameters may | |
1205 | only be referenced; assignment to them is not allowed. | |
1206 | .PD 0 | |
1207 | .TP | |
1208 | .B * | |
1209 | Expands to the positional parameters, starting from one. When the | |
1210 | expansion occurs within double quotes, it expands to a single word | |
1211 | with the value of each parameter separated by the first character | |
1212 | of the | |
1213 | .SM | |
1214 | .B IFS | |
cce855bc JA |
1215 | special variable. That is, "\fB$*\fP" is equivalent |
1216 | to "\fB$1\fP\fIc\fP\fB$2\fP\fIc\fP\fB...\fP", where | |
726f6388 JA |
1217 | .I c |
1218 | is the first character of the value of the | |
1219 | .SM | |
1220 | .B IFS | |
1221 | variable. If | |
1222 | .SM | |
1223 | .B IFS | |
d166f048 JA |
1224 | is unset, the parameters are separated by spaces. |
1225 | If | |
1226 | .SM | |
1227 | .B IFS | |
1228 | is null, the parameters are joined without intervening separators. | |
726f6388 JA |
1229 | .TP |
1230 | .B @ | |
1231 | Expands to the positional parameters, starting from one. When the | |
cce855bc JA |
1232 | expansion occurs within double quotes, each parameter expands to a |
1233 | separate word. That is, "\fB$@\fP" is equivalent to | |
1234 | "\fB$1\fP" "\fB$2\fP" ... | |
be7d8f2d CR |
1235 | If the double-quoted expansion occurs within a word, the expansion of |
1236 | the first parameter is joined with the beginning part of the original | |
1237 | word, and the expansion of the last parameter is joined with the last | |
1238 | part of the original word. | |
cce855bc | 1239 | When there are no positional parameters, "\fB$@\fP" and |
726f6388 JA |
1240 | .B $@ |
1241 | expand to nothing (i.e., they are removed). | |
1242 | .TP | |
1243 | .B # | |
1244 | Expands to the number of positional parameters in decimal. | |
1245 | .TP | |
1246 | .B ? | |
e882163b | 1247 | Expands to the exit status of the most recently executed foreground |
726f6388 JA |
1248 | pipeline. |
1249 | .TP | |
1250 | .B \- | |
1251 | Expands to the current option flags as specified upon invocation, | |
1252 | by the | |
1253 | .B set | |
1254 | builtin command, or those set by the shell itself | |
1255 | (such as the | |
1256 | .B \-i | |
cce855bc | 1257 | option). |
726f6388 JA |
1258 | .TP |
1259 | .B $ | |
1260 | Expands to the process ID of the shell. In a () subshell, it | |
1261 | expands to the process ID of the current shell, not the | |
1262 | subshell. | |
1263 | .TP | |
1264 | .B ! | |
1265 | Expands to the process ID of the most recently executed background | |
1266 | (asynchronous) command. | |
1267 | .TP | |
1268 | .B 0 | |
1269 | Expands to the name of the shell or shell script. This is set at | |
1270 | shell initialization. If | |
1271 | .B bash | |
1272 | is invoked with a file of commands, | |
1273 | .B $0 | |
1274 | is set to the name of that file. If | |
1275 | .B bash | |
1276 | is started with the | |
1277 | .B \-c | |
1278 | option, then | |
1279 | .B $0 | |
1280 | is set to the first argument after the string to be | |
1281 | executed, if one is present. Otherwise, it is set | |
ccc6cda3 | 1282 | to the file name used to invoke |
726f6388 JA |
1283 | .BR bash , |
1284 | as given by argument zero. | |
1285 | .TP | |
1286 | .B _ | |
cc87ba64 CR |
1287 | At shell startup, set to the absolute pathname used to invoke the |
1288 | shell or shell script being executed as passed in the environment | |
1289 | or argument list. | |
ccc6cda3 JA |
1290 | Subsequently, expands to the last argument to the previous command, |
1291 | after expansion. | |
cc87ba64 CR |
1292 | Also set to the full pathname used to invoke each command executed |
1293 | and placed in the environment exported to that command. | |
ccc6cda3 JA |
1294 | When checking mail, this parameter holds the name of the mail file |
1295 | currently being checked. | |
726f6388 JA |
1296 | .PD |
1297 | .SS Shell Variables | |
1298 | .PP | |
1299 | The following variables are set by the shell: | |
1300 | .PP | |
1301 | .PD 0 | |
1302 | .TP | |
726f6388 | 1303 | .B BASH |
ccc6cda3 | 1304 | Expands to the full file name used to invoke this instance of |
726f6388 JA |
1305 | .BR bash . |
1306 | .TP | |
d3ad40de | 1307 | .B BASHPID |
29d25b54 | 1308 | Expands to the process id of the current \fBbash\fP process. |
d3ad40de | 1309 | This differs from \fB$$\fP under certain circumstances, such as subshells |
29d25b54 | 1310 | that do not require \fBbash\fP to be re-initialized. |
d3ad40de | 1311 | .TP |
fdf670ea CR |
1312 | .B BASH_ALIASES |
1313 | An associative array variable whose members correspond to the internal | |
1314 | list of aliases as maintained by the \fBalias\fP builtin | |
1315 | Elements added to this array appear in the alias list; unsetting array | |
1316 | elements cause aliases to be removed from the alias list. | |
1317 | .TP | |
d3a24ed2 CR |
1318 | .B BASH_ARGC |
1319 | An array variable whose values are the number of parameters in each | |
29d25b54 | 1320 | frame of the current \fBbash\fP execution call stack. |
2206f89a | 1321 | The number of |
d3a24ed2 | 1322 | parameters to the current subroutine (shell function or script executed |
2206f89a CR |
1323 | with \fB.\fP or \fBsource\fP) is at the top of the stack. |
1324 | When a subroutine is executed, the number of parameters passed is pushed onto | |
d3a24ed2 | 1325 | \fBBASH_ARGC\fP. |
2206f89a CR |
1326 | The shell sets \fBBASH_ARGC\fP only when in extended debugging mode |
1327 | (see the description of the | |
1328 | .B extdebug | |
1329 | option to the | |
1330 | .B shopt | |
1331 | builtin below) | |
d3a24ed2 CR |
1332 | .TP |
1333 | .B BASH_ARGV | |
29d25b54 | 1334 | An array variable containing all of the parameters in the current \fBbash\fP |
d3a24ed2 CR |
1335 | execution call stack. The final parameter of the last subroutine call |
1336 | is at the top of the stack; the first parameter of the initial call is | |
1337 | at the bottom. When a subroutine is executed, the parameters supplied | |
1338 | are pushed onto \fBBASH_ARGV\fP. | |
2206f89a CR |
1339 | The shell sets \fBBASH_ARGV\fP only when in extended debugging mode |
1340 | (see the description of the | |
1341 | .B extdebug | |
1342 | option to the | |
1343 | .B shopt | |
1344 | builtin below) | |
d3a24ed2 | 1345 | .TP |
fdf670ea CR |
1346 | .B BASH_CMDS |
1347 | An associative array variable whose members correspond to the internal | |
1348 | hash table of commands as maintained by the \fBhash\fP builtin. | |
1349 | Elements added to this array appear in the hash table; unsetting array | |
1350 | elements cause commands to be removed from the hash table. | |
1351 | .TP | |
d3a24ed2 CR |
1352 | .B BASH_COMMAND |
1353 | The command currently being executed or about to be executed, unless the | |
1354 | shell is executing a command as the result of a trap, | |
1355 | in which case it is the command executing at the time of the trap. | |
1356 | .TP | |
1357 | .B BASH_EXECUTION_STRING | |
1358 | The command argument to the \fB\-c\fP invocation option. | |
1359 | .TP | |
1360 | .B BASH_LINENO | |
1361 | An array variable whose members are the line numbers in source files | |
be7d8f2d | 1362 | corresponding to each member of \fBFUNCNAME\fP. |
d3a24ed2 | 1363 | \fB${BASH_LINENO[\fP\fI$i\fP\fB]}\fP is the line number in the source |
3d4e09aa CR |
1364 | file where \fB${FUNCNAME[\fP\fI$i\fP\fB]}\fP was called |
1365 | (or \fB${BASH_LINENO[\fP\fI$i-1\fP\fB]}\fP if referenced within another | |
1366 | shell function). | |
db31fb26 | 1367 | The corresponding source file name is \fB${BASH_SOURCE[\fP\fI$i\fP\fB]}\fP. |
d3a24ed2 CR |
1368 | Use \fBLINENO\fP to obtain the current line number. |
1369 | .TP | |
1370 | .B BASH_REMATCH | |
1371 | An array variable whose members are assigned by the \fB=~\fP binary | |
1372 | operator to the \fB[[\fP conditional command. | |
1373 | The element with index 0 is the portion of the string | |
1374 | matching the entire regular expression. | |
1375 | The element with index \fIn\fP is the portion of the | |
1376 | string matching the \fIn\fPth parenthesized subexpression. | |
1377 | This variable is read-only. | |
1378 | .TP | |
1379 | .B BASH_SOURCE | |
1380 | An array variable whose members are the source filenames corresponding | |
1381 | to the elements in the \fBFUNCNAME\fP array variable. | |
1382 | .TP | |
1383 | .B BASH_SUBSHELL | |
1384 | Incremented by one each time a subshell or subshell environment is spawned. | |
1385 | The initial value is 0. | |
1386 | .TP | |
ccc6cda3 | 1387 | .B BASH_VERSINFO |
cce855bc JA |
1388 | A readonly array variable whose members hold version information for |
1389 | this instance of | |
ccc6cda3 JA |
1390 | .BR bash . |
1391 | The values assigned to the array members are as follows: | |
1392 | .sp .5 | |
1393 | .RS | |
1394 | .PD 0 | |
1395 | .TP 24 | |
1396 | .B BASH_VERSINFO[\fR0\fP] | |
1397 | The major version number (the \fIrelease\fP). | |
1398 | .TP | |
1399 | .B BASH_VERSINFO[\fR1\fP] | |
1400 | The minor version number (the \fIversion\fP). | |
1401 | .TP | |
1402 | .B BASH_VERSINFO[\fR2\fP] | |
1403 | The patch level. | |
1404 | .TP | |
1405 | .B BASH_VERSINFO[\fR3\fP] | |
1406 | The build version. | |
1407 | .TP | |
1408 | .B BASH_VERSINFO[\fR4\fP] | |
1409 | The release status (e.g., \fIbeta1\fP). | |
1410 | .TP | |
1411 | .B BASH_VERSINFO[\fR5\fP] | |
1412 | The value of \fBMACHTYPE\fP. | |
1413 | .PD | |
1414 | .RE | |
1415 | .TP | |
f73dda09 JA |
1416 | .B BASH_VERSION |
1417 | Expands to a string describing the version of this instance of | |
1418 | .BR bash . | |
726f6388 | 1419 | .TP |
f73dda09 JA |
1420 | .B COMP_CWORD |
1421 | An index into \fB${COMP_WORDS}\fP of the word containing the current | |
1422 | cursor position. | |
1423 | This variable is available only in shell functions invoked by the | |
1424 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1425 | below). | |
1426 | .TP | |
d3ad40de CR |
1427 | .B COMP_KEY |
1428 | The key (or final key of a key sequence) used to invoke the current | |
1429 | completion function. | |
1430 | .TP | |
f73dda09 JA |
1431 | .B COMP_LINE |
1432 | The current command line. | |
1433 | This variable is available only in shell functions and external | |
1434 | commands invoked by the | |
1435 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1436 | below). | |
1437 | .TP | |
1438 | .B COMP_POINT | |
1439 | The index of the current cursor position relative to the beginning of | |
1440 | the current command. | |
1441 | If the current cursor position is at the end of the current command, | |
1442 | the value of this variable is equal to \fB${#COMP_LINE}\fP. | |
1443 | This variable is available only in shell functions and external | |
1444 | commands invoked by the | |
1445 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1446 | below). | |
1447 | .TP | |
d3ad40de CR |
1448 | .B COMP_TYPE |
1449 | Set to an integer value corresponding to the type of completion attempted | |
1450 | that caused a completion function to be called: | |
1451 | \fITAB\fP, for normal completion, | |
1452 | \fI?\fP, for listing completions after successive tabs, | |
1453 | \fI!\fP, for listing alternatives on partial word completion, | |
1454 | \fI@\fP, to list completions if the word is not unmodified, | |
1455 | or | |
1456 | \fI%\fP, for menu completion. | |
1457 | This variable is available only in shell functions and external | |
1458 | commands invoked by the | |
1459 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1460 | below). | |
1461 | .TP | |
d3a24ed2 | 1462 | .B COMP_WORDBREAKS |
db31fb26 | 1463 | The set of characters that the \fBreadline\fP library treats as word |
d3a24ed2 CR |
1464 | separators when performing word completion. |
1465 | If | |
1466 | .SM | |
1467 | .B COMP_WORDBREAKS | |
1468 | is unset, it loses its special properties, even if it is | |
1469 | subsequently reset. | |
1470 | .TP | |
f73dda09 JA |
1471 | .B COMP_WORDS |
1472 | An array variable (see \fBArrays\fP below) consisting of the individual | |
1473 | words in the current command line. | |
db31fb26 CR |
1474 | The line is split into words as \fBreadline\fP would split it, using |
1475 | \fBCOMP_WORDBREAKS\fP as described above. | |
f73dda09 JA |
1476 | This variable is available only in shell functions invoked by the |
1477 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1478 | below). | |
1479 | .TP | |
1480 | .B DIRSTACK | |
1481 | An array variable (see | |
1482 | .B Arrays | |
1483 | below) containing the current contents of the directory stack. | |
1484 | Directories appear in the stack in the order they are displayed by the | |
1485 | .B dirs | |
1486 | builtin. | |
1487 | Assigning to members of this array variable may be used to modify | |
1488 | directories already in the stack, but the | |
1489 | .B pushd | |
1490 | and | |
1491 | .B popd | |
1492 | builtins must be used to add and remove directories. | |
1493 | Assignment to this variable will not change the current directory. | |
726f6388 JA |
1494 | If |
1495 | .SM | |
f73dda09 | 1496 | .B DIRSTACK |
726f6388 JA |
1497 | is unset, it loses its special properties, even if it is |
1498 | subsequently reset. | |
1499 | .TP | |
f73dda09 JA |
1500 | .B EUID |
1501 | Expands to the effective user ID of the current user, initialized at | |
1502 | shell startup. This variable is readonly. | |
1503 | .TP | |
1504 | .B FUNCNAME | |
d3a24ed2 CR |
1505 | An array variable containing the names of all shell functions |
1506 | currently in the execution call stack. | |
1507 | The element with index 0 is the name of any currently-executing | |
1508 | shell function. | |
d3ad40de CR |
1509 | The bottom-most element is |
1510 | .if t \f(CW"main"\fP. | |
1511 | .if n "main". | |
f73dda09 JA |
1512 | This variable exists only when a shell function is executing. |
1513 | Assignments to | |
726f6388 | 1514 | .SM |
f73dda09 JA |
1515 | .B FUNCNAME |
1516 | have no effect and return an error status. | |
726f6388 JA |
1517 | If |
1518 | .SM | |
f73dda09 | 1519 | .B FUNCNAME |
726f6388 JA |
1520 | is unset, it loses its special properties, even if it is |
1521 | subsequently reset. | |
1522 | .TP | |
f73dda09 JA |
1523 | .B GROUPS |
1524 | An array variable containing the list of groups of which the current | |
1525 | user is a member. | |
1526 | Assignments to | |
1527 | .SM | |
1528 | .B GROUPS | |
1529 | have no effect and return an error status. | |
726f6388 JA |
1530 | If |
1531 | .SM | |
f73dda09 | 1532 | .B GROUPS |
726f6388 JA |
1533 | is unset, it loses its special properties, even if it is |
1534 | subsequently reset. | |
1535 | .TP | |
1536 | .B HISTCMD | |
1537 | The history number, or index in the history list, of the current | |
ccc6cda3 JA |
1538 | command. |
1539 | If | |
726f6388 JA |
1540 | .SM |
1541 | .B HISTCMD | |
1542 | is unset, it loses its special properties, even if it is | |
1543 | subsequently reset. | |
1544 | .TP | |
f73dda09 JA |
1545 | .B HOSTNAME |
1546 | Automatically set to the name of the current host. | |
bb70624e | 1547 | .TP |
f73dda09 JA |
1548 | .B HOSTTYPE |
1549 | Automatically set to a string that uniquely | |
1550 | describes the type of machine on which | |
1551 | .B bash | |
1552 | is executing. | |
1553 | The default is system-dependent. | |
1554 | .TP | |
1555 | .B LINENO | |
1556 | Each time this parameter is referenced, the shell substitutes | |
1557 | a decimal number representing the current sequential line number | |
1558 | (starting with 1) within a script or function. When not in a | |
1559 | script or function, the value substituted is not guaranteed to | |
1560 | be meaningful. | |
ccc6cda3 JA |
1561 | If |
1562 | .SM | |
f73dda09 | 1563 | .B LINENO |
ccc6cda3 JA |
1564 | is unset, it loses its special properties, even if it is |
1565 | subsequently reset. | |
1566 | .TP | |
f73dda09 JA |
1567 | .B MACHTYPE |
1568 | Automatically set to a string that fully describes the system | |
1569 | type on which | |
1570 | .B bash | |
1571 | is executing, in the standard GNU \fIcpu-company-system\fP format. | |
1572 | The default is system-dependent. | |
1573 | .TP | |
1574 | .B OLDPWD | |
1575 | The previous working directory as set by the | |
1576 | .B cd | |
1577 | command. | |
ccc6cda3 | 1578 | .TP |
726f6388 JA |
1579 | .B OPTARG |
1580 | The value of the last option argument processed by the | |
1581 | .B getopts | |
1582 | builtin command (see | |
1583 | .SM | |
1584 | .B SHELL BUILTIN COMMANDS | |
1585 | below). | |
1586 | .TP | |
1587 | .B OPTIND | |
1588 | The index of the next argument to be processed by the | |
1589 | .B getopts | |
1590 | builtin command (see | |
1591 | .SM | |
1592 | .B SHELL BUILTIN COMMANDS | |
1593 | below). | |
1594 | .TP | |
726f6388 JA |
1595 | .B OSTYPE |
1596 | Automatically set to a string that | |
1597 | describes the operating system on which | |
1598 | .B bash | |
ccc6cda3 JA |
1599 | is executing. |
1600 | The default is system-dependent. | |
1601 | .TP | |
f73dda09 JA |
1602 | .B PIPESTATUS |
1603 | An array variable (see | |
1604 | .B Arrays | |
1605 | below) containing a list of exit status values from the processes | |
1606 | in the most-recently-executed foreground pipeline (which may | |
1607 | contain only a single command). | |
ccc6cda3 | 1608 | .TP |
f73dda09 JA |
1609 | .B PPID |
1610 | The process ID of the shell's parent. This variable is readonly. | |
1611 | .TP | |
1612 | .B PWD | |
1613 | The current working directory as set by the | |
1614 | .B cd | |
1615 | command. | |
1616 | .TP | |
1617 | .B RANDOM | |
1618 | Each time this parameter is referenced, a random integer between | |
1619 | 0 and 32767 is | |
1620 | generated. The sequence of random numbers may be initialized by assigning | |
1621 | a value to | |
1622 | .SM | |
1623 | .BR RANDOM . | |
1624 | If | |
1625 | .SM | |
1626 | .B RANDOM | |
1627 | is unset, it loses its special properties, even if it is | |
1628 | subsequently reset. | |
1629 | .TP | |
1630 | .B REPLY | |
1631 | Set to the line of input read by the | |
1632 | .B read | |
1633 | builtin command when no arguments are supplied. | |
1634 | .TP | |
1635 | .B SECONDS | |
1636 | Each time this parameter is | |
1637 | referenced, the number of seconds since shell invocation is returned. If a | |
1638 | value is assigned to | |
1639 | .SM | |
1640 | .BR SECONDS , | |
1641 | the value returned upon subsequent | |
1642 | references is | |
1643 | the number of seconds since the assignment plus the value assigned. | |
1644 | If | |
1645 | .SM | |
1646 | .B SECONDS | |
1647 | is unset, it loses its special properties, even if it is | |
1648 | subsequently reset. | |
1649 | .TP | |
1650 | .B SHELLOPTS | |
1651 | A colon-separated list of enabled shell options. Each word in | |
1652 | the list is a valid argument for the | |
1653 | .B \-o | |
1654 | option to the | |
1655 | .B set | |
1656 | builtin command (see | |
1657 | .SM | |
1658 | .B "SHELL BUILTIN COMMANDS" | |
1659 | below). The options appearing in | |
ccc6cda3 JA |
1660 | .SM |
1661 | .B SHELLOPTS | |
1662 | are those reported as | |
1663 | .I on | |
1664 | by \fBset \-o\fP. | |
1665 | If this variable is in the environment when | |
1666 | .B bash | |
1667 | starts up, each shell option in the list will be enabled before | |
1668 | reading any startup files. | |
1669 | This variable is read-only. | |
bb70624e | 1670 | .TP |
f73dda09 JA |
1671 | .B SHLVL |
1672 | Incremented by one each time an instance of | |
1673 | .B bash | |
1674 | is started. | |
bb70624e | 1675 | .TP |
f73dda09 JA |
1676 | .B UID |
1677 | Expands to the user ID of the current user, initialized at shell startup. | |
1678 | This variable is readonly. | |
726f6388 JA |
1679 | .PD |
1680 | .PP | |
1681 | The following variables are used by the shell. In some cases, | |
1682 | .B bash | |
1683 | assigns a default value to a variable; these cases are noted | |
1684 | below. | |
1685 | .PP | |
1686 | .PD 0 | |
1687 | .TP | |
d166f048 | 1688 | .B BASH_ENV |
726f6388 JA |
1689 | If this parameter is set when \fBbash\fP is executing a shell script, |
1690 | its value is interpreted as a filename containing commands to | |
1691 | initialize the shell, as in | |
cce855bc | 1692 | .IR ~/.bashrc . |
726f6388 JA |
1693 | The value of |
1694 | .SM | |
d166f048 | 1695 | .B BASH_ENV |
726f6388 | 1696 | is subjected to parameter expansion, command substitution, and arithmetic |
ccc6cda3 | 1697 | expansion before being interpreted as a file name. |
726f6388 JA |
1698 | .SM |
1699 | .B PATH | |
ccc6cda3 | 1700 | is not used to search for the resultant file name. |
726f6388 | 1701 | .TP |
f73dda09 JA |
1702 | .B CDPATH |
1703 | The search path for the | |
1704 | .B cd | |
1705 | command. | |
1706 | This is a colon-separated list of directories in which the shell looks | |
1707 | for destination directories specified by the | |
1708 | .B cd | |
1709 | command. | |
7117c2d2 JA |
1710 | A sample value is |
1711 | .if t \f(CW".:~:/usr"\fP. | |
1712 | .if n ".:~:/usr". | |
726f6388 | 1713 | .TP |
f73dda09 JA |
1714 | .B COLUMNS |
1715 | Used by the \fBselect\fP builtin command to determine the terminal width | |
1716 | when printing selection lists. Automatically set upon receipt of a SIGWINCH. | |
726f6388 | 1717 | .TP |
f73dda09 JA |
1718 | .B COMPREPLY |
1719 | An array variable from which \fBbash\fP reads the possible completions | |
1720 | generated by a shell function invoked by the programmable completion | |
1721 | facility (see \fBProgrammable Completion\fP below). | |
726f6388 | 1722 | .TP |
d3a24ed2 CR |
1723 | .B EMACS |
1724 | If \fBbash\fP finds this variable in the environment when the shell starts | |
1725 | with value | |
1726 | .if t \f(CWt\fP, | |
1727 | .if n "t", | |
1728 | it assumes that the shell is running in an emacs shell buffer and disables | |
1729 | line editing. | |
1730 | .TP | |
f73dda09 JA |
1731 | .B FCEDIT |
1732 | The default editor for the | |
1733 | .B fc | |
1734 | builtin command. | |
726f6388 | 1735 | .TP |
f73dda09 JA |
1736 | .B FIGNORE |
1737 | A colon-separated list of suffixes to ignore when performing | |
1738 | filename completion (see | |
726f6388 | 1739 | .SM |
f73dda09 JA |
1740 | .B READLINE |
1741 | below). | |
1742 | A filename whose suffix matches one of the entries in | |
726f6388 | 1743 | .SM |
f73dda09 JA |
1744 | .B FIGNORE |
1745 | is excluded from the list of matched filenames. | |
7117c2d2 JA |
1746 | A sample value is |
1747 | .if t \f(CW".o:~"\fP. | |
1748 | .if n ".o:~". | |
ccc6cda3 | 1749 | .TP |
f73dda09 JA |
1750 | .B GLOBIGNORE |
1751 | A colon-separated list of patterns defining the set of filenames to | |
1752 | be ignored by pathname expansion. | |
1753 | If a filename matched by a pathname expansion pattern also matches one | |
1754 | of the patterns in | |
726f6388 | 1755 | .SM |
f73dda09 JA |
1756 | .BR GLOBIGNORE , |
1757 | it is removed from the list of matches. | |
1758 | .TP | |
1759 | .B HISTCONTROL | |
d3a24ed2 CR |
1760 | A colon-separated list of values controlling how commands are saved on |
1761 | the history list. | |
1762 | If the list of values includes | |
f73dda09 JA |
1763 | .IR ignorespace , |
1764 | lines which begin with a | |
1765 | .B space | |
d3a24ed2 CR |
1766 | character are not saved in the history list. |
1767 | A value of | |
1768 | .I ignoredups | |
1769 | causes lines matching the previous history entry to not be saved. | |
f73dda09 JA |
1770 | A value of |
1771 | .I ignoreboth | |
d3a24ed2 CR |
1772 | is shorthand for \fIignorespace\fP and \fIignoredups\fP. |
1773 | A value of | |
1774 | .IR erasedups | |
1775 | causes all previous lines matching the current line to be removed from | |
1776 | the history list before that line is saved. | |
1777 | Any value not in the above list is ignored. | |
1778 | If \fBHISTCONTROL\fP is unset, or does not include a valid value, | |
1779 | all lines read by the shell parser are saved on the history list, | |
1780 | subject to the value of | |
f73dda09 JA |
1781 | .BR HISTIGNORE . |
1782 | The second and subsequent lines of a multi-line compound command are | |
1783 | not tested, and are added to the history regardless of the value of | |
1784 | .BR HISTCONTROL . | |
726f6388 JA |
1785 | .TP |
1786 | .B HISTFILE | |
ccc6cda3 | 1787 | The name of the file in which command history is saved (see |
726f6388 JA |
1788 | .SM |
1789 | .B HISTORY | |
ccc6cda3 | 1790 | below). The default value is \fI~/.bash_history\fP. If unset, the |
726f6388 JA |
1791 | command history is not saved when an interactive shell exits. |
1792 | .TP | |
1793 | .B HISTFILESIZE | |
1794 | The maximum number of lines contained in the history file. When this | |
1795 | variable is assigned a value, the history file is truncated, if | |
d3ad40de CR |
1796 | necessary, by removing the oldest entries, |
1797 | to contain no more than that number of lines. The default | |
ccc6cda3 JA |
1798 | value is 500. The history file is also truncated to this size after |
1799 | writing it when an interactive shell exits. | |
726f6388 | 1800 | .TP |
f73dda09 JA |
1801 | .B HISTIGNORE |
1802 | A colon-separated list of patterns used to decide which command lines | |
1803 | should be saved on the history list. Each pattern is anchored at the | |
1804 | beginning of the line and must match the complete line (no implicit | |
1805 | `\fB*\fP' is appended). Each pattern is tested against the line | |
1806 | after the checks specified by | |
1807 | .B HISTCONTROL | |
1808 | are applied. | |
1809 | In addition to the normal shell pattern matching characters, `\fB&\fP' | |
1810 | matches the previous history line. `\fB&\fP' may be escaped using a | |
1811 | backslash; the backslash is removed before attempting a match. | |
1812 | The second and subsequent lines of a multi-line compound command are | |
1813 | not tested, and are added to the history regardless of the value of | |
1814 | .BR HISTIGNORE . | |
1815 | .TP | |
1816 | .B HISTSIZE | |
1817 | The number of commands to remember in the command history (see | |
1818 | .SM | |
1819 | .B HISTORY | |
1820 | below). The default value is 500. | |
1821 | .TP | |
d3a24ed2 CR |
1822 | .B HISTTIMEFORMAT |
1823 | If this variable is set and not null, its value is used as a format string | |
1824 | for \fIstrftime\fP(3) to print the time stamp associated with each history | |
1825 | entry displayed by the \fBhistory\fP builtin. | |
1826 | If this variable is set, time stamps are written to the history file so | |
1827 | they may be preserved across shell sessions. | |
d3ad40de CR |
1828 | This uses the history comment character to distinguish timestamps from |
1829 | other history lines. | |
d3a24ed2 | 1830 | .TP |
f73dda09 JA |
1831 | .B HOME |
1832 | The home directory of the current user; the default argument for the | |
1833 | \fBcd\fP builtin command. | |
1834 | The value of this variable is also used when performing tilde expansion. | |
1835 | .TP | |
1836 | .B HOSTFILE | |
1837 | Contains the name of a file in the same format as | |
1838 | .FN /etc/hosts | |
1839 | that should be read when the shell needs to complete a | |
1840 | hostname. | |
1841 | The list of possible hostname completions may be changed while the | |
1842 | shell is running; | |
1843 | the next time hostname completion is attempted after the | |
1844 | value is changed, | |
726f6388 | 1845 | .B bash |
f73dda09 JA |
1846 | adds the contents of the new file to the existing list. |
1847 | If | |
726f6388 | 1848 | .SM |
f73dda09 | 1849 | .B HOSTFILE |
9dd88db7 CR |
1850 | is set, but has no value, or does not name a readable file, |
1851 | \fBbash\fP attempts to read | |
f73dda09 JA |
1852 | .FN /etc/hosts |
1853 | to obtain the list of possible hostname completions. | |
1854 | When | |
726f6388 | 1855 | .SM |
f73dda09 JA |
1856 | .B HOSTFILE |
1857 | is unset, the hostname list is cleared. | |
1858 | .TP | |
1859 | .B IFS | |
1860 | The | |
1861 | .I Internal Field Separator | |
1862 | that is used | |
1863 | for word splitting after expansion and to | |
1864 | split lines into words with the | |
1865 | .B read | |
1866 | builtin command. The default value is | |
1867 | ``<space><tab><newline>''. | |
1868 | .TP | |
1869 | .B IGNOREEOF | |
1870 | Controls the | |
1871 | action of an interactive shell on receipt of an | |
1872 | .SM | |
1873 | .B EOF | |
1874 | character as the sole input. If set, the value is the number of | |
1875 | consecutive | |
1876 | .SM | |
1877 | .B EOF | |
1878 | characters which must be | |
1879 | typed as the first characters on an input line before | |
1880 | .B bash | |
1881 | exits. If the variable exists but does not have a numeric value, or | |
1882 | has no value, the default value is 10. If it does not exist, | |
1883 | .SM | |
1884 | .B EOF | |
1885 | signifies the end of input to the shell. | |
1886 | .TP | |
1887 | .B INPUTRC | |
1888 | The filename for the | |
1889 | .B readline | |
1890 | startup file, overriding the default of | |
1891 | .FN ~/.inputrc | |
1892 | (see | |
1893 | .SM | |
1894 | .B READLINE | |
1895 | below). | |
726f6388 | 1896 | .TP |
ccc6cda3 JA |
1897 | .B LANG |
1898 | Used to determine the locale category for any category not specifically | |
1899 | selected with a variable starting with \fBLC_\fP. | |
1900 | .TP | |
1901 | .B LC_ALL | |
1902 | This variable overrides the value of \fBLANG\fP and any other | |
1903 | \fBLC_\fP variable specifying a locale category. | |
1904 | .TP | |
1905 | .B LC_COLLATE | |
1906 | This variable determines the collation order used when sorting the | |
cce855bc JA |
1907 | results of pathname expansion, and determines the behavior of range |
1908 | expressions, equivalence classes, and collating sequences within | |
1909 | pathname expansion and pattern matching. | |
1910 | .TP | |
1911 | .B LC_CTYPE | |
1912 | This variable determines the interpretation of characters and the | |
1913 | behavior of character classes within pathname expansion and pattern | |
1914 | matching. | |
ccc6cda3 JA |
1915 | .TP |
1916 | .B LC_MESSAGES | |
1917 | This variable determines the locale used to translate double-quoted | |
1918 | strings preceded by a \fB$\fP. | |
1919 | .TP | |
bb70624e JA |
1920 | .B LC_NUMERIC |
1921 | This variable determines the locale category used for number formatting. | |
1922 | .TP | |
28ef6c31 JA |
1923 | .B LINES |
1924 | Used by the \fBselect\fP builtin command to determine the column length | |
1925 | for printing selection lists. Automatically set upon receipt of a SIGWINCH. | |
1926 | .TP | |
f73dda09 JA |
1927 | .B MAIL |
1928 | If this parameter is set to a file name and the | |
726f6388 | 1929 | .SM |
f73dda09 JA |
1930 | .B MAILPATH |
1931 | variable is not set, | |
726f6388 | 1932 | .B bash |
f73dda09 | 1933 | informs the user of the arrival of mail in the specified file. |
726f6388 | 1934 | .TP |
f73dda09 JA |
1935 | .B MAILCHECK |
1936 | Specifies how | |
1937 | often (in seconds) | |
1938 | .B bash | |
1939 | checks for mail. The default is 60 seconds. When it is time to check | |
1940 | for mail, the shell does so before displaying the primary prompt. | |
1941 | If this variable is unset, or set to a value that is not a number | |
1942 | greater than or equal to zero, the shell disables mail checking. | |
726f6388 | 1943 | .TP |
f73dda09 JA |
1944 | .B MAILPATH |
1945 | A colon-separated list of file names to be checked for mail. | |
1946 | The message to be printed when mail arrives in a particular file | |
1947 | may be specified by separating the file name from the message with a `?'. | |
1948 | When used in the text of the message, \fB$_\fP expands to the name of | |
1949 | the current mailfile. | |
1950 | Example: | |
1951 | .RS | |
1952 | .PP | |
20587658 | 1953 | \fBMAILPATH\fP=\(aq/var/mail/bfox?"You have mail":~/shell\-mail?"$_ has mail!"\(aq |
f73dda09 JA |
1954 | .PP |
1955 | .B Bash | |
1956 | supplies a default value for this variable, but the location of the user | |
1957 | mail files that it uses is system dependent (e.g., /var/mail/\fB$USER\fP). | |
1958 | .RE | |
726f6388 | 1959 | .TP |
f73dda09 JA |
1960 | .B OPTERR |
1961 | If set to the value 1, | |
1962 | .B bash | |
1963 | displays error messages generated by the | |
1964 | .B getopts | |
1965 | builtin command (see | |
726f6388 | 1966 | .SM |
f73dda09 | 1967 | .B SHELL BUILTIN COMMANDS |
ccc6cda3 | 1968 | below). |
726f6388 | 1969 | .SM |
f73dda09 JA |
1970 | .B OPTERR |
1971 | is initialized to 1 each time the shell is invoked or a shell | |
1972 | script is executed. | |
ccc6cda3 | 1973 | .TP |
f73dda09 JA |
1974 | .B PATH |
1975 | The search path for commands. It | |
1976 | is a colon-separated list of directories in which | |
1977 | the shell looks for commands (see | |
ccc6cda3 | 1978 | .SM |
f73dda09 | 1979 | .B COMMAND EXECUTION |
d3a24ed2 CR |
1980 | below). |
1981 | A zero-length (null) directory name in the value of \fBPATH\fP indicates the | |
1982 | current directory. | |
1983 | A null directory name may appear as two adjacent colons, or as an initial | |
1984 | or trailing colon. | |
1985 | The default path is system-dependent, | |
f73dda09 JA |
1986 | and is set by the administrator who installs |
1987 | .BR bash . | |
1988 | A common value is | |
5e13499c CR |
1989 | .if t \f(CW/usr/gnu/bin:/usr/local/bin:/usr/ucb:/bin:/usr/bin\fP. |
1990 | .if n ``/usr/gnu/bin:/usr/local/bin:/usr/ucb:/bin:/usr/bin''. | |
726f6388 | 1991 | .TP |
f73dda09 JA |
1992 | .B POSIXLY_CORRECT |
1993 | If this variable is in the environment when \fBbash\fP starts, the shell | |
1994 | enters \fIposix mode\fP before reading the startup files, as if the | |
1995 | .B \-\-posix | |
1996 | invocation option had been supplied. If it is set while the shell is | |
1997 | running, \fBbash\fP enables \fIposix mode\fP, as if the command | |
1998 | .if t \f(CWset -o posix\fP | |
1999 | .if n \fIset -o posix\fP | |
2000 | had been executed. | |
726f6388 | 2001 | .TP |
f73dda09 JA |
2002 | .B PROMPT_COMMAND |
2003 | If set, the value is executed as a command prior to issuing each primary | |
2004 | prompt. | |
ccc6cda3 | 2005 | .TP |
ed35cb4a CR |
2006 | .B PROMPT_DIRTRIM |
2007 | If set to a number greater than zero, the value is used as the number of | |
d0ca3503 | 2008 | trailing directory components to retain when expanding the \fB\ew\fP and |
ed35cb4a CR |
2009 | \fB\eW\fP prompt string escapes (see |
2010 | .SM | |
2011 | .B PROMPTING | |
2012 | below). Characters removed are replaced with an ellipsis. | |
2013 | .TP | |
f73dda09 JA |
2014 | .B PS1 |
2015 | The value of this parameter is expanded (see | |
2016 | .SM | |
2017 | .B PROMPTING | |
2018 | below) and used as the primary prompt string. The default value is | |
2019 | ``\fB\es\-\ev\e$ \fP''. | |
726f6388 | 2020 | .TP |
f73dda09 JA |
2021 | .B PS2 |
2022 | The value of this parameter is expanded as with | |
2023 | .B PS1 | |
2024 | and used as the secondary prompt string. The default is | |
2025 | ``\fB> \fP''. | |
2026 | .TP | |
2027 | .B PS3 | |
2028 | The value of this parameter is used as the prompt for the | |
2029 | .B select | |
2030 | command (see | |
726f6388 | 2031 | .SM |
f73dda09 JA |
2032 | .B SHELL GRAMMAR |
2033 | above). | |
726f6388 | 2034 | .TP |
f73dda09 JA |
2035 | .B PS4 |
2036 | The value of this parameter is expanded as with | |
2037 | .B PS1 | |
2038 | and the value is printed before each command | |
726f6388 | 2039 | .B bash |
f73dda09 | 2040 | displays during an execution trace. The first character of |
bb70624e | 2041 | .SM |
f73dda09 JA |
2042 | .B PS4 |
2043 | is replicated multiple times, as necessary, to indicate multiple | |
2044 | levels of indirection. The default is ``\fB+ \fP''. | |
2045 | .TP | |
61deeb13 CR |
2046 | .B SHELL |
2047 | The full pathname to the shell is kept in this environment variable. | |
2048 | If it is not set when the shell starts, | |
2049 | .B bash | |
2050 | assigns to it the full pathname of the current user's login shell. | |
2051 | .TP | |
f73dda09 JA |
2052 | .B TIMEFORMAT |
2053 | The value of this parameter is used as a format string specifying | |
2054 | how the timing information for pipelines prefixed with the | |
2055 | .B time | |
2056 | reserved word should be displayed. | |
2057 | The \fB%\fP character introduces an escape sequence that is | |
2058 | expanded to a time value or other information. | |
2059 | The escape sequences and their meanings are as follows; the | |
2060 | braces denote optional portions. | |
2061 | .sp .5 | |
2062 | .RS | |
2063 | .PD 0 | |
2064 | .TP 10 | |
2065 | .B %% | |
2066 | A literal \fB%\fP. | |
2067 | .TP | |
2068 | .B %[\fIp\fP][l]R | |
2069 | The elapsed time in seconds. | |
2070 | .TP | |
2071 | .B %[\fIp\fP][l]U | |
2072 | The number of CPU seconds spent in user mode. | |
2073 | .TP | |
2074 | .B %[\fIp\fP][l]S | |
2075 | The number of CPU seconds spent in system mode. | |
2076 | .TP | |
2077 | .B %P | |
2078 | The CPU percentage, computed as (%U + %S) / %R. | |
2079 | .PD | |
2080 | .RE | |
2081 | .IP | |
2082 | The optional \fIp\fP is a digit specifying the \fIprecision\fP, | |
2083 | the number of fractional digits after a decimal point. | |
2084 | A value of 0 causes no decimal point or fraction to be output. | |
2085 | At most three places after the decimal point may be specified; | |
2086 | values of \fIp\fP greater than 3 are changed to 3. | |
2087 | If \fIp\fP is not specified, the value 3 is used. | |
2088 | .IP | |
2089 | The optional \fBl\fP specifies a longer format, including | |
2090 | minutes, of the form \fIMM\fPm\fISS\fP.\fIFF\fPs. | |
2091 | The value of \fIp\fP determines whether or not the fraction is | |
2092 | included. | |
2093 | .IP | |
2094 | If this variable is not set, \fBbash\fP acts as if it had the | |
20587658 | 2095 | value \fB$\(aq\enreal\et%3lR\enuser\et%3lU\ensys\t%3lS\(aq\fP. |
f73dda09 JA |
2096 | If the value is null, no timing information is displayed. |
2097 | A trailing newline is added when the format string is displayed. | |
2098 | .TP | |
2099 | .B TMOUT | |
7117c2d2 JA |
2100 | If set to a value greater than zero, \fBTMOUT\fP is treated as the |
2101 | default timeout for the \fBread\fP builtin. | |
2102 | The \fBselect\fP command terminates if input does not arrive | |
2103 | after \fBTMOUT\fP seconds when input is coming from a terminal. | |
2104 | In an interactive shell, the value is interpreted as the | |
f73dda09 JA |
2105 | number of seconds to wait for input after issuing the primary prompt. |
2106 | .B Bash | |
2107 | terminates after waiting for that number of seconds if input does | |
2108 | not arrive. | |
726f6388 | 2109 | .TP |
1569c106 CR |
2110 | .B TMPDIR |
2111 | If set, \fBBash\fP uses its value as the name of a directory in which | |
2112 | \fBBash\fP creates temporary files for the shell's use. | |
2113 | .TP | |
726f6388 JA |
2114 | .B auto_resume |
2115 | This variable controls how the shell interacts with the user and | |
2116 | job control. If this variable is set, single word simple | |
2117 | commands without redirections are treated as candidates for resumption | |
2118 | of an existing stopped job. There is no ambiguity allowed; if there is | |
2119 | more than one job beginning with the string typed, the job most recently | |
2120 | accessed is selected. The | |
2121 | .I name | |
2122 | of a stopped job, in this context, is the command line used to | |
2123 | start it. | |
2124 | If set to the value | |
2125 | .IR exact , | |
2126 | the string supplied must match the name of a stopped job exactly; | |
2127 | if set to | |
2128 | .IR substring , | |
2129 | the string supplied needs to match a substring of the name of a | |
2130 | stopped job. The | |
2131 | .I substring | |
2132 | value provides functionality analogous to the | |
2133 | .B %? | |
ccc6cda3 | 2134 | job identifier (see |
726f6388 JA |
2135 | .SM |
2136 | .B JOB CONTROL | |
2137 | below). If set to any other value, the supplied string must | |
2138 | be a prefix of a stopped job's name; this provides functionality | |
22e63b05 | 2139 | analogous to the \fB%\fP\fIstring\fP job identifier. |
bb70624e | 2140 | .TP |
f73dda09 JA |
2141 | .B histchars |
2142 | The two or three characters which control history expansion | |
2143 | and tokenization (see | |
2144 | .SM | |
2145 | .B HISTORY EXPANSION | |
2146 | below). The first character is the \fIhistory expansion\fP character, | |
2147 | the character which signals the start of a history | |
2148 | expansion, normally `\fB!\fP'. | |
2149 | The second character is the \fIquick substitution\fP | |
2150 | character, which is used as shorthand for re-running the previous | |
2151 | command entered, substituting one string for another in the command. | |
2152 | The default is `\fB^\fP'. | |
2153 | The optional third character is the character | |
2154 | which indicates that the remainder of the line is a comment when found | |
2155 | as the first character of a word, normally `\fB#\fP'. The history | |
2156 | comment character causes history substitution to be skipped for the | |
2157 | remaining words on the line. It does not necessarily cause the shell | |
2158 | parser to treat the rest of the line as a comment. | |
726f6388 | 2159 | .PD |
ccc6cda3 JA |
2160 | .SS Arrays |
2161 | .B Bash | |
fdf670ea | 2162 | provides one-dimensional indexed and associative array variables. |
09767ff0 | 2163 | Any variable may be used as an indexed array; the |
ccc6cda3 | 2164 | .B declare |
fdf670ea CR |
2165 | builtin will explicitly declare an array. |
2166 | There is no maximum | |
ccc6cda3 | 2167 | limit on the size of an array, nor any requirement that members |
fdf670ea CR |
2168 | be indexed or assigned contiguously. |
2169 | Indexed arrays are referenced using integers (including arithmetic | |
09767ff0 CR |
2170 | expressions) and are zero-based; associative arrays are referenced |
2171 | using arbitrary strings. | |
ccc6cda3 | 2172 | .PP |
fdf670ea CR |
2173 | An indexed array is created automatically if any variable is assigned to |
2174 | using the syntax \fIname\fP[\fIsubscript\fP]=\fIvalue\fP. The | |
ccc6cda3 JA |
2175 | .I subscript |
2176 | is treated as an arithmetic expression that must evaluate to a number | |
fdf670ea CR |
2177 | greater than or equal to zero. To explicitly declare an indexed array, |
2178 | use | |
ccc6cda3 JA |
2179 | .B declare \-a \fIname\fP |
2180 | (see | |
2181 | .SM | |
2182 | .B SHELL BUILTIN COMMANDS | |
2183 | below). | |
2184 | .B declare \-a \fIname\fP[\fIsubscript\fP] | |
09767ff0 CR |
2185 | is also accepted; the \fIsubscript\fP is ignored. |
2186 | .PP | |
2187 | Associative arrays are created using | |
2188 | .BR "declare \-A \fIname\fP" . | |
2189 | .PP | |
2190 | Attributes may be | |
ccc6cda3 JA |
2191 | specified for an array variable using the |
2192 | .B declare | |
2193 | and | |
2194 | .B readonly | |
2195 | builtins. Each attribute applies to all members of an array. | |
2196 | .PP | |
2197 | Arrays are assigned to using compound assignments of the form | |
2198 | \fIname\fP=\fB(\fPvalue\fI1\fP ... value\fIn\fP\fB)\fP, where each | |
09767ff0 CR |
2199 | \fIvalue\fP is of the form [\fIsubscript\fP]=\fIstring\fP. |
2200 | Indexed array assignments do not require the bracket and subscript. | |
2201 | When assigning to indexed arrays, if the optional brackets and subscript | |
2202 | are supplied, that index is assigned to; | |
ccc6cda3 JA |
2203 | otherwise the index of the element assigned is the last index assigned |
2204 | to by the statement plus one. Indexing starts at zero. | |
fdf670ea CR |
2205 | .PP |
2206 | When assigning to an associative array, the subscript is required. | |
2207 | .PP | |
ccc6cda3 JA |
2208 | This syntax is also accepted by the |
2209 | .B declare | |
2210 | builtin. Individual array elements may be assigned to using the | |
2211 | \fIname\fP[\fIsubscript\fP]=\fIvalue\fP syntax introduced above. | |
2212 | .PP | |
2213 | Any element of an array may be referenced using | |
2214 | ${\fIname\fP[\fIsubscript\fP]}. The braces are required to avoid | |
2215 | conflicts with pathname expansion. If | |
2216 | \fIsubscript\fP is \fB@\fP or \fB*\fP, the word expands to | |
2217 | all members of \fIname\fP. These subscripts differ only when the | |
2218 | word appears within double quotes. If the word is double-quoted, | |
2219 | ${\fIname\fP[*]} expands to a single | |
2220 | word with the value of each array member separated by the first | |
2221 | character of the | |
2222 | .SM | |
2223 | .B IFS | |
2224 | special variable, and ${\fIname\fP[@]} expands each element of | |
2225 | \fIname\fP to a separate word. When there are no array members, | |
be7d8f2d CR |
2226 | ${\fIname\fP[@]} expands to nothing. |
2227 | If the double-quoted expansion occurs within a word, the expansion of | |
2228 | the first parameter is joined with the beginning part of the original | |
2229 | word, and the expansion of the last parameter is joined with the last | |
2230 | part of the original word. | |
2231 | This is analogous to the expansion | |
ccc6cda3 JA |
2232 | of the special parameters \fB*\fP and \fB@\fP (see |
2233 | .B Special Parameters | |
2234 | above). ${#\fIname\fP[\fIsubscript\fP]} expands to the length of | |
2235 | ${\fIname\fP[\fIsubscript\fP]}. If \fIsubscript\fP is \fB*\fP or | |
2236 | \fB@\fP, the expansion is the number of elements in the array. | |
2237 | Referencing an array variable without a subscript is equivalent to | |
fdf670ea | 2238 | referencing the array with a subscript of 0. |
ccc6cda3 | 2239 | .PP |
94a5513e CR |
2240 | An array variable is considered set if a subscript has been assigned a |
2241 | value. The null string is a valid value. | |
2242 | .PP | |
ccc6cda3 JA |
2243 | The |
2244 | .B unset | |
bb70624e | 2245 | builtin is used to destroy arrays. \fBunset\fP \fIname\fP[\fIsubscript\fP] |
ccc6cda3 | 2246 | destroys the array element at index \fIsubscript\fP. |
d0ca3503 CR |
2247 | Care must be taken to avoid unwanted side effects caused by pathname |
2248 | expansion. | |
ccc6cda3 JA |
2249 | \fBunset\fP \fIname\fP, where \fIname\fP is an array, or |
2250 | \fBunset\fP \fIname\fP[\fIsubscript\fP], where | |
2251 | \fIsubscript\fP is \fB*\fP or \fB@\fP, removes the entire array. | |
2252 | .PP | |
2253 | The | |
2254 | .BR declare , | |
2255 | .BR local , | |
2256 | and | |
2257 | .B readonly | |
2258 | builtins each accept a | |
2259 | .B \-a | |
fdf670ea CR |
2260 | option to specify an indexed array and a |
2261 | .B \-A | |
2262 | option to specify an associative array. | |
2263 | The | |
ccc6cda3 JA |
2264 | .B read |
2265 | builtin accepts a | |
2266 | .B \-a | |
2267 | option to assign a list of words read from the standard input | |
2268 | to an array. The | |
2269 | .B set | |
2270 | and | |
2271 | .B declare | |
2272 | builtins display array values in a way that allows them to be | |
2273 | reused as assignments. | |
726f6388 JA |
2274 | .SH EXPANSION |
2275 | Expansion is performed on the command line after it has been split into | |
2276 | words. There are seven kinds of expansion performed: | |
2277 | .IR "brace expansion" , | |
2278 | .IR "tilde expansion" , | |
2279 | .IR "parameter and variable expansion" , | |
2280 | .IR "command substitution" , | |
2281 | .IR "arithmetic expansion" , | |
2282 | .IR "word splitting" , | |
2283 | and | |
2284 | .IR "pathname expansion" . | |
2285 | .PP | |
2286 | The order of expansions is: brace expansion, tilde expansion, | |
ccc6cda3 JA |
2287 | parameter, variable and arithmetic expansion and |
2288 | command substitution | |
2289 | (done in a left-to-right fashion), word splitting, and pathname | |
726f6388 JA |
2290 | expansion. |
2291 | .PP | |
2292 | On systems that can support it, there is an additional expansion | |
2293 | available: \fIprocess substitution\fP. | |
2294 | .PP | |
2295 | Only brace expansion, word splitting, and pathname expansion | |
2296 | can change the number of words of the expansion; other expansions | |
2297 | expand a single word to a single word. | |
ccc6cda3 | 2298 | The only exceptions to this are the expansions of |
cce855bc | 2299 | "\fB$@\fP" and "\fB${\fP\fIname\fP\fB[@]}\fP" |
ccc6cda3 | 2300 | as explained above (see |
726f6388 JA |
2301 | .SM |
2302 | .BR PARAMETERS ). | |
2303 | .SS Brace Expansion | |
2304 | .PP | |
2305 | .I "Brace expansion" | |
2306 | is a mechanism by which arbitrary strings | |
2307 | may be generated. This mechanism is similar to | |
2308 | \fIpathname expansion\fP, but the filenames generated | |
2309 | need not exist. Patterns to be brace expanded take | |
2310 | the form of an optional | |
2311 | .IR preamble , | |
d3a24ed2 CR |
2312 | followed by either a series of comma-separated strings or |
2313 | a sequence expression between a pair of braces, followed by | |
2314 | an optional | |
cce855bc | 2315 | .IR postscript . |
ccc6cda3 | 2316 | The preamble is prefixed to each string contained |
cce855bc | 2317 | within the braces, and the postscript is then appended |
726f6388 JA |
2318 | to each resulting string, expanding left to right. |
2319 | .PP | |
2320 | Brace expansions may be nested. The results of each expanded | |
2321 | string are not sorted; left to right order is preserved. | |
2322 | For example, a\fB{\fPd,c,b\fB}\fPe expands into `ade ace abe'. | |
2323 | .PP | |
8943768b | 2324 | A sequence expression takes the form |
36211029 | 2325 | \fB{\fP\fIx\fP\fB..\fP\fIy\fP\fB[..\fP\fIincr\fP\fB]}\fP, |
8943768b CR |
2326 | where \fIx\fP and \fIy\fP are either integers or single characters, |
2327 | and \fIincr\fP, an optional increment, is an integer. | |
d3a24ed2 CR |
2328 | When integers are supplied, the expression expands to each number between |
2329 | \fIx\fP and \fIy\fP, inclusive. | |
8943768b CR |
2330 | Supplied integers may be prefixed with \fI0\fP to force each term to have the |
2331 | same width. When either \fIx\fP or \fPy\fP begins with a zero, the shell | |
2332 | attempts to force all generated terms to contain the same number of digits, | |
2333 | zero-padding where necessary. | |
d3a24ed2 CR |
2334 | When characters are supplied, the expression expands to each character |
2335 | lexicographically between \fIx\fP and \fIy\fP, inclusive. Note that | |
2336 | both \fIx\fP and \fIy\fP must be of the same type. | |
8943768b CR |
2337 | When the increment is supplied, it is used as the difference between |
2338 | each term. The default increment is 1 or -1 as appropriate. | |
d3a24ed2 | 2339 | .PP |
726f6388 JA |
2340 | Brace expansion is performed before any other expansions, |
2341 | and any characters special to other expansions are preserved | |
2342 | in the result. It is strictly textual. | |
2343 | .B Bash | |
2344 | does not apply any syntactic interpretation to the context of the | |
2345 | expansion or the text between the braces. | |
2346 | .PP | |
2347 | A correctly-formed brace expansion must contain unquoted opening | |
d3a24ed2 CR |
2348 | and closing braces, and at least one unquoted comma or a valid |
2349 | sequence expression. | |
726f6388 | 2350 | Any incorrectly formed brace expansion is left unchanged. |
ccc6cda3 JA |
2351 | A \fB{\fP or \fB,\fP may be quoted with a backslash to prevent its |
2352 | being considered part of a brace expression. | |
bb70624e JA |
2353 | To avoid conflicts with parameter expansion, the string \fB${\fP |
2354 | is not considered eligible for brace expansion. | |
726f6388 JA |
2355 | .PP |
2356 | This construct is typically used as shorthand when the common | |
2357 | prefix of the strings to be generated is longer than in the | |
2358 | above example: | |
2359 | .RS | |
2360 | .PP | |
2361 | mkdir /usr/local/src/bash/{old,new,dist,bugs} | |
2362 | .RE | |
2363 | or | |
2364 | .RS | |
2365 | chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}} | |
2366 | .RE | |
2367 | .PP | |
2368 | Brace expansion introduces a slight incompatibility with | |
ccc6cda3 JA |
2369 | historical versions of |
2370 | .BR sh . | |
726f6388 JA |
2371 | .B sh |
2372 | does not treat opening or closing braces specially when they | |
2373 | appear as part of a word, and preserves them in the output. | |
2374 | .B Bash | |
2375 | removes braces from words as a consequence of brace | |
2376 | expansion. For example, a word entered to | |
2377 | .B sh | |
2378 | as \fIfile{1,2}\fP | |
2379 | appears identically in the output. The same word is | |
2380 | output as | |
2381 | .I file1 file2 | |
2382 | after expansion by | |
2383 | .BR bash . | |
2384 | If strict compatibility with | |
2385 | .B sh | |
2386 | is desired, start | |
2387 | .B bash | |
2388 | with the | |
ccc6cda3 JA |
2389 | .B +B |
2390 | option or disable brace expansion with the | |
2391 | .B +B | |
726f6388 JA |
2392 | option to the |
2393 | .B set | |
2394 | command (see | |
2395 | .SM | |
2396 | .B SHELL BUILTIN COMMANDS | |
2397 | below). | |
2398 | .SS Tilde Expansion | |
2399 | .PP | |
cce855bc JA |
2400 | If a word begins with an unquoted tilde character (`\fB~\fP'), all of |
2401 | the characters preceding the first unquoted slash (or all characters, | |
2402 | if there is no unquoted slash) are considered a \fItilde-prefix\fP. | |
2403 | If none of the characters in the tilde-prefix are quoted, the | |
2404 | characters in the tilde-prefix following the tilde are treated as a | |
2405 | possible \fIlogin name\fP. | |
2406 | If this login name is the null string, the tilde is replaced with the | |
2407 | value of the shell parameter | |
726f6388 JA |
2408 | .SM |
2409 | .BR HOME . | |
2410 | If | |
2411 | .SM | |
2412 | .B HOME | |
cce855bc JA |
2413 | is unset, the home directory of the user executing the shell is |
2414 | substituted instead. | |
2415 | Otherwise, the tilde-prefix is replaced with the home directory | |
2416 | associated with the specified login name. | |
726f6388 | 2417 | .PP |
cce855bc | 2418 | If the tilde-prefix is a `~+', the value of the shell variable |
726f6388 JA |
2419 | .SM |
2420 | .B PWD | |
cce855bc JA |
2421 | replaces the tilde-prefix. |
2422 | If the tilde-prefix is a `~\-', the value of the shell variable | |
2423 | .SM | |
2424 | .BR OLDPWD , | |
2425 | if it is set, is substituted. | |
2426 | If the characters following the tilde in the tilde-prefix consist | |
2427 | of a number \fIN\fP, optionally prefixed | |
2428 | by a `+' or a `\-', the tilde-prefix is replaced with the corresponding | |
2429 | element from the directory stack, as it would be displayed by the | |
2430 | .B dirs | |
2431 | builtin invoked with the tilde-prefix as an argument. | |
2432 | If the characters following the tilde in the tilde-prefix consist of a | |
2433 | number without a leading `+' or `\-', `+' is assumed. | |
2434 | .PP | |
2435 | If the login name is invalid, or the tilde expansion fails, the word | |
2436 | is unchanged. | |
726f6388 | 2437 | .PP |
cce855bc JA |
2438 | Each variable assignment is checked for unquoted tilde-prefixes immediately |
2439 | following a | |
726f6388 | 2440 | .B : |
43df7bbb | 2441 | or the first |
726f6388 | 2442 | .BR = . |
cce855bc JA |
2443 | In these cases, tilde expansion is also performed. |
2444 | Consequently, one may use file names with tildes in assignments to | |
726f6388 JA |
2445 | .SM |
2446 | .BR PATH , | |
2447 | .SM | |
2448 | .BR MAILPATH , | |
2449 | and | |
2450 | .SM | |
2451 | .BR CDPATH , | |
2452 | and the shell assigns the expanded value. | |
2453 | .SS Parameter Expansion | |
2454 | .PP | |
2455 | The `\fB$\fP' character introduces parameter expansion, | |
2456 | command substitution, or arithmetic expansion. The parameter name | |
2457 | or symbol to be expanded may be enclosed in braces, which | |
2458 | are optional but serve to protect the variable to be expanded from | |
2459 | characters immediately following it which could be | |
2460 | interpreted as part of the name. | |
2461 | .PP | |
cce855bc JA |
2462 | When braces are used, the matching ending brace is the first `\fB}\fP' |
2463 | not escaped by a backslash or within a quoted string, and not within an | |
f75912ae | 2464 | embedded arithmetic expansion, command substitution, or parameter |
cce855bc JA |
2465 | expansion. |
2466 | .PP | |
726f6388 JA |
2467 | .PD 0 |
2468 | .TP | |
2469 | ${\fIparameter\fP} | |
2470 | The value of \fIparameter\fP is substituted. The braces are required | |
2471 | when | |
2472 | .I parameter | |
2473 | is a positional parameter with more than one digit, | |
2474 | or when | |
2475 | .I parameter | |
2476 | is followed by a character which is not to be | |
2477 | interpreted as part of its name. | |
2478 | .PD | |
2479 | .PP | |
ccc6cda3 JA |
2480 | If the first character of \fIparameter\fP is an exclamation point, |
2481 | a level of variable indirection is introduced. | |
2482 | \fBBash\fP uses the value of the variable formed from the rest of | |
2483 | \fIparameter\fP as the name of the variable; this variable is then | |
bb70624e | 2484 | expanded and that value is used in the rest of the substitution, rather |
ccc6cda3 JA |
2485 | than the value of \fIparameter\fP itself. |
2486 | This is known as \fIindirect expansion\fP. | |
d3a24ed2 CR |
2487 | The exceptions to this are the expansions of ${!\fIprefix\fP*} and |
2488 | ${\fB!\fP\fIname\fP[\fI@\fP]} described below. | |
2489 | The exclamation point must immediately follow the left brace in order to | |
2490 | introduce indirection. | |
ccc6cda3 | 2491 | .PP |
726f6388 JA |
2492 | In each of the cases below, \fIword\fP is subject to tilde expansion, |
2493 | parameter expansion, command substitution, and arithmetic expansion. | |
e141c35a CR |
2494 | .PP |
2495 | When not performing substring expansion, using the forms documented below, | |
2496 | \fBbash\fP tests for a parameter that is unset or null. Omitting the colon | |
2497 | results in a test only for a parameter that is unset. | |
726f6388 JA |
2498 | .PP |
2499 | .PD 0 | |
2500 | .TP | |
2501 | ${\fIparameter\fP\fB:\-\fP\fIword\fP} | |
2502 | \fBUse Default Values\fP. If | |
2503 | .I parameter | |
2504 | is unset or null, the expansion of | |
2505 | .I word | |
2506 | is substituted. Otherwise, the value of | |
2507 | .I parameter | |
2508 | is substituted. | |
2509 | .TP | |
2510 | ${\fIparameter\fP\fB:=\fP\fIword\fP} | |
2511 | \fBAssign Default Values\fP. | |
2512 | If | |
2513 | .I parameter | |
2514 | is unset or null, the expansion of | |
2515 | .I word | |
2516 | is assigned to | |
2517 | .IR parameter . | |
2518 | The value of | |
2519 | .I parameter | |
2520 | is then substituted. Positional parameters and special parameters may | |
2521 | not be assigned to in this way. | |
2522 | .TP | |
2523 | ${\fIparameter\fP\fB:?\fP\fIword\fP} | |
2524 | \fBDisplay Error if Null or Unset\fP. | |
2525 | If | |
2526 | .I parameter | |
2527 | is null or unset, the expansion of \fIword\fP (or a message to that effect | |
2528 | if | |
2529 | .I word | |
2530 | is not present) is written to the standard error and the shell, if it | |
2531 | is not interactive, exits. Otherwise, the value of \fIparameter\fP is | |
2532 | substituted. | |
2533 | .TP | |
2534 | ${\fIparameter\fP\fB:+\fP\fIword\fP} | |
2535 | \fBUse Alternate Value\fP. | |
2536 | If | |
2537 | .I parameter | |
2538 | is null or unset, nothing is substituted, otherwise the expansion of | |
2539 | .I word | |
2540 | is substituted. | |
2541 | .TP | |
ccc6cda3 | 2542 | ${\fIparameter\fP\fB:\fP\fIoffset\fP} |
7117c2d2 | 2543 | .PD 0 |
ccc6cda3 JA |
2544 | .TP |
2545 | ${\fIparameter\fP\fB:\fP\fIoffset\fP\fB:\fP\fIlength\fP} | |
2546 | .PD | |
2547 | \fBSubstring Expansion.\fP | |
bb70624e JA |
2548 | Expands to up to \fIlength\fP characters of \fIparameter\fP |
2549 | starting at the character specified by \fIoffset\fP. | |
ccc6cda3 | 2550 | If \fIlength\fP is omitted, expands to the substring of |
bb70624e | 2551 | \fIparameter\fP starting at the character specified by \fIoffset\fP. |
ccc6cda3 JA |
2552 | \fIlength\fP and \fIoffset\fP are arithmetic expressions (see |
2553 | .SM | |
2554 | .B | |
2555 | ARITHMETIC EVALUATION | |
2556 | below). | |
2557 | \fIlength\fP must evaluate to a number greater than or equal to zero. | |
2558 | If \fIoffset\fP evaluates to a number less than zero, the value | |
2559 | is used as an offset from the end of the value of \fIparameter\fP. | |
2560 | If \fIparameter\fP is \fB@\fP, the result is \fIlength\fP positional | |
2561 | parameters beginning at \fIoffset\fP. | |
09767ff0 | 2562 | If \fIparameter\fP is an indexed array name subscripted by @ or *, |
ccc6cda3 JA |
2563 | the result is the \fIlength\fP |
2564 | members of the array beginning with ${\fIparameter\fP[\fIoffset\fP]}. | |
ec2199bd CR |
2565 | A negative \fIoffset\fP is taken relative to one greater than the maximum |
2566 | index of the specified array. | |
09767ff0 CR |
2567 | Substring expansion applied to an associative array produces undefined |
2568 | results. | |
ec2199bd CR |
2569 | Note that a negative offset must be separated from the colon by at least |
2570 | one space to avoid being confused with the :- expansion. | |
cce855bc | 2571 | Substring indexing is zero-based unless the positional parameters |
d3ad40de CR |
2572 | are used, in which case the indexing starts at 1 by default. |
2573 | If \fIoffset\fP is 0, and the positional parameters are used, \fB$0\fP is | |
2574 | prefixed to the list. | |
ccc6cda3 | 2575 | .TP |
bb70624e | 2576 | ${\fB!\fP\fIprefix\fP\fB*\fP} |
d3a24ed2 CR |
2577 | .PD 0 |
2578 | .TP | |
2579 | ${\fB!\fP\fIprefix\fP\fB@\fP} | |
2580 | .PD | |
36211029 | 2581 | \fBNames matching prefix.\fP |
bb70624e JA |
2582 | Expands to the names of variables whose names begin with \fIprefix\fP, |
2583 | separated by the first character of the | |
2584 | .SM | |
2585 | .B IFS | |
2586 | special variable. | |
d3ad40de CR |
2587 | When \fI@\fP is used and the expansion appears within double quotes, each |
2588 | variable name expands to a separate word. | |
bb70624e | 2589 | .TP |
d3a24ed2 CR |
2590 | ${\fB!\fP\fIname\fP[\fI@\fP]} |
2591 | .PD 0 | |
2592 | .TP | |
2593 | ${\fB!\fP\fIname\fP[\fI*\fP]} | |
2594 | .PD | |
36211029 | 2595 | \fBList of array keys.\fP |
d3a24ed2 CR |
2596 | If \fIname\fP is an array variable, expands to the list of array indices |
2597 | (keys) assigned in \fIname\fP. | |
2598 | If \fIname\fP is not an array, expands to 0 if \fIname\fP is set and null | |
2599 | otherwise. | |
2600 | When \fI@\fP is used and the expansion appears within double quotes, each | |
2601 | key expands to a separate word. | |
2602 | .TP | |
726f6388 | 2603 | ${\fB#\fP\fIparameter\fP} |
36211029 | 2604 | \fBParameter length.\fP |
726f6388 | 2605 | The length in characters of the value of \fIparameter\fP is substituted. |
ccc6cda3 JA |
2606 | If |
2607 | .I parameter | |
2608 | is | |
726f6388 JA |
2609 | .B * |
2610 | or | |
2611 | .BR @ , | |
cce855bc | 2612 | the value substituted is the number of positional parameters. |
ccc6cda3 JA |
2613 | If |
2614 | .I parameter | |
2615 | is an array name subscripted by | |
726f6388 | 2616 | .B * |
ccc6cda3 JA |
2617 | or |
2618 | .BR @ , | |
cce855bc | 2619 | the value substituted is the number of elements in the array. |
726f6388 | 2620 | .TP |
726f6388 | 2621 | ${\fIparameter\fP\fB#\fP\fIword\fP} |
7117c2d2 | 2622 | .PD 0 |
726f6388 JA |
2623 | .TP |
2624 | ${\fIparameter\fP\fB##\fP\fIword\fP} | |
2625 | .PD | |
36211029 | 2626 | \fBRemove matching prefix pattern.\fP |
726f6388 JA |
2627 | The |
2628 | .I word | |
2629 | is expanded to produce a pattern just as in pathname | |
2630 | expansion. If the pattern matches the beginning of | |
2631 | the value of | |
2632 | .IR parameter , | |
cce855bc | 2633 | then the result of the expansion is the expanded value of |
726f6388 | 2634 | .I parameter |
ccc6cda3 JA |
2635 | with the shortest matching pattern (the ``\fB#\fP'' case) or the |
2636 | longest matching pattern (the ``\fB##\fP'' case) deleted. | |
2637 | If | |
2638 | .I parameter | |
2639 | is | |
2640 | .B @ | |
2641 | or | |
2642 | .BR * , | |
2643 | the pattern removal operation is applied to each positional | |
2644 | parameter in turn, and the expansion is the resultant list. | |
2645 | If | |
2646 | .I parameter | |
2647 | is an array variable subscripted with | |
2648 | .B @ | |
2649 | or | |
2650 | .BR * , | |
2651 | the pattern removal operation is applied to each member of the | |
2652 | array in turn, and the expansion is the resultant list. | |
726f6388 | 2653 | .TP |
726f6388 | 2654 | ${\fIparameter\fP\fB%\fP\fIword\fP} |
7117c2d2 | 2655 | .PD 0 |
726f6388 JA |
2656 | .TP |
2657 | ${\fIparameter\fP\fB%%\fP\fIword\fP} | |
2658 | .PD | |
36211029 | 2659 | \fBRemove matching suffix pattern.\fP |
726f6388 | 2660 | The \fIword\fP is expanded to produce a pattern just as in |
ccc6cda3 | 2661 | pathname expansion. |
cce855bc | 2662 | If the pattern matches a trailing portion of the expanded value of |
726f6388 | 2663 | .IR parameter , |
cce855bc | 2664 | then the result of the expansion is the expanded value of |
726f6388 | 2665 | .I parameter |
ccc6cda3 JA |
2666 | with the shortest matching pattern (the ``\fB%\fP'' case) or the |
2667 | longest matching pattern (the ``\fB%%\fP'' case) deleted. | |
2668 | If | |
2669 | .I parameter | |
2670 | is | |
2671 | .B @ | |
2672 | or | |
2673 | .BR * , | |
2674 | the pattern removal operation is applied to each positional | |
2675 | parameter in turn, and the expansion is the resultant list. | |
2676 | If | |
2677 | .I parameter | |
2678 | is an array variable subscripted with | |
2679 | .B @ | |
2680 | or | |
2681 | .BR * , | |
2682 | the pattern removal operation is applied to each member of the | |
2683 | array in turn, and the expansion is the resultant list. | |
2684 | .TP | |
ccc6cda3 | 2685 | ${\fIparameter\fP\fB/\fP\fIpattern\fP\fB/\fP\fIstring\fP} |
36211029 | 2686 | \fBPattern substitution.\fP |
ccc6cda3 JA |
2687 | The \fIpattern\fP is expanded to produce a pattern just as in |
2688 | pathname expansion. | |
2689 | \fIParameter\fP is expanded and the longest match of \fIpattern\fP | |
2690 | against its value is replaced with \fIstring\fP. | |
e6598ba4 | 2691 | If \fIpattern\fP begins with \fB/\fP, all matches of \fIpattern\fP are |
dc8fbaf9 | 2692 | replaced with \fIstring\fP. Normally only the first match is replaced. |
ccc6cda3 | 2693 | If \fIpattern\fP begins with \fB#\fP, it must match at the beginning |
b72432fd | 2694 | of the expanded value of \fIparameter\fP. |
ccc6cda3 | 2695 | If \fIpattern\fP begins with \fB%\fP, it must match at the end |
b72432fd | 2696 | of the expanded value of \fIparameter\fP. |
ccc6cda3 JA |
2697 | If \fIstring\fP is null, matches of \fIpattern\fP are deleted |
2698 | and the \fB/\fP following \fIpattern\fP may be omitted. | |
2699 | If | |
2700 | .I parameter | |
2701 | is | |
2702 | .B @ | |
2703 | or | |
2704 | .BR * , | |
2705 | the substitution operation is applied to each positional | |
2706 | parameter in turn, and the expansion is the resultant list. | |
2707 | If | |
2708 | .I parameter | |
2709 | is an array variable subscripted with | |
2710 | .B @ | |
2711 | or | |
2712 | .BR * , | |
2713 | the substitution operation is applied to each member of the | |
2714 | array in turn, and the expansion is the resultant list. | |
09767ff0 CR |
2715 | .TP |
2716 | ${\fIparameter\fP\fB^\fP\fIpattern\fP} | |
2717 | .PD 0 | |
2718 | .TP | |
2719 | ${\fIparameter\fP\fB^^\fP\fIpattern\fP} | |
2720 | .TP | |
2721 | ${\fIparameter\fP\fB,\fP\fIpattern\fP} | |
2722 | .TP | |
2723 | ${\fIparameter\fP\fB,,\fP\fIpattern\fP} | |
2724 | .PD | |
36211029 | 2725 | \fBCase modification.\fP |
09767ff0 CR |
2726 | This expansion modifies the case of alphabetic characters in \fIparameter\fP. |
2727 | The \fIpattern\fP is expanded to produce a pattern just as in | |
2728 | pathname expansion. | |
2729 | The \fB^\fP operator converts lowercase letters matching \fIpattern\fP | |
2730 | to uppercase; the \fB,\fP operator converts matching uppercase letters | |
2731 | to lowercase. | |
2732 | The \fB^^\fP and \fB,,\fP expansions convert each matched character in the | |
2733 | expanded value; the \fB^\fP and \fB,\fP expansions match and convert only | |
e141c35a | 2734 | the first character in the expanded value.. |
09767ff0 CR |
2735 | If \fIpattern\fP is omitted, it is treated like a \fB?\fP, which matches |
2736 | every character. | |
2737 | If | |
2738 | .I parameter | |
2739 | is | |
2740 | .B @ | |
2741 | or | |
2742 | .BR * , | |
2743 | the case modification operation is applied to each positional | |
2744 | parameter in turn, and the expansion is the resultant list. | |
2745 | If | |
2746 | .I parameter | |
2747 | is an array variable subscripted with | |
2748 | .B @ | |
2749 | or | |
2750 | .BR * , | |
2751 | the case modification operation is applied to each member of the | |
2752 | array in turn, and the expansion is the resultant list. | |
726f6388 JA |
2753 | .SS Command Substitution |
2754 | .PP | |
cce855bc | 2755 | \fICommand substitution\fP allows the output of a command to replace |
726f6388 JA |
2756 | the command name. There are two forms: |
2757 | .PP | |
2758 | .RS | |
2759 | .PP | |
2760 | \fB$(\fP\fIcommand\fP\|\fB)\fP | |
2761 | .RE | |
2762 | or | |
2763 | .RS | |
3d4e09aa | 2764 | \fB\`\fP\fIcommand\fP\fB\`\fP |
726f6388 JA |
2765 | .RE |
2766 | .PP | |
ccc6cda3 | 2767 | .B Bash |
726f6388 JA |
2768 | performs the expansion by executing \fIcommand\fP and |
2769 | replacing the command substitution with the standard output of the | |
2770 | command, with any trailing newlines deleted. | |
cce855bc JA |
2771 | Embedded newlines are not deleted, but they may be removed during |
2772 | word splitting. | |
2773 | The command substitution \fB$(cat \fIfile\fP)\fR can be replaced by | |
2774 | the equivalent but faster \fB$(< \fIfile\fP)\fR. | |
726f6388 | 2775 | .PP |
ccc6cda3 | 2776 | When the old-style backquote form of substitution is used, |
726f6388 JA |
2777 | backslash retains its literal meaning except when followed by |
2778 | .BR $ , | |
3d4e09aa | 2779 | .BR \` , |
726f6388 JA |
2780 | or |
2781 | .BR \e . | |
cce855bc JA |
2782 | The first backquote not preceded by a backslash terminates the |
2783 | command substitution. | |
726f6388 JA |
2784 | When using the $(\^\fIcommand\fP\|) form, all characters between the |
2785 | parentheses make up the command; none are treated specially. | |
2786 | .PP | |
cce855bc | 2787 | Command substitutions may be nested. To nest when using the backquoted form, |
726f6388 JA |
2788 | escape the inner backquotes with backslashes. |
2789 | .PP | |
2790 | If the substitution appears within double quotes, word splitting and | |
2791 | pathname expansion are not performed on the results. | |
2792 | .SS Arithmetic Expansion | |
2793 | .PP | |
2794 | Arithmetic expansion allows the evaluation of an arithmetic expression | |
ccc6cda3 | 2795 | and the substitution of the result. The format for arithmetic expansion is: |
726f6388 JA |
2796 | .RS |
2797 | .PP | |
726f6388 JA |
2798 | \fB$((\fP\fIexpression\fP\fB))\fP |
2799 | .RE | |
2800 | .PP | |
2801 | The | |
2802 | .I expression | |
2803 | is treated as if it were within double quotes, but a double quote | |
ccc6cda3 JA |
2804 | inside the parentheses is not treated specially. |
2805 | All tokens in the expression undergo parameter expansion, string | |
2806 | expansion, command substitution, and quote removal. | |
d3a24ed2 | 2807 | Arithmetic expansions may be nested. |
726f6388 JA |
2808 | .PP |
2809 | The evaluation is performed according to the rules listed below under | |
2810 | .SM | |
2811 | .BR "ARITHMETIC EVALUATION" . | |
2812 | If | |
2813 | .I expression | |
2814 | is invalid, | |
2815 | .B bash | |
2816 | prints a message indicating failure and no substitution occurs. | |
2817 | .SS Process Substitution | |
2818 | .PP | |
2819 | \fIProcess substitution\fP is supported on systems that support named | |
2820 | pipes (\fIFIFOs\fP) or the \fB/dev/fd\fP method of naming open files. | |
2821 | It takes the form of | |
2822 | \fB<(\fP\fIlist\^\fP\fB)\fP | |
2823 | or | |
2824 | \fB>(\fP\fIlist\^\fP\fB)\fP. | |
2825 | The process \fIlist\fP is run with its input or output connected to a | |
2826 | \fIFIFO\fP or some file in \fB/dev/fd\fP. The name of this file is | |
2827 | passed as an argument to the current command as the result of the | |
2828 | expansion. If the \fB>(\fP\fIlist\^\fP\fB)\fP form is used, writing to | |
2829 | the file will provide input for \fIlist\fP. If the | |
2830 | \fB<(\fP\fIlist\^\fP\fB)\fP form is used, the file passed as an | |
2831 | argument should be read to obtain the output of \fIlist\fP. | |
2832 | .PP | |
bb70624e | 2833 | When available, process substitution is performed |
ccc6cda3 JA |
2834 | simultaneously with parameter and variable expansion, |
2835 | command substitution, | |
2836 | and arithmetic expansion. | |
726f6388 JA |
2837 | .SS Word Splitting |
2838 | .PP | |
2839 | The shell scans the results of | |
2840 | parameter expansion, | |
2841 | command substitution, | |
2842 | and | |
2843 | arithmetic expansion | |
2844 | that did not occur within double quotes for | |
2845 | .IR "word splitting" . | |
2846 | .PP | |
2847 | The shell treats each character of | |
2848 | .SM | |
2849 | .B IFS | |
2850 | as a delimiter, and splits the results of the other | |
ccc6cda3 | 2851 | expansions into words on these characters. If |
726f6388 JA |
2852 | .SM |
2853 | .B IFS | |
ccc6cda3 JA |
2854 | is unset, or its |
2855 | value is exactly | |
726f6388 JA |
2856 | .BR <space><tab><newline> , |
2857 | the default, then | |
d3ad40de CR |
2858 | sequences of |
2859 | .BR <space> , | |
2860 | .BR <tab> , | |
2861 | and | |
2862 | .B <newline> | |
2863 | at the beginning and end of the results of the previous | |
2864 | expansions are ignored, and | |
726f6388 JA |
2865 | any sequence of |
2866 | .SM | |
2867 | .B IFS | |
d3ad40de CR |
2868 | characters not at the beginning or end serves to delimit words. |
2869 | If | |
726f6388 JA |
2870 | .SM |
2871 | .B IFS | |
2872 | has a value other than the default, then sequences of | |
2873 | the whitespace characters | |
2874 | .B space | |
2875 | and | |
2876 | .B tab | |
2877 | are ignored at the beginning and end of the | |
2878 | word, as long as the whitespace character is in the | |
2879 | value of | |
2880 | .SM | |
2881 | .BR IFS | |
2882 | (an | |
2883 | .SM | |
2884 | .B IFS | |
2885 | whitespace character). | |
2886 | Any character in | |
2887 | .SM | |
2888 | .B IFS | |
2889 | that is not | |
2890 | .SM | |
2891 | .B IFS | |
2892 | whitespace, along with any adjacent | |
2893 | .SM | |
2894 | .B IFS | |
2895 | whitespace characters, delimits a field. | |
2896 | A sequence of | |
2897 | .SM | |
2898 | .B IFS | |
2899 | whitespace characters is also treated as a delimiter. | |
2900 | If the value of | |
2901 | .SM | |
2902 | .B IFS | |
2903 | is null, no word splitting occurs. | |
726f6388 | 2904 | .PP |
20587658 | 2905 | Explicit null arguments (\^\f3"\^"\fP or \^\f3\(aq\^\(aq\fP\^) are retained. |
ccc6cda3 | 2906 | Unquoted implicit null arguments, resulting from the expansion of |
bb70624e | 2907 | parameters that have no values, are removed. |
ccc6cda3 JA |
2908 | If a parameter with no value is expanded within double quotes, a |
2909 | null argument results and is retained. | |
726f6388 JA |
2910 | .PP |
2911 | Note that if no expansion occurs, no splitting | |
2912 | is performed. | |
2913 | .SS Pathname Expansion | |
2914 | .PP | |
2915 | After word splitting, | |
2916 | unless the | |
2917 | .B \-f | |
2918 | option has been set, | |
2919 | .B bash | |
ccc6cda3 | 2920 | scans each word for the characters |
726f6388 JA |
2921 | .BR * , |
2922 | .BR ? , | |
2923 | and | |
2924 | .BR [ . | |
2925 | If one of these characters appears, then the word is | |
2926 | regarded as a | |
2927 | .IR pattern , | |
2928 | and replaced with an alphabetically sorted list of | |
ccc6cda3 JA |
2929 | file names matching the pattern. |
2930 | If no matching file names are found, | |
2931 | and the shell option | |
2932 | .B nullglob | |
57a3f689 | 2933 | is not enabled, the word is left unchanged. |
cce855bc JA |
2934 | If the |
2935 | .B nullglob | |
2936 | option is set, and no matches are found, | |
726f6388 | 2937 | the word is removed. |
d3a24ed2 CR |
2938 | If the |
2939 | .B failglob | |
2940 | shell option is set, and no matches are found, an error message | |
2941 | is printed and the command is not executed. | |
cce855bc JA |
2942 | If the shell option |
2943 | .B nocaseglob | |
2944 | is enabled, the match is performed without regard to the case | |
2945 | of alphabetic characters. | |
ccc6cda3 | 2946 | When a pattern is used for pathname expansion, |
726f6388 JA |
2947 | the character |
2948 | .B ``.'' | |
2949 | at the start of a name or immediately following a slash | |
ccc6cda3 JA |
2950 | must be matched explicitly, unless the shell option |
2951 | .B dotglob | |
2952 | is set. | |
cce855bc JA |
2953 | When matching a pathname, the slash character must always be |
2954 | matched explicitly. | |
ccc6cda3 | 2955 | In other cases, the |
726f6388 JA |
2956 | .B ``.'' |
2957 | character is not treated specially. | |
ccc6cda3 JA |
2958 | See the description of |
2959 | .B shopt | |
2960 | below under | |
2961 | .SM | |
2962 | .B SHELL BUILTIN COMMANDS | |
2963 | for a description of the | |
cce855bc JA |
2964 | .BR nocaseglob , |
2965 | .BR nullglob , | |
d3a24ed2 | 2966 | .BR failglob , |
ccc6cda3 JA |
2967 | and |
2968 | .B dotglob | |
2969 | shell options. | |
2970 | .PP | |
2971 | The | |
2972 | .SM | |
2973 | .B GLOBIGNORE | |
2974 | shell variable may be used to restrict the set of file names matching a | |
2975 | .IR pattern . | |
2976 | If | |
2977 | .SM | |
2978 | .B GLOBIGNORE | |
2979 | is set, each matching file name that also matches one of the patterns in | |
2980 | .SM | |
2981 | .B GLOBIGNORE | |
2982 | is removed from the list of matches. | |
2983 | The file names | |
2984 | .B ``.'' | |
2985 | and | |
2986 | .B ``..'' | |
d3a24ed2 | 2987 | are always ignored when |
ccc6cda3 JA |
2988 | .SM |
2989 | .B GLOBIGNORE | |
d3a24ed2 | 2990 | is set and not null. However, setting |
ccc6cda3 JA |
2991 | .SM |
2992 | .B GLOBIGNORE | |
d3a24ed2 | 2993 | to a non-null value has the effect of enabling the |
ccc6cda3 JA |
2994 | .B dotglob |
2995 | shell option, so all other file names beginning with a | |
2996 | .B ``.'' | |
2997 | will match. | |
2998 | To get the old behavior of ignoring file names beginning with a | |
2999 | .BR ``.'' , | |
3000 | make | |
3001 | .B ``.*'' | |
3002 | one of the patterns in | |
3003 | .SM | |
3004 | .BR GLOBIGNORE . | |
3005 | The | |
3006 | .B dotglob | |
3007 | option is disabled when | |
3008 | .SM | |
3009 | .B GLOBIGNORE | |
3010 | is unset. | |
726f6388 | 3011 | .PP |
cce855bc JA |
3012 | \fBPattern Matching\fP |
3013 | .PP | |
3014 | Any character that appears in a pattern, other than the special pattern | |
3015 | characters described below, matches itself. The NUL character may not | |
d3a24ed2 CR |
3016 | occur in a pattern. A backslash escapes the following character; the |
3017 | escaping backslash is discarded when matching. | |
3018 | The special pattern characters must be quoted if | |
cce855bc JA |
3019 | they are to be matched literally. |
3020 | .PP | |
726f6388 JA |
3021 | The special pattern characters have the following meanings: |
3022 | .PP | |
3023 | .PD 0 | |
3024 | .TP | |
3025 | .B * | |
3026 | Matches any string, including the null string. | |
4ac1ff98 | 3027 | When the \fBglobstar\fP shell option is enabled, and \fB*\fP is used in |
d0ca3503 | 3028 | a pathname expansion context, two adjacent \fB*\fPs used as a single |
4ac1ff98 CR |
3029 | pattern will match all files and zero or more directories and |
3030 | subdirectories. | |
3031 | If followed by a \fB/\fP, two adjacent \fB*\fPs will match only directories | |
3032 | and subdirectories. | |
726f6388 JA |
3033 | .TP |
3034 | .B ? | |
3035 | Matches any single character. | |
3036 | .TP | |
3037 | .B [...] | |
3038 | Matches any one of the enclosed characters. A pair of characters | |
28ef6c31 JA |
3039 | separated by a hyphen denotes a |
3040 | \fIrange expression\fP; | |
3041 | any character that sorts between those two characters, inclusive, | |
3042 | using the current locale's collating sequence and character set, | |
726f6388 JA |
3043 | is matched. If the first character following the |
3044 | .B [ | |
3045 | is a | |
3046 | .B ! | |
3047 | or a | |
3048 | .B ^ | |
ccc6cda3 | 3049 | then any character not enclosed is matched. |
28ef6c31 JA |
3050 | The sorting order of characters in range expressions is determined by |
3051 | the current locale and the value of the \fBLC_COLLATE\fP shell variable, | |
3052 | if set. | |
ccc6cda3 | 3053 | A |
726f6388 | 3054 | .B \- |
726f6388 JA |
3055 | may be matched by including it as the first or last character |
3056 | in the set. | |
ccc6cda3 JA |
3057 | A |
3058 | .B ] | |
3059 | may be matched by including it as the first character | |
3060 | in the set. | |
cce855bc JA |
3061 | .br |
3062 | .if t .sp 0.5 | |
3063 | .if n .sp 1 | |
3064 | Within | |
3065 | .B [ | |
3066 | and | |
3067 | .BR ] , | |
3068 | \fIcharacter classes\fP can be specified using the syntax | |
3069 | \fB[:\fP\fIclass\fP\fB:]\fP, where \fIclass\fP is one of the | |
ac18b312 | 3070 | following classes defined in the POSIX standard: |
cce855bc JA |
3071 | .PP |
3072 | .RS | |
3073 | .B | |
7117c2d2 JA |
3074 | .if n alnum alpha ascii blank cntrl digit graph lower print punct space upper word xdigit |
3075 | .if t alnum alpha ascii blank cntrl digit graph lower print punct space upper word xdigit | |
cce855bc JA |
3076 | .br |
3077 | A character class matches any character belonging to that class. | |
7117c2d2 | 3078 | The \fBword\fP character class matches letters, digits, and the character _. |
cce855bc JA |
3079 | .br |
3080 | .if t .sp 0.5 | |
3081 | .if n .sp 1 | |
3082 | Within | |
3083 | .B [ | |
3084 | and | |
3085 | .BR ] , | |
3086 | an \fIequivalence class\fP can be specified using the syntax | |
3087 | \fB[=\fP\fIc\fP\fB=]\fP, which matches all characters with the | |
3088 | same collation weight (as defined by the current locale) as | |
3089 | the character \fIc\fP. | |
3090 | .br | |
3091 | .if t .sp 0.5 | |
3092 | .if n .sp 1 | |
3093 | Within | |
3094 | .B [ | |
3095 | and | |
3096 | .BR ] , | |
3097 | the syntax \fB[.\fP\fIsymbol\fP\fB.]\fP matches the collating symbol | |
3098 | \fIsymbol\fP. | |
3099 | .RE | |
3100 | .PD | |
3101 | .PP | |
3102 | If the \fBextglob\fP shell option is enabled using the \fBshopt\fP | |
3103 | builtin, several extended pattern matching operators are recognized. | |
bb70624e | 3104 | In the following description, a \fIpattern-list\fP is a list of one |
cce855bc JA |
3105 | or more patterns separated by a \fB|\fP. |
3106 | Composite patterns may be formed using one or more of the following | |
3107 | sub-patterns: | |
3108 | .sp 1 | |
3109 | .PD 0 | |
3110 | .RS | |
3111 | .TP | |
3112 | \fB?(\fP\^\fIpattern-list\^\fP\fB)\fP | |
3113 | Matches zero or one occurrence of the given patterns | |
3114 | .TP | |
3115 | \fB*(\fP\^\fIpattern-list\^\fP\fB)\fP | |
3116 | Matches zero or more occurrences of the given patterns | |
3117 | .TP | |
3118 | \fB+(\fP\^\fIpattern-list\^\fP\fB)\fP | |
3119 | Matches one or more occurrences of the given patterns | |
3120 | .TP | |
3121 | \fB@(\fP\^\fIpattern-list\^\fP\fB)\fP | |
43df7bbb | 3122 | Matches one of the given patterns |
cce855bc JA |
3123 | .TP |
3124 | \fB!(\fP\^\fIpattern-list\^\fP\fB)\fP | |
3125 | Matches anything except one of the given patterns | |
3126 | .RE | |
726f6388 JA |
3127 | .PD |
3128 | .SS Quote Removal | |
3129 | .PP | |
3130 | After the preceding expansions, all unquoted occurrences of the | |
3131 | characters | |
3132 | .BR \e , | |
20587658 | 3133 | .BR \(aq , |
ccc6cda3 JA |
3134 | and \^\f3"\fP\^ that did not result from one of the above |
3135 | expansions are removed. | |
726f6388 JA |
3136 | .SH REDIRECTION |
3137 | Before a command is executed, its input and output | |
3138 | may be | |
3139 | .I redirected | |
3140 | using a special notation interpreted by the shell. | |
3141 | Redirection may also be used to open and close files for the | |
3142 | current shell execution environment. The following redirection | |
3143 | operators may precede or appear anywhere within a | |
3144 | .I simple command | |
3145 | or may follow a | |
3146 | .IR command . | |
3147 | Redirections are processed in the order they appear, from | |
3148 | left to right. | |
3149 | .PP | |
3150 | In the following descriptions, if the file descriptor number is | |
3151 | omitted, and the first character of the redirection operator is | |
3152 | .BR < , | |
3153 | the redirection refers to the standard input (file descriptor | |
3154 | 0). If the first character of the redirection operator is | |
3155 | .BR > , | |
3156 | the redirection refers to the standard output (file descriptor | |
3157 | 1). | |
3158 | .PP | |
cce855bc JA |
3159 | The word following the redirection operator in the following |
3160 | descriptions, unless otherwise noted, is subjected to brace expansion, | |
3161 | tilde expansion, parameter expansion, command substitution, arithmetic | |
bb70624e | 3162 | expansion, quote removal, pathname expansion, and word splitting. |
cce855bc | 3163 | If it expands to more than one word, |
726f6388 JA |
3164 | .B bash |
3165 | reports an error. | |
3166 | .PP | |
3167 | Note that the order of redirections is significant. For example, | |
3168 | the command | |
3169 | .RS | |
3170 | .PP | |
3171 | ls \fB>\fP dirlist 2\fB>&\fP1 | |
3172 | .RE | |
3173 | .PP | |
3174 | directs both standard output and standard error to the file | |
3175 | .IR dirlist , | |
3176 | while the command | |
3177 | .RS | |
3178 | .PP | |
3179 | ls 2\fB>&\fP1 \fB>\fP dirlist | |
3180 | .RE | |
3181 | .PP | |
3182 | directs only the standard output to file | |
3183 | .IR dirlist , | |
db31fb26 | 3184 | because the standard error was duplicated from the standard output |
726f6388 JA |
3185 | before the standard output was redirected to |
3186 | .IR dirlist . | |
cce855bc | 3187 | .PP |
bb70624e JA |
3188 | \fBBash\fP handles several filenames specially when they are used in |
3189 | redirections, as described in the following table: | |
3190 | .RS | |
3191 | .PP | |
3192 | .PD 0 | |
3193 | .TP | |
3194 | .B /dev/fd/\fIfd\fP | |
3195 | If \fIfd\fP is a valid integer, file descriptor \fIfd\fP is duplicated. | |
3196 | .TP | |
3197 | .B /dev/stdin | |
3198 | File descriptor 0 is duplicated. | |
3199 | .TP | |
3200 | .B /dev/stdout | |
3201 | File descriptor 1 is duplicated. | |
3202 | .TP | |
3203 | .B /dev/stderr | |
3204 | File descriptor 2 is duplicated. | |
3205 | .TP | |
3206 | .B /dev/tcp/\fIhost\fP/\fIport\fP | |
3207 | If \fIhost\fP is a valid hostname or Internet address, and \fIport\fP | |
f73dda09 JA |
3208 | is an integer port number or service name, \fBbash\fP attempts to open |
3209 | a TCP connection to the corresponding socket. | |
bb70624e JA |
3210 | .TP |
3211 | .B /dev/udp/\fIhost\fP/\fIport\fP | |
3212 | If \fIhost\fP is a valid hostname or Internet address, and \fIport\fP | |
f73dda09 JA |
3213 | is an integer port number or service name, \fBbash\fP attempts to open |
3214 | a UDP connection to the corresponding socket. | |
bb70624e JA |
3215 | .PD |
3216 | .RE | |
3217 | .PP | |
cce855bc | 3218 | A failure to open or create a file causes the redirection to fail. |
cac4cdbf CR |
3219 | .PP |
3220 | Redirections using file descriptors greater than 9 should be used with | |
3221 | care, as they may conflict with file descriptors the shell uses | |
3222 | internally. | |
726f6388 JA |
3223 | .SS Redirecting Input |
3224 | .PP | |
3225 | Redirection of input causes the file whose name results from | |
3226 | the expansion of | |
3227 | .I word | |
3228 | to be opened for reading on file descriptor | |
3229 | .IR n , | |
3230 | or the standard input (file descriptor 0) if | |
3231 | .I n | |
3232 | is not specified. | |
3233 | .PP | |
3234 | The general format for redirecting input is: | |
3235 | .RS | |
3236 | .PP | |
3237 | [\fIn\fP]\fB<\fP\fIword\fP | |
3238 | .RE | |
3239 | .SS Redirecting Output | |
3240 | .PP | |
3241 | Redirection of output causes the file whose name results from | |
3242 | the expansion of | |
3243 | .I word | |
3244 | to be opened for writing on file descriptor | |
3245 | .IR n , | |
3246 | or the standard output (file descriptor 1) if | |
3247 | .I n | |
3248 | is not specified. If the file does not exist it is created; | |
3249 | if it does exist it is truncated to zero size. | |
3250 | .PP | |
3251 | The general format for redirecting output is: | |
3252 | .RS | |
3253 | .PP | |
3254 | [\fIn\fP]\fB>\fP\fIword\fP | |
3255 | .RE | |
3256 | .PP | |
3257 | If the redirection operator is | |
ccc6cda3 JA |
3258 | .BR > , |
3259 | and the | |
cce855bc | 3260 | .B noclobber |
ccc6cda3 JA |
3261 | option to the |
3262 | .B set | |
bb70624e | 3263 | builtin has been enabled, the redirection will fail if the file |
cce855bc JA |
3264 | whose name results from the expansion of \fIword\fP exists and is |
3265 | a regular file. | |
ccc6cda3 | 3266 | If the redirection operator is |
726f6388 | 3267 | .BR >| , |
cce855bc JA |
3268 | or the redirection operator is |
3269 | .B > | |
3270 | and the | |
3271 | .B noclobber | |
726f6388 JA |
3272 | option to the |
3273 | .B set | |
cce855bc | 3274 | builtin command is not enabled, the redirection is attempted even |
ccc6cda3 | 3275 | if the file named by \fIword\fP exists. |
726f6388 JA |
3276 | .SS Appending Redirected Output |
3277 | .PP | |
3278 | Redirection of output in this fashion | |
3279 | causes the file whose name results from | |
3280 | the expansion of | |
3281 | .I word | |
3282 | to be opened for appending on file descriptor | |
3283 | .IR n , | |
3284 | or the standard output (file descriptor 1) if | |
3285 | .I n | |
3286 | is not specified. If the file does not exist it is created. | |
3287 | .PP | |
3288 | The general format for appending output is: | |
3289 | .RS | |
3290 | .PP | |
3291 | [\fIn\fP]\fB>>\fP\fIword\fP | |
3292 | .RE | |
3293 | .PP | |
3294 | .SS Redirecting Standard Output and Standard Error | |
3295 | .PP | |
8943768b | 3296 | This construct allows both the |
726f6388 JA |
3297 | standard output (file descriptor 1) and |
3298 | the standard error output (file descriptor 2) | |
3299 | to be redirected to the file whose name is the | |
3300 | expansion of | |
8943768b | 3301 | .IR word . |
726f6388 JA |
3302 | .PP |
3303 | There are two formats for redirecting standard output and | |
3304 | standard error: | |
3305 | .RS | |
3306 | .PP | |
3307 | \fB&>\fP\fIword\fP | |
3308 | .RE | |
3309 | and | |
3310 | .RS | |
3311 | \fB>&\fP\fIword\fP | |
3312 | .RE | |
3313 | .PP | |
3314 | Of the two forms, the first is preferred. | |
3315 | This is semantically equivalent to | |
3316 | .RS | |
3317 | .PP | |
3318 | \fB>\fP\fIword\fP 2\fB>&\fP1 | |
3319 | .RE | |
8943768b CR |
3320 | .PP |
3321 | .SS Appending Standard Output and Standard Error | |
3322 | .PP | |
3323 | This construct allows both the | |
3324 | standard output (file descriptor 1) and | |
3325 | the standard error output (file descriptor 2) | |
3326 | to be appended to the file whose name is the | |
3327 | expansion of | |
3328 | .IR word . | |
3329 | .PP | |
3330 | The format for appending standard output and standard error is: | |
3331 | .RS | |
3332 | .PP | |
3333 | \fB&>>\fP\fIword\fP | |
3334 | .RE | |
3335 | .PP | |
3336 | This is semantically equivalent to | |
3337 | .RS | |
3338 | .PP | |
3339 | \fB>>\fP\fIword\fP 2\fB>&\fP1 | |
3340 | .RE | |
726f6388 JA |
3341 | .SS Here Documents |
3342 | .PP | |
3343 | This type of redirection instructs the shell to read input from the | |
3344 | current source until a line containing only | |
626d0694 | 3345 | .I delimiter |
726f6388 JA |
3346 | (with no trailing blanks) |
3347 | is seen. All of | |
3348 | the lines read up to that point are then used as the standard | |
3349 | input for a command. | |
3350 | .PP | |
7117c2d2 | 3351 | The format of here-documents is: |
726f6388 JA |
3352 | .RS |
3353 | .PP | |
3354 | .nf | |
3355 | \fB<<\fP[\fB\-\fP]\fIword\fP | |
f73dda09 | 3356 | \fIhere-document\fP |
726f6388 JA |
3357 | \fIdelimiter\fP |
3358 | .fi | |
3359 | .RE | |
3360 | .PP | |
bb70624e JA |
3361 | No parameter expansion, command substitution, arithmetic expansion, |
3362 | or pathname expansion is performed on | |
726f6388 JA |
3363 | .IR word . |
3364 | If any characters in | |
3365 | .I word | |
3366 | are quoted, the | |
3367 | .I delimiter | |
3368 | is the result of quote removal on | |
3369 | .IR word , | |
cce855bc JA |
3370 | and the lines in the here-document are not expanded. |
3371 | If \fIword\fP is unquoted, | |
726f6388 JA |
3372 | all lines of the here-document are subjected to parameter expansion, |
3373 | command substitution, and arithmetic expansion. In the latter | |
bb70624e | 3374 | case, the character sequence |
726f6388 JA |
3375 | .B \e<newline> |
3376 | is ignored, and | |
3377 | .B \e | |
3378 | must be used to quote the characters | |
3379 | .BR \e , | |
3380 | .BR $ , | |
3381 | and | |
3d4e09aa | 3382 | .BR \` . |
726f6388 JA |
3383 | .PP |
3384 | If the redirection operator is | |
3385 | .BR <<\- , | |
3386 | then all leading tab characters are stripped from input lines and the | |
3387 | line containing | |
3388 | .IR delimiter . | |
3389 | This allows | |
3390 | here-documents within shell scripts to be indented in a | |
3391 | natural fashion. | |
7117c2d2 JA |
3392 | .SS "Here Strings" |
3393 | A variant of here documents, the format is: | |
3394 | .RS | |
3395 | .PP | |
3396 | .nf | |
3397 | \fB<<<\fP\fIword\fP | |
3398 | .fi | |
3399 | .RE | |
3400 | .PP | |
3401 | The \fIword\fP is expanded and supplied to the command on its standard | |
3402 | input. | |
726f6388 JA |
3403 | .SS "Duplicating File Descriptors" |
3404 | .PP | |
3405 | The redirection operator | |
3406 | .RS | |
3407 | .PP | |
3408 | [\fIn\fP]\fB<&\fP\fIword\fP | |
3409 | .RE | |
3410 | .PP | |
3411 | is used to duplicate input file descriptors. | |
3412 | If | |
3413 | .I word | |
3414 | expands to one or more digits, the file descriptor denoted by | |
3415 | .I n | |
cce855bc JA |
3416 | is made to be a copy of that file descriptor. |
3417 | If the digits in | |
3418 | .I word | |
3419 | do not specify a file descriptor open for input, a redirection error occurs. | |
3420 | If | |
726f6388 JA |
3421 | .I word |
3422 | evaluates to | |
3423 | .BR \- , | |
3424 | file descriptor | |
3425 | .I n | |
3426 | is closed. If | |
3427 | .I n | |
3428 | is not specified, the standard input (file descriptor 0) is used. | |
3429 | .PP | |
3430 | The operator | |
3431 | .RS | |
3432 | .PP | |
3433 | [\fIn\fP]\fB>&\fP\fIword\fP | |
3434 | .RE | |
3435 | .PP | |
3436 | is used similarly to duplicate output file descriptors. If | |
3437 | .I n | |
3438 | is not specified, the standard output (file descriptor 1) is used. | |
cce855bc JA |
3439 | If the digits in |
3440 | .I word | |
3441 | do not specify a file descriptor open for output, a redirection error occurs. | |
726f6388 JA |
3442 | As a special case, if \fIn\fP is omitted, and \fIword\fP does not |
3443 | expand to one or more digits, the standard output and standard | |
3444 | error are redirected as described previously. | |
7117c2d2 JA |
3445 | .SS "Moving File Descriptors" |
3446 | .PP | |
3447 | The redirection operator | |
3448 | .RS | |
3449 | .PP | |
3450 | [\fIn\fP]\fB<&\fP\fIdigit\fP\fB\-\fP | |
3451 | .RE | |
3452 | .PP | |
3453 | moves the file descriptor \fIdigit\fP to file descriptor | |
3454 | .IR n , | |
3455 | or the standard input (file descriptor 0) if \fIn\fP is not specified. | |
3456 | \fIdigit\fP is closed after being duplicated to \fIn\fP. | |
3457 | .PP | |
3458 | Similarly, the redirection operator | |
3459 | .RS | |
3460 | .PP | |
3461 | [\fIn\fP]\fB>&\fP\fIdigit\fP\fB\-\fP | |
3462 | .RE | |
3463 | .PP | |
3464 | moves the file descriptor \fIdigit\fP to file descriptor | |
3465 | .IR n , | |
3466 | or the standard output (file descriptor 1) if \fIn\fP is not specified. | |
726f6388 JA |
3467 | .SS "Opening File Descriptors for Reading and Writing" |
3468 | .PP | |
3469 | The redirection operator | |
3470 | .RS | |
3471 | .PP | |
3472 | [\fIn\fP]\fB<>\fP\fIword\fP | |
3473 | .RE | |
3474 | .PP | |
3475 | causes the file whose name is the expansion of | |
3476 | .I word | |
3477 | to be opened for both reading and writing on file descriptor | |
3478 | .IR n , | |
ccc6cda3 | 3479 | or on file descriptor 0 if |
726f6388 JA |
3480 | .I n |
3481 | is not specified. If the file does not exist, it is created. | |
726f6388 | 3482 | .SH ALIASES |
bb70624e | 3483 | \fIAliases\fP allow a string to be substituted for a word when it is used |
cce855bc | 3484 | as the first word of a simple command. |
bb70624e | 3485 | The shell maintains a list of aliases that may be set and unset with the |
726f6388 JA |
3486 | .B alias |
3487 | and | |
3488 | .B unalias | |
3489 | builtin commands (see | |
3490 | .SM | |
3491 | .B SHELL BUILTIN COMMANDS | |
3492 | below). | |
de8913bd | 3493 | The first word of each simple command, if unquoted, |
726f6388 JA |
3494 | is checked to see if it has an |
3495 | alias. If so, that word is replaced by the text of the alias. | |
3d4e09aa | 3496 | The characters \fB/\fP, \fB$\fP, \fB\`\fP, and \fB=\fP and |
de8913bd CR |
3497 | any of the shell \fImetacharacters\fP or quoting characters |
3498 | listed above may not appear in an alias name. | |
3499 | The replacement text may contain any valid shell input, | |
3500 | including shell metacharacters. | |
3501 | The first word of the replacement text is tested | |
726f6388 | 3502 | for aliases, but a word that is identical to an alias being expanded |
de8913bd CR |
3503 | is not expanded a second time. |
3504 | This means that one may alias | |
726f6388 JA |
3505 | .B ls |
3506 | to | |
3507 | .BR "ls \-F" , | |
3508 | for instance, and | |
3509 | .B bash | |
3510 | does not try to recursively expand the replacement text. | |
3511 | If the last character of the alias value is a | |
3512 | .IR blank , | |
3513 | then the next command | |
3514 | word following the alias is also checked for alias expansion. | |
3515 | .PP | |
3516 | Aliases are created and listed with the | |
3517 | .B alias | |
3518 | command, and removed with the | |
3519 | .B unalias | |
3520 | command. | |
3521 | .PP | |
ccc6cda3 | 3522 | There is no mechanism for using arguments in the replacement text. |
bb70624e JA |
3523 | If arguments are needed, a shell function should be used (see |
3524 | .SM | |
3525 | .B FUNCTIONS | |
3526 | below). | |
726f6388 | 3527 | .PP |
ccc6cda3 JA |
3528 | Aliases are not expanded when the shell is not interactive, unless |
3529 | the | |
3530 | .B expand_aliases | |
3531 | shell option is set using | |
3532 | .B shopt | |
3533 | (see the description of | |
3534 | .B shopt | |
3535 | under | |
3536 | .SM | |
3537 | \fBSHELL BUILTIN COMMANDS\fP | |
3538 | below). | |
726f6388 JA |
3539 | .PP |
3540 | The rules concerning the definition and use of aliases are | |
3541 | somewhat confusing. | |
3542 | .B Bash | |
3543 | always reads at least one complete line | |
3544 | of input before executing any | |
3545 | of the commands on that line. Aliases are expanded when a | |
3546 | command is read, not when it is executed. Therefore, an | |
3547 | alias definition appearing on the same line as another | |
3548 | command does not take effect until the next line of input is read. | |
ccc6cda3 | 3549 | The commands following the alias definition |
726f6388 JA |
3550 | on that line are not affected by the new alias. |
3551 | This behavior is also an issue when functions are executed. | |
cce855bc | 3552 | Aliases are expanded when a function definition is read, |
726f6388 JA |
3553 | not when the function is executed, because a function definition |
3554 | is itself a compound command. As a consequence, aliases | |
3555 | defined in a function are not available until after that | |
3556 | function is executed. To be safe, always put | |
3557 | alias definitions on a separate line, and do not use | |
3558 | .B alias | |
3559 | in compound commands. | |
3560 | .PP | |
cce855bc | 3561 | For almost every purpose, aliases are superseded by |
726f6388 | 3562 | shell functions. |
ccc6cda3 JA |
3563 | .SH FUNCTIONS |
3564 | A shell function, defined as described above under | |
3565 | .SM | |
3566 | .BR "SHELL GRAMMAR" , | |
3567 | stores a series of commands for later execution. | |
bb70624e JA |
3568 | When the name of a shell function is used as a simple command name, |
3569 | the list of commands associated with that function name is executed. | |
ccc6cda3 JA |
3570 | Functions are executed in the context of the |
3571 | current shell; no new process is created to interpret | |
3572 | them (contrast this with the execution of a shell script). | |
3573 | When a function is executed, the arguments to the | |
3574 | function become the positional parameters | |
bb70624e JA |
3575 | during its execution. |
3576 | The special parameter | |
ccc6cda3 | 3577 | .B # |
de8913bd | 3578 | is updated to reflect the change. Special parameter 0 |
bb70624e | 3579 | is unchanged. |
d3a24ed2 | 3580 | The first element of the |
bb70624e JA |
3581 | .SM |
3582 | .B FUNCNAME | |
3583 | variable is set to the name of the function while the function | |
3584 | is executing. | |
4301bca7 | 3585 | .PP |
bb70624e | 3586 | All other aspects of the shell execution |
ccc6cda3 | 3587 | environment are identical between a function and its caller |
4301bca7 | 3588 | with these exceptions: the |
ccc6cda3 JA |
3589 | .SM |
3590 | .B DEBUG | |
76a8d78d CR |
3591 | and |
3592 | .B RETURN | |
3593 | traps (see the description of the | |
ccc6cda3 JA |
3594 | .B trap |
3595 | builtin under | |
3596 | .SM | |
3597 | .B SHELL BUILTIN COMMANDS | |
76a8d78d | 3598 | below) are not inherited unless the function has been given the |
7117c2d2 JA |
3599 | \fBtrace\fP attribute (see the description of the |
3600 | .SM | |
3601 | .B declare | |
d3a24ed2 CR |
3602 | builtin below) or the |
3603 | \fB\-o functrace\fP shell option has been enabled with | |
3604 | the \fBset\fP builtin | |
4301bca7 CR |
3605 | (in which case all functions inherit the \fBDEBUG\fP and \fBRETURN\fP traps), |
3606 | and the | |
3607 | .SM | |
3608 | .B ERR | |
3609 | trap is not inherited unless the \fB\-o errtrace\fP shell option has | |
3610 | been enabled. | |
726f6388 | 3611 | .PP |
ccc6cda3 JA |
3612 | Variables local to the function may be declared with the |
3613 | .B local | |
3614 | builtin command. Ordinarily, variables and their values | |
3615 | are shared between the function and its caller. | |
726f6388 | 3616 | .PP |
ccc6cda3 JA |
3617 | If the builtin command |
3618 | .B return | |
3619 | is executed in a function, the function completes and | |
3620 | execution resumes with the next command after the function | |
d3a24ed2 CR |
3621 | call. |
3622 | Any command associated with the \fBRETURN\fP trap is executed | |
3623 | before execution resumes. | |
3624 | When a function completes, the values of the | |
ccc6cda3 JA |
3625 | positional parameters and the special parameter |
3626 | .B # | |
cce855bc | 3627 | are restored to the values they had prior to the function's |
ccc6cda3 | 3628 | execution. |
726f6388 | 3629 | .PP |
ccc6cda3 JA |
3630 | Function names and definitions may be listed with the |
3631 | .B \-f | |
726f6388 | 3632 | option to the |
ccc6cda3 JA |
3633 | .B declare |
3634 | or | |
3635 | .B typeset | |
3636 | builtin commands. The | |
3637 | .B \-F | |
3638 | option to | |
3639 | .B declare | |
3640 | or | |
3641 | .B typeset | |
d3a24ed2 CR |
3642 | will list the function names only |
3643 | (and optionally the source file and line number, if the \fBextdebug\fP | |
3644 | shell option is enabled). | |
ccc6cda3 JA |
3645 | Functions may be exported so that subshells |
3646 | automatically have them defined with the | |
3647 | .B \-f | |
3648 | option to the | |
3649 | .B export | |
3650 | builtin. | |
11a6f9a9 CR |
3651 | A function definition may be deleted using the \fB\-f\fP option to |
3652 | the | |
3653 | .B unset | |
3654 | builtin. | |
d3a24ed2 CR |
3655 | Note that shell functions and variables with the same name may result |
3656 | in multiple identically-named entries in the environment passed to the | |
3657 | shell's children. | |
3658 | Care should be taken in cases where this may cause a problem. | |
726f6388 | 3659 | .PP |
ccc6cda3 JA |
3660 | Functions may be recursive. No limit is imposed on the number |
3661 | of recursive calls. | |
cce855bc JA |
3662 | .SH "ARITHMETIC EVALUATION" |
3663 | The shell allows arithmetic expressions to be evaluated, under | |
d3a24ed2 CR |
3664 | certain circumstances (see the \fBlet\fP and \fBdeclare\fP builtin |
3665 | commands and \fBArithmetic Expansion\fP). | |
7117c2d2 | 3666 | Evaluation is done in fixed-width integers with no check for overflow, |
cce855bc | 3667 | though division by 0 is trapped and flagged as an error. |
d3a24ed2 CR |
3668 | The operators and their precedence, associativity, and values |
3669 | are the same as in the C language. | |
cce855bc JA |
3670 | The following list of operators is grouped into levels of |
3671 | equal-precedence operators. | |
3672 | The levels are listed in order of decreasing precedence. | |
726f6388 | 3673 | .PP |
cce855bc JA |
3674 | .PD 0 |
3675 | .TP | |
bb70624e JA |
3676 | .B \fIid\fP++ \fIid\fP\-\- |
3677 | variable post-increment and post-decrement | |
3678 | .TP | |
3679 | .B ++\fIid\fP \-\-\fIid\fP | |
3680 | variable pre-increment and pre-decrement | |
3681 | .TP | |
cce855bc JA |
3682 | .B \- + |
3683 | unary minus and plus | |
3684 | .TP | |
3685 | .B ! ~ | |
3686 | logical and bitwise negation | |
3687 | .TP | |
3688 | .B ** | |
3689 | exponentiation | |
3690 | .TP | |
3691 | .B * / % | |
3692 | multiplication, division, remainder | |
3693 | .TP | |
3694 | .B + \- | |
3695 | addition, subtraction | |
3696 | .TP | |
3697 | .B << >> | |
3698 | left and right bitwise shifts | |
3699 | .TP | |
3700 | .B <= >= < > | |
3701 | comparison | |
3702 | .TP | |
3703 | .B == != | |
3704 | equality and inequality | |
3705 | .TP | |
3706 | .B & | |
3707 | bitwise AND | |
3708 | .TP | |
3709 | .B ^ | |
3710 | bitwise exclusive OR | |
3711 | .TP | |
3712 | .B | | |
3713 | bitwise OR | |
3714 | .TP | |
3715 | .B && | |
3716 | logical AND | |
3717 | .TP | |
3718 | .B || | |
3719 | logical OR | |
3720 | .TP | |
3721 | .B \fIexpr\fP?\fIexpr\fP:\fIexpr\fP | |
d3a24ed2 | 3722 | conditional operator |
cce855bc JA |
3723 | .TP |
3724 | .B = *= /= %= += \-= <<= >>= &= ^= |= | |
3725 | assignment | |
bb70624e JA |
3726 | .TP |
3727 | .B \fIexpr1\fP , \fIexpr2\fP | |
3728 | comma | |
cce855bc | 3729 | .PD |
ccc6cda3 | 3730 | .PP |
cce855bc | 3731 | Shell variables are allowed as operands; parameter expansion is |
bb70624e JA |
3732 | performed before the expression is evaluated. |
3733 | Within an expression, shell variables may also be referenced by name | |
3734 | without using the parameter expansion syntax. | |
d3a24ed2 CR |
3735 | A shell variable that is null or unset evaluates to 0 when referenced |
3736 | by name without using the parameter expansion syntax. | |
bb70624e | 3737 | The value of a variable is evaluated as an arithmetic expression |
d3a24ed2 CR |
3738 | when it is referenced, or when a variable which has been given the |
3739 | \fIinteger\fP attribute using \fBdeclare -i\fP is assigned a value. | |
3740 | A null value evaluates to 0. | |
bb70624e | 3741 | A shell variable need not have its integer attribute |
cce855bc | 3742 | turned on to be used in an expression. |
ccc6cda3 | 3743 | .PP |
cce855bc JA |
3744 | Constants with a leading 0 are interpreted as octal numbers. |
3745 | A leading 0x or 0X denotes hexadecimal. | |
3746 | Otherwise, numbers take the form [\fIbase#\fP]n, where \fIbase\fP | |
3747 | is a decimal number between 2 and 64 representing the arithmetic | |
3748 | base, and \fIn\fP is a number in that base. | |
bb70624e | 3749 | If \fIbase#\fP is omitted, then base 10 is used. |
cce855bc | 3750 | The digits greater than 9 are represented by the lowercase letters, |
f73dda09 | 3751 | the uppercase letters, @, and _, in that order. |
cce855bc | 3752 | If \fIbase\fP is less than or equal to 36, lowercase and uppercase |
f75912ae | 3753 | letters may be used interchangeably to represent numbers between 10 |
cce855bc | 3754 | and 35. |
ccc6cda3 | 3755 | .PP |
cce855bc JA |
3756 | Operators are evaluated in order of precedence. Sub-expressions in |
3757 | parentheses are evaluated first and may override the precedence | |
3758 | rules above. | |
3759 | .SH "CONDITIONAL EXPRESSIONS" | |
3760 | Conditional expressions are used by the \fB[[\fP compound command and | |
3761 | the \fBtest\fP and \fB[\fP builtin commands to test file attributes | |
3762 | and perform string and arithmetic comparisons. | |
3763 | Expressions are formed from the following unary or binary primaries. | |
3764 | If any \fIfile\fP argument to one of the primaries is of the form | |
bb70624e JA |
3765 | \fI/dev/fd/n\fP, then file descriptor \fIn\fP is checked. |
3766 | If the \fIfile\fP argument to one of the primaries is one of | |
3767 | \fI/dev/stdin\fP, \fI/dev/stdout\fP, or \fI/dev/stderr\fP, file | |
3768 | descriptor 0, 1, or 2, respectively, is checked. | |
be7d8f2d CR |
3769 | .PP |
3770 | Unless otherwise specified, primaries that operate on files follow symbolic | |
3771 | links and operate on the target of the link, rather than the link itself. | |
cce855bc JA |
3772 | .sp 1 |
3773 | .PD 0 | |
3774 | .TP | |
3775 | .B \-a \fIfile\fP | |
3776 | True if \fIfile\fP exists. | |
3777 | .TP | |
3778 | .B \-b \fIfile\fP | |
3779 | True if \fIfile\fP exists and is a block special file. | |
3780 | .TP | |
3781 | .B \-c \fIfile\fP | |
3782 | True if \fIfile\fP exists and is a character special file. | |
3783 | .TP | |
3784 | .B \-d \fIfile\fP | |
3785 | True if \fIfile\fP exists and is a directory. | |
3786 | .TP | |
3787 | .B \-e \fIfile\fP | |
3788 | True if \fIfile\fP exists. | |
3789 | .TP | |
3790 | .B \-f \fIfile\fP | |
3791 | True if \fIfile\fP exists and is a regular file. | |
3792 | .TP | |
3793 | .B \-g \fIfile\fP | |
3794 | True if \fIfile\fP exists and is set-group-id. | |
3795 | .TP | |
b72432fd JA |
3796 | .B \-h \fIfile\fP |
3797 | True if \fIfile\fP exists and is a symbolic link. | |
3798 | .TP | |
cce855bc JA |
3799 | .B \-k \fIfile\fP |
3800 | True if \fIfile\fP exists and its ``sticky'' bit is set. | |
3801 | .TP | |
3802 | .B \-p \fIfile\fP | |
3803 | True if \fIfile\fP exists and is a named pipe (FIFO). | |
3804 | .TP | |
3805 | .B \-r \fIfile\fP | |
3806 | True if \fIfile\fP exists and is readable. | |
3807 | .TP | |
3808 | .B \-s \fIfile\fP | |
3809 | True if \fIfile\fP exists and has a size greater than zero. | |
3810 | .TP | |
3811 | .B \-t \fIfd\fP | |
3812 | True if file descriptor | |
3813 | .I fd | |
3814 | is open and refers to a terminal. | |
3815 | .TP | |
3816 | .B \-u \fIfile\fP | |
3817 | True if \fIfile\fP exists and its set-user-id bit is set. | |
3818 | .TP | |
3819 | .B \-w \fIfile\fP | |
3820 | True if \fIfile\fP exists and is writable. | |
3821 | .TP | |
3822 | .B \-x \fIfile\fP | |
3823 | True if \fIfile\fP exists and is executable. | |
3824 | .TP | |
3825 | .B \-O \fIfile\fP | |
3826 | True if \fIfile\fP exists and is owned by the effective user id. | |
3827 | .TP | |
3828 | .B \-G \fIfile\fP | |
3829 | True if \fIfile\fP exists and is owned by the effective group id. | |
3830 | .TP | |
3831 | .B \-L \fIfile\fP | |
3832 | True if \fIfile\fP exists and is a symbolic link. | |
3833 | .TP | |
3834 | .B \-S \fIfile\fP | |
3835 | True if \fIfile\fP exists and is a socket. | |
3836 | .TP | |
3837 | .B \-N \fIfile\fP | |
3838 | True if \fIfile\fP exists and has been modified since it was last read. | |
3839 | .TP | |
3840 | \fIfile1\fP \-\fBnt\fP \fIfile2\fP | |
7117c2d2 JA |
3841 | True if \fIfile1\fP is newer (according to modification date) than \fIfile2\fP, |
3842 | or if \fIfile1\fP exists and \fPfile2\fP does not. | |
cce855bc JA |
3843 | .TP |
3844 | \fIfile1\fP \-\fBot\fP \fIfile2\fP | |
7117c2d2 JA |
3845 | True if \fIfile1\fP is older than \fIfile2\fP, or if \fIfile2\fP exists |
3846 | and \fIfile1\fP does not. | |
cce855bc JA |
3847 | .TP |
3848 | \fIfile1\fP \fB\-ef\fP \fIfile2\fP | |
7117c2d2 | 3849 | True if \fIfile1\fP and \fIfile2\fP refer to the same device and |
cce855bc JA |
3850 | inode numbers. |
3851 | .TP | |
3852 | .B \-o \fIoptname\fP | |
3853 | True if shell option | |
3854 | .I optname | |
3855 | is enabled. | |
3856 | See the list of options under the description of the | |
3857 | .B \-o | |
3858 | option to the | |
3859 | .B set | |
3860 | builtin below. | |
3861 | .TP | |
3862 | .B \-z \fIstring\fP | |
3863 | True if the length of \fIstring\fP is zero. | |
3864 | .TP | |
cce855bc | 3865 | \fIstring\fP |
f085a21f CR |
3866 | .PD 0 |
3867 | .TP | |
3868 | .B \-n \fIstring\fP | |
3869 | .PD | |
cce855bc JA |
3870 | True if the length of |
3871 | .I string | |
3872 | is non-zero. | |
3873 | .TP | |
3874 | \fIstring1\fP \fB==\fP \fIstring2\fP | |
3875 | True if the strings are equal. \fB=\fP may be used in place of | |
7117c2d2 | 3876 | \fB==\fP for strict POSIX compliance. |
cce855bc JA |
3877 | .TP |
3878 | \fIstring1\fP \fB!=\fP \fIstring2\fP | |
3879 | True if the strings are not equal. | |
3880 | .TP | |
3881 | \fIstring1\fP \fB<\fP \fIstring2\fP | |
0d8616ff | 3882 | True if \fIstring1\fP sorts before \fIstring2\fP lexicographically. |
cce855bc JA |
3883 | .TP |
3884 | \fIstring1\fP \fB>\fP \fIstring2\fP | |
0d8616ff | 3885 | True if \fIstring1\fP sorts after \fIstring2\fP lexicographically. |
cce855bc JA |
3886 | .TP |
3887 | .I \fIarg1\fP \fBOP\fP \fIarg2\fP | |
3888 | .SM | |
3889 | .B OP | |
3890 | is one of | |
3891 | .BR \-eq , | |
3892 | .BR \-ne , | |
3893 | .BR \-lt , | |
3894 | .BR \-le , | |
3895 | .BR \-gt , | |
3896 | or | |
3897 | .BR \-ge . | |
3898 | These arithmetic binary operators return true if \fIarg1\fP | |
3899 | is equal to, not equal to, less than, less than or equal to, | |
3900 | greater than, or greater than or equal to \fIarg2\fP, respectively. | |
3901 | .I Arg1 | |
3902 | and | |
3903 | .I arg2 | |
3904 | may be positive or negative integers. | |
3905 | .PD | |
3906 | .SH "SIMPLE COMMAND EXPANSION" | |
3907 | When a simple command is executed, the shell performs the following | |
3908 | expansions, assignments, and redirections, from left to right. | |
3909 | .IP 1. | |
3910 | The words that the parser has marked as variable assignments (those | |
3911 | preceding the command name) and redirections are saved for later | |
3912 | processing. | |
3913 | .IP 2. | |
3914 | The words that are not variable assignments or redirections are | |
3915 | expanded. If any words remain after expansion, the first word | |
3916 | is taken to be the name of the command and the remaining words are | |
3917 | the arguments. | |
3918 | .IP 3. | |
3919 | Redirections are performed as described above under | |
3920 | .SM | |
3921 | .BR REDIRECTION . | |
3922 | .IP 4. | |
3923 | The text after the \fB=\fP in each variable assignment undergoes tilde | |
3924 | expansion, parameter expansion, command substitution, arithmetic expansion, | |
3925 | and quote removal before being assigned to the variable. | |
3926 | .PP | |
3927 | If no command name results, the variable assignments affect the current | |
3928 | shell environment. Otherwise, the variables are added to the environment | |
3929 | of the executed command and do not affect the current shell environment. | |
3930 | If any of the assignments attempts to assign a value to a readonly variable, | |
3931 | an error occurs, and the command exits with a non-zero status. | |
3932 | .PP | |
3933 | If no command name results, redirections are performed, but do not | |
3934 | affect the current shell environment. A redirection error causes the | |
3935 | command to exit with a non-zero status. | |
3936 | .PP | |
3937 | If there is a command name left after expansion, execution proceeds as | |
3938 | described below. Otherwise, the command exits. If one of the expansions | |
3939 | contained a command substitution, the exit status of the command is | |
3940 | the exit status of the last command substitution performed. If there | |
3941 | were no command substitutions, the command exits with a status of zero. | |
3942 | .SH "COMMAND EXECUTION" | |
3943 | After a command has been split into words, if it results in a | |
3944 | simple command and an optional list of arguments, the following | |
3945 | actions are taken. | |
3946 | .PP | |
3947 | If the command name contains no slashes, the shell attempts to | |
3948 | locate it. If there exists a shell function by that name, that | |
3949 | function is invoked as described above in | |
3950 | .SM | |
3951 | .BR FUNCTIONS . | |
3952 | If the name does not match a function, the shell searches for | |
3953 | it in the list of shell builtins. If a match is found, that | |
3954 | builtin is invoked. | |
3955 | .PP | |
3956 | If the name is neither a shell function nor a builtin, | |
3957 | and contains no slashes, | |
3958 | .B bash | |
3959 | searches each element of the | |
3960 | .SM | |
3961 | .B PATH | |
3962 | for a directory containing an executable file by that name. | |
3963 | .B Bash | |
bb70624e | 3964 | uses a hash table to remember the full pathnames of executable |
cce855bc JA |
3965 | files (see |
3966 | .B hash | |
3967 | under | |
3968 | .SM | |
3969 | .B "SHELL BUILTIN COMMANDS" | |
3970 | below). | |
3971 | A full search of the directories in | |
3972 | .SM | |
3973 | .B PATH | |
3974 | is performed only if the command is not found in the hash table. | |
245a493c CR |
3975 | If the search is unsuccessful, the shell searches for a defined shell |
3976 | function named \fBcommand_not_found_handle\fP. | |
3977 | If that function exists, it is invoked with the original command and | |
3978 | the original command's arguments as its arguments, and the function's | |
3979 | exit status becomes the exit status of the shell. | |
3980 | If that function is not defined, the shell prints an error | |
cce855bc JA |
3981 | message and returns an exit status of 127. |
3982 | .PP | |
3983 | If the search is successful, or if the command name contains | |
3984 | one or more slashes, the shell executes the named program in a | |
3985 | separate execution environment. | |
3986 | Argument 0 is set to the name given, and the remaining arguments | |
3987 | to the command are set to the arguments given, if any. | |
3988 | .PP | |
3989 | If this execution fails because the file is not in executable | |
3990 | format, and the file is not a directory, it is assumed to be | |
3991 | a \fIshell script\fP, a file | |
3992 | containing shell commands. A subshell is spawned to execute | |
3993 | it. This subshell reinitializes itself, so | |
3994 | that the effect is as if a new shell had been invoked | |
3995 | to handle the script, with the exception that the locations of | |
3996 | commands remembered by the parent (see | |
3997 | .B hash | |
3998 | below under | |
3999 | .SM | |
4000 | \fBSHELL BUILTIN COMMANDS\fP) | |
4001 | are retained by the child. | |
4002 | .PP | |
4003 | If the program is a file beginning with | |
4004 | .BR #! , | |
4005 | the remainder of the first line specifies an interpreter | |
4006 | for the program. The shell executes the | |
4007 | specified interpreter on operating systems that do not | |
4008 | handle this executable format themselves. The arguments to the | |
4009 | interpreter consist of a single optional argument following the | |
4010 | interpreter name on the first line of the program, followed | |
4011 | by the name of the program, followed by the command | |
4012 | arguments, if any. | |
4013 | .SH COMMAND EXECUTION ENVIRONMENT | |
4014 | The shell has an \fIexecution environment\fP, which consists of the | |
4015 | following: | |
4016 | .sp 1 | |
4017 | .IP \(bu | |
4018 | open files inherited by the shell at invocation, as modified by | |
4019 | redirections supplied to the \fBexec\fP builtin | |
4020 | .IP \(bu | |
4021 | the current working directory as set by \fBcd\fP, \fBpushd\fP, or | |
4022 | \fBpopd\fP, or inherited by the shell at invocation | |
4023 | .IP \(bu | |
4024 | the file creation mode mask as set by \fBumask\fP or inherited from | |
4025 | the shell's parent | |
4026 | .IP \(bu | |
4027 | current traps set by \fBtrap\fP | |
4028 | .IP \(bu | |
4029 | shell parameters that are set by variable assignment or with \fBset\fP | |
4030 | or inherited from the shell's parent in the environment | |
4031 | .IP \(bu | |
4032 | shell functions defined during execution or inherited from the shell's | |
4033 | parent in the environment | |
4034 | .IP \(bu | |
4035 | options enabled at invocation (either by default or with command-line | |
4036 | arguments) or by \fBset\fP | |
4037 | .IP \(bu | |
4038 | options enabled by \fBshopt\fP | |
4039 | .IP \(bu | |
4040 | shell aliases defined with \fBalias\fP | |
4041 | .IP \(bu | |
4042 | various process IDs, including those of background jobs, the value | |
4043 | of \fB$$\fP, and the value of \fB$PPID\fP | |
4044 | .PP | |
4045 | When a simple command other than a builtin or shell function | |
4046 | is to be executed, it | |
4047 | is invoked in a separate execution environment that consists of | |
4048 | the following. Unless otherwise noted, the values are inherited | |
4049 | from the shell. | |
4050 | .sp 1 | |
4051 | .IP \(bu | |
4052 | the shell's open files, plus any modifications and additions specified | |
4053 | by redirections to the command | |
4054 | .IP \(bu | |
4055 | the current working directory | |
4056 | .IP \(bu | |
4057 | the file creation mode mask | |
4058 | .IP \(bu | |
d3a24ed2 CR |
4059 | shell variables and functions marked for export, along with variables |
4060 | exported for the command, passed in the environment | |
cce855bc | 4061 | .IP \(bu |
d3a24ed2 CR |
4062 | traps caught by the shell are reset to the values inherited from the |
4063 | shell's parent, and traps ignored by the shell are ignored | |
cce855bc JA |
4064 | .PP |
4065 | A command invoked in this separate environment cannot affect the | |
4066 | shell's execution environment. | |
4067 | .PP | |
d3a24ed2 CR |
4068 | Command substitution, commands grouped with parentheses, |
4069 | and asynchronous commands are invoked in a | |
cce855bc JA |
4070 | subshell environment that is a duplicate of the shell environment, |
4071 | except that traps caught by the shell are reset to the values | |
4072 | that the shell inherited from its parent at invocation. Builtin | |
4073 | commands that are invoked as part of a pipeline are also executed in a | |
4074 | subshell environment. Changes made to the subshell environment | |
4075 | cannot affect the shell's execution environment. | |
f73dda09 | 4076 | .PP |
012bac39 CR |
4077 | Subshells spawned to execute command substitutions inherit the value of |
4078 | the \fB\-e\fP option from the parent shell. When not in posix mode, | |
4079 | Bash clears the \fB\-e\fP option in such subshells. | |
4080 | .PP | |
f73dda09 JA |
4081 | If a command is followed by a \fB&\fP and job control is not active, the |
4082 | default standard input for the command is the empty file \fI/dev/null\fP. | |
4083 | Otherwise, the invoked command inherits the file descriptors of the calling | |
4084 | shell as modified by redirections. | |
cce855bc JA |
4085 | .SH ENVIRONMENT |
4086 | When a program is invoked it is given an array of strings | |
4087 | called the | |
4088 | .IR environment . | |
4089 | This is a list of | |
4090 | \fIname\fP\-\fIvalue\fP pairs, of the form | |
4091 | .IR "name\fR=\fPvalue" . | |
4092 | .PP | |
bb70624e JA |
4093 | The shell provides several ways to manipulate the environment. |
4094 | On invocation, the shell scans its own environment and | |
cce855bc JA |
4095 | creates a parameter for each name found, automatically marking |
4096 | it for | |
4097 | .I export | |
4098 | to child processes. Executed commands inherit the environment. | |
4099 | The | |
4100 | .B export | |
4101 | and | |
4102 | .B declare \-x | |
4103 | commands allow parameters and functions to be added to and | |
4104 | deleted from the environment. If the value of a parameter | |
4105 | in the environment is modified, the new value becomes part | |
4106 | of the environment, replacing the old. The environment | |
4107 | inherited by any executed command consists of the shell's | |
4108 | initial environment, whose values may be modified in the shell, | |
4109 | less any pairs removed by the | |
4110 | .B unset | |
4111 | command, plus any additions via the | |
4112 | .B export | |
4113 | and | |
4114 | .B declare \-x | |
4115 | commands. | |
4116 | .PP | |
4117 | The environment for any | |
4118 | .I simple command | |
4119 | or function may be augmented temporarily by prefixing it with | |
4120 | parameter assignments, as described above in | |
4121 | .SM | |
4122 | .BR PARAMETERS . | |
4123 | These assignment statements affect only the environment seen | |
4124 | by that command. | |
4125 | .PP | |
4126 | If the | |
4127 | .B \-k | |
4128 | option is set (see the | |
4129 | .B set | |
4130 | builtin command below), then | |
4131 | .I all | |
4132 | parameter assignments are placed in the environment for a command, | |
4133 | not just those that precede the command name. | |
4134 | .PP | |
4135 | When | |
4136 | .B bash | |
4137 | invokes an external command, the variable | |
4138 | .B _ | |
4139 | is set to the full file name of the command and passed to that | |
ccc6cda3 JA |
4140 | command in its environment. |
4141 | .SH "EXIT STATUS" | |
35ee8ea0 CR |
4142 | .PP |
4143 | The exit status of an executed command is the value returned by the | |
4144 | \fIwaitpid\fP system call or equivalent function. Exit statuses | |
4145 | fall between 0 and 255, though, as explained below, the shell may | |
4146 | use values above 125 specially. Exit statuses from shell builtins and | |
4147 | compound commands are also limited to this range. Under certain | |
4148 | circumstances, the shell will use special values to indicate specific | |
4149 | failure modes. | |
4150 | .PP | |
cce855bc | 4151 | For the shell's purposes, a command which exits with a |
ccc6cda3 JA |
4152 | zero exit status has succeeded. An exit status of zero |
4153 | indicates success. A non-zero exit status indicates failure. | |
bb70624e JA |
4154 | When a command terminates on a fatal signal \fIN\fP, \fBbash\fP uses |
4155 | the value of 128+\fIN\fP as the exit status. | |
ccc6cda3 JA |
4156 | .PP |
4157 | If a command is not found, the child process created to | |
4158 | execute it returns a status of 127. If a command is found | |
4159 | but is not executable, the return status is 126. | |
4160 | .PP | |
cce855bc JA |
4161 | If a command fails because of an error during expansion or redirection, |
4162 | the exit status is greater than zero. | |
4163 | .PP | |
ccc6cda3 JA |
4164 | Shell builtin commands return a status of 0 (\fItrue\fP) if |
4165 | successful, and non-zero (\fIfalse\fP) if an error occurs | |
4166 | while they execute. | |
4167 | All builtins return an exit status of 2 to indicate incorrect usage. | |
4168 | .PP | |
4169 | \fBBash\fP itself returns the exit status of the last command | |
4170 | executed, unless a syntax error occurs, in which case it exits | |
4171 | with a non-zero value. See also the \fBexit\fP builtin | |
4172 | command below. | |
4173 | .SH SIGNALS | |
cce855bc | 4174 | When \fBbash\fP is interactive, in the absence of any traps, it ignores |
ccc6cda3 JA |
4175 | .SM |
4176 | .B SIGTERM | |
4177 | (so that \fBkill 0\fP does not kill an interactive shell), | |
4178 | and | |
4179 | .SM | |
4180 | .B SIGINT | |
4181 | is caught and handled (so that the \fBwait\fP builtin is interruptible). | |
4182 | In all cases, \fBbash\fP ignores | |
4183 | .SM | |
4184 | .BR SIGQUIT . | |
4185 | If job control is in effect, | |
4186 | .B bash | |
4187 | ignores | |
4188 | .SM | |
4189 | .BR SIGTTIN , | |
4190 | .SM | |
4191 | .BR SIGTTOU , | |
4192 | and | |
4193 | .SM | |
4194 | .BR SIGTSTP . | |
4195 | .PP | |
5e13499c | 4196 | Non-builtin commands run by \fBbash\fP have signal handlers |
cce855bc JA |
4197 | set to the values inherited by the shell from its parent. |
4198 | When job control is not in effect, asynchronous commands | |
ccc6cda3 JA |
4199 | ignore |
4200 | .SM | |
4201 | .B SIGINT | |
4202 | and | |
4203 | .SM | |
cce855bc | 4204 | .B SIGQUIT |
5e13499c | 4205 | in addition to these inherited handlers. |
ccc6cda3 JA |
4206 | Commands run as a result of command substitution ignore the |
4207 | keyboard-generated job control signals | |
4208 | .SM | |
4209 | .BR SIGTTIN , | |
4210 | .SM | |
4211 | .BR SIGTTOU , | |
4212 | and | |
4213 | .SM | |
4214 | .BR SIGTSTP . | |
4215 | .PP | |
4216 | The shell exits by default upon receipt of a | |
4217 | .SM | |
4218 | .BR SIGHUP . | |
f73dda09 | 4219 | Before exiting, an interactive shell resends the |
ccc6cda3 JA |
4220 | .SM |
4221 | .B SIGHUP | |
cce855bc JA |
4222 | to all jobs, running or stopped. |
4223 | Stopped jobs are sent | |
4224 | .SM | |
4225 | .B SIGCONT | |
4226 | to ensure that they receive the | |
4227 | .SM | |
4228 | .BR SIGHUP . | |
4229 | To prevent the shell from | |
4230 | sending the signal to a particular job, it should be removed from the | |
ccc6cda3 JA |
4231 | jobs table with the |
4232 | .B disown | |
4233 | builtin (see | |
4234 | .SM | |
4235 | .B "SHELL BUILTIN COMMANDS" | |
cce855bc JA |
4236 | below) or marked |
4237 | to not receive | |
ccc6cda3 | 4238 | .SM |
cce855bc JA |
4239 | .B SIGHUP |
4240 | using | |
4241 | .BR "disown \-h" . | |
4242 | .PP | |
4243 | If the | |
4244 | .B huponexit | |
4245 | shell option has been set with | |
4246 | .BR shopt , | |
4247 | .B bash | |
4248 | sends a | |
4249 | .SM | |
4250 | .B SIGHUP | |
4251 | to all jobs when an interactive login shell exits. | |
4252 | .PP | |
b66cc816 | 4253 | If \fBbash\fP is waiting for a command to complete and receives a signal |
5e13499c CR |
4254 | for which a trap has been set, the trap will not be executed until |
4255 | the command completes. | |
cce855bc JA |
4256 | When \fBbash\fP is waiting for an asynchronous command via the \fBwait\fP |
4257 | builtin, the reception of a signal for which a trap has been set will | |
4258 | cause the \fBwait\fP builtin to return immediately with an exit status | |
4259 | greater than 128, immediately after which the trap is executed. | |
ccc6cda3 JA |
4260 | .SH "JOB CONTROL" |
4261 | .I Job control | |
4262 | refers to the ability to selectively stop (\fIsuspend\fP) | |
4263 | the execution of processes and continue (\fIresume\fP) | |
4264 | their execution at a later point. A user typically employs | |
4265 | this facility via an interactive interface supplied jointly | |
602bb739 | 4266 | by the operating system kernel's terminal driver and |
ccc6cda3 JA |
4267 | .BR bash . |
4268 | .PP | |
4269 | The shell associates a | |
4270 | .I job | |
4271 | with each pipeline. It keeps a table of currently executing | |
4272 | jobs, which may be listed with the | |
4273 | .B jobs | |
4274 | command. When | |
4275 | .B bash | |
4276 | starts a job asynchronously (in the | |
4277 | .IR background ), | |
4278 | it prints a line that looks like: | |
4279 | .RS | |
4280 | .PP | |
4281 | [1] 25647 | |
4282 | .RE | |
4283 | .PP | |
4284 | indicating that this job is job number 1 and that the process ID | |
4285 | of the last process in the pipeline associated with this job is 25647. | |
4286 | All of the processes in a single pipeline are members of the same job. | |
4287 | .B Bash | |
4288 | uses the | |
4289 | .I job | |
4290 | abstraction as the basis for job control. | |
4291 | .PP | |
4292 | To facilitate the implementation of the user interface to job | |
bb70624e | 4293 | control, the operating system maintains the notion of a \fIcurrent terminal |
ccc6cda3 JA |
4294 | process group ID\fP. Members of this process group (processes whose |
4295 | process group ID is equal to the current terminal process group ID) | |
4296 | receive keyboard-generated signals such as | |
4297 | .SM | |
4298 | .BR SIGINT . | |
4299 | These processes are said to be in the | |
4300 | .IR foreground . | |
4301 | .I Background | |
4302 | processes are those whose process group ID differs from the terminal's; | |
4303 | such processes are immune to keyboard-generated signals. | |
602bb739 CR |
4304 | Only foreground processes are allowed to read from or, if the |
4305 | user so specifies with \f(CWstty tostop\fP, write to the | |
4306 | terminal. | |
4307 | Background processes which attempt to read from (write to when | |
4308 | \f(CWstty tostop\fP is in effect) the | |
ccc6cda3 JA |
4309 | terminal are sent a |
4310 | .SM | |
4311 | .B SIGTTIN (SIGTTOU) | |
602bb739 | 4312 | signal by the kernel's terminal driver, |
ccc6cda3 JA |
4313 | which, unless caught, suspends the process. |
4314 | .PP | |
4315 | If the operating system on which | |
4316 | .B bash | |
4317 | is running supports | |
4318 | job control, | |
4319 | .B bash | |
bb70624e | 4320 | contains facilities to use it. |
ccc6cda3 JA |
4321 | Typing the |
4322 | .I suspend | |
4323 | character (typically | |
4324 | .BR ^Z , | |
4325 | Control-Z) while a process is running | |
bb70624e | 4326 | causes that process to be stopped and returns control to |
ccc6cda3 JA |
4327 | .BR bash . |
4328 | Typing the | |
4329 | .I "delayed suspend" | |
4330 | character (typically | |
4331 | .BR ^Y , | |
4332 | Control-Y) causes the process to be stopped when it | |
4333 | attempts to read input from the terminal, and control to | |
4334 | be returned to | |
4335 | .BR bash . | |
cce855bc | 4336 | The user may then manipulate the state of this job, using the |
ccc6cda3 JA |
4337 | .B bg |
4338 | command to continue it in the background, the | |
4339 | .B fg | |
4340 | command to continue it in the foreground, or | |
4341 | the | |
4342 | .B kill | |
4343 | command to kill it. A \fB^Z\fP takes effect immediately, | |
4344 | and has the additional side effect of causing pending output | |
4345 | and typeahead to be discarded. | |
4346 | .PP | |
4347 | There are a number of ways to refer to a job in the shell. | |
4348 | The character | |
4349 | .B % | |
8e1a6eaa | 4350 | introduces a job specification (\fIjobspec\fP). Job number |
ccc6cda3 JA |
4351 | .I n |
4352 | may be referred to as | |
4353 | .BR %n . | |
4354 | A job may also be referred to using a prefix of the name used to | |
4355 | start it, or using a substring that appears in its command line. | |
4356 | For example, | |
4357 | .B %ce | |
4358 | refers to a stopped | |
4359 | .B ce | |
4360 | job. If a prefix matches more than one job, | |
4361 | .B bash | |
4362 | reports an error. Using | |
4363 | .BR %?ce , | |
4364 | on the other hand, refers to any job containing the string | |
4365 | .B ce | |
4366 | in its command line. If the substring matches more than one job, | |
4367 | .B bash | |
4368 | reports an error. The symbols | |
4369 | .B %% | |
4370 | and | |
4371 | .B %+ | |
4372 | refer to the shell's notion of the | |
4373 | .IR "current job" , | |
4374 | which is the last job stopped while it was in | |
cce855bc | 4375 | the foreground or started in the background. |
ccc6cda3 JA |
4376 | The |
4377 | .I "previous job" | |
4378 | may be referenced using | |
4379 | .BR %\- . | |
e33f2203 CR |
4380 | If there is only a single job, \fB%+\fP and \fB%\-\fP can both be used |
4381 | to refer to that job. | |
ccc6cda3 JA |
4382 | In output pertaining to jobs (e.g., the output of the |
4383 | .B jobs | |
4384 | command), the current job is always flagged with a | |
4385 | .BR + , | |
4386 | and the previous job with a | |
4387 | .BR \- . | |
43df7bbb CR |
4388 | A single % (with no accompanying job specification) also refers to the |
4389 | current job. | |
726f6388 | 4390 | .PP |
ccc6cda3 JA |
4391 | Simply naming a job can be used to bring it into the |
4392 | foreground: | |
4393 | .B %1 | |
4394 | is a synonym for | |
4395 | \fB``fg %1''\fP, | |
4396 | bringing job 1 from the background into the foreground. | |
4397 | Similarly, | |
4398 | .B ``%1 &'' | |
4399 | resumes job 1 in the background, equivalent to | |
4400 | \fB``bg %1''\fP. | |
726f6388 | 4401 | .PP |
ccc6cda3 JA |
4402 | The shell learns immediately whenever a job changes state. |
4403 | Normally, | |
4404 | .B bash | |
4405 | waits until it is about to print a prompt before reporting | |
4406 | changes in a job's status so as to not interrupt | |
4407 | any other output. If the | |
4408 | .B \-b | |
4409 | option to the | |
726f6388 | 4410 | .B set |
ccc6cda3 | 4411 | builtin command |
cce855bc | 4412 | is enabled, |
726f6388 | 4413 | .B bash |
ccc6cda3 | 4414 | reports such changes immediately. |
f73dda09 JA |
4415 | Any trap on |
4416 | .SM | |
4417 | .B SIGCHLD | |
4418 | is executed for each child that exits. | |
726f6388 | 4419 | .PP |
ccc6cda3 JA |
4420 | If an attempt to exit |
4421 | .B bash | |
d3ad40de CR |
4422 | is made while jobs are stopped (or, if the \fBcheckjobs\fP shell option has |
4423 | been enabled using the \fBshopt\fP builtin, running), the shell prints a | |
4424 | warning message, and, if the \fBcheckjobs\fP option is enabled, lists the | |
4425 | jobs and their statuses. | |
4426 | The | |
ccc6cda3 | 4427 | .B jobs |
d3ad40de | 4428 | command may then be used to inspect their status. |
ccc6cda3 | 4429 | If a second attempt to exit is made without an intervening command, |
d3ad40de | 4430 | the shell does not print another warning, and any stopped |
ccc6cda3 | 4431 | jobs are terminated. |
726f6388 JA |
4432 | .SH PROMPTING |
4433 | When executing interactively, | |
4434 | .B bash | |
4435 | displays the primary prompt | |
4436 | .SM | |
4437 | .B PS1 | |
4438 | when it is ready to read a command, and the secondary prompt | |
4439 | .SM | |
4440 | .B PS2 | |
4441 | when it needs more input to complete a command. | |
4442 | .B Bash | |
4443 | allows these prompt strings to be customized by inserting a number of | |
4444 | backslash-escaped special characters that are decoded as follows: | |
4445 | .RS | |
4446 | .PD 0 | |
4447 | .TP | |
ccc6cda3 JA |
4448 | .B \ea |
4449 | an ASCII bell character (07) | |
726f6388 JA |
4450 | .TP |
4451 | .B \ed | |
4452 | the date in "Weekday Month Date" format (e.g., "Tue May 26") | |
4453 | .TP | |
7117c2d2 JA |
4454 | .B \eD{\fIformat\fP} |
4455 | the \fIformat\fP is passed to \fIstrftime\fP(3) and the result is inserted | |
4456 | into the prompt string; an empty \fIformat\fP results in a locale-specific | |
4457 | time representation. The braces are required | |
4458 | .TP | |
ccc6cda3 JA |
4459 | .B \ee |
4460 | an ASCII escape character (033) | |
4461 | .TP | |
4462 | .B \eh | |
4463 | the hostname up to the first `.' | |
4464 | .TP | |
4465 | .B \eH | |
4466 | the hostname | |
4467 | .TP | |
bb70624e JA |
4468 | .B \ej |
4469 | the number of jobs currently managed by the shell | |
4470 | .TP | |
4471 | .B \el | |
4472 | the basename of the shell's terminal device name | |
4473 | .TP | |
726f6388 JA |
4474 | .B \en |
4475 | newline | |
4476 | .TP | |
cce855bc JA |
4477 | .B \er |
4478 | carriage return | |
4479 | .TP | |
726f6388 JA |
4480 | .B \es |
4481 | the name of the shell, the basename of | |
4482 | .B $0 | |
4483 | (the portion following the final slash) | |
4484 | .TP | |
ccc6cda3 JA |
4485 | .B \et |
4486 | the current time in 24-hour HH:MM:SS format | |
726f6388 | 4487 | .TP |
ccc6cda3 JA |
4488 | .B \eT |
4489 | the current time in 12-hour HH:MM:SS format | |
4490 | .TP | |
4491 | .B \e@ | |
4492 | the current time in 12-hour am/pm format | |
726f6388 | 4493 | .TP |
f73dda09 JA |
4494 | .B \eA |
4495 | the current time in 24-hour HH:MM format | |
4496 | .TP | |
726f6388 JA |
4497 | .B \eu |
4498 | the username of the current user | |
4499 | .TP | |
ccc6cda3 JA |
4500 | .B \ev |
4501 | the version of \fBbash\fP (e.g., 2.00) | |
726f6388 | 4502 | .TP |
ccc6cda3 | 4503 | .B \eV |
a5e25162 | 4504 | the release of \fBbash\fP, version + patch level (e.g., 2.00.0) |
ccc6cda3 JA |
4505 | .TP |
4506 | .B \ew | |
12d937f9 | 4507 | the current working directory, with \fB$HOME\fP abbreviated with a tilde |
ed35cb4a | 4508 | (uses the \fB$PROMPT_DIRTRIM\fP variable) |
ccc6cda3 JA |
4509 | .TP |
4510 | .B \eW | |
12d937f9 CR |
4511 | the basename of the current working directory, with \fB$HOME\fP |
4512 | abbreviated with a tilde | |
726f6388 JA |
4513 | .TP |
4514 | .B \e! | |
4515 | the history number of this command | |
4516 | .TP | |
ccc6cda3 JA |
4517 | .B \e# |
4518 | the command number of this command | |
4519 | .TP | |
726f6388 JA |
4520 | .B \e$ |
4521 | if the effective UID is 0, a | |
4522 | .BR # , | |
4523 | otherwise a | |
4524 | .B $ | |
4525 | .TP | |
ccc6cda3 JA |
4526 | .B \e\fInnn\fP |
4527 | the character corresponding to the octal number \fInnn\fP | |
726f6388 JA |
4528 | .TP |
4529 | .B \e\e | |
4530 | a backslash | |
4531 | .TP | |
4532 | .B \e[ | |
4533 | begin a sequence of non-printing characters, which could be used to | |
4534 | embed a terminal control sequence into the prompt | |
4535 | .TP | |
4536 | .B \e] | |
4537 | end a sequence of non-printing characters | |
4538 | .PD | |
4539 | .RE | |
4540 | .PP | |
4541 | The command number and the history number are usually different: | |
4542 | the history number of a command is its position in the history | |
4543 | list, which may include commands restored from the history file | |
4544 | (see | |
4545 | .SM | |
4546 | .B HISTORY | |
4547 | below), while the command number is the position in the sequence | |
4548 | of commands executed during the current shell session. | |
4549 | After the string is decoded, it is expanded via | |
bb70624e JA |
4550 | parameter expansion, command substitution, arithmetic |
4551 | expansion, and quote removal, subject to the value of the | |
ccc6cda3 JA |
4552 | .B promptvars |
4553 | shell option (see the description of the | |
4554 | .B shopt | |
4555 | command under | |
4556 | .SM | |
4557 | .B "SHELL BUILTIN COMMANDS" | |
4558 | below). | |
726f6388 JA |
4559 | .SH READLINE |
4560 | This is the library that handles reading input when using an interactive | |
4561 | shell, unless the | |
d166f048 | 4562 | .B \-\-noediting |
ccc6cda3 | 4563 | option is given at shell invocation. |
14e8b2a7 CR |
4564 | Line editing is also used when using the \fB\-e\fP option to the |
4565 | \fBread\fP builtin. | |
ccc6cda3 | 4566 | By default, the line editing commands are similar to those of emacs. |
726f6388 | 4567 | A vi-style line editing interface is also available. |
14e8b2a7 CR |
4568 | Line editing can be enabled at any time using the |
4569 | .B \-o emacs | |
ccc6cda3 | 4570 | or |
14e8b2a7 | 4571 | .B \-o vi |
ccc6cda3 JA |
4572 | options to the |
4573 | .B set | |
4574 | builtin (see | |
4575 | .SM | |
4576 | .B SHELL BUILTIN COMMANDS | |
4577 | below). | |
14e8b2a7 CR |
4578 | To turn off line editing after the shell is running, use the |
4579 | .B +o emacs | |
4580 | or | |
4581 | .B +o vi | |
4582 | options to the | |
4583 | .B set | |
4584 | builtin. | |
ccc6cda3 | 4585 | .SS "Readline Notation" |
726f6388 JA |
4586 | .PP |
4587 | In this section, the emacs-style notation is used to denote | |
4588 | keystrokes. Control keys are denoted by C\-\fIkey\fR, e.g., C\-n | |
4589 | means Control\-N. Similarly, | |
4590 | .I meta | |
4591 | keys are denoted by M\-\fIkey\fR, so M\-x means Meta\-X. (On keyboards | |
4592 | without a | |
4593 | .I meta | |
4594 | key, M\-\fIx\fP means ESC \fIx\fP, i.e., press the Escape key | |
4595 | then the | |
4596 | .I x | |
4597 | key. This makes ESC the \fImeta prefix\fP. | |
4598 | The combination M\-C\-\fIx\fP means ESC\-Control\-\fIx\fP, | |
4599 | or press the Escape key | |
4600 | then hold the Control key while pressing the | |
4601 | .I x | |
4602 | key.) | |
4603 | .PP | |
ccc6cda3 JA |
4604 | Readline commands may be given numeric |
4605 | .IR arguments , | |
4606 | which normally act as a repeat count. | |
4607 | Sometimes, however, it is the sign of the argument that is significant. | |
4608 | Passing a negative argument to a command that acts in the forward | |
4609 | direction (e.g., \fBkill\-line\fP) causes that command to act in a | |
4610 | backward direction. | |
4611 | Commands whose behavior with arguments deviates from this are noted | |
4612 | below. | |
4613 | .PP | |
4614 | When a command is described as \fIkilling\fP text, the text | |
4615 | deleted is saved for possible future retrieval | |
4616 | (\fIyanking\fP). The killed text is saved in a | |
4617 | \fIkill ring\fP. Consecutive kills cause the text to be | |
4618 | accumulated into one unit, which can be yanked all at once. | |
4619 | Commands which do not kill text separate the chunks of text | |
4620 | on the kill ring. | |
4621 | .SS "Readline Initialization" | |
4622 | .PP | |
4623 | Readline is customized by putting commands in an initialization | |
4624 | file (the \fIinputrc\fP file). | |
4625 | The name of this file is taken from the value of the | |
726f6388 | 4626 | .SM |
ccc6cda3 JA |
4627 | .B INPUTRC |
4628 | variable. If that variable is unset, the default is | |
726f6388 | 4629 | .IR ~/.inputrc . |
ccc6cda3 JA |
4630 | When a program which uses the readline library starts up, the |
4631 | initialization file is read, and the key bindings and variables | |
4632 | are set. | |
4633 | There are only a few basic constructs allowed in the | |
4634 | readline initialization file. | |
4635 | Blank lines are ignored. | |
4636 | Lines beginning with a \fB#\fP are comments. | |
4637 | Lines beginning with a \fB$\fP indicate conditional constructs. | |
4638 | Other lines denote key bindings and variable settings. | |
4639 | .PP | |
4640 | The default key-bindings may be changed with an | |
4641 | .I inputrc | |
4642 | file. | |
726f6388 JA |
4643 | Other programs that use this library may add their own commands |
4644 | and bindings. | |
4645 | .PP | |
4646 | For example, placing | |
4647 | .RS | |
4648 | .PP | |
4649 | M\-Control\-u: universal\-argument | |
4650 | .RE | |
4651 | or | |
4652 | .RS | |
4653 | C\-Meta\-u: universal\-argument | |
4654 | .RE | |
4655 | into the | |
ccc6cda3 | 4656 | .I inputrc |
726f6388 JA |
4657 | would make M\-C\-u execute the readline command |
4658 | .IR universal\-argument . | |
4659 | .PP | |
4660 | The following symbolic character names are recognized: | |
4661 | .IR RUBOUT , | |
4662 | .IR DEL , | |
4663 | .IR ESC , | |
4664 | .IR LFD , | |
4665 | .IR NEWLINE , | |
4666 | .IR RET , | |
4667 | .IR RETURN , | |
4668 | .IR SPC , | |
4669 | .IR SPACE , | |
4670 | and | |
4671 | .IR TAB . | |
bb70624e | 4672 | .PP |
726f6388 JA |
4673 | In addition to command names, readline allows keys to be bound |
4674 | to a string that is inserted when the key is pressed (a \fImacro\fP). | |
ccc6cda3 | 4675 | .SS "Readline Key Bindings" |
726f6388 JA |
4676 | .PP |
4677 | The syntax for controlling key bindings in the | |
cce855bc | 4678 | .I inputrc |
726f6388 JA |
4679 | file is simple. All that is required is the name of the |
4680 | command or the text of a macro and a key sequence to which | |
4681 | it should be bound. The name may be specified in one of two ways: | |
ccc6cda3 | 4682 | as a symbolic key name, possibly with \fIMeta\-\fP or \fIControl\-\fP |
726f6388 | 4683 | prefixes, or as a key sequence. |
28ef6c31 | 4684 | .PP |
cce855bc | 4685 | When using the form \fBkeyname\fP:\^\fIfunction\-name\fP or \fImacro\fP, |
726f6388 JA |
4686 | .I keyname |
4687 | is the name of a key spelled out in English. For example: | |
4688 | .sp | |
4689 | .RS | |
4690 | Control-u: universal\-argument | |
4691 | .br | |
4692 | Meta-Rubout: backward-kill-word | |
4693 | .br | |
ccc6cda3 | 4694 | Control-o: "> output" |
726f6388 JA |
4695 | .RE |
4696 | .LP | |
4697 | In the above example, | |
ccc6cda3 | 4698 | .I C\-u |
726f6388 JA |
4699 | is bound to the function |
4700 | .BR universal\-argument , | |
ccc6cda3 | 4701 | .I M\-DEL |
726f6388 JA |
4702 | is bound to the function |
4703 | .BR backward\-kill\-word , | |
4704 | and | |
ccc6cda3 | 4705 | .I C\-o |
726f6388 JA |
4706 | is bound to run the macro |
4707 | expressed on the right hand side (that is, to insert the text | |
28ef6c31 JA |
4708 | .if t \f(CW> output\fP |
4709 | .if n ``> output'' | |
726f6388 JA |
4710 | into the line). |
4711 | .PP | |
cce855bc | 4712 | In the second form, \fB"keyseq"\fP:\^\fIfunction\-name\fP or \fImacro\fP, |
726f6388 JA |
4713 | .B keyseq |
4714 | differs from | |
4715 | .B keyname | |
4716 | above in that strings denoting | |
4717 | an entire key sequence may be specified by placing the sequence | |
4718 | within double quotes. Some GNU Emacs style key escapes can be | |
28ef6c31 JA |
4719 | used, as in the following example, but the symbolic character names |
4720 | are not recognized. | |
726f6388 JA |
4721 | .sp |
4722 | .RS | |
ccc6cda3 | 4723 | "\eC\-u": universal\-argument |
726f6388 | 4724 | .br |
ccc6cda3 | 4725 | "\eC\-x\eC\-r": re\-read\-init\-file |
726f6388 JA |
4726 | .br |
4727 | "\ee[11~": "Function Key 1" | |
4728 | .RE | |
4729 | .PP | |
4730 | In this example, | |
ccc6cda3 | 4731 | .I C\-u |
726f6388 JA |
4732 | is again bound to the function |
4733 | .BR universal\-argument . | |
ccc6cda3 | 4734 | .I "C\-x C\-r" |
726f6388 JA |
4735 | is bound to the function |
4736 | .BR re\-read\-init\-file , | |
4737 | and | |
4738 | .I "ESC [ 1 1 ~" | |
4739 | is bound to insert the text | |
28ef6c31 JA |
4740 | .if t \f(CWFunction Key 1\fP. |
4741 | .if n ``Function Key 1''. | |
4742 | .PP | |
cce855bc | 4743 | The full set of GNU Emacs style escape sequences is |
726f6388 | 4744 | .RS |
cce855bc | 4745 | .PD 0 |
726f6388 JA |
4746 | .TP |
4747 | .B \eC\- | |
4748 | control prefix | |
4749 | .TP | |
ccc6cda3 | 4750 | .B \eM\- |
726f6388 JA |
4751 | meta prefix |
4752 | .TP | |
4753 | .B \ee | |
4754 | an escape character | |
4755 | .TP | |
4756 | .B \e\e | |
4757 | backslash | |
4758 | .TP | |
4759 | .B \e" | |
4760 | literal " | |
4761 | .TP | |
20587658 CR |
4762 | .B \e\(aq |
4763 | literal \(aq | |
726f6388 | 4764 | .RE |
cce855bc JA |
4765 | .PD |
4766 | .PP | |
4767 | In addition to the GNU Emacs style escape sequences, a second | |
4768 | set of backslash escapes is available: | |
4769 | .RS | |
4770 | .PD 0 | |
4771 | .TP | |
4772 | .B \ea | |
4773 | alert (bell) | |
4774 | .TP | |
4775 | .B \eb | |
4776 | backspace | |
4777 | .TP | |
4778 | .B \ed | |
4779 | delete | |
4780 | .TP | |
4781 | .B \ef | |
4782 | form feed | |
4783 | .TP | |
4784 | .B \en | |
4785 | newline | |
4786 | .TP | |
4787 | .B \er | |
4788 | carriage return | |
4789 | .TP | |
4790 | .B \et | |
4791 | horizontal tab | |
4792 | .TP | |
4793 | .B \ev | |
4794 | vertical tab | |
4795 | .TP | |
4796 | .B \e\fInnn\fP | |
f73dda09 | 4797 | the eight-bit character whose value is the octal value \fInnn\fP |
cce855bc JA |
4798 | (one to three digits) |
4799 | .TP | |
f73dda09 JA |
4800 | .B \ex\fIHH\fP |
4801 | the eight-bit character whose value is the hexadecimal value \fIHH\fP | |
4802 | (one or two hex digits) | |
cce855bc JA |
4803 | .RE |
4804 | .PD | |
726f6388 | 4805 | .PP |
cce855bc JA |
4806 | When entering the text of a macro, single or double quotes must |
4807 | be used to indicate a macro definition. | |
4808 | Unquoted text is assumed to be a function name. | |
4809 | In the macro body, the backslash escapes described above are expanded. | |
4810 | Backslash will quote any other character in the macro text, | |
20587658 | 4811 | including " and \(aq. |
726f6388 JA |
4812 | .PP |
4813 | .B Bash | |
4814 | allows the current readline key bindings to be displayed or modified | |
4815 | with the | |
4816 | .B bind | |
4817 | builtin command. The editing mode may be switched during interactive | |
4818 | use by using the | |
4819 | .B \-o | |
4820 | option to the | |
4821 | .B set | |
4822 | builtin command (see | |
4823 | .SM | |
4824 | .B SHELL BUILTIN COMMANDS | |
4825 | below). | |
ccc6cda3 | 4826 | .SS "Readline Variables" |
726f6388 JA |
4827 | .PP |
4828 | Readline has variables that can be used to further customize its | |
4829 | behavior. A variable may be set in the | |
4830 | .I inputrc | |
4831 | file with a statement of the form | |
4832 | .RS | |
4833 | .PP | |
4834 | \fBset\fP \fIvariable\-name\fP \fIvalue\fP | |
4835 | .RE | |
4836 | .PP | |
4837 | Except where noted, readline variables can take the values | |
4838 | .B On | |
4839 | or | |
ff247e74 CR |
4840 | .B Off |
4841 | (without regard to case). | |
4842 | Unrecognized variable names are ignored. | |
4843 | When a variable value is read, empty or null values, "on" (case-insensitive), | |
4844 | and "1" are equivalent to \fBOn\fP. All other values are equivalent to | |
4845 | \fBOff\fP. | |
726f6388 JA |
4846 | The variables and their default values are: |
4847 | .PP | |
4848 | .PD 0 | |
4849 | .TP | |
726f6388 JA |
4850 | .B bell\-style (audible) |
4851 | Controls what happens when readline wants to ring the terminal bell. | |
4852 | If set to \fBnone\fP, readline never rings the bell. If set to | |
4853 | \fBvisible\fP, readline uses a visible bell if one is available. | |
4854 | If set to \fBaudible\fP, readline attempts to ring the terminal's bell. | |
4855 | .TP | |
453f278a CR |
4856 | .B bind\-tty\-special\-chars (On) |
4857 | If set to \fBOn\fP, readline attempts to bind the control characters | |
4858 | treated specially by the kernel's terminal driver to their readline | |
4859 | equivalents. | |
4860 | .TP | |
726f6388 | 4861 | .B comment\-begin (``#'') |
bb70624e | 4862 | The string that is inserted when the readline |
ccc6cda3 | 4863 | .B insert\-comment |
726f6388 | 4864 | command is executed. |
ccc6cda3 JA |
4865 | This command is bound to |
4866 | .B M\-# | |
4867 | in emacs mode and to | |
4868 | .B # | |
4869 | in vi command mode. | |
726f6388 | 4870 | .TP |
cce855bc JA |
4871 | .B completion\-ignore\-case (Off) |
4872 | If set to \fBOn\fP, readline performs filename matching and completion | |
4873 | in a case\-insensitive fashion. | |
4874 | .TP | |
f13513ff CR |
4875 | .B completion\-prefix\-display\-length (0) |
4876 | The length in characters of the common prefix of a list of possible | |
4877 | completions that is displayed without modification. When set to a | |
4878 | value greater than zero, common prefixes longer than this value are | |
4879 | replaced with an ellipsis when displaying possible completions. | |
4880 | .TP | |
726f6388 JA |
4881 | .B completion\-query\-items (100) |
4882 | This determines when the user is queried about viewing | |
4883 | the number of possible completions | |
4884 | generated by the \fBpossible\-completions\fP command. | |
4885 | It may be set to any integer value greater than or equal to | |
4886 | zero. If the number of possible completions is greater than | |
4887 | or equal to the value of this variable, the user is asked whether | |
4888 | or not he wishes to view them; otherwise they are simply listed | |
4889 | on the terminal. | |
4890 | .TP | |
ccc6cda3 JA |
4891 | .B convert\-meta (On) |
4892 | If set to \fBOn\fP, readline will convert characters with the | |
4893 | eighth bit set to an ASCII key sequence | |
bb70624e | 4894 | by stripping the eighth bit and prefixing an |
ccc6cda3 JA |
4895 | escape character (in effect, using escape as the \fImeta prefix\fP). |
4896 | .TP | |
4897 | .B disable\-completion (Off) | |
4898 | If set to \fBOn\fP, readline will inhibit word completion. Completion | |
4899 | characters will be inserted into the line as if they had been | |
4900 | mapped to \fBself-insert\fP. | |
4901 | .TP | |
4902 | .B editing\-mode (emacs) | |
4903 | Controls whether readline begins with a set of key bindings similar | |
4904 | to \fIemacs\fP or \fIvi\fP. | |
4905 | .B editing\-mode | |
4906 | can be set to either | |
4907 | .B emacs | |
4908 | or | |
4909 | .BR vi . | |
4910 | .TP | |
4911 | .B enable\-keypad (Off) | |
4912 | When set to \fBOn\fP, readline will try to enable the application | |
4913 | keypad when it is called. Some systems need this to enable the | |
4914 | arrow keys. | |
4915 | .TP | |
4916 | .B expand\-tilde (Off) | |
4917 | If set to \fBon\fP, tilde expansion is performed when readline | |
4918 | attempts word completion. | |
4919 | .TP | |
cdb32d45 | 4920 | .B history\-preserve\-point (Off) |
f73dda09 | 4921 | If set to \fBon\fP, the history code attempts to place point at the |
f75912ae | 4922 | same location on each history line retrieved with \fBprevious-history\fP |
f73dda09 JA |
4923 | or \fBnext-history\fP. |
4924 | .TP | |
1d0e1a34 CR |
4925 | .B history\-size (0) |
4926 | Set the maximum number of history entries saved in the history list. If | |
4927 | set to zero, the number of entries in the history list is not limited. | |
4928 | .TP | |
ccc6cda3 JA |
4929 | .B horizontal\-scroll\-mode (Off) |
4930 | When set to \fBOn\fP, makes readline use a single line for display, | |
4931 | scrolling the input horizontally on a single screen line when it | |
4932 | becomes longer than the screen width rather than wrapping to a new line. | |
4933 | .TP | |
4934 | .B input\-meta (Off) | |
4935 | If set to \fBOn\fP, readline will enable eight-bit input (that is, | |
4936 | it will not strip the high bit from the characters it reads), | |
4937 | regardless of what the terminal claims it can support. The name | |
4938 | .B meta\-flag | |
4939 | is a synonym for this variable. | |
4940 | .TP | |
b72432fd JA |
4941 | .B isearch\-terminators (``C\-[C\-J'') |
4942 | The string of characters that should terminate an incremental | |
4943 | search without subsequently executing the character as a command. | |
4944 | If this variable has not been given a value, the characters | |
4945 | \fIESC\fP and \fIC\-J\fP will terminate an incremental search. | |
4946 | .TP | |
726f6388 | 4947 | .B keymap (emacs) |
cce855bc | 4948 | Set the current readline keymap. The set of valid keymap names is |
ccc6cda3 JA |
4949 | \fIemacs, emacs\-standard, emacs\-meta, emacs\-ctlx, vi, |
4950 | vi\-command\fP, and | |
4951 | .IR vi\-insert . | |
4952 | \fIvi\fP is equivalent to \fIvi\-command\fP; \fIemacs\fP is | |
4953 | equivalent to \fIemacs\-standard\fP. The default value is | |
726f6388 JA |
4954 | .IR emacs ; |
4955 | the value of | |
4956 | .B editing\-mode | |
4957 | also affects the default keymap. | |
4958 | .TP | |
ccc6cda3 JA |
4959 | .B mark\-directories (On) |
4960 | If set to \fBOn\fP, completed directory names have a slash | |
4961 | appended. | |
4962 | .TP | |
4963 | .B mark\-modified\-lines (Off) | |
4964 | If set to \fBOn\fP, history lines that have been modified are displayed | |
4965 | with a preceding asterisk (\fB*\fP). | |
4966 | .TP | |
7117c2d2 JA |
4967 | .B mark\-symlinked\-directories (Off) |
4968 | If set to \fBOn\fP, completed names which are symbolic links to directories | |
4969 | have a slash appended (subject to the value of | |
4970 | \fBmark\-directories\fP). | |
4971 | .TP | |
f73dda09 JA |
4972 | .B match\-hidden\-files (On) |
4973 | This variable, when set to \fBOn\fP, causes readline to match files whose | |
4974 | names begin with a `.' (hidden files) when performing filename | |
4975 | completion, unless the leading `.' is | |
4976 | supplied by the user in the filename to be completed. | |
4977 | .TP | |
ccc6cda3 JA |
4978 | .B output\-meta (Off) |
4979 | If set to \fBOn\fP, readline will display characters with the | |
4980 | eighth bit set directly rather than as a meta-prefixed escape | |
4981 | sequence. | |
4982 | .TP | |
7117c2d2 JA |
4983 | .B page\-completions (On) |
4984 | If set to \fBOn\fP, readline uses an internal \fImore\fP-like pager | |
4985 | to display a screenful of possible completions at a time. | |
4986 | .TP | |
cce855bc JA |
4987 | .B print\-completions\-horizontally (Off) |
4988 | If set to \fBOn\fP, readline will display completions with matches | |
4989 | sorted horizontally in alphabetical order, rather than down the screen. | |
f13513ff CR |
4990 | .TP |
4991 | .B revert\-all\-at\-newline (Off) | |
4992 | If set to \fBon\fP, readline will undo all changes to history lines | |
4993 | before returning when \fBaccept\-line\fP is executed. By default, | |
4994 | history lines may be modified and retain individual undo lists across | |
4995 | calls to \fBreadline\fP. | |
cce855bc | 4996 | .TP |
726f6388 JA |
4997 | .B show\-all\-if\-ambiguous (Off) |
4998 | This alters the default behavior of the completion functions. If | |
4999 | set to | |
5000 | .BR on , | |
5001 | words which have more than one possible completion cause the | |
5002 | matches to be listed immediately instead of ringing the bell. | |
5003 | .TP | |
d3a24ed2 CR |
5004 | .B show\-all\-if\-unmodified (Off) |
5005 | This alters the default behavior of the completion functions in | |
5006 | a fashion similar to \fBshow\-all\-if\-ambiguous\fP. | |
5007 | If set to | |
5008 | .BR on , | |
5009 | words which have more than one possible completion without any | |
5010 | possible partial completion (the possible completions don't share | |
5011 | a common prefix) cause the matches to be listed immediately instead | |
5012 | of ringing the bell. | |
5013 | .TP | |
ccc6cda3 JA |
5014 | .B visible\-stats (Off) |
5015 | If set to \fBOn\fP, a character denoting a file's type as reported | |
5016 | by \fIstat\fP(2) is appended to the filename when listing possible | |
5017 | completions. | |
726f6388 | 5018 | .PD |
ccc6cda3 | 5019 | .SS "Readline Conditional Constructs" |
726f6388 JA |
5020 | .PP |
5021 | Readline implements a facility similar in spirit to the conditional | |
5022 | compilation features of the C preprocessor which allows key | |
5023 | bindings and variable settings to be performed as the result | |
cce855bc | 5024 | of tests. There are four parser directives used. |
726f6388 JA |
5025 | .IP \fB$if\fP |
5026 | The | |
5027 | .B $if | |
5028 | construct allows bindings to be made based on the | |
5029 | editing mode, the terminal being used, or the application using | |
5030 | readline. The text of the test extends to the end of the line; | |
5031 | no characters are required to isolate it. | |
5032 | .RS | |
5033 | .IP \fBmode\fP | |
5034 | The \fBmode=\fP form of the \fB$if\fP directive is used to test | |
5035 | whether readline is in emacs or vi mode. | |
5036 | This may be used in conjunction | |
5037 | with the \fBset keymap\fP command, for instance, to set bindings in | |
ccc6cda3 | 5038 | the \fIemacs\-standard\fP and \fIemacs\-ctlx\fP keymaps only if |
726f6388 JA |
5039 | readline is starting out in emacs mode. |
5040 | .IP \fBterm\fP | |
5041 | The \fBterm=\fP form may be used to include terminal-specific | |
5042 | key bindings, perhaps to bind the key sequences output by the | |
5043 | terminal's function keys. The word on the right side of the | |
5044 | .B = | |
cce855bc | 5045 | is tested against the both full name of the terminal and the portion |
726f6388 JA |
5046 | of the terminal name before the first \fB\-\fP. This allows |
5047 | .I sun | |
5048 | to match both | |
5049 | .I sun | |
5050 | and | |
5051 | .IR sun\-cmd , | |
5052 | for instance. | |
5053 | .IP \fBapplication\fP | |
5054 | The \fBapplication\fP construct is used to include | |
ccc6cda3 | 5055 | application-specific settings. Each program using the readline |
726f6388 JA |
5056 | library sets the \fIapplication name\fP, and an initialization |
5057 | file can test for a particular value. | |
5058 | This could be used to bind key sequences to functions useful for | |
5059 | a specific program. For instance, the following command adds a | |
5060 | key sequence that quotes the current or previous word in Bash: | |
cce855bc | 5061 | .sp 1 |
726f6388 JA |
5062 | .RS |
5063 | .nf | |
5064 | \fB$if\fP Bash | |
5065 | # Quote the current or previous word | |
ccc6cda3 | 5066 | "\eC\-xq": "\eeb\e"\eef\e"" |
726f6388 JA |
5067 | \fB$endif\fP |
5068 | .fi | |
5069 | .RE | |
5070 | .RE | |
5071 | .IP \fB$endif\fP | |
cce855bc | 5072 | This command, as seen in the previous example, terminates an |
726f6388 JA |
5073 | \fB$if\fP command. |
5074 | .IP \fB$else\fP | |
5075 | Commands in this branch of the \fB$if\fP directive are executed if | |
5076 | the test fails. | |
cce855bc JA |
5077 | .IP \fB$include\fP |
5078 | This directive takes a single filename as an argument and reads commands | |
5079 | and bindings from that file. For example, the following directive | |
5080 | would read \fI/etc/inputrc\fP: | |
5081 | .sp 1 | |
5082 | .RS | |
5083 | .nf | |
5084 | \fB$include\fP \^ \fI/etc/inputrc\fP | |
5085 | .fi | |
5086 | .RE | |
ccc6cda3 | 5087 | .SS Searching |
726f6388 | 5088 | .PP |
ccc6cda3 JA |
5089 | Readline provides commands for searching through the command history |
5090 | (see | |
5091 | .SM | |
5092 | .B HISTORY | |
5093 | below) for lines containing a specified string. | |
5094 | There are two search modes: | |
5095 | .I incremental | |
5096 | and | |
5097 | .IR non-incremental . | |
5098 | .PP | |
5099 | Incremental searches begin before the user has finished typing the | |
5100 | search string. | |
5101 | As each character of the search string is typed, readline displays | |
5102 | the next entry from the history matching the string typed so far. | |
5103 | An incremental search requires only as many characters as needed to | |
5104 | find the desired history entry. | |
bb70624e | 5105 | The characters present in the value of the \fBisearch-terminators\fP |
b72432fd JA |
5106 | variable are used to terminate an incremental search. |
5107 | If that variable has not been assigned a value the Escape and | |
5108 | Control-J characters will terminate an incremental search. | |
ccc6cda3 JA |
5109 | Control-G will abort an incremental search and restore the original |
5110 | line. | |
5111 | When the search is terminated, the history entry containing the | |
5112 | search string becomes the current line. | |
bb70624e | 5113 | .PP |
ccc6cda3 JA |
5114 | To find other matching entries in the history list, type Control-S or |
5115 | Control-R as appropriate. | |
5116 | This will search backward or forward in the history for the next | |
5117 | entry matching the search string typed so far. | |
5118 | Any other key sequence bound to a readline command will terminate | |
5119 | the search and execute that command. | |
5120 | For instance, a \fInewline\fP will terminate the search and accept | |
5121 | the line, thereby executing the command from the history list. | |
5122 | .PP | |
f73dda09 JA |
5123 | Readline remembers the last incremental search string. If two |
5124 | Control-Rs are typed without any intervening characters defining a | |
5125 | new search string, any remembered search string is used. | |
5126 | .PP | |
ccc6cda3 JA |
5127 | Non-incremental searches read the entire search string before starting |
5128 | to search for matching history lines. The search string may be | |
cce855bc | 5129 | typed by the user or be part of the contents of the current line. |
ccc6cda3 | 5130 | .SS "Readline Command Names" |
726f6388 JA |
5131 | .PP |
5132 | The following is a list of the names of the commands and the default | |
5133 | key sequences to which they are bound. | |
ccc6cda3 | 5134 | Command names without an accompanying key sequence are unbound by default. |
bb70624e JA |
5135 | In the following descriptions, \fIpoint\fP refers to the current cursor |
5136 | position, and \fImark\fP refers to a cursor position saved by the | |
5137 | \fBset\-mark\fP command. | |
5138 | The text between the point and mark is referred to as the \fIregion\fP. | |
726f6388 JA |
5139 | .SS Commands for Moving |
5140 | .PP | |
5141 | .PD 0 | |
5142 | .TP | |
5143 | .B beginning\-of\-line (C\-a) | |
5144 | Move to the start of the current line. | |
5145 | .TP | |
5146 | .B end\-of\-line (C\-e) | |
5147 | Move to the end of the line. | |
5148 | .TP | |
5149 | .B forward\-char (C\-f) | |
5150 | Move forward a character. | |
5151 | .TP | |
5152 | .B backward\-char (C\-b) | |
5153 | Move back a character. | |
5154 | .TP | |
5155 | .B forward\-word (M\-f) | |
5156 | Move forward to the end of the next word. Words are composed of | |
5157 | alphanumeric characters (letters and digits). | |
5158 | .TP | |
5159 | .B backward\-word (M\-b) | |
8c2fef19 CR |
5160 | Move back to the start of the current or previous word. |
5161 | Words are composed of alphanumeric characters (letters and digits). | |
5162 | .TP | |
5163 | .B shell\-forward\-word | |
5164 | Move forward to the end of the next word. | |
5165 | Words are delimited by non-quoted shell metacharacters. | |
5166 | .TP | |
5167 | .B shell\-backward\-word | |
5168 | Move back to the start of the current or previous word. | |
5169 | Words are delimited by non-quoted shell metacharacters. | |
726f6388 JA |
5170 | .TP |
5171 | .B clear\-screen (C\-l) | |
5172 | Clear the screen leaving the current line at the top of the screen. | |
5173 | With an argument, refresh the current line without clearing the | |
5174 | screen. | |
5175 | .TP | |
5176 | .B redraw\-current\-line | |
ccc6cda3 | 5177 | Refresh the current line. |
726f6388 JA |
5178 | .PD |
5179 | .SS Commands for Manipulating the History | |
5180 | .PP | |
5181 | .PD 0 | |
5182 | .TP | |
5183 | .B accept\-line (Newline, Return) | |
5184 | Accept the line regardless of where the cursor is. If this line is | |
ccc6cda3 | 5185 | non-empty, add it to the history list according to the state of the |
726f6388 JA |
5186 | .SM |
5187 | .B HISTCONTROL | |
5188 | variable. If the line is a modified history | |
5189 | line, then restore the history line to its original state. | |
5190 | .TP | |
5191 | .B previous\-history (C\-p) | |
5192 | Fetch the previous command from the history list, moving back in | |
5193 | the list. | |
5194 | .TP | |
5195 | .B next\-history (C\-n) | |
5196 | Fetch the next command from the history list, moving forward in the | |
5197 | list. | |
5198 | .TP | |
5199 | .B beginning\-of\-history (M\-<) | |
5200 | Move to the first line in the history. | |
5201 | .TP | |
5202 | .B end\-of\-history (M\->) | |
5203 | Move to the end of the input history, i.e., the line currently being | |
5204 | entered. | |
5205 | .TP | |
5206 | .B reverse\-search\-history (C\-r) | |
5207 | Search backward starting at the current line and moving `up' through | |
5208 | the history as necessary. This is an incremental search. | |
5209 | .TP | |
5210 | .B forward\-search\-history (C\-s) | |
5211 | Search forward starting at the current line and moving `down' through | |
5212 | the history as necessary. This is an incremental search. | |
5213 | .TP | |
5214 | .B non\-incremental\-reverse\-search\-history (M\-p) | |
5215 | Search backward through the history starting at the current line | |
ccc6cda3 | 5216 | using a non-incremental search for a string supplied by the user. |
726f6388 JA |
5217 | .TP |
5218 | .B non\-incremental\-forward\-search\-history (M\-n) | |
ccc6cda3 | 5219 | Search forward through the history using a non-incremental search for |
726f6388 JA |
5220 | a string supplied by the user. |
5221 | .TP | |
5222 | .B history\-search\-forward | |
5223 | Search forward through the history for the string of characters | |
bb70624e | 5224 | between the start of the current line and the point. |
ccc6cda3 | 5225 | This is a non-incremental search. |
726f6388 JA |
5226 | .TP |
5227 | .B history\-search\-backward | |
5228 | Search backward through the history for the string of characters | |
ccc6cda3 JA |
5229 | between the start of the current line and the point. |
5230 | This is a non-incremental search. | |
726f6388 JA |
5231 | .TP |
5232 | .B yank\-nth\-arg (M\-C\-y) | |
5233 | Insert the first argument to the previous command (usually | |
28ef6c31 JA |
5234 | the second word on the previous line) at point. |
5235 | With an argument | |
726f6388 JA |
5236 | .IR n , |
5237 | insert the \fIn\fPth word from the previous command (the words | |
5238 | in the previous command begin with word 0). A negative argument | |
5239 | inserts the \fIn\fPth word from the end of the previous command. | |
eb2bb562 CR |
5240 | Once the argument \fIn\fP is computed, the argument is extracted |
5241 | as if the "!\fIn\fP" history expansion had been specified. | |
726f6388 JA |
5242 | .TP |
5243 | .B | |
5244 | yank\-last\-arg (M\-.\^, M\-_\^) | |
ccc6cda3 JA |
5245 | Insert the last argument to the previous command (the last word of |
5246 | the previous history entry). With an argument, | |
5247 | behave exactly like \fByank\-nth\-arg\fP. | |
cce855bc JA |
5248 | Successive calls to \fByank\-last\-arg\fP move back through the history |
5249 | list, inserting the last argument of each line in turn. | |
eb2bb562 CR |
5250 | The history expansion facilities are used to extract the last argument, |
5251 | as if the "!$" history expansion had been specified. | |
726f6388 JA |
5252 | .TP |
5253 | .B shell\-expand\-line (M\-C\-e) | |
cce855bc | 5254 | Expand the line as the shell does. This |
726f6388 JA |
5255 | performs alias and history expansion as well as all of the shell |
5256 | word expansions. See | |
5257 | .SM | |
5258 | .B HISTORY EXPANSION | |
5259 | below for a description of history expansion. | |
5260 | .TP | |
5261 | .B history\-expand\-line (M\-^) | |
d166f048 JA |
5262 | Perform history expansion on the current line. |
5263 | See | |
726f6388 JA |
5264 | .SM |
5265 | .B HISTORY EXPANSION | |
5266 | below for a description of history expansion. | |
5267 | .TP | |
cce855bc JA |
5268 | .B magic\-space |
5269 | Perform history expansion on the current line and insert a space. | |
5270 | See | |
5271 | .SM | |
5272 | .B HISTORY EXPANSION | |
5273 | below for a description of history expansion. | |
5274 | .TP | |
d166f048 JA |
5275 | .B alias\-expand\-line |
5276 | Perform alias expansion on the current line. | |
5277 | See | |
5278 | .SM | |
5279 | .B ALIASES | |
5280 | above for a description of alias expansion. | |
5281 | .TP | |
5282 | .B history\-and\-alias\-expand\-line | |
5283 | Perform history and alias expansion on the current line. | |
5284 | .TP | |
726f6388 JA |
5285 | .B insert\-last\-argument (M\-.\^, M\-_\^) |
5286 | A synonym for \fByank\-last\-arg\fP. | |
5287 | .TP | |
ccc6cda3 | 5288 | .B operate\-and\-get\-next (C\-o) |
726f6388 JA |
5289 | Accept the current line for execution and fetch the next line |
5290 | relative to the current line from the history for editing. Any | |
5291 | argument is ignored. | |
7117c2d2 JA |
5292 | .TP |
5293 | .B edit\-and\-execute\-command (C\-xC\-e) | |
5294 | Invoke an editor on the current command line, and execute the result as shell | |
5295 | commands. | |
5296 | \fBBash\fP attempts to invoke | |
5297 | .SM | |
dd4f3dd8 | 5298 | .BR $VISUAL , |
7117c2d2 JA |
5299 | .SM |
5300 | .BR $EDITOR , | |
5301 | and \fIemacs\fP as the editor, in that order. | |
726f6388 JA |
5302 | .PD |
5303 | .SS Commands for Changing Text | |
5304 | .PP | |
5305 | .PD 0 | |
5306 | .TP | |
5307 | .B delete\-char (C\-d) | |
28ef6c31 | 5308 | Delete the character at point. If point is at the |
726f6388 | 5309 | beginning of the line, there are no characters in the line, and |
cce855bc | 5310 | the last character typed was not bound to \fBdelete\-char\fP, |
726f6388 JA |
5311 | then return |
5312 | .SM | |
5313 | .BR EOF . | |
5314 | .TP | |
5315 | .B backward\-delete\-char (Rubout) | |
5316 | Delete the character behind the cursor. When given a numeric argument, | |
ccc6cda3 | 5317 | save the deleted text on the kill ring. |
726f6388 | 5318 | .TP |
b72432fd JA |
5319 | .B forward\-backward\-delete\-char |
5320 | Delete the character under the cursor, unless the cursor is at the | |
5321 | end of the line, in which case the character behind the cursor is | |
f73dda09 | 5322 | deleted. |
b72432fd | 5323 | .TP |
726f6388 | 5324 | .B quoted\-insert (C\-q, C\-v) |
cce855bc | 5325 | Add the next character typed to the line verbatim. This is |
726f6388 JA |
5326 | how to insert characters like \fBC\-q\fP, for example. |
5327 | .TP | |
ccc6cda3 | 5328 | .B tab\-insert (C\-v TAB) |
726f6388 JA |
5329 | Insert a tab character. |
5330 | .TP | |
5331 | .B self\-insert (a,\ b,\ A,\ 1,\ !,\ ...) | |
5332 | Insert the character typed. | |
5333 | .TP | |
5334 | .B transpose\-chars (C\-t) | |
28ef6c31 JA |
5335 | Drag the character before point forward over the character at point, |
5336 | moving point forward as well. | |
5337 | If point is at the end of the line, then this transposes | |
5338 | the two characters before point. | |
bb70624e | 5339 | Negative arguments have no effect. |
726f6388 JA |
5340 | .TP |
5341 | .B transpose\-words (M\-t) | |
bb70624e | 5342 | Drag the word before point past the word after point, |
28ef6c31 | 5343 | moving point over that word as well. |
f73dda09 JA |
5344 | If point is at the end of the line, this transposes |
5345 | the last two words on the line. | |
726f6388 JA |
5346 | .TP |
5347 | .B upcase\-word (M\-u) | |
5348 | Uppercase the current (or following) word. With a negative argument, | |
cce855bc | 5349 | uppercase the previous word, but do not move point. |
726f6388 JA |
5350 | .TP |
5351 | .B downcase\-word (M\-l) | |
5352 | Lowercase the current (or following) word. With a negative argument, | |
cce855bc | 5353 | lowercase the previous word, but do not move point. |
726f6388 JA |
5354 | .TP |
5355 | .B capitalize\-word (M\-c) | |
5356 | Capitalize the current (or following) word. With a negative argument, | |
cce855bc | 5357 | capitalize the previous word, but do not move point. |
7117c2d2 JA |
5358 | .TP |
5359 | .B overwrite\-mode | |
5360 | Toggle overwrite mode. With an explicit positive numeric argument, | |
5361 | switches to overwrite mode. With an explicit non-positive numeric | |
5362 | argument, switches to insert mode. This command affects only | |
5363 | \fBemacs\fP mode; \fBvi\fP mode does overwrite differently. | |
5364 | Each call to \fIreadline()\fP starts in insert mode. | |
5365 | In overwrite mode, characters bound to \fBself\-insert\fP replace | |
5366 | the text at point rather than pushing the text to the right. | |
5367 | Characters bound to \fBbackward\-delete\-char\fP replace the character | |
5368 | before point with a space. By default, this command is unbound. | |
726f6388 JA |
5369 | .PD |
5370 | .SS Killing and Yanking | |
5371 | .PP | |
5372 | .PD 0 | |
5373 | .TP | |
5374 | .B kill\-line (C\-k) | |
bb70624e | 5375 | Kill the text from point to the end of the line. |
726f6388 | 5376 | .TP |
ccc6cda3 | 5377 | .B backward\-kill\-line (C\-x Rubout) |
726f6388 JA |
5378 | Kill backward to the beginning of the line. |
5379 | .TP | |
5380 | .B unix\-line\-discard (C\-u) | |
5381 | Kill backward from point to the beginning of the line. | |
cce855bc | 5382 | The killed text is saved on the kill-ring. |
bb70624e | 5383 | .\" There is no real difference between this and backward-kill-line |
726f6388 JA |
5384 | .TP |
5385 | .B kill\-whole\-line | |
bb70624e | 5386 | Kill all characters on the current line, no matter where point is. |
726f6388 JA |
5387 | .TP |
5388 | .B kill\-word (M\-d) | |
bb70624e JA |
5389 | Kill from point to the end of the current word, or if between |
5390 | words, to the end of the next word. | |
5391 | Word boundaries are the same as those used by \fBforward\-word\fP. | |
726f6388 JA |
5392 | .TP |
5393 | .B backward\-kill\-word (M\-Rubout) | |
bb70624e JA |
5394 | Kill the word behind point. |
5395 | Word boundaries are the same as those used by \fBbackward\-word\fP. | |
726f6388 | 5396 | .TP |
8c2fef19 CR |
5397 | .B shell\-kill\-word (M\-d) |
5398 | Kill from point to the end of the current word, or if between | |
5399 | words, to the end of the next word. | |
5400 | Word boundaries are the same as those used by \fBshell\-forward\-word\fP. | |
5401 | .TP | |
5402 | .B shell\-backward\-kill\-word (M\-Rubout) | |
5403 | Kill the word behind point. | |
5404 | Word boundaries are the same as those used by \fBshell\-backward\-word\fP. | |
5405 | .TP | |
726f6388 | 5406 | .B unix\-word\-rubout (C\-w) |
bb70624e | 5407 | Kill the word behind point, using white space as a word boundary. |
bb70624e | 5408 | The killed text is saved on the kill-ring. |
113d85a4 CR |
5409 | .TP |
5410 | .B unix\-filename\-rubout | |
5411 | Kill the word behind point, using white space and the slash character | |
5412 | as the word boundaries. | |
5413 | The killed text is saved on the kill-ring. | |
ccc6cda3 JA |
5414 | .TP |
5415 | .B delete\-horizontal\-space (M\-\e) | |
5416 | Delete all spaces and tabs around point. | |
5417 | .TP | |
5418 | .B kill\-region | |
bb70624e | 5419 | Kill the text in the current region. |
ccc6cda3 JA |
5420 | .TP |
5421 | .B copy\-region\-as\-kill | |
5422 | Copy the text in the region to the kill buffer. | |
726f6388 | 5423 | .TP |
ccc6cda3 JA |
5424 | .B copy\-backward\-word |
5425 | Copy the word before point to the kill buffer. | |
cce855bc | 5426 | The word boundaries are the same as \fBbackward\-word\fP. |
ccc6cda3 JA |
5427 | .TP |
5428 | .B copy\-forward\-word | |
5429 | Copy the word following point to the kill buffer. | |
cce855bc | 5430 | The word boundaries are the same as \fBforward\-word\fP. |
726f6388 JA |
5431 | .TP |
5432 | .B yank (C\-y) | |
28ef6c31 | 5433 | Yank the top of the kill ring into the buffer at point. |
726f6388 JA |
5434 | .TP |
5435 | .B yank\-pop (M\-y) | |
ccc6cda3 | 5436 | Rotate the kill ring, and yank the new top. Only works following |
726f6388 JA |
5437 | .B yank |
5438 | or | |
5439 | .BR yank\-pop . | |
5440 | .PD | |
5441 | .SS Numeric Arguments | |
5442 | .PP | |
5443 | .PD 0 | |
5444 | .TP | |
5445 | .B digit\-argument (M\-0, M\-1, ..., M\-\-) | |
5446 | Add this digit to the argument already accumulating, or start a new | |
5447 | argument. M\-\- starts a negative argument. | |
5448 | .TP | |
5449 | .B universal\-argument | |
d166f048 JA |
5450 | This is another way to specify an argument. |
5451 | If this command is followed by one or more digits, optionally with a | |
5452 | leading minus sign, those digits define the argument. | |
5453 | If the command is followed by digits, executing | |
5454 | .B universal\-argument | |
5455 | again ends the numeric argument, but is otherwise ignored. | |
5456 | As a special case, if this command is immediately followed by a | |
5457 | character that is neither a digit or minus sign, the argument count | |
5458 | for the next command is multiplied by four. | |
726f6388 | 5459 | The argument count is initially one, so executing this function the |
d166f048 JA |
5460 | first time makes the argument count four, a second time makes the |
5461 | argument count sixteen, and so on. | |
726f6388 JA |
5462 | .PD |
5463 | .SS Completing | |
5464 | .PP | |
5465 | .PD 0 | |
5466 | .TP | |
5467 | .B complete (TAB) | |
5468 | Attempt to perform completion on the text before point. | |
5469 | .B Bash | |
5470 | attempts completion treating the text as a variable (if the | |
5471 | text begins with \fB$\fP), username (if the text begins with | |
5472 | \fB~\fP), hostname (if the text begins with \fB@\fP), or | |
5473 | command (including aliases and functions) in turn. If none | |
5474 | of these produces a match, filename completion is attempted. | |
5475 | .TP | |
ccc6cda3 | 5476 | .B possible\-completions (M\-?) |
726f6388 JA |
5477 | List the possible completions of the text before point. |
5478 | .TP | |
ccc6cda3 | 5479 | .B insert\-completions (M\-*) |
726f6388 JA |
5480 | Insert all completions of the text before point |
5481 | that would have been generated by | |
ccc6cda3 | 5482 | \fBpossible\-completions\fP. |
726f6388 | 5483 | .TP |
cce855bc JA |
5484 | .B menu\-complete |
5485 | Similar to \fBcomplete\fP, but replaces the word to be completed | |
5486 | with a single match from the list of possible completions. | |
5487 | Repeated execution of \fBmenu\-complete\fP steps through the list | |
5488 | of possible completions, inserting each match in turn. | |
28ef6c31 | 5489 | At the end of the list of completions, the bell is rung |
f73dda09 | 5490 | (subject to the setting of \fBbell\-style\fP) |
28ef6c31 | 5491 | and the original text is restored. |
cce855bc JA |
5492 | An argument of \fIn\fP moves \fIn\fP positions forward in the list |
5493 | of matches; a negative argument may be used to move backward | |
5494 | through the list. | |
5495 | This command is intended to be bound to \fBTAB\fP, but is unbound | |
5496 | by default. | |
5497 | .TP | |
9dd88db7 CR |
5498 | .B menu\-complete-\backward |
5499 | Identical to \fBmenu\-complete\fP, but moves backward through the list | |
5500 | of possible completions, as if \fBmenu\-complete\fP had been given a | |
5501 | negative argument. This command is unbound by default. | |
5502 | .TP | |
b72432fd JA |
5503 | .B delete\-char\-or\-list |
5504 | Deletes the character under the cursor if not at the beginning or | |
bb70624e | 5505 | end of the line (like \fBdelete\-char\fP). |
b72432fd | 5506 | If at the end of the line, behaves identically to |
bb70624e | 5507 | \fBpossible\-completions\fP. |
b72432fd JA |
5508 | This command is unbound by default. |
5509 | .TP | |
726f6388 JA |
5510 | .B complete\-filename (M\-/) |
5511 | Attempt filename completion on the text before point. | |
5512 | .TP | |
5513 | .B possible\-filename\-completions (C\-x /) | |
5514 | List the possible completions of the text before point, | |
5515 | treating it as a filename. | |
5516 | .TP | |
5517 | .B complete\-username (M\-~) | |
5518 | Attempt completion on the text before point, treating | |
5519 | it as a username. | |
5520 | .TP | |
5521 | .B possible\-username\-completions (C\-x ~) | |
5522 | List the possible completions of the text before point, | |
5523 | treating it as a username. | |
5524 | .TP | |
5525 | .B complete\-variable (M\-$) | |
5526 | Attempt completion on the text before point, treating | |
5527 | it as a shell variable. | |
5528 | .TP | |
5529 | .B possible\-variable\-completions (C\-x $) | |
5530 | List the possible completions of the text before point, | |
5531 | treating it as a shell variable. | |
5532 | .TP | |
5533 | .B complete\-hostname (M\-@) | |
5534 | Attempt completion on the text before point, treating | |
5535 | it as a hostname. | |
5536 | .TP | |
5537 | .B possible\-hostname\-completions (C\-x @) | |
5538 | List the possible completions of the text before point, | |
5539 | treating it as a hostname. | |
5540 | .TP | |
5541 | .B complete\-command (M\-!) | |
5542 | Attempt completion on the text before point, treating | |
5543 | it as a command name. Command completion attempts to | |
5544 | match the text against aliases, reserved words, shell | |
cce855bc | 5545 | functions, shell builtins, and finally executable filenames, |
726f6388 JA |
5546 | in that order. |
5547 | .TP | |
5548 | .B possible\-command\-completions (C\-x !) | |
5549 | List the possible completions of the text before point, | |
5550 | treating it as a command name. | |
5551 | .TP | |
ccc6cda3 | 5552 | .B dynamic\-complete\-history (M\-TAB) |
726f6388 JA |
5553 | Attempt completion on the text before point, comparing |
5554 | the text against lines from the history list for possible | |
5555 | completion matches. | |
5556 | .TP | |
8943768b CR |
5557 | .B dabbrev\-expand |
5558 | Attempt menu completion on the text before point, comparing | |
5559 | the text against lines from the history list for possible | |
5560 | completion matches. | |
5561 | .TP | |
726f6388 | 5562 | .B complete\-into\-braces (M\-{) |
bb70624e | 5563 | Perform filename completion and insert the list of possible completions |
726f6388 JA |
5564 | enclosed within braces so the list is available to the shell (see |
5565 | .B Brace Expansion | |
5566 | above). | |
5567 | .PD | |
5568 | .SS Keyboard Macros | |
5569 | .PP | |
5570 | .PD 0 | |
5571 | .TP | |
ccc6cda3 | 5572 | .B start\-kbd\-macro (C\-x (\^) |
726f6388 JA |
5573 | Begin saving the characters typed into the current keyboard macro. |
5574 | .TP | |
ccc6cda3 | 5575 | .B end\-kbd\-macro (C\-x )\^) |
726f6388 | 5576 | Stop saving the characters typed into the current keyboard macro |
ccc6cda3 | 5577 | and store the definition. |
726f6388 | 5578 | .TP |
ccc6cda3 | 5579 | .B call\-last\-kbd\-macro (C\-x e) |
726f6388 JA |
5580 | Re-execute the last keyboard macro defined, by making the characters |
5581 | in the macro appear as if typed at the keyboard. | |
5582 | .PD | |
5583 | .SS Miscellaneous | |
5584 | .PP | |
5585 | .PD 0 | |
5586 | .TP | |
5587 | .B re\-read\-init\-file (C\-x C\-r) | |
ccc6cda3 | 5588 | Read in the contents of the \fIinputrc\fP file, and incorporate |
726f6388 JA |
5589 | any bindings or variable assignments found there. |
5590 | .TP | |
5591 | .B abort (C\-g) | |
5592 | Abort the current editing command and | |
5593 | ring the terminal's bell (subject to the setting of | |
5594 | .BR bell\-style ). | |
5595 | .TP | |
ccc6cda3 JA |
5596 | .B do\-uppercase\-version (M\-a, M\-b, M\-\fIx\fP, ...) |
5597 | If the metafied character \fIx\fP is lowercase, run the command | |
5598 | that is bound to the corresponding uppercase character. | |
726f6388 JA |
5599 | .TP |
5600 | .B prefix\-meta (ESC) | |
5601 | Metafy the next character typed. | |
5602 | .SM | |
5603 | .B ESC | |
5604 | .B f | |
5605 | is equivalent to | |
5606 | .BR Meta\-f . | |
5607 | .TP | |
5608 | .B undo (C\-_, C\-x C\-u) | |
5609 | Incremental undo, separately remembered for each line. | |
5610 | .TP | |
5611 | .B revert\-line (M\-r) | |
cce855bc | 5612 | Undo all changes made to this line. This is like executing the |
726f6388 JA |
5613 | .B undo |
5614 | command enough times to return the line to its initial state. | |
5615 | .TP | |
b72432fd | 5616 | .B tilde\-expand (M\-&) |
726f6388 JA |
5617 | Perform tilde expansion on the current word. |
5618 | .TP | |
ccc6cda3 | 5619 | .B set\-mark (C\-@, M\-<space>) |
28ef6c31 | 5620 | Set the mark to the point. If a |
ccc6cda3 JA |
5621 | numeric argument is supplied, the mark is set to that position. |
5622 | .TP | |
5623 | .B exchange\-point\-and\-mark (C\-x C\-x) | |
5624 | Swap the point with the mark. The current cursor position is set to | |
5625 | the saved position, and the old cursor position is saved as the mark. | |
5626 | .TP | |
5627 | .B character\-search (C\-]) | |
5628 | A character is read and point is moved to the next occurrence of that | |
5629 | character. A negative count searches for previous occurrences. | |
5630 | .TP | |
5631 | .B character\-search\-backward (M\-C\-]) | |
5632 | A character is read and point is moved to the previous occurrence of that | |
5633 | character. A negative count searches for subsequent occurrences. | |
5634 | .TP | |
5635 | .B insert\-comment (M\-#) | |
7117c2d2 | 5636 | Without a numeric argument, the value of the readline |
ccc6cda3 | 5637 | .B comment\-begin |
7117c2d2 JA |
5638 | variable is inserted at the beginning of the current line. |
5639 | If a numeric argument is supplied, this command acts as a toggle: if | |
5640 | the characters at the beginning of the line do not match the value | |
5641 | of \fBcomment\-begin\fP, the value is inserted, otherwise | |
db31fb26 | 5642 | the characters in \fBcomment\-begin\fP are deleted from the beginning of |
7117c2d2 JA |
5643 | the line. |
5644 | In either case, the line is accepted as if a newline had been typed. | |
5645 | The default value of | |
bb70624e | 5646 | \fBcomment\-begin\fP causes this command to make the current line |
ccc6cda3 | 5647 | a shell comment. |
7117c2d2 JA |
5648 | If a numeric argument causes the comment character to be removed, the line |
5649 | will be executed by the shell. | |
5650 | .TP | |
5651 | .B glob\-complete\-word (M\-g) | |
5652 | The word before point is treated as a pattern for pathname expansion, | |
5653 | with an asterisk implicitly appended. This pattern is used to | |
5654 | generate a list of matching file names for possible completions. | |
ccc6cda3 JA |
5655 | .TP |
5656 | .B glob\-expand\-word (C\-x *) | |
5657 | The word before point is treated as a pattern for pathname expansion, | |
5658 | and the list of matching file names is inserted, replacing the word. | |
7117c2d2 JA |
5659 | If a numeric argument is supplied, an asterisk is appended before |
5660 | pathname expansion. | |
ccc6cda3 JA |
5661 | .TP |
5662 | .B glob\-list\-expansions (C\-x g) | |
5663 | The list of expansions that would have been generated by | |
5664 | .B glob\-expand\-word | |
5665 | is displayed, and the line is redrawn. | |
7117c2d2 JA |
5666 | If a numeric argument is supplied, an asterisk is appended before |
5667 | pathname expansion. | |
ccc6cda3 | 5668 | .TP |
726f6388 JA |
5669 | .B dump\-functions |
5670 | Print all of the functions and their key bindings to the | |
5671 | readline output stream. If a numeric argument is supplied, | |
5672 | the output is formatted in such a way that it can be made part | |
5673 | of an \fIinputrc\fP file. | |
5674 | .TP | |
ccc6cda3 JA |
5675 | .B dump\-variables |
5676 | Print all of the settable readline variables and their values to the | |
5677 | readline output stream. If a numeric argument is supplied, | |
5678 | the output is formatted in such a way that it can be made part | |
5679 | of an \fIinputrc\fP file. | |
5680 | .TP | |
5681 | .B dump\-macros | |
5682 | Print all of the readline key sequences bound to macros and the | |
22e63b05 | 5683 | strings they output. If a numeric argument is supplied, |
ccc6cda3 JA |
5684 | the output is formatted in such a way that it can be made part |
5685 | of an \fIinputrc\fP file. | |
5686 | .TP | |
726f6388 JA |
5687 | .B display\-shell\-version (C\-x C\-v) |
5688 | Display version information about the current instance of | |
5689 | .BR bash . | |
5690 | .PD | |
bb70624e JA |
5691 | .SS Programmable Completion |
5692 | .PP | |
5693 | When word completion is attempted for an argument to a command for | |
5694 | which a completion specification (a \fIcompspec\fP) has been defined | |
5695 | using the \fBcomplete\fP builtin (see | |
5696 | .SM | |
5697 | .B "SHELL BUILTIN COMMANDS" | |
5698 | below), the programmable completion facilities are invoked. | |
5699 | .PP | |
5700 | First, the command name is identified. | |
3eb2d94a CR |
5701 | If the command word is the empty string (completion attempted at the |
5702 | beginning of an empty line), any compspec defined with | |
5703 | the \fB\-E\fP option to \fBcomplete\fP is used. | |
bb70624e JA |
5704 | If a compspec has been defined for that command, the |
5705 | compspec is used to generate the list of possible completions for the word. | |
5706 | If the command word is a full pathname, a compspec for the full | |
5707 | pathname is searched for first. | |
5708 | If no compspec is found for the full pathname, an attempt is made to | |
5709 | find a compspec for the portion following the final slash. | |
3eb2d94a CR |
5710 | If those searches to not result in a compspec, any compspec defined with |
5711 | the \fB\-D\fP option to \fBcomplete\fP is used as the default. | |
bb70624e JA |
5712 | .PP |
5713 | Once a compspec has been found, it is used to generate the list of | |
5714 | matching words. | |
5715 | If a compspec is not found, the default \fBbash\fP completion as | |
5716 | described above under \fBCompleting\fP is performed. | |
5717 | .PP | |
5718 | First, the actions specified by the compspec are used. | |
5719 | Only matches which are prefixed by the word being completed are | |
5720 | returned. | |
5721 | When the | |
5722 | .B \-f | |
5723 | or | |
5724 | .B \-d | |
5725 | option is used for filename or directory name completion, the shell | |
5726 | variable | |
5727 | .SM | |
5728 | .B FIGNORE | |
5729 | is used to filter the matches. | |
5730 | .PP | |
d0ca3503 | 5731 | Any completions specified by a pathname expansion pattern to the |
bb70624e JA |
5732 | \fB\-G\fP option are generated next. |
5733 | The words generated by the pattern need not match the word | |
5734 | being completed. | |
5735 | The | |
5736 | .SM | |
5737 | .B GLOBIGNORE | |
5738 | shell variable is not used to filter the matches, but the | |
5739 | .SM | |
5740 | .B FIGNORE | |
5741 | variable is used. | |
5742 | .PP | |
5743 | Next, the string specified as the argument to the \fB\-W\fP option | |
5744 | is considered. | |
5745 | The string is first split using the characters in the | |
5746 | .SM | |
5747 | .B IFS | |
5748 | special variable as delimiters. | |
5749 | Shell quoting is honored. | |
5750 | Each word is then expanded using | |
5751 | brace expansion, tilde expansion, parameter and variable expansion, | |
6e70dbff | 5752 | command substitution, and arithmetic expansion, |
bb70624e JA |
5753 | as described above under |
5754 | .SM | |
5755 | .BR EXPANSION . | |
5756 | The results are split using the rules described above under | |
5757 | \fBWord Splitting\fP. | |
5758 | The results of the expansion are prefix-matched against the word being | |
5759 | completed, and the matching words become the possible completions. | |
5760 | .PP | |
5761 | After these matches have been generated, any shell function or command | |
5762 | specified with the \fB\-F\fP and \fB\-C\fP options is invoked. | |
5763 | When the command or function is invoked, the | |
5764 | .SM | |
d3ad40de CR |
5765 | .BR COMP_LINE , |
5766 | .SM | |
5767 | .BR COMP_POINT , | |
5768 | .SM | |
5769 | .BR COMP_KEY , | |
bb70624e JA |
5770 | and |
5771 | .SM | |
d3ad40de | 5772 | .B COMP_TYPE |
bb70624e JA |
5773 | variables are assigned values as described above under |
5774 | \fBShell Variables\fP. | |
5775 | If a shell function is being invoked, the | |
5776 | .SM | |
5777 | .B COMP_WORDS | |
5778 | and | |
5779 | .SM | |
5780 | .B COMP_CWORD | |
5781 | variables are also set. | |
5782 | When the function or command is invoked, the first argument is the | |
5783 | name of the command whose arguments are being completed, the | |
5784 | second argument is the word being completed, and the third argument | |
5785 | is the word preceding the word being completed on the current command line. | |
5786 | No filtering of the generated completions against the word being completed | |
5787 | is performed; the function or command has complete freedom in generating | |
5788 | the matches. | |
5789 | .PP | |
5790 | Any function specified with \fB\-F\fP is invoked first. | |
5791 | The function may use any of the shell facilities, including the | |
5792 | \fBcompgen\fP builtin described below, to generate the matches. | |
5793 | It must put the possible completions in the | |
5794 | .SM | |
5795 | .B COMPREPLY | |
5796 | array variable. | |
5797 | .PP | |
5798 | Next, any command specified with the \fB\-C\fP option is invoked | |
5799 | in an environment equivalent to command substitution. | |
5800 | It should print a list of completions, one per line, to the | |
5801 | standard output. | |
5802 | Backslash may be used to escape a newline, if necessary. | |
5803 | .PP | |
5804 | After all of the possible completions are generated, any filter | |
5805 | specified with the \fB\-X\fP option is applied to the list. | |
5806 | The filter is a pattern as used for pathname expansion; a \fB&\fP | |
5807 | in the pattern is replaced with the text of the word being completed. | |
5808 | A literal \fB&\fP may be escaped with a backslash; the backslash | |
5809 | is removed before attempting a match. | |
5810 | Any completion that matches the pattern will be removed from the list. | |
5811 | A leading \fB!\fP negates the pattern; in this case any completion | |
5812 | not matching the pattern will be removed. | |
5813 | .PP | |
5814 | Finally, any prefix and suffix specified with the \fB\-P\fP and \fB\-S\fP | |
5815 | options are added to each member of the completion list, and the result is | |
5816 | returned to the readline completion code as the list of possible | |
5817 | completions. | |
5818 | .PP | |
28ef6c31 JA |
5819 | If the previously-applied actions do not generate any matches, and the |
5820 | \fB\-o dirnames\fP option was supplied to \fBcomplete\fP when the | |
5821 | compspec was defined, directory name completion is attempted. | |
5822 | .PP | |
d3a24ed2 CR |
5823 | If the \fB\-o plusdirs\fP option was supplied to \fBcomplete\fP when the |
5824 | compspec was defined, directory name completion is attempted and any | |
5825 | matches are added to the results of the other actions. | |
5826 | .PP | |
28ef6c31 JA |
5827 | By default, if a compspec is found, whatever it generates is returned |
5828 | to the completion code as the full set of possible completions. | |
bb70624e JA |
5829 | The default \fBbash\fP completions are not attempted, and the readline |
5830 | default of filename completion is disabled. | |
d3a24ed2 CR |
5831 | If the \fB\-o bashdefault\fP option was supplied to \fBcomplete\fP when |
5832 | the compspec was defined, the \fBbash\fP default completions are attempted | |
28ef6c31 | 5833 | if the compspec generates no matches. |
d3a24ed2 CR |
5834 | If the \fB\-o default\fP option was supplied to \fBcomplete\fP when the |
5835 | compspec was defined, readline's default completion will be performed | |
5836 | if the compspec (and, if attempted, the default \fBbash\fP completions) | |
5837 | generate no matches. | |
7117c2d2 JA |
5838 | .PP |
5839 | When a compspec indicates that directory name completion is desired, | |
5840 | the programmable completion functions force readline to append a slash | |
5841 | to completed names which are symbolic links to directories, subject to | |
5842 | the value of the \fBmark\-directories\fP readline variable, regardless | |
5843 | of the setting of the \fBmark-symlinked\-directories\fP readline variable. | |
3eb2d94a CR |
5844 | .PP |
5845 | There is some support for dynamically modifying completions. This is | |
5846 | most useful when used in combination with a default completion specified | |
5847 | with \fBcomplete -D\fP. | |
5848 | It's possible for shell functions executed as completion | |
5849 | handlers to indicate that completion should be retried by returning an | |
5850 | exit status of 124. If a shell function returns 124, and changes | |
5851 | the compspec associated with the command on which completion is being | |
5852 | attempted (supplied as the first argument when the function is executed), | |
5853 | programmable completion restarts from the beginning, with an | |
5854 | attempt to find a compspec for that command. This allows a set of | |
5855 | completions to be built dynamically as completion is attempted, rather than | |
5856 | being loaded all at once. | |
5857 | .PP | |
5858 | For instance, assuming that there is a library of compspecs, each kept in a | |
5859 | file corresponding to the name of the command, the following default | |
5860 | completion function would load completions dynamically: | |
5861 | .PP | |
5862 | \f(CW_completion_loader() | |
5863 | .br | |
5864 | { | |
5865 | .br | |
5866 | . "/etc/bash_completion.d/$1.sh" >/dev/null 2>&1 && return 124 | |
5867 | .br | |
5868 | } | |
5869 | .br | |
5870 | complete -D -F _completion_loader | |
5871 | .br | |
5872 | \fP | |
726f6388 | 5873 | .SH HISTORY |
ccc6cda3 | 5874 | When the |
d166f048 | 5875 | .B \-o history |
ccc6cda3 JA |
5876 | option to the |
5877 | .B set | |
5878 | builtin is enabled, the shell provides access to the | |
5879 | \fIcommand history\fP, | |
bb70624e JA |
5880 | the list of commands previously typed. |
5881 | The value of the \fBHISTSIZE\fP variable is used as the | |
5882 | number of commands to save in a history list. | |
5883 | The text of the last | |
726f6388 JA |
5884 | .SM |
5885 | .B HISTSIZE | |
bb70624e | 5886 | commands (default 500) is saved. The shell |
726f6388 JA |
5887 | stores each command in the history list prior to parameter and |
5888 | variable expansion (see | |
5889 | .SM | |
5890 | .B EXPANSION | |
5891 | above) but after history expansion is performed, subject to the | |
5892 | values of the shell variables | |
ccc6cda3 JA |
5893 | .SM |
5894 | .B HISTIGNORE | |
726f6388 JA |
5895 | and |
5896 | .SM | |
5897 | .BR HISTCONTROL . | |
bb70624e | 5898 | .PP |
726f6388 JA |
5899 | On startup, the history is initialized from the file named by |
5900 | the variable | |
5901 | .SM | |
5902 | .B HISTFILE | |
5903 | (default \fI~/.bash_history\fP). | |
bb70624e | 5904 | The file named by the value of |
726f6388 JA |
5905 | .SM |
5906 | .B HISTFILE | |
5907 | is truncated, if necessary, to contain no more than | |
bb70624e | 5908 | the number of lines specified by the value of |
726f6388 | 5909 | .SM |
bb70624e | 5910 | .BR HISTFILESIZE . |
d3ad40de CR |
5911 | When the history file is read, |
5912 | lines beginning with the history comment character followed immediately | |
5913 | by a digit are interpreted as timestamps for the preceding history line. | |
5914 | These timestamps are optionally displayed depending on the value of the | |
5915 | .SM | |
5916 | .B HISTTIMEFORMAT | |
5917 | variable. | |
ccc6cda3 JA |
5918 | When an interactive shell exits, the last |
5919 | .SM | |
bb70624e | 5920 | .B $HISTSIZE |
ccc6cda3 JA |
5921 | lines are copied from the history list to |
5922 | .SM | |
bb70624e | 5923 | .BR $HISTFILE . |
ccc6cda3 JA |
5924 | If the |
5925 | .B histappend | |
5926 | shell option is enabled | |
5927 | (see the description of | |
5928 | .B shopt | |
5929 | under | |
5930 | .SM | |
5931 | .B "SHELL BUILTIN COMMANDS" | |
5932 | below), the lines are appended to the history file, | |
5933 | otherwise the history file is overwritten. | |
5934 | If | |
5935 | .SM | |
5936 | .B HISTFILE | |
5937 | is unset, or if the history file is unwritable, the history is | |
d3ad40de CR |
5938 | not saved. |
5939 | If the | |
5940 | .SM | |
5941 | .HISTTIMEFORMAT | |
5942 | variable is set, time stamps are written to the history file, marked | |
5943 | with the history comment character, so | |
5944 | they may be preserved across shell sessions. | |
5945 | This uses the history comment character to distinguish timestamps from | |
5946 | other history lines. | |
5947 | After saving the history, the history file is truncated | |
ccc6cda3 JA |
5948 | to contain no more than |
5949 | .SM | |
5950 | .B HISTFILESIZE | |
5951 | lines. If | |
5952 | .SM | |
5953 | .B HISTFILESIZE | |
5954 | is not set, no truncation is performed. | |
5955 | .PP | |
726f6388 JA |
5956 | The builtin command |
5957 | .B fc | |
5958 | (see | |
5959 | .SM | |
5960 | .B SHELL BUILTIN COMMANDS | |
5961 | below) may be used to list or edit and re-execute a portion of | |
5962 | the history list. | |
5963 | The | |
5964 | .B history | |
bb70624e | 5965 | builtin may be used to display or modify the history list and |
ccc6cda3 | 5966 | manipulate the history file. |
bb70624e | 5967 | When using command-line editing, search commands |
726f6388 | 5968 | are available in each editing mode that provide access to the |
ccc6cda3 JA |
5969 | history list. |
5970 | .PP | |
5971 | The shell allows control over which commands are saved on the history | |
5972 | list. The | |
726f6388 | 5973 | .SM |
ccc6cda3 JA |
5974 | .B HISTCONTROL |
5975 | and | |
726f6388 | 5976 | .SM |
ccc6cda3 JA |
5977 | .B HISTIGNORE |
5978 | variables may be set to cause the shell to save only a subset of the | |
5979 | commands entered. | |
5980 | The | |
5981 | .B cmdhist | |
5982 | shell option, if enabled, causes the shell to attempt to save each | |
5983 | line of a multi-line command in the same history entry, adding | |
5984 | semicolons where necessary to preserve syntactic correctness. | |
5985 | The | |
5986 | .B lithist | |
5987 | shell option causes the shell to save the command with embedded newlines | |
5988 | instead of semicolons. See the description of the | |
5989 | .B shopt | |
5990 | builtin below under | |
5991 | .SM | |
5992 | .B "SHELL BUILTIN COMMANDS" | |
5993 | for information on setting and unsetting shell options. | |
726f6388 JA |
5994 | .SH "HISTORY EXPANSION" |
5995 | .PP | |
5996 | The shell supports a history expansion feature that | |
5997 | is similar to the history expansion in | |
5998 | .BR csh. | |
5999 | This section describes what syntax features are available. This | |
6000 | feature is enabled by default for interactive shells, and can be | |
6001 | disabled using the | |
6002 | .B \+H | |
6003 | option to the | |
6004 | .B set | |
6005 | builtin command (see | |
6006 | .SM | |
6007 | .B SHELL BUILTIN COMMANDS | |
ccc6cda3 JA |
6008 | below). Non-interactive shells do not perform history expansion |
6009 | by default. | |
6010 | .PP | |
6011 | History expansions introduce words from the history list into | |
6012 | the input stream, making it easy to repeat commands, insert the | |
6013 | arguments to a previous command into the current input line, or | |
6014 | fix errors in previous commands quickly. | |
726f6388 JA |
6015 | .PP |
6016 | History expansion is performed immediately after a complete line | |
6017 | is read, before the shell breaks it into words. | |
ccc6cda3 | 6018 | It takes place in two parts. |
cce855bc | 6019 | The first is to determine which line from the history list |
ccc6cda3 JA |
6020 | to use during substitution. |
6021 | The second is to select portions of that line for inclusion into | |
6022 | the current one. | |
cce855bc | 6023 | The line selected from the history is the \fIevent\fP, |
ccc6cda3 JA |
6024 | and the portions of that line that are acted upon are \fIwords\fP. |
6025 | Various \fImodifiers\fP are available to manipulate the selected words. | |
6026 | The line is broken into words in the same fashion as when reading input, | |
6027 | so that several \fImetacharacter\fP-separated words surrounded by | |
cce855bc | 6028 | quotes are considered one word. |
ccc6cda3 JA |
6029 | History expansions are introduced by the appearance of the |
6030 | history expansion character, which is \^\fB!\fP\^ by default. | |
6031 | Only backslash (\^\fB\e\fP\^) and single quotes can quote | |
6032 | the history expansion character. | |
6033 | .PP | |
d3a24ed2 CR |
6034 | Several characters inhibit history expansion if found immediately |
6035 | following the history expansion character, even if it is unquoted: | |
6036 | space, tab, newline, carriage return, and \fB=\fP. | |
6037 | If the \fBextglob\fP shell option is enabled, \fB(\fP will also | |
6038 | inhibit expansion. | |
6039 | .PP | |
ccc6cda3 JA |
6040 | Several shell options settable with the |
6041 | .B shopt | |
6042 | builtin may be used to tailor the behavior of history expansion. | |
6043 | If the | |
6044 | .B histverify | |
6045 | shell option is enabled (see the description of the | |
6046 | .B shopt | |
6047 | builtin), and | |
6048 | .B readline | |
6049 | is being used, history substitutions are not immediately passed to | |
6050 | the shell parser. | |
6051 | Instead, the expanded line is reloaded into the | |
6052 | .B readline | |
6053 | editing buffer for further modification. | |
6054 | If | |
6055 | .B readline | |
6056 | is being used, and the | |
6057 | .B histreedit | |
6058 | shell option is enabled, a failed history substitution will be reloaded | |
6059 | into the | |
6060 | .B readline | |
6061 | editing buffer for correction. | |
6062 | The | |
6063 | .B \-p | |
6064 | option to the | |
6065 | .B history | |
6066 | builtin command may be used to see what a history expansion will | |
6067 | do before using it. | |
6068 | The | |
6069 | .B \-s | |
6070 | option to the | |
6071 | .B history | |
6072 | builtin may be used to add commands to the end of the history list | |
6073 | without actually executing them, so that they are available for | |
6074 | subsequent recall. | |
726f6388 JA |
6075 | .PP |
6076 | The shell allows control of the various characters used by the | |
6077 | history expansion mechanism (see the description of | |
6078 | .B histchars | |
6079 | above under | |
6080 | .BR "Shell Variables" ). | |
d3ad40de CR |
6081 | The shell uses |
6082 | the history comment character to mark history timestamps when | |
6083 | writing the history file. | |
726f6388 JA |
6084 | .SS Event Designators |
6085 | .PP | |
6086 | An event designator is a reference to a command line entry in the | |
6087 | history list. | |
6088 | .PP | |
6089 | .PD 0 | |
6090 | .TP | |
6091 | .B ! | |
6092 | Start a history substitution, except when followed by a | |
6093 | .BR blank , | |
d3a24ed2 CR |
6094 | newline, carriage return, = |
6095 | or ( (when the \fBextglob\fP shell option is enabled using | |
6096 | the \fBshopt\fP builtin). | |
726f6388 | 6097 | .TP |
726f6388 JA |
6098 | .B !\fIn\fR |
6099 | Refer to command line | |
6100 | .IR n . | |
6101 | .TP | |
6102 | .B !\-\fIn\fR | |
6103 | Refer to the current command line minus | |
6104 | .IR n . | |
6105 | .TP | |
ccc6cda3 JA |
6106 | .B !! |
6107 | Refer to the previous command. This is a synonym for `!\-1'. | |
6108 | .TP | |
726f6388 JA |
6109 | .B !\fIstring\fR |
6110 | Refer to the most recent command starting with | |
6111 | .IR string . | |
6112 | .TP | |
6113 | .B !?\fIstring\fR\fB[?]\fR | |
6114 | Refer to the most recent command containing | |
6115 | .IR string . | |
ccc6cda3 JA |
6116 | The trailing \fB?\fP may be omitted if |
6117 | .I string | |
6118 | is followed immediately by a newline. | |
726f6388 JA |
6119 | .TP |
6120 | .B \d\s+2^\s-2\u\fIstring1\fP\d\s+2^\s-2\u\fIstring2\fP\d\s+2^\s-2\u | |
6121 | Quick substitution. Repeat the last command, replacing | |
6122 | .I string1 | |
6123 | with | |
6124 | .IR string2 . | |
6125 | Equivalent to | |
6126 | ``!!:s/\fIstring1\fP/\fIstring2\fP/'' | |
6127 | (see \fBModifiers\fP below). | |
6128 | .TP | |
6129 | .B !# | |
6130 | The entire command line typed so far. | |
6131 | .PD | |
6132 | .SS Word Designators | |
6133 | .PP | |
ccc6cda3 | 6134 | Word designators are used to select desired words from the event. |
726f6388 JA |
6135 | A |
6136 | .B : | |
ccc6cda3 | 6137 | separates the event specification from the word designator. |
cce855bc | 6138 | It may be omitted if the word designator begins with a |
726f6388 JA |
6139 | .BR ^ , |
6140 | .BR $ , | |
6141 | .BR * , | |
ccc6cda3 | 6142 | .BR \- , |
726f6388 JA |
6143 | or |
6144 | .BR % . | |
6145 | Words are numbered from the beginning of the line, | |
ccc6cda3 JA |
6146 | with the first word being denoted by 0 (zero). |
6147 | Words are inserted into the current line separated by single spaces. | |
726f6388 JA |
6148 | .PP |
6149 | .PD 0 | |
6150 | .TP | |
6151 | .B 0 (zero) | |
6152 | The zeroth word. For the shell, this is the command | |
6153 | word. | |
6154 | .TP | |
6155 | .I n | |
6156 | The \fIn\fRth word. | |
6157 | .TP | |
6158 | .B ^ | |
6159 | The first argument. That is, word 1. | |
6160 | .TP | |
6161 | .B $ | |
6162 | The last argument. | |
6163 | .TP | |
6164 | .B % | |
6165 | The word matched by the most recent `?\fIstring\fR?' search. | |
6166 | .TP | |
6167 | .I x\fB\-\fPy | |
6168 | A range of words; `\-\fIy\fR' abbreviates `0\-\fIy\fR'. | |
6169 | .TP | |
6170 | .B * | |
6171 | All of the words but the zeroth. This is a synonym | |
6172 | for `\fI1\-$\fP'. It is not an error to use | |
6173 | .B * | |
6174 | if there is just one | |
6175 | word in the event; the empty string is returned in that case. | |
6176 | .TP | |
6177 | .B x* | |
6178 | Abbreviates \fIx\-$\fP. | |
6179 | .TP | |
6180 | .B x\- | |
6181 | Abbreviates \fIx\-$\fP like \fBx*\fP, but omits the last word. | |
6182 | .PD | |
ccc6cda3 JA |
6183 | .PP |
6184 | If a word designator is supplied without an event specification, the | |
6185 | previous command is used as the event. | |
726f6388 JA |
6186 | .SS Modifiers |
6187 | .PP | |
ccc6cda3 JA |
6188 | After the optional word designator, there may appear a sequence of |
6189 | one or more of the following modifiers, each preceded by a `:'. | |
726f6388 JA |
6190 | .PP |
6191 | .PD 0 | |
6192 | .PP | |
6193 | .TP | |
6194 | .B h | |
ccc6cda3 JA |
6195 | Remove a trailing file name component, leaving only the head. |
6196 | .TP | |
6197 | .B t | |
6198 | Remove all leading file name components, leaving the tail. | |
726f6388 JA |
6199 | .TP |
6200 | .B r | |
6201 | Remove a trailing suffix of the form \fI.xxx\fP, leaving the | |
6202 | basename. | |
6203 | .TP | |
6204 | .B e | |
6205 | Remove all but the trailing suffix. | |
6206 | .TP | |
726f6388 JA |
6207 | .B p |
6208 | Print the new command but do not execute it. | |
6209 | .TP | |
6210 | .B q | |
6211 | Quote the substituted words, escaping further substitutions. | |
6212 | .TP | |
cce855bc JA |
6213 | .B x |
6214 | Quote the substituted words as with | |
6215 | .BR q , | |
6216 | but break into words at | |
6217 | .B blanks | |
6218 | and newlines. | |
726f6388 | 6219 | .TP |
cce855bc JA |
6220 | .B s/\fIold\fP/\fInew\fP/ |
6221 | Substitute | |
6222 | .I new | |
6223 | for the first occurrence of | |
6224 | .I old | |
6225 | in the event line. Any delimiter can be used in place of /. The | |
6226 | final delimiter is optional if it is the last character of the | |
6227 | event line. The delimiter may be quoted in | |
6228 | .I old | |
6229 | and | |
6230 | .I new | |
6231 | with a single backslash. If & appears in | |
6232 | .IR new , | |
6233 | it is replaced by | |
6234 | .IR old . | |
6235 | A single backslash will quote the &. If | |
6236 | .I old | |
6237 | is null, it is set to the last | |
6238 | .I old | |
6239 | substituted, or, if no previous history substitutions took place, | |
6240 | the last | |
6241 | .I string | |
6242 | in a | |
6243 | .B !?\fIstring\fR\fB[?]\fR | |
6244 | search. | |
ccc6cda3 | 6245 | .TP |
cce855bc JA |
6246 | .B & |
6247 | Repeat the previous substitution. | |
6248 | .TP | |
6249 | .B g | |
6250 | Cause changes to be applied over the entire event line. This is | |
6251 | used in conjunction with `\fB:s\fP' (e.g., `\fB:gs/\fIold\fP/\fInew\fP/\fR') | |
6252 | or `\fB:&\fP'. If used with | |
6253 | `\fB:s\fP', any delimiter can be used | |
6254 | in place of /, and the final delimiter is optional | |
6255 | if it is the last character of the event line. | |
d3a24ed2 CR |
6256 | An \fBa\fP may be used as a synonym for \fBg\fP. |
6257 | .TP | |
6258 | .B G | |
6259 | Apply the following `\fBs\fP' modifier once to each word in the event line. | |
726f6388 | 6260 | .PD |
726f6388 JA |
6261 | .SH "SHELL BUILTIN COMMANDS" |
6262 | .\" start of bash_builtins | |
6263 | .zZ | |
ccc6cda3 JA |
6264 | .PP |
6265 | Unless otherwise noted, each builtin command documented in this | |
6266 | section as accepting options preceded by | |
6267 | .B \- | |
6268 | accepts | |
6269 | .B \-\- | |
6270 | to signify the end of the options. | |
6932f7f5 CR |
6271 | The \fB:\fP, \fBtrue\fP, \fBfalse\fP, and \fBtest\fP builtins |
6272 | do not accept options and do not treat \fB\-\-\fP specially. | |
6273 | The \fBexit\fP, \fBlogout\fP, \fBbreak\fP, \fBcontinue\fP, \fBlet\fP, | |
6274 | and \fBshift\fP builtins accept and process arguments beginning with | |
6275 | \fB\-\fP without requiring \fB\-\-\fP. | |
6276 | Other builtins that accept arguments but are not specified as accepting | |
6277 | options interpret arguments beginning with \fB\-\fP as invalid options and | |
6278 | require \fB\-\-\fP to prevent this interpretation. | |
ccc6cda3 | 6279 | .sp .5 |
726f6388 JA |
6280 | .PD 0 |
6281 | .TP | |
6282 | \fB:\fP [\fIarguments\fP] | |
6283 | .PD | |
6284 | No effect; the command does nothing beyond expanding | |
6285 | .I arguments | |
6286 | and performing any specified | |
6287 | redirections. A zero exit code is returned. | |
6288 | .TP | |
726f6388 | 6289 | \fB .\| \fP \fIfilename\fP [\fIarguments\fP] |
7117c2d2 | 6290 | .PD 0 |
726f6388 JA |
6291 | .TP |
6292 | \fBsource\fP \fIfilename\fP [\fIarguments\fP] | |
6293 | .PD | |
6294 | Read and execute commands from | |
6295 | .I filename | |
6296 | in the current | |
6297 | shell environment and return the exit status of the last command | |
6298 | executed from | |
6299 | .IR filename . | |
6300 | If | |
6301 | .I filename | |
ccc6cda3 | 6302 | does not contain a slash, file names in |
726f6388 JA |
6303 | .SM |
6304 | .B PATH | |
6305 | are used to find the directory containing | |
6306 | .IR filename . | |
6307 | The file searched for in | |
6308 | .SM | |
6309 | .B PATH | |
28ef6c31 JA |
6310 | need not be executable. |
6311 | When \fBbash\fP is not in \fIposix mode\fP, the current directory is | |
726f6388 JA |
6312 | searched if no file is found in |
6313 | .SM | |
6314 | .BR PATH . | |
ccc6cda3 JA |
6315 | If the |
6316 | .B sourcepath | |
6317 | option to the | |
6318 | .B shopt | |
6319 | builtin command is turned off, the | |
6320 | .SM | |
6321 | .B PATH | |
6322 | is not searched. | |
726f6388 | 6323 | If any \fIarguments\fP are supplied, they become the positional |
ccc6cda3 | 6324 | parameters when \fIfilename\fP is executed. Otherwise the positional |
726f6388 JA |
6325 | parameters are unchanged. |
6326 | The return status is the status of the last command exited within | |
6327 | the script (0 if no commands are executed), and false if | |
6328 | .I filename | |
cce855bc | 6329 | is not found or cannot be read. |
726f6388 | 6330 | .TP |
ccc6cda3 JA |
6331 | \fBalias\fP [\fB\-p\fP] [\fIname\fP[=\fIvalue\fP] ...] |
6332 | \fBAlias\fP with no arguments or with the | |
6333 | .B \-p | |
6334 | option prints the list of aliases in the form | |
6335 | \fBalias\fP \fIname\fP=\fIvalue\fP on standard output. | |
6336 | When arguments are supplied, an alias is defined for | |
6337 | each \fIname\fP whose \fIvalue\fP is given. | |
6338 | A trailing space in \fIvalue\fP causes the next word to be | |
6339 | checked for alias substitution when the alias is expanded. | |
6340 | For each \fIname\fP in the argument list for which no \fIvalue\fP | |
6341 | is supplied, the name and value of the alias is printed. | |
6342 | \fBAlias\fP returns true unless a \fIname\fP is given for which | |
6343 | no alias has been defined. | |
726f6388 | 6344 | .TP |
de3341d1 CR |
6345 | \fBbg\fP [\fIjobspec\fP ...] |
6346 | Resume each suspended job \fIjobspec\fP in the background, as if it | |
cce855bc | 6347 | had been started with |
726f6388 | 6348 | .BR & . |
d3ad40de CR |
6349 | If |
6350 | .I jobspec | |
6351 | is not present, the shell's notion of the \fIcurrent job\fP is used. | |
726f6388 JA |
6352 | .B bg |
6353 | .I jobspec | |
6354 | returns 0 unless run when job control is disabled or, when run with | |
ff247e74 CR |
6355 | job control enabled, any specified \fIjobspec\fP was not found |
6356 | or was started without job control. | |
726f6388 | 6357 | .TP |
cce855bc | 6358 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] [\fB\-lpsvPSV\fP] |
7117c2d2 | 6359 | .PD 0 |
cce855bc JA |
6360 | .TP |
6361 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] [\fB\-q\fP \fIfunction\fP] [\fB\-u\fP \fIfunction\fP] [\fB\-r\fP \fIkeyseq\fP] | |
726f6388 | 6362 | .TP |
ccc6cda3 | 6363 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fB\-f\fP \fIfilename\fP |
726f6388 | 6364 | .TP |
bb70624e JA |
6365 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fB\-x\fP \fIkeyseq\fP:\fIshell\-command\fP |
6366 | .TP | |
ccc6cda3 | 6367 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fIkeyseq\fP:\fIfunction\-name\fP |
7117c2d2 JA |
6368 | .TP |
6369 | \fBbind\fP \fIreadline\-command\fP | |
726f6388 JA |
6370 | .PD |
6371 | Display current | |
6372 | .B readline | |
7117c2d2 | 6373 | key and function bindings, bind a key sequence to a |
726f6388 | 6374 | .B readline |
7117c2d2 JA |
6375 | function or macro, or set a |
6376 | .B readline | |
6377 | variable. | |
6378 | Each non-option argument is a command as it would appear in | |
726f6388 | 6379 | .IR .inputrc , |
7117c2d2 JA |
6380 | but each binding or command must be passed as a separate argument; |
6381 | e.g., '"\eC\-x\eC\-r": re\-read\-init\-file'. | |
6382 | Options, if supplied, have the following meanings: | |
726f6388 JA |
6383 | .RS |
6384 | .PD 0 | |
6385 | .TP | |
6386 | .B \-m \fIkeymap\fP | |
6387 | Use | |
6388 | .I keymap | |
6389 | as the keymap to be affected by the subsequent bindings. | |
6390 | Acceptable | |
6391 | .I keymap | |
6392 | names are | |
ccc6cda3 | 6393 | \fIemacs, emacs\-standard, emacs\-meta, emacs\-ctlx, vi, |
28ef6c31 | 6394 | vi\-move, vi\-command\fP, and |
ccc6cda3 JA |
6395 | .IR vi\-insert . |
6396 | \fIvi\fP is equivalent to \fIvi\-command\fP; \fIemacs\fP is | |
6397 | equivalent to \fIemacs\-standard\fP. | |
726f6388 JA |
6398 | .TP |
6399 | .B \-l | |
ccc6cda3 JA |
6400 | List the names of all \fBreadline\fP functions. |
6401 | .TP | |
6402 | .B \-p | |
6403 | Display \fBreadline\fP function names and bindings in such a way | |
6404 | that they can be re-read. | |
6405 | .TP | |
6406 | .B \-P | |
6407 | List current \fBreadline\fP function names and bindings. | |
726f6388 | 6408 | .TP |
ccc6cda3 JA |
6409 | .B \-s |
6410 | Display \fBreadline\fP key sequences bound to macros and the strings | |
6411 | they output in such a way that they can be re-read. | |
6412 | .TP | |
6413 | .B \-S | |
6414 | Display \fBreadline\fP key sequences bound to macros and the strings | |
6415 | they output. | |
726f6388 | 6416 | .TP |
d3ad40de CR |
6417 | .B \-v |
6418 | Display \fBreadline\fP variable names and values in such a way that they | |
6419 | can be re-read. | |
6420 | .TP | |
6421 | .B \-V | |
6422 | List current \fBreadline\fP variable names and values. | |
6423 | .TP | |
726f6388 | 6424 | .B \-f \fIfilename\fP |
ccc6cda3 | 6425 | Read key bindings from \fIfilename\fP. |
726f6388 JA |
6426 | .TP |
6427 | .B \-q \fIfunction\fP | |
ccc6cda3 JA |
6428 | Query about which keys invoke the named \fIfunction\fP. |
6429 | .TP | |
cce855bc JA |
6430 | .B \-u \fIfunction\fP |
6431 | Unbind all keys bound to the named \fIfunction\fP. | |
6432 | .TP | |
ccc6cda3 JA |
6433 | .B \-r \fIkeyseq\fP |
6434 | Remove any current binding for \fIkeyseq\fP. | |
bb70624e JA |
6435 | .TP |
6436 | .B \-x \fIkeyseq\fP:\fIshell\-command\fP | |
6437 | Cause \fIshell\-command\fP to be executed whenever \fIkeyseq\fP is | |
6438 | entered. | |
8943768b CR |
6439 | When \fIshell\-command\fP is executed, the shell sets the |
6440 | .B READLINE_LINE | |
6441 | variable to the contents of the \fBreadline\fP line buffer and the | |
6442 | .B READLINE_POINT | |
6443 | variable to the current location of the insertion point. | |
6444 | If the executed command changes the value of | |
6445 | .B READLINE_LINE | |
6446 | or | |
6447 | .BR READLINE_POINT , | |
6448 | those new values will be reflected in the editing state. | |
726f6388 JA |
6449 | .PD |
6450 | .PP | |
6451 | The return value is 0 unless an unrecognized option is given or an | |
6452 | error occurred. | |
6453 | .RE | |
6454 | .TP | |
6455 | \fBbreak\fP [\fIn\fP] | |
6456 | Exit from within a | |
6457 | .BR for , | |
6458 | .BR while , | |
ccc6cda3 | 6459 | .BR until , |
726f6388 | 6460 | or |
ccc6cda3 | 6461 | .B select |
726f6388 JA |
6462 | loop. If \fIn\fP is specified, break \fIn\fP levels. |
6463 | .I n | |
6464 | must be \(>= 1. If | |
6465 | .I n | |
6466 | is greater than the number of enclosing loops, all enclosing loops | |
33fe8777 CR |
6467 | are exited. |
6468 | The return value is 0 unless \fIn\fP is not greater than or equal to 1. | |
726f6388 JA |
6469 | .TP |
6470 | \fBbuiltin\fP \fIshell\-builtin\fP [\fIarguments\fP] | |
6471 | Execute the specified shell builtin, passing it | |
6472 | .IR arguments , | |
6473 | and return its exit status. | |
cce855bc | 6474 | This is useful when defining a |
726f6388 | 6475 | function whose name is the same as a shell builtin, |
cce855bc JA |
6476 | retaining the functionality of the builtin within the function. |
6477 | The \fBcd\fP builtin is commonly redefined this way. | |
6478 | The return status is false if | |
726f6388 JA |
6479 | .I shell\-builtin |
6480 | is not a shell builtin command. | |
6481 | .TP | |
6a8fd0ed CR |
6482 | \fBcaller\fP [\fIexpr\fP] |
6483 | Returns the context of any active subroutine call (a shell function or | |
6484 | a script executed with the \fB.\fP or \fBsource\fP builtins. | |
6485 | Without \fIexpr\fP, \fBcaller\fP displays the line number and source | |
6486 | filename of the current subroutine call. | |
6487 | If a non-negative integer is supplied as \fIexpr\fP, \fBcaller\fP | |
6488 | displays the line number, subroutine name, and source file corresponding | |
6489 | to that position in the current execution call stack. This extra | |
6490 | information may be used, for example, to print a stack trace. The | |
6491 | current frame is frame 0. | |
6492 | The return value is 0 unless the shell is not executing a subroutine | |
6493 | call or \fIexpr\fP does not correspond to a valid position in the | |
6494 | call stack. | |
6495 | .TP | |
7117c2d2 | 6496 | \fBcd\fP [\fB\-L|-P\fP] [\fIdir\fP] |
726f6388 JA |
6497 | Change the current directory to \fIdir\fP. The variable |
6498 | .SM | |
6499 | .B HOME | |
6500 | is the | |
6501 | default | |
6502 | .IR dir . | |
6503 | The variable | |
6504 | .SM | |
6505 | .B CDPATH | |
ccc6cda3 | 6506 | defines the search path for the directory containing |
726f6388 | 6507 | .IR dir . |
ccc6cda3 JA |
6508 | Alternative directory names in |
6509 | .SM | |
6510 | .B CDPATH | |
6511 | are separated by a colon (:). A null directory name in | |
726f6388 JA |
6512 | .SM |
6513 | .B CDPATH | |
ccc6cda3 | 6514 | is the same as the current directory, i.e., ``\fB.\fP''. If |
726f6388 JA |
6515 | .I dir |
6516 | begins with a slash (/), | |
6517 | then | |
6518 | .SM | |
6519 | .B CDPATH | |
ccc6cda3 JA |
6520 | is not used. The |
6521 | .B \-P | |
6522 | option says to use the physical directory structure instead of | |
6523 | following symbolic links (see also the | |
6524 | .B \-P | |
6525 | option to the | |
6526 | .B set | |
6527 | builtin command); the | |
6528 | .B \-L | |
6529 | option forces symbolic links to be followed. An argument of | |
726f6388 JA |
6530 | .B \- |
6531 | is equivalent to | |
6532 | .SM | |
6533 | .BR $OLDPWD . | |
d3a24ed2 CR |
6534 | If a non-empty directory name from \fBCDPATH\fP is used, or if |
6535 | \fB\-\fP is the first argument, and the directory change is | |
6536 | successful, the absolute pathname of the new working directory is | |
6537 | written to the standard output. | |
726f6388 JA |
6538 | The return value is true if the directory was successfully changed; |
6539 | false otherwise. | |
6540 | .TP | |
ccc6cda3 | 6541 | \fBcommand\fP [\fB\-pVv\fP] \fIcommand\fP [\fIarg\fP ...] |
726f6388 JA |
6542 | Run |
6543 | .I command | |
6544 | with | |
6545 | .I args | |
6546 | suppressing the normal shell function lookup. Only builtin | |
6547 | commands or commands found in the | |
6548 | .SM | |
6549 | .B PATH | |
6550 | are executed. If the | |
6551 | .B \-p | |
6552 | option is given, the search for | |
6553 | .I command | |
6554 | is performed using a default value for | |
6555 | .B PATH | |
6556 | that is guaranteed to find all of the standard utilities. | |
6557 | If either the | |
6558 | .B \-V | |
6559 | or | |
6560 | .B \-v | |
6561 | option is supplied, a description of | |
6562 | .I command | |
6563 | is printed. The | |
6564 | .B \-v | |
ccc6cda3 | 6565 | option causes a single word indicating the command or file name |
726f6388 JA |
6566 | used to invoke |
6567 | .I command | |
cce855bc | 6568 | to be displayed; the |
726f6388 JA |
6569 | .B \-V |
6570 | option produces a more verbose description. | |
726f6388 JA |
6571 | If the |
6572 | .B \-V | |
6573 | or | |
6574 | .B \-v | |
6575 | option is supplied, the exit status is 0 if | |
6576 | .I command | |
6577 | was found, and 1 if not. If neither option is supplied and | |
6578 | an error occurred or | |
6579 | .I command | |
6580 | cannot be found, the exit status is 127. Otherwise, the exit status of the | |
6581 | .B command | |
6582 | builtin is the exit status of | |
6583 | .IR command . | |
6584 | .TP | |
bb70624e JA |
6585 | \fBcompgen\fP [\fIoption\fP] [\fIword\fP] |
6586 | Generate possible completion matches for \fIword\fP according to | |
6587 | the \fIoption\fPs, which may be any option accepted by the | |
6588 | .B complete | |
6589 | builtin with the exception of \fB\-p\fP and \fB\-r\fP, and write | |
6590 | the matches to the standard output. | |
6591 | When using the \fB\-F\fP or \fB\-C\fP options, the various shell variables | |
6592 | set by the programmable completion facilities, while available, will not | |
6593 | have useful values. | |
6594 | .sp 1 | |
6595 | The matches will be generated in the same way as if the programmable | |
6596 | completion code had generated them directly from a completion specification | |
6597 | with the same flags. | |
6598 | If \fIword\fP is specified, only those completions matching \fIword\fP | |
6599 | will be displayed. | |
6600 | .sp 1 | |
6601 | The return value is true unless an invalid option is supplied, or no | |
6602 | matches were generated. | |
6603 | .TP | |
3eb2d94a | 6604 | \fBcomplete\fP [\fB\-abcdefgjksuv\fP] [\fB\-o\fP \fIcomp-option\fP] [\fB\-DE\fP] [\fB\-A\fP \fIaction\fP] [\fB\-G\fP \fIglobpat\fP] [\fB\-W\fP \fIwordlist\fP] [\fB\-F\fP \fIfunction\fP] [\fB\-C\fP \fIcommand\fP] |
bb70624e | 6605 | .br |
d3ad40de | 6606 | [\fB\-X\fP \fIfilterpat\fP] [\fB\-P\fP \fIprefix\fP] [\fB\-S\fP \fIsuffix\fP] \fIname\fP [\fIname ...\fP] |
7117c2d2 | 6607 | .PD 0 |
bb70624e | 6608 | .TP |
3eb2d94a | 6609 | \fBcomplete\fP \fB\-pr\fP [\fB\-DE\fP] [\fIname\fP ...] |
bb70624e JA |
6610 | .PD |
6611 | Specify how arguments to each \fIname\fP should be completed. | |
6612 | If the \fB\-p\fP option is supplied, or if no options are supplied, | |
6613 | existing completion specifications are printed in a way that allows | |
6614 | them to be reused as input. | |
6615 | The \fB\-r\fP option removes a completion specification for | |
6616 | each \fIname\fP, or, if no \fIname\fPs are supplied, all | |
6617 | completion specifications. | |
3eb2d94a CR |
6618 | The \fB\-D\fP option indicates that the remaining options and actions should |
6619 | apply to the ``default'' command completion; that is, completion attempted | |
6620 | on a command for which no completion has previously been defined. | |
6a8fd0ed CR |
6621 | The \fB\-E\fP option indicates that the remaining options and actions should |
6622 | apply to ``empty'' command completion; that is, completion attempted on a | |
6623 | blank line. | |
bb70624e JA |
6624 | .sp 1 |
6625 | The process of applying these completion specifications when word completion | |
6626 | is attempted is described above under \fBProgrammable Completion\fP. | |
6627 | .sp 1 | |
6628 | Other options, if specified, have the following meanings. | |
6629 | The arguments to the \fB\-G\fP, \fB\-W\fP, and \fB\-X\fP options | |
6630 | (and, if necessary, the \fB\-P\fP and \fB\-S\fP options) | |
6631 | should be quoted to protect them from expansion before the | |
6632 | .B complete | |
6633 | builtin is invoked. | |
6634 | .RS | |
6635 | .PD 0 | |
6636 | .TP 8 | |
28ef6c31 JA |
6637 | \fB\-o\fP \fIcomp-option\fP |
6638 | The \fIcomp-option\fP controls several aspects of the compspec's behavior | |
6639 | beyond the simple generation of completions. | |
6640 | \fIcomp-option\fP may be one of: | |
6641 | .RS | |
6642 | .TP 8 | |
d3a24ed2 CR |
6643 | .B bashdefault |
6644 | Perform the rest of the default \fBbash\fP completions if the compspec | |
6645 | generates no matches. | |
6646 | .TP 8 | |
28ef6c31 | 6647 | .B default |
7117c2d2 JA |
6648 | Use readline's default filename completion if the compspec generates |
6649 | no matches. | |
28ef6c31 JA |
6650 | .TP 8 |
6651 | .B dirnames | |
6652 | Perform directory name completion if the compspec generates no matches. | |
6653 | .TP 8 | |
6654 | .B filenames | |
6655 | Tell readline that the compspec generates filenames, so it can perform any | |
e77a3058 CR |
6656 | filename\-specific processing (like adding a slash to directory names, |
6657 | quoting special characters, or suppressing trailing spaces). | |
6658 | Intended to be used with shell functions. | |
7117c2d2 JA |
6659 | .TP 8 |
6660 | .B nospace | |
6661 | Tell readline not to append a space (the default) to words completed at | |
6662 | the end of the line. | |
301e2142 CR |
6663 | .TP 8 |
6664 | .B plusdirs | |
6665 | After any matches defined by the compspec are generated, | |
6666 | directory name completion is attempted and any | |
6667 | matches are added to the results of the other actions. | |
28ef6c31 JA |
6668 | .RE |
6669 | .TP 8 | |
bb70624e JA |
6670 | \fB\-A\fP \fIaction\fP |
6671 | The \fIaction\fP may be one of the following to generate a list of possible | |
6672 | completions: | |
6673 | .RS | |
6674 | .TP 8 | |
6675 | .B alias | |
6676 | Alias names. May also be specified as \fB\-a\fP. | |
6677 | .TP 8 | |
6678 | .B arrayvar | |
6679 | Array variable names. | |
6680 | .TP 8 | |
6681 | .B binding | |
6682 | \fBReadline\fP key binding names. | |
6683 | .TP 8 | |
6684 | .B builtin | |
6685 | Names of shell builtin commands. May also be specified as \fB\-b\fP. | |
6686 | .TP 8 | |
6687 | .B command | |
6688 | Command names. May also be specified as \fB\-c\fP. | |
6689 | .TP 8 | |
6690 | .B directory | |
6691 | Directory names. May also be specified as \fB\-d\fP. | |
6692 | .TP 8 | |
6693 | .B disabled | |
6694 | Names of disabled shell builtins. | |
6695 | .TP 8 | |
6696 | .B enabled | |
6697 | Names of enabled shell builtins. | |
6698 | .TP 8 | |
6699 | .B export | |
6700 | Names of exported shell variables. May also be specified as \fB\-e\fP. | |
6701 | .TP 8 | |
6702 | .B file | |
6703 | File names. May also be specified as \fB\-f\fP. | |
6704 | .TP 8 | |
6705 | .B function | |
6706 | Names of shell functions. | |
6707 | .TP 8 | |
f73dda09 JA |
6708 | .B group |
6709 | Group names. May also be specified as \fB\-g\fP. | |
6710 | .TP 8 | |
bb70624e JA |
6711 | .B helptopic |
6712 | Help topics as accepted by the \fBhelp\fP builtin. | |
6713 | .TP 8 | |
6714 | .B hostname | |
6715 | Hostnames, as taken from the file specified by the | |
6716 | .SM | |
6717 | .B HOSTFILE | |
6718 | shell variable. | |
6719 | .TP 8 | |
6720 | .B job | |
6721 | Job names, if job control is active. May also be specified as \fB\-j\fP. | |
6722 | .TP 8 | |
6723 | .B keyword | |
6724 | Shell reserved words. May also be specified as \fB\-k\fP. | |
6725 | .TP 8 | |
6726 | .B running | |
6727 | Names of running jobs, if job control is active. | |
6728 | .TP 8 | |
7117c2d2 JA |
6729 | .B service |
6730 | Service names. May also be specified as \fB\-s\fP. | |
6731 | .TP 8 | |
bb70624e JA |
6732 | .B setopt |
6733 | Valid arguments for the \fB\-o\fP option to the \fBset\fP builtin. | |
6734 | .TP 8 | |
6735 | .B shopt | |
6736 | Shell option names as accepted by the \fBshopt\fP builtin. | |
6737 | .TP 8 | |
6738 | .B signal | |
6739 | Signal names. | |
6740 | .TP 8 | |
6741 | .B stopped | |
6742 | Names of stopped jobs, if job control is active. | |
6743 | .TP 8 | |
6744 | .B user | |
6745 | User names. May also be specified as \fB\-u\fP. | |
6746 | .TP 8 | |
6747 | .B variable | |
6748 | Names of all shell variables. May also be specified as \fB\-v\fP. | |
6749 | .RE | |
6750 | .TP 8 | |
6751 | \fB\-G\fP \fIglobpat\fP | |
d0ca3503 | 6752 | The pathname expansion pattern \fIglobpat\fP is expanded to generate |
bb70624e JA |
6753 | the possible completions. |
6754 | .TP 8 | |
6755 | \fB\-W\fP \fIwordlist\fP | |
6756 | The \fIwordlist\fP is split using the characters in the | |
6757 | .SM | |
6758 | .B IFS | |
6759 | special variable as delimiters, and each resultant word is expanded. | |
6760 | The possible completions are the members of the resultant list which | |
6761 | match the word being completed. | |
6762 | .TP 8 | |
6763 | \fB\-C\fP \fIcommand\fP | |
6764 | \fIcommand\fP is executed in a subshell environment, and its output is | |
6765 | used as the possible completions. | |
6766 | .TP 8 | |
6767 | \fB\-F\fP \fIfunction\fP | |
6768 | The shell function \fIfunction\fP is executed in the current shell | |
6769 | environment. | |
6770 | When it finishes, the possible completions are retrieved from the value | |
6771 | of the | |
6772 | .SM | |
6773 | .B COMPREPLY | |
6774 | array variable. | |
6775 | .TP 8 | |
6776 | \fB\-X\fP \fIfilterpat\fP | |
d0ca3503 | 6777 | \fIfilterpat\fP is a pattern as used for pathname expansion. |
bb70624e JA |
6778 | It is applied to the list of possible completions generated by the |
6779 | preceding options and arguments, and each completion matching | |
6780 | \fIfilterpat\fP is removed from the list. | |
6781 | A leading \fB!\fP in \fIfilterpat\fP negates the pattern; in this | |
6782 | case, any completion not matching \fIfilterpat\fP is removed. | |
6783 | .TP 8 | |
6784 | \fB\-P\fP \fIprefix\fP | |
6785 | \fIprefix\fP is added at the beginning of each possible completion | |
6786 | after all other options have been applied. | |
6787 | .TP 8 | |
6788 | \fB\-S\fP \fIsuffix\fP | |
6789 | \fIsuffix\fP is appended to each possible completion | |
6790 | after all other options have been applied. | |
6791 | .PD | |
6792 | .PP | |
6793 | The return value is true unless an invalid option is supplied, an option | |
6794 | other than \fB\-p\fP or \fB\-r\fP is supplied without a \fIname\fP | |
6795 | argument, an attempt is made to remove a completion specification for | |
6796 | a \fIname\fP for which no specification exists, or | |
6797 | an error occurs adding a completion specification. | |
6798 | .RE | |
6799 | .TP | |
3eb2d94a | 6800 | \fBcompopt\fP [\fB\-o\fP \fIoption\fP] [\fB\-DE\fP] [\fB+o\fP \fIoption\fP] [\fIname\fP] |
6fbe7620 CR |
6801 | Modify completion options for each \fIname\fP according to the |
6802 | \fIoption\fPs, or for the | |
6803 | currently-execution completion if no \fIname\fPs are supplied. | |
6804 | If no \fIoption\fPs are given, display the completion options for each | |
6805 | \fIname\fP or the current completion. | |
6806 | The possible values of \fIoption\fP are those valid for the \fBcomplete\fP | |
6807 | builtin described above. | |
3eb2d94a CR |
6808 | The \fB\-D\fP option indicates that the remaining options should |
6809 | apply to the ``default'' command completion; that is, completion attempted | |
6810 | on a command for which no completion has previously been defined. | |
6811 | The \fB\-E\fP option indicates that the remaining options should | |
6812 | apply to ``empty'' command completion; that is, completion attempted on a | |
6813 | blank line. | |
6fbe7620 CR |
6814 | .PP |
6815 | The return value is true unless an invalid option is supplied, an attempt | |
6816 | is made to modify the options for a \fIname\fP for which no completion | |
6817 | specification exists, or an output error occurs. | |
6818 | .TP | |
726f6388 JA |
6819 | \fBcontinue\fP [\fIn\fP] |
6820 | Resume the next iteration of the enclosing | |
6821 | .BR for , | |
6822 | .BR while , | |
ccc6cda3 | 6823 | .BR until , |
726f6388 | 6824 | or |
ccc6cda3 | 6825 | .B select |
726f6388 JA |
6826 | loop. |
6827 | If | |
6828 | .I n | |
6829 | is specified, resume at the \fIn\fPth enclosing loop. | |
6830 | .I n | |
6831 | must be \(>= 1. If | |
6832 | .I n | |
6833 | is greater than the number of enclosing loops, the last enclosing loop | |
33fe8777 CR |
6834 | (the ``top-level'' loop) is resumed. |
6835 | The return value is 0 unless \fIn\fP is not greater than or equal to 1. | |
726f6388 | 6836 | .TP |
09767ff0 | 6837 | \fBdeclare\fP [\fB\-aAfFilrtux\fP] [\fB\-p\fP] [\fIname\fP[=\fIvalue\fP] ...] |
726f6388 | 6838 | .PD 0 |
726f6388 | 6839 | .TP |
09767ff0 | 6840 | \fBtypeset\fP [\fB\-aAfFilrtux\fP] [\fB\-p\fP] [\fIname\fP[=\fIvalue\fP] ...] |
726f6388 | 6841 | .PD |
ccc6cda3 JA |
6842 | Declare variables and/or give them attributes. |
6843 | If no \fIname\fPs are given then display the values of variables. | |
6844 | The | |
6845 | .B \-p | |
6846 | option will display the attributes and values of each | |
6847 | .IR name . | |
6848 | When | |
6849 | .B \-p | |
6fbe7620 CR |
6850 | is used with \fIname\fP arguments, additional options are ignored. |
6851 | When | |
6852 | .B \-p | |
6853 | is supplied without \fIname\fP arguments, it will display the attributes | |
6854 | and values of all variables having the attributes specified by the | |
6855 | additional options. | |
6856 | If no other options are supplied with \fB\-p\fP, \fBdeclare\fP will display | |
6857 | the attributes and values of all shell variables. The \fB\-f\fP option | |
6858 | will restrict the display to shell functions. | |
ccc6cda3 JA |
6859 | The |
6860 | .B \-F | |
6861 | option inhibits the display of function definitions; only the | |
6862 | function name and attributes are printed. | |
d3a24ed2 CR |
6863 | If the \fBextdebug\fP shell option is enabled using \fBshopt\fP, |
6864 | the source file name and line number where the function is defined | |
6865 | are displayed as well. The | |
ccc6cda3 JA |
6866 | .B \-F |
6867 | option implies | |
6868 | .BR \-f . | |
6869 | The following options can | |
6870 | be used to restrict output to variables with the specified attribute or | |
6871 | to give variables attributes: | |
726f6388 JA |
6872 | .RS |
6873 | .PD 0 | |
6874 | .TP | |
ccc6cda3 | 6875 | .B \-a |
fdf670ea CR |
6876 | Each \fIname\fP is an indexed array variable (see |
6877 | .B Arrays | |
6878 | above). | |
6879 | .TP | |
6880 | .B \-A | |
6881 | Each \fIname\fP is an associative array variable (see | |
ccc6cda3 JA |
6882 | .B Arrays |
6883 | above). | |
6884 | .TP | |
726f6388 | 6885 | .B \-f |
ccc6cda3 JA |
6886 | Use function names only. |
6887 | .TP | |
6888 | .B \-i | |
6889 | The variable is treated as an integer; arithmetic evaluation (see | |
6890 | .SM | |
6891 | .B "ARITHMETIC EVALUATION" ") " | |
6892 | is performed when the variable is assigned a value. | |
726f6388 | 6893 | .TP |
09767ff0 CR |
6894 | .B \-l |
6895 | When the variable is assigned a value, all upper-case characters are | |
6896 | converted to lower-case. | |
6897 | The upper-case attribute is disabled. | |
6898 | .TP | |
726f6388 JA |
6899 | .B \-r |
6900 | Make \fIname\fPs readonly. These names cannot then be assigned values | |
cce855bc | 6901 | by subsequent assignment statements or unset. |
726f6388 | 6902 | .TP |
7117c2d2 JA |
6903 | .B \-t |
6904 | Give each \fIname\fP the \fItrace\fP attribute. | |
76a8d78d CR |
6905 | Traced functions inherit the \fBDEBUG\fP and \fBRETURN\fP traps from |
6906 | the calling shell. | |
7117c2d2 JA |
6907 | The trace attribute has no special meaning for variables. |
6908 | .TP | |
09767ff0 CR |
6909 | .B \-u |
6910 | When the variable is assigned a value, all lower-case characters are | |
6911 | converted to upper-case. | |
6912 | The lower-case attribute is disabled. | |
6913 | .TP | |
726f6388 JA |
6914 | .B \-x |
6915 | Mark \fIname\fPs for export to subsequent commands via the environment. | |
726f6388 JA |
6916 | .PD |
6917 | .PP | |
6918 | Using `+' instead of `\-' | |
d3ad40de CR |
6919 | turns off the attribute instead, |
6920 | with the exceptions that \fB+a\fP | |
6921 | may not be used to destroy an array variable and \fB+r\fB will not | |
6922 | remove the readonly attribute. | |
6923 | When used in a function, | |
ccc6cda3 JA |
6924 | makes each |
6925 | \fIname\fP local, as with the | |
726f6388 | 6926 | .B local |
d3a24ed2 CR |
6927 | command. |
6928 | If a variable name is followed by =\fIvalue\fP, the value of | |
6929 | the variable is set to \fIvalue\fP. | |
6930 | The return value is 0 unless an invalid option is encountered, | |
bb70624e JA |
6931 | an attempt is made to define a function using |
6932 | .if n ``\-f foo=bar'', | |
6933 | .if t \f(CW\-f foo=bar\fP, | |
ccc6cda3 JA |
6934 | an attempt is made to assign a value to a readonly variable, |
6935 | an attempt is made to assign a value to an array variable without | |
6936 | using the compound assignment syntax (see | |
6937 | .B Arrays | |
cce855bc | 6938 | above), one of the \fInames\fP is not a valid shell variable name, |
726f6388 | 6939 | an attempt is made to turn off readonly status for a readonly variable, |
ccc6cda3 | 6940 | an attempt is made to turn off array status for an array variable, |
bb70624e | 6941 | or an attempt is made to display a non-existent function with \fB\-f\fP. |
726f6388 JA |
6942 | .RE |
6943 | .TP | |
d3ad40de | 6944 | .B dirs [+\fIn\fP] [\-\fIn\fP] [\fB\-cplv\fP] |
ccc6cda3 JA |
6945 | Without options, displays the list of currently remembered directories. |
6946 | The default display is on a single line with directory names separated | |
6947 | by spaces. | |
6948 | Directories are added to the list with the | |
726f6388 JA |
6949 | .B pushd |
6950 | command; the | |
6951 | .B popd | |
ccc6cda3 | 6952 | command removes entries from the list. |
726f6388 JA |
6953 | .RS |
6954 | .PD 0 | |
6955 | .TP | |
ccc6cda3 JA |
6956 | \fB+\fP\fIn\fP |
6957 | Displays the \fIn\fPth entry counting from the left of the list | |
726f6388 JA |
6958 | shown by |
6959 | .B dirs | |
6960 | when invoked without options, starting with zero. | |
6961 | .TP | |
ccc6cda3 JA |
6962 | \fB\-\fP\fIn\fP |
6963 | Displays the \fIn\fPth entry counting from the right of the list | |
726f6388 JA |
6964 | shown by |
6965 | .B dirs | |
6966 | when invoked without options, starting with zero. | |
6967 | .TP | |
ccc6cda3 JA |
6968 | .B \-c |
6969 | Clears the directory stack by deleting all of the entries. | |
6970 | .TP | |
726f6388 | 6971 | .B \-l |
ccc6cda3 | 6972 | Produces a longer listing; the default listing format uses a |
726f6388 | 6973 | tilde to denote the home directory. |
ccc6cda3 JA |
6974 | .TP |
6975 | .B \-p | |
6976 | Print the directory stack with one entry per line. | |
6977 | .TP | |
6978 | .B \-v | |
6979 | Print the directory stack with one entry per line, | |
6980 | prefixing each entry with its index in the stack. | |
726f6388 JA |
6981 | .PD |
6982 | .PP | |
6983 | The return value is 0 unless an | |
cce855bc | 6984 | invalid option is supplied or \fIn\fP indexes beyond the end |
726f6388 JA |
6985 | of the directory stack. |
6986 | .RE | |
6987 | .TP | |
cce855bc | 6988 | \fBdisown\fP [\fB\-ar\fP] [\fB\-h\fP] [\fIjobspec\fP ...] |
ccc6cda3 JA |
6989 | Without options, each |
6990 | .I jobspec | |
6991 | is removed from the table of active jobs. | |
d3ad40de CR |
6992 | If |
6993 | .I jobspec | |
6994 | is not present, and neither \fB\-a\fB nor \fB\-r\fP is supplied, | |
6995 | the shell's notion of the \fIcurrent job\fP is used. | |
cce855bc JA |
6996 | If the \fB\-h\fP option is given, each |
6997 | .I jobspec | |
6998 | is not removed from the table, but is marked so that | |
ccc6cda3 JA |
6999 | .SM |
7000 | .B SIGHUP | |
7001 | is not sent to the job if the shell receives a | |
7002 | .SM | |
7003 | .BR SIGHUP . | |
7004 | If no | |
7005 | .I jobspec | |
cce855bc JA |
7006 | is present, and neither the |
7007 | .B \-a | |
7008 | nor the | |
7009 | .B \-r | |
7010 | option is supplied, the \fIcurrent job\fP is used. | |
7011 | If no | |
7012 | .I jobspec | |
7013 | is supplied, the | |
7014 | .B \-a | |
7015 | option means to remove or mark all jobs; the | |
7016 | .B \-r | |
7017 | option without a | |
7018 | .I jobspec | |
7019 | argument restricts operation to running jobs. | |
7020 | The return value is 0 unless a | |
ccc6cda3 JA |
7021 | .I jobspec |
7022 | does not specify a valid job. | |
7023 | .TP | |
726f6388 | 7024 | \fBecho\fP [\fB\-neE\fP] [\fIarg\fP ...] |
ccc6cda3 JA |
7025 | Output the \fIarg\fPs, separated by spaces, followed by a newline. |
7026 | The return status is always 0. | |
7027 | If \fB\-n\fP is specified, the trailing newline is | |
726f6388 JA |
7028 | suppressed. If the \fB\-e\fP option is given, interpretation of |
7029 | the following backslash-escaped characters is enabled. The | |
7030 | .B \-E | |
7031 | option disables the interpretation of these escape characters, | |
7032 | even on systems where they are interpreted by default. | |
28ef6c31 | 7033 | The \fBxpg_echo\fP shell option may be used to |
bb70624e JA |
7034 | dynamically determine whether or not \fBecho\fP expands these |
7035 | escape characters by default. | |
ccc6cda3 | 7036 | .B echo |
3ffb039a | 7037 | does not interpret \fB\-\-\fP to mean the end of options. |
ccc6cda3 JA |
7038 | .B echo |
7039 | interprets the following escape sequences: | |
726f6388 JA |
7040 | .RS |
7041 | .PD 0 | |
7042 | .TP | |
7043 | .B \ea | |
7044 | alert (bell) | |
7045 | .TP | |
7046 | .B \eb | |
7047 | backspace | |
7048 | .TP | |
7049 | .B \ec | |
2e4498b3 | 7050 | suppress further output |
726f6388 | 7051 | .TP |
ccc6cda3 JA |
7052 | .B \ee |
7053 | an escape character | |
7054 | .TP | |
726f6388 JA |
7055 | .B \ef |
7056 | form feed | |
7057 | .TP | |
7058 | .B \en | |
7059 | new line | |
7060 | .TP | |
7061 | .B \er | |
7062 | carriage return | |
7063 | .TP | |
7064 | .B \et | |
7065 | horizontal tab | |
7066 | .TP | |
7067 | .B \ev | |
7068 | vertical tab | |
7069 | .TP | |
7070 | .B \e\e | |
7071 | backslash | |
7072 | .TP | |
7117c2d2 JA |
7073 | .B \e0\fInnn\fP |
7074 | the eight-bit character whose value is the octal value \fInnn\fP | |
7075 | (zero to three octal digits) | |
7076 | .TP | |
f73dda09 JA |
7077 | .B \ex\fIHH\fP |
7078 | the eight-bit character whose value is the hexadecimal value \fIHH\fP | |
7079 | (one or two hex digits) | |
726f6388 JA |
7080 | .PD |
7081 | .RE | |
7082 | .TP | |
d3ad40de | 7083 | \fBenable\fP [\fB\-a\fP] [\fB\-dnps\fP] [\fB\-f\fP \fIfilename\fP] [\fIname\fP ...] |
cce855bc JA |
7084 | Enable and disable builtin shell commands. |
7085 | Disabling a builtin allows a disk command which has the same name | |
bb70624e | 7086 | as a shell builtin to be executed without specifying a full pathname, |
cce855bc | 7087 | even though the shell normally searches for builtins before disk commands. |
726f6388 JA |
7088 | If \fB\-n\fP is used, each \fIname\fP |
7089 | is disabled; otherwise, | |
7090 | \fInames\fP are enabled. For example, to use the | |
7091 | .B test | |
7092 | binary found via the | |
7093 | .SM | |
7094 | .B PATH | |
ccc6cda3 | 7095 | instead of the shell builtin version, run |
28ef6c31 JA |
7096 | .if t \f(CWenable -n test\fP. |
7097 | .if n ``enable -n test''. | |
ccc6cda3 JA |
7098 | The |
7099 | .B \-f | |
7100 | option means to load the new builtin command | |
7101 | .I name | |
7102 | from shared object | |
7103 | .IR filename , | |
7104 | on systems that support dynamic loading. The | |
7105 | .B \-d | |
7106 | option will delete a builtin previously loaded with | |
7107 | .BR \-f . | |
7108 | If no \fIname\fP arguments are given, or if the | |
7109 | .B \-p | |
7110 | option is supplied, a list of shell builtins is printed. | |
7111 | With no other option arguments, the list consists of all enabled | |
7112 | shell builtins. | |
7113 | If \fB\-n\fP is supplied, only disabled builtins are printed. | |
7114 | If \fB\-a\fP is supplied, the list printed includes all builtins, with an | |
726f6388 | 7115 | indication of whether or not each is enabled. |
ccc6cda3 JA |
7116 | If \fB\-s\fP is supplied, the output is restricted to the POSIX |
7117 | \fIspecial\fP builtins. | |
726f6388 JA |
7118 | The return value is 0 unless a |
7119 | .I name | |
bb70624e | 7120 | is not a shell builtin or there is an error loading a new builtin |
ccc6cda3 | 7121 | from a shared object. |
726f6388 JA |
7122 | .TP |
7123 | \fBeval\fP [\fIarg\fP ...] | |
7124 | The \fIarg\fPs are read and concatenated together into a single | |
7125 | command. This command is then read and executed by the shell, and | |
ccc6cda3 JA |
7126 | its exit status is returned as the value of |
7127 | .BR eval . | |
7128 | If there are no | |
726f6388 JA |
7129 | .IR args , |
7130 | or only null arguments, | |
7131 | .B eval | |
ccc6cda3 | 7132 | returns 0. |
726f6388 | 7133 | .TP |
cce855bc | 7134 | \fBexec\fP [\fB\-cl\fP] [\fB\-a\fP \fIname\fP] [\fIcommand\fP [\fIarguments\fP]] |
726f6388 JA |
7135 | If |
7136 | .I command | |
7137 | is specified, it replaces the shell. | |
7138 | No new process is created. The | |
7139 | .I arguments | |
7140 | become the arguments to \fIcommand\fP. | |
ccc6cda3 JA |
7141 | If the |
7142 | .B \-l | |
7143 | option is supplied, | |
d3ad40de | 7144 | the shell places a dash at the beginning of the zeroth argument passed to |
726f6388 | 7145 | .IR command . |
ccc6cda3 JA |
7146 | This is what |
7147 | .IR login (1) | |
7148 | does. The | |
7149 | .B \-c | |
7150 | option causes | |
7151 | .I command | |
7152 | to be executed with an empty environment. If | |
7153 | .B \-a | |
7154 | is supplied, the shell passes | |
7155 | .I name | |
7156 | as the zeroth argument to the executed command. If | |
7157 | .I command | |
726f6388 | 7158 | cannot be executed for some reason, a non-interactive shell exits, |
ccc6cda3 JA |
7159 | unless the shell option |
7160 | .B execfail | |
7161 | is enabled, in which case it returns failure. | |
7162 | An interactive shell returns failure if the file cannot be executed. | |
726f6388 JA |
7163 | If |
7164 | .I command | |
7165 | is not specified, any redirections take effect in the current shell, | |
cce855bc JA |
7166 | and the return status is 0. If there is a redirection error, the |
7167 | return status is 1. | |
726f6388 JA |
7168 | .TP |
7169 | \fBexit\fP [\fIn\fP] | |
7170 | Cause the shell to exit | |
7171 | with a status of \fIn\fP. If | |
7172 | .I n | |
7173 | is omitted, the exit status | |
7174 | is that of the last command executed. | |
7175 | A trap on | |
7176 | .SM | |
7177 | .B EXIT | |
7178 | is executed before the shell terminates. | |
7179 | .TP | |
ccc6cda3 | 7180 | \fBexport\fP [\fB\-fn\fP\^] [\fIname\fP[=\fIword\fP]] ... |
7117c2d2 | 7181 | .PD 0 |
726f6388 JA |
7182 | .TP |
7183 | .B export \-p | |
7184 | .PD | |
7185 | The supplied | |
7186 | .I names | |
7187 | are marked for automatic export to the environment of | |
7188 | subsequently executed commands. If the | |
7189 | .B \-f | |
7190 | option is given, | |
7191 | the | |
7192 | .I names | |
7193 | refer to functions. | |
7194 | If no | |
7195 | .I names | |
7196 | are given, or if the | |
7197 | .B \-p | |
7198 | option is supplied, a list | |
7199 | of all names that are exported in this shell is printed. | |
7200 | The | |
7201 | .B \-n | |
5e13499c CR |
7202 | option causes the export property to be removed from each |
7203 | \fIname\fP. | |
d3a24ed2 CR |
7204 | If a variable name is followed by =\fIword\fP, the value of |
7205 | the variable is set to \fIword\fP. | |
726f6388 | 7206 | .B export |
cce855bc | 7207 | returns an exit status of 0 unless an invalid option is |
726f6388 | 7208 | encountered, |
cce855bc | 7209 | one of the \fInames\fP is not a valid shell variable name, or |
726f6388 JA |
7210 | .B \-f |
7211 | is supplied with a | |
7212 | .I name | |
7213 | that is not a function. | |
7214 | .TP | |
d3ad40de | 7215 | \fBfc\fP [\fB\-e\fP \fIename\fP] [\fB\-lnr\fP] [\fIfirst\fP] [\fIlast\fP] |
7117c2d2 | 7216 | .PD 0 |
726f6388 JA |
7217 | .TP |
7218 | \fBfc\fP \fB\-s\fP [\fIpat\fP=\fIrep\fP] [\fIcmd\fP] | |
7219 | .PD | |
7220 | Fix Command. In the first form, a range of commands from | |
7221 | .I first | |
7222 | to | |
7223 | .I last | |
7224 | is selected from the history list. | |
7225 | .I First | |
7226 | and | |
7227 | .I last | |
7228 | may be specified as a string (to locate the last command beginning | |
7229 | with that string) or as a number (an index into the history list, | |
7230 | where a negative number is used as an offset from the current | |
7231 | command number). If | |
7232 | .I last | |
7233 | is not specified it is set to | |
7234 | the current command for listing (so that | |
bb70624e JA |
7235 | .if n ``fc \-l \-10'' |
7236 | .if t \f(CWfc \-l \-10\fP | |
726f6388 JA |
7237 | prints the last 10 commands) and to |
7238 | .I first | |
7239 | otherwise. | |
7240 | If | |
7241 | .I first | |
7242 | is not specified it is set to the previous | |
7243 | command for editing and \-16 for listing. | |
7244 | .sp 1 | |
7245 | The | |
7246 | .B \-n | |
cce855bc | 7247 | option suppresses |
726f6388 JA |
7248 | the command numbers when listing. The |
7249 | .B \-r | |
cce855bc | 7250 | option reverses the order of |
726f6388 JA |
7251 | the commands. If the |
7252 | .B \-l | |
cce855bc | 7253 | option is given, |
726f6388 JA |
7254 | the commands are listed on |
7255 | standard output. Otherwise, the editor given by | |
7256 | .I ename | |
7257 | is invoked | |
7258 | on a file containing those commands. If | |
7259 | .I ename | |
7260 | is not given, the | |
7261 | value of the | |
7262 | .SM | |
7263 | .B FCEDIT | |
7264 | variable is used, and | |
7265 | the value of | |
7266 | .SM | |
7267 | .B EDITOR | |
7268 | if | |
7269 | .SM | |
7270 | .B FCEDIT | |
7271 | is not set. If neither variable is set, | |
7272 | .FN vi | |
7273 | is used. When editing is complete, the edited commands are | |
7274 | echoed and executed. | |
7275 | .sp 1 | |
7276 | In the second form, \fIcommand\fP is re-executed after each instance | |
7277 | of \fIpat\fP is replaced by \fIrep\fP. | |
ccc6cda3 | 7278 | A useful alias to use with this is |
d3a24ed2 | 7279 | .if n ``r="fc -s"'', |
ccc6cda3 JA |
7280 | .if t \f(CWr='fc \-s'\fP, |
7281 | so that typing | |
7282 | .if n ``r cc'' | |
7283 | .if t \f(CWr cc\fP | |
7284 | runs the last command beginning with | |
7285 | .if n ``cc'' | |
7286 | .if t \f(CWcc\fP | |
7287 | and typing | |
7288 | .if n ``r'' | |
7289 | .if t \f(CWr\fP | |
726f6388 JA |
7290 | re-executes the last command. |
7291 | .sp 1 | |
cce855bc | 7292 | If the first form is used, the return value is 0 unless an invalid |
726f6388 JA |
7293 | option is encountered or |
7294 | .I first | |
7295 | or | |
7296 | .I last | |
7297 | specify history lines out of range. | |
7298 | If the | |
7299 | .B \-e | |
7300 | option is supplied, the return value is the value of the last | |
7301 | command executed or failure if an error occurs with the temporary | |
7302 | file of commands. If the second form is used, the return status | |
7303 | is that of the command re-executed, unless | |
7304 | .I cmd | |
7305 | does not specify a valid history line, in which case | |
7306 | .B fc | |
7307 | returns failure. | |
7308 | .TP | |
7309 | \fBfg\fP [\fIjobspec\fP] | |
cce855bc | 7310 | Resume |
726f6388 | 7311 | .I jobspec |
cce855bc JA |
7312 | in the foreground, and make it the current job. |
7313 | If | |
726f6388 JA |
7314 | .I jobspec |
7315 | is not present, the shell's notion of the \fIcurrent job\fP is used. | |
7316 | The return value is that of the command placed into the foreground, | |
7317 | or failure if run when job control is disabled or, when run with | |
7318 | job control enabled, if | |
7319 | .I jobspec | |
7320 | does not specify a valid job or | |
7321 | .I jobspec | |
7322 | specifies a job that was started without job control. | |
7323 | .TP | |
7324 | \fBgetopts\fP \fIoptstring\fP \fIname\fP [\fIargs\fP] | |
7325 | .B getopts | |
7326 | is used by shell procedures to parse positional parameters. | |
7327 | .I optstring | |
bb70624e | 7328 | contains the option characters to be recognized; if a character |
726f6388 JA |
7329 | is followed by a colon, the option is expected to have an |
7330 | argument, which should be separated from it by white space. | |
bb70624e JA |
7331 | The colon and question mark characters may not be used as |
7332 | option characters. | |
726f6388 JA |
7333 | Each time it is invoked, |
7334 | .B getopts | |
7335 | places the next option in the shell variable | |
7336 | .IR name , | |
7337 | initializing | |
7338 | .I name | |
7339 | if it does not exist, | |
7340 | and the index of the next argument to be processed into the | |
7341 | variable | |
7342 | .SM | |
7343 | .BR OPTIND . | |
7344 | .SM | |
7345 | .B OPTIND | |
7346 | is initialized to 1 each time the shell or a shell script | |
7347 | is invoked. When an option requires an argument, | |
7348 | .B getopts | |
7349 | places that argument into the variable | |
7350 | .SM | |
7351 | .BR OPTARG . | |
7352 | The shell does not reset | |
7353 | .SM | |
7354 | .B OPTIND | |
7355 | automatically; it must be manually reset between multiple | |
7356 | calls to | |
7357 | .B getopts | |
7358 | within the same shell invocation if a new set of parameters | |
7359 | is to be used. | |
7360 | .sp 1 | |
cce855bc JA |
7361 | When the end of options is encountered, \fBgetopts\fP exits with a |
7362 | return value greater than zero. | |
7363 | \fBOPTIND\fP is set to the index of the first non-option argument, | |
7364 | and \fBname\fP is set to ?. | |
7365 | .sp 1 | |
7366 | .B getopts | |
7367 | normally parses the positional parameters, but if more arguments are | |
7368 | given in | |
7369 | .IR args , | |
7370 | .B getopts | |
7371 | parses those instead. | |
7372 | .sp 1 | |
726f6388 JA |
7373 | .B getopts |
7374 | can report errors in two ways. If the first character of | |
7375 | .I optstring | |
7376 | is a colon, | |
7377 | .I silent | |
7378 | error reporting is used. In normal operation diagnostic messages | |
cce855bc | 7379 | are printed when invalid options or missing option arguments are |
726f6388 JA |
7380 | encountered. |
7381 | If the variable | |
7382 | .SM | |
7383 | .B OPTERR | |
cce855bc | 7384 | is set to 0, no error messages will be displayed, even if the first |
726f6388 JA |
7385 | character of |
7386 | .I optstring | |
7387 | is not a colon. | |
7388 | .sp 1 | |
cce855bc | 7389 | If an invalid option is seen, |
726f6388 JA |
7390 | .B getopts |
7391 | places ? into | |
7392 | .I name | |
7393 | and, if not silent, | |
7394 | prints an error message and unsets | |
7395 | .SM | |
7396 | .BR OPTARG . | |
7397 | If | |
7398 | .B getopts | |
7399 | is silent, | |
7400 | the option character found is placed in | |
7401 | .SM | |
7402 | .B OPTARG | |
7403 | and no diagnostic message is printed. | |
7404 | .sp 1 | |
7405 | If a required argument is not found, and | |
7406 | .B getopts | |
7407 | is not silent, | |
7408 | a question mark (\^\fB?\fP\^) is placed in | |
7409 | .IR name , | |
f73dda09 | 7410 | .SM |
726f6388 JA |
7411 | .B OPTARG |
7412 | is unset, and a diagnostic message is printed. | |
7413 | If | |
7414 | .B getopts | |
7415 | is silent, then a colon (\^\fB:\fP\^) is placed in | |
7416 | .I name | |
7417 | and | |
7418 | .SM | |
7419 | .B OPTARG | |
7420 | is set to the option character found. | |
7421 | .sp 1 | |
7422 | .B getopts | |
726f6388 JA |
7423 | returns true if an option, specified or unspecified, is found. |
7424 | It returns false if the end of options is encountered or an | |
7425 | error occurs. | |
7426 | .TP | |
7117c2d2 | 7427 | \fBhash\fP [\fB\-lr\fP] [\fB\-p\fP \fIfilename\fP] [\fB\-dt\fP] [\fIname\fP] |
726f6388 JA |
7428 | For each |
7429 | .IR name , | |
ccc6cda3 JA |
7430 | the full file name of the command is determined by searching |
7431 | the directories in | |
7432 | .B $PATH | |
7433 | and remembered. | |
7434 | If the | |
7435 | .B \-p | |
7436 | option is supplied, no path search is performed, and | |
7437 | .I filename | |
7438 | is used as the full file name of the command. | |
7439 | The | |
726f6388 JA |
7440 | .B \-r |
7441 | option causes the shell to forget all | |
f73dda09 | 7442 | remembered locations. |
7117c2d2 JA |
7443 | The |
7444 | .B \-d | |
7445 | option causes the shell to forget the remembered location of each \fIname\fP. | |
f73dda09 JA |
7446 | If the |
7447 | .B \-t | |
7448 | option is supplied, the full pathname to which each \fIname\fP corresponds | |
7449 | is printed. If multiple \fIname\fP arguments are supplied with \fB\-t\fP, | |
7450 | the \fIname\fP is printed before the hashed full pathname. | |
7117c2d2 JA |
7451 | The |
7452 | .B \-l | |
7453 | option causes output to be displayed in a format that may be reused as input. | |
7454 | If no arguments are given, or if only \fB\-l\fP is supplied, | |
7455 | information about remembered commands is printed. | |
ccc6cda3 | 7456 | The return status is true unless a |
726f6388 | 7457 | .I name |
cce855bc | 7458 | is not found or an invalid option is supplied. |
726f6388 | 7459 | .TP |
6a8fd0ed | 7460 | \fBhelp\fP [\fB\-dms\fP] [\fIpattern\fP] |
726f6388 JA |
7461 | Display helpful information about builtin commands. If |
7462 | .I pattern | |
7463 | is specified, | |
7464 | .B help | |
7465 | gives detailed help on all commands matching | |
7466 | .IR pattern ; | |
ccc6cda3 | 7467 | otherwise help for all the builtins and shell control structures |
bb70624e | 7468 | is printed. |
6a8fd0ed CR |
7469 | .RS |
7470 | .PD 0 | |
7471 | .TP | |
7472 | .B \-d | |
7473 | Display a short description of each \fIpattern\fP | |
7474 | .TP | |
6932f7f5 | 7475 | .B \-m |
6a8fd0ed CR |
7476 | Display the description of each \fIpattern\fP in a manpage-like format |
7477 | .TP | |
7478 | .B \-s | |
7479 | Display only a short usage synopsis for each \fIpattern\fP | |
7480 | .PD | |
7481 | .RE | |
bb70624e | 7482 | The return status is 0 unless no command matches |
726f6388 JA |
7483 | .IR pattern . |
7484 | .TP | |
bb70624e | 7485 | \fBhistory [\fIn\fP] |
7117c2d2 | 7486 | .PD 0 |
bb70624e JA |
7487 | .TP |
7488 | \fBhistory\fP \fB\-c\fP | |
7489 | .TP | |
7490 | \fBhistory \-d\fP \fIoffset\fP | |
ccc6cda3 JA |
7491 | .TP |
7492 | \fBhistory\fP \fB\-anrw\fP [\fIfilename\fP] | |
726f6388 | 7493 | .TP |
ccc6cda3 JA |
7494 | \fBhistory\fP \fB\-p\fP \fIarg\fP [\fIarg ...\fP] |
7495 | .TP | |
7496 | \fBhistory\fP \fB\-s\fP \fIarg\fP [\fIarg ...\fP] | |
726f6388 JA |
7497 | .PD |
7498 | With no options, display the command | |
7499 | history list with line numbers. Lines listed | |
7500 | with a | |
7501 | .B * | |
7502 | have been modified. An argument of | |
7503 | .I n | |
7504 | lists only the last | |
7505 | .I n | |
d3a24ed2 CR |
7506 | lines. |
7507 | If the shell variable \fBHISTTIMEFORMAT\fP is set and not null, | |
7508 | it is used as a format string for \fIstrftime\fP(3) to display | |
7509 | the time stamp associated with each displayed history entry. | |
7510 | No intervening blank is printed between the formatted time stamp | |
7511 | and the history line. | |
7512 | If \fIfilename\fP is supplied, it is used as the | |
726f6388 JA |
7513 | name of the history file; if not, the value of |
7514 | .SM | |
7515 | .B HISTFILE | |
7516 | is used. Options, if supplied, have the following meanings: | |
7517 | .RS | |
7518 | .PD 0 | |
7519 | .TP | |
bb70624e JA |
7520 | .B \-c |
7521 | Clear the history list by deleting all the entries. | |
7522 | .TP | |
7523 | \fB\-d\fP \fIoffset\fP | |
7524 | Delete the history entry at position \fIoffset\fP. | |
7525 | .TP | |
726f6388 JA |
7526 | .B \-a |
7527 | Append the ``new'' history lines (history lines entered since the | |
ccc6cda3 | 7528 | beginning of the current \fBbash\fP session) to the history file. |
726f6388 JA |
7529 | .TP |
7530 | .B \-n | |
7531 | Read the history lines not already read from the history | |
7532 | file into the current history list. These are lines | |
7533 | appended to the history file since the beginning of the | |
7534 | current \fBbash\fP session. | |
7535 | .TP | |
7536 | .B \-r | |
7537 | Read the contents of the history file | |
ccc6cda3 | 7538 | and use them as the current history. |
726f6388 JA |
7539 | .TP |
7540 | .B \-w | |
7541 | Write the current history to the history file, overwriting the | |
7542 | history file's contents. | |
ccc6cda3 | 7543 | .TP |
ccc6cda3 JA |
7544 | .B \-p |
7545 | Perform history substitution on the following \fIargs\fP and display | |
7546 | the result on the standard output. | |
7547 | Does not store the results in the history list. | |
7548 | Each \fIarg\fP must be quoted to disable normal history expansion. | |
7549 | .TP | |
7550 | .B \-s | |
7551 | Store the | |
7552 | .I args | |
7553 | in the history list as a single entry. The last command in the | |
7554 | history list is removed before the | |
7555 | .I args | |
7556 | are added. | |
726f6388 JA |
7557 | .PD |
7558 | .PP | |
d3a24ed2 | 7559 | If the \fBHISTTIMEFORMAT\fP is set, the time stamp information |
d3ad40de CR |
7560 | associated with each history entry is written to the history file, |
7561 | marked with the history comment character. | |
7562 | When the history file is read, lines beginning with the history | |
7563 | comment character followed immediately by a digit are interpreted | |
7564 | as timestamps for the previous history line. | |
bb70624e JA |
7565 | The return value is 0 unless an invalid option is encountered, an |
7566 | error occurs while reading or writing the history file, an invalid | |
7567 | \fIoffset\fP is supplied as an argument to \fB\-d\fP, or the | |
7568 | history expansion supplied as an argument to \fB\-p\fP fails. | |
726f6388 JA |
7569 | .RE |
7570 | .TP | |
ccc6cda3 | 7571 | \fBjobs\fP [\fB\-lnprs\fP] [ \fIjobspec\fP ... ] |
7117c2d2 | 7572 | .PD 0 |
726f6388 JA |
7573 | .TP |
7574 | \fBjobs\fP \fB\-x\fP \fIcommand\fP [ \fIargs\fP ... ] | |
7575 | .PD | |
ccc6cda3 JA |
7576 | The first form lists the active jobs. The options have the following |
7577 | meanings: | |
7578 | .RS | |
7579 | .PD 0 | |
7580 | .TP | |
726f6388 | 7581 | .B \-l |
ccc6cda3 JA |
7582 | List process IDs |
7583 | in addition to the normal information. | |
7584 | .TP | |
726f6388 | 7585 | .B \-p |
ccc6cda3 JA |
7586 | List only the process ID of the job's process group |
7587 | leader. | |
7588 | .TP | |
726f6388 | 7589 | .B \-n |
ccc6cda3 JA |
7590 | Display information only about jobs that have changed status since |
7591 | the user was last notified of their status. | |
7592 | .TP | |
7593 | .B \-r | |
7594 | Restrict output to running jobs. | |
7595 | .TP | |
7596 | .B \-s | |
7597 | Restrict output to stopped jobs. | |
7598 | .PD | |
7599 | .PP | |
7600 | If | |
726f6388 JA |
7601 | .I jobspec |
7602 | is given, output is restricted to information about that job. | |
cce855bc JA |
7603 | The return status is 0 unless an invalid option is encountered |
7604 | or an invalid | |
726f6388 JA |
7605 | .I jobspec |
7606 | is supplied. | |
ccc6cda3 | 7607 | .PP |
726f6388 JA |
7608 | If the |
7609 | .B \-x | |
7610 | option is supplied, | |
7611 | .B jobs | |
7612 | replaces any | |
7613 | .I jobspec | |
7614 | found in | |
7615 | .I command | |
7616 | or | |
7617 | .I args | |
7618 | with the corresponding process group ID, and executes | |
7619 | .I command | |
7620 | passing it | |
7621 | .IR args , | |
7622 | returning its exit status. | |
ccc6cda3 | 7623 | .RE |
726f6388 | 7624 | .TP |
ccc6cda3 | 7625 | \fBkill\fP [\fB\-s\fP \fIsigspec\fP | \fB\-n\fP \fIsignum\fP | \fB\-\fP\fIsigspec\fP] [\fIpid\fP | \fIjobspec\fP] ... |
7117c2d2 | 7626 | .PD 0 |
726f6388 | 7627 | .TP |
cce855bc | 7628 | \fBkill\fP \fB\-l\fP [\fIsigspec\fP | \fIexit_status\fP] |
726f6388 JA |
7629 | .PD |
7630 | Send the signal named by | |
7631 | .I sigspec | |
ccc6cda3 JA |
7632 | or |
7633 | .I signum | |
726f6388 JA |
7634 | to the processes named by |
7635 | .I pid | |
7636 | or | |
7637 | .IR jobspec . | |
7638 | .I sigspec | |
61deeb13 | 7639 | is either a case-insensitive signal name such as |
726f6388 JA |
7640 | .SM |
7641 | .B SIGKILL | |
61deeb13 | 7642 | (with or without the |
726f6388 JA |
7643 | .SM |
7644 | .B SIG | |
61deeb13 CR |
7645 | prefix) or a signal number; |
7646 | .I signum | |
7647 | is a signal number. | |
726f6388 JA |
7648 | If |
7649 | .I sigspec | |
7650 | is not present, then | |
7651 | .SM | |
7652 | .B SIGTERM | |
cce855bc JA |
7653 | is assumed. |
7654 | An argument of | |
726f6388 | 7655 | .B \-l |
cce855bc JA |
7656 | lists the signal names. |
7657 | If any arguments are supplied when | |
726f6388 | 7658 | .B \-l |
cce855bc JA |
7659 | is given, the names of the signals corresponding to the arguments are |
7660 | listed, and the return status is 0. | |
7661 | The \fIexit_status\fP argument to | |
ccc6cda3 | 7662 | .B \-l |
cce855bc JA |
7663 | is a number specifying either a signal number or the exit status of |
7664 | a process terminated by a signal. | |
726f6388 JA |
7665 | .B kill |
7666 | returns true if at least one signal was successfully sent, or false | |
cce855bc | 7667 | if an error occurs or an invalid option is encountered. |
726f6388 JA |
7668 | .TP |
7669 | \fBlet\fP \fIarg\fP [\fIarg\fP ...] | |
7670 | Each | |
7671 | .I arg | |
7672 | is an arithmetic expression to be evaluated (see | |
7673 | .SM | |
7674 | .BR "ARITHMETIC EVALUATION" ). | |
7675 | If the last | |
7676 | .I arg | |
7677 | evaluates to 0, | |
7678 | .B let | |
7679 | returns 1; 0 is returned otherwise. | |
7680 | .TP | |
bb70624e | 7681 | \fBlocal\fP [\fIoption\fP] [\fIname\fP[=\fIvalue\fP] ...] |
cce855bc JA |
7682 | For each argument, a local variable named |
7683 | .I name | |
7684 | is created, and assigned | |
726f6388 | 7685 | .IR value . |
bb70624e | 7686 | The \fIoption\fP can be any of the options accepted by \fBdeclare\fP. |
726f6388 JA |
7687 | When |
7688 | .B local | |
7689 | is used within a function, it causes the variable | |
7690 | .I name | |
7691 | to have a visible scope restricted to that function and its children. | |
7692 | With no operands, | |
7693 | .B local | |
7694 | writes a list of local variables to the standard output. It is | |
7695 | an error to use | |
7696 | .B local | |
7697 | when not within a function. The return status is 0 unless | |
7698 | .B local | |
bb70624e | 7699 | is used outside a function, an invalid |
726f6388 | 7700 | .I name |
bb70624e JA |
7701 | is supplied, or |
7702 | \fIname\fP is a readonly variable. | |
726f6388 JA |
7703 | .TP |
7704 | .B logout | |
7705 | Exit a login shell. | |
7706 | .TP | |
09767ff0 | 7707 | \fBmapfile\fP [\fB\-n\fP \fIcount\fP] [\fB\-O\fP \fIorigin\fP] [\fB\-s\fP \fIcount\fP] [\fB\-t\fP] [\fB\-u\fP \fIfd\fP] [\fB\-C\fP \fIcallback\fP] [\fB\-c\fP \fIquantum\fP] [\fIarray\fP] |
e141c35a CR |
7708 | .PD 0 |
7709 | .TP | |
7710 | \fBreadarray\fP [\fB\-n\fP \fIcount\fP] [\fB\-O\fP \fIorigin\fP] [\fB\-s\fP \fIcount\fP] [\fB\-t\fP] [\fB\-u\fP \fIfd\fP] [\fB\-C\fP \fIcallback\fP] [\fB\-c\fP \fIquantum\fP] [\fIarray\fP] | |
7711 | .PD | |
6a8fd0ed CR |
7712 | Read lines from the standard input into array variable |
7713 | .IR array , | |
7714 | or from file descriptor | |
7715 | .IR fd | |
7716 | if the | |
7717 | .B \-u | |
7718 | option is supplied. | |
7719 | The variable \fBMAPFILE\fP is the default \fIarray\fP. | |
7720 | Options, if supplied, have the following meanings: | |
7721 | .RS | |
7722 | .PD 0 | |
7723 | .TP | |
7724 | .B \-n | |
7725 | Copy at most | |
7726 | .I count | |
7727 | lines. If \fIcount\fP is 0, all lines are copied. | |
7728 | .TP | |
7729 | .B \-O | |
7730 | Begin assigning to | |
7731 | .I array | |
7732 | at index | |
7733 | .IR origin . | |
7734 | The default index is 0. | |
7735 | .TP | |
7736 | .B \-s | |
7737 | Discard the first \fIcount\fP lines read. | |
7738 | .TP | |
7739 | .B \-t | |
7740 | Remove a trailing line from each line read. | |
7741 | .TP | |
7742 | .B \-u | |
7743 | Read lines from file descriptor \fIfd\fP instead of the standard input. | |
7744 | .TP | |
7745 | .B \-C | |
7746 | Evaluate | |
7747 | .I callback | |
7748 | each time \fIquantum\fP lines are read. The \fB\-c\fP option specifies | |
7749 | .IR quantum . | |
7750 | .TP | |
7751 | .B \-c | |
7752 | Specify the number of lines read between each call to | |
7753 | .IR callback . | |
7754 | .PD | |
7755 | .PP | |
7756 | If | |
7757 | .B \-C | |
7758 | is specified without | |
7759 | .BR \-c , | |
7760 | the default quantum is 5000. | |
e141c35a CR |
7761 | When \fIcallback\fP is evaluated, it is supplied the index of the next |
7762 | array element to be assigned as an additional argument. | |
7763 | \fIcallback\fP is evaluated after the line is read but before the | |
7764 | array element is assigned. | |
6a8fd0ed CR |
7765 | .PP |
7766 | If not supplied with an explicit origin, \fBmapfile\fP will clear \fIarray\fP | |
7767 | before assigning to it. | |
7768 | .PP | |
7769 | \fBmapfile\fP returns successfully unless an invalid option or option | |
7770 | argument is supplied, or \fIarray\fP is invalid or unassignable. | |
7771 | .RE | |
7772 | .TP | |
ccc6cda3 | 7773 | \fBpopd\fP [\-\fBn\fP] [+\fIn\fP] [\-\fIn\fP] |
726f6388 JA |
7774 | Removes entries from the directory stack. With no arguments, |
7775 | removes the top directory from the stack, and performs a | |
7776 | .B cd | |
7777 | to the new top directory. | |
ccc6cda3 | 7778 | Arguments, if supplied, have the following meanings: |
726f6388 JA |
7779 | .RS |
7780 | .PD 0 | |
7781 | .TP | |
d3ad40de CR |
7782 | .B \-n |
7783 | Suppresses the normal change of directory when removing directories | |
7784 | from the stack, so that only the stack is manipulated. | |
7785 | .TP | |
ccc6cda3 JA |
7786 | \fB+\fP\fIn\fP |
7787 | Removes the \fIn\fPth entry counting from the left of the list | |
726f6388 JA |
7788 | shown by |
7789 | .BR dirs , | |
bb70624e JA |
7790 | starting with zero. For example: |
7791 | .if n ``popd +0'' | |
7792 | .if t \f(CWpopd +0\fP | |
7793 | removes the first directory, | |
7794 | .if n ``popd +1'' | |
7795 | .if t \f(CWpopd +1\fP | |
7796 | the second. | |
726f6388 | 7797 | .TP |
ccc6cda3 JA |
7798 | \fB\-\fP\fIn\fP |
7799 | Removes the \fIn\fPth entry counting from the right of the list | |
726f6388 JA |
7800 | shown by |
7801 | .BR dirs , | |
bb70624e JA |
7802 | starting with zero. For example: |
7803 | .if n ``popd -0'' | |
7804 | .if t \f(CWpopd -0\fP | |
7805 | removes the last directory, | |
7806 | .if n ``popd -1'' | |
7807 | .if t \f(CWpopd -1\fP | |
7808 | the next to last. | |
726f6388 JA |
7809 | .PD |
7810 | .PP | |
7811 | If the | |
7812 | .B popd | |
7813 | command is successful, a | |
7814 | .B dirs | |
7815 | is performed as well, and the return status is 0. | |
7816 | .B popd | |
cce855bc | 7817 | returns false if an invalid option is encountered, the directory stack |
726f6388 JA |
7818 | is empty, a non-existent directory stack entry is specified, or the |
7819 | directory change fails. | |
7820 | .RE | |
7821 | .TP | |
3ee6b87d | 7822 | \fBprintf\fP [\fB\-v\fP \fIvar\fP] \fIformat\fP [\fIarguments\fP] |
cce855bc JA |
7823 | Write the formatted \fIarguments\fP to the standard output under the |
7824 | control of the \fIformat\fP. | |
7825 | The \fIformat\fP is a character string which contains three types of objects: | |
7826 | plain characters, which are simply copied to standard output, character | |
7827 | escape sequences, which are converted and copied to the standard output, and | |
7828 | format specifications, each of which causes printing of the next successive | |
7829 | \fIargument\fP. | |
f73dda09 | 7830 | In addition to the standard \fIprintf\fP(1) formats, \fB%b\fP causes |
cce855bc | 7831 | \fBprintf\fP to expand backslash escape sequences in the corresponding |
5e13499c | 7832 | \fIargument\fP (except that \fB\ec\fP terminates output, backslashes in |
20587658 | 7833 | \fB\e\(aq\fP, \fB\e"\fP, and \fB\e?\fP are not removed, and octal escapes |
5e13499c CR |
7834 | beginning with \fB\e0\fP may contain up to four digits), |
7835 | and \fB%q\fP causes \fBprintf\fP to output the corresponding | |
cce855bc JA |
7836 | \fIargument\fP in a format that can be reused as shell input. |
7837 | .sp 1 | |
3ee6b87d CR |
7838 | The \fB\-v\fP option causes the output to be assigned to the variable |
7839 | \fIvar\fP rather than being printed to the standard output. | |
7840 | .sp 1 | |
cce855bc JA |
7841 | The \fIformat\fP is reused as necessary to consume all of the \fIarguments\fP. |
7842 | If the \fIformat\fP requires more \fIarguments\fP than are supplied, the | |
7843 | extra format specifications behave as if a zero value or null string, as | |
bb70624e JA |
7844 | appropriate, had been supplied. The return value is zero on success, |
7845 | non-zero on failure. | |
cce855bc | 7846 | .TP |
d3ad40de | 7847 | \fBpushd\fP [\fB\-n\fP] [+\fIn\fP] [\-\fIn\fP] |
7117c2d2 | 7848 | .PD 0 |
726f6388 | 7849 | .TP |
d3ad40de | 7850 | \fBpushd\fP [\fB\-n\fP] [\fIdir\fP] |
726f6388 JA |
7851 | .PD |
7852 | Adds a directory to the top of the directory stack, or rotates | |
7853 | the stack, making the new top of the stack the current working | |
7854 | directory. With no arguments, exchanges the top two directories | |
7855 | and returns 0, unless the directory stack is empty. | |
ccc6cda3 | 7856 | Arguments, if supplied, have the following meanings: |
726f6388 JA |
7857 | .RS |
7858 | .PD 0 | |
7859 | .TP | |
d3ad40de CR |
7860 | .B \-n |
7861 | Suppresses the normal change of directory when adding directories | |
7862 | to the stack, so that only the stack is manipulated. | |
7863 | .TP | |
ccc6cda3 | 7864 | \fB+\fP\fIn\fP |
726f6388 JA |
7865 | Rotates the stack so that the \fIn\fPth directory |
7866 | (counting from the left of the list shown by | |
d166f048 JA |
7867 | .BR dirs , |
7868 | starting with zero) | |
726f6388 JA |
7869 | is at the top. |
7870 | .TP | |
ccc6cda3 | 7871 | \fB\-\fP\fIn\fP |
726f6388 | 7872 | Rotates the stack so that the \fIn\fPth directory |
d166f048 JA |
7873 | (counting from the right of the list shown by |
7874 | .BR dirs , | |
7875 | starting with zero) is at the top. | |
726f6388 | 7876 | .TP |
bb70624e | 7877 | .I dir |
ccc6cda3 | 7878 | Adds |
726f6388 JA |
7879 | .I dir |
7880 | to the directory stack at the top, making it the | |
7881 | new current working directory. | |
7882 | .PD | |
7883 | .PP | |
7884 | If the | |
7885 | .B pushd | |
7886 | command is successful, a | |
7887 | .B dirs | |
7888 | is performed as well. | |
7889 | If the first form is used, | |
7890 | .B pushd | |
7891 | returns 0 unless the cd to | |
7892 | .I dir | |
7893 | fails. With the second form, | |
7894 | .B pushd | |
7895 | returns 0 unless the directory stack is empty, | |
ccc6cda3 | 7896 | a non-existent directory stack element is specified, |
726f6388 JA |
7897 | or the directory change to the specified new current directory |
7898 | fails. | |
7899 | .RE | |
7900 | .TP | |
ccc6cda3 | 7901 | \fBpwd\fP [\fB\-LP\fP] |
bb70624e JA |
7902 | Print the absolute pathname of the current working directory. |
7903 | The pathname printed contains no symbolic links if the | |
726f6388 | 7904 | .B \-P |
ccc6cda3 JA |
7905 | option is supplied or the |
7906 | .B \-o physical | |
726f6388 JA |
7907 | option to the |
7908 | .B set | |
ccc6cda3 JA |
7909 | builtin command is enabled. |
7910 | If the | |
7911 | .B \-L | |
bb70624e | 7912 | option is used, the pathname printed may contain symbolic links. |
ccc6cda3 | 7913 | The return status is 0 unless an error occurs while |
cce855bc JA |
7914 | reading the name of the current directory or an |
7915 | invalid option is supplied. | |
726f6388 | 7916 | .TP |
db31fb26 | 7917 | \fBread\fP [\fB\-ers\fP] [\fB\-a\fP \fIaname\fP] [\fB\-d\fP \fIdelim\fP] [\fB\-i\fP \fItext\fP] [\fB\-n\fP \fInchars\fP] [\fB\-p\fP \fIprompt\fP] [\fB\-t\fP \fItimeout\fP] [\fB\-u\fP \fIfd\fP] [\fIname\fP ...] |
7117c2d2 JA |
7918 | One line is read from the standard input, or from the file descriptor |
7919 | \fIfd\fP supplied as an argument to the \fB\-u\fP option, and the first word | |
726f6388 JA |
7920 | is assigned to the first |
7921 | .IR name , | |
7922 | the second word to the second | |
7923 | .IR name , | |
cce855bc JA |
7924 | and so on, with leftover words and their intervening separators assigned |
7925 | to the last | |
726f6388 | 7926 | .IR name . |
7117c2d2 | 7927 | If there are fewer words read from the input stream than names, |
cce855bc JA |
7928 | the remaining names are assigned empty values. |
7929 | The characters in | |
726f6388 JA |
7930 | .SM |
7931 | .B IFS | |
cce855bc | 7932 | are used to split the line into words. |
b72432fd JA |
7933 | The backslash character (\fB\e\fP) may be used to remove any special |
7934 | meaning for the next character read and for line continuation. | |
cce855bc | 7935 | Options, if supplied, have the following meanings: |
ccc6cda3 JA |
7936 | .RS |
7937 | .PD 0 | |
7938 | .TP | |
bb70624e | 7939 | .B \-a \fIaname\fP |
ccc6cda3 JA |
7940 | The words are assigned to sequential indices |
7941 | of the array variable | |
7942 | .IR aname , | |
7943 | starting at 0. | |
7944 | .I aname | |
7945 | is unset before any new values are assigned. | |
cce855bc | 7946 | Other \fIname\fP arguments are ignored. |
ccc6cda3 | 7947 | .TP |
bb70624e JA |
7948 | .B \-d \fIdelim\fP |
7949 | The first character of \fIdelim\fP is used to terminate the input line, | |
7950 | rather than newline. | |
7951 | .TP | |
ccc6cda3 JA |
7952 | .B \-e |
7953 | If the standard input | |
7954 | is coming from a terminal, | |
7955 | .B readline | |
7956 | (see | |
7957 | .SM | |
7958 | .B READLINE | |
7959 | above) is used to obtain the line. | |
14e8b2a7 CR |
7960 | Readline uses the current (or default, if line editing was not previously |
7961 | active) editing settings. | |
bb70624e | 7962 | .TP |
1d0e1a34 CR |
7963 | .B \-i \fItext\fP |
7964 | If | |
7965 | .B readline | |
7966 | is being used to read the line, \fItext\fP is placed into the editing | |
7967 | buffer before editing begins. | |
7968 | .TP | |
bb70624e JA |
7969 | .B \-n \fInchars\fP |
7970 | \fBread\fP returns after reading \fInchars\fP characters rather than | |
7971 | waiting for a complete line of input. | |
7972 | .TP | |
7973 | .B \-p \fIprompt\fP | |
f73dda09 | 7974 | Display \fIprompt\fP on standard error, without a |
bb70624e JA |
7975 | trailing newline, before attempting to read any input. The prompt |
7976 | is displayed only if input is coming from a terminal. | |
7977 | .TP | |
7978 | .B \-r | |
7979 | Backslash does not act as an escape character. | |
7980 | The backslash is considered to be part of the line. | |
7981 | In particular, a backslash-newline pair may not be used as a line | |
7982 | continuation. | |
7983 | .TP | |
7984 | .B \-s | |
7985 | Silent mode. If input is coming from a terminal, characters are | |
7986 | not echoed. | |
7987 | .TP | |
7988 | .B \-t \fItimeout\fP | |
7989 | Cause \fBread\fP to time out and return failure if a complete line of | |
7990 | input is not read within \fItimeout\fP seconds. | |
4ac1ff98 CR |
7991 | \fItimeout\fP may be a decimal number with a fractional portion following |
7992 | the decimal point. | |
e33f2203 CR |
7993 | This option is only effective if \fBread\fP is reading input from a |
7994 | terminal, pipe, or other special file; it has no effect when reading | |
7995 | from regular files. | |
48ff5447 CR |
7996 | If \fItimeout\fP is 0, \fBread\fP returns success if input is available on |
7997 | the specified file descriptor, failure otherwise. | |
e33f2203 | 7998 | The exit status is greater than 128 if the timeout is exceeded. |
7117c2d2 | 7999 | .TP |
0f445e6c | 8000 | .B \-u \fIfd\fP |
7117c2d2 | 8001 | Read input from file descriptor \fIfd\fP. |
ccc6cda3 JA |
8002 | .PD |
8003 | .PP | |
8004 | If no | |
726f6388 JA |
8005 | .I names |
8006 | are supplied, the line read is assigned to the variable | |
8007 | .SM | |
8008 | .BR REPLY . | |
7117c2d2 | 8009 | The return code is zero, unless end-of-file is encountered, \fBread\fP |
09767ff0 CR |
8010 | times out (in which case the return code is greater than 128), or an |
8011 | invalid file descriptor is supplied as the argument to \fB\-u\fP. | |
ccc6cda3 | 8012 | .RE |
726f6388 | 8013 | .TP |
fdf670ea | 8014 | \fBreadonly\fP [\fB\-aApf\fP] [\fIname\fP[=\fIword\fP] ...] |
726f6388 JA |
8015 | .PD |
8016 | The given | |
ccc6cda3 JA |
8017 | \fInames\fP are marked readonly; the values of these |
8018 | .I names | |
726f6388 JA |
8019 | may not be changed by subsequent assignment. |
8020 | If the | |
8021 | .B \-f | |
8022 | option is supplied, the functions corresponding to the | |
8023 | \fInames\fP are so | |
ccc6cda3 JA |
8024 | marked. |
8025 | The | |
8026 | .B \-a | |
fdf670ea CR |
8027 | option restricts the variables to indexed arrays; the |
8028 | .B \-A | |
8029 | option restricts the variables to associative arrays. | |
ccc6cda3 JA |
8030 | If no |
8031 | .I name | |
8032 | arguments are given, or if the | |
726f6388 | 8033 | .B \-p |
ccc6cda3 | 8034 | option is supplied, a list of all readonly names is printed. |
cce855bc JA |
8035 | The |
8036 | .B \-p | |
bb70624e JA |
8037 | option causes output to be displayed in a format that |
8038 | may be reused as input. | |
d3a24ed2 CR |
8039 | If a variable name is followed by =\fIword\fP, the value of |
8040 | the variable is set to \fIword\fP. | |
cce855bc | 8041 | The return status is 0 unless an invalid option is encountered, |
ccc6cda3 JA |
8042 | one of the |
8043 | .I names | |
cce855bc | 8044 | is not a valid shell variable name, or |
726f6388 JA |
8045 | .B \-f |
8046 | is supplied with a | |
8047 | .I name | |
8048 | that is not a function. | |
8049 | .TP | |
8050 | \fBreturn\fP [\fIn\fP] | |
8051 | Causes a function to exit with the return value specified by | |
8052 | .IR n . | |
8053 | If | |
8054 | .I n | |
8055 | is omitted, the return status is that of the last command | |
8056 | executed in the function body. If used outside a function, | |
8057 | but during execution of a script by the | |
8058 | .B . | |
8059 | (\fBsource\fP) command, it causes the shell to stop executing | |
8060 | that script and return either | |
8061 | .I n | |
8062 | or the exit status of the last command executed within the | |
8063 | script as the exit status of the script. If used outside a | |
8064 | function and not during execution of a script by \fB.\fP\^, | |
8065 | the return status is false. | |
d3a24ed2 CR |
8066 | Any command associated with the \fBRETURN\fP trap is executed |
8067 | before execution resumes after the function or script. | |
726f6388 | 8068 | .TP |
d3ad40de CR |
8069 | \fBset\fP [\fB\-\-abefhkmnptuvxBCEHPT\fP] [\fB\-o\fP \fIoption\fP] [\fIarg\fP ...] |
8070 | .PD 0 | |
8071 | .TP | |
8072 | \fBset\fP [\fB+abefhkmnptuvxBCEHPT\fP] [\fB+o\fP \fIoption\fP] [\fIarg\fP ...] | |
8073 | .PD | |
ccc6cda3 | 8074 | Without options, the name and value of each shell variable are displayed |
54cdd75a CR |
8075 | in a format that can be reused as input |
8076 | for setting or resetting the currently-set variables. | |
8077 | Read-only variables cannot be reset. | |
8078 | In \fIposix mode\fP, only shell variables are listed. | |
cce855bc | 8079 | The output is sorted according to the current locale. |
ccc6cda3 | 8080 | When options are specified, they set or unset shell attributes. |
626d0694 | 8081 | Any arguments remaining after option processing are treated |
ccc6cda3 JA |
8082 | as values for the positional parameters and are assigned, in order, to |
8083 | .BR $1 , | |
8084 | .BR $2 , | |
8085 | .B ... | |
8086 | .BR $\fIn\fP . | |
8087 | Options, if specified, have the following meanings: | |
726f6388 JA |
8088 | .RS |
8089 | .PD 0 | |
8090 | .TP 8 | |
8091 | .B \-a | |
5e13499c CR |
8092 | Automatically mark variables and functions which are modified or |
8093 | created for export to the environment of subsequent commands. | |
726f6388 JA |
8094 | .TP 8 |
8095 | .B \-b | |
ccc6cda3 JA |
8096 | Report the status of terminated background jobs |
8097 | immediately, rather than before the next primary prompt. This is | |
8098 | effective only when job control is enabled. | |
726f6388 JA |
8099 | .TP 8 |
8100 | .B \-e | |
a05a1337 CR |
8101 | Exit immediately if a \fIpipeline\fP (which may consist of a single |
8102 | \fIsimple command\fP), a \fIsubshell\fP command enclosed in parentheses, | |
8103 | or one of the commands executed as part of a command list enclosed | |
8104 | by braces (see | |
726f6388 JA |
8105 | .SM |
8106 | .B SHELL GRAMMAR | |
d3a24ed2 CR |
8107 | above) exits with a non-zero status. |
8108 | The shell does not exit if the | |
8109 | command that fails is part of the command list immediately following a | |
8110 | .B while | |
726f6388 | 8111 | or |
d3a24ed2 CR |
8112 | .B until |
8113 | keyword, | |
4b9cc222 | 8114 | part of the test following the |
d3ad40de | 8115 | .B if |
4b9cc222 CR |
8116 | or |
8117 | .B elif | |
8118 | reserved words, part of any command executed in a | |
726f6388 JA |
8119 | .B && |
8120 | or | |
ccc6cda3 | 8121 | .B \(bv\(bv |
a05a1337 | 8122 | list except the command following the final \fB&&\fP or \fB\(bv\(bv\fP, |
d3ad40de CR |
8123 | any command in a pipeline but the last, |
8124 | or if the command's return value is | |
a05a1337 | 8125 | being inverted with |
726f6388 | 8126 | .BR ! . |
f73dda09 | 8127 | A trap on \fBERR\fP, if set, is executed before the shell exits. |
a05a1337 CR |
8128 | This option applies to the shell environment and each subshell environment |
8129 | separately (see | |
8130 | .B "COMMAND EXECUTION ENVIRONMENT" | |
8131 | above), and may cause | |
8132 | subshells to exit before executing all the commands in the subshell. | |
726f6388 JA |
8133 | .TP 8 |
8134 | .B \-f | |
8135 | Disable pathname expansion. | |
8136 | .TP 8 | |
8137 | .B \-h | |
ccc6cda3 | 8138 | Remember the location of commands as they are looked up for execution. |
cce855bc | 8139 | This is enabled by default. |
726f6388 JA |
8140 | .TP 8 |
8141 | .B \-k | |
ccc6cda3 JA |
8142 | All arguments in the form of assignment statements |
8143 | are placed in the environment for a command, not just | |
8144 | those that precede the command name. | |
726f6388 JA |
8145 | .TP 8 |
8146 | .B \-m | |
cce855bc | 8147 | Monitor mode. Job control is enabled. This option is on |
726f6388 JA |
8148 | by default for interactive shells on systems that support |
8149 | it (see | |
8150 | .SM | |
8151 | .B JOB CONTROL | |
8152 | above). Background processes run in a separate process | |
8153 | group and a line containing their exit status is printed | |
8154 | upon their completion. | |
8155 | .TP 8 | |
8156 | .B \-n | |
8157 | Read commands but do not execute them. This may be used to | |
ccc6cda3 | 8158 | check a shell script for syntax errors. This is ignored by |
726f6388 JA |
8159 | interactive shells. |
8160 | .TP 8 | |
ccc6cda3 JA |
8161 | .B \-o \fIoption\-name\fP |
8162 | The \fIoption\-name\fP can be one of the following: | |
726f6388 JA |
8163 | .RS |
8164 | .TP 8 | |
8165 | .B allexport | |
8166 | Same as | |
8167 | .BR \-a . | |
8168 | .TP 8 | |
8169 | .B braceexpand | |
ccc6cda3 JA |
8170 | Same as |
8171 | .BR \-B . | |
726f6388 JA |
8172 | .TP 8 |
8173 | .B emacs | |
8174 | Use an emacs-style command line editing interface. This is enabled | |
8175 | by default when the shell is interactive, unless the shell is started | |
8176 | with the | |
ccc6cda3 | 8177 | .B \-\-noediting |
726f6388 | 8178 | option. |
10a4e415 | 8179 | This also affects the editing interface used for \fBread \-e\fP. |
726f6388 | 8180 | .TP 8 |
d3a24ed2 CR |
8181 | .B errtrace |
8182 | Same as | |
8183 | .BR \-E . | |
8184 | .TP 8 | |
8185 | .B functrace | |
8186 | Same as | |
8187 | .BR \-T . | |
8188 | .TP 8 | |
726f6388 JA |
8189 | .B errexit |
8190 | Same as | |
8191 | .BR \-e . | |
8192 | .TP 8 | |
ccc6cda3 JA |
8193 | .B hashall |
8194 | Same as | |
8195 | .BR \-h . | |
8196 | .TP 8 | |
726f6388 JA |
8197 | .B histexpand |
8198 | Same as | |
8199 | .BR \-H . | |
8200 | .TP 8 | |
ccc6cda3 JA |
8201 | .B history |
8202 | Enable command history, as described above under | |
8203 | .SM | |
8204 | .BR HISTORY . | |
8205 | This option is on by default in interactive shells. | |
8206 | .TP 8 | |
726f6388 | 8207 | .B ignoreeof |
28ef6c31 JA |
8208 | The effect is as if the shell command |
8209 | .if t \f(CWIGNOREEOF=10\fP | |
8210 | .if n ``IGNOREEOF=10'' | |
8211 | had been executed | |
726f6388 JA |
8212 | (see |
8213 | .B Shell Variables | |
8214 | above). | |
8215 | .TP 8 | |
ccc6cda3 JA |
8216 | .B keyword |
8217 | Same as | |
8218 | .BR \-k . | |
726f6388 JA |
8219 | .TP 8 |
8220 | .B monitor | |
8221 | Same as | |
8222 | .BR \-m . | |
8223 | .TP 8 | |
8224 | .B noclobber | |
8225 | Same as | |
8226 | .BR \-C . | |
8227 | .TP 8 | |
8228 | .B noexec | |
8229 | Same as | |
8230 | .BR \-n . | |
8231 | .TP 8 | |
8232 | .B noglob | |
8233 | Same as | |
8234 | .BR \-f . | |
57a3f689 | 8235 | .TP 8 |
f73dda09 JA |
8236 | .B nolog |
8237 | Currently ignored. | |
726f6388 | 8238 | .TP 8 |
726f6388 JA |
8239 | .B notify |
8240 | Same as | |
8241 | .BR \-b . | |
8242 | .TP 8 | |
8243 | .B nounset | |
8244 | Same as | |
8245 | .BR \-u . | |
8246 | .TP 8 | |
ccc6cda3 JA |
8247 | .B onecmd |
8248 | Same as | |
8249 | .BR \-t . | |
8250 | .TP 8 | |
726f6388 JA |
8251 | .B physical |
8252 | Same as | |
8253 | .BR \-P . | |
8254 | .TP 8 | |
d3a24ed2 CR |
8255 | .B pipefail |
8256 | If set, the return value of a pipeline is the value of the last | |
8257 | (rightmost) command to exit with a non-zero status, or zero if all | |
8258 | commands in the pipeline exit successfully. | |
8259 | This option is disabled by default. | |
8260 | .TP 8 | |
726f6388 | 8261 | .B posix |
ccc6cda3 JA |
8262 | Change the behavior of |
8263 | .B bash | |
8264 | where the default operation differs | |
ac18b312 | 8265 | from the POSIX standard to match the standard (\fIposix mode\fP). |
726f6388 JA |
8266 | .TP 8 |
8267 | .B privileged | |
8268 | Same as | |
8269 | .BR \-p . | |
8270 | .TP 8 | |
8271 | .B verbose | |
8272 | Same as | |
8273 | .BR \-v . | |
8274 | .TP 8 | |
8275 | .B vi | |
8276 | Use a vi-style command line editing interface. | |
10a4e415 | 8277 | This also affects the editing interface used for \fBread \-e\fP. |
726f6388 JA |
8278 | .TP 8 |
8279 | .B xtrace | |
8280 | Same as | |
8281 | .BR \-x . | |
ccc6cda3 | 8282 | .sp .5 |
726f6388 | 8283 | .PP |
ccc6cda3 JA |
8284 | If |
8285 | .B \-o | |
8286 | is supplied with no \fIoption\-name\fP, the values of the current options are | |
726f6388 | 8287 | printed. |
ccc6cda3 JA |
8288 | If |
8289 | .B +o | |
8290 | is supplied with no \fIoption\-name\fP, a series of | |
8291 | .B set | |
8292 | commands to recreate the current option settings is displayed on | |
8293 | the standard output. | |
726f6388 JA |
8294 | .RE |
8295 | .TP 8 | |
8296 | .B \-p | |
8297 | Turn on | |
8298 | .I privileged | |
8299 | mode. In this mode, the | |
bb70624e | 8300 | .SM |
726f6388 | 8301 | .B $ENV |
b72432fd | 8302 | and |
bb70624e | 8303 | .SM |
b72432fd JA |
8304 | .B $BASH_ENV |
8305 | files are not processed, shell functions are not inherited from the | |
bb70624e JA |
8306 | environment, and the |
8307 | .SM | |
e77a3058 CR |
8308 | .BR SHELLOPTS , |
8309 | .BR CDPATH , | |
8310 | and | |
8311 | .B GLOBIGNORE | |
8312 | variables, if they appear in the environment, are ignored. | |
b72432fd JA |
8313 | If the shell is started with the effective user (group) id not equal to the |
8314 | real user (group) id, and the \fB\-p\fP option is not supplied, these actions | |
8315 | are taken and the effective user id is set to the real user id. | |
8316 | If the \fB\-p\fP option is supplied at startup, the effective user id is | |
8317 | not reset. | |
cce855bc | 8318 | Turning this option off causes the effective user |
726f6388 JA |
8319 | and group ids to be set to the real user and group ids. |
8320 | .TP 8 | |
8321 | .B \-t | |
8322 | Exit after reading and executing one command. | |
8323 | .TP 8 | |
8324 | .B \-u | |
2c471a92 CR |
8325 | Treat unset variables and parameters other than the special |
8326 | parameters "@" and "*" as an error when performing | |
726f6388 | 8327 | parameter expansion. If expansion is attempted on an |
2c471a92 | 8328 | unset variable or parameter, the shell prints an error message, and, |
ccc6cda3 | 8329 | if not interactive, exits with a non-zero status. |
726f6388 JA |
8330 | .TP 8 |
8331 | .B \-v | |
8332 | Print shell input lines as they are read. | |
8333 | .TP 8 | |
8334 | .B \-x | |
ccc6cda3 | 8335 | After expanding each \fIsimple command\fP, |
d3a24ed2 CR |
8336 | \fBfor\fP command, \fBcase\fP command, \fBselect\fP command, or |
8337 | arithmetic \fBfor\fP command, display the expanded value of | |
726f6388 JA |
8338 | .SM |
8339 | .BR PS4 , | |
d3a24ed2 CR |
8340 | followed by the command and its expanded arguments |
8341 | or associated word list. | |
726f6388 | 8342 | .TP 8 |
ccc6cda3 JA |
8343 | .B \-B |
8344 | The shell performs brace expansion (see | |
8345 | .B Brace Expansion | |
8346 | above). This is on by default. | |
726f6388 JA |
8347 | .TP 8 |
8348 | .B \-C | |
ccc6cda3 JA |
8349 | If set, |
8350 | .B bash | |
8351 | does not overwrite an existing file with the | |
8352 | .BR > , | |
8353 | .BR >& , | |
8354 | and | |
8355 | .B <> | |
8356 | redirection operators. This may be overridden when | |
8357 | creating output files by using the redirection operator | |
8358 | .B >| | |
8359 | instead of | |
8360 | .BR > . | |
726f6388 | 8361 | .TP 8 |
d3a24ed2 CR |
8362 | .B \-E |
8363 | If set, any trap on \fBERR\fP is inherited by shell functions, command | |
8364 | substitutions, and commands executed in a subshell environment. | |
8365 | The \fBERR\fP trap is normally not inherited in such cases. | |
8366 | .TP 8 | |
726f6388 JA |
8367 | .B \-H |
8368 | Enable | |
8369 | .B ! | |
cce855bc | 8370 | style history substitution. This option is on by |
726f6388 JA |
8371 | default when the shell is interactive. |
8372 | .TP 8 | |
8373 | .B \-P | |
ccc6cda3 JA |
8374 | If set, the shell does not follow symbolic links when executing |
8375 | commands such as | |
726f6388 | 8376 | .B cd |
ccc6cda3 JA |
8377 | that change the current working directory. It uses the |
8378 | physical directory structure instead. By default, | |
8379 | .B bash | |
8380 | follows the logical chain of directories when performing commands | |
8381 | which change the current directory. | |
726f6388 | 8382 | .TP 8 |
d3a24ed2 | 8383 | .B \-T |
76a8d78d CR |
8384 | If set, any traps on \fBDEBUG\fP and \fBRETURN\fP are inherited by shell |
8385 | functions, command substitutions, and commands executed in a | |
8386 | subshell environment. | |
8387 | The \fBDEBUG\fP and \fBRETURN\fP traps are normally not inherited | |
8388 | in such cases. | |
d3a24ed2 | 8389 | .TP 8 |
726f6388 | 8390 | .B \-\- |
cce855bc | 8391 | If no arguments follow this option, then the positional parameters are |
726f6388 JA |
8392 | unset. Otherwise, the positional parameters are set to the |
8393 | \fIarg\fPs, even if some of them begin with a | |
8394 | .BR \- . | |
8395 | .TP 8 | |
8396 | .B \- | |
8397 | Signal the end of options, cause all remaining \fIarg\fPs to be | |
8398 | assigned to the positional parameters. The | |
8399 | .B \-x | |
8400 | and | |
8401 | .B \-v | |
8402 | options are turned off. | |
8403 | If there are no \fIarg\fPs, | |
8404 | the positional parameters remain unchanged. | |
8405 | .PD | |
8406 | .PP | |
cce855bc JA |
8407 | The options are off by default unless otherwise noted. |
8408 | Using + rather than \- causes these options to be turned off. | |
8409 | The options can also be specified as arguments to an invocation of | |
8410 | the shell. | |
8411 | The current set of options may be found in | |
726f6388 | 8412 | .BR $\- . |
cce855bc | 8413 | The return status is always true unless an invalid option is encountered. |
726f6388 JA |
8414 | .RE |
8415 | .TP | |
8416 | \fBshift\fP [\fIn\fP] | |
8417 | The positional parameters from \fIn\fP+1 ... are renamed to | |
8418 | .B $1 | |
8419 | .B .... | |
8420 | Parameters represented by the numbers \fB$#\fP | |
8421 | down to \fB$#\fP\-\fIn\fP+1 are unset. | |
ccc6cda3 JA |
8422 | .I n |
8423 | must be a non-negative number less than or equal to \fB$#\fP. | |
726f6388 JA |
8424 | If |
8425 | .I n | |
8426 | is 0, no parameters are changed. | |
8427 | If | |
8428 | .I n | |
8429 | is not given, it is assumed to be 1. | |
726f6388 JA |
8430 | If |
8431 | .I n | |
8432 | is greater than \fB$#\fP, the positional parameters are not changed. | |
ccc6cda3 | 8433 | The return status is greater than zero if |
726f6388 JA |
8434 | .I n |
8435 | is greater than | |
8436 | .B $# | |
ccc6cda3 JA |
8437 | or less than zero; otherwise 0. |
8438 | .TP | |
8439 | \fBshopt\fP [\fB\-pqsu\fP] [\fB\-o\fP] [\fIoptname\fP ...] | |
8440 | Toggle the values of variables controlling optional shell behavior. | |
8441 | With no options, or with the | |
8442 | .B \-p | |
8443 | option, a list of all settable options is displayed, with | |
cce855bc JA |
8444 | an indication of whether or not each is set. |
8445 | The \fB\-p\fP option causes output to be displayed in a form that | |
8446 | may be reused as input. | |
8447 | Other options have the following meanings: | |
ccc6cda3 JA |
8448 | .RS |
8449 | .PD 0 | |
8450 | .TP | |
8451 | .B \-s | |
8452 | Enable (set) each \fIoptname\fP. | |
8453 | .TP | |
8454 | .B \-u | |
8455 | Disable (unset) each \fIoptname\fP. | |
8456 | .TP | |
8457 | .B \-q | |
8458 | Suppresses normal output (quiet mode); the return status indicates | |
8459 | whether the \fIoptname\fP is set or unset. | |
8460 | If multiple \fIoptname\fP arguments are given with | |
8461 | .BR \-q , | |
8462 | the return status is zero if all \fIoptnames\fP are enabled; non-zero | |
8463 | otherwise. | |
8464 | .TP | |
8465 | .B \-o | |
8466 | Restricts the values of \fIoptname\fP to be those defined for the | |
8467 | .B \-o | |
8468 | option to the | |
8469 | .B set | |
8470 | builtin. | |
8471 | .PD | |
8472 | .PP | |
8473 | If either | |
8474 | .B \-s | |
8475 | or | |
8476 | .B \-u | |
8477 | is used with no \fIoptname\fP arguments, the display is limited to | |
8478 | those options which are set or unset, respectively. | |
8479 | Unless otherwise noted, the \fBshopt\fP options are disabled (unset) | |
8480 | by default. | |
8481 | .PP | |
8482 | The return status when listing options is zero if all \fIoptnames\fP | |
8483 | are enabled, non-zero otherwise. When setting or unsetting options, | |
cce855bc | 8484 | the return status is zero unless an \fIoptname\fP is not a valid shell |
ccc6cda3 JA |
8485 | option. |
8486 | .PP | |
8487 | The list of \fBshopt\fP options is: | |
8488 | .if t .sp .5v | |
8489 | .if n .sp 1v | |
8490 | .PD 0 | |
8491 | .TP 8 | |
d3ad40de CR |
8492 | .B autocd |
8493 | If set, a command name that is the name of a directory is executed as if | |
8494 | it were the argument to the \fBcd\fP command. | |
8495 | This option is only used by interactive shells. | |
8496 | .TP 8 | |
ccc6cda3 JA |
8497 | .B cdable_vars |
8498 | If set, an argument to the | |
8499 | .B cd | |
8500 | builtin command that | |
8501 | is not a directory is assumed to be the name of a variable whose | |
8502 | value is the directory to change to. | |
8503 | .TP 8 | |
8504 | .B cdspell | |
8505 | If set, minor errors in the spelling of a directory component in a | |
8506 | .B cd | |
8507 | command will be corrected. | |
8508 | The errors checked for are transposed characters, | |
8509 | a missing character, and one character too many. | |
8510 | If a correction is found, the corrected file name is printed, | |
8511 | and the command proceeds. | |
d166f048 | 8512 | This option is only used by interactive shells. |
ccc6cda3 JA |
8513 | .TP 8 |
8514 | .B checkhash | |
8515 | If set, \fBbash\fP checks that a command found in the hash | |
8516 | table exists before trying to execute it. If a hashed command no | |
8517 | longer exists, a normal path search is performed. | |
8518 | .TP 8 | |
d3ad40de | 8519 | .B checkjobs |
29d25b54 | 8520 | If set, \fBbash\fP lists the status of any stopped and running jobs before |
d3ad40de CR |
8521 | exiting an interactive shell. If any jobs are running, this causes |
8522 | the exit to be deferred until a second exit is attempted without an | |
8523 | intervening command (see \fBJOB CONTROL\fP above). The shell always | |
8524 | postpones exiting if any jobs are stopped. | |
8525 | .TP 8 | |
ccc6cda3 JA |
8526 | .B checkwinsize |
8527 | If set, \fBbash\fP checks the window size after each command | |
8528 | and, if necessary, updates the values of | |
8529 | .SM | |
8530 | .B LINES | |
8531 | and | |
8532 | .SM | |
8533 | .BR COLUMNS . | |
8534 | .TP 8 | |
8535 | .B cmdhist | |
8536 | If set, | |
8537 | .B bash | |
8538 | attempts to save all lines of a multiple-line | |
8539 | command in the same history entry. This allows | |
8540 | easy re-editing of multi-line commands. | |
8541 | .TP 8 | |
35ee8ea0 CR |
8542 | .B compat31 |
8543 | If set, | |
8544 | .B bash | |
8545 | changes its behavior to that of version 3.1 with respect to quoted | |
8546 | arguments to the conditional command's =~ operator. | |
8547 | .TP 8 | |
4ac1ff98 CR |
8548 | .B dirspell |
8549 | If set, | |
8550 | .B bash | |
8551 | attempts spelling correction on directory names during word completion | |
8552 | if the directory name initially supplied does not exist. | |
8553 | .TP 8 | |
ccc6cda3 JA |
8554 | .B dotglob |
8555 | If set, | |
8556 | .B bash | |
8557 | includes filenames beginning with a `.' in the results of pathname | |
8558 | expansion. | |
8559 | .TP 8 | |
8560 | .B execfail | |
8561 | If set, a non-interactive shell will not exit if | |
8562 | it cannot execute the file specified as an argument to the | |
8563 | .B exec | |
8564 | builtin command. An interactive shell does not exit if | |
8565 | .B exec | |
8566 | fails. | |
8567 | .TP 8 | |
8568 | .B expand_aliases | |
8569 | If set, aliases are expanded as described above under | |
8570 | .SM | |
8571 | .BR ALIASES . | |
8572 | This option is enabled by default for interactive shells. | |
8573 | .TP 8 | |
d3a24ed2 CR |
8574 | .B extdebug |
8575 | If set, behavior intended for use by debuggers is enabled: | |
8576 | .RS | |
8577 | .TP | |
8578 | .B 1. | |
8579 | The \fB\-F\fP option to the \fBdeclare\fP builtin displays the source | |
8580 | file name and line number corresponding to each function name supplied | |
8581 | as an argument. | |
8582 | .TP | |
8583 | .B 2. | |
8584 | If the command run by the \fBDEBUG\fP trap returns a non-zero value, the | |
8585 | next command is skipped and not executed. | |
8586 | .TP | |
8587 | .B 3. | |
8588 | If the command run by the \fBDEBUG\fP trap returns a value of 2, and the | |
8589 | shell is executing in a subroutine (a shell function or a shell script | |
8590 | executed by the \fB.\fP or \fBsource\fP builtins), a call to | |
8591 | \fBreturn\fP is simulated. | |
2206f89a CR |
8592 | .TP |
8593 | .B 4. | |
8594 | \fBBASH_ARGC\fP and \fBBASH_ARGV\fP are updated as described in their | |
8595 | descriptions above. | |
8596 | .TP | |
8597 | .B 5. | |
8598 | Function tracing is enabled: command substitution, shell functions, and | |
8599 | subshells invoked with \fB(\fP \fIcommand\fP \fB)\fP inherit the | |
8600 | \fBDEBUG\fP and \fBRETURN\fP traps. | |
8601 | .TP | |
8602 | .B 6. | |
8603 | Error tracing is enabled: command substitution, shell functions, and | |
8604 | subshells invoked with \fB(\fP \fIcommand\fP \fB)\fP inherit the | |
8605 | \fBERROR\fP trap. | |
d3a24ed2 CR |
8606 | .RE |
8607 | .TP 8 | |
cce855bc JA |
8608 | .B extglob |
8609 | If set, the extended pattern matching features described above under | |
8610 | \fBPathname Expansion\fP are enabled. | |
8611 | .TP 8 | |
d3a24ed2 | 8612 | .B extquote |
20587658 | 8613 | If set, \fB$\fP\(aq\fIstring\fP\(aq and \fB$\fP"\fIstring\fP" quoting is |
d3a24ed2 CR |
8614 | performed within \fB${\fP\fIparameter\fP\fB}\fP expansions |
8615 | enclosed in double quotes. This option is enabled by default. | |
8616 | .TP 8 | |
8617 | .B failglob | |
8618 | If set, patterns which fail to match filenames during pathname expansion | |
8619 | result in an expansion error. | |
8620 | .TP 8 | |
8621 | .B force_fignore | |
8622 | If set, the suffixes specified by the \fBFIGNORE\fP shell variable | |
8623 | cause words to be ignored when performing word completion even if | |
8624 | the ignored words are the only possible completions. | |
8625 | See | |
8626 | .SM | |
8627 | \fBSHELL VARIABLES\fP | |
8628 | above for a description of \fBFIGNORE\fP. | |
8629 | This option is enabled by default. | |
8630 | .TP 8 | |
4ac1ff98 | 8631 | .B globstar |
d0ca3503 | 8632 | If set, the pattern \fB**\fP used in a pathname expansion context will |
4ac1ff98 CR |
8633 | match a files and zero or more directories and subdirectories. |
8634 | If the pattern is followed by a \fB/\fP, only directories and | |
8635 | subdirectories match. | |
8636 | .TP 8 | |
d3a24ed2 CR |
8637 | .B gnu_errfmt |
8638 | If set, shell error messages are written in the standard GNU error | |
8639 | message format. | |
8640 | .TP 8 | |
ccc6cda3 JA |
8641 | .B histappend |
8642 | If set, the history list is appended to the file named by the value | |
8643 | of the | |
8644 | .B HISTFILE | |
8645 | variable when the shell exits, rather than overwriting the file. | |
8646 | .TP 8 | |
8647 | .B histreedit | |
8648 | If set, and | |
8649 | .B readline | |
8650 | is being used, a user is given the opportunity to re-edit a | |
8651 | failed history substitution. | |
8652 | .TP 8 | |
8653 | .B histverify | |
8654 | If set, and | |
8655 | .B readline | |
8656 | is being used, the results of history substitution are not immediately | |
8657 | passed to the shell parser. Instead, the resulting line is loaded into | |
8658 | the \fBreadline\fP editing buffer, allowing further modification. | |
8659 | .TP 8 | |
8660 | .B hostcomplete | |
8661 | If set, and | |
8662 | .B readline | |
cce855bc JA |
8663 | is being used, \fBbash\fP will attempt to perform hostname completion when a |
8664 | word containing a \fB@\fP is being completed (see | |
ccc6cda3 JA |
8665 | .B Completing |
8666 | under | |
8667 | .SM | |
8668 | .B READLINE | |
8669 | above). | |
8670 | This is enabled by default. | |
8671 | .TP 8 | |
cce855bc JA |
8672 | .B huponexit |
8673 | If set, \fBbash\fP will send | |
8674 | .SM | |
8675 | .B SIGHUP | |
8676 | to all jobs when an interactive login shell exits. | |
8677 | .TP 8 | |
ccc6cda3 JA |
8678 | .B interactive_comments |
8679 | If set, allow a word beginning with | |
8680 | .B # | |
8681 | to cause that word and all remaining characters on that | |
8682 | line to be ignored in an interactive shell (see | |
8683 | .SM | |
8684 | .B COMMENTS | |
8685 | above). This option is enabled by default. | |
8686 | .TP 8 | |
8687 | .B lithist | |
8688 | If set, and the | |
8689 | .B cmdhist | |
8690 | option is enabled, multi-line commands are saved to the history with | |
8691 | embedded newlines rather than using semicolon separators where possible. | |
8692 | .TP 8 | |
f73dda09 JA |
8693 | .B login_shell |
8694 | The shell sets this option if it is started as a login shell (see | |
8695 | .SM | |
8696 | .B "INVOCATION" | |
8697 | above). | |
8698 | The value may not be changed. | |
8699 | .TP 8 | |
ccc6cda3 JA |
8700 | .B mailwarn |
8701 | If set, and a file that \fBbash\fP is checking for mail has been | |
8702 | accessed since the last time it was checked, the message ``The mail in | |
8703 | \fImailfile\fP has been read'' is displayed. | |
8704 | .TP 8 | |
bb70624e JA |
8705 | .B no_empty_cmd_completion |
8706 | If set, and | |
8707 | .B readline | |
8708 | is being used, | |
8709 | .B bash | |
8710 | will not attempt to search the \fBPATH\fP for possible completions when | |
8711 | completion is attempted on an empty line. | |
8712 | .TP 8 | |
cce855bc JA |
8713 | .B nocaseglob |
8714 | If set, | |
8715 | .B bash | |
8716 | matches filenames in a case\-insensitive fashion when performing pathname | |
8717 | expansion (see | |
8718 | .B Pathname Expansion | |
8719 | above). | |
8720 | .TP 8 | |
2206f89a CR |
8721 | .B nocasematch |
8722 | If set, | |
8723 | .B bash | |
8724 | matches patterns in a case\-insensitive fashion when performing matching | |
8725 | while executing \fBcase\fP or \fB[[\fP conditional commands. | |
8726 | .TP 8 | |
ccc6cda3 JA |
8727 | .B nullglob |
8728 | If set, | |
8729 | .B bash | |
8730 | allows patterns which match no | |
8731 | files (see | |
8732 | .B Pathname Expansion | |
8733 | above) | |
8734 | to expand to a null string, rather than themselves. | |
8735 | .TP 8 | |
bb70624e JA |
8736 | .B progcomp |
8737 | If set, the programmable completion facilities (see | |
8738 | \fBProgrammable Completion\fP above) are enabled. | |
8739 | This option is enabled by default. | |
8740 | .TP 8 | |
ccc6cda3 | 8741 | .B promptvars |
d3a24ed2 CR |
8742 | If set, prompt strings undergo |
8743 | parameter expansion, command substitution, arithmetic | |
8744 | expansion, and quote removal after being expanded as described in | |
ccc6cda3 JA |
8745 | .SM |
8746 | .B PROMPTING | |
8747 | above. This option is enabled by default. | |
8748 | .TP 8 | |
b72432fd JA |
8749 | .B restricted_shell |
8750 | The shell sets this option if it is started in restricted mode (see | |
8751 | .SM | |
8752 | .B "RESTRICTED SHELL" | |
8753 | below). | |
8754 | The value may not be changed. | |
8755 | This is not reset when the startup files are executed, allowing | |
8756 | the startup files to discover whether or not a shell is restricted. | |
8757 | .TP 8 | |
ccc6cda3 JA |
8758 | .B shift_verbose |
8759 | If set, the | |
8760 | .B shift | |
8761 | builtin prints an error message when the shift count exceeds the | |
8762 | number of positional parameters. | |
8763 | .TP 8 | |
8764 | .B sourcepath | |
8765 | If set, the | |
8766 | \fBsource\fP (\fB.\fP) builtin uses the value of | |
8767 | .SM | |
8768 | .B PATH | |
8769 | to find the directory containing the file supplied as an argument. | |
cce855bc | 8770 | This option is enabled by default. |
bb70624e JA |
8771 | .TP 8 |
8772 | .B xpg_echo | |
8773 | If set, the \fBecho\fP builtin expands backslash-escape sequences | |
8774 | by default. | |
ccc6cda3 | 8775 | .RE |
726f6388 JA |
8776 | .TP |
8777 | \fBsuspend\fP [\fB\-f\fP] | |
8778 | Suspend the execution of this shell until it receives a | |
8779 | .SM | |
8780 | .B SIGCONT | |
09767ff0 | 8781 | signal. A login shell cannot be suspended; the |
726f6388 | 8782 | .B \-f |
09767ff0 CR |
8783 | option can be used to override this and force the suspension. |
8784 | The return status is 0 unless the shell is a login shell and | |
726f6388 JA |
8785 | .B \-f |
8786 | is not supplied, or if job control is not enabled. | |
8787 | .TP | |
726f6388 | 8788 | \fBtest\fP \fIexpr\fP |
7117c2d2 | 8789 | .PD 0 |
726f6388 JA |
8790 | .TP |
8791 | \fB[\fP \fIexpr\fP \fB]\fP | |
ccc6cda3 | 8792 | Return a status of 0 or 1 depending on |
726f6388 JA |
8793 | the evaluation of the conditional expression |
8794 | .IR expr . | |
cce855bc JA |
8795 | Each operator and operand must be a separate argument. |
8796 | Expressions are composed of the primaries described above under | |
8797 | .SM | |
8798 | .BR "CONDITIONAL EXPRESSIONS" . | |
3ffb039a CR |
8799 | \fBtest\fP does not accept any options, nor does it accept and ignore |
8800 | an argument of \fB\-\-\fP as signifying the end of options. | |
cce855bc JA |
8801 | .if t .sp 0.5 |
8802 | .if n .sp 1 | |
8803 | Expressions may be combined using the following operators, listed | |
8804 | in decreasing order of precedence. | |
641d8f00 | 8805 | The evaluation depends on the number of arguments; see below. |
726f6388 JA |
8806 | .RS |
8807 | .PD 0 | |
8808 | .TP | |
726f6388 JA |
8809 | .B ! \fIexpr\fP |
8810 | True if | |
8811 | .I expr | |
8812 | is false. | |
8813 | .TP | |
cce855bc JA |
8814 | .B ( \fIexpr\fP ) |
8815 | Returns the value of \fIexpr\fP. | |
8816 | This may be used to override the normal precedence of operators. | |
8817 | .TP | |
726f6388 JA |
8818 | \fIexpr1\fP \-\fBa\fP \fIexpr2\fP |
8819 | True if both | |
8820 | .I expr1 | |
cce855bc | 8821 | and |
726f6388 JA |
8822 | .I expr2 |
8823 | are true. | |
8824 | .TP | |
8825 | \fIexpr1\fP \-\fBo\fP \fIexpr2\fP | |
8826 | True if either | |
8827 | .I expr1 | |
cce855bc | 8828 | or |
726f6388 JA |
8829 | .I expr2 |
8830 | is true. | |
cce855bc JA |
8831 | .PD |
8832 | .PP | |
8833 | \fBtest\fP and \fB[\fP evaluate conditional | |
8834 | expressions using a set of rules based on the number of arguments. | |
8835 | .if t .sp 0.5 | |
8836 | .if n .sp 1 | |
8837 | .PD 0 | |
726f6388 | 8838 | .TP |
cce855bc JA |
8839 | 0 arguments |
8840 | The expression is false. | |
8841 | .TP | |
8842 | 1 argument | |
8843 | The expression is true if and only if the argument is not null. | |
8844 | .TP | |
8845 | 2 arguments | |
8846 | If the first argument is \fB!\fP, the expression is true if and | |
8847 | only if the second argument is null. | |
8848 | If the first argument is one of the unary conditional operators listed above | |
8849 | under | |
726f6388 | 8850 | .SM |
cce855bc JA |
8851 | .BR "CONDITIONAL EXPRESSIONS" , |
8852 | the expression is true if the unary test is true. | |
8853 | If the first argument is not a valid unary conditional operator, the expression | |
8854 | is false. | |
8855 | .TP | |
8856 | 3 arguments | |
8857 | If the second argument is one of the binary conditional operators listed above | |
8858 | under | |
8859 | .SM | |
8860 | .BR "CONDITIONAL EXPRESSIONS" , | |
8861 | the result of the expression is the result of the binary test using | |
8862 | the first and third arguments as operands. | |
641d8f00 CR |
8863 | The \fB\-a\fP and \fB\-o\fP operators are considered binary operators |
8864 | when there are three arguments. | |
cce855bc JA |
8865 | If the first argument is \fB!\fP, the value is the negation of |
8866 | the two-argument test using the second and third arguments. | |
8867 | If the first argument is exactly \fB(\fP and the third argument is | |
8868 | exactly \fB)\fP, the result is the one-argument test of the second | |
8869 | argument. | |
8870 | Otherwise, the expression is false. | |
cce855bc JA |
8871 | .TP |
8872 | 4 arguments | |
8873 | If the first argument is \fB!\fP, the result is the negation of | |
8874 | the three-argument expression composed of the remaining arguments. | |
8875 | Otherwise, the expression is parsed and evaluated according to | |
8876 | precedence using the rules listed above. | |
8877 | .TP | |
8878 | 5 or more arguments | |
8879 | The expression is parsed and evaluated according to precedence | |
8880 | using the rules listed above. | |
726f6388 | 8881 | .RE |
cce855bc | 8882 | .PD |
726f6388 JA |
8883 | .TP |
8884 | .B times | |
8885 | Print the accumulated user and system times for the shell and | |
8886 | for processes run from the shell. The return status is 0. | |
8887 | .TP | |
61deeb13 | 8888 | \fBtrap\fP [\fB\-lp\fP] [[\fIarg\fP] \fIsigspec\fP ...] |
726f6388 JA |
8889 | The command |
8890 | .I arg | |
8891 | is to be read and executed when the shell receives | |
8892 | signal(s) | |
8893 | .IR sigspec . | |
8894 | If | |
8895 | .I arg | |
61deeb13 | 8896 | is absent (and there is a single \fIsigspec\fP) or |
726f6388 | 8897 | .BR \- , |
61deeb13 CR |
8898 | each specified signal is |
8899 | reset to its original disposition (the value it had | |
d166f048 JA |
8900 | upon entrance to the shell). |
8901 | If | |
726f6388 | 8902 | .I arg |
d166f048 JA |
8903 | is the null string the signal specified by each |
8904 | .I sigspec | |
8905 | is ignored by the shell and by the commands it invokes. | |
ccc6cda3 JA |
8906 | If |
8907 | .I arg | |
bb70624e | 8908 | is not present and |
ccc6cda3 | 8909 | .B \-p |
bb70624e | 8910 | has been supplied, then the trap commands associated with each |
ccc6cda3 | 8911 | .I sigspec |
bb70624e JA |
8912 | are displayed. |
8913 | If no arguments are supplied or if only | |
ccc6cda3 JA |
8914 | .B \-p |
8915 | is given, | |
8916 | .B trap | |
61deeb13 | 8917 | prints the list of commands associated with each signal. |
d3a24ed2 CR |
8918 | The |
8919 | .B \-l | |
8920 | option causes the shell to print a list of signal names and | |
8921 | their corresponding numbers. | |
d166f048 | 8922 | Each |
726f6388 JA |
8923 | .I sigspec |
8924 | is either | |
d166f048 | 8925 | a signal name defined in <\fIsignal.h\fP>, or a signal number. |
61deeb13 | 8926 | Signal names are case insensitive and the SIG prefix is optional. |
4301bca7 CR |
8927 | .if t .sp 0.5 |
8928 | .if n .sp 1 | |
d166f048 | 8929 | If a |
726f6388 JA |
8930 | .I sigspec |
8931 | is | |
8932 | .SM | |
8933 | .B EXIT | |
8934 | (0) the command | |
8935 | .I arg | |
f73dda09 JA |
8936 | is executed on exit from the shell. |
8937 | If a | |
ccc6cda3 JA |
8938 | .I sigspec |
8939 | is | |
8940 | .SM | |
8941 | .BR DEBUG , | |
8942 | the command | |
8943 | .I arg | |
d3a24ed2 CR |
8944 | is executed before every \fIsimple command\fP, \fIfor\fP command, |
8945 | \fIcase\fP command, \fIselect\fP command, every arithmetic \fIfor\fP | |
8946 | command, and before the first command executes in a shell function (see | |
ccc6cda3 JA |
8947 | .SM |
8948 | .B SHELL GRAMMAR | |
8949 | above). | |
40b074c6 | 8950 | Refer to the description of the \fBextdebug\fP option to the |
d3a24ed2 | 8951 | \fBshopt\fP builtin for details of its effect on the \fBDEBUG\fP trap. |
f73dda09 JA |
8952 | If a |
8953 | .I sigspec | |
8954 | is | |
8955 | .SM | |
4301bca7 CR |
8956 | .BR RETURN , |
8957 | the command | |
8958 | .I arg | |
8959 | is executed each time a shell function or a script executed with the | |
8960 | \fB.\fP or \fBsource\fP builtins finishes executing. | |
8961 | .if t .sp 0.5 | |
8962 | .if n .sp 1 | |
8963 | If a | |
8964 | .I sigspec | |
8965 | is | |
8966 | .SM | |
f73dda09 JA |
8967 | .BR ERR , |
8968 | the command | |
8969 | .I arg | |
5e13499c CR |
8970 | is executed whenever a simple command has a non\-zero exit status, |
8971 | subject to the following conditions. | |
f73dda09 JA |
8972 | The |
8973 | .SM | |
d3a24ed2 CR |
8974 | .B ERR |
8975 | trap is not executed if the failed | |
8976 | command is part of the command list immediately following a | |
8977 | .B while | |
f73dda09 | 8978 | or |
d3a24ed2 CR |
8979 | .B until |
8980 | keyword, | |
8981 | part of the test in an | |
f73dda09 | 8982 | .I if |
9d85af6d | 8983 | statement, part of a command executed in a |
f73dda09 JA |
8984 | .B && |
8985 | or | |
8986 | .B \(bv\(bv | |
8987 | list, or if the command's return value is | |
8988 | being inverted via | |
8989 | .BR ! . | |
5e13499c | 8990 | These are the same conditions obeyed by the \fBerrexit\fP option. |
4301bca7 CR |
8991 | .if t .sp 0.5 |
8992 | .if n .sp 1 | |
726f6388 | 8993 | Signals ignored upon entry to the shell cannot be trapped or reset. |
d3ad40de | 8994 | Trapped signals that are not being ignored are reset to their original |
4301bca7 | 8995 | values in a subshell or subshell environment when one is created. |
d166f048 | 8996 | The return status is false if any |
ccc6cda3 JA |
8997 | .I sigspec |
8998 | is invalid; otherwise | |
726f6388 JA |
8999 | .B trap |
9000 | returns true. | |
9001 | .TP | |
7117c2d2 | 9002 | \fBtype\fP [\fB\-aftpP\fP] \fIname\fP [\fIname\fP ...] |
726f6388 JA |
9003 | With no options, |
9004 | indicate how each | |
9005 | .I name | |
9006 | would be interpreted if used as a command name. | |
9007 | If the | |
cce855bc JA |
9008 | .B \-t |
9009 | option is used, | |
726f6388 | 9010 | .B type |
ccc6cda3 | 9011 | prints a string which is one of |
726f6388 JA |
9012 | .IR alias , |
9013 | .IR keyword , | |
9014 | .IR function , | |
9015 | .IR builtin , | |
9016 | or | |
9017 | .I file | |
9018 | if | |
9019 | .I name | |
9020 | is an alias, shell reserved word, function, builtin, or disk file, | |
ccc6cda3 JA |
9021 | respectively. |
9022 | If the | |
9023 | .I name | |
9024 | is not found, then nothing is printed, and an exit status of false | |
9025 | is returned. | |
726f6388 | 9026 | If the |
cce855bc JA |
9027 | .B \-p |
9028 | option is used, | |
726f6388 JA |
9029 | .B type |
9030 | either returns the name of the disk file | |
9031 | that would be executed if | |
9032 | .I name | |
9033 | were specified as a command name, | |
28ef6c31 JA |
9034 | or nothing if |
9035 | .if t \f(CWtype -t name\fP | |
9036 | .if n ``type -t name'' | |
726f6388 JA |
9037 | would not return |
9038 | .IR file . | |
7117c2d2 JA |
9039 | The |
9040 | .B \-P | |
9041 | option forces a | |
9042 | .SM | |
9043 | .B PATH | |
9044 | search for each \fIname\fP, even if | |
9045 | .if t \f(CWtype -t name\fP | |
9046 | .if n ``type -t name'' | |
9047 | would not return | |
9048 | .IR file . | |
726f6388 | 9049 | If a command is hashed, |
cce855bc | 9050 | .B \-p |
7117c2d2 JA |
9051 | and |
9052 | .B \-P | |
9053 | print the hashed value, not necessarily the file that appears | |
726f6388 JA |
9054 | first in |
9055 | .SM | |
9056 | .BR PATH . | |
9057 | If the | |
cce855bc JA |
9058 | .B \-a |
9059 | option is used, | |
726f6388 JA |
9060 | .B type |
9061 | prints all of the places that contain | |
9062 | an executable named | |
9063 | .IR name . | |
9064 | This includes aliases and functions, | |
9065 | if and only if the | |
cce855bc JA |
9066 | .B \-p |
9067 | option is not also used. | |
726f6388 JA |
9068 | The table of hashed commands is not consulted |
9069 | when using | |
cce855bc | 9070 | .BR \-a . |
7117c2d2 JA |
9071 | The |
9072 | .B \-f | |
9073 | option suppresses shell function lookup, as with the \fBcommand\fP builtin. | |
726f6388 | 9074 | .B type |
6a8fd0ed CR |
9075 | returns true if all of the arguments are found, false if |
9076 | any are not found. | |
726f6388 | 9077 | .TP |
6fbe7620 | 9078 | \fBulimit\fP [\fB\-HSTabcdefilmnpqrstuvx\fP [\fIlimit\fP]] |
ccc6cda3 | 9079 | Provides control over the resources available to the shell and to |
f73dda09 | 9080 | processes started by it, on systems that allow such control. |
ccc6cda3 | 9081 | The \fB\-H\fP and \fB\-S\fP options specify that the hard or soft limit is |
79e6c7dc CR |
9082 | set for the given resource. |
9083 | A hard limit cannot be increased by a non-root user once it is set; | |
9084 | a soft limit may be increased up to the value of the hard limit. | |
ccc6cda3 JA |
9085 | If neither \fB\-H\fP nor \fB\-S\fP is specified, both the soft and hard |
9086 | limits are set. | |
f73dda09 JA |
9087 | The value of |
9088 | .I limit | |
9089 | can be a number in the unit specified for the resource | |
9090 | or one of the special values | |
9091 | .BR hard , | |
9092 | .BR soft , | |
9093 | or | |
9094 | .BR unlimited , | |
9095 | which stand for the current hard limit, the current soft limit, and | |
9096 | no limit, respectively. | |
ccc6cda3 | 9097 | If |
726f6388 JA |
9098 | .I limit |
9099 | is omitted, the current value of the soft limit of the resource is | |
ccc6cda3 JA |
9100 | printed, unless the \fB\-H\fP option is given. When more than one |
9101 | resource is specified, the limit name and unit are printed before the value. | |
726f6388 JA |
9102 | Other options are interpreted as follows: |
9103 | .RS | |
9104 | .PD 0 | |
9105 | .TP | |
9106 | .B \-a | |
ccc6cda3 | 9107 | All current limits are reported |
726f6388 | 9108 | .TP |
6fbe7620 CR |
9109 | .B \-b |
9110 | The maximum socket buffer size | |
9111 | .TP | |
726f6388 | 9112 | .B \-c |
ccc6cda3 | 9113 | The maximum size of core files created |
726f6388 JA |
9114 | .TP |
9115 | .B \-d | |
ccc6cda3 | 9116 | The maximum size of a process's data segment |
726f6388 | 9117 | .TP |
dc8fbaf9 CR |
9118 | .B \-e |
9119 | The maximum scheduling priority ("nice") | |
9120 | .TP | |
726f6388 | 9121 | .B \-f |
d3ad40de | 9122 | The maximum size of files written by the shell and its children |
726f6388 | 9123 | .TP |
af12dacd CR |
9124 | .B \-i |
9125 | The maximum number of pending signals | |
9126 | .TP | |
ccc6cda3 JA |
9127 | .B \-l |
9128 | The maximum size that may be locked into memory | |
726f6388 | 9129 | .TP |
ccc6cda3 | 9130 | .B \-m |
db31fb26 | 9131 | The maximum resident set size (many systems do not honor this limit) |
726f6388 | 9132 | .TP |
ccc6cda3 JA |
9133 | .B \-n |
9134 | The maximum number of open file descriptors (most systems do not | |
9135 | allow this value to be set) | |
726f6388 JA |
9136 | .TP |
9137 | .B \-p | |
ccc6cda3 | 9138 | The pipe size in 512-byte blocks (this may not be set) |
726f6388 | 9139 | .TP |
af12dacd CR |
9140 | .B \-q |
9141 | The maximum number of bytes in POSIX message queues | |
9142 | .TP | |
dc8fbaf9 CR |
9143 | .B \-r |
9144 | The maximum real-time scheduling priority | |
9145 | .TP | |
ccc6cda3 JA |
9146 | .B \-s |
9147 | The maximum stack size | |
9148 | .TP | |
9149 | .B \-t | |
9150 | The maximum amount of cpu time in seconds | |
726f6388 JA |
9151 | .TP |
9152 | .B \-u | |
ccc6cda3 | 9153 | The maximum number of processes available to a single user |
726f6388 JA |
9154 | .TP |
9155 | .B \-v | |
9156 | The maximum amount of virtual memory available to the shell | |
af12dacd CR |
9157 | .TP |
9158 | .B \-x | |
9159 | The maximum number of file locks | |
6fbe7620 CR |
9160 | .TP |
9161 | .B \-T | |
9162 | The maximum number of threads | |
726f6388 JA |
9163 | .PD |
9164 | .PP | |
ccc6cda3 | 9165 | If |
726f6388 JA |
9166 | .I limit |
9167 | is given, it is the new value of the specified resource (the | |
9168 | .B \-a | |
9169 | option is display only). | |
9170 | If no option is given, then | |
9171 | .B \-f | |
9172 | is assumed. Values are in 1024-byte increments, except for | |
9173 | .BR \-t , | |
9174 | which is in seconds, | |
9175 | .BR \-p , | |
9176 | which is in units of 512-byte blocks, | |
9177 | and | |
6fbe7620 CR |
9178 | .BR \-T , |
9179 | .BR \-b , | |
9180 | .BR \-n , | |
726f6388 JA |
9181 | and |
9182 | .BR \-u , | |
f73dda09 JA |
9183 | which are unscaled values. |
9184 | The return status is 0 unless an invalid option or argument is supplied, | |
9185 | or an error occurs while setting a new limit. | |
726f6388 JA |
9186 | .RE |
9187 | .TP | |
cce855bc | 9188 | \fBumask\fP [\fB\-p\fP] [\fB\-S\fP] [\fImode\fP] |
726f6388 JA |
9189 | The user file-creation mask is set to |
9190 | .IR mode . | |
9191 | If | |
9192 | .I mode | |
9193 | begins with a digit, it | |
9194 | is interpreted as an octal number; otherwise | |
9195 | it is interpreted as a symbolic mode mask similar | |
9196 | to that accepted by | |
9197 | .IR chmod (1). | |
9198 | If | |
9199 | .I mode | |
bb70624e | 9200 | is omitted, the current value of the mask is printed. |
ccc6cda3 | 9201 | The |
726f6388 JA |
9202 | .B \-S |
9203 | option causes the mask to be printed in symbolic form; the | |
9204 | default output is an octal number. | |
cce855bc JA |
9205 | If the |
9206 | .B \-p | |
9207 | option is supplied, and | |
9208 | .I mode | |
9209 | is omitted, the output is in a form that may be reused as input. | |
ccc6cda3 | 9210 | The return status is 0 if the mode was successfully changed or if |
726f6388 JA |
9211 | no \fImode\fP argument was supplied, and false otherwise. |
9212 | .TP | |
9213 | \fBunalias\fP [\-\fBa\fP] [\fIname\fP ...] | |
bb70624e | 9214 | Remove each \fIname\fP from the list of defined aliases. If |
726f6388 JA |
9215 | .B \-a |
9216 | is supplied, all alias definitions are removed. The return | |
9217 | value is true unless a supplied | |
9218 | .I name | |
9219 | is not a defined alias. | |
9220 | .TP | |
9221 | \fBunset\fP [\-\fBfv\fP] [\fIname\fP ...] | |
9222 | For each | |
9223 | .IR name , | |
ccc6cda3 JA |
9224 | remove the corresponding variable or function. |
9225 | If no options are supplied, or the | |
9226 | .B \-v | |
9227 | option is given, each | |
9228 | .I name | |
9229 | refers to a shell variable. | |
9230 | Read-only variables may not be unset. | |
9231 | If | |
726f6388 | 9232 | .B \-f |
f75912ae | 9233 | is specified, each |
ccc6cda3 JA |
9234 | .I name |
9235 | refers to a shell function, and the function definition | |
9236 | is removed. | |
9237 | Each unset variable or function is removed from the environment | |
9238 | passed to subsequent commands. | |
9239 | If any of | |
726f6388 JA |
9240 | .SM |
9241 | .BR RANDOM , | |
9242 | .SM | |
9243 | .BR SECONDS , | |
9244 | .SM | |
9245 | .BR LINENO , | |
ccc6cda3 JA |
9246 | .SM |
9247 | .BR HISTCMD , | |
bb70624e JA |
9248 | .SM |
9249 | .BR FUNCNAME , | |
9250 | .SM | |
9251 | .BR GROUPS , | |
726f6388 JA |
9252 | or |
9253 | .SM | |
ccc6cda3 | 9254 | .B DIRSTACK |
726f6388 JA |
9255 | are unset, they lose their special properties, even if they are |
9256 | subsequently reset. The exit status is true unless a | |
9257 | .I name | |
d3a24ed2 | 9258 | is readonly. |
726f6388 | 9259 | .TP |
d90269dd CR |
9260 | \fBwait\fP [\fIn ...\fP] |
9261 | Wait for each specified process and return its termination status. | |
9262 | Each | |
726f6388 JA |
9263 | .I n |
9264 | may be a process | |
9265 | ID or a job specification; if a job spec is given, all processes | |
9266 | in that job's pipeline are waited for. If | |
9267 | .I n | |
9268 | is not given, all currently active child processes | |
9269 | are waited for, and the return status is zero. If | |
9270 | .I n | |
ccc6cda3 | 9271 | specifies a non-existent process or job, the return status is |
726f6388 JA |
9272 | 127. Otherwise, the return status is the exit status of the last |
9273 | process or job waited for. | |
9274 | .\" bash_builtins | |
9275 | .if \n(zZ=1 .ig zZ | |
ccc6cda3 | 9276 | .SH "RESTRICTED SHELL" |
bb70624e JA |
9277 | .\" rbash.1 |
9278 | .zY | |
726f6388 | 9279 | .PP |
ccc6cda3 | 9280 | If |
726f6388 | 9281 | .B bash |
ccc6cda3 JA |
9282 | is started with the name |
9283 | .BR rbash , | |
9284 | or the | |
9285 | .B \-r | |
9286 | option is supplied at invocation, | |
9287 | the shell becomes restricted. | |
9288 | A restricted shell is used to | |
9289 | set up an environment more controlled than the standard shell. | |
9290 | It behaves identically to | |
9291 | .B bash | |
cce855bc | 9292 | with the exception that the following are disallowed or not performed: |
ccc6cda3 JA |
9293 | .IP \(bu |
9294 | changing directories with \fBcd\fP | |
9295 | .IP \(bu | |
9296 | setting or unsetting the values of | |
b72432fd JA |
9297 | .BR SHELL , |
9298 | .BR PATH , | |
9299 | .BR ENV , | |
ccc6cda3 | 9300 | or |
b72432fd | 9301 | .B BASH_ENV |
ccc6cda3 JA |
9302 | .IP \(bu |
9303 | specifying command names containing | |
9304 | .B / | |
9305 | .IP \(bu | |
9306 | specifying a file name containing a | |
9307 | .B / | |
9308 | as an argument to the | |
9309 | .B . | |
9310 | builtin command | |
9311 | .IP \(bu | |
bb70624e JA |
9312 | Specifying a filename containing a slash as an argument to the |
9313 | .B \-p | |
9314 | option to the | |
9315 | .B hash | |
9316 | builtin command | |
9317 | .IP \(bu | |
ccc6cda3 JA |
9318 | importing function definitions from the shell environment at startup |
9319 | .IP \(bu | |
cce855bc JA |
9320 | parsing the value of \fBSHELLOPTS\fP from the shell environment at startup |
9321 | .IP \(bu | |
ccc6cda3 JA |
9322 | redirecting output using the >, >|, <>, >&, &>, and >> redirection operators |
9323 | .IP \(bu | |
9324 | using the | |
9325 | .B exec | |
9326 | builtin command to replace the shell with another command | |
9327 | .IP \(bu | |
9328 | adding or deleting builtin commands with the | |
9329 | .B \-f | |
726f6388 | 9330 | and |
ccc6cda3 JA |
9331 | .B \-d |
9332 | options to the | |
9333 | .B enable | |
9334 | builtin command | |
9335 | .IP \(bu | |
7117c2d2 JA |
9336 | Using the \fBenable\fP builtin command to enable disabled shell builtins |
9337 | .IP \(bu | |
ccc6cda3 JA |
9338 | specifying the |
9339 | .B \-p | |
9340 | option to the | |
9341 | .B command | |
9342 | builtin command | |
9343 | .IP \(bu | |
9344 | turning off restricted mode with | |
cce855bc | 9345 | \fBset +r\fP or \fBset +o restricted\fP. |
726f6388 | 9346 | .PP |
ccc6cda3 JA |
9347 | These restrictions are enforced after any startup files are read. |
9348 | .PP | |
61deeb13 CR |
9349 | .ie \n(zY=1 When a command that is found to be a shell script is executed, |
9350 | .el \{ When a command that is found to be a shell script is executed | |
9351 | (see | |
ccc6cda3 JA |
9352 | .SM |
9353 | .B "COMMAND EXECUTION" | |
9354 | above), | |
61deeb13 | 9355 | \} |
ccc6cda3 JA |
9356 | .B rbash |
9357 | turns off any restrictions in the shell spawned to execute the | |
9358 | script. | |
bb70624e JA |
9359 | .\" end of rbash.1 |
9360 | .if \n(zY=1 .ig zY | |
726f6388 JA |
9361 | .SH "SEE ALSO" |
9362 | .PD 0 | |
9363 | .TP | |
bb70624e | 9364 | \fIBash Reference Manual\fP, Brian Fox and Chet Ramey |
726f6388 JA |
9365 | .TP |
9366 | \fIThe Gnu Readline Library\fP, Brian Fox and Chet Ramey | |
9367 | .TP | |
9368 | \fIThe Gnu History Library\fP, Brian Fox and Chet Ramey | |
9369 | .TP | |
726f6388 JA |
9370 | \fIPortable Operating System Interface (POSIX) Part 2: Shell and Utilities\fP, IEEE |
9371 | .TP | |
9372 | \fIsh\fP(1), \fIksh\fP(1), \fIcsh\fP(1) | |
9373 | .TP | |
9374 | \fIemacs\fP(1), \fIvi\fP(1) | |
9375 | .TP | |
9376 | \fIreadline\fP(3) | |
9377 | .PD | |
9378 | .SH FILES | |
9379 | .PD 0 | |
9380 | .TP | |
9381 | .FN /bin/bash | |
9382 | The \fBbash\fP executable | |
9383 | .TP | |
9384 | .FN /etc/profile | |
9385 | The systemwide initialization file, executed for login shells | |
9386 | .TP | |
9387 | .FN ~/.bash_profile | |
9388 | The personal initialization file, executed for login shells | |
9389 | .TP | |
9390 | .FN ~/.bashrc | |
9391 | The individual per-interactive-shell startup file | |
9392 | .TP | |
b72432fd JA |
9393 | .FN ~/.bash_logout |
9394 | The individual login shell cleanup file, executed when a login shell exits | |
9395 | .TP | |
726f6388 JA |
9396 | .FN ~/.inputrc |
9397 | Individual \fIreadline\fP initialization file | |
9398 | .PD | |
9399 | .SH AUTHORS | |
ccc6cda3 | 9400 | Brian Fox, Free Software Foundation |
726f6388 | 9401 | .br |
bb70624e | 9402 | bfox@gnu.org |
726f6388 JA |
9403 | .PP |
9404 | Chet Ramey, Case Western Reserve University | |
9405 | .br | |
db31fb26 | 9406 | chet.ramey@case.edu |
726f6388 JA |
9407 | .SH BUG REPORTS |
9408 | If you find a bug in | |
9409 | .B bash, | |
9410 | you should report it. But first, you should | |
9411 | make sure that it really is a bug, and that it appears in the latest | |
9412 | version of | |
d3a24ed2 CR |
9413 | .BR bash . |
9414 | The latest version is always available from | |
9415 | \fIftp://ftp.gnu.org/pub/bash/\fP. | |
726f6388 JA |
9416 | .PP |
9417 | Once you have determined that a bug actually exists, use the | |
9418 | .I bashbug | |
9419 | command to submit a bug report. | |
d166f048 | 9420 | If you have a fix, you are encouraged to mail that as well! |
726f6388 | 9421 | Suggestions and `philosophical' bug reports may be mailed |
cce855bc | 9422 | to \fIbug-bash@gnu.org\fP or posted to the Usenet |
726f6388 JA |
9423 | newsgroup |
9424 | .BR gnu.bash.bug . | |
9425 | .PP | |
9426 | ALL bug reports should include: | |
9427 | .PP | |
9428 | .PD 0 | |
9429 | .TP 20 | |
9430 | The version number of \fBbash\fR | |
9431 | .TP | |
9432 | The hardware and operating system | |
9433 | .TP | |
9434 | The compiler used to compile | |
9435 | .TP | |
9436 | A description of the bug behaviour | |
9437 | .TP | |
9438 | A short script or `recipe' which exercises the bug | |
9439 | .PD | |
9440 | .PP | |
9441 | .I bashbug | |
9442 | inserts the first three items automatically into the template | |
9443 | it provides for filing a bug report. | |
9444 | .PP | |
9445 | Comments and bug reports concerning | |
9446 | this manual page should be directed to | |
e225d5a9 | 9447 | .IR chet@po.cwru.edu . |
726f6388 JA |
9448 | .SH BUGS |
9449 | .PP | |
9450 | It's too big and too slow. | |
9451 | .PP | |
9452 | There are some subtle differences between | |
9453 | .B bash | |
9454 | and traditional versions of | |
9455 | .BR sh , | |
9456 | mostly because of the | |
9457 | .SM | |
9458 | .B POSIX | |
9459 | specification. | |
9460 | .PP | |
9461 | Aliases are confusing in some uses. | |
ccc6cda3 JA |
9462 | .PP |
9463 | Shell builtin commands and functions are not stoppable/restartable. | |
9464 | .PP | |
9465 | Compound commands and command sequences of the form `a ; b ; c' | |
9466 | are not handled gracefully when process suspension is attempted. | |
9467 | When a process is stopped, the shell immediately executes the next | |
9468 | command in the sequence. | |
9469 | It suffices to place the sequence of commands between | |
9470 | parentheses to force it into a subshell, which may be stopped as | |
9471 | a unit. | |
9472 | .PP | |
ccc6cda3 | 9473 | Array variables may not (yet) be exported. |
09767ff0 CR |
9474 | .PP |
9475 | There may be only one active coprocess at a time. | |
726f6388 | 9476 | .zZ |
bb70624e | 9477 | .zY |