]>
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 | .\" |
53ac45a3 | 8 | .\" Last Change: Fri Sep 14 13:44:37 EDT 2007 |
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 |
53ac45a3 | 13 | .TH BASH 1 "2007 September 14" "GNU Bash-3.2" |
726f6388 JA |
14 | .\" |
15 | .\" There's some problem with having a `@' | |
16 | .\" in a tagged paragraph with the BSD man macros. | |
17 | .\" It has to do with `@' appearing in the }1 macro. | |
18 | .\" This is a problem on 4.3 BSD and Ultrix, but Sun | |
19 | .\" appears to have fixed it. | |
20 | .\" If you're seeing the characters | |
21 | .\" `@u-3p' appearing before the lines reading | |
22 | .\" `possible-hostname-completions | |
23 | .\" and `complete-hostname' down in READLINE, | |
24 | .\" then uncomment this redefinition. | |
25 | .\" | |
26 | .de }1 | |
27 | .ds ]X \&\\*(]B\\ | |
28 | .nr )E 0 | |
29 | .if !"\\$1"" .nr )I \\$1n | |
30 | .}f | |
31 | .ll \\n(LLu | |
32 | .in \\n()Ru+\\n(INu+\\n()Iu | |
33 | .ti \\n(INu | |
34 | .ie !\\n()Iu+\\n()Ru-\w\a\\*(]X\au-3p \{\\*(]X | |
35 | .br\} | |
36 | .el \\*(]X\h\a|\\n()Iu+\\n()Ru\a\c | |
37 | .}f | |
38 | .. | |
39 | .\" | |
40 | .\" File Name macro. This used to be `.PN', for Path Name, | |
41 | .\" but Sun doesn't seem to like that very much. | |
42 | .\" | |
43 | .de FN | |
44 | \fI\|\\$1\|\fP | |
45 | .. | |
46 | .SH NAME | |
ccc6cda3 | 47 | bash \- GNU Bourne-Again SHell |
726f6388 JA |
48 | .SH SYNOPSIS |
49 | .B bash | |
50 | [options] | |
51 | [file] | |
52 | .SH COPYRIGHT | |
d3ad40de CR |
53 | .if n Bash is Copyright (C) 1989-2007 by the Free Software Foundation, Inc. |
54 | .if t Bash is Copyright \(co 1989-2007 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 | |
412 | attempts to determine when it is being run by the remote shell | |
413 | daemon, usually \fIrshd\fP. | |
414 | If | |
415 | .B bash | |
416 | determines it is being run by \fIrshd\fP, it reads and executes | |
417 | commands from \fI~/.bashrc\fP, if that file exists and is readable. | |
418 | It will not do this if invoked as \fBsh\fP. | |
419 | The | |
420 | .B \-\-norc | |
421 | option may be used to inhibit this behavior, and the | |
422 | .B \-\-rcfile | |
423 | option may be used to force another file to be read, but | |
424 | \fIrshd\fP does not generally invoke the shell with those options | |
425 | or allow them to be specified. | |
b72432fd JA |
426 | .PP |
427 | If the shell is started with the effective user (group) id not equal to the | |
428 | real user (group) id, and the \fB\-p\fP option is not supplied, no startup | |
f73dda09 JA |
429 | files are read, shell functions are not inherited from the environment, the |
430 | .SM | |
431 | .B SHELLOPTS | |
432 | variable, if it appears in the environment, is ignored, | |
b72432fd JA |
433 | and the effective user id is set to the real user id. |
434 | If the \fB\-p\fP option is supplied at invocation, the startup behavior is | |
435 | the same, but the effective user id is not reset. | |
726f6388 | 436 | .SH DEFINITIONS |
ccc6cda3 JA |
437 | .PP |
438 | The following definitions are used throughout the rest of this | |
439 | document. | |
726f6388 JA |
440 | .PD 0 |
441 | .TP | |
442 | .B blank | |
443 | A space or tab. | |
444 | .TP | |
445 | .B word | |
446 | A sequence of characters considered as a single unit by the shell. | |
447 | Also known as a | |
448 | .BR token . | |
449 | .TP | |
450 | .B name | |
451 | A | |
452 | .I word | |
453 | consisting only of alphanumeric characters and underscores, and | |
454 | beginning with an alphabetic character or an underscore. Also | |
455 | referred to as an | |
456 | .BR identifier . | |
457 | .TP | |
458 | .B metacharacter | |
459 | A character that, when unquoted, separates words. One of the following: | |
460 | .br | |
461 | .RS | |
462 | .PP | |
463 | .if t \fB| & ; ( ) < > space tab\fP | |
464 | .if n \fB| & ; ( ) < > space tab\fP | |
465 | .RE | |
466 | .PP | |
467 | .TP | |
468 | .B control operator | |
469 | A \fItoken\fP that performs a control function. It is one of the following | |
470 | symbols: | |
471 | .RS | |
472 | .PP | |
ccc6cda3 | 473 | .if t \fB\(bv\(bv & && ; ;; ( ) | <newline>\fP |
726f6388 JA |
474 | .if n \fB|| & && ; ;; ( ) | <newline>\fP |
475 | .RE | |
476 | .PD | |
477 | .SH "RESERVED WORDS" | |
478 | \fIReserved words\fP are words that have a special meaning to the shell. | |
479 | The following words are recognized as reserved when unquoted and either | |
480 | the first word of a simple command (see | |
481 | .SM | |
482 | .B SHELL GRAMMAR | |
483 | below) or the third word of a | |
484 | .B case | |
485 | or | |
486 | .B for | |
487 | command: | |
488 | .if t .RS | |
489 | .PP | |
490 | .B | |
cce855bc JA |
491 | .if n ! case do done elif else esac fi for function if in select then until while { } time [[ ]] |
492 | .if t ! case do done elif else esac fi for function if in select then until while { } time [[ ]] | |
726f6388 | 493 | .if t .RE |
726f6388 JA |
494 | .SH "SHELL GRAMMAR" |
495 | .SS Simple Commands | |
496 | .PP | |
497 | A \fIsimple command\fP is a sequence of optional variable assignments | |
ccc6cda3 | 498 | followed by \fBblank\fP-separated words and redirections, and |
726f6388 | 499 | terminated by a \fIcontrol operator\fP. The first word |
f73dda09 JA |
500 | specifies the command to be executed, and is passed as argument zero. |
501 | The remaining words are passed as arguments to the invoked command. | |
726f6388 JA |
502 | .PP |
503 | The return value of a \fIsimple command\fP is its exit status, or | |
504 | 128+\fIn\^\fP if the command is terminated by signal | |
505 | .IR n . | |
506 | .SS Pipelines | |
507 | .PP | |
508 | A \fIpipeline\fP is a sequence of one or more commands separated by | |
509 | the character | |
510 | .BR | . | |
511 | The format for a pipeline is: | |
512 | .RS | |
513 | .PP | |
ccc6cda3 | 514 | [\fBtime\fP [\fB\-p\fP]] [ ! ] \fIcommand\fP [ \fB|\fP \fIcommand2\fP ... ] |
726f6388 JA |
515 | .RE |
516 | .PP | |
517 | The standard output of | |
518 | .I command | |
f73dda09 | 519 | is connected via a pipe to the standard input of |
726f6388 JA |
520 | .IR command2 . |
521 | This connection is performed before any redirections specified by the | |
522 | command (see | |
523 | .SM | |
524 | .B REDIRECTION | |
525 | below). | |
526 | .PP | |
d3a24ed2 CR |
527 | The return status of a pipeline is the exit status of the last |
528 | command, unless the \fBpipefail\fP option is enabled. | |
529 | If \fBpipefail\fP is enabled, the pipeline's return status is the | |
530 | value of the last (rightmost) command to exit with a non-zero status, | |
531 | or zero if all commands exit successfully. | |
726f6388 JA |
532 | If the reserved word |
533 | .B ! | |
d3a24ed2 CR |
534 | precedes a pipeline, the exit status of that pipeline is the logical |
535 | negation of the exit status as described above. | |
ccc6cda3 | 536 | The shell waits for all commands in the pipeline to |
726f6388 JA |
537 | terminate before returning a value. |
538 | .PP | |
ccc6cda3 JA |
539 | If the |
540 | .B time | |
541 | reserved word precedes a pipeline, the elapsed as well as user and | |
542 | system time consumed by its execution are reported when the pipeline | |
543 | terminates. | |
544 | The \fB\-p\fP option changes the output format to that specified by POSIX. | |
545 | The | |
546 | .SM | |
547 | .B TIMEFORMAT | |
548 | variable may be set to a format string that specifies how the timing | |
549 | information should be displayed; see the description of | |
550 | .SM | |
551 | .B TIMEFORMAT | |
552 | under | |
553 | .B "Shell Variables" | |
554 | below. | |
555 | .PP | |
726f6388 JA |
556 | Each command in a pipeline is executed as a separate process (i.e., in a |
557 | subshell). | |
558 | .SS Lists | |
559 | .PP | |
560 | A \fIlist\fP is a sequence of one or more pipelines separated by one | |
561 | of the operators | |
562 | .BR ; , | |
563 | .BR & , | |
564 | .BR && , | |
565 | or | |
ccc6cda3 JA |
566 | .BR \(bv\(bv , |
567 | and optionally terminated by one of | |
726f6388 JA |
568 | .BR ; , |
569 | .BR & , | |
570 | or | |
571 | .BR <newline> . | |
572 | .PP | |
573 | Of these list operators, | |
574 | .B && | |
575 | and | |
ccc6cda3 | 576 | .B \(bv\(bv |
726f6388 JA |
577 | have equal precedence, followed by |
578 | .B ; | |
579 | and | |
b1a26c01 | 580 | .BR & , |
726f6388 JA |
581 | which have equal precedence. |
582 | .PP | |
7117c2d2 JA |
583 | A sequence of one or more newlines may appear in a \fIlist\fP instead |
584 | of a semicolon to delimit commands. | |
585 | .PP | |
726f6388 JA |
586 | If a command is terminated by the control operator |
587 | .BR & , | |
588 | the shell executes the command in the \fIbackground\fP | |
589 | in a subshell. The shell does not wait for the command to | |
590 | finish, and the return status is 0. Commands separated by a | |
591 | .B ; | |
592 | are executed sequentially; the shell waits for each | |
593 | command to terminate in turn. The return status is the | |
594 | exit status of the last command executed. | |
595 | .PP | |
596 | The control operators | |
597 | .B && | |
598 | and | |
ccc6cda3 | 599 | .B \(bv\(bv |
726f6388 JA |
600 | denote AND lists and OR lists, respectively. |
601 | An AND list has the form | |
602 | .RS | |
603 | .PP | |
bb70624e | 604 | \fIcommand1\fP \fB&&\fP \fIcommand2\fP |
726f6388 JA |
605 | .RE |
606 | .PP | |
607 | .I command2 | |
608 | is executed if, and only if, | |
bb70624e | 609 | .I command1 |
726f6388 JA |
610 | returns an exit status of zero. |
611 | .PP | |
612 | An OR list has the form | |
613 | .RS | |
614 | .PP | |
bb70624e | 615 | \fIcommand1\fP \fB\(bv\(bv\fP \fIcommand2\fP |
726f6388 JA |
616 | .PP |
617 | .RE | |
618 | .PP | |
619 | .I command2 | |
620 | is executed if and only if | |
bb70624e | 621 | .I command1 |
ccc6cda3 | 622 | returns a non-zero exit status. The return status of |
726f6388 JA |
623 | AND and OR lists is the exit status of the last command |
624 | executed in the list. | |
625 | .SS Compound Commands | |
626 | .PP | |
627 | A \fIcompound command\fP is one of the following: | |
628 | .TP | |
629 | (\fIlist\fP) | |
d3a24ed2 CR |
630 | \fIlist\fP is executed in a subshell environment (see |
631 | .SM | |
632 | \fBCOMMAND EXECUTION ENVIRONMENT\fP | |
633 | below). | |
634 | Variable assignments and builtin | |
726f6388 JA |
635 | commands that affect the shell's environment do not remain in effect |
636 | after the command completes. The return status is the exit status of | |
637 | \fIlist\fP. | |
638 | .TP | |
639 | { \fIlist\fP; } | |
ccc6cda3 JA |
640 | \fIlist\fP is simply executed in the current shell environment. |
641 | \fIlist\fP must be terminated with a newline or semicolon. | |
642 | This is known as a \fIgroup command\fP. | |
643 | The return status is the exit status of | |
726f6388 | 644 | \fIlist\fP. |
d3a24ed2 | 645 | Note that unlike the metacharacters \fB(\fP and \fB)\fP, \fB{\fP and |
f73dda09 JA |
646 | \fB}\fP are \fIreserved words\fP and must occur where a reserved |
647 | word is permitted to be recognized. Since they do not cause a word | |
641d8f00 CR |
648 | break, they must be separated from \fIlist\fP by whitespace or another |
649 | shell metacharacter. | |
726f6388 | 650 | .TP |
ccc6cda3 JA |
651 | ((\fIexpression\fP)) |
652 | The \fIexpression\fP is evaluated according to the rules described | |
653 | below under | |
654 | .SM | |
655 | .BR "ARITHMETIC EVALUATION" . | |
656 | If the value of the expression is non-zero, the return status is 0; | |
657 | otherwise the return status is 1. This is exactly equivalent to | |
658 | \fBlet "\fIexpression\fP"\fR. | |
659 | .TP | |
cce855bc JA |
660 | \fB[[\fP \fIexpression\fP \fB]]\fP |
661 | Return a status of 0 or 1 depending on the evaluation of | |
662 | the conditional expression \fIexpression\fP. | |
663 | Expressions are composed of the primaries described below under | |
664 | .SM | |
665 | .BR "CONDITIONAL EXPRESSIONS" . | |
666 | Word splitting and pathname expansion are not performed on the words | |
667 | between the \fB[[\fP and \fB]]\fP; tilde expansion, parameter and | |
668 | variable expansion, arithmetic expansion, command substitution, process | |
669 | substitution, and quote removal are performed. | |
d3a24ed2 CR |
670 | Conditional operators such as \fB\-f\fP must be unquoted to be recognized |
671 | as primaries. | |
cce855bc JA |
672 | .if t .sp 0.5 |
673 | .if n .sp 1 | |
674 | When the \fB==\fP and \fB!=\fP operators are used, the string to the | |
675 | right of the operator is considered a pattern and matched according | |
676 | to the rules described below under \fBPattern Matching\fP. | |
2206f89a CR |
677 | If the shell option |
678 | .B nocasematch | |
679 | is enabled, the match is performed without regard to the case | |
680 | of alphabetic characters. | |
dc8fbaf9 CR |
681 | The return value is 0 if the string matches (\fB==\fP) or does not match |
682 | (\fB!=\fP) the pattern, and 1 otherwise. | |
cce855bc JA |
683 | Any part of the pattern may be quoted to force it to be matched as a |
684 | string. | |
685 | .if t .sp 0.5 | |
686 | .if n .sp 1 | |
d3a24ed2 CR |
687 | An additional binary operator, \fB=~\fP, is available, with the same |
688 | precedence as \fB==\fP and \fB!=\fP. | |
689 | When it is used, the string to the right of the operator is considered | |
690 | an extended regular expression and matched accordingly (as in \fIregex\fP(3)). | |
d7f49990 CR |
691 | The return value is 0 if the string matches |
692 | the pattern, and 1 otherwise. | |
d3a24ed2 CR |
693 | If the regular expression is syntactically incorrect, the conditional |
694 | expression's return value is 2. | |
695 | If the shell option | |
2206f89a | 696 | .B nocasematch |
d3a24ed2 CR |
697 | is enabled, the match is performed without regard to the case |
698 | of alphabetic characters. | |
3745eee9 CR |
699 | Any part of the pattern may be quoted to force it to be matched as a |
700 | string. | |
d3a24ed2 CR |
701 | Substrings matched by parenthesized subexpressions within the regular |
702 | expression are saved in the array variable \fBBASH_REMATCH\fP. | |
703 | The element of \fBBASH_REMATCH\fP with index 0 is the portion of the string | |
704 | matching the entire regular expression. | |
705 | The element of \fBBASH_REMATCH\fP with index \fIn\fP is the portion of the | |
706 | string matching the \fIn\fPth parenthesized subexpression. | |
707 | .if t .sp 0.5 | |
708 | .if n .sp 1 | |
cce855bc JA |
709 | Expressions may be combined using the following operators, listed |
710 | in decreasing order of precedence: | |
711 | .if t .sp 0.5 | |
712 | .if n .sp 1 | |
713 | .RS | |
714 | .PD 0 | |
715 | .TP | |
716 | .B ( \fIexpression\fP ) | |
717 | Returns the value of \fIexpression\fP. | |
718 | This may be used to override the normal precedence of operators. | |
719 | .TP | |
720 | .B ! \fIexpression\fP | |
721 | True if | |
722 | .I expression | |
723 | is false. | |
724 | .TP | |
725 | \fIexpression1\fP \fB&&\fP \fIexpression2\fP | |
726 | True if both | |
727 | .I expression1 | |
728 | and | |
729 | .I expression2 | |
730 | are true. | |
731 | .TP | |
732 | .if t \fIexpression1\fP \fB\(bv\(bv\fP \fIexpression2\fP | |
733 | .if n \fIexpression1\fP \fB||\fP \fIexpression2\fP | |
734 | True if either | |
735 | .I expression1 | |
736 | or | |
737 | .I expression2 | |
738 | is true. | |
739 | .PD | |
cce855bc JA |
740 | .LP |
741 | The \fB&&\fP and | |
742 | .if t \fB\(bv\(bv\fP | |
743 | .if n \fB||\fP | |
7117c2d2 | 744 | operators do not evaluate \fIexpression2\fP if the value of |
cce855bc JA |
745 | \fIexpression1\fP is sufficient to determine the return value of |
746 | the entire conditional expression. | |
f73dda09 | 747 | .RE |
cce855bc | 748 | .TP |
b72432fd | 749 | \fBfor\fP \fIname\fP [ \fBin\fP \fIword\fP ] ; \fBdo\fP \fIlist\fP ; \fBdone\fP |
726f6388 | 750 | The list of words following \fBin\fP is expanded, generating a list |
bb70624e JA |
751 | of items. |
752 | The variable \fIname\fP is set to each element of this list | |
753 | in turn, and \fIlist\fP is executed each time. | |
754 | If the \fBin\fP \fIword\fP is omitted, the \fBfor\fP command executes | |
755 | \fIlist\fP once for each positional parameter that is set (see | |
726f6388 JA |
756 | .SM |
757 | .B PARAMETERS | |
758 | below). | |
cce855bc JA |
759 | The return status is the exit status of the last command that executes. |
760 | If the expansion of the items following \fBin\fP results in an empty | |
761 | list, no commands are executed, and the return status is 0. | |
726f6388 | 762 | .TP |
bb70624e JA |
763 | \fBfor\fP (( \fIexpr1\fP ; \fIexpr2\fP ; \fIexpr3\fP )) ; \fBdo\fP \fIlist\fP ; \fBdone\fP |
764 | First, the arithmetic expression \fIexpr1\fP is evaluated according | |
765 | to the rules described below under | |
766 | .SM | |
767 | .BR "ARITHMETIC EVALUATION" . | |
768 | The arithmetic expression \fIexpr2\fP is then evaluated repeatedly | |
769 | until it evaluates to zero. | |
770 | Each time \fIexpr2\fP evaluates to a non-zero value, \fIlist\fP is | |
771 | executed and the arithmetic expression \fIexpr3\fP is evaluated. | |
772 | If any expression is omitted, it behaves as if it evaluates to 1. | |
773 | The return value is the exit status of the last command in \fIlist\fP | |
774 | that is executed, or false if any of the expressions is invalid. | |
775 | .TP | |
b72432fd | 776 | \fBselect\fP \fIname\fP [ \fBin\fP \fIword\fP ] ; \fBdo\fP \fIlist\fP ; \fBdone\fP |
726f6388 JA |
777 | The list of words following \fBin\fP is expanded, generating a list |
778 | of items. The set of expanded words is printed on the standard | |
779 | error, each preceded by a number. If the \fBin\fP | |
780 | \fIword\fP is omitted, the positional parameters are printed (see | |
781 | .SM | |
782 | .B PARAMETERS | |
783 | below). The | |
784 | .B PS3 | |
785 | prompt is then displayed and a line read from the standard input. | |
ccc6cda3 | 786 | If the line consists of a number corresponding to one of |
726f6388 JA |
787 | the displayed words, then the value of |
788 | .I name | |
789 | is set to that word. If the line is empty, the words and prompt | |
790 | are displayed again. If EOF is read, the command completes. Any | |
791 | other value read causes | |
792 | .I name | |
793 | to be set to null. The line read is saved in the variable | |
794 | .BR REPLY . | |
795 | The | |
796 | .I list | |
797 | is executed after each selection until a | |
798 | .B break | |
726f6388 JA |
799 | command is executed. |
800 | The exit status of | |
801 | .B select | |
802 | is the exit status of the last command executed in | |
803 | .IR list , | |
804 | or zero if no commands were executed. | |
805 | .TP | |
bb70624e | 806 | \fBcase\fP \fIword\fP \fBin\fP [ [(] \fIpattern\fP [ \fB|\fP \fIpattern\fP ] \ |
726f6388 JA |
807 | ... ) \fIlist\fP ;; ] ... \fBesac\fP |
808 | A \fBcase\fP command first expands \fIword\fP, and tries to match | |
809 | it against each \fIpattern\fP in turn, using the same matching rules | |
810 | as for pathname expansion (see | |
811 | .B Pathname Expansion | |
2206f89a | 812 | below). |
dc8fbaf9 | 813 | The \fIword\fP is expanded using tilde |
d3ad40de | 814 | expansion, parameter and variable expansion, arithmetic substitution, |
dc8fbaf9 CR |
815 | command substitution, process substitution and quote removal. |
816 | Each \fIpattern\fP examined is expanded using tilde | |
d3ad40de | 817 | expansion, parameter and variable expansion, arithmetic substitution, |
dc8fbaf9 | 818 | command substitution, and process substitution. |
2206f89a CR |
819 | If the shell option |
820 | .B nocasematch | |
821 | is enabled, the match is performed without regard to the case | |
822 | of alphabetic characters. | |
823 | When a match is found, the | |
726f6388 JA |
824 | corresponding \fIlist\fP is executed. After the first match, no |
825 | subsequent matches are attempted. The exit status is zero if no | |
ccc6cda3 | 826 | pattern matches. Otherwise, it is the exit status of the |
726f6388 JA |
827 | last command executed in \fIlist\fP. |
828 | .TP | |
ccc6cda3 JA |
829 | \fBif\fP \fIlist\fP; \fBthen\fP \fIlist;\fP \ |
830 | [ \fBelif\fP \fIlist\fP; \fBthen\fP \fIlist\fP; ] ... \ | |
831 | [ \fBelse\fP \fIlist\fP; ] \fBfi\fP | |
726f6388 JA |
832 | The |
833 | .B if | |
834 | .I list | |
835 | is executed. If its exit status is zero, the | |
836 | \fBthen\fP \fIlist\fP is executed. Otherwise, each \fBelif\fP | |
837 | \fIlist\fP is executed in turn, and if its exit status is zero, | |
838 | the corresponding \fBthen\fP \fIlist\fP is executed and the | |
839 | command completes. Otherwise, the \fBelse\fP \fIlist\fP is | |
840 | executed, if present. The exit status is the exit status of the | |
841 | last command executed, or zero if no condition tested true. | |
842 | .TP | |
ccc6cda3 | 843 | \fBwhile\fP \fIlist\fP; \fBdo\fP \fIlist\fP; \fBdone\fP |
7117c2d2 | 844 | .PD 0 |
726f6388 | 845 | .TP |
ccc6cda3 | 846 | \fBuntil\fP \fIlist\fP; \fBdo\fP \fIlist\fP; \fBdone\fP |
726f6388 JA |
847 | .PD |
848 | The \fBwhile\fP command continuously executes the \fBdo\fP | |
849 | \fIlist\fP as long as the last command in \fIlist\fP returns | |
850 | an exit status of zero. The \fBuntil\fP command is identical | |
851 | to the \fBwhile\fP command, except that the test is negated; | |
852 | the | |
853 | .B do | |
854 | .I list | |
855 | is executed as long as the last command in | |
856 | .I list | |
ccc6cda3 | 857 | returns a non-zero exit status. |
726f6388 JA |
858 | The exit status of the \fBwhile\fP and \fBuntil\fP commands |
859 | is the exit status | |
860 | of the last \fBdo\fP \fIlist\fP command executed, or zero if | |
861 | none was executed. | |
d3a24ed2 CR |
862 | .SS Shell Function Definitions |
863 | .PP | |
864 | A shell function is an object that is called like a simple command and | |
865 | executes a compound command with a new set of positional parameters. | |
866 | Shell functions are declared as follows: | |
867 | .TP | |
868 | [ \fBfunction\fP ] \fIname\fP () \fIcompound\-command\fP [\fIredirection\fP] | |
869 | This defines a function named \fIname\fP. | |
870 | The reserved word \fBfunction\fP is optional. | |
871 | If the \fBfunction\fP reserved word is supplied, the parentheses are optional. | |
872 | The \fIbody\fP of the function is the compound command | |
873 | .I compound\-command | |
874 | (see \fBCompound Commands\fP above). | |
875 | That command is usually a \fIlist\fP of commands between { and }, but | |
876 | may be any command listed under \fBCompound Commands\fP above. | |
877 | \fIcompound\-command\fP is executed whenever \fIname\fP is specified as the | |
878 | name of a simple command. | |
879 | Any redirections (see | |
880 | .SM | |
881 | .B REDIRECTION | |
882 | below) specified when a function is defined are performed | |
883 | when the function is executed. | |
884 | The exit status of a function definition is zero unless a syntax error | |
885 | occurs or a readonly function with the same name already exists. | |
886 | When executed, the exit status of a function is the exit status of the | |
887 | last command executed in the body. (See | |
726f6388 JA |
888 | .SM |
889 | .B FUNCTIONS | |
890 | below.) | |
891 | .SH COMMENTS | |
ccc6cda3 JA |
892 | In a non-interactive shell, or an interactive shell in which the |
893 | .B interactive_comments | |
894 | option to the | |
895 | .B shopt | |
896 | builtin is enabled (see | |
897 | .SM | |
898 | .B "SHELL BUILTIN COMMANDS" | |
899 | below), a word beginning with | |
726f6388 JA |
900 | .B # |
901 | causes that word and all remaining characters on that line to | |
902 | be ignored. An interactive shell without the | |
ccc6cda3 | 903 | .B interactive_comments |
ccc6cda3 JA |
904 | option enabled does not allow comments. The |
905 | .B interactive_comments | |
906 | option is on by default in interactive shells. | |
726f6388 JA |
907 | .SH QUOTING |
908 | \fIQuoting\fP is used to remove the special meaning of certain | |
909 | characters or words to the shell. Quoting can be used to | |
910 | disable special treatment for special characters, to prevent | |
911 | reserved words from being recognized as such, and to prevent | |
912 | parameter expansion. | |
913 | .PP | |
914 | Each of the \fImetacharacters\fP listed above under | |
915 | .SM | |
916 | .B DEFINITIONS | |
bb70624e JA |
917 | has special meaning to the shell and must be quoted if it is to |
918 | represent itself. | |
919 | .PP | |
5c96a638 CR |
920 | When the command history expansion facilities are being used |
921 | (see | |
922 | .SM | |
923 | .B HISTORY EXPANSION | |
924 | below), the | |
bb70624e JA |
925 | \fIhistory expansion\fP character, usually \fB!\fP, must be quoted |
926 | to prevent history expansion. | |
927 | .PP | |
928 | There are three quoting mechanisms: the | |
726f6388 JA |
929 | .IR "escape character" , |
930 | single quotes, and double quotes. | |
931 | .PP | |
932 | A non-quoted backslash (\fB\e\fP) is the | |
933 | .IR "escape character" . | |
934 | It preserves the literal value of the next character that follows, | |
935 | with the exception of <newline>. If a \fB\e\fP<newline> pair | |
cce855bc JA |
936 | appears, and the backslash is not itself quoted, the \fB\e\fP<newline> |
937 | is treated as a line continuation (that is, it is removed from the | |
938 | input stream and effectively ignored). | |
726f6388 JA |
939 | .PP |
940 | Enclosing characters in single quotes preserves the literal value | |
941 | of each character within the quotes. A single quote may not occur | |
942 | between single quotes, even when preceded by a backslash. | |
943 | .PP | |
944 | Enclosing characters in double quotes preserves the literal value | |
945 | of all characters within the quotes, with the exception of | |
946 | .BR $ , | |
3d4e09aa | 947 | .BR \` , |
5c96a638 CR |
948 | .BR \e , |
949 | and, when history expansion is enabled, | |
950 | .BR ! . | |
726f6388 JA |
951 | The characters |
952 | .B $ | |
953 | and | |
3d4e09aa | 954 | .B \` |
726f6388 JA |
955 | retain their special meaning within double quotes. The backslash |
956 | retains its special meaning only when followed by one of the following | |
957 | characters: | |
958 | .BR $ , | |
3d4e09aa | 959 | .BR \` , |
726f6388 JA |
960 | \^\fB"\fP\^, |
961 | .BR \e , | |
962 | or | |
963 | .BR <newline> . | |
964 | A double quote may be quoted within double quotes by preceding it with | |
965 | a backslash. | |
5c96a638 CR |
966 | If enabled, history expansion will be performed unless an |
967 | .B ! | |
968 | appearing in double quotes is escaped using a backslash. | |
969 | The backslash preceding the | |
970 | .B ! | |
971 | is not removed. | |
726f6388 JA |
972 | .PP |
973 | The special parameters | |
974 | .B * | |
975 | and | |
976 | .B @ | |
977 | have special meaning when in double | |
978 | quotes (see | |
979 | .SM | |
980 | .B PARAMETERS | |
981 | below). | |
ccc6cda3 | 982 | .PP |
20587658 | 983 | Words of the form \fB$\fP\(aq\fIstring\fP\(aq are treated specially. The |
ccc6cda3 | 984 | word expands to \fIstring\fP, with backslash-escaped characters replaced |
f75912ae | 985 | as specified by the ANSI C standard. Backslash escape sequences, if |
ccc6cda3 JA |
986 | present, are decoded as follows: |
987 | .RS | |
988 | .PD 0 | |
989 | .TP | |
990 | .B \ea | |
991 | alert (bell) | |
992 | .TP | |
993 | .B \eb | |
994 | backspace | |
995 | .TP | |
996 | .B \ee | |
997 | an escape character | |
998 | .TP | |
999 | .B \ef | |
1000 | form feed | |
1001 | .TP | |
1002 | .B \en | |
1003 | new line | |
1004 | .TP | |
1005 | .B \er | |
1006 | carriage return | |
1007 | .TP | |
1008 | .B \et | |
1009 | horizontal tab | |
1010 | .TP | |
1011 | .B \ev | |
1012 | vertical tab | |
1013 | .TP | |
1014 | .B \e\e | |
1015 | backslash | |
bb70624e | 1016 | .TP |
20587658 | 1017 | .B \e\(aq |
bb70624e | 1018 | single quote |
ccc6cda3 JA |
1019 | .TP |
1020 | .B \e\fInnn\fP | |
f73dda09 | 1021 | the eight-bit character whose value is the octal value \fInnn\fP |
cce855bc JA |
1022 | (one to three digits) |
1023 | .TP | |
f73dda09 JA |
1024 | .B \ex\fIHH\fP |
1025 | the eight-bit character whose value is the hexadecimal value \fIHH\fP | |
1026 | (one or two hex digits) | |
7117c2d2 JA |
1027 | .TP |
1028 | .B \ec\fIx\fP | |
1029 | a control-\fIx\fP character | |
ccc6cda3 JA |
1030 | .PD |
1031 | .RE | |
1032 | .LP | |
bb70624e | 1033 | The expanded result is single-quoted, as if the dollar sign had |
ccc6cda3 JA |
1034 | not been present. |
1035 | .PP | |
1036 | A double-quoted string preceded by a dollar sign (\fB$\fP) will cause | |
1037 | the string to be translated according to the current locale. | |
1038 | If the current locale is \fBC\fP or \fBPOSIX\fP, the dollar sign | |
1039 | is ignored. | |
1040 | If the string is translated and replaced, the replacement is | |
1041 | double-quoted. | |
726f6388 JA |
1042 | .SH PARAMETERS |
1043 | A | |
1044 | .I parameter | |
ccc6cda3 JA |
1045 | is an entity that stores values. |
1046 | It can be a | |
726f6388 JA |
1047 | .IR name , |
1048 | a number, or one of the special characters listed below under | |
1049 | .BR "Special Parameters" . | |
d3a24ed2 | 1050 | A |
726f6388 JA |
1051 | .I variable |
1052 | is a parameter denoted by a | |
1053 | .IR name . | |
f73dda09 JA |
1054 | A variable has a \fIvalue\fP and zero or more \fIattributes\fP. |
1055 | Attributes are assigned using the | |
1056 | .B declare | |
1057 | builtin command (see | |
1058 | .B declare | |
1059 | below in | |
1060 | .SM | |
1061 | .BR "SHELL BUILTIN COMMANDS" ). | |
726f6388 JA |
1062 | .PP |
1063 | A parameter is set if it has been assigned a value. The null string is | |
1064 | a valid value. Once a variable is set, it may be unset only by using | |
1065 | the | |
1066 | .B unset | |
1067 | builtin command (see | |
1068 | .SM | |
1069 | .B SHELL BUILTIN COMMANDS | |
1070 | below). | |
1071 | .PP | |
1072 | A | |
1073 | .I variable | |
1074 | may be assigned to by a statement of the form | |
1075 | .RS | |
1076 | .PP | |
1077 | \fIname\fP=[\fIvalue\fP] | |
1078 | .RE | |
1079 | .PP | |
1080 | If | |
1081 | .I value | |
1082 | is not given, the variable is assigned the null string. All | |
1083 | .I values | |
bb70624e JA |
1084 | undergo tilde expansion, parameter and variable expansion, |
1085 | command substitution, arithmetic expansion, and quote | |
ccc6cda3 JA |
1086 | removal (see |
1087 | .SM | |
1088 | .B EXPANSION | |
1089 | below). If the variable has its | |
cce855bc | 1090 | .B integer |
f73dda09 | 1091 | attribute set, then |
726f6388 | 1092 | .I value |
d3a24ed2 | 1093 | is evaluated as an arithmetic expression even if the $((...)) expansion is |
cce855bc | 1094 | not used (see |
ccc6cda3 JA |
1095 | .B "Arithmetic Expansion" |
1096 | below). | |
1097 | Word splitting is not performed, with the exception | |
726f6388 JA |
1098 | of \fB"$@"\fP as explained below under |
1099 | .BR "Special Parameters" . | |
1100 | Pathname expansion is not performed. | |
f73dda09 | 1101 | Assignment statements may also appear as arguments to the |
5e13499c | 1102 | .BR alias , |
f73dda09 JA |
1103 | .BR declare , |
1104 | .BR typeset , | |
1105 | .BR export , | |
1106 | .BR readonly , | |
1107 | and | |
1108 | .B local | |
1109 | builtin commands. | |
d11b8b46 CR |
1110 | .PP |
1111 | In the context where an assignment statement is assigning a value | |
1112 | to a shell variable or array index, the += operator can be used to | |
1113 | append to or add to the variable's previous value. | |
1114 | When += is applied to a variable for which the integer attribute has been | |
1115 | set, \fIvalue\fP is evaluated as an arithmetic expression and added to the | |
1116 | variable's current value, which is also evaluated. | |
1117 | When += is applied to an array variable using compound assignment (see | |
1118 | .B Arrays | |
1119 | below), the | |
1120 | variable's value is not unset (as it is when using =), and new values are | |
1121 | appended to the array beginning at one greater than the array's maximum index. | |
1122 | When applied to a string-valued variable, \fIvalue\fP is expanded and | |
1123 | appended to the variable's value. | |
726f6388 JA |
1124 | .SS Positional Parameters |
1125 | .PP | |
1126 | A | |
1127 | .I positional parameter | |
1128 | is a parameter denoted by one or more | |
1129 | digits, other than the single digit 0. Positional parameters are | |
1130 | assigned from the shell's arguments when it is invoked, | |
1131 | and may be reassigned using the | |
1132 | .B set | |
1133 | builtin command. Positional parameters may not be assigned to | |
1134 | with assignment statements. The positional parameters are | |
1135 | temporarily replaced when a shell function is executed (see | |
1136 | .SM | |
1137 | .B FUNCTIONS | |
1138 | below). | |
1139 | .PP | |
1140 | When a positional parameter consisting of more than a single | |
1141 | digit is expanded, it must be enclosed in braces (see | |
1142 | .SM | |
1143 | .B EXPANSION | |
1144 | below). | |
1145 | .SS Special Parameters | |
1146 | .PP | |
1147 | The shell treats several parameters specially. These parameters may | |
1148 | only be referenced; assignment to them is not allowed. | |
1149 | .PD 0 | |
1150 | .TP | |
1151 | .B * | |
1152 | Expands to the positional parameters, starting from one. When the | |
1153 | expansion occurs within double quotes, it expands to a single word | |
1154 | with the value of each parameter separated by the first character | |
1155 | of the | |
1156 | .SM | |
1157 | .B IFS | |
cce855bc JA |
1158 | special variable. That is, "\fB$*\fP" is equivalent |
1159 | to "\fB$1\fP\fIc\fP\fB$2\fP\fIc\fP\fB...\fP", where | |
726f6388 JA |
1160 | .I c |
1161 | is the first character of the value of the | |
1162 | .SM | |
1163 | .B IFS | |
1164 | variable. If | |
1165 | .SM | |
1166 | .B IFS | |
d166f048 JA |
1167 | is unset, the parameters are separated by spaces. |
1168 | If | |
1169 | .SM | |
1170 | .B IFS | |
1171 | is null, the parameters are joined without intervening separators. | |
726f6388 JA |
1172 | .TP |
1173 | .B @ | |
1174 | Expands to the positional parameters, starting from one. When the | |
cce855bc JA |
1175 | expansion occurs within double quotes, each parameter expands to a |
1176 | separate word. That is, "\fB$@\fP" is equivalent to | |
1177 | "\fB$1\fP" "\fB$2\fP" ... | |
be7d8f2d CR |
1178 | If the double-quoted expansion occurs within a word, the expansion of |
1179 | the first parameter is joined with the beginning part of the original | |
1180 | word, and the expansion of the last parameter is joined with the last | |
1181 | part of the original word. | |
cce855bc | 1182 | When there are no positional parameters, "\fB$@\fP" and |
726f6388 JA |
1183 | .B $@ |
1184 | expand to nothing (i.e., they are removed). | |
1185 | .TP | |
1186 | .B # | |
1187 | Expands to the number of positional parameters in decimal. | |
1188 | .TP | |
1189 | .B ? | |
1190 | Expands to the status of the most recently executed foreground | |
1191 | pipeline. | |
1192 | .TP | |
1193 | .B \- | |
1194 | Expands to the current option flags as specified upon invocation, | |
1195 | by the | |
1196 | .B set | |
1197 | builtin command, or those set by the shell itself | |
1198 | (such as the | |
1199 | .B \-i | |
cce855bc | 1200 | option). |
726f6388 JA |
1201 | .TP |
1202 | .B $ | |
1203 | Expands to the process ID of the shell. In a () subshell, it | |
1204 | expands to the process ID of the current shell, not the | |
1205 | subshell. | |
1206 | .TP | |
1207 | .B ! | |
1208 | Expands to the process ID of the most recently executed background | |
1209 | (asynchronous) command. | |
1210 | .TP | |
1211 | .B 0 | |
1212 | Expands to the name of the shell or shell script. This is set at | |
1213 | shell initialization. If | |
1214 | .B bash | |
1215 | is invoked with a file of commands, | |
1216 | .B $0 | |
1217 | is set to the name of that file. If | |
1218 | .B bash | |
1219 | is started with the | |
1220 | .B \-c | |
1221 | option, then | |
1222 | .B $0 | |
1223 | is set to the first argument after the string to be | |
1224 | executed, if one is present. Otherwise, it is set | |
ccc6cda3 | 1225 | to the file name used to invoke |
726f6388 JA |
1226 | .BR bash , |
1227 | as given by argument zero. | |
1228 | .TP | |
1229 | .B _ | |
cc87ba64 CR |
1230 | At shell startup, set to the absolute pathname used to invoke the |
1231 | shell or shell script being executed as passed in the environment | |
1232 | or argument list. | |
ccc6cda3 JA |
1233 | Subsequently, expands to the last argument to the previous command, |
1234 | after expansion. | |
cc87ba64 CR |
1235 | Also set to the full pathname used to invoke each command executed |
1236 | and placed in the environment exported to that command. | |
ccc6cda3 JA |
1237 | When checking mail, this parameter holds the name of the mail file |
1238 | currently being checked. | |
726f6388 JA |
1239 | .PD |
1240 | .SS Shell Variables | |
1241 | .PP | |
1242 | The following variables are set by the shell: | |
1243 | .PP | |
1244 | .PD 0 | |
1245 | .TP | |
726f6388 | 1246 | .B BASH |
ccc6cda3 | 1247 | Expands to the full file name used to invoke this instance of |
726f6388 JA |
1248 | .BR bash . |
1249 | .TP | |
d3ad40de CR |
1250 | .B BASHPID |
1251 | Expands to the process id of the current bash process. | |
1252 | This differs from \fB$$\fP under certain circumstances, such as subshells | |
1253 | that do not require bash to be re-initialized. | |
1254 | .TP | |
d3a24ed2 CR |
1255 | .B BASH_ARGC |
1256 | An array variable whose values are the number of parameters in each | |
2206f89a CR |
1257 | frame of the current bash execution call stack. |
1258 | The number of | |
d3a24ed2 | 1259 | parameters to the current subroutine (shell function or script executed |
2206f89a CR |
1260 | with \fB.\fP or \fBsource\fP) is at the top of the stack. |
1261 | When a subroutine is executed, the number of parameters passed is pushed onto | |
d3a24ed2 | 1262 | \fBBASH_ARGC\fP. |
2206f89a CR |
1263 | The shell sets \fBBASH_ARGC\fP only when in extended debugging mode |
1264 | (see the description of the | |
1265 | .B extdebug | |
1266 | option to the | |
1267 | .B shopt | |
1268 | builtin below) | |
d3a24ed2 CR |
1269 | .TP |
1270 | .B BASH_ARGV | |
1271 | An array variable containing all of the parameters in the current bash | |
1272 | execution call stack. The final parameter of the last subroutine call | |
1273 | is at the top of the stack; the first parameter of the initial call is | |
1274 | at the bottom. When a subroutine is executed, the parameters supplied | |
1275 | are pushed onto \fBBASH_ARGV\fP. | |
2206f89a CR |
1276 | The shell sets \fBBASH_ARGV\fP only when in extended debugging mode |
1277 | (see the description of the | |
1278 | .B extdebug | |
1279 | option to the | |
1280 | .B shopt | |
1281 | builtin below) | |
d3a24ed2 CR |
1282 | .TP |
1283 | .B BASH_COMMAND | |
1284 | The command currently being executed or about to be executed, unless the | |
1285 | shell is executing a command as the result of a trap, | |
1286 | in which case it is the command executing at the time of the trap. | |
1287 | .TP | |
1288 | .B BASH_EXECUTION_STRING | |
1289 | The command argument to the \fB\-c\fP invocation option. | |
1290 | .TP | |
1291 | .B BASH_LINENO | |
1292 | An array variable whose members are the line numbers in source files | |
be7d8f2d | 1293 | corresponding to each member of \fBFUNCNAME\fP. |
d3a24ed2 | 1294 | \fB${BASH_LINENO[\fP\fI$i\fP\fB]}\fP is the line number in the source |
3d4e09aa CR |
1295 | file where \fB${FUNCNAME[\fP\fI$i\fP\fB]}\fP was called |
1296 | (or \fB${BASH_LINENO[\fP\fI$i-1\fP\fB]}\fP if referenced within another | |
1297 | shell function). | |
633e5c6d | 1298 | The corresponding source file name is \fB${BASH_SOURCE[\fP\fI$i\fP\fB]}\fB. |
d3a24ed2 CR |
1299 | Use \fBLINENO\fP to obtain the current line number. |
1300 | .TP | |
1301 | .B BASH_REMATCH | |
1302 | An array variable whose members are assigned by the \fB=~\fP binary | |
1303 | operator to the \fB[[\fP conditional command. | |
1304 | The element with index 0 is the portion of the string | |
1305 | matching the entire regular expression. | |
1306 | The element with index \fIn\fP is the portion of the | |
1307 | string matching the \fIn\fPth parenthesized subexpression. | |
1308 | This variable is read-only. | |
1309 | .TP | |
1310 | .B BASH_SOURCE | |
1311 | An array variable whose members are the source filenames corresponding | |
1312 | to the elements in the \fBFUNCNAME\fP array variable. | |
1313 | .TP | |
1314 | .B BASH_SUBSHELL | |
1315 | Incremented by one each time a subshell or subshell environment is spawned. | |
1316 | The initial value is 0. | |
1317 | .TP | |
ccc6cda3 | 1318 | .B BASH_VERSINFO |
cce855bc JA |
1319 | A readonly array variable whose members hold version information for |
1320 | this instance of | |
ccc6cda3 JA |
1321 | .BR bash . |
1322 | The values assigned to the array members are as follows: | |
1323 | .sp .5 | |
1324 | .RS | |
1325 | .PD 0 | |
1326 | .TP 24 | |
1327 | .B BASH_VERSINFO[\fR0\fP] | |
1328 | The major version number (the \fIrelease\fP). | |
1329 | .TP | |
1330 | .B BASH_VERSINFO[\fR1\fP] | |
1331 | The minor version number (the \fIversion\fP). | |
1332 | .TP | |
1333 | .B BASH_VERSINFO[\fR2\fP] | |
1334 | The patch level. | |
1335 | .TP | |
1336 | .B BASH_VERSINFO[\fR3\fP] | |
1337 | The build version. | |
1338 | .TP | |
1339 | .B BASH_VERSINFO[\fR4\fP] | |
1340 | The release status (e.g., \fIbeta1\fP). | |
1341 | .TP | |
1342 | .B BASH_VERSINFO[\fR5\fP] | |
1343 | The value of \fBMACHTYPE\fP. | |
1344 | .PD | |
1345 | .RE | |
1346 | .TP | |
f73dda09 JA |
1347 | .B BASH_VERSION |
1348 | Expands to a string describing the version of this instance of | |
1349 | .BR bash . | |
726f6388 | 1350 | .TP |
f73dda09 JA |
1351 | .B COMP_CWORD |
1352 | An index into \fB${COMP_WORDS}\fP of the word containing the current | |
1353 | cursor position. | |
1354 | This variable is available only in shell functions invoked by the | |
1355 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1356 | below). | |
1357 | .TP | |
d3ad40de CR |
1358 | .B COMP_KEY |
1359 | The key (or final key of a key sequence) used to invoke the current | |
1360 | completion function. | |
1361 | .TP | |
f73dda09 JA |
1362 | .B COMP_LINE |
1363 | The current command line. | |
1364 | This variable is available only in shell functions and external | |
1365 | commands invoked by the | |
1366 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1367 | below). | |
1368 | .TP | |
1369 | .B COMP_POINT | |
1370 | The index of the current cursor position relative to the beginning of | |
1371 | the current command. | |
1372 | If the current cursor position is at the end of the current command, | |
1373 | the value of this variable is equal to \fB${#COMP_LINE}\fP. | |
1374 | This variable is available only in shell functions and external | |
1375 | commands invoked by the | |
1376 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1377 | below). | |
1378 | .TP | |
d3ad40de CR |
1379 | .B COMP_TYPE |
1380 | Set to an integer value corresponding to the type of completion attempted | |
1381 | that caused a completion function to be called: | |
1382 | \fITAB\fP, for normal completion, | |
1383 | \fI?\fP, for listing completions after successive tabs, | |
1384 | \fI!\fP, for listing alternatives on partial word completion, | |
1385 | \fI@\fP, to list completions if the word is not unmodified, | |
1386 | or | |
1387 | \fI%\fP, for menu completion. | |
1388 | This variable is available only in shell functions and external | |
1389 | commands invoked by the | |
1390 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1391 | below). | |
1392 | .TP | |
d3a24ed2 CR |
1393 | .B COMP_WORDBREAKS |
1394 | The set of characters that the Readline library treats as word | |
1395 | separators when performing word completion. | |
1396 | If | |
1397 | .SM | |
1398 | .B COMP_WORDBREAKS | |
1399 | is unset, it loses its special properties, even if it is | |
1400 | subsequently reset. | |
1401 | .TP | |
f73dda09 JA |
1402 | .B COMP_WORDS |
1403 | An array variable (see \fBArrays\fP below) consisting of the individual | |
1404 | words in the current command line. | |
d3ad40de CR |
1405 | The words are split on shell metacharacters as the shell parser would |
1406 | separate them. | |
f73dda09 JA |
1407 | This variable is available only in shell functions invoked by the |
1408 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1409 | below). | |
1410 | .TP | |
1411 | .B DIRSTACK | |
1412 | An array variable (see | |
1413 | .B Arrays | |
1414 | below) containing the current contents of the directory stack. | |
1415 | Directories appear in the stack in the order they are displayed by the | |
1416 | .B dirs | |
1417 | builtin. | |
1418 | Assigning to members of this array variable may be used to modify | |
1419 | directories already in the stack, but the | |
1420 | .B pushd | |
1421 | and | |
1422 | .B popd | |
1423 | builtins must be used to add and remove directories. | |
1424 | Assignment to this variable will not change the current directory. | |
726f6388 JA |
1425 | If |
1426 | .SM | |
f73dda09 | 1427 | .B DIRSTACK |
726f6388 JA |
1428 | is unset, it loses its special properties, even if it is |
1429 | subsequently reset. | |
1430 | .TP | |
f73dda09 JA |
1431 | .B EUID |
1432 | Expands to the effective user ID of the current user, initialized at | |
1433 | shell startup. This variable is readonly. | |
1434 | .TP | |
1435 | .B FUNCNAME | |
d3a24ed2 CR |
1436 | An array variable containing the names of all shell functions |
1437 | currently in the execution call stack. | |
1438 | The element with index 0 is the name of any currently-executing | |
1439 | shell function. | |
d3ad40de CR |
1440 | The bottom-most element is |
1441 | .if t \f(CW"main"\fP. | |
1442 | .if n "main". | |
f73dda09 JA |
1443 | This variable exists only when a shell function is executing. |
1444 | Assignments to | |
726f6388 | 1445 | .SM |
f73dda09 JA |
1446 | .B FUNCNAME |
1447 | have no effect and return an error status. | |
726f6388 JA |
1448 | If |
1449 | .SM | |
f73dda09 | 1450 | .B FUNCNAME |
726f6388 JA |
1451 | is unset, it loses its special properties, even if it is |
1452 | subsequently reset. | |
1453 | .TP | |
f73dda09 JA |
1454 | .B GROUPS |
1455 | An array variable containing the list of groups of which the current | |
1456 | user is a member. | |
1457 | Assignments to | |
1458 | .SM | |
1459 | .B GROUPS | |
1460 | have no effect and return an error status. | |
726f6388 JA |
1461 | If |
1462 | .SM | |
f73dda09 | 1463 | .B GROUPS |
726f6388 JA |
1464 | is unset, it loses its special properties, even if it is |
1465 | subsequently reset. | |
1466 | .TP | |
1467 | .B HISTCMD | |
1468 | The history number, or index in the history list, of the current | |
ccc6cda3 JA |
1469 | command. |
1470 | If | |
726f6388 JA |
1471 | .SM |
1472 | .B HISTCMD | |
1473 | is unset, it loses its special properties, even if it is | |
1474 | subsequently reset. | |
1475 | .TP | |
f73dda09 JA |
1476 | .B HOSTNAME |
1477 | Automatically set to the name of the current host. | |
bb70624e | 1478 | .TP |
f73dda09 JA |
1479 | .B HOSTTYPE |
1480 | Automatically set to a string that uniquely | |
1481 | describes the type of machine on which | |
1482 | .B bash | |
1483 | is executing. | |
1484 | The default is system-dependent. | |
1485 | .TP | |
1486 | .B LINENO | |
1487 | Each time this parameter is referenced, the shell substitutes | |
1488 | a decimal number representing the current sequential line number | |
1489 | (starting with 1) within a script or function. When not in a | |
1490 | script or function, the value substituted is not guaranteed to | |
1491 | be meaningful. | |
ccc6cda3 JA |
1492 | If |
1493 | .SM | |
f73dda09 | 1494 | .B LINENO |
ccc6cda3 JA |
1495 | is unset, it loses its special properties, even if it is |
1496 | subsequently reset. | |
1497 | .TP | |
f73dda09 JA |
1498 | .B MACHTYPE |
1499 | Automatically set to a string that fully describes the system | |
1500 | type on which | |
1501 | .B bash | |
1502 | is executing, in the standard GNU \fIcpu-company-system\fP format. | |
1503 | The default is system-dependent. | |
1504 | .TP | |
1505 | .B OLDPWD | |
1506 | The previous working directory as set by the | |
1507 | .B cd | |
1508 | command. | |
ccc6cda3 | 1509 | .TP |
726f6388 JA |
1510 | .B OPTARG |
1511 | The value of the last option argument processed by the | |
1512 | .B getopts | |
1513 | builtin command (see | |
1514 | .SM | |
1515 | .B SHELL BUILTIN COMMANDS | |
1516 | below). | |
1517 | .TP | |
1518 | .B OPTIND | |
1519 | The index of the next argument to be processed by the | |
1520 | .B getopts | |
1521 | builtin command (see | |
1522 | .SM | |
1523 | .B SHELL BUILTIN COMMANDS | |
1524 | below). | |
1525 | .TP | |
726f6388 JA |
1526 | .B OSTYPE |
1527 | Automatically set to a string that | |
1528 | describes the operating system on which | |
1529 | .B bash | |
ccc6cda3 JA |
1530 | is executing. |
1531 | The default is system-dependent. | |
1532 | .TP | |
f73dda09 JA |
1533 | .B PIPESTATUS |
1534 | An array variable (see | |
1535 | .B Arrays | |
1536 | below) containing a list of exit status values from the processes | |
1537 | in the most-recently-executed foreground pipeline (which may | |
1538 | contain only a single command). | |
ccc6cda3 | 1539 | .TP |
f73dda09 JA |
1540 | .B PPID |
1541 | The process ID of the shell's parent. This variable is readonly. | |
1542 | .TP | |
1543 | .B PWD | |
1544 | The current working directory as set by the | |
1545 | .B cd | |
1546 | command. | |
1547 | .TP | |
1548 | .B RANDOM | |
1549 | Each time this parameter is referenced, a random integer between | |
1550 | 0 and 32767 is | |
1551 | generated. The sequence of random numbers may be initialized by assigning | |
1552 | a value to | |
1553 | .SM | |
1554 | .BR RANDOM . | |
1555 | If | |
1556 | .SM | |
1557 | .B RANDOM | |
1558 | is unset, it loses its special properties, even if it is | |
1559 | subsequently reset. | |
1560 | .TP | |
1561 | .B REPLY | |
1562 | Set to the line of input read by the | |
1563 | .B read | |
1564 | builtin command when no arguments are supplied. | |
1565 | .TP | |
1566 | .B SECONDS | |
1567 | Each time this parameter is | |
1568 | referenced, the number of seconds since shell invocation is returned. If a | |
1569 | value is assigned to | |
1570 | .SM | |
1571 | .BR SECONDS , | |
1572 | the value returned upon subsequent | |
1573 | references is | |
1574 | the number of seconds since the assignment plus the value assigned. | |
1575 | If | |
1576 | .SM | |
1577 | .B SECONDS | |
1578 | is unset, it loses its special properties, even if it is | |
1579 | subsequently reset. | |
1580 | .TP | |
1581 | .B SHELLOPTS | |
1582 | A colon-separated list of enabled shell options. Each word in | |
1583 | the list is a valid argument for the | |
1584 | .B \-o | |
1585 | option to the | |
1586 | .B set | |
1587 | builtin command (see | |
1588 | .SM | |
1589 | .B "SHELL BUILTIN COMMANDS" | |
1590 | below). The options appearing in | |
ccc6cda3 JA |
1591 | .SM |
1592 | .B SHELLOPTS | |
1593 | are those reported as | |
1594 | .I on | |
1595 | by \fBset \-o\fP. | |
1596 | If this variable is in the environment when | |
1597 | .B bash | |
1598 | starts up, each shell option in the list will be enabled before | |
1599 | reading any startup files. | |
1600 | This variable is read-only. | |
bb70624e | 1601 | .TP |
f73dda09 JA |
1602 | .B SHLVL |
1603 | Incremented by one each time an instance of | |
1604 | .B bash | |
1605 | is started. | |
bb70624e | 1606 | .TP |
f73dda09 JA |
1607 | .B UID |
1608 | Expands to the user ID of the current user, initialized at shell startup. | |
1609 | This variable is readonly. | |
726f6388 JA |
1610 | .PD |
1611 | .PP | |
1612 | The following variables are used by the shell. In some cases, | |
1613 | .B bash | |
1614 | assigns a default value to a variable; these cases are noted | |
1615 | below. | |
1616 | .PP | |
1617 | .PD 0 | |
1618 | .TP | |
d166f048 | 1619 | .B BASH_ENV |
726f6388 JA |
1620 | If this parameter is set when \fBbash\fP is executing a shell script, |
1621 | its value is interpreted as a filename containing commands to | |
1622 | initialize the shell, as in | |
cce855bc | 1623 | .IR ~/.bashrc . |
726f6388 JA |
1624 | The value of |
1625 | .SM | |
d166f048 | 1626 | .B BASH_ENV |
726f6388 | 1627 | is subjected to parameter expansion, command substitution, and arithmetic |
ccc6cda3 | 1628 | expansion before being interpreted as a file name. |
726f6388 JA |
1629 | .SM |
1630 | .B PATH | |
ccc6cda3 | 1631 | is not used to search for the resultant file name. |
726f6388 | 1632 | .TP |
f73dda09 JA |
1633 | .B CDPATH |
1634 | The search path for the | |
1635 | .B cd | |
1636 | command. | |
1637 | This is a colon-separated list of directories in which the shell looks | |
1638 | for destination directories specified by the | |
1639 | .B cd | |
1640 | command. | |
7117c2d2 JA |
1641 | A sample value is |
1642 | .if t \f(CW".:~:/usr"\fP. | |
1643 | .if n ".:~:/usr". | |
726f6388 | 1644 | .TP |
f73dda09 JA |
1645 | .B COLUMNS |
1646 | Used by the \fBselect\fP builtin command to determine the terminal width | |
1647 | when printing selection lists. Automatically set upon receipt of a SIGWINCH. | |
726f6388 | 1648 | .TP |
f73dda09 JA |
1649 | .B COMPREPLY |
1650 | An array variable from which \fBbash\fP reads the possible completions | |
1651 | generated by a shell function invoked by the programmable completion | |
1652 | facility (see \fBProgrammable Completion\fP below). | |
726f6388 | 1653 | .TP |
d3a24ed2 CR |
1654 | .B EMACS |
1655 | If \fBbash\fP finds this variable in the environment when the shell starts | |
1656 | with value | |
1657 | .if t \f(CWt\fP, | |
1658 | .if n "t", | |
1659 | it assumes that the shell is running in an emacs shell buffer and disables | |
1660 | line editing. | |
1661 | .TP | |
f73dda09 JA |
1662 | .B FCEDIT |
1663 | The default editor for the | |
1664 | .B fc | |
1665 | builtin command. | |
726f6388 | 1666 | .TP |
f73dda09 JA |
1667 | .B FIGNORE |
1668 | A colon-separated list of suffixes to ignore when performing | |
1669 | filename completion (see | |
726f6388 | 1670 | .SM |
f73dda09 JA |
1671 | .B READLINE |
1672 | below). | |
1673 | A filename whose suffix matches one of the entries in | |
726f6388 | 1674 | .SM |
f73dda09 JA |
1675 | .B FIGNORE |
1676 | is excluded from the list of matched filenames. | |
7117c2d2 JA |
1677 | A sample value is |
1678 | .if t \f(CW".o:~"\fP. | |
1679 | .if n ".o:~". | |
ccc6cda3 | 1680 | .TP |
f73dda09 JA |
1681 | .B GLOBIGNORE |
1682 | A colon-separated list of patterns defining the set of filenames to | |
1683 | be ignored by pathname expansion. | |
1684 | If a filename matched by a pathname expansion pattern also matches one | |
1685 | of the patterns in | |
726f6388 | 1686 | .SM |
f73dda09 JA |
1687 | .BR GLOBIGNORE , |
1688 | it is removed from the list of matches. | |
1689 | .TP | |
1690 | .B HISTCONTROL | |
d3a24ed2 CR |
1691 | A colon-separated list of values controlling how commands are saved on |
1692 | the history list. | |
1693 | If the list of values includes | |
f73dda09 JA |
1694 | .IR ignorespace , |
1695 | lines which begin with a | |
1696 | .B space | |
d3a24ed2 CR |
1697 | character are not saved in the history list. |
1698 | A value of | |
1699 | .I ignoredups | |
1700 | causes lines matching the previous history entry to not be saved. | |
f73dda09 JA |
1701 | A value of |
1702 | .I ignoreboth | |
d3a24ed2 CR |
1703 | is shorthand for \fIignorespace\fP and \fIignoredups\fP. |
1704 | A value of | |
1705 | .IR erasedups | |
1706 | causes all previous lines matching the current line to be removed from | |
1707 | the history list before that line is saved. | |
1708 | Any value not in the above list is ignored. | |
1709 | If \fBHISTCONTROL\fP is unset, or does not include a valid value, | |
1710 | all lines read by the shell parser are saved on the history list, | |
1711 | subject to the value of | |
f73dda09 JA |
1712 | .BR HISTIGNORE . |
1713 | The second and subsequent lines of a multi-line compound command are | |
1714 | not tested, and are added to the history regardless of the value of | |
1715 | .BR HISTCONTROL . | |
726f6388 JA |
1716 | .TP |
1717 | .B HISTFILE | |
ccc6cda3 | 1718 | The name of the file in which command history is saved (see |
726f6388 JA |
1719 | .SM |
1720 | .B HISTORY | |
ccc6cda3 | 1721 | below). The default value is \fI~/.bash_history\fP. If unset, the |
726f6388 JA |
1722 | command history is not saved when an interactive shell exits. |
1723 | .TP | |
1724 | .B HISTFILESIZE | |
1725 | The maximum number of lines contained in the history file. When this | |
1726 | variable is assigned a value, the history file is truncated, if | |
d3ad40de CR |
1727 | necessary, by removing the oldest entries, |
1728 | to contain no more than that number of lines. The default | |
ccc6cda3 JA |
1729 | value is 500. The history file is also truncated to this size after |
1730 | writing it when an interactive shell exits. | |
726f6388 | 1731 | .TP |
f73dda09 JA |
1732 | .B HISTIGNORE |
1733 | A colon-separated list of patterns used to decide which command lines | |
1734 | should be saved on the history list. Each pattern is anchored at the | |
1735 | beginning of the line and must match the complete line (no implicit | |
1736 | `\fB*\fP' is appended). Each pattern is tested against the line | |
1737 | after the checks specified by | |
1738 | .B HISTCONTROL | |
1739 | are applied. | |
1740 | In addition to the normal shell pattern matching characters, `\fB&\fP' | |
1741 | matches the previous history line. `\fB&\fP' may be escaped using a | |
1742 | backslash; the backslash is removed before attempting a match. | |
1743 | The second and subsequent lines of a multi-line compound command are | |
1744 | not tested, and are added to the history regardless of the value of | |
1745 | .BR HISTIGNORE . | |
1746 | .TP | |
1747 | .B HISTSIZE | |
1748 | The number of commands to remember in the command history (see | |
1749 | .SM | |
1750 | .B HISTORY | |
1751 | below). The default value is 500. | |
1752 | .TP | |
d3a24ed2 CR |
1753 | .B HISTTIMEFORMAT |
1754 | If this variable is set and not null, its value is used as a format string | |
1755 | for \fIstrftime\fP(3) to print the time stamp associated with each history | |
1756 | entry displayed by the \fBhistory\fP builtin. | |
1757 | If this variable is set, time stamps are written to the history file so | |
1758 | they may be preserved across shell sessions. | |
d3ad40de CR |
1759 | This uses the history comment character to distinguish timestamps from |
1760 | other history lines. | |
d3a24ed2 | 1761 | .TP |
f73dda09 JA |
1762 | .B HOME |
1763 | The home directory of the current user; the default argument for the | |
1764 | \fBcd\fP builtin command. | |
1765 | The value of this variable is also used when performing tilde expansion. | |
1766 | .TP | |
1767 | .B HOSTFILE | |
1768 | Contains the name of a file in the same format as | |
1769 | .FN /etc/hosts | |
1770 | that should be read when the shell needs to complete a | |
1771 | hostname. | |
1772 | The list of possible hostname completions may be changed while the | |
1773 | shell is running; | |
1774 | the next time hostname completion is attempted after the | |
1775 | value is changed, | |
726f6388 | 1776 | .B bash |
f73dda09 JA |
1777 | adds the contents of the new file to the existing list. |
1778 | If | |
726f6388 | 1779 | .SM |
f73dda09 JA |
1780 | .B HOSTFILE |
1781 | is set, but has no value, \fBbash\fP attempts to read | |
1782 | .FN /etc/hosts | |
1783 | to obtain the list of possible hostname completions. | |
1784 | When | |
726f6388 | 1785 | .SM |
f73dda09 JA |
1786 | .B HOSTFILE |
1787 | is unset, the hostname list is cleared. | |
1788 | .TP | |
1789 | .B IFS | |
1790 | The | |
1791 | .I Internal Field Separator | |
1792 | that is used | |
1793 | for word splitting after expansion and to | |
1794 | split lines into words with the | |
1795 | .B read | |
1796 | builtin command. The default value is | |
1797 | ``<space><tab><newline>''. | |
1798 | .TP | |
1799 | .B IGNOREEOF | |
1800 | Controls the | |
1801 | action of an interactive shell on receipt of an | |
1802 | .SM | |
1803 | .B EOF | |
1804 | character as the sole input. If set, the value is the number of | |
1805 | consecutive | |
1806 | .SM | |
1807 | .B EOF | |
1808 | characters which must be | |
1809 | typed as the first characters on an input line before | |
1810 | .B bash | |
1811 | exits. If the variable exists but does not have a numeric value, or | |
1812 | has no value, the default value is 10. If it does not exist, | |
1813 | .SM | |
1814 | .B EOF | |
1815 | signifies the end of input to the shell. | |
1816 | .TP | |
1817 | .B INPUTRC | |
1818 | The filename for the | |
1819 | .B readline | |
1820 | startup file, overriding the default of | |
1821 | .FN ~/.inputrc | |
1822 | (see | |
1823 | .SM | |
1824 | .B READLINE | |
1825 | below). | |
726f6388 | 1826 | .TP |
ccc6cda3 JA |
1827 | .B LANG |
1828 | Used to determine the locale category for any category not specifically | |
1829 | selected with a variable starting with \fBLC_\fP. | |
1830 | .TP | |
1831 | .B LC_ALL | |
1832 | This variable overrides the value of \fBLANG\fP and any other | |
1833 | \fBLC_\fP variable specifying a locale category. | |
1834 | .TP | |
1835 | .B LC_COLLATE | |
1836 | This variable determines the collation order used when sorting the | |
cce855bc JA |
1837 | results of pathname expansion, and determines the behavior of range |
1838 | expressions, equivalence classes, and collating sequences within | |
1839 | pathname expansion and pattern matching. | |
1840 | .TP | |
1841 | .B LC_CTYPE | |
1842 | This variable determines the interpretation of characters and the | |
1843 | behavior of character classes within pathname expansion and pattern | |
1844 | matching. | |
ccc6cda3 JA |
1845 | .TP |
1846 | .B LC_MESSAGES | |
1847 | This variable determines the locale used to translate double-quoted | |
1848 | strings preceded by a \fB$\fP. | |
1849 | .TP | |
bb70624e JA |
1850 | .B LC_NUMERIC |
1851 | This variable determines the locale category used for number formatting. | |
1852 | .TP | |
28ef6c31 JA |
1853 | .B LINES |
1854 | Used by the \fBselect\fP builtin command to determine the column length | |
1855 | for printing selection lists. Automatically set upon receipt of a SIGWINCH. | |
1856 | .TP | |
f73dda09 JA |
1857 | .B MAIL |
1858 | If this parameter is set to a file name and the | |
726f6388 | 1859 | .SM |
f73dda09 JA |
1860 | .B MAILPATH |
1861 | variable is not set, | |
726f6388 | 1862 | .B bash |
f73dda09 | 1863 | informs the user of the arrival of mail in the specified file. |
726f6388 | 1864 | .TP |
f73dda09 JA |
1865 | .B MAILCHECK |
1866 | Specifies how | |
1867 | often (in seconds) | |
1868 | .B bash | |
1869 | checks for mail. The default is 60 seconds. When it is time to check | |
1870 | for mail, the shell does so before displaying the primary prompt. | |
1871 | If this variable is unset, or set to a value that is not a number | |
1872 | greater than or equal to zero, the shell disables mail checking. | |
726f6388 | 1873 | .TP |
f73dda09 JA |
1874 | .B MAILPATH |
1875 | A colon-separated list of file names to be checked for mail. | |
1876 | The message to be printed when mail arrives in a particular file | |
1877 | may be specified by separating the file name from the message with a `?'. | |
1878 | When used in the text of the message, \fB$_\fP expands to the name of | |
1879 | the current mailfile. | |
1880 | Example: | |
1881 | .RS | |
1882 | .PP | |
20587658 | 1883 | \fBMAILPATH\fP=\(aq/var/mail/bfox?"You have mail":~/shell\-mail?"$_ has mail!"\(aq |
f73dda09 JA |
1884 | .PP |
1885 | .B Bash | |
1886 | supplies a default value for this variable, but the location of the user | |
1887 | mail files that it uses is system dependent (e.g., /var/mail/\fB$USER\fP). | |
1888 | .RE | |
726f6388 | 1889 | .TP |
f73dda09 JA |
1890 | .B OPTERR |
1891 | If set to the value 1, | |
1892 | .B bash | |
1893 | displays error messages generated by the | |
1894 | .B getopts | |
1895 | builtin command (see | |
726f6388 | 1896 | .SM |
f73dda09 | 1897 | .B SHELL BUILTIN COMMANDS |
ccc6cda3 | 1898 | below). |
726f6388 | 1899 | .SM |
f73dda09 JA |
1900 | .B OPTERR |
1901 | is initialized to 1 each time the shell is invoked or a shell | |
1902 | script is executed. | |
ccc6cda3 | 1903 | .TP |
f73dda09 JA |
1904 | .B PATH |
1905 | The search path for commands. It | |
1906 | is a colon-separated list of directories in which | |
1907 | the shell looks for commands (see | |
ccc6cda3 | 1908 | .SM |
f73dda09 | 1909 | .B COMMAND EXECUTION |
d3a24ed2 CR |
1910 | below). |
1911 | A zero-length (null) directory name in the value of \fBPATH\fP indicates the | |
1912 | current directory. | |
1913 | A null directory name may appear as two adjacent colons, or as an initial | |
1914 | or trailing colon. | |
1915 | The default path is system-dependent, | |
f73dda09 JA |
1916 | and is set by the administrator who installs |
1917 | .BR bash . | |
1918 | A common value is | |
5e13499c CR |
1919 | .if t \f(CW/usr/gnu/bin:/usr/local/bin:/usr/ucb:/bin:/usr/bin\fP. |
1920 | .if n ``/usr/gnu/bin:/usr/local/bin:/usr/ucb:/bin:/usr/bin''. | |
726f6388 | 1921 | .TP |
f73dda09 JA |
1922 | .B POSIXLY_CORRECT |
1923 | If this variable is in the environment when \fBbash\fP starts, the shell | |
1924 | enters \fIposix mode\fP before reading the startup files, as if the | |
1925 | .B \-\-posix | |
1926 | invocation option had been supplied. If it is set while the shell is | |
1927 | running, \fBbash\fP enables \fIposix mode\fP, as if the command | |
1928 | .if t \f(CWset -o posix\fP | |
1929 | .if n \fIset -o posix\fP | |
1930 | had been executed. | |
726f6388 | 1931 | .TP |
f73dda09 JA |
1932 | .B PROMPT_COMMAND |
1933 | If set, the value is executed as a command prior to issuing each primary | |
1934 | prompt. | |
ccc6cda3 | 1935 | .TP |
f73dda09 JA |
1936 | .B PS1 |
1937 | The value of this parameter is expanded (see | |
1938 | .SM | |
1939 | .B PROMPTING | |
1940 | below) and used as the primary prompt string. The default value is | |
1941 | ``\fB\es\-\ev\e$ \fP''. | |
726f6388 | 1942 | .TP |
f73dda09 JA |
1943 | .B PS2 |
1944 | The value of this parameter is expanded as with | |
1945 | .B PS1 | |
1946 | and used as the secondary prompt string. The default is | |
1947 | ``\fB> \fP''. | |
1948 | .TP | |
1949 | .B PS3 | |
1950 | The value of this parameter is used as the prompt for the | |
1951 | .B select | |
1952 | command (see | |
726f6388 | 1953 | .SM |
f73dda09 JA |
1954 | .B SHELL GRAMMAR |
1955 | above). | |
726f6388 | 1956 | .TP |
f73dda09 JA |
1957 | .B PS4 |
1958 | The value of this parameter is expanded as with | |
1959 | .B PS1 | |
1960 | and the value is printed before each command | |
726f6388 | 1961 | .B bash |
f73dda09 | 1962 | displays during an execution trace. The first character of |
bb70624e | 1963 | .SM |
f73dda09 JA |
1964 | .B PS4 |
1965 | is replicated multiple times, as necessary, to indicate multiple | |
1966 | levels of indirection. The default is ``\fB+ \fP''. | |
1967 | .TP | |
61deeb13 CR |
1968 | .B SHELL |
1969 | The full pathname to the shell is kept in this environment variable. | |
1970 | If it is not set when the shell starts, | |
1971 | .B bash | |
1972 | assigns to it the full pathname of the current user's login shell. | |
1973 | .TP | |
f73dda09 JA |
1974 | .B TIMEFORMAT |
1975 | The value of this parameter is used as a format string specifying | |
1976 | how the timing information for pipelines prefixed with the | |
1977 | .B time | |
1978 | reserved word should be displayed. | |
1979 | The \fB%\fP character introduces an escape sequence that is | |
1980 | expanded to a time value or other information. | |
1981 | The escape sequences and their meanings are as follows; the | |
1982 | braces denote optional portions. | |
1983 | .sp .5 | |
1984 | .RS | |
1985 | .PD 0 | |
1986 | .TP 10 | |
1987 | .B %% | |
1988 | A literal \fB%\fP. | |
1989 | .TP | |
1990 | .B %[\fIp\fP][l]R | |
1991 | The elapsed time in seconds. | |
1992 | .TP | |
1993 | .B %[\fIp\fP][l]U | |
1994 | The number of CPU seconds spent in user mode. | |
1995 | .TP | |
1996 | .B %[\fIp\fP][l]S | |
1997 | The number of CPU seconds spent in system mode. | |
1998 | .TP | |
1999 | .B %P | |
2000 | The CPU percentage, computed as (%U + %S) / %R. | |
2001 | .PD | |
2002 | .RE | |
2003 | .IP | |
2004 | The optional \fIp\fP is a digit specifying the \fIprecision\fP, | |
2005 | the number of fractional digits after a decimal point. | |
2006 | A value of 0 causes no decimal point or fraction to be output. | |
2007 | At most three places after the decimal point may be specified; | |
2008 | values of \fIp\fP greater than 3 are changed to 3. | |
2009 | If \fIp\fP is not specified, the value 3 is used. | |
2010 | .IP | |
2011 | The optional \fBl\fP specifies a longer format, including | |
2012 | minutes, of the form \fIMM\fPm\fISS\fP.\fIFF\fPs. | |
2013 | The value of \fIp\fP determines whether or not the fraction is | |
2014 | included. | |
2015 | .IP | |
2016 | If this variable is not set, \fBbash\fP acts as if it had the | |
20587658 | 2017 | value \fB$\(aq\enreal\et%3lR\enuser\et%3lU\ensys\t%3lS\(aq\fP. |
f73dda09 JA |
2018 | If the value is null, no timing information is displayed. |
2019 | A trailing newline is added when the format string is displayed. | |
2020 | .TP | |
2021 | .B TMOUT | |
7117c2d2 JA |
2022 | If set to a value greater than zero, \fBTMOUT\fP is treated as the |
2023 | default timeout for the \fBread\fP builtin. | |
2024 | The \fBselect\fP command terminates if input does not arrive | |
2025 | after \fBTMOUT\fP seconds when input is coming from a terminal. | |
2026 | In an interactive shell, the value is interpreted as the | |
f73dda09 JA |
2027 | number of seconds to wait for input after issuing the primary prompt. |
2028 | .B Bash | |
2029 | terminates after waiting for that number of seconds if input does | |
2030 | not arrive. | |
726f6388 | 2031 | .TP |
1569c106 CR |
2032 | .B TMPDIR |
2033 | If set, \fBBash\fP uses its value as the name of a directory in which | |
2034 | \fBBash\fP creates temporary files for the shell's use. | |
2035 | .TP | |
726f6388 JA |
2036 | .B auto_resume |
2037 | This variable controls how the shell interacts with the user and | |
2038 | job control. If this variable is set, single word simple | |
2039 | commands without redirections are treated as candidates for resumption | |
2040 | of an existing stopped job. There is no ambiguity allowed; if there is | |
2041 | more than one job beginning with the string typed, the job most recently | |
2042 | accessed is selected. The | |
2043 | .I name | |
2044 | of a stopped job, in this context, is the command line used to | |
2045 | start it. | |
2046 | If set to the value | |
2047 | .IR exact , | |
2048 | the string supplied must match the name of a stopped job exactly; | |
2049 | if set to | |
2050 | .IR substring , | |
2051 | the string supplied needs to match a substring of the name of a | |
2052 | stopped job. The | |
2053 | .I substring | |
2054 | value provides functionality analogous to the | |
2055 | .B %? | |
ccc6cda3 | 2056 | job identifier (see |
726f6388 JA |
2057 | .SM |
2058 | .B JOB CONTROL | |
2059 | below). If set to any other value, the supplied string must | |
2060 | be a prefix of a stopped job's name; this provides functionality | |
22e63b05 | 2061 | analogous to the \fB%\fP\fIstring\fP job identifier. |
bb70624e | 2062 | .TP |
f73dda09 JA |
2063 | .B histchars |
2064 | The two or three characters which control history expansion | |
2065 | and tokenization (see | |
2066 | .SM | |
2067 | .B HISTORY EXPANSION | |
2068 | below). The first character is the \fIhistory expansion\fP character, | |
2069 | the character which signals the start of a history | |
2070 | expansion, normally `\fB!\fP'. | |
2071 | The second character is the \fIquick substitution\fP | |
2072 | character, which is used as shorthand for re-running the previous | |
2073 | command entered, substituting one string for another in the command. | |
2074 | The default is `\fB^\fP'. | |
2075 | The optional third character is the character | |
2076 | which indicates that the remainder of the line is a comment when found | |
2077 | as the first character of a word, normally `\fB#\fP'. The history | |
2078 | comment character causes history substitution to be skipped for the | |
2079 | remaining words on the line. It does not necessarily cause the shell | |
2080 | parser to treat the rest of the line as a comment. | |
726f6388 | 2081 | .PD |
ccc6cda3 JA |
2082 | .SS Arrays |
2083 | .B Bash | |
2084 | provides one-dimensional array variables. Any variable may be used as | |
2085 | an array; the | |
2086 | .B declare | |
2087 | builtin will explicitly declare an array. There is no maximum | |
2088 | limit on the size of an array, nor any requirement that members | |
2089 | be indexed or assigned contiguously. Arrays are indexed using | |
2090 | integers and are zero-based. | |
2091 | .PP | |
2092 | An array is created automatically if any variable is assigned to using | |
2093 | the syntax \fIname\fP[\fIsubscript\fP]=\fIvalue\fP. The | |
2094 | .I subscript | |
2095 | is treated as an arithmetic expression that must evaluate to a number | |
2096 | greater than or equal to zero. To explicitly declare an array, use | |
2097 | .B declare \-a \fIname\fP | |
2098 | (see | |
2099 | .SM | |
2100 | .B SHELL BUILTIN COMMANDS | |
2101 | below). | |
2102 | .B declare \-a \fIname\fP[\fIsubscript\fP] | |
2103 | is also accepted; the \fIsubscript\fP is ignored. Attributes may be | |
2104 | specified for an array variable using the | |
2105 | .B declare | |
2106 | and | |
2107 | .B readonly | |
2108 | builtins. Each attribute applies to all members of an array. | |
2109 | .PP | |
2110 | Arrays are assigned to using compound assignments of the form | |
2111 | \fIname\fP=\fB(\fPvalue\fI1\fP ... value\fIn\fP\fB)\fP, where each | |
2112 | \fIvalue\fP is of the form [\fIsubscript\fP]=\fIstring\fP. Only | |
2113 | \fIstring\fP is required. If | |
2114 | the optional brackets and subscript are supplied, that index is assigned to; | |
2115 | otherwise the index of the element assigned is the last index assigned | |
2116 | to by the statement plus one. Indexing starts at zero. | |
2117 | This syntax is also accepted by the | |
2118 | .B declare | |
2119 | builtin. Individual array elements may be assigned to using the | |
2120 | \fIname\fP[\fIsubscript\fP]=\fIvalue\fP syntax introduced above. | |
2121 | .PP | |
2122 | Any element of an array may be referenced using | |
2123 | ${\fIname\fP[\fIsubscript\fP]}. The braces are required to avoid | |
2124 | conflicts with pathname expansion. If | |
2125 | \fIsubscript\fP is \fB@\fP or \fB*\fP, the word expands to | |
2126 | all members of \fIname\fP. These subscripts differ only when the | |
2127 | word appears within double quotes. If the word is double-quoted, | |
2128 | ${\fIname\fP[*]} expands to a single | |
2129 | word with the value of each array member separated by the first | |
2130 | character of the | |
2131 | .SM | |
2132 | .B IFS | |
2133 | special variable, and ${\fIname\fP[@]} expands each element of | |
2134 | \fIname\fP to a separate word. When there are no array members, | |
be7d8f2d CR |
2135 | ${\fIname\fP[@]} expands to nothing. |
2136 | If the double-quoted expansion occurs within a word, the expansion of | |
2137 | the first parameter is joined with the beginning part of the original | |
2138 | word, and the expansion of the last parameter is joined with the last | |
2139 | part of the original word. | |
2140 | This is analogous to the expansion | |
ccc6cda3 JA |
2141 | of the special parameters \fB*\fP and \fB@\fP (see |
2142 | .B Special Parameters | |
2143 | above). ${#\fIname\fP[\fIsubscript\fP]} expands to the length of | |
2144 | ${\fIname\fP[\fIsubscript\fP]}. If \fIsubscript\fP is \fB*\fP or | |
2145 | \fB@\fP, the expansion is the number of elements in the array. | |
2146 | Referencing an array variable without a subscript is equivalent to | |
2147 | referencing element zero. | |
2148 | .PP | |
2149 | The | |
2150 | .B unset | |
bb70624e | 2151 | builtin is used to destroy arrays. \fBunset\fP \fIname\fP[\fIsubscript\fP] |
ccc6cda3 | 2152 | destroys the array element at index \fIsubscript\fP. |
a82a04b3 CR |
2153 | Care must be taken to avoid unwanted side effects caused by filename |
2154 | generation. | |
ccc6cda3 JA |
2155 | \fBunset\fP \fIname\fP, where \fIname\fP is an array, or |
2156 | \fBunset\fP \fIname\fP[\fIsubscript\fP], where | |
2157 | \fIsubscript\fP is \fB*\fP or \fB@\fP, removes the entire array. | |
2158 | .PP | |
2159 | The | |
2160 | .BR declare , | |
2161 | .BR local , | |
2162 | and | |
2163 | .B readonly | |
2164 | builtins each accept a | |
2165 | .B \-a | |
2166 | option to specify an array. The | |
2167 | .B read | |
2168 | builtin accepts a | |
2169 | .B \-a | |
2170 | option to assign a list of words read from the standard input | |
2171 | to an array. The | |
2172 | .B set | |
2173 | and | |
2174 | .B declare | |
2175 | builtins display array values in a way that allows them to be | |
2176 | reused as assignments. | |
726f6388 JA |
2177 | .SH EXPANSION |
2178 | Expansion is performed on the command line after it has been split into | |
2179 | words. There are seven kinds of expansion performed: | |
2180 | .IR "brace expansion" , | |
2181 | .IR "tilde expansion" , | |
2182 | .IR "parameter and variable expansion" , | |
2183 | .IR "command substitution" , | |
2184 | .IR "arithmetic expansion" , | |
2185 | .IR "word splitting" , | |
2186 | and | |
2187 | .IR "pathname expansion" . | |
2188 | .PP | |
2189 | The order of expansions is: brace expansion, tilde expansion, | |
ccc6cda3 JA |
2190 | parameter, variable and arithmetic expansion and |
2191 | command substitution | |
2192 | (done in a left-to-right fashion), word splitting, and pathname | |
726f6388 JA |
2193 | expansion. |
2194 | .PP | |
2195 | On systems that can support it, there is an additional expansion | |
2196 | available: \fIprocess substitution\fP. | |
2197 | .PP | |
2198 | Only brace expansion, word splitting, and pathname expansion | |
2199 | can change the number of words of the expansion; other expansions | |
2200 | expand a single word to a single word. | |
ccc6cda3 | 2201 | The only exceptions to this are the expansions of |
cce855bc | 2202 | "\fB$@\fP" and "\fB${\fP\fIname\fP\fB[@]}\fP" |
ccc6cda3 | 2203 | as explained above (see |
726f6388 JA |
2204 | .SM |
2205 | .BR PARAMETERS ). | |
2206 | .SS Brace Expansion | |
2207 | .PP | |
2208 | .I "Brace expansion" | |
2209 | is a mechanism by which arbitrary strings | |
2210 | may be generated. This mechanism is similar to | |
2211 | \fIpathname expansion\fP, but the filenames generated | |
2212 | need not exist. Patterns to be brace expanded take | |
2213 | the form of an optional | |
2214 | .IR preamble , | |
d3a24ed2 CR |
2215 | followed by either a series of comma-separated strings or |
2216 | a sequence expression between a pair of braces, followed by | |
2217 | an optional | |
cce855bc | 2218 | .IR postscript . |
ccc6cda3 | 2219 | The preamble is prefixed to each string contained |
cce855bc | 2220 | within the braces, and the postscript is then appended |
726f6388 JA |
2221 | to each resulting string, expanding left to right. |
2222 | .PP | |
2223 | Brace expansions may be nested. The results of each expanded | |
2224 | string are not sorted; left to right order is preserved. | |
2225 | For example, a\fB{\fPd,c,b\fB}\fPe expands into `ade ace abe'. | |
2226 | .PP | |
d3a24ed2 CR |
2227 | A sequence expression takes the form \fB{\fP\fIx\fP\fB..\fP\fIy\fP\fB}\fP, |
2228 | where \fIx\fP and \fIy\fP are either integers or single characters. | |
2229 | When integers are supplied, the expression expands to each number between | |
2230 | \fIx\fP and \fIy\fP, inclusive. | |
2231 | When characters are supplied, the expression expands to each character | |
2232 | lexicographically between \fIx\fP and \fIy\fP, inclusive. Note that | |
2233 | both \fIx\fP and \fIy\fP must be of the same type. | |
2234 | .PP | |
726f6388 JA |
2235 | Brace expansion is performed before any other expansions, |
2236 | and any characters special to other expansions are preserved | |
2237 | in the result. It is strictly textual. | |
2238 | .B Bash | |
2239 | does not apply any syntactic interpretation to the context of the | |
2240 | expansion or the text between the braces. | |
2241 | .PP | |
2242 | A correctly-formed brace expansion must contain unquoted opening | |
d3a24ed2 CR |
2243 | and closing braces, and at least one unquoted comma or a valid |
2244 | sequence expression. | |
726f6388 | 2245 | Any incorrectly formed brace expansion is left unchanged. |
ccc6cda3 JA |
2246 | A \fB{\fP or \fB,\fP may be quoted with a backslash to prevent its |
2247 | being considered part of a brace expression. | |
bb70624e JA |
2248 | To avoid conflicts with parameter expansion, the string \fB${\fP |
2249 | is not considered eligible for brace expansion. | |
726f6388 JA |
2250 | .PP |
2251 | This construct is typically used as shorthand when the common | |
2252 | prefix of the strings to be generated is longer than in the | |
2253 | above example: | |
2254 | .RS | |
2255 | .PP | |
2256 | mkdir /usr/local/src/bash/{old,new,dist,bugs} | |
2257 | .RE | |
2258 | or | |
2259 | .RS | |
2260 | chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}} | |
2261 | .RE | |
2262 | .PP | |
2263 | Brace expansion introduces a slight incompatibility with | |
ccc6cda3 JA |
2264 | historical versions of |
2265 | .BR sh . | |
726f6388 JA |
2266 | .B sh |
2267 | does not treat opening or closing braces specially when they | |
2268 | appear as part of a word, and preserves them in the output. | |
2269 | .B Bash | |
2270 | removes braces from words as a consequence of brace | |
2271 | expansion. For example, a word entered to | |
2272 | .B sh | |
2273 | as \fIfile{1,2}\fP | |
2274 | appears identically in the output. The same word is | |
2275 | output as | |
2276 | .I file1 file2 | |
2277 | after expansion by | |
2278 | .BR bash . | |
2279 | If strict compatibility with | |
2280 | .B sh | |
2281 | is desired, start | |
2282 | .B bash | |
2283 | with the | |
ccc6cda3 JA |
2284 | .B +B |
2285 | option or disable brace expansion with the | |
2286 | .B +B | |
726f6388 JA |
2287 | option to the |
2288 | .B set | |
2289 | command (see | |
2290 | .SM | |
2291 | .B SHELL BUILTIN COMMANDS | |
2292 | below). | |
2293 | .SS Tilde Expansion | |
2294 | .PP | |
cce855bc JA |
2295 | If a word begins with an unquoted tilde character (`\fB~\fP'), all of |
2296 | the characters preceding the first unquoted slash (or all characters, | |
2297 | if there is no unquoted slash) are considered a \fItilde-prefix\fP. | |
2298 | If none of the characters in the tilde-prefix are quoted, the | |
2299 | characters in the tilde-prefix following the tilde are treated as a | |
2300 | possible \fIlogin name\fP. | |
2301 | If this login name is the null string, the tilde is replaced with the | |
2302 | value of the shell parameter | |
726f6388 JA |
2303 | .SM |
2304 | .BR HOME . | |
2305 | If | |
2306 | .SM | |
2307 | .B HOME | |
cce855bc JA |
2308 | is unset, the home directory of the user executing the shell is |
2309 | substituted instead. | |
2310 | Otherwise, the tilde-prefix is replaced with the home directory | |
2311 | associated with the specified login name. | |
726f6388 | 2312 | .PP |
cce855bc | 2313 | If the tilde-prefix is a `~+', the value of the shell variable |
726f6388 JA |
2314 | .SM |
2315 | .B PWD | |
cce855bc JA |
2316 | replaces the tilde-prefix. |
2317 | If the tilde-prefix is a `~\-', the value of the shell variable | |
2318 | .SM | |
2319 | .BR OLDPWD , | |
2320 | if it is set, is substituted. | |
2321 | If the characters following the tilde in the tilde-prefix consist | |
2322 | of a number \fIN\fP, optionally prefixed | |
2323 | by a `+' or a `\-', the tilde-prefix is replaced with the corresponding | |
2324 | element from the directory stack, as it would be displayed by the | |
2325 | .B dirs | |
2326 | builtin invoked with the tilde-prefix as an argument. | |
2327 | If the characters following the tilde in the tilde-prefix consist of a | |
2328 | number without a leading `+' or `\-', `+' is assumed. | |
2329 | .PP | |
2330 | If the login name is invalid, or the tilde expansion fails, the word | |
2331 | is unchanged. | |
726f6388 | 2332 | .PP |
cce855bc JA |
2333 | Each variable assignment is checked for unquoted tilde-prefixes immediately |
2334 | following a | |
726f6388 | 2335 | .B : |
43df7bbb | 2336 | or the first |
726f6388 | 2337 | .BR = . |
cce855bc JA |
2338 | In these cases, tilde expansion is also performed. |
2339 | Consequently, one may use file names with tildes in assignments to | |
726f6388 JA |
2340 | .SM |
2341 | .BR PATH , | |
2342 | .SM | |
2343 | .BR MAILPATH , | |
2344 | and | |
2345 | .SM | |
2346 | .BR CDPATH , | |
2347 | and the shell assigns the expanded value. | |
2348 | .SS Parameter Expansion | |
2349 | .PP | |
2350 | The `\fB$\fP' character introduces parameter expansion, | |
2351 | command substitution, or arithmetic expansion. The parameter name | |
2352 | or symbol to be expanded may be enclosed in braces, which | |
2353 | are optional but serve to protect the variable to be expanded from | |
2354 | characters immediately following it which could be | |
2355 | interpreted as part of the name. | |
2356 | .PP | |
cce855bc JA |
2357 | When braces are used, the matching ending brace is the first `\fB}\fP' |
2358 | not escaped by a backslash or within a quoted string, and not within an | |
f75912ae | 2359 | embedded arithmetic expansion, command substitution, or parameter |
cce855bc JA |
2360 | expansion. |
2361 | .PP | |
726f6388 JA |
2362 | .PD 0 |
2363 | .TP | |
2364 | ${\fIparameter\fP} | |
2365 | The value of \fIparameter\fP is substituted. The braces are required | |
2366 | when | |
2367 | .I parameter | |
2368 | is a positional parameter with more than one digit, | |
2369 | or when | |
2370 | .I parameter | |
2371 | is followed by a character which is not to be | |
2372 | interpreted as part of its name. | |
2373 | .PD | |
2374 | .PP | |
ccc6cda3 JA |
2375 | If the first character of \fIparameter\fP is an exclamation point, |
2376 | a level of variable indirection is introduced. | |
2377 | \fBBash\fP uses the value of the variable formed from the rest of | |
2378 | \fIparameter\fP as the name of the variable; this variable is then | |
bb70624e | 2379 | expanded and that value is used in the rest of the substitution, rather |
ccc6cda3 JA |
2380 | than the value of \fIparameter\fP itself. |
2381 | This is known as \fIindirect expansion\fP. | |
d3a24ed2 CR |
2382 | The exceptions to this are the expansions of ${!\fIprefix\fP*} and |
2383 | ${\fB!\fP\fIname\fP[\fI@\fP]} described below. | |
2384 | The exclamation point must immediately follow the left brace in order to | |
2385 | introduce indirection. | |
ccc6cda3 | 2386 | .PP |
726f6388 JA |
2387 | In each of the cases below, \fIword\fP is subject to tilde expansion, |
2388 | parameter expansion, command substitution, and arithmetic expansion. | |
ccc6cda3 JA |
2389 | When not performing substring expansion, \fBbash\fP tests for a parameter |
2390 | that is unset or null; omitting the colon results in a test only for a | |
2391 | parameter that is unset. | |
726f6388 JA |
2392 | .PP |
2393 | .PD 0 | |
2394 | .TP | |
2395 | ${\fIparameter\fP\fB:\-\fP\fIword\fP} | |
2396 | \fBUse Default Values\fP. If | |
2397 | .I parameter | |
2398 | is unset or null, the expansion of | |
2399 | .I word | |
2400 | is substituted. Otherwise, the value of | |
2401 | .I parameter | |
2402 | is substituted. | |
2403 | .TP | |
2404 | ${\fIparameter\fP\fB:=\fP\fIword\fP} | |
2405 | \fBAssign Default Values\fP. | |
2406 | If | |
2407 | .I parameter | |
2408 | is unset or null, the expansion of | |
2409 | .I word | |
2410 | is assigned to | |
2411 | .IR parameter . | |
2412 | The value of | |
2413 | .I parameter | |
2414 | is then substituted. Positional parameters and special parameters may | |
2415 | not be assigned to in this way. | |
2416 | .TP | |
2417 | ${\fIparameter\fP\fB:?\fP\fIword\fP} | |
2418 | \fBDisplay Error if Null or Unset\fP. | |
2419 | If | |
2420 | .I parameter | |
2421 | is null or unset, the expansion of \fIword\fP (or a message to that effect | |
2422 | if | |
2423 | .I word | |
2424 | is not present) is written to the standard error and the shell, if it | |
2425 | is not interactive, exits. Otherwise, the value of \fIparameter\fP is | |
2426 | substituted. | |
2427 | .TP | |
2428 | ${\fIparameter\fP\fB:+\fP\fIword\fP} | |
2429 | \fBUse Alternate Value\fP. | |
2430 | If | |
2431 | .I parameter | |
2432 | is null or unset, nothing is substituted, otherwise the expansion of | |
2433 | .I word | |
2434 | is substituted. | |
2435 | .TP | |
ccc6cda3 | 2436 | ${\fIparameter\fP\fB:\fP\fIoffset\fP} |
7117c2d2 | 2437 | .PD 0 |
ccc6cda3 JA |
2438 | .TP |
2439 | ${\fIparameter\fP\fB:\fP\fIoffset\fP\fB:\fP\fIlength\fP} | |
2440 | .PD | |
2441 | \fBSubstring Expansion.\fP | |
bb70624e JA |
2442 | Expands to up to \fIlength\fP characters of \fIparameter\fP |
2443 | starting at the character specified by \fIoffset\fP. | |
ccc6cda3 | 2444 | If \fIlength\fP is omitted, expands to the substring of |
bb70624e | 2445 | \fIparameter\fP starting at the character specified by \fIoffset\fP. |
ccc6cda3 JA |
2446 | \fIlength\fP and \fIoffset\fP are arithmetic expressions (see |
2447 | .SM | |
2448 | .B | |
2449 | ARITHMETIC EVALUATION | |
2450 | below). | |
2451 | \fIlength\fP must evaluate to a number greater than or equal to zero. | |
2452 | If \fIoffset\fP evaluates to a number less than zero, the value | |
2453 | is used as an offset from the end of the value of \fIparameter\fP. | |
2454 | If \fIparameter\fP is \fB@\fP, the result is \fIlength\fP positional | |
2455 | parameters beginning at \fIoffset\fP. | |
2456 | If \fIparameter\fP is an array name indexed by @ or *, | |
2457 | the result is the \fIlength\fP | |
2458 | members of the array beginning with ${\fIparameter\fP[\fIoffset\fP]}. | |
ec2199bd CR |
2459 | A negative \fIoffset\fP is taken relative to one greater than the maximum |
2460 | index of the specified array. | |
2461 | Note that a negative offset must be separated from the colon by at least | |
2462 | one space to avoid being confused with the :- expansion. | |
cce855bc | 2463 | Substring indexing is zero-based unless the positional parameters |
d3ad40de CR |
2464 | are used, in which case the indexing starts at 1 by default. |
2465 | If \fIoffset\fP is 0, and the positional parameters are used, \fB$0\fP is | |
2466 | prefixed to the list. | |
ccc6cda3 | 2467 | .TP |
bb70624e | 2468 | ${\fB!\fP\fIprefix\fP\fB*\fP} |
d3a24ed2 CR |
2469 | .PD 0 |
2470 | .TP | |
2471 | ${\fB!\fP\fIprefix\fP\fB@\fP} | |
2472 | .PD | |
bb70624e JA |
2473 | Expands to the names of variables whose names begin with \fIprefix\fP, |
2474 | separated by the first character of the | |
2475 | .SM | |
2476 | .B IFS | |
2477 | special variable. | |
d3ad40de CR |
2478 | When \fI@\fP is used and the expansion appears within double quotes, each |
2479 | variable name expands to a separate word. | |
bb70624e | 2480 | .TP |
d3a24ed2 CR |
2481 | ${\fB!\fP\fIname\fP[\fI@\fP]} |
2482 | .PD 0 | |
2483 | .TP | |
2484 | ${\fB!\fP\fIname\fP[\fI*\fP]} | |
2485 | .PD | |
2486 | If \fIname\fP is an array variable, expands to the list of array indices | |
2487 | (keys) assigned in \fIname\fP. | |
2488 | If \fIname\fP is not an array, expands to 0 if \fIname\fP is set and null | |
2489 | otherwise. | |
2490 | When \fI@\fP is used and the expansion appears within double quotes, each | |
2491 | key expands to a separate word. | |
2492 | .TP | |
726f6388 JA |
2493 | ${\fB#\fP\fIparameter\fP} |
2494 | The length in characters of the value of \fIparameter\fP is substituted. | |
ccc6cda3 JA |
2495 | If |
2496 | .I parameter | |
2497 | is | |
726f6388 JA |
2498 | .B * |
2499 | or | |
2500 | .BR @ , | |
cce855bc | 2501 | the value substituted is the number of positional parameters. |
ccc6cda3 JA |
2502 | If |
2503 | .I parameter | |
2504 | is an array name subscripted by | |
726f6388 | 2505 | .B * |
ccc6cda3 JA |
2506 | or |
2507 | .BR @ , | |
cce855bc | 2508 | the value substituted is the number of elements in the array. |
726f6388 | 2509 | .TP |
726f6388 | 2510 | ${\fIparameter\fP\fB#\fP\fIword\fP} |
7117c2d2 | 2511 | .PD 0 |
726f6388 JA |
2512 | .TP |
2513 | ${\fIparameter\fP\fB##\fP\fIword\fP} | |
2514 | .PD | |
2515 | The | |
2516 | .I word | |
2517 | is expanded to produce a pattern just as in pathname | |
2518 | expansion. If the pattern matches the beginning of | |
2519 | the value of | |
2520 | .IR parameter , | |
cce855bc | 2521 | then the result of the expansion is the expanded value of |
726f6388 | 2522 | .I parameter |
ccc6cda3 JA |
2523 | with the shortest matching pattern (the ``\fB#\fP'' case) or the |
2524 | longest matching pattern (the ``\fB##\fP'' case) deleted. | |
2525 | If | |
2526 | .I parameter | |
2527 | is | |
2528 | .B @ | |
2529 | or | |
2530 | .BR * , | |
2531 | the pattern removal operation is applied to each positional | |
2532 | parameter in turn, and the expansion is the resultant list. | |
2533 | If | |
2534 | .I parameter | |
2535 | is an array variable subscripted with | |
2536 | .B @ | |
2537 | or | |
2538 | .BR * , | |
2539 | the pattern removal operation is applied to each member of the | |
2540 | array in turn, and the expansion is the resultant list. | |
726f6388 | 2541 | .TP |
726f6388 | 2542 | ${\fIparameter\fP\fB%\fP\fIword\fP} |
7117c2d2 | 2543 | .PD 0 |
726f6388 JA |
2544 | .TP |
2545 | ${\fIparameter\fP\fB%%\fP\fIword\fP} | |
2546 | .PD | |
2547 | The \fIword\fP is expanded to produce a pattern just as in | |
ccc6cda3 | 2548 | pathname expansion. |
cce855bc | 2549 | If the pattern matches a trailing portion of the expanded value of |
726f6388 | 2550 | .IR parameter , |
cce855bc | 2551 | then the result of the expansion is the expanded value of |
726f6388 | 2552 | .I parameter |
ccc6cda3 JA |
2553 | with the shortest matching pattern (the ``\fB%\fP'' case) or the |
2554 | longest matching pattern (the ``\fB%%\fP'' case) deleted. | |
2555 | If | |
2556 | .I parameter | |
2557 | is | |
2558 | .B @ | |
2559 | or | |
2560 | .BR * , | |
2561 | the pattern removal operation is applied to each positional | |
2562 | parameter in turn, and the expansion is the resultant list. | |
2563 | If | |
2564 | .I parameter | |
2565 | is an array variable subscripted with | |
2566 | .B @ | |
2567 | or | |
2568 | .BR * , | |
2569 | the pattern removal operation is applied to each member of the | |
2570 | array in turn, and the expansion is the resultant list. | |
2571 | .TP | |
ccc6cda3 | 2572 | ${\fIparameter\fP\fB/\fP\fIpattern\fP\fB/\fP\fIstring\fP} |
ccc6cda3 JA |
2573 | The \fIpattern\fP is expanded to produce a pattern just as in |
2574 | pathname expansion. | |
2575 | \fIParameter\fP is expanded and the longest match of \fIpattern\fP | |
2576 | against its value is replaced with \fIstring\fP. | |
e6598ba4 | 2577 | If \fIpattern\fP begins with \fB/\fP, all matches of \fIpattern\fP are |
dc8fbaf9 | 2578 | replaced with \fIstring\fP. Normally only the first match is replaced. |
ccc6cda3 | 2579 | If \fIpattern\fP begins with \fB#\fP, it must match at the beginning |
b72432fd | 2580 | of the expanded value of \fIparameter\fP. |
ccc6cda3 | 2581 | If \fIpattern\fP begins with \fB%\fP, it must match at the end |
b72432fd | 2582 | of the expanded value of \fIparameter\fP. |
ccc6cda3 JA |
2583 | If \fIstring\fP is null, matches of \fIpattern\fP are deleted |
2584 | and the \fB/\fP following \fIpattern\fP may be omitted. | |
2585 | If | |
2586 | .I parameter | |
2587 | is | |
2588 | .B @ | |
2589 | or | |
2590 | .BR * , | |
2591 | the substitution operation is applied to each positional | |
2592 | parameter in turn, and the expansion is the resultant list. | |
2593 | If | |
2594 | .I parameter | |
2595 | is an array variable subscripted with | |
2596 | .B @ | |
2597 | or | |
2598 | .BR * , | |
2599 | the substitution operation is applied to each member of the | |
2600 | array in turn, and the expansion is the resultant list. | |
726f6388 JA |
2601 | .SS Command Substitution |
2602 | .PP | |
cce855bc | 2603 | \fICommand substitution\fP allows the output of a command to replace |
726f6388 JA |
2604 | the command name. There are two forms: |
2605 | .PP | |
2606 | .RS | |
2607 | .PP | |
2608 | \fB$(\fP\fIcommand\fP\|\fB)\fP | |
2609 | .RE | |
2610 | or | |
2611 | .RS | |
3d4e09aa | 2612 | \fB\`\fP\fIcommand\fP\fB\`\fP |
726f6388 JA |
2613 | .RE |
2614 | .PP | |
ccc6cda3 | 2615 | .B Bash |
726f6388 JA |
2616 | performs the expansion by executing \fIcommand\fP and |
2617 | replacing the command substitution with the standard output of the | |
2618 | command, with any trailing newlines deleted. | |
cce855bc JA |
2619 | Embedded newlines are not deleted, but they may be removed during |
2620 | word splitting. | |
2621 | The command substitution \fB$(cat \fIfile\fP)\fR can be replaced by | |
2622 | the equivalent but faster \fB$(< \fIfile\fP)\fR. | |
726f6388 | 2623 | .PP |
ccc6cda3 | 2624 | When the old-style backquote form of substitution is used, |
726f6388 JA |
2625 | backslash retains its literal meaning except when followed by |
2626 | .BR $ , | |
3d4e09aa | 2627 | .BR \` , |
726f6388 JA |
2628 | or |
2629 | .BR \e . | |
cce855bc JA |
2630 | The first backquote not preceded by a backslash terminates the |
2631 | command substitution. | |
726f6388 JA |
2632 | When using the $(\^\fIcommand\fP\|) form, all characters between the |
2633 | parentheses make up the command; none are treated specially. | |
2634 | .PP | |
cce855bc | 2635 | Command substitutions may be nested. To nest when using the backquoted form, |
726f6388 JA |
2636 | escape the inner backquotes with backslashes. |
2637 | .PP | |
2638 | If the substitution appears within double quotes, word splitting and | |
2639 | pathname expansion are not performed on the results. | |
2640 | .SS Arithmetic Expansion | |
2641 | .PP | |
2642 | Arithmetic expansion allows the evaluation of an arithmetic expression | |
ccc6cda3 | 2643 | and the substitution of the result. The format for arithmetic expansion is: |
726f6388 JA |
2644 | .RS |
2645 | .PP | |
726f6388 JA |
2646 | \fB$((\fP\fIexpression\fP\fB))\fP |
2647 | .RE | |
2648 | .PP | |
2649 | The | |
2650 | .I expression | |
2651 | is treated as if it were within double quotes, but a double quote | |
ccc6cda3 JA |
2652 | inside the parentheses is not treated specially. |
2653 | All tokens in the expression undergo parameter expansion, string | |
2654 | expansion, command substitution, and quote removal. | |
d3a24ed2 | 2655 | Arithmetic expansions may be nested. |
726f6388 JA |
2656 | .PP |
2657 | The evaluation is performed according to the rules listed below under | |
2658 | .SM | |
2659 | .BR "ARITHMETIC EVALUATION" . | |
2660 | If | |
2661 | .I expression | |
2662 | is invalid, | |
2663 | .B bash | |
2664 | prints a message indicating failure and no substitution occurs. | |
2665 | .SS Process Substitution | |
2666 | .PP | |
2667 | \fIProcess substitution\fP is supported on systems that support named | |
2668 | pipes (\fIFIFOs\fP) or the \fB/dev/fd\fP method of naming open files. | |
2669 | It takes the form of | |
2670 | \fB<(\fP\fIlist\^\fP\fB)\fP | |
2671 | or | |
2672 | \fB>(\fP\fIlist\^\fP\fB)\fP. | |
2673 | The process \fIlist\fP is run with its input or output connected to a | |
2674 | \fIFIFO\fP or some file in \fB/dev/fd\fP. The name of this file is | |
2675 | passed as an argument to the current command as the result of the | |
2676 | expansion. If the \fB>(\fP\fIlist\^\fP\fB)\fP form is used, writing to | |
2677 | the file will provide input for \fIlist\fP. If the | |
2678 | \fB<(\fP\fIlist\^\fP\fB)\fP form is used, the file passed as an | |
2679 | argument should be read to obtain the output of \fIlist\fP. | |
2680 | .PP | |
bb70624e | 2681 | When available, process substitution is performed |
ccc6cda3 JA |
2682 | simultaneously with parameter and variable expansion, |
2683 | command substitution, | |
2684 | and arithmetic expansion. | |
726f6388 JA |
2685 | .SS Word Splitting |
2686 | .PP | |
2687 | The shell scans the results of | |
2688 | parameter expansion, | |
2689 | command substitution, | |
2690 | and | |
2691 | arithmetic expansion | |
2692 | that did not occur within double quotes for | |
2693 | .IR "word splitting" . | |
2694 | .PP | |
2695 | The shell treats each character of | |
2696 | .SM | |
2697 | .B IFS | |
2698 | as a delimiter, and splits the results of the other | |
ccc6cda3 | 2699 | expansions into words on these characters. If |
726f6388 JA |
2700 | .SM |
2701 | .B IFS | |
ccc6cda3 JA |
2702 | is unset, or its |
2703 | value is exactly | |
726f6388 JA |
2704 | .BR <space><tab><newline> , |
2705 | the default, then | |
d3ad40de CR |
2706 | sequences of |
2707 | .BR <space> , | |
2708 | .BR <tab> , | |
2709 | and | |
2710 | .B <newline> | |
2711 | at the beginning and end of the results of the previous | |
2712 | expansions are ignored, and | |
726f6388 JA |
2713 | any sequence of |
2714 | .SM | |
2715 | .B IFS | |
d3ad40de CR |
2716 | characters not at the beginning or end serves to delimit words. |
2717 | If | |
726f6388 JA |
2718 | .SM |
2719 | .B IFS | |
2720 | has a value other than the default, then sequences of | |
2721 | the whitespace characters | |
2722 | .B space | |
2723 | and | |
2724 | .B tab | |
2725 | are ignored at the beginning and end of the | |
2726 | word, as long as the whitespace character is in the | |
2727 | value of | |
2728 | .SM | |
2729 | .BR IFS | |
2730 | (an | |
2731 | .SM | |
2732 | .B IFS | |
2733 | whitespace character). | |
2734 | Any character in | |
2735 | .SM | |
2736 | .B IFS | |
2737 | that is not | |
2738 | .SM | |
2739 | .B IFS | |
2740 | whitespace, along with any adjacent | |
2741 | .SM | |
2742 | .B IFS | |
2743 | whitespace characters, delimits a field. | |
2744 | A sequence of | |
2745 | .SM | |
2746 | .B IFS | |
2747 | whitespace characters is also treated as a delimiter. | |
2748 | If the value of | |
2749 | .SM | |
2750 | .B IFS | |
2751 | is null, no word splitting occurs. | |
726f6388 | 2752 | .PP |
20587658 | 2753 | Explicit null arguments (\^\f3"\^"\fP or \^\f3\(aq\^\(aq\fP\^) are retained. |
ccc6cda3 | 2754 | Unquoted implicit null arguments, resulting from the expansion of |
bb70624e | 2755 | parameters that have no values, are removed. |
ccc6cda3 JA |
2756 | If a parameter with no value is expanded within double quotes, a |
2757 | null argument results and is retained. | |
726f6388 JA |
2758 | .PP |
2759 | Note that if no expansion occurs, no splitting | |
2760 | is performed. | |
2761 | .SS Pathname Expansion | |
2762 | .PP | |
2763 | After word splitting, | |
2764 | unless the | |
2765 | .B \-f | |
2766 | option has been set, | |
2767 | .B bash | |
ccc6cda3 | 2768 | scans each word for the characters |
726f6388 JA |
2769 | .BR * , |
2770 | .BR ? , | |
2771 | and | |
2772 | .BR [ . | |
2773 | If one of these characters appears, then the word is | |
2774 | regarded as a | |
2775 | .IR pattern , | |
2776 | and replaced with an alphabetically sorted list of | |
ccc6cda3 JA |
2777 | file names matching the pattern. |
2778 | If no matching file names are found, | |
2779 | and the shell option | |
2780 | .B nullglob | |
2781 | is disabled, the word is left unchanged. | |
cce855bc JA |
2782 | If the |
2783 | .B nullglob | |
2784 | option is set, and no matches are found, | |
726f6388 | 2785 | the word is removed. |
d3a24ed2 CR |
2786 | If the |
2787 | .B failglob | |
2788 | shell option is set, and no matches are found, an error message | |
2789 | is printed and the command is not executed. | |
cce855bc JA |
2790 | If the shell option |
2791 | .B nocaseglob | |
2792 | is enabled, the match is performed without regard to the case | |
2793 | of alphabetic characters. | |
ccc6cda3 | 2794 | When a pattern is used for pathname expansion, |
726f6388 JA |
2795 | the character |
2796 | .B ``.'' | |
2797 | at the start of a name or immediately following a slash | |
ccc6cda3 JA |
2798 | must be matched explicitly, unless the shell option |
2799 | .B dotglob | |
2800 | is set. | |
cce855bc JA |
2801 | When matching a pathname, the slash character must always be |
2802 | matched explicitly. | |
ccc6cda3 | 2803 | In other cases, the |
726f6388 JA |
2804 | .B ``.'' |
2805 | character is not treated specially. | |
ccc6cda3 JA |
2806 | See the description of |
2807 | .B shopt | |
2808 | below under | |
2809 | .SM | |
2810 | .B SHELL BUILTIN COMMANDS | |
2811 | for a description of the | |
cce855bc JA |
2812 | .BR nocaseglob , |
2813 | .BR nullglob , | |
d3a24ed2 | 2814 | .BR failglob , |
ccc6cda3 JA |
2815 | and |
2816 | .B dotglob | |
2817 | shell options. | |
2818 | .PP | |
2819 | The | |
2820 | .SM | |
2821 | .B GLOBIGNORE | |
2822 | shell variable may be used to restrict the set of file names matching a | |
2823 | .IR pattern . | |
2824 | If | |
2825 | .SM | |
2826 | .B GLOBIGNORE | |
2827 | is set, each matching file name that also matches one of the patterns in | |
2828 | .SM | |
2829 | .B GLOBIGNORE | |
2830 | is removed from the list of matches. | |
2831 | The file names | |
2832 | .B ``.'' | |
2833 | and | |
2834 | .B ``..'' | |
d3a24ed2 | 2835 | are always ignored when |
ccc6cda3 JA |
2836 | .SM |
2837 | .B GLOBIGNORE | |
d3a24ed2 | 2838 | is set and not null. However, setting |
ccc6cda3 JA |
2839 | .SM |
2840 | .B GLOBIGNORE | |
d3a24ed2 | 2841 | to a non-null value has the effect of enabling the |
ccc6cda3 JA |
2842 | .B dotglob |
2843 | shell option, so all other file names beginning with a | |
2844 | .B ``.'' | |
2845 | will match. | |
2846 | To get the old behavior of ignoring file names beginning with a | |
2847 | .BR ``.'' , | |
2848 | make | |
2849 | .B ``.*'' | |
2850 | one of the patterns in | |
2851 | .SM | |
2852 | .BR GLOBIGNORE . | |
2853 | The | |
2854 | .B dotglob | |
2855 | option is disabled when | |
2856 | .SM | |
2857 | .B GLOBIGNORE | |
2858 | is unset. | |
726f6388 | 2859 | .PP |
cce855bc JA |
2860 | \fBPattern Matching\fP |
2861 | .PP | |
2862 | Any character that appears in a pattern, other than the special pattern | |
2863 | characters described below, matches itself. The NUL character may not | |
d3a24ed2 CR |
2864 | occur in a pattern. A backslash escapes the following character; the |
2865 | escaping backslash is discarded when matching. | |
2866 | The special pattern characters must be quoted if | |
cce855bc JA |
2867 | they are to be matched literally. |
2868 | .PP | |
726f6388 JA |
2869 | The special pattern characters have the following meanings: |
2870 | .PP | |
2871 | .PD 0 | |
2872 | .TP | |
2873 | .B * | |
2874 | Matches any string, including the null string. | |
2875 | .TP | |
2876 | .B ? | |
2877 | Matches any single character. | |
2878 | .TP | |
2879 | .B [...] | |
2880 | Matches any one of the enclosed characters. A pair of characters | |
28ef6c31 JA |
2881 | separated by a hyphen denotes a |
2882 | \fIrange expression\fP; | |
2883 | any character that sorts between those two characters, inclusive, | |
2884 | using the current locale's collating sequence and character set, | |
726f6388 JA |
2885 | is matched. If the first character following the |
2886 | .B [ | |
2887 | is a | |
2888 | .B ! | |
2889 | or a | |
2890 | .B ^ | |
ccc6cda3 | 2891 | then any character not enclosed is matched. |
28ef6c31 JA |
2892 | The sorting order of characters in range expressions is determined by |
2893 | the current locale and the value of the \fBLC_COLLATE\fP shell variable, | |
2894 | if set. | |
ccc6cda3 | 2895 | A |
726f6388 | 2896 | .B \- |
726f6388 JA |
2897 | may be matched by including it as the first or last character |
2898 | in the set. | |
ccc6cda3 JA |
2899 | A |
2900 | .B ] | |
2901 | may be matched by including it as the first character | |
2902 | in the set. | |
cce855bc JA |
2903 | .br |
2904 | .if t .sp 0.5 | |
2905 | .if n .sp 1 | |
2906 | Within | |
2907 | .B [ | |
2908 | and | |
2909 | .BR ] , | |
2910 | \fIcharacter classes\fP can be specified using the syntax | |
2911 | \fB[:\fP\fIclass\fP\fB:]\fP, where \fIclass\fP is one of the | |
ac18b312 | 2912 | following classes defined in the POSIX standard: |
cce855bc JA |
2913 | .PP |
2914 | .RS | |
2915 | .B | |
7117c2d2 JA |
2916 | .if n alnum alpha ascii blank cntrl digit graph lower print punct space upper word xdigit |
2917 | .if t alnum alpha ascii blank cntrl digit graph lower print punct space upper word xdigit | |
cce855bc JA |
2918 | .br |
2919 | A character class matches any character belonging to that class. | |
7117c2d2 | 2920 | The \fBword\fP character class matches letters, digits, and the character _. |
cce855bc JA |
2921 | .br |
2922 | .if t .sp 0.5 | |
2923 | .if n .sp 1 | |
2924 | Within | |
2925 | .B [ | |
2926 | and | |
2927 | .BR ] , | |
2928 | an \fIequivalence class\fP can be specified using the syntax | |
2929 | \fB[=\fP\fIc\fP\fB=]\fP, which matches all characters with the | |
2930 | same collation weight (as defined by the current locale) as | |
2931 | the character \fIc\fP. | |
2932 | .br | |
2933 | .if t .sp 0.5 | |
2934 | .if n .sp 1 | |
2935 | Within | |
2936 | .B [ | |
2937 | and | |
2938 | .BR ] , | |
2939 | the syntax \fB[.\fP\fIsymbol\fP\fB.]\fP matches the collating symbol | |
2940 | \fIsymbol\fP. | |
2941 | .RE | |
2942 | .PD | |
2943 | .PP | |
2944 | If the \fBextglob\fP shell option is enabled using the \fBshopt\fP | |
2945 | builtin, several extended pattern matching operators are recognized. | |
bb70624e | 2946 | In the following description, a \fIpattern-list\fP is a list of one |
cce855bc JA |
2947 | or more patterns separated by a \fB|\fP. |
2948 | Composite patterns may be formed using one or more of the following | |
2949 | sub-patterns: | |
2950 | .sp 1 | |
2951 | .PD 0 | |
2952 | .RS | |
2953 | .TP | |
2954 | \fB?(\fP\^\fIpattern-list\^\fP\fB)\fP | |
2955 | Matches zero or one occurrence of the given patterns | |
2956 | .TP | |
2957 | \fB*(\fP\^\fIpattern-list\^\fP\fB)\fP | |
2958 | Matches zero or more occurrences of the given patterns | |
2959 | .TP | |
2960 | \fB+(\fP\^\fIpattern-list\^\fP\fB)\fP | |
2961 | Matches one or more occurrences of the given patterns | |
2962 | .TP | |
2963 | \fB@(\fP\^\fIpattern-list\^\fP\fB)\fP | |
43df7bbb | 2964 | Matches one of the given patterns |
cce855bc JA |
2965 | .TP |
2966 | \fB!(\fP\^\fIpattern-list\^\fP\fB)\fP | |
2967 | Matches anything except one of the given patterns | |
2968 | .RE | |
726f6388 JA |
2969 | .PD |
2970 | .SS Quote Removal | |
2971 | .PP | |
2972 | After the preceding expansions, all unquoted occurrences of the | |
2973 | characters | |
2974 | .BR \e , | |
20587658 | 2975 | .BR \(aq , |
ccc6cda3 JA |
2976 | and \^\f3"\fP\^ that did not result from one of the above |
2977 | expansions are removed. | |
726f6388 JA |
2978 | .SH REDIRECTION |
2979 | Before a command is executed, its input and output | |
2980 | may be | |
2981 | .I redirected | |
2982 | using a special notation interpreted by the shell. | |
2983 | Redirection may also be used to open and close files for the | |
2984 | current shell execution environment. The following redirection | |
2985 | operators may precede or appear anywhere within a | |
2986 | .I simple command | |
2987 | or may follow a | |
2988 | .IR command . | |
2989 | Redirections are processed in the order they appear, from | |
2990 | left to right. | |
2991 | .PP | |
2992 | In the following descriptions, if the file descriptor number is | |
2993 | omitted, and the first character of the redirection operator is | |
2994 | .BR < , | |
2995 | the redirection refers to the standard input (file descriptor | |
2996 | 0). If the first character of the redirection operator is | |
2997 | .BR > , | |
2998 | the redirection refers to the standard output (file descriptor | |
2999 | 1). | |
3000 | .PP | |
cce855bc JA |
3001 | The word following the redirection operator in the following |
3002 | descriptions, unless otherwise noted, is subjected to brace expansion, | |
3003 | tilde expansion, parameter expansion, command substitution, arithmetic | |
bb70624e | 3004 | expansion, quote removal, pathname expansion, and word splitting. |
cce855bc | 3005 | If it expands to more than one word, |
726f6388 JA |
3006 | .B bash |
3007 | reports an error. | |
3008 | .PP | |
3009 | Note that the order of redirections is significant. For example, | |
3010 | the command | |
3011 | .RS | |
3012 | .PP | |
3013 | ls \fB>\fP dirlist 2\fB>&\fP1 | |
3014 | .RE | |
3015 | .PP | |
3016 | directs both standard output and standard error to the file | |
3017 | .IR dirlist , | |
3018 | while the command | |
3019 | .RS | |
3020 | .PP | |
3021 | ls 2\fB>&\fP1 \fB>\fP dirlist | |
3022 | .RE | |
3023 | .PP | |
3024 | directs only the standard output to file | |
3025 | .IR dirlist , | |
3026 | because the standard error was duplicated as standard output | |
3027 | before the standard output was redirected to | |
3028 | .IR dirlist . | |
cce855bc | 3029 | .PP |
bb70624e JA |
3030 | \fBBash\fP handles several filenames specially when they are used in |
3031 | redirections, as described in the following table: | |
3032 | .RS | |
3033 | .PP | |
3034 | .PD 0 | |
3035 | .TP | |
3036 | .B /dev/fd/\fIfd\fP | |
3037 | If \fIfd\fP is a valid integer, file descriptor \fIfd\fP is duplicated. | |
3038 | .TP | |
3039 | .B /dev/stdin | |
3040 | File descriptor 0 is duplicated. | |
3041 | .TP | |
3042 | .B /dev/stdout | |
3043 | File descriptor 1 is duplicated. | |
3044 | .TP | |
3045 | .B /dev/stderr | |
3046 | File descriptor 2 is duplicated. | |
3047 | .TP | |
3048 | .B /dev/tcp/\fIhost\fP/\fIport\fP | |
3049 | If \fIhost\fP is a valid hostname or Internet address, and \fIport\fP | |
f73dda09 JA |
3050 | is an integer port number or service name, \fBbash\fP attempts to open |
3051 | a TCP connection to the corresponding socket. | |
bb70624e JA |
3052 | .TP |
3053 | .B /dev/udp/\fIhost\fP/\fIport\fP | |
3054 | If \fIhost\fP is a valid hostname or Internet address, and \fIport\fP | |
f73dda09 JA |
3055 | is an integer port number or service name, \fBbash\fP attempts to open |
3056 | a UDP connection to the corresponding socket. | |
bb70624e JA |
3057 | .PD |
3058 | .RE | |
3059 | .PP | |
cce855bc | 3060 | A failure to open or create a file causes the redirection to fail. |
cac4cdbf CR |
3061 | .PP |
3062 | Redirections using file descriptors greater than 9 should be used with | |
3063 | care, as they may conflict with file descriptors the shell uses | |
3064 | internally. | |
726f6388 JA |
3065 | .SS Redirecting Input |
3066 | .PP | |
3067 | Redirection of input causes the file whose name results from | |
3068 | the expansion of | |
3069 | .I word | |
3070 | to be opened for reading on file descriptor | |
3071 | .IR n , | |
3072 | or the standard input (file descriptor 0) if | |
3073 | .I n | |
3074 | is not specified. | |
3075 | .PP | |
3076 | The general format for redirecting input is: | |
3077 | .RS | |
3078 | .PP | |
3079 | [\fIn\fP]\fB<\fP\fIword\fP | |
3080 | .RE | |
3081 | .SS Redirecting Output | |
3082 | .PP | |
3083 | Redirection of output causes the file whose name results from | |
3084 | the expansion of | |
3085 | .I word | |
3086 | to be opened for writing on file descriptor | |
3087 | .IR n , | |
3088 | or the standard output (file descriptor 1) if | |
3089 | .I n | |
3090 | is not specified. If the file does not exist it is created; | |
3091 | if it does exist it is truncated to zero size. | |
3092 | .PP | |
3093 | The general format for redirecting output is: | |
3094 | .RS | |
3095 | .PP | |
3096 | [\fIn\fP]\fB>\fP\fIword\fP | |
3097 | .RE | |
3098 | .PP | |
3099 | If the redirection operator is | |
ccc6cda3 JA |
3100 | .BR > , |
3101 | and the | |
cce855bc | 3102 | .B noclobber |
ccc6cda3 JA |
3103 | option to the |
3104 | .B set | |
bb70624e | 3105 | builtin has been enabled, the redirection will fail if the file |
cce855bc JA |
3106 | whose name results from the expansion of \fIword\fP exists and is |
3107 | a regular file. | |
ccc6cda3 | 3108 | If the redirection operator is |
726f6388 | 3109 | .BR >| , |
cce855bc JA |
3110 | or the redirection operator is |
3111 | .B > | |
3112 | and the | |
3113 | .B noclobber | |
726f6388 JA |
3114 | option to the |
3115 | .B set | |
cce855bc | 3116 | builtin command is not enabled, the redirection is attempted even |
ccc6cda3 | 3117 | if the file named by \fIword\fP exists. |
726f6388 JA |
3118 | .SS Appending Redirected Output |
3119 | .PP | |
3120 | Redirection of output in this fashion | |
3121 | causes the file whose name results from | |
3122 | the expansion of | |
3123 | .I word | |
3124 | to be opened for appending on file descriptor | |
3125 | .IR n , | |
3126 | or the standard output (file descriptor 1) if | |
3127 | .I n | |
3128 | is not specified. If the file does not exist it is created. | |
3129 | .PP | |
3130 | The general format for appending output is: | |
3131 | .RS | |
3132 | .PP | |
3133 | [\fIn\fP]\fB>>\fP\fIword\fP | |
3134 | .RE | |
3135 | .PP | |
3136 | .SS Redirecting Standard Output and Standard Error | |
3137 | .PP | |
3138 | .B Bash | |
3139 | allows both the | |
3140 | standard output (file descriptor 1) and | |
3141 | the standard error output (file descriptor 2) | |
3142 | to be redirected to the file whose name is the | |
3143 | expansion of | |
3144 | .I word | |
3145 | with this construct. | |
3146 | .PP | |
3147 | There are two formats for redirecting standard output and | |
3148 | standard error: | |
3149 | .RS | |
3150 | .PP | |
3151 | \fB&>\fP\fIword\fP | |
3152 | .RE | |
3153 | and | |
3154 | .RS | |
3155 | \fB>&\fP\fIword\fP | |
3156 | .RE | |
3157 | .PP | |
3158 | Of the two forms, the first is preferred. | |
3159 | This is semantically equivalent to | |
3160 | .RS | |
3161 | .PP | |
3162 | \fB>\fP\fIword\fP 2\fB>&\fP1 | |
3163 | .RE | |
3164 | .SS Here Documents | |
3165 | .PP | |
3166 | This type of redirection instructs the shell to read input from the | |
3167 | current source until a line containing only | |
3168 | .I word | |
3169 | (with no trailing blanks) | |
3170 | is seen. All of | |
3171 | the lines read up to that point are then used as the standard | |
3172 | input for a command. | |
3173 | .PP | |
7117c2d2 | 3174 | The format of here-documents is: |
726f6388 JA |
3175 | .RS |
3176 | .PP | |
3177 | .nf | |
3178 | \fB<<\fP[\fB\-\fP]\fIword\fP | |
f73dda09 | 3179 | \fIhere-document\fP |
726f6388 JA |
3180 | \fIdelimiter\fP |
3181 | .fi | |
3182 | .RE | |
3183 | .PP | |
bb70624e JA |
3184 | No parameter expansion, command substitution, arithmetic expansion, |
3185 | or pathname expansion is performed on | |
726f6388 JA |
3186 | .IR word . |
3187 | If any characters in | |
3188 | .I word | |
3189 | are quoted, the | |
3190 | .I delimiter | |
3191 | is the result of quote removal on | |
3192 | .IR word , | |
cce855bc JA |
3193 | and the lines in the here-document are not expanded. |
3194 | If \fIword\fP is unquoted, | |
726f6388 JA |
3195 | all lines of the here-document are subjected to parameter expansion, |
3196 | command substitution, and arithmetic expansion. In the latter | |
bb70624e | 3197 | case, the character sequence |
726f6388 JA |
3198 | .B \e<newline> |
3199 | is ignored, and | |
3200 | .B \e | |
3201 | must be used to quote the characters | |
3202 | .BR \e , | |
3203 | .BR $ , | |
3204 | and | |
3d4e09aa | 3205 | .BR \` . |
726f6388 JA |
3206 | .PP |
3207 | If the redirection operator is | |
3208 | .BR <<\- , | |
3209 | then all leading tab characters are stripped from input lines and the | |
3210 | line containing | |
3211 | .IR delimiter . | |
3212 | This allows | |
3213 | here-documents within shell scripts to be indented in a | |
3214 | natural fashion. | |
7117c2d2 JA |
3215 | .SS "Here Strings" |
3216 | A variant of here documents, the format is: | |
3217 | .RS | |
3218 | .PP | |
3219 | .nf | |
3220 | \fB<<<\fP\fIword\fP | |
3221 | .fi | |
3222 | .RE | |
3223 | .PP | |
3224 | The \fIword\fP is expanded and supplied to the command on its standard | |
3225 | input. | |
726f6388 JA |
3226 | .SS "Duplicating File Descriptors" |
3227 | .PP | |
3228 | The redirection operator | |
3229 | .RS | |
3230 | .PP | |
3231 | [\fIn\fP]\fB<&\fP\fIword\fP | |
3232 | .RE | |
3233 | .PP | |
3234 | is used to duplicate input file descriptors. | |
3235 | If | |
3236 | .I word | |
3237 | expands to one or more digits, the file descriptor denoted by | |
3238 | .I n | |
cce855bc JA |
3239 | is made to be a copy of that file descriptor. |
3240 | If the digits in | |
3241 | .I word | |
3242 | do not specify a file descriptor open for input, a redirection error occurs. | |
3243 | If | |
726f6388 JA |
3244 | .I word |
3245 | evaluates to | |
3246 | .BR \- , | |
3247 | file descriptor | |
3248 | .I n | |
3249 | is closed. If | |
3250 | .I n | |
3251 | is not specified, the standard input (file descriptor 0) is used. | |
3252 | .PP | |
3253 | The operator | |
3254 | .RS | |
3255 | .PP | |
3256 | [\fIn\fP]\fB>&\fP\fIword\fP | |
3257 | .RE | |
3258 | .PP | |
3259 | is used similarly to duplicate output file descriptors. If | |
3260 | .I n | |
3261 | is not specified, the standard output (file descriptor 1) is used. | |
cce855bc JA |
3262 | If the digits in |
3263 | .I word | |
3264 | do not specify a file descriptor open for output, a redirection error occurs. | |
726f6388 JA |
3265 | As a special case, if \fIn\fP is omitted, and \fIword\fP does not |
3266 | expand to one or more digits, the standard output and standard | |
3267 | error are redirected as described previously. | |
7117c2d2 JA |
3268 | .SS "Moving File Descriptors" |
3269 | .PP | |
3270 | The redirection operator | |
3271 | .RS | |
3272 | .PP | |
3273 | [\fIn\fP]\fB<&\fP\fIdigit\fP\fB\-\fP | |
3274 | .RE | |
3275 | .PP | |
3276 | moves the file descriptor \fIdigit\fP to file descriptor | |
3277 | .IR n , | |
3278 | or the standard input (file descriptor 0) if \fIn\fP is not specified. | |
3279 | \fIdigit\fP is closed after being duplicated to \fIn\fP. | |
3280 | .PP | |
3281 | Similarly, the redirection operator | |
3282 | .RS | |
3283 | .PP | |
3284 | [\fIn\fP]\fB>&\fP\fIdigit\fP\fB\-\fP | |
3285 | .RE | |
3286 | .PP | |
3287 | moves the file descriptor \fIdigit\fP to file descriptor | |
3288 | .IR n , | |
3289 | or the standard output (file descriptor 1) if \fIn\fP is not specified. | |
726f6388 JA |
3290 | .SS "Opening File Descriptors for Reading and Writing" |
3291 | .PP | |
3292 | The redirection operator | |
3293 | .RS | |
3294 | .PP | |
3295 | [\fIn\fP]\fB<>\fP\fIword\fP | |
3296 | .RE | |
3297 | .PP | |
3298 | causes the file whose name is the expansion of | |
3299 | .I word | |
3300 | to be opened for both reading and writing on file descriptor | |
3301 | .IR n , | |
ccc6cda3 | 3302 | or on file descriptor 0 if |
726f6388 JA |
3303 | .I n |
3304 | is not specified. If the file does not exist, it is created. | |
726f6388 | 3305 | .SH ALIASES |
bb70624e | 3306 | \fIAliases\fP allow a string to be substituted for a word when it is used |
cce855bc | 3307 | as the first word of a simple command. |
bb70624e | 3308 | The shell maintains a list of aliases that may be set and unset with the |
726f6388 JA |
3309 | .B alias |
3310 | and | |
3311 | .B unalias | |
3312 | builtin commands (see | |
3313 | .SM | |
3314 | .B SHELL BUILTIN COMMANDS | |
3315 | below). | |
de8913bd | 3316 | The first word of each simple command, if unquoted, |
726f6388 JA |
3317 | is checked to see if it has an |
3318 | alias. If so, that word is replaced by the text of the alias. | |
3d4e09aa | 3319 | The characters \fB/\fP, \fB$\fP, \fB\`\fP, and \fB=\fP and |
de8913bd CR |
3320 | any of the shell \fImetacharacters\fP or quoting characters |
3321 | listed above may not appear in an alias name. | |
3322 | The replacement text may contain any valid shell input, | |
3323 | including shell metacharacters. | |
3324 | The first word of the replacement text is tested | |
726f6388 | 3325 | for aliases, but a word that is identical to an alias being expanded |
de8913bd CR |
3326 | is not expanded a second time. |
3327 | This means that one may alias | |
726f6388 JA |
3328 | .B ls |
3329 | to | |
3330 | .BR "ls \-F" , | |
3331 | for instance, and | |
3332 | .B bash | |
3333 | does not try to recursively expand the replacement text. | |
3334 | If the last character of the alias value is a | |
3335 | .IR blank , | |
3336 | then the next command | |
3337 | word following the alias is also checked for alias expansion. | |
3338 | .PP | |
3339 | Aliases are created and listed with the | |
3340 | .B alias | |
3341 | command, and removed with the | |
3342 | .B unalias | |
3343 | command. | |
3344 | .PP | |
ccc6cda3 | 3345 | There is no mechanism for using arguments in the replacement text. |
bb70624e JA |
3346 | If arguments are needed, a shell function should be used (see |
3347 | .SM | |
3348 | .B FUNCTIONS | |
3349 | below). | |
726f6388 | 3350 | .PP |
ccc6cda3 JA |
3351 | Aliases are not expanded when the shell is not interactive, unless |
3352 | the | |
3353 | .B expand_aliases | |
3354 | shell option is set using | |
3355 | .B shopt | |
3356 | (see the description of | |
3357 | .B shopt | |
3358 | under | |
3359 | .SM | |
3360 | \fBSHELL BUILTIN COMMANDS\fP | |
3361 | below). | |
726f6388 JA |
3362 | .PP |
3363 | The rules concerning the definition and use of aliases are | |
3364 | somewhat confusing. | |
3365 | .B Bash | |
3366 | always reads at least one complete line | |
3367 | of input before executing any | |
3368 | of the commands on that line. Aliases are expanded when a | |
3369 | command is read, not when it is executed. Therefore, an | |
3370 | alias definition appearing on the same line as another | |
3371 | command does not take effect until the next line of input is read. | |
ccc6cda3 | 3372 | The commands following the alias definition |
726f6388 JA |
3373 | on that line are not affected by the new alias. |
3374 | This behavior is also an issue when functions are executed. | |
cce855bc | 3375 | Aliases are expanded when a function definition is read, |
726f6388 JA |
3376 | not when the function is executed, because a function definition |
3377 | is itself a compound command. As a consequence, aliases | |
3378 | defined in a function are not available until after that | |
3379 | function is executed. To be safe, always put | |
3380 | alias definitions on a separate line, and do not use | |
3381 | .B alias | |
3382 | in compound commands. | |
3383 | .PP | |
cce855bc | 3384 | For almost every purpose, aliases are superseded by |
726f6388 | 3385 | shell functions. |
ccc6cda3 JA |
3386 | .SH FUNCTIONS |
3387 | A shell function, defined as described above under | |
3388 | .SM | |
3389 | .BR "SHELL GRAMMAR" , | |
3390 | stores a series of commands for later execution. | |
bb70624e JA |
3391 | When the name of a shell function is used as a simple command name, |
3392 | the list of commands associated with that function name is executed. | |
ccc6cda3 JA |
3393 | Functions are executed in the context of the |
3394 | current shell; no new process is created to interpret | |
3395 | them (contrast this with the execution of a shell script). | |
3396 | When a function is executed, the arguments to the | |
3397 | function become the positional parameters | |
bb70624e JA |
3398 | during its execution. |
3399 | The special parameter | |
ccc6cda3 | 3400 | .B # |
de8913bd | 3401 | is updated to reflect the change. Special parameter 0 |
bb70624e | 3402 | is unchanged. |
d3a24ed2 | 3403 | The first element of the |
bb70624e JA |
3404 | .SM |
3405 | .B FUNCNAME | |
3406 | variable is set to the name of the function while the function | |
3407 | is executing. | |
3408 | All other aspects of the shell execution | |
ccc6cda3 JA |
3409 | environment are identical between a function and its caller |
3410 | with the exception that the | |
3411 | .SM | |
3412 | .B DEBUG | |
76a8d78d CR |
3413 | and |
3414 | .B RETURN | |
3415 | traps (see the description of the | |
ccc6cda3 JA |
3416 | .B trap |
3417 | builtin under | |
3418 | .SM | |
3419 | .B SHELL BUILTIN COMMANDS | |
76a8d78d | 3420 | below) are not inherited unless the function has been given the |
7117c2d2 JA |
3421 | \fBtrace\fP attribute (see the description of the |
3422 | .SM | |
3423 | .B declare | |
d3a24ed2 CR |
3424 | builtin below) or the |
3425 | \fB\-o functrace\fP shell option has been enabled with | |
3426 | the \fBset\fP builtin | |
76a8d78d | 3427 | (in which case all functions inherit the \fBDEBUG\fP and \fBRETURN\fP traps). |
726f6388 | 3428 | .PP |
ccc6cda3 JA |
3429 | Variables local to the function may be declared with the |
3430 | .B local | |
3431 | builtin command. Ordinarily, variables and their values | |
3432 | are shared between the function and its caller. | |
726f6388 | 3433 | .PP |
ccc6cda3 JA |
3434 | If the builtin command |
3435 | .B return | |
3436 | is executed in a function, the function completes and | |
3437 | execution resumes with the next command after the function | |
d3a24ed2 CR |
3438 | call. |
3439 | Any command associated with the \fBRETURN\fP trap is executed | |
3440 | before execution resumes. | |
3441 | When a function completes, the values of the | |
ccc6cda3 JA |
3442 | positional parameters and the special parameter |
3443 | .B # | |
cce855bc | 3444 | are restored to the values they had prior to the function's |
ccc6cda3 | 3445 | execution. |
726f6388 | 3446 | .PP |
ccc6cda3 JA |
3447 | Function names and definitions may be listed with the |
3448 | .B \-f | |
726f6388 | 3449 | option to the |
ccc6cda3 JA |
3450 | .B declare |
3451 | or | |
3452 | .B typeset | |
3453 | builtin commands. The | |
3454 | .B \-F | |
3455 | option to | |
3456 | .B declare | |
3457 | or | |
3458 | .B typeset | |
d3a24ed2 CR |
3459 | will list the function names only |
3460 | (and optionally the source file and line number, if the \fBextdebug\fP | |
3461 | shell option is enabled). | |
ccc6cda3 JA |
3462 | Functions may be exported so that subshells |
3463 | automatically have them defined with the | |
3464 | .B \-f | |
3465 | option to the | |
3466 | .B export | |
3467 | builtin. | |
11a6f9a9 CR |
3468 | A function definition may be deleted using the \fB\-f\fP option to |
3469 | the | |
3470 | .B unset | |
3471 | builtin. | |
d3a24ed2 CR |
3472 | Note that shell functions and variables with the same name may result |
3473 | in multiple identically-named entries in the environment passed to the | |
3474 | shell's children. | |
3475 | Care should be taken in cases where this may cause a problem. | |
726f6388 | 3476 | .PP |
ccc6cda3 JA |
3477 | Functions may be recursive. No limit is imposed on the number |
3478 | of recursive calls. | |
cce855bc JA |
3479 | .SH "ARITHMETIC EVALUATION" |
3480 | The shell allows arithmetic expressions to be evaluated, under | |
d3a24ed2 CR |
3481 | certain circumstances (see the \fBlet\fP and \fBdeclare\fP builtin |
3482 | commands and \fBArithmetic Expansion\fP). | |
7117c2d2 | 3483 | Evaluation is done in fixed-width integers with no check for overflow, |
cce855bc | 3484 | though division by 0 is trapped and flagged as an error. |
d3a24ed2 CR |
3485 | The operators and their precedence, associativity, and values |
3486 | are the same as in the C language. | |
cce855bc JA |
3487 | The following list of operators is grouped into levels of |
3488 | equal-precedence operators. | |
3489 | The levels are listed in order of decreasing precedence. | |
726f6388 | 3490 | .PP |
cce855bc JA |
3491 | .PD 0 |
3492 | .TP | |
bb70624e JA |
3493 | .B \fIid\fP++ \fIid\fP\-\- |
3494 | variable post-increment and post-decrement | |
3495 | .TP | |
3496 | .B ++\fIid\fP \-\-\fIid\fP | |
3497 | variable pre-increment and pre-decrement | |
3498 | .TP | |
cce855bc JA |
3499 | .B \- + |
3500 | unary minus and plus | |
3501 | .TP | |
3502 | .B ! ~ | |
3503 | logical and bitwise negation | |
3504 | .TP | |
3505 | .B ** | |
3506 | exponentiation | |
3507 | .TP | |
3508 | .B * / % | |
3509 | multiplication, division, remainder | |
3510 | .TP | |
3511 | .B + \- | |
3512 | addition, subtraction | |
3513 | .TP | |
3514 | .B << >> | |
3515 | left and right bitwise shifts | |
3516 | .TP | |
3517 | .B <= >= < > | |
3518 | comparison | |
3519 | .TP | |
3520 | .B == != | |
3521 | equality and inequality | |
3522 | .TP | |
3523 | .B & | |
3524 | bitwise AND | |
3525 | .TP | |
3526 | .B ^ | |
3527 | bitwise exclusive OR | |
3528 | .TP | |
3529 | .B | | |
3530 | bitwise OR | |
3531 | .TP | |
3532 | .B && | |
3533 | logical AND | |
3534 | .TP | |
3535 | .B || | |
3536 | logical OR | |
3537 | .TP | |
3538 | .B \fIexpr\fP?\fIexpr\fP:\fIexpr\fP | |
d3a24ed2 | 3539 | conditional operator |
cce855bc JA |
3540 | .TP |
3541 | .B = *= /= %= += \-= <<= >>= &= ^= |= | |
3542 | assignment | |
bb70624e JA |
3543 | .TP |
3544 | .B \fIexpr1\fP , \fIexpr2\fP | |
3545 | comma | |
cce855bc | 3546 | .PD |
ccc6cda3 | 3547 | .PP |
cce855bc | 3548 | Shell variables are allowed as operands; parameter expansion is |
bb70624e JA |
3549 | performed before the expression is evaluated. |
3550 | Within an expression, shell variables may also be referenced by name | |
3551 | without using the parameter expansion syntax. | |
d3a24ed2 CR |
3552 | A shell variable that is null or unset evaluates to 0 when referenced |
3553 | by name without using the parameter expansion syntax. | |
bb70624e | 3554 | The value of a variable is evaluated as an arithmetic expression |
d3a24ed2 CR |
3555 | when it is referenced, or when a variable which has been given the |
3556 | \fIinteger\fP attribute using \fBdeclare -i\fP is assigned a value. | |
3557 | A null value evaluates to 0. | |
bb70624e | 3558 | A shell variable need not have its integer attribute |
cce855bc | 3559 | turned on to be used in an expression. |
ccc6cda3 | 3560 | .PP |
cce855bc JA |
3561 | Constants with a leading 0 are interpreted as octal numbers. |
3562 | A leading 0x or 0X denotes hexadecimal. | |
3563 | Otherwise, numbers take the form [\fIbase#\fP]n, where \fIbase\fP | |
3564 | is a decimal number between 2 and 64 representing the arithmetic | |
3565 | base, and \fIn\fP is a number in that base. | |
bb70624e | 3566 | If \fIbase#\fP is omitted, then base 10 is used. |
cce855bc | 3567 | The digits greater than 9 are represented by the lowercase letters, |
f73dda09 | 3568 | the uppercase letters, @, and _, in that order. |
cce855bc | 3569 | If \fIbase\fP is less than or equal to 36, lowercase and uppercase |
f75912ae | 3570 | letters may be used interchangeably to represent numbers between 10 |
cce855bc | 3571 | and 35. |
ccc6cda3 | 3572 | .PP |
cce855bc JA |
3573 | Operators are evaluated in order of precedence. Sub-expressions in |
3574 | parentheses are evaluated first and may override the precedence | |
3575 | rules above. | |
3576 | .SH "CONDITIONAL EXPRESSIONS" | |
3577 | Conditional expressions are used by the \fB[[\fP compound command and | |
3578 | the \fBtest\fP and \fB[\fP builtin commands to test file attributes | |
3579 | and perform string and arithmetic comparisons. | |
3580 | Expressions are formed from the following unary or binary primaries. | |
3581 | If any \fIfile\fP argument to one of the primaries is of the form | |
bb70624e JA |
3582 | \fI/dev/fd/n\fP, then file descriptor \fIn\fP is checked. |
3583 | If the \fIfile\fP argument to one of the primaries is one of | |
3584 | \fI/dev/stdin\fP, \fI/dev/stdout\fP, or \fI/dev/stderr\fP, file | |
3585 | descriptor 0, 1, or 2, respectively, is checked. | |
be7d8f2d CR |
3586 | .PP |
3587 | Unless otherwise specified, primaries that operate on files follow symbolic | |
3588 | links and operate on the target of the link, rather than the link itself. | |
cce855bc JA |
3589 | .sp 1 |
3590 | .PD 0 | |
3591 | .TP | |
3592 | .B \-a \fIfile\fP | |
3593 | True if \fIfile\fP exists. | |
3594 | .TP | |
3595 | .B \-b \fIfile\fP | |
3596 | True if \fIfile\fP exists and is a block special file. | |
3597 | .TP | |
3598 | .B \-c \fIfile\fP | |
3599 | True if \fIfile\fP exists and is a character special file. | |
3600 | .TP | |
3601 | .B \-d \fIfile\fP | |
3602 | True if \fIfile\fP exists and is a directory. | |
3603 | .TP | |
3604 | .B \-e \fIfile\fP | |
3605 | True if \fIfile\fP exists. | |
3606 | .TP | |
3607 | .B \-f \fIfile\fP | |
3608 | True if \fIfile\fP exists and is a regular file. | |
3609 | .TP | |
3610 | .B \-g \fIfile\fP | |
3611 | True if \fIfile\fP exists and is set-group-id. | |
3612 | .TP | |
b72432fd JA |
3613 | .B \-h \fIfile\fP |
3614 | True if \fIfile\fP exists and is a symbolic link. | |
3615 | .TP | |
cce855bc JA |
3616 | .B \-k \fIfile\fP |
3617 | True if \fIfile\fP exists and its ``sticky'' bit is set. | |
3618 | .TP | |
3619 | .B \-p \fIfile\fP | |
3620 | True if \fIfile\fP exists and is a named pipe (FIFO). | |
3621 | .TP | |
3622 | .B \-r \fIfile\fP | |
3623 | True if \fIfile\fP exists and is readable. | |
3624 | .TP | |
3625 | .B \-s \fIfile\fP | |
3626 | True if \fIfile\fP exists and has a size greater than zero. | |
3627 | .TP | |
3628 | .B \-t \fIfd\fP | |
3629 | True if file descriptor | |
3630 | .I fd | |
3631 | is open and refers to a terminal. | |
3632 | .TP | |
3633 | .B \-u \fIfile\fP | |
3634 | True if \fIfile\fP exists and its set-user-id bit is set. | |
3635 | .TP | |
3636 | .B \-w \fIfile\fP | |
3637 | True if \fIfile\fP exists and is writable. | |
3638 | .TP | |
3639 | .B \-x \fIfile\fP | |
3640 | True if \fIfile\fP exists and is executable. | |
3641 | .TP | |
3642 | .B \-O \fIfile\fP | |
3643 | True if \fIfile\fP exists and is owned by the effective user id. | |
3644 | .TP | |
3645 | .B \-G \fIfile\fP | |
3646 | True if \fIfile\fP exists and is owned by the effective group id. | |
3647 | .TP | |
3648 | .B \-L \fIfile\fP | |
3649 | True if \fIfile\fP exists and is a symbolic link. | |
3650 | .TP | |
3651 | .B \-S \fIfile\fP | |
3652 | True if \fIfile\fP exists and is a socket. | |
3653 | .TP | |
3654 | .B \-N \fIfile\fP | |
3655 | True if \fIfile\fP exists and has been modified since it was last read. | |
3656 | .TP | |
3657 | \fIfile1\fP \-\fBnt\fP \fIfile2\fP | |
7117c2d2 JA |
3658 | True if \fIfile1\fP is newer (according to modification date) than \fIfile2\fP, |
3659 | or if \fIfile1\fP exists and \fPfile2\fP does not. | |
cce855bc JA |
3660 | .TP |
3661 | \fIfile1\fP \-\fBot\fP \fIfile2\fP | |
7117c2d2 JA |
3662 | True if \fIfile1\fP is older than \fIfile2\fP, or if \fIfile2\fP exists |
3663 | and \fIfile1\fP does not. | |
cce855bc JA |
3664 | .TP |
3665 | \fIfile1\fP \fB\-ef\fP \fIfile2\fP | |
7117c2d2 | 3666 | True if \fIfile1\fP and \fIfile2\fP refer to the same device and |
cce855bc JA |
3667 | inode numbers. |
3668 | .TP | |
3669 | .B \-o \fIoptname\fP | |
3670 | True if shell option | |
3671 | .I optname | |
3672 | is enabled. | |
3673 | See the list of options under the description of the | |
3674 | .B \-o | |
3675 | option to the | |
3676 | .B set | |
3677 | builtin below. | |
3678 | .TP | |
3679 | .B \-z \fIstring\fP | |
3680 | True if the length of \fIstring\fP is zero. | |
3681 | .TP | |
cce855bc | 3682 | \fIstring\fP |
f085a21f CR |
3683 | .PD 0 |
3684 | .TP | |
3685 | .B \-n \fIstring\fP | |
3686 | .PD | |
cce855bc JA |
3687 | True if the length of |
3688 | .I string | |
3689 | is non-zero. | |
3690 | .TP | |
3691 | \fIstring1\fP \fB==\fP \fIstring2\fP | |
3692 | True if the strings are equal. \fB=\fP may be used in place of | |
7117c2d2 | 3693 | \fB==\fP for strict POSIX compliance. |
cce855bc JA |
3694 | .TP |
3695 | \fIstring1\fP \fB!=\fP \fIstring2\fP | |
3696 | True if the strings are not equal. | |
3697 | .TP | |
3698 | \fIstring1\fP \fB<\fP \fIstring2\fP | |
3699 | True if \fIstring1\fP sorts before \fIstring2\fP lexicographically | |
3700 | in the current locale. | |
3701 | .TP | |
3702 | \fIstring1\fP \fB>\fP \fIstring2\fP | |
3703 | True if \fIstring1\fP sorts after \fIstring2\fP lexicographically | |
3704 | in the current locale. | |
3705 | .TP | |
3706 | .I \fIarg1\fP \fBOP\fP \fIarg2\fP | |
3707 | .SM | |
3708 | .B OP | |
3709 | is one of | |
3710 | .BR \-eq , | |
3711 | .BR \-ne , | |
3712 | .BR \-lt , | |
3713 | .BR \-le , | |
3714 | .BR \-gt , | |
3715 | or | |
3716 | .BR \-ge . | |
3717 | These arithmetic binary operators return true if \fIarg1\fP | |
3718 | is equal to, not equal to, less than, less than or equal to, | |
3719 | greater than, or greater than or equal to \fIarg2\fP, respectively. | |
3720 | .I Arg1 | |
3721 | and | |
3722 | .I arg2 | |
3723 | may be positive or negative integers. | |
3724 | .PD | |
3725 | .SH "SIMPLE COMMAND EXPANSION" | |
3726 | When a simple command is executed, the shell performs the following | |
3727 | expansions, assignments, and redirections, from left to right. | |
3728 | .IP 1. | |
3729 | The words that the parser has marked as variable assignments (those | |
3730 | preceding the command name) and redirections are saved for later | |
3731 | processing. | |
3732 | .IP 2. | |
3733 | The words that are not variable assignments or redirections are | |
3734 | expanded. If any words remain after expansion, the first word | |
3735 | is taken to be the name of the command and the remaining words are | |
3736 | the arguments. | |
3737 | .IP 3. | |
3738 | Redirections are performed as described above under | |
3739 | .SM | |
3740 | .BR REDIRECTION . | |
3741 | .IP 4. | |
3742 | The text after the \fB=\fP in each variable assignment undergoes tilde | |
3743 | expansion, parameter expansion, command substitution, arithmetic expansion, | |
3744 | and quote removal before being assigned to the variable. | |
3745 | .PP | |
3746 | If no command name results, the variable assignments affect the current | |
3747 | shell environment. Otherwise, the variables are added to the environment | |
3748 | of the executed command and do not affect the current shell environment. | |
3749 | If any of the assignments attempts to assign a value to a readonly variable, | |
3750 | an error occurs, and the command exits with a non-zero status. | |
3751 | .PP | |
3752 | If no command name results, redirections are performed, but do not | |
3753 | affect the current shell environment. A redirection error causes the | |
3754 | command to exit with a non-zero status. | |
3755 | .PP | |
3756 | If there is a command name left after expansion, execution proceeds as | |
3757 | described below. Otherwise, the command exits. If one of the expansions | |
3758 | contained a command substitution, the exit status of the command is | |
3759 | the exit status of the last command substitution performed. If there | |
3760 | were no command substitutions, the command exits with a status of zero. | |
3761 | .SH "COMMAND EXECUTION" | |
3762 | After a command has been split into words, if it results in a | |
3763 | simple command and an optional list of arguments, the following | |
3764 | actions are taken. | |
3765 | .PP | |
3766 | If the command name contains no slashes, the shell attempts to | |
3767 | locate it. If there exists a shell function by that name, that | |
3768 | function is invoked as described above in | |
3769 | .SM | |
3770 | .BR FUNCTIONS . | |
3771 | If the name does not match a function, the shell searches for | |
3772 | it in the list of shell builtins. If a match is found, that | |
3773 | builtin is invoked. | |
3774 | .PP | |
3775 | If the name is neither a shell function nor a builtin, | |
3776 | and contains no slashes, | |
3777 | .B bash | |
3778 | searches each element of the | |
3779 | .SM | |
3780 | .B PATH | |
3781 | for a directory containing an executable file by that name. | |
3782 | .B Bash | |
bb70624e | 3783 | uses a hash table to remember the full pathnames of executable |
cce855bc JA |
3784 | files (see |
3785 | .B hash | |
3786 | under | |
3787 | .SM | |
3788 | .B "SHELL BUILTIN COMMANDS" | |
3789 | below). | |
3790 | A full search of the directories in | |
3791 | .SM | |
3792 | .B PATH | |
3793 | is performed only if the command is not found in the hash table. | |
3794 | If the search is unsuccessful, the shell prints an error | |
3795 | message and returns an exit status of 127. | |
3796 | .PP | |
3797 | If the search is successful, or if the command name contains | |
3798 | one or more slashes, the shell executes the named program in a | |
3799 | separate execution environment. | |
3800 | Argument 0 is set to the name given, and the remaining arguments | |
3801 | to the command are set to the arguments given, if any. | |
3802 | .PP | |
3803 | If this execution fails because the file is not in executable | |
3804 | format, and the file is not a directory, it is assumed to be | |
3805 | a \fIshell script\fP, a file | |
3806 | containing shell commands. A subshell is spawned to execute | |
3807 | it. This subshell reinitializes itself, so | |
3808 | that the effect is as if a new shell had been invoked | |
3809 | to handle the script, with the exception that the locations of | |
3810 | commands remembered by the parent (see | |
3811 | .B hash | |
3812 | below under | |
3813 | .SM | |
3814 | \fBSHELL BUILTIN COMMANDS\fP) | |
3815 | are retained by the child. | |
3816 | .PP | |
3817 | If the program is a file beginning with | |
3818 | .BR #! , | |
3819 | the remainder of the first line specifies an interpreter | |
3820 | for the program. The shell executes the | |
3821 | specified interpreter on operating systems that do not | |
3822 | handle this executable format themselves. The arguments to the | |
3823 | interpreter consist of a single optional argument following the | |
3824 | interpreter name on the first line of the program, followed | |
3825 | by the name of the program, followed by the command | |
3826 | arguments, if any. | |
3827 | .SH COMMAND EXECUTION ENVIRONMENT | |
3828 | The shell has an \fIexecution environment\fP, which consists of the | |
3829 | following: | |
3830 | .sp 1 | |
3831 | .IP \(bu | |
3832 | open files inherited by the shell at invocation, as modified by | |
3833 | redirections supplied to the \fBexec\fP builtin | |
3834 | .IP \(bu | |
3835 | the current working directory as set by \fBcd\fP, \fBpushd\fP, or | |
3836 | \fBpopd\fP, or inherited by the shell at invocation | |
3837 | .IP \(bu | |
3838 | the file creation mode mask as set by \fBumask\fP or inherited from | |
3839 | the shell's parent | |
3840 | .IP \(bu | |
3841 | current traps set by \fBtrap\fP | |
3842 | .IP \(bu | |
3843 | shell parameters that are set by variable assignment or with \fBset\fP | |
3844 | or inherited from the shell's parent in the environment | |
3845 | .IP \(bu | |
3846 | shell functions defined during execution or inherited from the shell's | |
3847 | parent in the environment | |
3848 | .IP \(bu | |
3849 | options enabled at invocation (either by default or with command-line | |
3850 | arguments) or by \fBset\fP | |
3851 | .IP \(bu | |
3852 | options enabled by \fBshopt\fP | |
3853 | .IP \(bu | |
3854 | shell aliases defined with \fBalias\fP | |
3855 | .IP \(bu | |
3856 | various process IDs, including those of background jobs, the value | |
3857 | of \fB$$\fP, and the value of \fB$PPID\fP | |
3858 | .PP | |
3859 | When a simple command other than a builtin or shell function | |
3860 | is to be executed, it | |
3861 | is invoked in a separate execution environment that consists of | |
3862 | the following. Unless otherwise noted, the values are inherited | |
3863 | from the shell. | |
3864 | .sp 1 | |
3865 | .IP \(bu | |
3866 | the shell's open files, plus any modifications and additions specified | |
3867 | by redirections to the command | |
3868 | .IP \(bu | |
3869 | the current working directory | |
3870 | .IP \(bu | |
3871 | the file creation mode mask | |
3872 | .IP \(bu | |
d3a24ed2 CR |
3873 | shell variables and functions marked for export, along with variables |
3874 | exported for the command, passed in the environment | |
cce855bc | 3875 | .IP \(bu |
d3a24ed2 CR |
3876 | traps caught by the shell are reset to the values inherited from the |
3877 | shell's parent, and traps ignored by the shell are ignored | |
cce855bc JA |
3878 | .PP |
3879 | A command invoked in this separate environment cannot affect the | |
3880 | shell's execution environment. | |
3881 | .PP | |
d3a24ed2 CR |
3882 | Command substitution, commands grouped with parentheses, |
3883 | and asynchronous commands are invoked in a | |
cce855bc JA |
3884 | subshell environment that is a duplicate of the shell environment, |
3885 | except that traps caught by the shell are reset to the values | |
3886 | that the shell inherited from its parent at invocation. Builtin | |
3887 | commands that are invoked as part of a pipeline are also executed in a | |
3888 | subshell environment. Changes made to the subshell environment | |
3889 | cannot affect the shell's execution environment. | |
f73dda09 JA |
3890 | .PP |
3891 | If a command is followed by a \fB&\fP and job control is not active, the | |
3892 | default standard input for the command is the empty file \fI/dev/null\fP. | |
3893 | Otherwise, the invoked command inherits the file descriptors of the calling | |
3894 | shell as modified by redirections. | |
cce855bc JA |
3895 | .SH ENVIRONMENT |
3896 | When a program is invoked it is given an array of strings | |
3897 | called the | |
3898 | .IR environment . | |
3899 | This is a list of | |
3900 | \fIname\fP\-\fIvalue\fP pairs, of the form | |
3901 | .IR "name\fR=\fPvalue" . | |
3902 | .PP | |
bb70624e JA |
3903 | The shell provides several ways to manipulate the environment. |
3904 | On invocation, the shell scans its own environment and | |
cce855bc JA |
3905 | creates a parameter for each name found, automatically marking |
3906 | it for | |
3907 | .I export | |
3908 | to child processes. Executed commands inherit the environment. | |
3909 | The | |
3910 | .B export | |
3911 | and | |
3912 | .B declare \-x | |
3913 | commands allow parameters and functions to be added to and | |
3914 | deleted from the environment. If the value of a parameter | |
3915 | in the environment is modified, the new value becomes part | |
3916 | of the environment, replacing the old. The environment | |
3917 | inherited by any executed command consists of the shell's | |
3918 | initial environment, whose values may be modified in the shell, | |
3919 | less any pairs removed by the | |
3920 | .B unset | |
3921 | command, plus any additions via the | |
3922 | .B export | |
3923 | and | |
3924 | .B declare \-x | |
3925 | commands. | |
3926 | .PP | |
3927 | The environment for any | |
3928 | .I simple command | |
3929 | or function may be augmented temporarily by prefixing it with | |
3930 | parameter assignments, as described above in | |
3931 | .SM | |
3932 | .BR PARAMETERS . | |
3933 | These assignment statements affect only the environment seen | |
3934 | by that command. | |
3935 | .PP | |
3936 | If the | |
3937 | .B \-k | |
3938 | option is set (see the | |
3939 | .B set | |
3940 | builtin command below), then | |
3941 | .I all | |
3942 | parameter assignments are placed in the environment for a command, | |
3943 | not just those that precede the command name. | |
3944 | .PP | |
3945 | When | |
3946 | .B bash | |
3947 | invokes an external command, the variable | |
3948 | .B _ | |
3949 | is set to the full file name of the command and passed to that | |
ccc6cda3 JA |
3950 | command in its environment. |
3951 | .SH "EXIT STATUS" | |
cce855bc | 3952 | For the shell's purposes, a command which exits with a |
ccc6cda3 JA |
3953 | zero exit status has succeeded. An exit status of zero |
3954 | indicates success. A non-zero exit status indicates failure. | |
bb70624e JA |
3955 | When a command terminates on a fatal signal \fIN\fP, \fBbash\fP uses |
3956 | the value of 128+\fIN\fP as the exit status. | |
ccc6cda3 JA |
3957 | .PP |
3958 | If a command is not found, the child process created to | |
3959 | execute it returns a status of 127. If a command is found | |
3960 | but is not executable, the return status is 126. | |
3961 | .PP | |
cce855bc JA |
3962 | If a command fails because of an error during expansion or redirection, |
3963 | the exit status is greater than zero. | |
3964 | .PP | |
ccc6cda3 JA |
3965 | Shell builtin commands return a status of 0 (\fItrue\fP) if |
3966 | successful, and non-zero (\fIfalse\fP) if an error occurs | |
3967 | while they execute. | |
3968 | All builtins return an exit status of 2 to indicate incorrect usage. | |
3969 | .PP | |
3970 | \fBBash\fP itself returns the exit status of the last command | |
3971 | executed, unless a syntax error occurs, in which case it exits | |
3972 | with a non-zero value. See also the \fBexit\fP builtin | |
3973 | command below. | |
3974 | .SH SIGNALS | |
cce855bc | 3975 | When \fBbash\fP is interactive, in the absence of any traps, it ignores |
ccc6cda3 JA |
3976 | .SM |
3977 | .B SIGTERM | |
3978 | (so that \fBkill 0\fP does not kill an interactive shell), | |
3979 | and | |
3980 | .SM | |
3981 | .B SIGINT | |
3982 | is caught and handled (so that the \fBwait\fP builtin is interruptible). | |
3983 | In all cases, \fBbash\fP ignores | |
3984 | .SM | |
3985 | .BR SIGQUIT . | |
3986 | If job control is in effect, | |
3987 | .B bash | |
3988 | ignores | |
3989 | .SM | |
3990 | .BR SIGTTIN , | |
3991 | .SM | |
3992 | .BR SIGTTOU , | |
3993 | and | |
3994 | .SM | |
3995 | .BR SIGTSTP . | |
3996 | .PP | |
5e13499c | 3997 | Non-builtin commands run by \fBbash\fP have signal handlers |
cce855bc JA |
3998 | set to the values inherited by the shell from its parent. |
3999 | When job control is not in effect, asynchronous commands | |
ccc6cda3 JA |
4000 | ignore |
4001 | .SM | |
4002 | .B SIGINT | |
4003 | and | |
4004 | .SM | |
cce855bc | 4005 | .B SIGQUIT |
5e13499c | 4006 | in addition to these inherited handlers. |
ccc6cda3 JA |
4007 | Commands run as a result of command substitution ignore the |
4008 | keyboard-generated job control signals | |
4009 | .SM | |
4010 | .BR SIGTTIN , | |
4011 | .SM | |
4012 | .BR SIGTTOU , | |
4013 | and | |
4014 | .SM | |
4015 | .BR SIGTSTP . | |
4016 | .PP | |
4017 | The shell exits by default upon receipt of a | |
4018 | .SM | |
4019 | .BR SIGHUP . | |
f73dda09 | 4020 | Before exiting, an interactive shell resends the |
ccc6cda3 JA |
4021 | .SM |
4022 | .B SIGHUP | |
cce855bc JA |
4023 | to all jobs, running or stopped. |
4024 | Stopped jobs are sent | |
4025 | .SM | |
4026 | .B SIGCONT | |
4027 | to ensure that they receive the | |
4028 | .SM | |
4029 | .BR SIGHUP . | |
4030 | To prevent the shell from | |
4031 | sending the signal to a particular job, it should be removed from the | |
ccc6cda3 JA |
4032 | jobs table with the |
4033 | .B disown | |
4034 | builtin (see | |
4035 | .SM | |
4036 | .B "SHELL BUILTIN COMMANDS" | |
cce855bc JA |
4037 | below) or marked |
4038 | to not receive | |
ccc6cda3 | 4039 | .SM |
cce855bc JA |
4040 | .B SIGHUP |
4041 | using | |
4042 | .BR "disown \-h" . | |
4043 | .PP | |
4044 | If the | |
4045 | .B huponexit | |
4046 | shell option has been set with | |
4047 | .BR shopt , | |
4048 | .B bash | |
4049 | sends a | |
4050 | .SM | |
4051 | .B SIGHUP | |
4052 | to all jobs when an interactive login shell exits. | |
4053 | .PP | |
b66cc816 | 4054 | If \fBbash\fP is waiting for a command to complete and receives a signal |
5e13499c CR |
4055 | for which a trap has been set, the trap will not be executed until |
4056 | the command completes. | |
cce855bc JA |
4057 | When \fBbash\fP is waiting for an asynchronous command via the \fBwait\fP |
4058 | builtin, the reception of a signal for which a trap has been set will | |
4059 | cause the \fBwait\fP builtin to return immediately with an exit status | |
4060 | greater than 128, immediately after which the trap is executed. | |
ccc6cda3 JA |
4061 | .SH "JOB CONTROL" |
4062 | .I Job control | |
4063 | refers to the ability to selectively stop (\fIsuspend\fP) | |
4064 | the execution of processes and continue (\fIresume\fP) | |
4065 | their execution at a later point. A user typically employs | |
4066 | this facility via an interactive interface supplied jointly | |
4067 | by the system's terminal driver and | |
4068 | .BR bash . | |
4069 | .PP | |
4070 | The shell associates a | |
4071 | .I job | |
4072 | with each pipeline. It keeps a table of currently executing | |
4073 | jobs, which may be listed with the | |
4074 | .B jobs | |
4075 | command. When | |
4076 | .B bash | |
4077 | starts a job asynchronously (in the | |
4078 | .IR background ), | |
4079 | it prints a line that looks like: | |
4080 | .RS | |
4081 | .PP | |
4082 | [1] 25647 | |
4083 | .RE | |
4084 | .PP | |
4085 | indicating that this job is job number 1 and that the process ID | |
4086 | of the last process in the pipeline associated with this job is 25647. | |
4087 | All of the processes in a single pipeline are members of the same job. | |
4088 | .B Bash | |
4089 | uses the | |
4090 | .I job | |
4091 | abstraction as the basis for job control. | |
4092 | .PP | |
4093 | To facilitate the implementation of the user interface to job | |
bb70624e | 4094 | control, the operating system maintains the notion of a \fIcurrent terminal |
ccc6cda3 JA |
4095 | process group ID\fP. Members of this process group (processes whose |
4096 | process group ID is equal to the current terminal process group ID) | |
4097 | receive keyboard-generated signals such as | |
4098 | .SM | |
4099 | .BR SIGINT . | |
4100 | These processes are said to be in the | |
4101 | .IR foreground . | |
4102 | .I Background | |
4103 | processes are those whose process group ID differs from the terminal's; | |
4104 | such processes are immune to keyboard-generated signals. | |
4105 | Only foreground processes are allowed to read from or write to the | |
4106 | terminal. Background processes which attempt to read from (write to) the | |
4107 | terminal are sent a | |
4108 | .SM | |
4109 | .B SIGTTIN (SIGTTOU) | |
4110 | signal by the terminal driver, | |
4111 | which, unless caught, suspends the process. | |
4112 | .PP | |
4113 | If the operating system on which | |
4114 | .B bash | |
4115 | is running supports | |
4116 | job control, | |
4117 | .B bash | |
bb70624e | 4118 | contains facilities to use it. |
ccc6cda3 JA |
4119 | Typing the |
4120 | .I suspend | |
4121 | character (typically | |
4122 | .BR ^Z , | |
4123 | Control-Z) while a process is running | |
bb70624e | 4124 | causes that process to be stopped and returns control to |
ccc6cda3 JA |
4125 | .BR bash . |
4126 | Typing the | |
4127 | .I "delayed suspend" | |
4128 | character (typically | |
4129 | .BR ^Y , | |
4130 | Control-Y) causes the process to be stopped when it | |
4131 | attempts to read input from the terminal, and control to | |
4132 | be returned to | |
4133 | .BR bash . | |
cce855bc | 4134 | The user may then manipulate the state of this job, using the |
ccc6cda3 JA |
4135 | .B bg |
4136 | command to continue it in the background, the | |
4137 | .B fg | |
4138 | command to continue it in the foreground, or | |
4139 | the | |
4140 | .B kill | |
4141 | command to kill it. A \fB^Z\fP takes effect immediately, | |
4142 | and has the additional side effect of causing pending output | |
4143 | and typeahead to be discarded. | |
4144 | .PP | |
4145 | There are a number of ways to refer to a job in the shell. | |
4146 | The character | |
4147 | .B % | |
4148 | introduces a job name. Job number | |
4149 | .I n | |
4150 | may be referred to as | |
4151 | .BR %n . | |
4152 | A job may also be referred to using a prefix of the name used to | |
4153 | start it, or using a substring that appears in its command line. | |
4154 | For example, | |
4155 | .B %ce | |
4156 | refers to a stopped | |
4157 | .B ce | |
4158 | job. If a prefix matches more than one job, | |
4159 | .B bash | |
4160 | reports an error. Using | |
4161 | .BR %?ce , | |
4162 | on the other hand, refers to any job containing the string | |
4163 | .B ce | |
4164 | in its command line. If the substring matches more than one job, | |
4165 | .B bash | |
4166 | reports an error. The symbols | |
4167 | .B %% | |
4168 | and | |
4169 | .B %+ | |
4170 | refer to the shell's notion of the | |
4171 | .IR "current job" , | |
4172 | which is the last job stopped while it was in | |
cce855bc | 4173 | the foreground or started in the background. |
ccc6cda3 JA |
4174 | The |
4175 | .I "previous job" | |
4176 | may be referenced using | |
4177 | .BR %\- . | |
4178 | In output pertaining to jobs (e.g., the output of the | |
4179 | .B jobs | |
4180 | command), the current job is always flagged with a | |
4181 | .BR + , | |
4182 | and the previous job with a | |
4183 | .BR \- . | |
43df7bbb CR |
4184 | A single % (with no accompanying job specification) also refers to the |
4185 | current job. | |
726f6388 | 4186 | .PP |
ccc6cda3 JA |
4187 | Simply naming a job can be used to bring it into the |
4188 | foreground: | |
4189 | .B %1 | |
4190 | is a synonym for | |
4191 | \fB``fg %1''\fP, | |
4192 | bringing job 1 from the background into the foreground. | |
4193 | Similarly, | |
4194 | .B ``%1 &'' | |
4195 | resumes job 1 in the background, equivalent to | |
4196 | \fB``bg %1''\fP. | |
726f6388 | 4197 | .PP |
ccc6cda3 JA |
4198 | The shell learns immediately whenever a job changes state. |
4199 | Normally, | |
4200 | .B bash | |
4201 | waits until it is about to print a prompt before reporting | |
4202 | changes in a job's status so as to not interrupt | |
4203 | any other output. If the | |
4204 | .B \-b | |
4205 | option to the | |
726f6388 | 4206 | .B set |
ccc6cda3 | 4207 | builtin command |
cce855bc | 4208 | is enabled, |
726f6388 | 4209 | .B bash |
ccc6cda3 | 4210 | reports such changes immediately. |
f73dda09 JA |
4211 | Any trap on |
4212 | .SM | |
4213 | .B SIGCHLD | |
4214 | is executed for each child that exits. | |
726f6388 | 4215 | .PP |
ccc6cda3 JA |
4216 | If an attempt to exit |
4217 | .B bash | |
d3ad40de CR |
4218 | is made while jobs are stopped (or, if the \fBcheckjobs\fP shell option has |
4219 | been enabled using the \fBshopt\fP builtin, running), the shell prints a | |
4220 | warning message, and, if the \fBcheckjobs\fP option is enabled, lists the | |
4221 | jobs and their statuses. | |
4222 | The | |
ccc6cda3 | 4223 | .B jobs |
d3ad40de | 4224 | command may then be used to inspect their status. |
ccc6cda3 | 4225 | If a second attempt to exit is made without an intervening command, |
d3ad40de | 4226 | the shell does not print another warning, and any stopped |
ccc6cda3 | 4227 | jobs are terminated. |
726f6388 JA |
4228 | .SH PROMPTING |
4229 | When executing interactively, | |
4230 | .B bash | |
4231 | displays the primary prompt | |
4232 | .SM | |
4233 | .B PS1 | |
4234 | when it is ready to read a command, and the secondary prompt | |
4235 | .SM | |
4236 | .B PS2 | |
4237 | when it needs more input to complete a command. | |
4238 | .B Bash | |
4239 | allows these prompt strings to be customized by inserting a number of | |
4240 | backslash-escaped special characters that are decoded as follows: | |
4241 | .RS | |
4242 | .PD 0 | |
4243 | .TP | |
ccc6cda3 JA |
4244 | .B \ea |
4245 | an ASCII bell character (07) | |
726f6388 JA |
4246 | .TP |
4247 | .B \ed | |
4248 | the date in "Weekday Month Date" format (e.g., "Tue May 26") | |
4249 | .TP | |
7117c2d2 JA |
4250 | .B \eD{\fIformat\fP} |
4251 | the \fIformat\fP is passed to \fIstrftime\fP(3) and the result is inserted | |
4252 | into the prompt string; an empty \fIformat\fP results in a locale-specific | |
4253 | time representation. The braces are required | |
4254 | .TP | |
ccc6cda3 JA |
4255 | .B \ee |
4256 | an ASCII escape character (033) | |
4257 | .TP | |
4258 | .B \eh | |
4259 | the hostname up to the first `.' | |
4260 | .TP | |
4261 | .B \eH | |
4262 | the hostname | |
4263 | .TP | |
bb70624e JA |
4264 | .B \ej |
4265 | the number of jobs currently managed by the shell | |
4266 | .TP | |
4267 | .B \el | |
4268 | the basename of the shell's terminal device name | |
4269 | .TP | |
726f6388 JA |
4270 | .B \en |
4271 | newline | |
4272 | .TP | |
cce855bc JA |
4273 | .B \er |
4274 | carriage return | |
4275 | .TP | |
726f6388 JA |
4276 | .B \es |
4277 | the name of the shell, the basename of | |
4278 | .B $0 | |
4279 | (the portion following the final slash) | |
4280 | .TP | |
ccc6cda3 JA |
4281 | .B \et |
4282 | the current time in 24-hour HH:MM:SS format | |
726f6388 | 4283 | .TP |
ccc6cda3 JA |
4284 | .B \eT |
4285 | the current time in 12-hour HH:MM:SS format | |
4286 | .TP | |
4287 | .B \e@ | |
4288 | the current time in 12-hour am/pm format | |
726f6388 | 4289 | .TP |
f73dda09 JA |
4290 | .B \eA |
4291 | the current time in 24-hour HH:MM format | |
4292 | .TP | |
726f6388 JA |
4293 | .B \eu |
4294 | the username of the current user | |
4295 | .TP | |
ccc6cda3 JA |
4296 | .B \ev |
4297 | the version of \fBbash\fP (e.g., 2.00) | |
726f6388 | 4298 | .TP |
ccc6cda3 | 4299 | .B \eV |
a5e25162 | 4300 | the release of \fBbash\fP, version + patch level (e.g., 2.00.0) |
ccc6cda3 JA |
4301 | .TP |
4302 | .B \ew | |
12d937f9 | 4303 | the current working directory, with \fB$HOME\fP abbreviated with a tilde |
ccc6cda3 JA |
4304 | .TP |
4305 | .B \eW | |
12d937f9 CR |
4306 | the basename of the current working directory, with \fB$HOME\fP |
4307 | abbreviated with a tilde | |
726f6388 JA |
4308 | .TP |
4309 | .B \e! | |
4310 | the history number of this command | |
4311 | .TP | |
ccc6cda3 JA |
4312 | .B \e# |
4313 | the command number of this command | |
4314 | .TP | |
726f6388 JA |
4315 | .B \e$ |
4316 | if the effective UID is 0, a | |
4317 | .BR # , | |
4318 | otherwise a | |
4319 | .B $ | |
4320 | .TP | |
ccc6cda3 JA |
4321 | .B \e\fInnn\fP |
4322 | the character corresponding to the octal number \fInnn\fP | |
726f6388 JA |
4323 | .TP |
4324 | .B \e\e | |
4325 | a backslash | |
4326 | .TP | |
4327 | .B \e[ | |
4328 | begin a sequence of non-printing characters, which could be used to | |
4329 | embed a terminal control sequence into the prompt | |
4330 | .TP | |
4331 | .B \e] | |
4332 | end a sequence of non-printing characters | |
4333 | .PD | |
4334 | .RE | |
4335 | .PP | |
4336 | The command number and the history number are usually different: | |
4337 | the history number of a command is its position in the history | |
4338 | list, which may include commands restored from the history file | |
4339 | (see | |
4340 | .SM | |
4341 | .B HISTORY | |
4342 | below), while the command number is the position in the sequence | |
4343 | of commands executed during the current shell session. | |
4344 | After the string is decoded, it is expanded via | |
bb70624e JA |
4345 | parameter expansion, command substitution, arithmetic |
4346 | expansion, and quote removal, subject to the value of the | |
ccc6cda3 JA |
4347 | .B promptvars |
4348 | shell option (see the description of the | |
4349 | .B shopt | |
4350 | command under | |
4351 | .SM | |
4352 | .B "SHELL BUILTIN COMMANDS" | |
4353 | below). | |
726f6388 JA |
4354 | .SH READLINE |
4355 | This is the library that handles reading input when using an interactive | |
4356 | shell, unless the | |
d166f048 | 4357 | .B \-\-noediting |
ccc6cda3 JA |
4358 | option is given at shell invocation. |
4359 | By default, the line editing commands are similar to those of emacs. | |
726f6388 | 4360 | A vi-style line editing interface is also available. |
ccc6cda3 JA |
4361 | To turn off line editing after the shell is running, use the |
4362 | .B +o emacs | |
4363 | or | |
4364 | .B +o vi | |
4365 | options to the | |
4366 | .B set | |
4367 | builtin (see | |
4368 | .SM | |
4369 | .B SHELL BUILTIN COMMANDS | |
4370 | below). | |
4371 | .SS "Readline Notation" | |
726f6388 JA |
4372 | .PP |
4373 | In this section, the emacs-style notation is used to denote | |
4374 | keystrokes. Control keys are denoted by C\-\fIkey\fR, e.g., C\-n | |
4375 | means Control\-N. Similarly, | |
4376 | .I meta | |
4377 | keys are denoted by M\-\fIkey\fR, so M\-x means Meta\-X. (On keyboards | |
4378 | without a | |
4379 | .I meta | |
4380 | key, M\-\fIx\fP means ESC \fIx\fP, i.e., press the Escape key | |
4381 | then the | |
4382 | .I x | |
4383 | key. This makes ESC the \fImeta prefix\fP. | |
4384 | The combination M\-C\-\fIx\fP means ESC\-Control\-\fIx\fP, | |
4385 | or press the Escape key | |
4386 | then hold the Control key while pressing the | |
4387 | .I x | |
4388 | key.) | |
4389 | .PP | |
ccc6cda3 JA |
4390 | Readline commands may be given numeric |
4391 | .IR arguments , | |
4392 | which normally act as a repeat count. | |
4393 | Sometimes, however, it is the sign of the argument that is significant. | |
4394 | Passing a negative argument to a command that acts in the forward | |
4395 | direction (e.g., \fBkill\-line\fP) causes that command to act in a | |
4396 | backward direction. | |
4397 | Commands whose behavior with arguments deviates from this are noted | |
4398 | below. | |
4399 | .PP | |
4400 | When a command is described as \fIkilling\fP text, the text | |
4401 | deleted is saved for possible future retrieval | |
4402 | (\fIyanking\fP). The killed text is saved in a | |
4403 | \fIkill ring\fP. Consecutive kills cause the text to be | |
4404 | accumulated into one unit, which can be yanked all at once. | |
4405 | Commands which do not kill text separate the chunks of text | |
4406 | on the kill ring. | |
4407 | .SS "Readline Initialization" | |
4408 | .PP | |
4409 | Readline is customized by putting commands in an initialization | |
4410 | file (the \fIinputrc\fP file). | |
4411 | The name of this file is taken from the value of the | |
726f6388 | 4412 | .SM |
ccc6cda3 JA |
4413 | .B INPUTRC |
4414 | variable. If that variable is unset, the default is | |
726f6388 | 4415 | .IR ~/.inputrc . |
ccc6cda3 JA |
4416 | When a program which uses the readline library starts up, the |
4417 | initialization file is read, and the key bindings and variables | |
4418 | are set. | |
4419 | There are only a few basic constructs allowed in the | |
4420 | readline initialization file. | |
4421 | Blank lines are ignored. | |
4422 | Lines beginning with a \fB#\fP are comments. | |
4423 | Lines beginning with a \fB$\fP indicate conditional constructs. | |
4424 | Other lines denote key bindings and variable settings. | |
4425 | .PP | |
4426 | The default key-bindings may be changed with an | |
4427 | .I inputrc | |
4428 | file. | |
726f6388 JA |
4429 | Other programs that use this library may add their own commands |
4430 | and bindings. | |
4431 | .PP | |
4432 | For example, placing | |
4433 | .RS | |
4434 | .PP | |
4435 | M\-Control\-u: universal\-argument | |
4436 | .RE | |
4437 | or | |
4438 | .RS | |
4439 | C\-Meta\-u: universal\-argument | |
4440 | .RE | |
4441 | into the | |
ccc6cda3 | 4442 | .I inputrc |
726f6388 JA |
4443 | would make M\-C\-u execute the readline command |
4444 | .IR universal\-argument . | |
4445 | .PP | |
4446 | The following symbolic character names are recognized: | |
4447 | .IR RUBOUT , | |
4448 | .IR DEL , | |
4449 | .IR ESC , | |
4450 | .IR LFD , | |
4451 | .IR NEWLINE , | |
4452 | .IR RET , | |
4453 | .IR RETURN , | |
4454 | .IR SPC , | |
4455 | .IR SPACE , | |
4456 | and | |
4457 | .IR TAB . | |
bb70624e | 4458 | .PP |
726f6388 JA |
4459 | In addition to command names, readline allows keys to be bound |
4460 | to a string that is inserted when the key is pressed (a \fImacro\fP). | |
ccc6cda3 | 4461 | .SS "Readline Key Bindings" |
726f6388 JA |
4462 | .PP |
4463 | The syntax for controlling key bindings in the | |
cce855bc | 4464 | .I inputrc |
726f6388 JA |
4465 | file is simple. All that is required is the name of the |
4466 | command or the text of a macro and a key sequence to which | |
4467 | it should be bound. The name may be specified in one of two ways: | |
ccc6cda3 | 4468 | as a symbolic key name, possibly with \fIMeta\-\fP or \fIControl\-\fP |
726f6388 | 4469 | prefixes, or as a key sequence. |
28ef6c31 | 4470 | .PP |
cce855bc | 4471 | When using the form \fBkeyname\fP:\^\fIfunction\-name\fP or \fImacro\fP, |
726f6388 JA |
4472 | .I keyname |
4473 | is the name of a key spelled out in English. For example: | |
4474 | .sp | |
4475 | .RS | |
4476 | Control-u: universal\-argument | |
4477 | .br | |
4478 | Meta-Rubout: backward-kill-word | |
4479 | .br | |
ccc6cda3 | 4480 | Control-o: "> output" |
726f6388 JA |
4481 | .RE |
4482 | .LP | |
4483 | In the above example, | |
ccc6cda3 | 4484 | .I C\-u |
726f6388 JA |
4485 | is bound to the function |
4486 | .BR universal\-argument , | |
ccc6cda3 | 4487 | .I M\-DEL |
726f6388 JA |
4488 | is bound to the function |
4489 | .BR backward\-kill\-word , | |
4490 | and | |
ccc6cda3 | 4491 | .I C\-o |
726f6388 JA |
4492 | is bound to run the macro |
4493 | expressed on the right hand side (that is, to insert the text | |
28ef6c31 JA |
4494 | .if t \f(CW> output\fP |
4495 | .if n ``> output'' | |
726f6388 JA |
4496 | into the line). |
4497 | .PP | |
cce855bc | 4498 | In the second form, \fB"keyseq"\fP:\^\fIfunction\-name\fP or \fImacro\fP, |
726f6388 JA |
4499 | .B keyseq |
4500 | differs from | |
4501 | .B keyname | |
4502 | above in that strings denoting | |
4503 | an entire key sequence may be specified by placing the sequence | |
4504 | within double quotes. Some GNU Emacs style key escapes can be | |
28ef6c31 JA |
4505 | used, as in the following example, but the symbolic character names |
4506 | are not recognized. | |
726f6388 JA |
4507 | .sp |
4508 | .RS | |
ccc6cda3 | 4509 | "\eC\-u": universal\-argument |
726f6388 | 4510 | .br |
ccc6cda3 | 4511 | "\eC\-x\eC\-r": re\-read\-init\-file |
726f6388 JA |
4512 | .br |
4513 | "\ee[11~": "Function Key 1" | |
4514 | .RE | |
4515 | .PP | |
4516 | In this example, | |
ccc6cda3 | 4517 | .I C\-u |
726f6388 JA |
4518 | is again bound to the function |
4519 | .BR universal\-argument . | |
ccc6cda3 | 4520 | .I "C\-x C\-r" |
726f6388 JA |
4521 | is bound to the function |
4522 | .BR re\-read\-init\-file , | |
4523 | and | |
4524 | .I "ESC [ 1 1 ~" | |
4525 | is bound to insert the text | |
28ef6c31 JA |
4526 | .if t \f(CWFunction Key 1\fP. |
4527 | .if n ``Function Key 1''. | |
4528 | .PP | |
cce855bc | 4529 | The full set of GNU Emacs style escape sequences is |
726f6388 | 4530 | .RS |
cce855bc | 4531 | .PD 0 |
726f6388 JA |
4532 | .TP |
4533 | .B \eC\- | |
4534 | control prefix | |
4535 | .TP | |
ccc6cda3 | 4536 | .B \eM\- |
726f6388 JA |
4537 | meta prefix |
4538 | .TP | |
4539 | .B \ee | |
4540 | an escape character | |
4541 | .TP | |
4542 | .B \e\e | |
4543 | backslash | |
4544 | .TP | |
4545 | .B \e" | |
4546 | literal " | |
4547 | .TP | |
20587658 CR |
4548 | .B \e\(aq |
4549 | literal \(aq | |
726f6388 | 4550 | .RE |
cce855bc JA |
4551 | .PD |
4552 | .PP | |
4553 | In addition to the GNU Emacs style escape sequences, a second | |
4554 | set of backslash escapes is available: | |
4555 | .RS | |
4556 | .PD 0 | |
4557 | .TP | |
4558 | .B \ea | |
4559 | alert (bell) | |
4560 | .TP | |
4561 | .B \eb | |
4562 | backspace | |
4563 | .TP | |
4564 | .B \ed | |
4565 | delete | |
4566 | .TP | |
4567 | .B \ef | |
4568 | form feed | |
4569 | .TP | |
4570 | .B \en | |
4571 | newline | |
4572 | .TP | |
4573 | .B \er | |
4574 | carriage return | |
4575 | .TP | |
4576 | .B \et | |
4577 | horizontal tab | |
4578 | .TP | |
4579 | .B \ev | |
4580 | vertical tab | |
4581 | .TP | |
4582 | .B \e\fInnn\fP | |
f73dda09 | 4583 | the eight-bit character whose value is the octal value \fInnn\fP |
cce855bc JA |
4584 | (one to three digits) |
4585 | .TP | |
f73dda09 JA |
4586 | .B \ex\fIHH\fP |
4587 | the eight-bit character whose value is the hexadecimal value \fIHH\fP | |
4588 | (one or two hex digits) | |
cce855bc JA |
4589 | .RE |
4590 | .PD | |
726f6388 | 4591 | .PP |
cce855bc JA |
4592 | When entering the text of a macro, single or double quotes must |
4593 | be used to indicate a macro definition. | |
4594 | Unquoted text is assumed to be a function name. | |
4595 | In the macro body, the backslash escapes described above are expanded. | |
4596 | Backslash will quote any other character in the macro text, | |
20587658 | 4597 | including " and \(aq. |
726f6388 JA |
4598 | .PP |
4599 | .B Bash | |
4600 | allows the current readline key bindings to be displayed or modified | |
4601 | with the | |
4602 | .B bind | |
4603 | builtin command. The editing mode may be switched during interactive | |
4604 | use by using the | |
4605 | .B \-o | |
4606 | option to the | |
4607 | .B set | |
4608 | builtin command (see | |
4609 | .SM | |
4610 | .B SHELL BUILTIN COMMANDS | |
4611 | below). | |
ccc6cda3 | 4612 | .SS "Readline Variables" |
726f6388 JA |
4613 | .PP |
4614 | Readline has variables that can be used to further customize its | |
4615 | behavior. A variable may be set in the | |
4616 | .I inputrc | |
4617 | file with a statement of the form | |
4618 | .RS | |
4619 | .PP | |
4620 | \fBset\fP \fIvariable\-name\fP \fIvalue\fP | |
4621 | .RE | |
4622 | .PP | |
4623 | Except where noted, readline variables can take the values | |
4624 | .B On | |
4625 | or | |
ff247e74 CR |
4626 | .B Off |
4627 | (without regard to case). | |
4628 | Unrecognized variable names are ignored. | |
4629 | When a variable value is read, empty or null values, "on" (case-insensitive), | |
4630 | and "1" are equivalent to \fBOn\fP. All other values are equivalent to | |
4631 | \fBOff\fP. | |
726f6388 JA |
4632 | The variables and their default values are: |
4633 | .PP | |
4634 | .PD 0 | |
4635 | .TP | |
726f6388 JA |
4636 | .B bell\-style (audible) |
4637 | Controls what happens when readline wants to ring the terminal bell. | |
4638 | If set to \fBnone\fP, readline never rings the bell. If set to | |
4639 | \fBvisible\fP, readline uses a visible bell if one is available. | |
4640 | If set to \fBaudible\fP, readline attempts to ring the terminal's bell. | |
4641 | .TP | |
453f278a CR |
4642 | .B bind\-tty\-special\-chars (On) |
4643 | If set to \fBOn\fP, readline attempts to bind the control characters | |
4644 | treated specially by the kernel's terminal driver to their readline | |
4645 | equivalents. | |
4646 | .TP | |
726f6388 | 4647 | .B comment\-begin (``#'') |
bb70624e | 4648 | The string that is inserted when the readline |
ccc6cda3 | 4649 | .B insert\-comment |
726f6388 | 4650 | command is executed. |
ccc6cda3 JA |
4651 | This command is bound to |
4652 | .B M\-# | |
4653 | in emacs mode and to | |
4654 | .B # | |
4655 | in vi command mode. | |
726f6388 | 4656 | .TP |
cce855bc JA |
4657 | .B completion\-ignore\-case (Off) |
4658 | If set to \fBOn\fP, readline performs filename matching and completion | |
4659 | in a case\-insensitive fashion. | |
4660 | .TP | |
726f6388 JA |
4661 | .B completion\-query\-items (100) |
4662 | This determines when the user is queried about viewing | |
4663 | the number of possible completions | |
4664 | generated by the \fBpossible\-completions\fP command. | |
4665 | It may be set to any integer value greater than or equal to | |
4666 | zero. If the number of possible completions is greater than | |
4667 | or equal to the value of this variable, the user is asked whether | |
4668 | or not he wishes to view them; otherwise they are simply listed | |
4669 | on the terminal. | |
4670 | .TP | |
ccc6cda3 JA |
4671 | .B convert\-meta (On) |
4672 | If set to \fBOn\fP, readline will convert characters with the | |
4673 | eighth bit set to an ASCII key sequence | |
bb70624e | 4674 | by stripping the eighth bit and prefixing an |
ccc6cda3 JA |
4675 | escape character (in effect, using escape as the \fImeta prefix\fP). |
4676 | .TP | |
4677 | .B disable\-completion (Off) | |
4678 | If set to \fBOn\fP, readline will inhibit word completion. Completion | |
4679 | characters will be inserted into the line as if they had been | |
4680 | mapped to \fBself-insert\fP. | |
4681 | .TP | |
4682 | .B editing\-mode (emacs) | |
4683 | Controls whether readline begins with a set of key bindings similar | |
4684 | to \fIemacs\fP or \fIvi\fP. | |
4685 | .B editing\-mode | |
4686 | can be set to either | |
4687 | .B emacs | |
4688 | or | |
4689 | .BR vi . | |
4690 | .TP | |
4691 | .B enable\-keypad (Off) | |
4692 | When set to \fBOn\fP, readline will try to enable the application | |
4693 | keypad when it is called. Some systems need this to enable the | |
4694 | arrow keys. | |
4695 | .TP | |
4696 | .B expand\-tilde (Off) | |
4697 | If set to \fBon\fP, tilde expansion is performed when readline | |
4698 | attempts word completion. | |
4699 | .TP | |
cdb32d45 | 4700 | .B history\-preserve\-point (Off) |
f73dda09 | 4701 | If set to \fBon\fP, the history code attempts to place point at the |
f75912ae | 4702 | same location on each history line retrieved with \fBprevious-history\fP |
f73dda09 JA |
4703 | or \fBnext-history\fP. |
4704 | .TP | |
ccc6cda3 JA |
4705 | .B horizontal\-scroll\-mode (Off) |
4706 | When set to \fBOn\fP, makes readline use a single line for display, | |
4707 | scrolling the input horizontally on a single screen line when it | |
4708 | becomes longer than the screen width rather than wrapping to a new line. | |
4709 | .TP | |
4710 | .B input\-meta (Off) | |
4711 | If set to \fBOn\fP, readline will enable eight-bit input (that is, | |
4712 | it will not strip the high bit from the characters it reads), | |
4713 | regardless of what the terminal claims it can support. The name | |
4714 | .B meta\-flag | |
4715 | is a synonym for this variable. | |
4716 | .TP | |
b72432fd JA |
4717 | .B isearch\-terminators (``C\-[C\-J'') |
4718 | The string of characters that should terminate an incremental | |
4719 | search without subsequently executing the character as a command. | |
4720 | If this variable has not been given a value, the characters | |
4721 | \fIESC\fP and \fIC\-J\fP will terminate an incremental search. | |
4722 | .TP | |
726f6388 | 4723 | .B keymap (emacs) |
cce855bc | 4724 | Set the current readline keymap. The set of valid keymap names is |
ccc6cda3 JA |
4725 | \fIemacs, emacs\-standard, emacs\-meta, emacs\-ctlx, vi, |
4726 | vi\-command\fP, and | |
4727 | .IR vi\-insert . | |
4728 | \fIvi\fP is equivalent to \fIvi\-command\fP; \fIemacs\fP is | |
4729 | equivalent to \fIemacs\-standard\fP. The default value is | |
726f6388 JA |
4730 | .IR emacs ; |
4731 | the value of | |
4732 | .B editing\-mode | |
4733 | also affects the default keymap. | |
4734 | .TP | |
ccc6cda3 JA |
4735 | .B mark\-directories (On) |
4736 | If set to \fBOn\fP, completed directory names have a slash | |
4737 | appended. | |
4738 | .TP | |
4739 | .B mark\-modified\-lines (Off) | |
4740 | If set to \fBOn\fP, history lines that have been modified are displayed | |
4741 | with a preceding asterisk (\fB*\fP). | |
4742 | .TP | |
7117c2d2 JA |
4743 | .B mark\-symlinked\-directories (Off) |
4744 | If set to \fBOn\fP, completed names which are symbolic links to directories | |
4745 | have a slash appended (subject to the value of | |
4746 | \fBmark\-directories\fP). | |
4747 | .TP | |
f73dda09 JA |
4748 | .B match\-hidden\-files (On) |
4749 | This variable, when set to \fBOn\fP, causes readline to match files whose | |
4750 | names begin with a `.' (hidden files) when performing filename | |
4751 | completion, unless the leading `.' is | |
4752 | supplied by the user in the filename to be completed. | |
4753 | .TP | |
ccc6cda3 JA |
4754 | .B output\-meta (Off) |
4755 | If set to \fBOn\fP, readline will display characters with the | |
4756 | eighth bit set directly rather than as a meta-prefixed escape | |
4757 | sequence. | |
4758 | .TP | |
7117c2d2 JA |
4759 | .B page\-completions (On) |
4760 | If set to \fBOn\fP, readline uses an internal \fImore\fP-like pager | |
4761 | to display a screenful of possible completions at a time. | |
4762 | .TP | |
cce855bc JA |
4763 | .B print\-completions\-horizontally (Off) |
4764 | If set to \fBOn\fP, readline will display completions with matches | |
4765 | sorted horizontally in alphabetical order, rather than down the screen. | |
4766 | .TP | |
726f6388 JA |
4767 | .B show\-all\-if\-ambiguous (Off) |
4768 | This alters the default behavior of the completion functions. If | |
4769 | set to | |
4770 | .BR on , | |
4771 | words which have more than one possible completion cause the | |
4772 | matches to be listed immediately instead of ringing the bell. | |
4773 | .TP | |
d3a24ed2 CR |
4774 | .B show\-all\-if\-unmodified (Off) |
4775 | This alters the default behavior of the completion functions in | |
4776 | a fashion similar to \fBshow\-all\-if\-ambiguous\fP. | |
4777 | If set to | |
4778 | .BR on , | |
4779 | words which have more than one possible completion without any | |
4780 | possible partial completion (the possible completions don't share | |
4781 | a common prefix) cause the matches to be listed immediately instead | |
4782 | of ringing the bell. | |
4783 | .TP | |
ccc6cda3 JA |
4784 | .B visible\-stats (Off) |
4785 | If set to \fBOn\fP, a character denoting a file's type as reported | |
4786 | by \fIstat\fP(2) is appended to the filename when listing possible | |
4787 | completions. | |
726f6388 | 4788 | .PD |
ccc6cda3 | 4789 | .SS "Readline Conditional Constructs" |
726f6388 JA |
4790 | .PP |
4791 | Readline implements a facility similar in spirit to the conditional | |
4792 | compilation features of the C preprocessor which allows key | |
4793 | bindings and variable settings to be performed as the result | |
cce855bc | 4794 | of tests. There are four parser directives used. |
726f6388 JA |
4795 | .IP \fB$if\fP |
4796 | The | |
4797 | .B $if | |
4798 | construct allows bindings to be made based on the | |
4799 | editing mode, the terminal being used, or the application using | |
4800 | readline. The text of the test extends to the end of the line; | |
4801 | no characters are required to isolate it. | |
4802 | .RS | |
4803 | .IP \fBmode\fP | |
4804 | The \fBmode=\fP form of the \fB$if\fP directive is used to test | |
4805 | whether readline is in emacs or vi mode. | |
4806 | This may be used in conjunction | |
4807 | with the \fBset keymap\fP command, for instance, to set bindings in | |
ccc6cda3 | 4808 | the \fIemacs\-standard\fP and \fIemacs\-ctlx\fP keymaps only if |
726f6388 JA |
4809 | readline is starting out in emacs mode. |
4810 | .IP \fBterm\fP | |
4811 | The \fBterm=\fP form may be used to include terminal-specific | |
4812 | key bindings, perhaps to bind the key sequences output by the | |
4813 | terminal's function keys. The word on the right side of the | |
4814 | .B = | |
cce855bc | 4815 | is tested against the both full name of the terminal and the portion |
726f6388 JA |
4816 | of the terminal name before the first \fB\-\fP. This allows |
4817 | .I sun | |
4818 | to match both | |
4819 | .I sun | |
4820 | and | |
4821 | .IR sun\-cmd , | |
4822 | for instance. | |
4823 | .IP \fBapplication\fP | |
4824 | The \fBapplication\fP construct is used to include | |
ccc6cda3 | 4825 | application-specific settings. Each program using the readline |
726f6388 JA |
4826 | library sets the \fIapplication name\fP, and an initialization |
4827 | file can test for a particular value. | |
4828 | This could be used to bind key sequences to functions useful for | |
4829 | a specific program. For instance, the following command adds a | |
4830 | key sequence that quotes the current or previous word in Bash: | |
cce855bc | 4831 | .sp 1 |
726f6388 JA |
4832 | .RS |
4833 | .nf | |
4834 | \fB$if\fP Bash | |
4835 | # Quote the current or previous word | |
ccc6cda3 | 4836 | "\eC\-xq": "\eeb\e"\eef\e"" |
726f6388 JA |
4837 | \fB$endif\fP |
4838 | .fi | |
4839 | .RE | |
4840 | .RE | |
4841 | .IP \fB$endif\fP | |
cce855bc | 4842 | This command, as seen in the previous example, terminates an |
726f6388 JA |
4843 | \fB$if\fP command. |
4844 | .IP \fB$else\fP | |
4845 | Commands in this branch of the \fB$if\fP directive are executed if | |
4846 | the test fails. | |
cce855bc JA |
4847 | .IP \fB$include\fP |
4848 | This directive takes a single filename as an argument and reads commands | |
4849 | and bindings from that file. For example, the following directive | |
4850 | would read \fI/etc/inputrc\fP: | |
4851 | .sp 1 | |
4852 | .RS | |
4853 | .nf | |
4854 | \fB$include\fP \^ \fI/etc/inputrc\fP | |
4855 | .fi | |
4856 | .RE | |
ccc6cda3 | 4857 | .SS Searching |
726f6388 | 4858 | .PP |
ccc6cda3 JA |
4859 | Readline provides commands for searching through the command history |
4860 | (see | |
4861 | .SM | |
4862 | .B HISTORY | |
4863 | below) for lines containing a specified string. | |
4864 | There are two search modes: | |
4865 | .I incremental | |
4866 | and | |
4867 | .IR non-incremental . | |
4868 | .PP | |
4869 | Incremental searches begin before the user has finished typing the | |
4870 | search string. | |
4871 | As each character of the search string is typed, readline displays | |
4872 | the next entry from the history matching the string typed so far. | |
4873 | An incremental search requires only as many characters as needed to | |
4874 | find the desired history entry. | |
bb70624e | 4875 | The characters present in the value of the \fBisearch-terminators\fP |
b72432fd JA |
4876 | variable are used to terminate an incremental search. |
4877 | If that variable has not been assigned a value the Escape and | |
4878 | Control-J characters will terminate an incremental search. | |
ccc6cda3 JA |
4879 | Control-G will abort an incremental search and restore the original |
4880 | line. | |
4881 | When the search is terminated, the history entry containing the | |
4882 | search string becomes the current line. | |
bb70624e | 4883 | .PP |
ccc6cda3 JA |
4884 | To find other matching entries in the history list, type Control-S or |
4885 | Control-R as appropriate. | |
4886 | This will search backward or forward in the history for the next | |
4887 | entry matching the search string typed so far. | |
4888 | Any other key sequence bound to a readline command will terminate | |
4889 | the search and execute that command. | |
4890 | For instance, a \fInewline\fP will terminate the search and accept | |
4891 | the line, thereby executing the command from the history list. | |
4892 | .PP | |
f73dda09 JA |
4893 | Readline remembers the last incremental search string. If two |
4894 | Control-Rs are typed without any intervening characters defining a | |
4895 | new search string, any remembered search string is used. | |
4896 | .PP | |
ccc6cda3 JA |
4897 | Non-incremental searches read the entire search string before starting |
4898 | to search for matching history lines. The search string may be | |
cce855bc | 4899 | typed by the user or be part of the contents of the current line. |
ccc6cda3 | 4900 | .SS "Readline Command Names" |
726f6388 JA |
4901 | .PP |
4902 | The following is a list of the names of the commands and the default | |
4903 | key sequences to which they are bound. | |
ccc6cda3 | 4904 | Command names without an accompanying key sequence are unbound by default. |
bb70624e JA |
4905 | In the following descriptions, \fIpoint\fP refers to the current cursor |
4906 | position, and \fImark\fP refers to a cursor position saved by the | |
4907 | \fBset\-mark\fP command. | |
4908 | The text between the point and mark is referred to as the \fIregion\fP. | |
726f6388 JA |
4909 | .SS Commands for Moving |
4910 | .PP | |
4911 | .PD 0 | |
4912 | .TP | |
4913 | .B beginning\-of\-line (C\-a) | |
4914 | Move to the start of the current line. | |
4915 | .TP | |
4916 | .B end\-of\-line (C\-e) | |
4917 | Move to the end of the line. | |
4918 | .TP | |
4919 | .B forward\-char (C\-f) | |
4920 | Move forward a character. | |
4921 | .TP | |
4922 | .B backward\-char (C\-b) | |
4923 | Move back a character. | |
4924 | .TP | |
4925 | .B forward\-word (M\-f) | |
4926 | Move forward to the end of the next word. Words are composed of | |
4927 | alphanumeric characters (letters and digits). | |
4928 | .TP | |
4929 | .B backward\-word (M\-b) | |
bb70624e | 4930 | Move back to the start of the current or previous word. Words are |
726f6388 JA |
4931 | composed of alphanumeric characters (letters and digits). |
4932 | .TP | |
4933 | .B clear\-screen (C\-l) | |
4934 | Clear the screen leaving the current line at the top of the screen. | |
4935 | With an argument, refresh the current line without clearing the | |
4936 | screen. | |
4937 | .TP | |
4938 | .B redraw\-current\-line | |
ccc6cda3 | 4939 | Refresh the current line. |
726f6388 JA |
4940 | .PD |
4941 | .SS Commands for Manipulating the History | |
4942 | .PP | |
4943 | .PD 0 | |
4944 | .TP | |
4945 | .B accept\-line (Newline, Return) | |
4946 | Accept the line regardless of where the cursor is. If this line is | |
ccc6cda3 | 4947 | non-empty, add it to the history list according to the state of the |
726f6388 JA |
4948 | .SM |
4949 | .B HISTCONTROL | |
4950 | variable. If the line is a modified history | |
4951 | line, then restore the history line to its original state. | |
4952 | .TP | |
4953 | .B previous\-history (C\-p) | |
4954 | Fetch the previous command from the history list, moving back in | |
4955 | the list. | |
4956 | .TP | |
4957 | .B next\-history (C\-n) | |
4958 | Fetch the next command from the history list, moving forward in the | |
4959 | list. | |
4960 | .TP | |
4961 | .B beginning\-of\-history (M\-<) | |
4962 | Move to the first line in the history. | |
4963 | .TP | |
4964 | .B end\-of\-history (M\->) | |
4965 | Move to the end of the input history, i.e., the line currently being | |
4966 | entered. | |
4967 | .TP | |
4968 | .B reverse\-search\-history (C\-r) | |
4969 | Search backward starting at the current line and moving `up' through | |
4970 | the history as necessary. This is an incremental search. | |
4971 | .TP | |
4972 | .B forward\-search\-history (C\-s) | |
4973 | Search forward starting at the current line and moving `down' through | |
4974 | the history as necessary. This is an incremental search. | |
4975 | .TP | |
4976 | .B non\-incremental\-reverse\-search\-history (M\-p) | |
4977 | Search backward through the history starting at the current line | |
ccc6cda3 | 4978 | using a non-incremental search for a string supplied by the user. |
726f6388 JA |
4979 | .TP |
4980 | .B non\-incremental\-forward\-search\-history (M\-n) | |
ccc6cda3 | 4981 | Search forward through the history using a non-incremental search for |
726f6388 JA |
4982 | a string supplied by the user. |
4983 | .TP | |
4984 | .B history\-search\-forward | |
4985 | Search forward through the history for the string of characters | |
bb70624e | 4986 | between the start of the current line and the point. |
ccc6cda3 | 4987 | This is a non-incremental search. |
726f6388 JA |
4988 | .TP |
4989 | .B history\-search\-backward | |
4990 | Search backward through the history for the string of characters | |
ccc6cda3 JA |
4991 | between the start of the current line and the point. |
4992 | This is a non-incremental search. | |
726f6388 JA |
4993 | .TP |
4994 | .B yank\-nth\-arg (M\-C\-y) | |
4995 | Insert the first argument to the previous command (usually | |
28ef6c31 JA |
4996 | the second word on the previous line) at point. |
4997 | With an argument | |
726f6388 JA |
4998 | .IR n , |
4999 | insert the \fIn\fPth word from the previous command (the words | |
5000 | in the previous command begin with word 0). A negative argument | |
5001 | inserts the \fIn\fPth word from the end of the previous command. | |
eb2bb562 CR |
5002 | Once the argument \fIn\fP is computed, the argument is extracted |
5003 | as if the "!\fIn\fP" history expansion had been specified. | |
726f6388 JA |
5004 | .TP |
5005 | .B | |
5006 | yank\-last\-arg (M\-.\^, M\-_\^) | |
ccc6cda3 JA |
5007 | Insert the last argument to the previous command (the last word of |
5008 | the previous history entry). With an argument, | |
5009 | behave exactly like \fByank\-nth\-arg\fP. | |
cce855bc JA |
5010 | Successive calls to \fByank\-last\-arg\fP move back through the history |
5011 | list, inserting the last argument of each line in turn. | |
eb2bb562 CR |
5012 | The history expansion facilities are used to extract the last argument, |
5013 | as if the "!$" history expansion had been specified. | |
726f6388 JA |
5014 | .TP |
5015 | .B shell\-expand\-line (M\-C\-e) | |
cce855bc | 5016 | Expand the line as the shell does. This |
726f6388 JA |
5017 | performs alias and history expansion as well as all of the shell |
5018 | word expansions. See | |
5019 | .SM | |
5020 | .B HISTORY EXPANSION | |
5021 | below for a description of history expansion. | |
5022 | .TP | |
5023 | .B history\-expand\-line (M\-^) | |
d166f048 JA |
5024 | Perform history expansion on the current line. |
5025 | See | |
726f6388 JA |
5026 | .SM |
5027 | .B HISTORY EXPANSION | |
5028 | below for a description of history expansion. | |
5029 | .TP | |
cce855bc JA |
5030 | .B magic\-space |
5031 | Perform history expansion on the current line and insert a space. | |
5032 | See | |
5033 | .SM | |
5034 | .B HISTORY EXPANSION | |
5035 | below for a description of history expansion. | |
5036 | .TP | |
d166f048 JA |
5037 | .B alias\-expand\-line |
5038 | Perform alias expansion on the current line. | |
5039 | See | |
5040 | .SM | |
5041 | .B ALIASES | |
5042 | above for a description of alias expansion. | |
5043 | .TP | |
5044 | .B history\-and\-alias\-expand\-line | |
5045 | Perform history and alias expansion on the current line. | |
5046 | .TP | |
726f6388 JA |
5047 | .B insert\-last\-argument (M\-.\^, M\-_\^) |
5048 | A synonym for \fByank\-last\-arg\fP. | |
5049 | .TP | |
ccc6cda3 | 5050 | .B operate\-and\-get\-next (C\-o) |
726f6388 JA |
5051 | Accept the current line for execution and fetch the next line |
5052 | relative to the current line from the history for editing. Any | |
5053 | argument is ignored. | |
7117c2d2 JA |
5054 | .TP |
5055 | .B edit\-and\-execute\-command (C\-xC\-e) | |
5056 | Invoke an editor on the current command line, and execute the result as shell | |
5057 | commands. | |
5058 | \fBBash\fP attempts to invoke | |
5059 | .SM | |
5060 | .BR $FCEDIT , | |
5061 | .SM | |
5062 | .BR $EDITOR , | |
5063 | and \fIemacs\fP as the editor, in that order. | |
726f6388 JA |
5064 | .PD |
5065 | .SS Commands for Changing Text | |
5066 | .PP | |
5067 | .PD 0 | |
5068 | .TP | |
5069 | .B delete\-char (C\-d) | |
28ef6c31 | 5070 | Delete the character at point. If point is at the |
726f6388 | 5071 | beginning of the line, there are no characters in the line, and |
cce855bc | 5072 | the last character typed was not bound to \fBdelete\-char\fP, |
726f6388 JA |
5073 | then return |
5074 | .SM | |
5075 | .BR EOF . | |
5076 | .TP | |
5077 | .B backward\-delete\-char (Rubout) | |
5078 | Delete the character behind the cursor. When given a numeric argument, | |
ccc6cda3 | 5079 | save the deleted text on the kill ring. |
726f6388 | 5080 | .TP |
b72432fd JA |
5081 | .B forward\-backward\-delete\-char |
5082 | Delete the character under the cursor, unless the cursor is at the | |
5083 | end of the line, in which case the character behind the cursor is | |
f73dda09 | 5084 | deleted. |
b72432fd | 5085 | .TP |
726f6388 | 5086 | .B quoted\-insert (C\-q, C\-v) |
cce855bc | 5087 | Add the next character typed to the line verbatim. This is |
726f6388 JA |
5088 | how to insert characters like \fBC\-q\fP, for example. |
5089 | .TP | |
ccc6cda3 | 5090 | .B tab\-insert (C\-v TAB) |
726f6388 JA |
5091 | Insert a tab character. |
5092 | .TP | |
5093 | .B self\-insert (a,\ b,\ A,\ 1,\ !,\ ...) | |
5094 | Insert the character typed. | |
5095 | .TP | |
5096 | .B transpose\-chars (C\-t) | |
28ef6c31 JA |
5097 | Drag the character before point forward over the character at point, |
5098 | moving point forward as well. | |
5099 | If point is at the end of the line, then this transposes | |
5100 | the two characters before point. | |
bb70624e | 5101 | Negative arguments have no effect. |
726f6388 JA |
5102 | .TP |
5103 | .B transpose\-words (M\-t) | |
bb70624e | 5104 | Drag the word before point past the word after point, |
28ef6c31 | 5105 | moving point over that word as well. |
f73dda09 JA |
5106 | If point is at the end of the line, this transposes |
5107 | the last two words on the line. | |
726f6388 JA |
5108 | .TP |
5109 | .B upcase\-word (M\-u) | |
5110 | Uppercase the current (or following) word. With a negative argument, | |
cce855bc | 5111 | uppercase the previous word, but do not move point. |
726f6388 JA |
5112 | .TP |
5113 | .B downcase\-word (M\-l) | |
5114 | Lowercase the current (or following) word. With a negative argument, | |
cce855bc | 5115 | lowercase the previous word, but do not move point. |
726f6388 JA |
5116 | .TP |
5117 | .B capitalize\-word (M\-c) | |
5118 | Capitalize the current (or following) word. With a negative argument, | |
cce855bc | 5119 | capitalize the previous word, but do not move point. |
7117c2d2 JA |
5120 | .TP |
5121 | .B overwrite\-mode | |
5122 | Toggle overwrite mode. With an explicit positive numeric argument, | |
5123 | switches to overwrite mode. With an explicit non-positive numeric | |
5124 | argument, switches to insert mode. This command affects only | |
5125 | \fBemacs\fP mode; \fBvi\fP mode does overwrite differently. | |
5126 | Each call to \fIreadline()\fP starts in insert mode. | |
5127 | In overwrite mode, characters bound to \fBself\-insert\fP replace | |
5128 | the text at point rather than pushing the text to the right. | |
5129 | Characters bound to \fBbackward\-delete\-char\fP replace the character | |
5130 | before point with a space. By default, this command is unbound. | |
726f6388 JA |
5131 | .PD |
5132 | .SS Killing and Yanking | |
5133 | .PP | |
5134 | .PD 0 | |
5135 | .TP | |
5136 | .B kill\-line (C\-k) | |
bb70624e | 5137 | Kill the text from point to the end of the line. |
726f6388 | 5138 | .TP |
ccc6cda3 | 5139 | .B backward\-kill\-line (C\-x Rubout) |
726f6388 JA |
5140 | Kill backward to the beginning of the line. |
5141 | .TP | |
5142 | .B unix\-line\-discard (C\-u) | |
5143 | Kill backward from point to the beginning of the line. | |
cce855bc | 5144 | The killed text is saved on the kill-ring. |
bb70624e | 5145 | .\" There is no real difference between this and backward-kill-line |
726f6388 JA |
5146 | .TP |
5147 | .B kill\-whole\-line | |
bb70624e | 5148 | Kill all characters on the current line, no matter where point is. |
726f6388 JA |
5149 | .TP |
5150 | .B kill\-word (M\-d) | |
bb70624e JA |
5151 | Kill from point to the end of the current word, or if between |
5152 | words, to the end of the next word. | |
5153 | Word boundaries are the same as those used by \fBforward\-word\fP. | |
726f6388 JA |
5154 | .TP |
5155 | .B backward\-kill\-word (M\-Rubout) | |
bb70624e JA |
5156 | Kill the word behind point. |
5157 | Word boundaries are the same as those used by \fBbackward\-word\fP. | |
726f6388 JA |
5158 | .TP |
5159 | .B unix\-word\-rubout (C\-w) | |
bb70624e | 5160 | Kill the word behind point, using white space as a word boundary. |
bb70624e | 5161 | The killed text is saved on the kill-ring. |
113d85a4 CR |
5162 | .TP |
5163 | .B unix\-filename\-rubout | |
5164 | Kill the word behind point, using white space and the slash character | |
5165 | as the word boundaries. | |
5166 | The killed text is saved on the kill-ring. | |
ccc6cda3 JA |
5167 | .TP |
5168 | .B delete\-horizontal\-space (M\-\e) | |
5169 | Delete all spaces and tabs around point. | |
5170 | .TP | |
5171 | .B kill\-region | |
bb70624e | 5172 | Kill the text in the current region. |
ccc6cda3 JA |
5173 | .TP |
5174 | .B copy\-region\-as\-kill | |
5175 | Copy the text in the region to the kill buffer. | |
726f6388 | 5176 | .TP |
ccc6cda3 JA |
5177 | .B copy\-backward\-word |
5178 | Copy the word before point to the kill buffer. | |
cce855bc | 5179 | The word boundaries are the same as \fBbackward\-word\fP. |
ccc6cda3 JA |
5180 | .TP |
5181 | .B copy\-forward\-word | |
5182 | Copy the word following point to the kill buffer. | |
cce855bc | 5183 | The word boundaries are the same as \fBforward\-word\fP. |
726f6388 JA |
5184 | .TP |
5185 | .B yank (C\-y) | |
28ef6c31 | 5186 | Yank the top of the kill ring into the buffer at point. |
726f6388 JA |
5187 | .TP |
5188 | .B yank\-pop (M\-y) | |
ccc6cda3 | 5189 | Rotate the kill ring, and yank the new top. Only works following |
726f6388 JA |
5190 | .B yank |
5191 | or | |
5192 | .BR yank\-pop . | |
5193 | .PD | |
5194 | .SS Numeric Arguments | |
5195 | .PP | |
5196 | .PD 0 | |
5197 | .TP | |
5198 | .B digit\-argument (M\-0, M\-1, ..., M\-\-) | |
5199 | Add this digit to the argument already accumulating, or start a new | |
5200 | argument. M\-\- starts a negative argument. | |
5201 | .TP | |
5202 | .B universal\-argument | |
d166f048 JA |
5203 | This is another way to specify an argument. |
5204 | If this command is followed by one or more digits, optionally with a | |
5205 | leading minus sign, those digits define the argument. | |
5206 | If the command is followed by digits, executing | |
5207 | .B universal\-argument | |
5208 | again ends the numeric argument, but is otherwise ignored. | |
5209 | As a special case, if this command is immediately followed by a | |
5210 | character that is neither a digit or minus sign, the argument count | |
5211 | for the next command is multiplied by four. | |
726f6388 | 5212 | The argument count is initially one, so executing this function the |
d166f048 JA |
5213 | first time makes the argument count four, a second time makes the |
5214 | argument count sixteen, and so on. | |
726f6388 JA |
5215 | .PD |
5216 | .SS Completing | |
5217 | .PP | |
5218 | .PD 0 | |
5219 | .TP | |
5220 | .B complete (TAB) | |
5221 | Attempt to perform completion on the text before point. | |
5222 | .B Bash | |
5223 | attempts completion treating the text as a variable (if the | |
5224 | text begins with \fB$\fP), username (if the text begins with | |
5225 | \fB~\fP), hostname (if the text begins with \fB@\fP), or | |
5226 | command (including aliases and functions) in turn. If none | |
5227 | of these produces a match, filename completion is attempted. | |
5228 | .TP | |
ccc6cda3 | 5229 | .B possible\-completions (M\-?) |
726f6388 JA |
5230 | List the possible completions of the text before point. |
5231 | .TP | |
ccc6cda3 | 5232 | .B insert\-completions (M\-*) |
726f6388 JA |
5233 | Insert all completions of the text before point |
5234 | that would have been generated by | |
ccc6cda3 | 5235 | \fBpossible\-completions\fP. |
726f6388 | 5236 | .TP |
cce855bc JA |
5237 | .B menu\-complete |
5238 | Similar to \fBcomplete\fP, but replaces the word to be completed | |
5239 | with a single match from the list of possible completions. | |
5240 | Repeated execution of \fBmenu\-complete\fP steps through the list | |
5241 | of possible completions, inserting each match in turn. | |
28ef6c31 | 5242 | At the end of the list of completions, the bell is rung |
f73dda09 | 5243 | (subject to the setting of \fBbell\-style\fP) |
28ef6c31 | 5244 | and the original text is restored. |
cce855bc JA |
5245 | An argument of \fIn\fP moves \fIn\fP positions forward in the list |
5246 | of matches; a negative argument may be used to move backward | |
5247 | through the list. | |
5248 | This command is intended to be bound to \fBTAB\fP, but is unbound | |
5249 | by default. | |
5250 | .TP | |
b72432fd JA |
5251 | .B delete\-char\-or\-list |
5252 | Deletes the character under the cursor if not at the beginning or | |
bb70624e | 5253 | end of the line (like \fBdelete\-char\fP). |
b72432fd | 5254 | If at the end of the line, behaves identically to |
bb70624e | 5255 | \fBpossible\-completions\fP. |
b72432fd JA |
5256 | This command is unbound by default. |
5257 | .TP | |
726f6388 JA |
5258 | .B complete\-filename (M\-/) |
5259 | Attempt filename completion on the text before point. | |
5260 | .TP | |
5261 | .B possible\-filename\-completions (C\-x /) | |
5262 | List the possible completions of the text before point, | |
5263 | treating it as a filename. | |
5264 | .TP | |
5265 | .B complete\-username (M\-~) | |
5266 | Attempt completion on the text before point, treating | |
5267 | it as a username. | |
5268 | .TP | |
5269 | .B possible\-username\-completions (C\-x ~) | |
5270 | List the possible completions of the text before point, | |
5271 | treating it as a username. | |
5272 | .TP | |
5273 | .B complete\-variable (M\-$) | |
5274 | Attempt completion on the text before point, treating | |
5275 | it as a shell variable. | |
5276 | .TP | |
5277 | .B possible\-variable\-completions (C\-x $) | |
5278 | List the possible completions of the text before point, | |
5279 | treating it as a shell variable. | |
5280 | .TP | |
5281 | .B complete\-hostname (M\-@) | |
5282 | Attempt completion on the text before point, treating | |
5283 | it as a hostname. | |
5284 | .TP | |
5285 | .B possible\-hostname\-completions (C\-x @) | |
5286 | List the possible completions of the text before point, | |
5287 | treating it as a hostname. | |
5288 | .TP | |
5289 | .B complete\-command (M\-!) | |
5290 | Attempt completion on the text before point, treating | |
5291 | it as a command name. Command completion attempts to | |
5292 | match the text against aliases, reserved words, shell | |
cce855bc | 5293 | functions, shell builtins, and finally executable filenames, |
726f6388 JA |
5294 | in that order. |
5295 | .TP | |
5296 | .B possible\-command\-completions (C\-x !) | |
5297 | List the possible completions of the text before point, | |
5298 | treating it as a command name. | |
5299 | .TP | |
ccc6cda3 | 5300 | .B dynamic\-complete\-history (M\-TAB) |
726f6388 JA |
5301 | Attempt completion on the text before point, comparing |
5302 | the text against lines from the history list for possible | |
5303 | completion matches. | |
5304 | .TP | |
5305 | .B complete\-into\-braces (M\-{) | |
bb70624e | 5306 | Perform filename completion and insert the list of possible completions |
726f6388 JA |
5307 | enclosed within braces so the list is available to the shell (see |
5308 | .B Brace Expansion | |
5309 | above). | |
5310 | .PD | |
5311 | .SS Keyboard Macros | |
5312 | .PP | |
5313 | .PD 0 | |
5314 | .TP | |
ccc6cda3 | 5315 | .B start\-kbd\-macro (C\-x (\^) |
726f6388 JA |
5316 | Begin saving the characters typed into the current keyboard macro. |
5317 | .TP | |
ccc6cda3 | 5318 | .B end\-kbd\-macro (C\-x )\^) |
726f6388 | 5319 | Stop saving the characters typed into the current keyboard macro |
ccc6cda3 | 5320 | and store the definition. |
726f6388 | 5321 | .TP |
ccc6cda3 | 5322 | .B call\-last\-kbd\-macro (C\-x e) |
726f6388 JA |
5323 | Re-execute the last keyboard macro defined, by making the characters |
5324 | in the macro appear as if typed at the keyboard. | |
5325 | .PD | |
5326 | .SS Miscellaneous | |
5327 | .PP | |
5328 | .PD 0 | |
5329 | .TP | |
5330 | .B re\-read\-init\-file (C\-x C\-r) | |
ccc6cda3 | 5331 | Read in the contents of the \fIinputrc\fP file, and incorporate |
726f6388 JA |
5332 | any bindings or variable assignments found there. |
5333 | .TP | |
5334 | .B abort (C\-g) | |
5335 | Abort the current editing command and | |
5336 | ring the terminal's bell (subject to the setting of | |
5337 | .BR bell\-style ). | |
5338 | .TP | |
ccc6cda3 JA |
5339 | .B do\-uppercase\-version (M\-a, M\-b, M\-\fIx\fP, ...) |
5340 | If the metafied character \fIx\fP is lowercase, run the command | |
5341 | that is bound to the corresponding uppercase character. | |
726f6388 JA |
5342 | .TP |
5343 | .B prefix\-meta (ESC) | |
5344 | Metafy the next character typed. | |
5345 | .SM | |
5346 | .B ESC | |
5347 | .B f | |
5348 | is equivalent to | |
5349 | .BR Meta\-f . | |
5350 | .TP | |
5351 | .B undo (C\-_, C\-x C\-u) | |
5352 | Incremental undo, separately remembered for each line. | |
5353 | .TP | |
5354 | .B revert\-line (M\-r) | |
cce855bc | 5355 | Undo all changes made to this line. This is like executing the |
726f6388 JA |
5356 | .B undo |
5357 | command enough times to return the line to its initial state. | |
5358 | .TP | |
b72432fd | 5359 | .B tilde\-expand (M\-&) |
726f6388 JA |
5360 | Perform tilde expansion on the current word. |
5361 | .TP | |
ccc6cda3 | 5362 | .B set\-mark (C\-@, M\-<space>) |
28ef6c31 | 5363 | Set the mark to the point. If a |
ccc6cda3 JA |
5364 | numeric argument is supplied, the mark is set to that position. |
5365 | .TP | |
5366 | .B exchange\-point\-and\-mark (C\-x C\-x) | |
5367 | Swap the point with the mark. The current cursor position is set to | |
5368 | the saved position, and the old cursor position is saved as the mark. | |
5369 | .TP | |
5370 | .B character\-search (C\-]) | |
5371 | A character is read and point is moved to the next occurrence of that | |
5372 | character. A negative count searches for previous occurrences. | |
5373 | .TP | |
5374 | .B character\-search\-backward (M\-C\-]) | |
5375 | A character is read and point is moved to the previous occurrence of that | |
5376 | character. A negative count searches for subsequent occurrences. | |
5377 | .TP | |
5378 | .B insert\-comment (M\-#) | |
7117c2d2 | 5379 | Without a numeric argument, the value of the readline |
ccc6cda3 | 5380 | .B comment\-begin |
7117c2d2 JA |
5381 | variable is inserted at the beginning of the current line. |
5382 | If a numeric argument is supplied, this command acts as a toggle: if | |
5383 | the characters at the beginning of the line do not match the value | |
5384 | of \fBcomment\-begin\fP, the value is inserted, otherwise | |
5385 | the characters in \fBcomment-begin\fP are deleted from the beginning of | |
5386 | the line. | |
5387 | In either case, the line is accepted as if a newline had been typed. | |
5388 | The default value of | |
bb70624e | 5389 | \fBcomment\-begin\fP causes this command to make the current line |
ccc6cda3 | 5390 | a shell comment. |
7117c2d2 JA |
5391 | If a numeric argument causes the comment character to be removed, the line |
5392 | will be executed by the shell. | |
5393 | .TP | |
5394 | .B glob\-complete\-word (M\-g) | |
5395 | The word before point is treated as a pattern for pathname expansion, | |
5396 | with an asterisk implicitly appended. This pattern is used to | |
5397 | generate a list of matching file names for possible completions. | |
ccc6cda3 JA |
5398 | .TP |
5399 | .B glob\-expand\-word (C\-x *) | |
5400 | The word before point is treated as a pattern for pathname expansion, | |
5401 | and the list of matching file names is inserted, replacing the word. | |
7117c2d2 JA |
5402 | If a numeric argument is supplied, an asterisk is appended before |
5403 | pathname expansion. | |
ccc6cda3 JA |
5404 | .TP |
5405 | .B glob\-list\-expansions (C\-x g) | |
5406 | The list of expansions that would have been generated by | |
5407 | .B glob\-expand\-word | |
5408 | is displayed, and the line is redrawn. | |
7117c2d2 JA |
5409 | If a numeric argument is supplied, an asterisk is appended before |
5410 | pathname expansion. | |
ccc6cda3 | 5411 | .TP |
726f6388 JA |
5412 | .B dump\-functions |
5413 | Print all of the functions and their key bindings to the | |
5414 | readline output stream. If a numeric argument is supplied, | |
5415 | the output is formatted in such a way that it can be made part | |
5416 | of an \fIinputrc\fP file. | |
5417 | .TP | |
ccc6cda3 JA |
5418 | .B dump\-variables |
5419 | Print all of the settable readline variables and their values to the | |
5420 | readline output stream. If a numeric argument is supplied, | |
5421 | the output is formatted in such a way that it can be made part | |
5422 | of an \fIinputrc\fP file. | |
5423 | .TP | |
5424 | .B dump\-macros | |
5425 | Print all of the readline key sequences bound to macros and the | |
22e63b05 | 5426 | strings they output. If a numeric argument is supplied, |
ccc6cda3 JA |
5427 | the output is formatted in such a way that it can be made part |
5428 | of an \fIinputrc\fP file. | |
5429 | .TP | |
726f6388 JA |
5430 | .B display\-shell\-version (C\-x C\-v) |
5431 | Display version information about the current instance of | |
5432 | .BR bash . | |
5433 | .PD | |
bb70624e JA |
5434 | .SS Programmable Completion |
5435 | .PP | |
5436 | When word completion is attempted for an argument to a command for | |
5437 | which a completion specification (a \fIcompspec\fP) has been defined | |
5438 | using the \fBcomplete\fP builtin (see | |
5439 | .SM | |
5440 | .B "SHELL BUILTIN COMMANDS" | |
5441 | below), the programmable completion facilities are invoked. | |
5442 | .PP | |
5443 | First, the command name is identified. | |
5444 | If a compspec has been defined for that command, the | |
5445 | compspec is used to generate the list of possible completions for the word. | |
5446 | If the command word is a full pathname, a compspec for the full | |
5447 | pathname is searched for first. | |
5448 | If no compspec is found for the full pathname, an attempt is made to | |
5449 | find a compspec for the portion following the final slash. | |
5450 | .PP | |
5451 | Once a compspec has been found, it is used to generate the list of | |
5452 | matching words. | |
5453 | If a compspec is not found, the default \fBbash\fP completion as | |
5454 | described above under \fBCompleting\fP is performed. | |
5455 | .PP | |
5456 | First, the actions specified by the compspec are used. | |
5457 | Only matches which are prefixed by the word being completed are | |
5458 | returned. | |
5459 | When the | |
5460 | .B \-f | |
5461 | or | |
5462 | .B \-d | |
5463 | option is used for filename or directory name completion, the shell | |
5464 | variable | |
5465 | .SM | |
5466 | .B FIGNORE | |
5467 | is used to filter the matches. | |
5468 | .PP | |
5469 | Any completions specified by a filename expansion pattern to the | |
5470 | \fB\-G\fP option are generated next. | |
5471 | The words generated by the pattern need not match the word | |
5472 | being completed. | |
5473 | The | |
5474 | .SM | |
5475 | .B GLOBIGNORE | |
5476 | shell variable is not used to filter the matches, but the | |
5477 | .SM | |
5478 | .B FIGNORE | |
5479 | variable is used. | |
5480 | .PP | |
5481 | Next, the string specified as the argument to the \fB\-W\fP option | |
5482 | is considered. | |
5483 | The string is first split using the characters in the | |
5484 | .SM | |
5485 | .B IFS | |
5486 | special variable as delimiters. | |
5487 | Shell quoting is honored. | |
5488 | Each word is then expanded using | |
5489 | brace expansion, tilde expansion, parameter and variable expansion, | |
6e70dbff | 5490 | command substitution, and arithmetic expansion, |
bb70624e JA |
5491 | as described above under |
5492 | .SM | |
5493 | .BR EXPANSION . | |
5494 | The results are split using the rules described above under | |
5495 | \fBWord Splitting\fP. | |
5496 | The results of the expansion are prefix-matched against the word being | |
5497 | completed, and the matching words become the possible completions. | |
5498 | .PP | |
5499 | After these matches have been generated, any shell function or command | |
5500 | specified with the \fB\-F\fP and \fB\-C\fP options is invoked. | |
5501 | When the command or function is invoked, the | |
5502 | .SM | |
d3ad40de CR |
5503 | .BR COMP_LINE , |
5504 | .SM | |
5505 | .BR COMP_POINT , | |
5506 | .SM | |
5507 | .BR COMP_KEY , | |
bb70624e JA |
5508 | and |
5509 | .SM | |
d3ad40de | 5510 | .B COMP_TYPE |
bb70624e JA |
5511 | variables are assigned values as described above under |
5512 | \fBShell Variables\fP. | |
5513 | If a shell function is being invoked, the | |
5514 | .SM | |
5515 | .B COMP_WORDS | |
5516 | and | |
5517 | .SM | |
5518 | .B COMP_CWORD | |
5519 | variables are also set. | |
5520 | When the function or command is invoked, the first argument is the | |
5521 | name of the command whose arguments are being completed, the | |
5522 | second argument is the word being completed, and the third argument | |
5523 | is the word preceding the word being completed on the current command line. | |
5524 | No filtering of the generated completions against the word being completed | |
5525 | is performed; the function or command has complete freedom in generating | |
5526 | the matches. | |
5527 | .PP | |
5528 | Any function specified with \fB\-F\fP is invoked first. | |
5529 | The function may use any of the shell facilities, including the | |
5530 | \fBcompgen\fP builtin described below, to generate the matches. | |
5531 | It must put the possible completions in the | |
5532 | .SM | |
5533 | .B COMPREPLY | |
5534 | array variable. | |
5535 | .PP | |
5536 | Next, any command specified with the \fB\-C\fP option is invoked | |
5537 | in an environment equivalent to command substitution. | |
5538 | It should print a list of completions, one per line, to the | |
5539 | standard output. | |
5540 | Backslash may be used to escape a newline, if necessary. | |
5541 | .PP | |
5542 | After all of the possible completions are generated, any filter | |
5543 | specified with the \fB\-X\fP option is applied to the list. | |
5544 | The filter is a pattern as used for pathname expansion; a \fB&\fP | |
5545 | in the pattern is replaced with the text of the word being completed. | |
5546 | A literal \fB&\fP may be escaped with a backslash; the backslash | |
5547 | is removed before attempting a match. | |
5548 | Any completion that matches the pattern will be removed from the list. | |
5549 | A leading \fB!\fP negates the pattern; in this case any completion | |
5550 | not matching the pattern will be removed. | |
5551 | .PP | |
5552 | Finally, any prefix and suffix specified with the \fB\-P\fP and \fB\-S\fP | |
5553 | options are added to each member of the completion list, and the result is | |
5554 | returned to the readline completion code as the list of possible | |
5555 | completions. | |
5556 | .PP | |
28ef6c31 JA |
5557 | If the previously-applied actions do not generate any matches, and the |
5558 | \fB\-o dirnames\fP option was supplied to \fBcomplete\fP when the | |
5559 | compspec was defined, directory name completion is attempted. | |
5560 | .PP | |
d3a24ed2 CR |
5561 | If the \fB\-o plusdirs\fP option was supplied to \fBcomplete\fP when the |
5562 | compspec was defined, directory name completion is attempted and any | |
5563 | matches are added to the results of the other actions. | |
5564 | .PP | |
28ef6c31 JA |
5565 | By default, if a compspec is found, whatever it generates is returned |
5566 | to the completion code as the full set of possible completions. | |
bb70624e JA |
5567 | The default \fBbash\fP completions are not attempted, and the readline |
5568 | default of filename completion is disabled. | |
d3a24ed2 CR |
5569 | If the \fB\-o bashdefault\fP option was supplied to \fBcomplete\fP when |
5570 | the compspec was defined, the \fBbash\fP default completions are attempted | |
28ef6c31 | 5571 | if the compspec generates no matches. |
d3a24ed2 CR |
5572 | If the \fB\-o default\fP option was supplied to \fBcomplete\fP when the |
5573 | compspec was defined, readline's default completion will be performed | |
5574 | if the compspec (and, if attempted, the default \fBbash\fP completions) | |
5575 | generate no matches. | |
7117c2d2 JA |
5576 | .PP |
5577 | When a compspec indicates that directory name completion is desired, | |
5578 | the programmable completion functions force readline to append a slash | |
5579 | to completed names which are symbolic links to directories, subject to | |
5580 | the value of the \fBmark\-directories\fP readline variable, regardless | |
5581 | of the setting of the \fBmark-symlinked\-directories\fP readline variable. | |
726f6388 | 5582 | .SH HISTORY |
ccc6cda3 | 5583 | When the |
d166f048 | 5584 | .B \-o history |
ccc6cda3 JA |
5585 | option to the |
5586 | .B set | |
5587 | builtin is enabled, the shell provides access to the | |
5588 | \fIcommand history\fP, | |
bb70624e JA |
5589 | the list of commands previously typed. |
5590 | The value of the \fBHISTSIZE\fP variable is used as the | |
5591 | number of commands to save in a history list. | |
5592 | The text of the last | |
726f6388 JA |
5593 | .SM |
5594 | .B HISTSIZE | |
bb70624e | 5595 | commands (default 500) is saved. The shell |
726f6388 JA |
5596 | stores each command in the history list prior to parameter and |
5597 | variable expansion (see | |
5598 | .SM | |
5599 | .B EXPANSION | |
5600 | above) but after history expansion is performed, subject to the | |
5601 | values of the shell variables | |
ccc6cda3 JA |
5602 | .SM |
5603 | .B HISTIGNORE | |
726f6388 JA |
5604 | and |
5605 | .SM | |
5606 | .BR HISTCONTROL . | |
bb70624e | 5607 | .PP |
726f6388 JA |
5608 | On startup, the history is initialized from the file named by |
5609 | the variable | |
5610 | .SM | |
5611 | .B HISTFILE | |
5612 | (default \fI~/.bash_history\fP). | |
bb70624e | 5613 | The file named by the value of |
726f6388 JA |
5614 | .SM |
5615 | .B HISTFILE | |
5616 | is truncated, if necessary, to contain no more than | |
bb70624e | 5617 | the number of lines specified by the value of |
726f6388 | 5618 | .SM |
bb70624e | 5619 | .BR HISTFILESIZE . |
d3ad40de CR |
5620 | When the history file is read, |
5621 | lines beginning with the history comment character followed immediately | |
5622 | by a digit are interpreted as timestamps for the preceding history line. | |
5623 | These timestamps are optionally displayed depending on the value of the | |
5624 | .SM | |
5625 | .B HISTTIMEFORMAT | |
5626 | variable. | |
ccc6cda3 JA |
5627 | When an interactive shell exits, the last |
5628 | .SM | |
bb70624e | 5629 | .B $HISTSIZE |
ccc6cda3 JA |
5630 | lines are copied from the history list to |
5631 | .SM | |
bb70624e | 5632 | .BR $HISTFILE . |
ccc6cda3 JA |
5633 | If the |
5634 | .B histappend | |
5635 | shell option is enabled | |
5636 | (see the description of | |
5637 | .B shopt | |
5638 | under | |
5639 | .SM | |
5640 | .B "SHELL BUILTIN COMMANDS" | |
5641 | below), the lines are appended to the history file, | |
5642 | otherwise the history file is overwritten. | |
5643 | If | |
5644 | .SM | |
5645 | .B HISTFILE | |
5646 | is unset, or if the history file is unwritable, the history is | |
d3ad40de CR |
5647 | not saved. |
5648 | If the | |
5649 | .SM | |
5650 | .HISTTIMEFORMAT | |
5651 | variable is set, time stamps are written to the history file, marked | |
5652 | with the history comment character, so | |
5653 | they may be preserved across shell sessions. | |
5654 | This uses the history comment character to distinguish timestamps from | |
5655 | other history lines. | |
5656 | After saving the history, the history file is truncated | |
ccc6cda3 JA |
5657 | to contain no more than |
5658 | .SM | |
5659 | .B HISTFILESIZE | |
5660 | lines. If | |
5661 | .SM | |
5662 | .B HISTFILESIZE | |
5663 | is not set, no truncation is performed. | |
5664 | .PP | |
726f6388 JA |
5665 | The builtin command |
5666 | .B fc | |
5667 | (see | |
5668 | .SM | |
5669 | .B SHELL BUILTIN COMMANDS | |
5670 | below) may be used to list or edit and re-execute a portion of | |
5671 | the history list. | |
5672 | The | |
5673 | .B history | |
bb70624e | 5674 | builtin may be used to display or modify the history list and |
ccc6cda3 | 5675 | manipulate the history file. |
bb70624e | 5676 | When using command-line editing, search commands |
726f6388 | 5677 | are available in each editing mode that provide access to the |
ccc6cda3 JA |
5678 | history list. |
5679 | .PP | |
5680 | The shell allows control over which commands are saved on the history | |
5681 | list. The | |
726f6388 | 5682 | .SM |
ccc6cda3 JA |
5683 | .B HISTCONTROL |
5684 | and | |
726f6388 | 5685 | .SM |
ccc6cda3 JA |
5686 | .B HISTIGNORE |
5687 | variables may be set to cause the shell to save only a subset of the | |
5688 | commands entered. | |
5689 | The | |
5690 | .B cmdhist | |
5691 | shell option, if enabled, causes the shell to attempt to save each | |
5692 | line of a multi-line command in the same history entry, adding | |
5693 | semicolons where necessary to preserve syntactic correctness. | |
5694 | The | |
5695 | .B lithist | |
5696 | shell option causes the shell to save the command with embedded newlines | |
5697 | instead of semicolons. See the description of the | |
5698 | .B shopt | |
5699 | builtin below under | |
5700 | .SM | |
5701 | .B "SHELL BUILTIN COMMANDS" | |
5702 | for information on setting and unsetting shell options. | |
726f6388 JA |
5703 | .SH "HISTORY EXPANSION" |
5704 | .PP | |
5705 | The shell supports a history expansion feature that | |
5706 | is similar to the history expansion in | |
5707 | .BR csh. | |
5708 | This section describes what syntax features are available. This | |
5709 | feature is enabled by default for interactive shells, and can be | |
5710 | disabled using the | |
5711 | .B \+H | |
5712 | option to the | |
5713 | .B set | |
5714 | builtin command (see | |
5715 | .SM | |
5716 | .B SHELL BUILTIN COMMANDS | |
ccc6cda3 JA |
5717 | below). Non-interactive shells do not perform history expansion |
5718 | by default. | |
5719 | .PP | |
5720 | History expansions introduce words from the history list into | |
5721 | the input stream, making it easy to repeat commands, insert the | |
5722 | arguments to a previous command into the current input line, or | |
5723 | fix errors in previous commands quickly. | |
726f6388 JA |
5724 | .PP |
5725 | History expansion is performed immediately after a complete line | |
5726 | is read, before the shell breaks it into words. | |
ccc6cda3 | 5727 | It takes place in two parts. |
cce855bc | 5728 | The first is to determine which line from the history list |
ccc6cda3 JA |
5729 | to use during substitution. |
5730 | The second is to select portions of that line for inclusion into | |
5731 | the current one. | |
cce855bc | 5732 | The line selected from the history is the \fIevent\fP, |
ccc6cda3 JA |
5733 | and the portions of that line that are acted upon are \fIwords\fP. |
5734 | Various \fImodifiers\fP are available to manipulate the selected words. | |
5735 | The line is broken into words in the same fashion as when reading input, | |
5736 | so that several \fImetacharacter\fP-separated words surrounded by | |
cce855bc | 5737 | quotes are considered one word. |
ccc6cda3 JA |
5738 | History expansions are introduced by the appearance of the |
5739 | history expansion character, which is \^\fB!\fP\^ by default. | |
5740 | Only backslash (\^\fB\e\fP\^) and single quotes can quote | |
5741 | the history expansion character. | |
5742 | .PP | |
d3a24ed2 CR |
5743 | Several characters inhibit history expansion if found immediately |
5744 | following the history expansion character, even if it is unquoted: | |
5745 | space, tab, newline, carriage return, and \fB=\fP. | |
5746 | If the \fBextglob\fP shell option is enabled, \fB(\fP will also | |
5747 | inhibit expansion. | |
5748 | .PP | |
ccc6cda3 JA |
5749 | Several shell options settable with the |
5750 | .B shopt | |
5751 | builtin may be used to tailor the behavior of history expansion. | |
5752 | If the | |
5753 | .B histverify | |
5754 | shell option is enabled (see the description of the | |
5755 | .B shopt | |
5756 | builtin), and | |
5757 | .B readline | |
5758 | is being used, history substitutions are not immediately passed to | |
5759 | the shell parser. | |
5760 | Instead, the expanded line is reloaded into the | |
5761 | .B readline | |
5762 | editing buffer for further modification. | |
5763 | If | |
5764 | .B readline | |
5765 | is being used, and the | |
5766 | .B histreedit | |
5767 | shell option is enabled, a failed history substitution will be reloaded | |
5768 | into the | |
5769 | .B readline | |
5770 | editing buffer for correction. | |
5771 | The | |
5772 | .B \-p | |
5773 | option to the | |
5774 | .B history | |
5775 | builtin command may be used to see what a history expansion will | |
5776 | do before using it. | |
5777 | The | |
5778 | .B \-s | |
5779 | option to the | |
5780 | .B history | |
5781 | builtin may be used to add commands to the end of the history list | |
5782 | without actually executing them, so that they are available for | |
5783 | subsequent recall. | |
726f6388 JA |
5784 | .PP |
5785 | The shell allows control of the various characters used by the | |
5786 | history expansion mechanism (see the description of | |
5787 | .B histchars | |
5788 | above under | |
5789 | .BR "Shell Variables" ). | |
d3ad40de CR |
5790 | The shell uses |
5791 | the history comment character to mark history timestamps when | |
5792 | writing the history file. | |
726f6388 JA |
5793 | .SS Event Designators |
5794 | .PP | |
5795 | An event designator is a reference to a command line entry in the | |
5796 | history list. | |
5797 | .PP | |
5798 | .PD 0 | |
5799 | .TP | |
5800 | .B ! | |
5801 | Start a history substitution, except when followed by a | |
5802 | .BR blank , | |
d3a24ed2 CR |
5803 | newline, carriage return, = |
5804 | or ( (when the \fBextglob\fP shell option is enabled using | |
5805 | the \fBshopt\fP builtin). | |
726f6388 | 5806 | .TP |
726f6388 JA |
5807 | .B !\fIn\fR |
5808 | Refer to command line | |
5809 | .IR n . | |
5810 | .TP | |
5811 | .B !\-\fIn\fR | |
5812 | Refer to the current command line minus | |
5813 | .IR n . | |
5814 | .TP | |
ccc6cda3 JA |
5815 | .B !! |
5816 | Refer to the previous command. This is a synonym for `!\-1'. | |
5817 | .TP | |
726f6388 JA |
5818 | .B !\fIstring\fR |
5819 | Refer to the most recent command starting with | |
5820 | .IR string . | |
5821 | .TP | |
5822 | .B !?\fIstring\fR\fB[?]\fR | |
5823 | Refer to the most recent command containing | |
5824 | .IR string . | |
ccc6cda3 JA |
5825 | The trailing \fB?\fP may be omitted if |
5826 | .I string | |
5827 | is followed immediately by a newline. | |
726f6388 JA |
5828 | .TP |
5829 | .B \d\s+2^\s-2\u\fIstring1\fP\d\s+2^\s-2\u\fIstring2\fP\d\s+2^\s-2\u | |
5830 | Quick substitution. Repeat the last command, replacing | |
5831 | .I string1 | |
5832 | with | |
5833 | .IR string2 . | |
5834 | Equivalent to | |
5835 | ``!!:s/\fIstring1\fP/\fIstring2\fP/'' | |
5836 | (see \fBModifiers\fP below). | |
5837 | .TP | |
5838 | .B !# | |
5839 | The entire command line typed so far. | |
5840 | .PD | |
5841 | .SS Word Designators | |
5842 | .PP | |
ccc6cda3 | 5843 | Word designators are used to select desired words from the event. |
726f6388 JA |
5844 | A |
5845 | .B : | |
ccc6cda3 | 5846 | separates the event specification from the word designator. |
cce855bc | 5847 | It may be omitted if the word designator begins with a |
726f6388 JA |
5848 | .BR ^ , |
5849 | .BR $ , | |
5850 | .BR * , | |
ccc6cda3 | 5851 | .BR \- , |
726f6388 JA |
5852 | or |
5853 | .BR % . | |
5854 | Words are numbered from the beginning of the line, | |
ccc6cda3 JA |
5855 | with the first word being denoted by 0 (zero). |
5856 | Words are inserted into the current line separated by single spaces. | |
726f6388 JA |
5857 | .PP |
5858 | .PD 0 | |
5859 | .TP | |
5860 | .B 0 (zero) | |
5861 | The zeroth word. For the shell, this is the command | |
5862 | word. | |
5863 | .TP | |
5864 | .I n | |
5865 | The \fIn\fRth word. | |
5866 | .TP | |
5867 | .B ^ | |
5868 | The first argument. That is, word 1. | |
5869 | .TP | |
5870 | .B $ | |
5871 | The last argument. | |
5872 | .TP | |
5873 | .B % | |
5874 | The word matched by the most recent `?\fIstring\fR?' search. | |
5875 | .TP | |
5876 | .I x\fB\-\fPy | |
5877 | A range of words; `\-\fIy\fR' abbreviates `0\-\fIy\fR'. | |
5878 | .TP | |
5879 | .B * | |
5880 | All of the words but the zeroth. This is a synonym | |
5881 | for `\fI1\-$\fP'. It is not an error to use | |
5882 | .B * | |
5883 | if there is just one | |
5884 | word in the event; the empty string is returned in that case. | |
5885 | .TP | |
5886 | .B x* | |
5887 | Abbreviates \fIx\-$\fP. | |
5888 | .TP | |
5889 | .B x\- | |
5890 | Abbreviates \fIx\-$\fP like \fBx*\fP, but omits the last word. | |
5891 | .PD | |
ccc6cda3 JA |
5892 | .PP |
5893 | If a word designator is supplied without an event specification, the | |
5894 | previous command is used as the event. | |
726f6388 JA |
5895 | .SS Modifiers |
5896 | .PP | |
ccc6cda3 JA |
5897 | After the optional word designator, there may appear a sequence of |
5898 | one or more of the following modifiers, each preceded by a `:'. | |
726f6388 JA |
5899 | .PP |
5900 | .PD 0 | |
5901 | .PP | |
5902 | .TP | |
5903 | .B h | |
ccc6cda3 JA |
5904 | Remove a trailing file name component, leaving only the head. |
5905 | .TP | |
5906 | .B t | |
5907 | Remove all leading file name components, leaving the tail. | |
726f6388 JA |
5908 | .TP |
5909 | .B r | |
5910 | Remove a trailing suffix of the form \fI.xxx\fP, leaving the | |
5911 | basename. | |
5912 | .TP | |
5913 | .B e | |
5914 | Remove all but the trailing suffix. | |
5915 | .TP | |
726f6388 JA |
5916 | .B p |
5917 | Print the new command but do not execute it. | |
5918 | .TP | |
5919 | .B q | |
5920 | Quote the substituted words, escaping further substitutions. | |
5921 | .TP | |
cce855bc JA |
5922 | .B x |
5923 | Quote the substituted words as with | |
5924 | .BR q , | |
5925 | but break into words at | |
5926 | .B blanks | |
5927 | and newlines. | |
726f6388 | 5928 | .TP |
cce855bc JA |
5929 | .B s/\fIold\fP/\fInew\fP/ |
5930 | Substitute | |
5931 | .I new | |
5932 | for the first occurrence of | |
5933 | .I old | |
5934 | in the event line. Any delimiter can be used in place of /. The | |
5935 | final delimiter is optional if it is the last character of the | |
5936 | event line. The delimiter may be quoted in | |
5937 | .I old | |
5938 | and | |
5939 | .I new | |
5940 | with a single backslash. If & appears in | |
5941 | .IR new , | |
5942 | it is replaced by | |
5943 | .IR old . | |
5944 | A single backslash will quote the &. If | |
5945 | .I old | |
5946 | is null, it is set to the last | |
5947 | .I old | |
5948 | substituted, or, if no previous history substitutions took place, | |
5949 | the last | |
5950 | .I string | |
5951 | in a | |
5952 | .B !?\fIstring\fR\fB[?]\fR | |
5953 | search. | |
ccc6cda3 | 5954 | .TP |
cce855bc JA |
5955 | .B & |
5956 | Repeat the previous substitution. | |
5957 | .TP | |
5958 | .B g | |
5959 | Cause changes to be applied over the entire event line. This is | |
5960 | used in conjunction with `\fB:s\fP' (e.g., `\fB:gs/\fIold\fP/\fInew\fP/\fR') | |
5961 | or `\fB:&\fP'. If used with | |
5962 | `\fB:s\fP', any delimiter can be used | |
5963 | in place of /, and the final delimiter is optional | |
5964 | if it is the last character of the event line. | |
d3a24ed2 CR |
5965 | An \fBa\fP may be used as a synonym for \fBg\fP. |
5966 | .TP | |
5967 | .B G | |
5968 | Apply the following `\fBs\fP' modifier once to each word in the event line. | |
726f6388 | 5969 | .PD |
726f6388 JA |
5970 | .SH "SHELL BUILTIN COMMANDS" |
5971 | .\" start of bash_builtins | |
5972 | .zZ | |
ccc6cda3 JA |
5973 | .PP |
5974 | Unless otherwise noted, each builtin command documented in this | |
5975 | section as accepting options preceded by | |
5976 | .B \- | |
5977 | accepts | |
5978 | .B \-\- | |
5979 | to signify the end of the options. | |
3ffb039a CR |
5980 | For example, the \fB:\fP, \fBtrue\fP, \fBfalse\fP, and \fBtest\fP builtins |
5981 | do not accept options. | |
ccc6cda3 | 5982 | .sp .5 |
726f6388 JA |
5983 | .PD 0 |
5984 | .TP | |
5985 | \fB:\fP [\fIarguments\fP] | |
5986 | .PD | |
5987 | No effect; the command does nothing beyond expanding | |
5988 | .I arguments | |
5989 | and performing any specified | |
5990 | redirections. A zero exit code is returned. | |
5991 | .TP | |
726f6388 | 5992 | \fB .\| \fP \fIfilename\fP [\fIarguments\fP] |
7117c2d2 | 5993 | .PD 0 |
726f6388 JA |
5994 | .TP |
5995 | \fBsource\fP \fIfilename\fP [\fIarguments\fP] | |
5996 | .PD | |
5997 | Read and execute commands from | |
5998 | .I filename | |
5999 | in the current | |
6000 | shell environment and return the exit status of the last command | |
6001 | executed from | |
6002 | .IR filename . | |
6003 | If | |
6004 | .I filename | |
ccc6cda3 | 6005 | does not contain a slash, file names in |
726f6388 JA |
6006 | .SM |
6007 | .B PATH | |
6008 | are used to find the directory containing | |
6009 | .IR filename . | |
6010 | The file searched for in | |
6011 | .SM | |
6012 | .B PATH | |
28ef6c31 JA |
6013 | need not be executable. |
6014 | When \fBbash\fP is not in \fIposix mode\fP, the current directory is | |
726f6388 JA |
6015 | searched if no file is found in |
6016 | .SM | |
6017 | .BR PATH . | |
ccc6cda3 JA |
6018 | If the |
6019 | .B sourcepath | |
6020 | option to the | |
6021 | .B shopt | |
6022 | builtin command is turned off, the | |
6023 | .SM | |
6024 | .B PATH | |
6025 | is not searched. | |
726f6388 | 6026 | If any \fIarguments\fP are supplied, they become the positional |
ccc6cda3 | 6027 | parameters when \fIfilename\fP is executed. Otherwise the positional |
726f6388 JA |
6028 | parameters are unchanged. |
6029 | The return status is the status of the last command exited within | |
6030 | the script (0 if no commands are executed), and false if | |
6031 | .I filename | |
cce855bc | 6032 | is not found or cannot be read. |
726f6388 | 6033 | .TP |
ccc6cda3 JA |
6034 | \fBalias\fP [\fB\-p\fP] [\fIname\fP[=\fIvalue\fP] ...] |
6035 | \fBAlias\fP with no arguments or with the | |
6036 | .B \-p | |
6037 | option prints the list of aliases in the form | |
6038 | \fBalias\fP \fIname\fP=\fIvalue\fP on standard output. | |
6039 | When arguments are supplied, an alias is defined for | |
6040 | each \fIname\fP whose \fIvalue\fP is given. | |
6041 | A trailing space in \fIvalue\fP causes the next word to be | |
6042 | checked for alias substitution when the alias is expanded. | |
6043 | For each \fIname\fP in the argument list for which no \fIvalue\fP | |
6044 | is supplied, the name and value of the alias is printed. | |
6045 | \fBAlias\fP returns true unless a \fIname\fP is given for which | |
6046 | no alias has been defined. | |
726f6388 | 6047 | .TP |
de3341d1 CR |
6048 | \fBbg\fP [\fIjobspec\fP ...] |
6049 | Resume each suspended job \fIjobspec\fP in the background, as if it | |
cce855bc | 6050 | had been started with |
726f6388 | 6051 | .BR & . |
d3ad40de CR |
6052 | If |
6053 | .I jobspec | |
6054 | is not present, the shell's notion of the \fIcurrent job\fP is used. | |
726f6388 JA |
6055 | .B bg |
6056 | .I jobspec | |
6057 | returns 0 unless run when job control is disabled or, when run with | |
ff247e74 CR |
6058 | job control enabled, any specified \fIjobspec\fP was not found |
6059 | or was started without job control. | |
726f6388 | 6060 | .TP |
cce855bc | 6061 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] [\fB\-lpsvPSV\fP] |
7117c2d2 | 6062 | .PD 0 |
cce855bc JA |
6063 | .TP |
6064 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] [\fB\-q\fP \fIfunction\fP] [\fB\-u\fP \fIfunction\fP] [\fB\-r\fP \fIkeyseq\fP] | |
726f6388 | 6065 | .TP |
ccc6cda3 | 6066 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fB\-f\fP \fIfilename\fP |
726f6388 | 6067 | .TP |
bb70624e JA |
6068 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fB\-x\fP \fIkeyseq\fP:\fIshell\-command\fP |
6069 | .TP | |
ccc6cda3 | 6070 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fIkeyseq\fP:\fIfunction\-name\fP |
7117c2d2 JA |
6071 | .TP |
6072 | \fBbind\fP \fIreadline\-command\fP | |
726f6388 JA |
6073 | .PD |
6074 | Display current | |
6075 | .B readline | |
7117c2d2 | 6076 | key and function bindings, bind a key sequence to a |
726f6388 | 6077 | .B readline |
7117c2d2 JA |
6078 | function or macro, or set a |
6079 | .B readline | |
6080 | variable. | |
6081 | Each non-option argument is a command as it would appear in | |
726f6388 | 6082 | .IR .inputrc , |
7117c2d2 JA |
6083 | but each binding or command must be passed as a separate argument; |
6084 | e.g., '"\eC\-x\eC\-r": re\-read\-init\-file'. | |
6085 | Options, if supplied, have the following meanings: | |
726f6388 JA |
6086 | .RS |
6087 | .PD 0 | |
6088 | .TP | |
6089 | .B \-m \fIkeymap\fP | |
6090 | Use | |
6091 | .I keymap | |
6092 | as the keymap to be affected by the subsequent bindings. | |
6093 | Acceptable | |
6094 | .I keymap | |
6095 | names are | |
ccc6cda3 | 6096 | \fIemacs, emacs\-standard, emacs\-meta, emacs\-ctlx, vi, |
28ef6c31 | 6097 | vi\-move, vi\-command\fP, and |
ccc6cda3 JA |
6098 | .IR vi\-insert . |
6099 | \fIvi\fP is equivalent to \fIvi\-command\fP; \fIemacs\fP is | |
6100 | equivalent to \fIemacs\-standard\fP. | |
726f6388 JA |
6101 | .TP |
6102 | .B \-l | |
ccc6cda3 JA |
6103 | List the names of all \fBreadline\fP functions. |
6104 | .TP | |
6105 | .B \-p | |
6106 | Display \fBreadline\fP function names and bindings in such a way | |
6107 | that they can be re-read. | |
6108 | .TP | |
6109 | .B \-P | |
6110 | List current \fBreadline\fP function names and bindings. | |
726f6388 | 6111 | .TP |
ccc6cda3 JA |
6112 | .B \-s |
6113 | Display \fBreadline\fP key sequences bound to macros and the strings | |
6114 | they output in such a way that they can be re-read. | |
6115 | .TP | |
6116 | .B \-S | |
6117 | Display \fBreadline\fP key sequences bound to macros and the strings | |
6118 | they output. | |
726f6388 | 6119 | .TP |
d3ad40de CR |
6120 | .B \-v |
6121 | Display \fBreadline\fP variable names and values in such a way that they | |
6122 | can be re-read. | |
6123 | .TP | |
6124 | .B \-V | |
6125 | List current \fBreadline\fP variable names and values. | |
6126 | .TP | |
726f6388 | 6127 | .B \-f \fIfilename\fP |
ccc6cda3 | 6128 | Read key bindings from \fIfilename\fP. |
726f6388 JA |
6129 | .TP |
6130 | .B \-q \fIfunction\fP | |
ccc6cda3 JA |
6131 | Query about which keys invoke the named \fIfunction\fP. |
6132 | .TP | |
cce855bc JA |
6133 | .B \-u \fIfunction\fP |
6134 | Unbind all keys bound to the named \fIfunction\fP. | |
6135 | .TP | |
ccc6cda3 JA |
6136 | .B \-r \fIkeyseq\fP |
6137 | Remove any current binding for \fIkeyseq\fP. | |
bb70624e JA |
6138 | .TP |
6139 | .B \-x \fIkeyseq\fP:\fIshell\-command\fP | |
6140 | Cause \fIshell\-command\fP to be executed whenever \fIkeyseq\fP is | |
6141 | entered. | |
726f6388 JA |
6142 | .PD |
6143 | .PP | |
6144 | The return value is 0 unless an unrecognized option is given or an | |
6145 | error occurred. | |
6146 | .RE | |
6147 | .TP | |
6148 | \fBbreak\fP [\fIn\fP] | |
6149 | Exit from within a | |
6150 | .BR for , | |
6151 | .BR while , | |
ccc6cda3 | 6152 | .BR until , |
726f6388 | 6153 | or |
ccc6cda3 | 6154 | .B select |
726f6388 JA |
6155 | loop. If \fIn\fP is specified, break \fIn\fP levels. |
6156 | .I n | |
6157 | must be \(>= 1. If | |
6158 | .I n | |
6159 | is greater than the number of enclosing loops, all enclosing loops | |
6160 | are exited. The return value is 0 unless the shell is not executing | |
6161 | a loop when | |
6162 | .B break | |
6163 | is executed. | |
6164 | .TP | |
6165 | \fBbuiltin\fP \fIshell\-builtin\fP [\fIarguments\fP] | |
6166 | Execute the specified shell builtin, passing it | |
6167 | .IR arguments , | |
6168 | and return its exit status. | |
cce855bc | 6169 | This is useful when defining a |
726f6388 | 6170 | function whose name is the same as a shell builtin, |
cce855bc JA |
6171 | retaining the functionality of the builtin within the function. |
6172 | The \fBcd\fP builtin is commonly redefined this way. | |
6173 | The return status is false if | |
726f6388 JA |
6174 | .I shell\-builtin |
6175 | is not a shell builtin command. | |
6176 | .TP | |
7117c2d2 | 6177 | \fBcd\fP [\fB\-L|-P\fP] [\fIdir\fP] |
726f6388 JA |
6178 | Change the current directory to \fIdir\fP. The variable |
6179 | .SM | |
6180 | .B HOME | |
6181 | is the | |
6182 | default | |
6183 | .IR dir . | |
6184 | The variable | |
6185 | .SM | |
6186 | .B CDPATH | |
ccc6cda3 | 6187 | defines the search path for the directory containing |
726f6388 | 6188 | .IR dir . |
ccc6cda3 JA |
6189 | Alternative directory names in |
6190 | .SM | |
6191 | .B CDPATH | |
6192 | are separated by a colon (:). A null directory name in | |
726f6388 JA |
6193 | .SM |
6194 | .B CDPATH | |
ccc6cda3 | 6195 | is the same as the current directory, i.e., ``\fB.\fP''. If |
726f6388 JA |
6196 | .I dir |
6197 | begins with a slash (/), | |
6198 | then | |
6199 | .SM | |
6200 | .B CDPATH | |
ccc6cda3 JA |
6201 | is not used. The |
6202 | .B \-P | |
6203 | option says to use the physical directory structure instead of | |
6204 | following symbolic links (see also the | |
6205 | .B \-P | |
6206 | option to the | |
6207 | .B set | |
6208 | builtin command); the | |
6209 | .B \-L | |
6210 | option forces symbolic links to be followed. An argument of | |
726f6388 JA |
6211 | .B \- |
6212 | is equivalent to | |
6213 | .SM | |
6214 | .BR $OLDPWD . | |
d3a24ed2 CR |
6215 | If a non-empty directory name from \fBCDPATH\fP is used, or if |
6216 | \fB\-\fP is the first argument, and the directory change is | |
6217 | successful, the absolute pathname of the new working directory is | |
6218 | written to the standard output. | |
726f6388 JA |
6219 | The return value is true if the directory was successfully changed; |
6220 | false otherwise. | |
6221 | .TP | |
d3a24ed2 CR |
6222 | \fBcaller\fP [\fIexpr\fP] |
6223 | Returns the context of any active subroutine call (a shell function or | |
6224 | a script executed with the \fB.\fP or \fBsource\fP builtins. | |
6225 | Without \fIexpr\fP, \fBcaller\fP displays the line number and source | |
6226 | filename of the current subroutine call. | |
6227 | If a non-negative integer is supplied as \fIexpr\fP, \fBcaller\fP | |
6228 | displays the line number, subroutine name, and source file corresponding | |
6229 | to that position in the current execution call stack. This extra | |
6230 | information may be used, for example, to print a stack trace. The | |
6231 | current frame is frame 0. | |
6232 | The return value is 0 unless the shell is not executing a subroutine | |
6233 | call or \fIexpr\fP does not correspond to a valid position in the | |
6234 | call stack. | |
6235 | .TP | |
ccc6cda3 | 6236 | \fBcommand\fP [\fB\-pVv\fP] \fIcommand\fP [\fIarg\fP ...] |
726f6388 JA |
6237 | Run |
6238 | .I command | |
6239 | with | |
6240 | .I args | |
6241 | suppressing the normal shell function lookup. Only builtin | |
6242 | commands or commands found in the | |
6243 | .SM | |
6244 | .B PATH | |
6245 | are executed. If the | |
6246 | .B \-p | |
6247 | option is given, the search for | |
6248 | .I command | |
6249 | is performed using a default value for | |
6250 | .B PATH | |
6251 | that is guaranteed to find all of the standard utilities. | |
6252 | If either the | |
6253 | .B \-V | |
6254 | or | |
6255 | .B \-v | |
6256 | option is supplied, a description of | |
6257 | .I command | |
6258 | is printed. The | |
6259 | .B \-v | |
ccc6cda3 | 6260 | option causes a single word indicating the command or file name |
726f6388 JA |
6261 | used to invoke |
6262 | .I command | |
cce855bc | 6263 | to be displayed; the |
726f6388 JA |
6264 | .B \-V |
6265 | option produces a more verbose description. | |
726f6388 JA |
6266 | If the |
6267 | .B \-V | |
6268 | or | |
6269 | .B \-v | |
6270 | option is supplied, the exit status is 0 if | |
6271 | .I command | |
6272 | was found, and 1 if not. If neither option is supplied and | |
6273 | an error occurred or | |
6274 | .I command | |
6275 | cannot be found, the exit status is 127. Otherwise, the exit status of the | |
6276 | .B command | |
6277 | builtin is the exit status of | |
6278 | .IR command . | |
6279 | .TP | |
bb70624e JA |
6280 | \fBcompgen\fP [\fIoption\fP] [\fIword\fP] |
6281 | Generate possible completion matches for \fIword\fP according to | |
6282 | the \fIoption\fPs, which may be any option accepted by the | |
6283 | .B complete | |
6284 | builtin with the exception of \fB\-p\fP and \fB\-r\fP, and write | |
6285 | the matches to the standard output. | |
6286 | When using the \fB\-F\fP or \fB\-C\fP options, the various shell variables | |
6287 | set by the programmable completion facilities, while available, will not | |
6288 | have useful values. | |
6289 | .sp 1 | |
6290 | The matches will be generated in the same way as if the programmable | |
6291 | completion code had generated them directly from a completion specification | |
6292 | with the same flags. | |
6293 | If \fIword\fP is specified, only those completions matching \fIword\fP | |
6294 | will be displayed. | |
6295 | .sp 1 | |
6296 | The return value is true unless an invalid option is supplied, or no | |
6297 | matches were generated. | |
6298 | .TP | |
d3ad40de | 6299 | \fBcomplete\fP [\fB\-abcdefgjksuv\fP] [\fB\-o\fP \fIcomp-option\fP] [\fB\-A\fP \fIaction\fP] [\fB\-G\fP \fIglobpat\fP] [\fB\-W\fP \fIwordlist\fP] [\fB\-F\fP \fIfunction\fP] [\fB\-C\fP \fIcommand\fP] |
bb70624e | 6300 | .br |
d3ad40de | 6301 | [\fB\-X\fP \fIfilterpat\fP] [\fB\-P\fP \fIprefix\fP] [\fB\-S\fP \fIsuffix\fP] \fIname\fP [\fIname ...\fP] |
7117c2d2 | 6302 | .PD 0 |
bb70624e JA |
6303 | .TP |
6304 | \fBcomplete\fP \fB\-pr\fP [\fIname\fP ...] | |
6305 | .PD | |
6306 | Specify how arguments to each \fIname\fP should be completed. | |
6307 | If the \fB\-p\fP option is supplied, or if no options are supplied, | |
6308 | existing completion specifications are printed in a way that allows | |
6309 | them to be reused as input. | |
6310 | The \fB\-r\fP option removes a completion specification for | |
6311 | each \fIname\fP, or, if no \fIname\fPs are supplied, all | |
6312 | completion specifications. | |
6313 | .sp 1 | |
6314 | The process of applying these completion specifications when word completion | |
6315 | is attempted is described above under \fBProgrammable Completion\fP. | |
6316 | .sp 1 | |
6317 | Other options, if specified, have the following meanings. | |
6318 | The arguments to the \fB\-G\fP, \fB\-W\fP, and \fB\-X\fP options | |
6319 | (and, if necessary, the \fB\-P\fP and \fB\-S\fP options) | |
6320 | should be quoted to protect them from expansion before the | |
6321 | .B complete | |
6322 | builtin is invoked. | |
6323 | .RS | |
6324 | .PD 0 | |
6325 | .TP 8 | |
28ef6c31 JA |
6326 | \fB\-o\fP \fIcomp-option\fP |
6327 | The \fIcomp-option\fP controls several aspects of the compspec's behavior | |
6328 | beyond the simple generation of completions. | |
6329 | \fIcomp-option\fP may be one of: | |
6330 | .RS | |
6331 | .TP 8 | |
d3a24ed2 CR |
6332 | .B bashdefault |
6333 | Perform the rest of the default \fBbash\fP completions if the compspec | |
6334 | generates no matches. | |
6335 | .TP 8 | |
28ef6c31 | 6336 | .B default |
7117c2d2 JA |
6337 | Use readline's default filename completion if the compspec generates |
6338 | no matches. | |
28ef6c31 JA |
6339 | .TP 8 |
6340 | .B dirnames | |
6341 | Perform directory name completion if the compspec generates no matches. | |
6342 | .TP 8 | |
6343 | .B filenames | |
6344 | Tell readline that the compspec generates filenames, so it can perform any | |
6345 | filename\-specific processing (like adding a slash to directory names or | |
6346 | suppressing trailing spaces). Intended to be used with shell functions. | |
7117c2d2 JA |
6347 | .TP 8 |
6348 | .B nospace | |
6349 | Tell readline not to append a space (the default) to words completed at | |
6350 | the end of the line. | |
301e2142 CR |
6351 | .TP 8 |
6352 | .B plusdirs | |
6353 | After any matches defined by the compspec are generated, | |
6354 | directory name completion is attempted and any | |
6355 | matches are added to the results of the other actions. | |
28ef6c31 JA |
6356 | .RE |
6357 | .TP 8 | |
bb70624e JA |
6358 | \fB\-A\fP \fIaction\fP |
6359 | The \fIaction\fP may be one of the following to generate a list of possible | |
6360 | completions: | |
6361 | .RS | |
6362 | .TP 8 | |
6363 | .B alias | |
6364 | Alias names. May also be specified as \fB\-a\fP. | |
6365 | .TP 8 | |
6366 | .B arrayvar | |
6367 | Array variable names. | |
6368 | .TP 8 | |
6369 | .B binding | |
6370 | \fBReadline\fP key binding names. | |
6371 | .TP 8 | |
6372 | .B builtin | |
6373 | Names of shell builtin commands. May also be specified as \fB\-b\fP. | |
6374 | .TP 8 | |
6375 | .B command | |
6376 | Command names. May also be specified as \fB\-c\fP. | |
6377 | .TP 8 | |
6378 | .B directory | |
6379 | Directory names. May also be specified as \fB\-d\fP. | |
6380 | .TP 8 | |
6381 | .B disabled | |
6382 | Names of disabled shell builtins. | |
6383 | .TP 8 | |
6384 | .B enabled | |
6385 | Names of enabled shell builtins. | |
6386 | .TP 8 | |
6387 | .B export | |
6388 | Names of exported shell variables. May also be specified as \fB\-e\fP. | |
6389 | .TP 8 | |
6390 | .B file | |
6391 | File names. May also be specified as \fB\-f\fP. | |
6392 | .TP 8 | |
6393 | .B function | |
6394 | Names of shell functions. | |
6395 | .TP 8 | |
f73dda09 JA |
6396 | .B group |
6397 | Group names. May also be specified as \fB\-g\fP. | |
6398 | .TP 8 | |
bb70624e JA |
6399 | .B helptopic |
6400 | Help topics as accepted by the \fBhelp\fP builtin. | |
6401 | .TP 8 | |
6402 | .B hostname | |
6403 | Hostnames, as taken from the file specified by the | |
6404 | .SM | |
6405 | .B HOSTFILE | |
6406 | shell variable. | |
6407 | .TP 8 | |
6408 | .B job | |
6409 | Job names, if job control is active. May also be specified as \fB\-j\fP. | |
6410 | .TP 8 | |
6411 | .B keyword | |
6412 | Shell reserved words. May also be specified as \fB\-k\fP. | |
6413 | .TP 8 | |
6414 | .B running | |
6415 | Names of running jobs, if job control is active. | |
6416 | .TP 8 | |
7117c2d2 JA |
6417 | .B service |
6418 | Service names. May also be specified as \fB\-s\fP. | |
6419 | .TP 8 | |
bb70624e JA |
6420 | .B setopt |
6421 | Valid arguments for the \fB\-o\fP option to the \fBset\fP builtin. | |
6422 | .TP 8 | |
6423 | .B shopt | |
6424 | Shell option names as accepted by the \fBshopt\fP builtin. | |
6425 | .TP 8 | |
6426 | .B signal | |
6427 | Signal names. | |
6428 | .TP 8 | |
6429 | .B stopped | |
6430 | Names of stopped jobs, if job control is active. | |
6431 | .TP 8 | |
6432 | .B user | |
6433 | User names. May also be specified as \fB\-u\fP. | |
6434 | .TP 8 | |
6435 | .B variable | |
6436 | Names of all shell variables. May also be specified as \fB\-v\fP. | |
6437 | .RE | |
6438 | .TP 8 | |
6439 | \fB\-G\fP \fIglobpat\fP | |
6440 | The filename expansion pattern \fIglobpat\fP is expanded to generate | |
6441 | the possible completions. | |
6442 | .TP 8 | |
6443 | \fB\-W\fP \fIwordlist\fP | |
6444 | The \fIwordlist\fP is split using the characters in the | |
6445 | .SM | |
6446 | .B IFS | |
6447 | special variable as delimiters, and each resultant word is expanded. | |
6448 | The possible completions are the members of the resultant list which | |
6449 | match the word being completed. | |
6450 | .TP 8 | |
6451 | \fB\-C\fP \fIcommand\fP | |
6452 | \fIcommand\fP is executed in a subshell environment, and its output is | |
6453 | used as the possible completions. | |
6454 | .TP 8 | |
6455 | \fB\-F\fP \fIfunction\fP | |
6456 | The shell function \fIfunction\fP is executed in the current shell | |
6457 | environment. | |
6458 | When it finishes, the possible completions are retrieved from the value | |
6459 | of the | |
6460 | .SM | |
6461 | .B COMPREPLY | |
6462 | array variable. | |
6463 | .TP 8 | |
6464 | \fB\-X\fP \fIfilterpat\fP | |
6465 | \fIfilterpat\fP is a pattern as used for filename expansion. | |
6466 | It is applied to the list of possible completions generated by the | |
6467 | preceding options and arguments, and each completion matching | |
6468 | \fIfilterpat\fP is removed from the list. | |
6469 | A leading \fB!\fP in \fIfilterpat\fP negates the pattern; in this | |
6470 | case, any completion not matching \fIfilterpat\fP is removed. | |
6471 | .TP 8 | |
6472 | \fB\-P\fP \fIprefix\fP | |
6473 | \fIprefix\fP is added at the beginning of each possible completion | |
6474 | after all other options have been applied. | |
6475 | .TP 8 | |
6476 | \fB\-S\fP \fIsuffix\fP | |
6477 | \fIsuffix\fP is appended to each possible completion | |
6478 | after all other options have been applied. | |
6479 | .PD | |
6480 | .PP | |
6481 | The return value is true unless an invalid option is supplied, an option | |
6482 | other than \fB\-p\fP or \fB\-r\fP is supplied without a \fIname\fP | |
6483 | argument, an attempt is made to remove a completion specification for | |
6484 | a \fIname\fP for which no specification exists, or | |
6485 | an error occurs adding a completion specification. | |
6486 | .RE | |
6487 | .TP | |
726f6388 JA |
6488 | \fBcontinue\fP [\fIn\fP] |
6489 | Resume the next iteration of the enclosing | |
6490 | .BR for , | |
6491 | .BR while , | |
ccc6cda3 | 6492 | .BR until , |
726f6388 | 6493 | or |
ccc6cda3 | 6494 | .B select |
726f6388 JA |
6495 | loop. |
6496 | If | |
6497 | .I n | |
6498 | is specified, resume at the \fIn\fPth enclosing loop. | |
6499 | .I n | |
6500 | must be \(>= 1. If | |
6501 | .I n | |
6502 | is greater than the number of enclosing loops, the last enclosing loop | |
ccc6cda3 | 6503 | (the ``top-level'' loop) is resumed. The return value is 0 unless the |
726f6388 JA |
6504 | shell is not executing a loop when |
6505 | .B continue | |
6506 | is executed. | |
6507 | .TP | |
d3a24ed2 | 6508 | \fBdeclare\fP [\fB\-afFirtx\fP] [\fB\-p\fP] [\fIname\fP[=\fIvalue\fP] ...] |
726f6388 | 6509 | .PD 0 |
726f6388 | 6510 | .TP |
d3a24ed2 | 6511 | \fBtypeset\fP [\fB\-afFirtx\fP] [\fB\-p\fP] [\fIname\fP[=\fIvalue\fP] ...] |
726f6388 | 6512 | .PD |
ccc6cda3 JA |
6513 | Declare variables and/or give them attributes. |
6514 | If no \fIname\fPs are given then display the values of variables. | |
6515 | The | |
6516 | .B \-p | |
6517 | option will display the attributes and values of each | |
6518 | .IR name . | |
6519 | When | |
6520 | .B \-p | |
6521 | is used, additional options are ignored. | |
6522 | The | |
6523 | .B \-F | |
6524 | option inhibits the display of function definitions; only the | |
6525 | function name and attributes are printed. | |
d3a24ed2 CR |
6526 | If the \fBextdebug\fP shell option is enabled using \fBshopt\fP, |
6527 | the source file name and line number where the function is defined | |
6528 | are displayed as well. The | |
ccc6cda3 JA |
6529 | .B \-F |
6530 | option implies | |
6531 | .BR \-f . | |
6532 | The following options can | |
6533 | be used to restrict output to variables with the specified attribute or | |
6534 | to give variables attributes: | |
726f6388 JA |
6535 | .RS |
6536 | .PD 0 | |
6537 | .TP | |
ccc6cda3 JA |
6538 | .B \-a |
6539 | Each \fIname\fP is an array variable (see | |
6540 | .B Arrays | |
6541 | above). | |
6542 | .TP | |
726f6388 | 6543 | .B \-f |
ccc6cda3 JA |
6544 | Use function names only. |
6545 | .TP | |
6546 | .B \-i | |
6547 | The variable is treated as an integer; arithmetic evaluation (see | |
6548 | .SM | |
6549 | .B "ARITHMETIC EVALUATION" ") " | |
6550 | is performed when the variable is assigned a value. | |
726f6388 JA |
6551 | .TP |
6552 | .B \-r | |
6553 | Make \fIname\fPs readonly. These names cannot then be assigned values | |
cce855bc | 6554 | by subsequent assignment statements or unset. |
726f6388 | 6555 | .TP |
7117c2d2 JA |
6556 | .B \-t |
6557 | Give each \fIname\fP the \fItrace\fP attribute. | |
76a8d78d CR |
6558 | Traced functions inherit the \fBDEBUG\fP and \fBRETURN\fP traps from |
6559 | the calling shell. | |
7117c2d2 JA |
6560 | The trace attribute has no special meaning for variables. |
6561 | .TP | |
726f6388 JA |
6562 | .B \-x |
6563 | Mark \fIname\fPs for export to subsequent commands via the environment. | |
726f6388 JA |
6564 | .PD |
6565 | .PP | |
6566 | Using `+' instead of `\-' | |
d3ad40de CR |
6567 | turns off the attribute instead, |
6568 | with the exceptions that \fB+a\fP | |
6569 | may not be used to destroy an array variable and \fB+r\fB will not | |
6570 | remove the readonly attribute. | |
6571 | When used in a function, | |
ccc6cda3 JA |
6572 | makes each |
6573 | \fIname\fP local, as with the | |
726f6388 | 6574 | .B local |
d3a24ed2 CR |
6575 | command. |
6576 | If a variable name is followed by =\fIvalue\fP, the value of | |
6577 | the variable is set to \fIvalue\fP. | |
6578 | The return value is 0 unless an invalid option is encountered, | |
bb70624e JA |
6579 | an attempt is made to define a function using |
6580 | .if n ``\-f foo=bar'', | |
6581 | .if t \f(CW\-f foo=bar\fP, | |
ccc6cda3 JA |
6582 | an attempt is made to assign a value to a readonly variable, |
6583 | an attempt is made to assign a value to an array variable without | |
6584 | using the compound assignment syntax (see | |
6585 | .B Arrays | |
cce855bc | 6586 | above), one of the \fInames\fP is not a valid shell variable name, |
726f6388 | 6587 | an attempt is made to turn off readonly status for a readonly variable, |
ccc6cda3 | 6588 | an attempt is made to turn off array status for an array variable, |
bb70624e | 6589 | or an attempt is made to display a non-existent function with \fB\-f\fP. |
726f6388 JA |
6590 | .RE |
6591 | .TP | |
d3ad40de | 6592 | .B dirs [+\fIn\fP] [\-\fIn\fP] [\fB\-cplv\fP] |
ccc6cda3 JA |
6593 | Without options, displays the list of currently remembered directories. |
6594 | The default display is on a single line with directory names separated | |
6595 | by spaces. | |
6596 | Directories are added to the list with the | |
726f6388 JA |
6597 | .B pushd |
6598 | command; the | |
6599 | .B popd | |
ccc6cda3 | 6600 | command removes entries from the list. |
726f6388 JA |
6601 | .RS |
6602 | .PD 0 | |
6603 | .TP | |
ccc6cda3 JA |
6604 | \fB+\fP\fIn\fP |
6605 | Displays the \fIn\fPth entry counting from the left of the list | |
726f6388 JA |
6606 | shown by |
6607 | .B dirs | |
6608 | when invoked without options, starting with zero. | |
6609 | .TP | |
ccc6cda3 JA |
6610 | \fB\-\fP\fIn\fP |
6611 | Displays the \fIn\fPth entry counting from the right of the list | |
726f6388 JA |
6612 | shown by |
6613 | .B dirs | |
6614 | when invoked without options, starting with zero. | |
6615 | .TP | |
ccc6cda3 JA |
6616 | .B \-c |
6617 | Clears the directory stack by deleting all of the entries. | |
6618 | .TP | |
726f6388 | 6619 | .B \-l |
ccc6cda3 | 6620 | Produces a longer listing; the default listing format uses a |
726f6388 | 6621 | tilde to denote the home directory. |
ccc6cda3 JA |
6622 | .TP |
6623 | .B \-p | |
6624 | Print the directory stack with one entry per line. | |
6625 | .TP | |
6626 | .B \-v | |
6627 | Print the directory stack with one entry per line, | |
6628 | prefixing each entry with its index in the stack. | |
726f6388 JA |
6629 | .PD |
6630 | .PP | |
6631 | The return value is 0 unless an | |
cce855bc | 6632 | invalid option is supplied or \fIn\fP indexes beyond the end |
726f6388 JA |
6633 | of the directory stack. |
6634 | .RE | |
6635 | .TP | |
cce855bc | 6636 | \fBdisown\fP [\fB\-ar\fP] [\fB\-h\fP] [\fIjobspec\fP ...] |
ccc6cda3 JA |
6637 | Without options, each |
6638 | .I jobspec | |
6639 | is removed from the table of active jobs. | |
d3ad40de CR |
6640 | If |
6641 | .I jobspec | |
6642 | is not present, and neither \fB\-a\fB nor \fB\-r\fP is supplied, | |
6643 | the shell's notion of the \fIcurrent job\fP is used. | |
cce855bc JA |
6644 | If the \fB\-h\fP option is given, each |
6645 | .I jobspec | |
6646 | is not removed from the table, but is marked so that | |
ccc6cda3 JA |
6647 | .SM |
6648 | .B SIGHUP | |
6649 | is not sent to the job if the shell receives a | |
6650 | .SM | |
6651 | .BR SIGHUP . | |
6652 | If no | |
6653 | .I jobspec | |
cce855bc JA |
6654 | is present, and neither the |
6655 | .B \-a | |
6656 | nor the | |
6657 | .B \-r | |
6658 | option is supplied, the \fIcurrent job\fP is used. | |
6659 | If no | |
6660 | .I jobspec | |
6661 | is supplied, the | |
6662 | .B \-a | |
6663 | option means to remove or mark all jobs; the | |
6664 | .B \-r | |
6665 | option without a | |
6666 | .I jobspec | |
6667 | argument restricts operation to running jobs. | |
6668 | The return value is 0 unless a | |
ccc6cda3 JA |
6669 | .I jobspec |
6670 | does not specify a valid job. | |
6671 | .TP | |
726f6388 | 6672 | \fBecho\fP [\fB\-neE\fP] [\fIarg\fP ...] |
ccc6cda3 JA |
6673 | Output the \fIarg\fPs, separated by spaces, followed by a newline. |
6674 | The return status is always 0. | |
6675 | If \fB\-n\fP is specified, the trailing newline is | |
726f6388 JA |
6676 | suppressed. If the \fB\-e\fP option is given, interpretation of |
6677 | the following backslash-escaped characters is enabled. The | |
6678 | .B \-E | |
6679 | option disables the interpretation of these escape characters, | |
6680 | even on systems where they are interpreted by default. | |
28ef6c31 | 6681 | The \fBxpg_echo\fP shell option may be used to |
bb70624e JA |
6682 | dynamically determine whether or not \fBecho\fP expands these |
6683 | escape characters by default. | |
ccc6cda3 | 6684 | .B echo |
3ffb039a | 6685 | does not interpret \fB\-\-\fP to mean the end of options. |
ccc6cda3 JA |
6686 | .B echo |
6687 | interprets the following escape sequences: | |
726f6388 JA |
6688 | .RS |
6689 | .PD 0 | |
6690 | .TP | |
6691 | .B \ea | |
6692 | alert (bell) | |
6693 | .TP | |
6694 | .B \eb | |
6695 | backspace | |
6696 | .TP | |
6697 | .B \ec | |
6698 | suppress trailing newline | |
6699 | .TP | |
ccc6cda3 JA |
6700 | .B \ee |
6701 | an escape character | |
6702 | .TP | |
726f6388 JA |
6703 | .B \ef |
6704 | form feed | |
6705 | .TP | |
6706 | .B \en | |
6707 | new line | |
6708 | .TP | |
6709 | .B \er | |
6710 | carriage return | |
6711 | .TP | |
6712 | .B \et | |
6713 | horizontal tab | |
6714 | .TP | |
6715 | .B \ev | |
6716 | vertical tab | |
6717 | .TP | |
6718 | .B \e\e | |
6719 | backslash | |
6720 | .TP | |
7117c2d2 JA |
6721 | .B \e0\fInnn\fP |
6722 | the eight-bit character whose value is the octal value \fInnn\fP | |
6723 | (zero to three octal digits) | |
6724 | .TP | |
f73dda09 JA |
6725 | .B \ex\fIHH\fP |
6726 | the eight-bit character whose value is the hexadecimal value \fIHH\fP | |
6727 | (one or two hex digits) | |
726f6388 JA |
6728 | .PD |
6729 | .RE | |
6730 | .TP | |
d3ad40de | 6731 | \fBenable\fP [\fB\-a\fP] [\fB\-dnps\fP] [\fB\-f\fP \fIfilename\fP] [\fIname\fP ...] |
cce855bc JA |
6732 | Enable and disable builtin shell commands. |
6733 | Disabling a builtin allows a disk command which has the same name | |
bb70624e | 6734 | as a shell builtin to be executed without specifying a full pathname, |
cce855bc | 6735 | even though the shell normally searches for builtins before disk commands. |
726f6388 JA |
6736 | If \fB\-n\fP is used, each \fIname\fP |
6737 | is disabled; otherwise, | |
6738 | \fInames\fP are enabled. For example, to use the | |
6739 | .B test | |
6740 | binary found via the | |
6741 | .SM | |
6742 | .B PATH | |
ccc6cda3 | 6743 | instead of the shell builtin version, run |
28ef6c31 JA |
6744 | .if t \f(CWenable -n test\fP. |
6745 | .if n ``enable -n test''. | |
ccc6cda3 JA |
6746 | The |
6747 | .B \-f | |
6748 | option means to load the new builtin command | |
6749 | .I name | |
6750 | from shared object | |
6751 | .IR filename , | |
6752 | on systems that support dynamic loading. The | |
6753 | .B \-d | |
6754 | option will delete a builtin previously loaded with | |
6755 | .BR \-f . | |
6756 | If no \fIname\fP arguments are given, or if the | |
6757 | .B \-p | |
6758 | option is supplied, a list of shell builtins is printed. | |
6759 | With no other option arguments, the list consists of all enabled | |
6760 | shell builtins. | |
6761 | If \fB\-n\fP is supplied, only disabled builtins are printed. | |
6762 | If \fB\-a\fP is supplied, the list printed includes all builtins, with an | |
726f6388 | 6763 | indication of whether or not each is enabled. |
ccc6cda3 JA |
6764 | If \fB\-s\fP is supplied, the output is restricted to the POSIX |
6765 | \fIspecial\fP builtins. | |
726f6388 JA |
6766 | The return value is 0 unless a |
6767 | .I name | |
bb70624e | 6768 | is not a shell builtin or there is an error loading a new builtin |
ccc6cda3 | 6769 | from a shared object. |
726f6388 JA |
6770 | .TP |
6771 | \fBeval\fP [\fIarg\fP ...] | |
6772 | The \fIarg\fPs are read and concatenated together into a single | |
6773 | command. This command is then read and executed by the shell, and | |
ccc6cda3 JA |
6774 | its exit status is returned as the value of |
6775 | .BR eval . | |
6776 | If there are no | |
726f6388 JA |
6777 | .IR args , |
6778 | or only null arguments, | |
6779 | .B eval | |
ccc6cda3 | 6780 | returns 0. |
726f6388 | 6781 | .TP |
cce855bc | 6782 | \fBexec\fP [\fB\-cl\fP] [\fB\-a\fP \fIname\fP] [\fIcommand\fP [\fIarguments\fP]] |
726f6388 JA |
6783 | If |
6784 | .I command | |
6785 | is specified, it replaces the shell. | |
6786 | No new process is created. The | |
6787 | .I arguments | |
6788 | become the arguments to \fIcommand\fP. | |
ccc6cda3 JA |
6789 | If the |
6790 | .B \-l | |
6791 | option is supplied, | |
d3ad40de | 6792 | the shell places a dash at the beginning of the zeroth argument passed to |
726f6388 | 6793 | .IR command . |
ccc6cda3 JA |
6794 | This is what |
6795 | .IR login (1) | |
6796 | does. The | |
6797 | .B \-c | |
6798 | option causes | |
6799 | .I command | |
6800 | to be executed with an empty environment. If | |
6801 | .B \-a | |
6802 | is supplied, the shell passes | |
6803 | .I name | |
6804 | as the zeroth argument to the executed command. If | |
6805 | .I command | |
726f6388 | 6806 | cannot be executed for some reason, a non-interactive shell exits, |
ccc6cda3 JA |
6807 | unless the shell option |
6808 | .B execfail | |
6809 | is enabled, in which case it returns failure. | |
6810 | An interactive shell returns failure if the file cannot be executed. | |
726f6388 JA |
6811 | If |
6812 | .I command | |
6813 | is not specified, any redirections take effect in the current shell, | |
cce855bc JA |
6814 | and the return status is 0. If there is a redirection error, the |
6815 | return status is 1. | |
726f6388 JA |
6816 | .TP |
6817 | \fBexit\fP [\fIn\fP] | |
6818 | Cause the shell to exit | |
6819 | with a status of \fIn\fP. If | |
6820 | .I n | |
6821 | is omitted, the exit status | |
6822 | is that of the last command executed. | |
6823 | A trap on | |
6824 | .SM | |
6825 | .B EXIT | |
6826 | is executed before the shell terminates. | |
6827 | .TP | |
ccc6cda3 | 6828 | \fBexport\fP [\fB\-fn\fP\^] [\fIname\fP[=\fIword\fP]] ... |
7117c2d2 | 6829 | .PD 0 |
726f6388 JA |
6830 | .TP |
6831 | .B export \-p | |
6832 | .PD | |
6833 | The supplied | |
6834 | .I names | |
6835 | are marked for automatic export to the environment of | |
6836 | subsequently executed commands. If the | |
6837 | .B \-f | |
6838 | option is given, | |
6839 | the | |
6840 | .I names | |
6841 | refer to functions. | |
6842 | If no | |
6843 | .I names | |
6844 | are given, or if the | |
6845 | .B \-p | |
6846 | option is supplied, a list | |
6847 | of all names that are exported in this shell is printed. | |
6848 | The | |
6849 | .B \-n | |
5e13499c CR |
6850 | option causes the export property to be removed from each |
6851 | \fIname\fP. | |
d3a24ed2 CR |
6852 | If a variable name is followed by =\fIword\fP, the value of |
6853 | the variable is set to \fIword\fP. | |
726f6388 | 6854 | .B export |
cce855bc | 6855 | returns an exit status of 0 unless an invalid option is |
726f6388 | 6856 | encountered, |
cce855bc | 6857 | one of the \fInames\fP is not a valid shell variable name, or |
726f6388 JA |
6858 | .B \-f |
6859 | is supplied with a | |
6860 | .I name | |
6861 | that is not a function. | |
6862 | .TP | |
d3ad40de | 6863 | \fBfc\fP [\fB\-e\fP \fIename\fP] [\fB\-lnr\fP] [\fIfirst\fP] [\fIlast\fP] |
7117c2d2 | 6864 | .PD 0 |
726f6388 JA |
6865 | .TP |
6866 | \fBfc\fP \fB\-s\fP [\fIpat\fP=\fIrep\fP] [\fIcmd\fP] | |
6867 | .PD | |
6868 | Fix Command. In the first form, a range of commands from | |
6869 | .I first | |
6870 | to | |
6871 | .I last | |
6872 | is selected from the history list. | |
6873 | .I First | |
6874 | and | |
6875 | .I last | |
6876 | may be specified as a string (to locate the last command beginning | |
6877 | with that string) or as a number (an index into the history list, | |
6878 | where a negative number is used as an offset from the current | |
6879 | command number). If | |
6880 | .I last | |
6881 | is not specified it is set to | |
6882 | the current command for listing (so that | |
bb70624e JA |
6883 | .if n ``fc \-l \-10'' |
6884 | .if t \f(CWfc \-l \-10\fP | |
726f6388 JA |
6885 | prints the last 10 commands) and to |
6886 | .I first | |
6887 | otherwise. | |
6888 | If | |
6889 | .I first | |
6890 | is not specified it is set to the previous | |
6891 | command for editing and \-16 for listing. | |
6892 | .sp 1 | |
6893 | The | |
6894 | .B \-n | |
cce855bc | 6895 | option suppresses |
726f6388 JA |
6896 | the command numbers when listing. The |
6897 | .B \-r | |
cce855bc | 6898 | option reverses the order of |
726f6388 JA |
6899 | the commands. If the |
6900 | .B \-l | |
cce855bc | 6901 | option is given, |
726f6388 JA |
6902 | the commands are listed on |
6903 | standard output. Otherwise, the editor given by | |
6904 | .I ename | |
6905 | is invoked | |
6906 | on a file containing those commands. If | |
6907 | .I ename | |
6908 | is not given, the | |
6909 | value of the | |
6910 | .SM | |
6911 | .B FCEDIT | |
6912 | variable is used, and | |
6913 | the value of | |
6914 | .SM | |
6915 | .B EDITOR | |
6916 | if | |
6917 | .SM | |
6918 | .B FCEDIT | |
6919 | is not set. If neither variable is set, | |
6920 | .FN vi | |
6921 | is used. When editing is complete, the edited commands are | |
6922 | echoed and executed. | |
6923 | .sp 1 | |
6924 | In the second form, \fIcommand\fP is re-executed after each instance | |
6925 | of \fIpat\fP is replaced by \fIrep\fP. | |
ccc6cda3 | 6926 | A useful alias to use with this is |
d3a24ed2 | 6927 | .if n ``r="fc -s"'', |
ccc6cda3 JA |
6928 | .if t \f(CWr='fc \-s'\fP, |
6929 | so that typing | |
6930 | .if n ``r cc'' | |
6931 | .if t \f(CWr cc\fP | |
6932 | runs the last command beginning with | |
6933 | .if n ``cc'' | |
6934 | .if t \f(CWcc\fP | |
6935 | and typing | |
6936 | .if n ``r'' | |
6937 | .if t \f(CWr\fP | |
726f6388 JA |
6938 | re-executes the last command. |
6939 | .sp 1 | |
cce855bc | 6940 | If the first form is used, the return value is 0 unless an invalid |
726f6388 JA |
6941 | option is encountered or |
6942 | .I first | |
6943 | or | |
6944 | .I last | |
6945 | specify history lines out of range. | |
6946 | If the | |
6947 | .B \-e | |
6948 | option is supplied, the return value is the value of the last | |
6949 | command executed or failure if an error occurs with the temporary | |
6950 | file of commands. If the second form is used, the return status | |
6951 | is that of the command re-executed, unless | |
6952 | .I cmd | |
6953 | does not specify a valid history line, in which case | |
6954 | .B fc | |
6955 | returns failure. | |
6956 | .TP | |
6957 | \fBfg\fP [\fIjobspec\fP] | |
cce855bc | 6958 | Resume |
726f6388 | 6959 | .I jobspec |
cce855bc JA |
6960 | in the foreground, and make it the current job. |
6961 | If | |
726f6388 JA |
6962 | .I jobspec |
6963 | is not present, the shell's notion of the \fIcurrent job\fP is used. | |
6964 | The return value is that of the command placed into the foreground, | |
6965 | or failure if run when job control is disabled or, when run with | |
6966 | job control enabled, if | |
6967 | .I jobspec | |
6968 | does not specify a valid job or | |
6969 | .I jobspec | |
6970 | specifies a job that was started without job control. | |
6971 | .TP | |
6972 | \fBgetopts\fP \fIoptstring\fP \fIname\fP [\fIargs\fP] | |
6973 | .B getopts | |
6974 | is used by shell procedures to parse positional parameters. | |
6975 | .I optstring | |
bb70624e | 6976 | contains the option characters to be recognized; if a character |
726f6388 JA |
6977 | is followed by a colon, the option is expected to have an |
6978 | argument, which should be separated from it by white space. | |
bb70624e JA |
6979 | The colon and question mark characters may not be used as |
6980 | option characters. | |
726f6388 JA |
6981 | Each time it is invoked, |
6982 | .B getopts | |
6983 | places the next option in the shell variable | |
6984 | .IR name , | |
6985 | initializing | |
6986 | .I name | |
6987 | if it does not exist, | |
6988 | and the index of the next argument to be processed into the | |
6989 | variable | |
6990 | .SM | |
6991 | .BR OPTIND . | |
6992 | .SM | |
6993 | .B OPTIND | |
6994 | is initialized to 1 each time the shell or a shell script | |
6995 | is invoked. When an option requires an argument, | |
6996 | .B getopts | |
6997 | places that argument into the variable | |
6998 | .SM | |
6999 | .BR OPTARG . | |
7000 | The shell does not reset | |
7001 | .SM | |
7002 | .B OPTIND | |
7003 | automatically; it must be manually reset between multiple | |
7004 | calls to | |
7005 | .B getopts | |
7006 | within the same shell invocation if a new set of parameters | |
7007 | is to be used. | |
7008 | .sp 1 | |
cce855bc JA |
7009 | When the end of options is encountered, \fBgetopts\fP exits with a |
7010 | return value greater than zero. | |
7011 | \fBOPTIND\fP is set to the index of the first non-option argument, | |
7012 | and \fBname\fP is set to ?. | |
7013 | .sp 1 | |
7014 | .B getopts | |
7015 | normally parses the positional parameters, but if more arguments are | |
7016 | given in | |
7017 | .IR args , | |
7018 | .B getopts | |
7019 | parses those instead. | |
7020 | .sp 1 | |
726f6388 JA |
7021 | .B getopts |
7022 | can report errors in two ways. If the first character of | |
7023 | .I optstring | |
7024 | is a colon, | |
7025 | .I silent | |
7026 | error reporting is used. In normal operation diagnostic messages | |
cce855bc | 7027 | are printed when invalid options or missing option arguments are |
726f6388 JA |
7028 | encountered. |
7029 | If the variable | |
7030 | .SM | |
7031 | .B OPTERR | |
cce855bc | 7032 | is set to 0, no error messages will be displayed, even if the first |
726f6388 JA |
7033 | character of |
7034 | .I optstring | |
7035 | is not a colon. | |
7036 | .sp 1 | |
cce855bc | 7037 | If an invalid option is seen, |
726f6388 JA |
7038 | .B getopts |
7039 | places ? into | |
7040 | .I name | |
7041 | and, if not silent, | |
7042 | prints an error message and unsets | |
7043 | .SM | |
7044 | .BR OPTARG . | |
7045 | If | |
7046 | .B getopts | |
7047 | is silent, | |
7048 | the option character found is placed in | |
7049 | .SM | |
7050 | .B OPTARG | |
7051 | and no diagnostic message is printed. | |
7052 | .sp 1 | |
7053 | If a required argument is not found, and | |
7054 | .B getopts | |
7055 | is not silent, | |
7056 | a question mark (\^\fB?\fP\^) is placed in | |
7057 | .IR name , | |
f73dda09 | 7058 | .SM |
726f6388 JA |
7059 | .B OPTARG |
7060 | is unset, and a diagnostic message is printed. | |
7061 | If | |
7062 | .B getopts | |
7063 | is silent, then a colon (\^\fB:\fP\^) is placed in | |
7064 | .I name | |
7065 | and | |
7066 | .SM | |
7067 | .B OPTARG | |
7068 | is set to the option character found. | |
7069 | .sp 1 | |
7070 | .B getopts | |
726f6388 JA |
7071 | returns true if an option, specified or unspecified, is found. |
7072 | It returns false if the end of options is encountered or an | |
7073 | error occurs. | |
7074 | .TP | |
7117c2d2 | 7075 | \fBhash\fP [\fB\-lr\fP] [\fB\-p\fP \fIfilename\fP] [\fB\-dt\fP] [\fIname\fP] |
726f6388 JA |
7076 | For each |
7077 | .IR name , | |
ccc6cda3 JA |
7078 | the full file name of the command is determined by searching |
7079 | the directories in | |
7080 | .B $PATH | |
7081 | and remembered. | |
7082 | If the | |
7083 | .B \-p | |
7084 | option is supplied, no path search is performed, and | |
7085 | .I filename | |
7086 | is used as the full file name of the command. | |
7087 | The | |
726f6388 JA |
7088 | .B \-r |
7089 | option causes the shell to forget all | |
f73dda09 | 7090 | remembered locations. |
7117c2d2 JA |
7091 | The |
7092 | .B \-d | |
7093 | option causes the shell to forget the remembered location of each \fIname\fP. | |
f73dda09 JA |
7094 | If the |
7095 | .B \-t | |
7096 | option is supplied, the full pathname to which each \fIname\fP corresponds | |
7097 | is printed. If multiple \fIname\fP arguments are supplied with \fB\-t\fP, | |
7098 | the \fIname\fP is printed before the hashed full pathname. | |
7117c2d2 JA |
7099 | The |
7100 | .B \-l | |
7101 | option causes output to be displayed in a format that may be reused as input. | |
7102 | If no arguments are given, or if only \fB\-l\fP is supplied, | |
7103 | information about remembered commands is printed. | |
ccc6cda3 | 7104 | The return status is true unless a |
726f6388 | 7105 | .I name |
cce855bc | 7106 | is not found or an invalid option is supplied. |
726f6388 | 7107 | .TP |
bb70624e | 7108 | \fBhelp\fP [\fB\-s\fP] [\fIpattern\fP] |
726f6388 JA |
7109 | Display helpful information about builtin commands. If |
7110 | .I pattern | |
7111 | is specified, | |
7112 | .B help | |
7113 | gives detailed help on all commands matching | |
7114 | .IR pattern ; | |
ccc6cda3 | 7115 | otherwise help for all the builtins and shell control structures |
bb70624e JA |
7116 | is printed. |
7117 | The \fB\-s\fP option restricts the information displayed to a short | |
7118 | usage synopsis. | |
7119 | The return status is 0 unless no command matches | |
726f6388 JA |
7120 | .IR pattern . |
7121 | .TP | |
bb70624e | 7122 | \fBhistory [\fIn\fP] |
7117c2d2 | 7123 | .PD 0 |
bb70624e JA |
7124 | .TP |
7125 | \fBhistory\fP \fB\-c\fP | |
7126 | .TP | |
7127 | \fBhistory \-d\fP \fIoffset\fP | |
ccc6cda3 JA |
7128 | .TP |
7129 | \fBhistory\fP \fB\-anrw\fP [\fIfilename\fP] | |
726f6388 | 7130 | .TP |
ccc6cda3 JA |
7131 | \fBhistory\fP \fB\-p\fP \fIarg\fP [\fIarg ...\fP] |
7132 | .TP | |
7133 | \fBhistory\fP \fB\-s\fP \fIarg\fP [\fIarg ...\fP] | |
726f6388 JA |
7134 | .PD |
7135 | With no options, display the command | |
7136 | history list with line numbers. Lines listed | |
7137 | with a | |
7138 | .B * | |
7139 | have been modified. An argument of | |
7140 | .I n | |
7141 | lists only the last | |
7142 | .I n | |
d3a24ed2 CR |
7143 | lines. |
7144 | If the shell variable \fBHISTTIMEFORMAT\fP is set and not null, | |
7145 | it is used as a format string for \fIstrftime\fP(3) to display | |
7146 | the time stamp associated with each displayed history entry. | |
7147 | No intervening blank is printed between the formatted time stamp | |
7148 | and the history line. | |
7149 | If \fIfilename\fP is supplied, it is used as the | |
726f6388 JA |
7150 | name of the history file; if not, the value of |
7151 | .SM | |
7152 | .B HISTFILE | |
7153 | is used. Options, if supplied, have the following meanings: | |
7154 | .RS | |
7155 | .PD 0 | |
7156 | .TP | |
bb70624e JA |
7157 | .B \-c |
7158 | Clear the history list by deleting all the entries. | |
7159 | .TP | |
7160 | \fB\-d\fP \fIoffset\fP | |
7161 | Delete the history entry at position \fIoffset\fP. | |
7162 | .TP | |
726f6388 JA |
7163 | .B \-a |
7164 | Append the ``new'' history lines (history lines entered since the | |
ccc6cda3 | 7165 | beginning of the current \fBbash\fP session) to the history file. |
726f6388 JA |
7166 | .TP |
7167 | .B \-n | |
7168 | Read the history lines not already read from the history | |
7169 | file into the current history list. These are lines | |
7170 | appended to the history file since the beginning of the | |
7171 | current \fBbash\fP session. | |
7172 | .TP | |
7173 | .B \-r | |
7174 | Read the contents of the history file | |
ccc6cda3 | 7175 | and use them as the current history. |
726f6388 JA |
7176 | .TP |
7177 | .B \-w | |
7178 | Write the current history to the history file, overwriting the | |
7179 | history file's contents. | |
ccc6cda3 | 7180 | .TP |
ccc6cda3 JA |
7181 | .B \-p |
7182 | Perform history substitution on the following \fIargs\fP and display | |
7183 | the result on the standard output. | |
7184 | Does not store the results in the history list. | |
7185 | Each \fIarg\fP must be quoted to disable normal history expansion. | |
7186 | .TP | |
7187 | .B \-s | |
7188 | Store the | |
7189 | .I args | |
7190 | in the history list as a single entry. The last command in the | |
7191 | history list is removed before the | |
7192 | .I args | |
7193 | are added. | |
726f6388 JA |
7194 | .PD |
7195 | .PP | |
d3a24ed2 | 7196 | If the \fBHISTTIMEFORMAT\fP is set, the time stamp information |
d3ad40de CR |
7197 | associated with each history entry is written to the history file, |
7198 | marked with the history comment character. | |
7199 | When the history file is read, lines beginning with the history | |
7200 | comment character followed immediately by a digit are interpreted | |
7201 | as timestamps for the previous history line. | |
bb70624e JA |
7202 | The return value is 0 unless an invalid option is encountered, an |
7203 | error occurs while reading or writing the history file, an invalid | |
7204 | \fIoffset\fP is supplied as an argument to \fB\-d\fP, or the | |
7205 | history expansion supplied as an argument to \fB\-p\fP fails. | |
726f6388 JA |
7206 | .RE |
7207 | .TP | |
ccc6cda3 | 7208 | \fBjobs\fP [\fB\-lnprs\fP] [ \fIjobspec\fP ... ] |
7117c2d2 | 7209 | .PD 0 |
726f6388 JA |
7210 | .TP |
7211 | \fBjobs\fP \fB\-x\fP \fIcommand\fP [ \fIargs\fP ... ] | |
7212 | .PD | |
ccc6cda3 JA |
7213 | The first form lists the active jobs. The options have the following |
7214 | meanings: | |
7215 | .RS | |
7216 | .PD 0 | |
7217 | .TP | |
726f6388 | 7218 | .B \-l |
ccc6cda3 JA |
7219 | List process IDs |
7220 | in addition to the normal information. | |
7221 | .TP | |
726f6388 | 7222 | .B \-p |
ccc6cda3 JA |
7223 | List only the process ID of the job's process group |
7224 | leader. | |
7225 | .TP | |
726f6388 | 7226 | .B \-n |
ccc6cda3 JA |
7227 | Display information only about jobs that have changed status since |
7228 | the user was last notified of their status. | |
7229 | .TP | |
7230 | .B \-r | |
7231 | Restrict output to running jobs. | |
7232 | .TP | |
7233 | .B \-s | |
7234 | Restrict output to stopped jobs. | |
7235 | .PD | |
7236 | .PP | |
7237 | If | |
726f6388 JA |
7238 | .I jobspec |
7239 | is given, output is restricted to information about that job. | |
cce855bc JA |
7240 | The return status is 0 unless an invalid option is encountered |
7241 | or an invalid | |
726f6388 JA |
7242 | .I jobspec |
7243 | is supplied. | |
ccc6cda3 | 7244 | .PP |
726f6388 JA |
7245 | If the |
7246 | .B \-x | |
7247 | option is supplied, | |
7248 | .B jobs | |
7249 | replaces any | |
7250 | .I jobspec | |
7251 | found in | |
7252 | .I command | |
7253 | or | |
7254 | .I args | |
7255 | with the corresponding process group ID, and executes | |
7256 | .I command | |
7257 | passing it | |
7258 | .IR args , | |
7259 | returning its exit status. | |
ccc6cda3 | 7260 | .RE |
726f6388 | 7261 | .TP |
ccc6cda3 | 7262 | \fBkill\fP [\fB\-s\fP \fIsigspec\fP | \fB\-n\fP \fIsignum\fP | \fB\-\fP\fIsigspec\fP] [\fIpid\fP | \fIjobspec\fP] ... |
7117c2d2 | 7263 | .PD 0 |
726f6388 | 7264 | .TP |
cce855bc | 7265 | \fBkill\fP \fB\-l\fP [\fIsigspec\fP | \fIexit_status\fP] |
726f6388 JA |
7266 | .PD |
7267 | Send the signal named by | |
7268 | .I sigspec | |
ccc6cda3 JA |
7269 | or |
7270 | .I signum | |
726f6388 JA |
7271 | to the processes named by |
7272 | .I pid | |
7273 | or | |
7274 | .IR jobspec . | |
7275 | .I sigspec | |
61deeb13 | 7276 | is either a case-insensitive signal name such as |
726f6388 JA |
7277 | .SM |
7278 | .B SIGKILL | |
61deeb13 | 7279 | (with or without the |
726f6388 JA |
7280 | .SM |
7281 | .B SIG | |
61deeb13 CR |
7282 | prefix) or a signal number; |
7283 | .I signum | |
7284 | is a signal number. | |
726f6388 JA |
7285 | If |
7286 | .I sigspec | |
7287 | is not present, then | |
7288 | .SM | |
7289 | .B SIGTERM | |
cce855bc JA |
7290 | is assumed. |
7291 | An argument of | |
726f6388 | 7292 | .B \-l |
cce855bc JA |
7293 | lists the signal names. |
7294 | If any arguments are supplied when | |
726f6388 | 7295 | .B \-l |
cce855bc JA |
7296 | is given, the names of the signals corresponding to the arguments are |
7297 | listed, and the return status is 0. | |
7298 | The \fIexit_status\fP argument to | |
ccc6cda3 | 7299 | .B \-l |
cce855bc JA |
7300 | is a number specifying either a signal number or the exit status of |
7301 | a process terminated by a signal. | |
726f6388 JA |
7302 | .B kill |
7303 | returns true if at least one signal was successfully sent, or false | |
cce855bc | 7304 | if an error occurs or an invalid option is encountered. |
726f6388 JA |
7305 | .TP |
7306 | \fBlet\fP \fIarg\fP [\fIarg\fP ...] | |
7307 | Each | |
7308 | .I arg | |
7309 | is an arithmetic expression to be evaluated (see | |
7310 | .SM | |
7311 | .BR "ARITHMETIC EVALUATION" ). | |
7312 | If the last | |
7313 | .I arg | |
7314 | evaluates to 0, | |
7315 | .B let | |
7316 | returns 1; 0 is returned otherwise. | |
7317 | .TP | |
bb70624e | 7318 | \fBlocal\fP [\fIoption\fP] [\fIname\fP[=\fIvalue\fP] ...] |
cce855bc JA |
7319 | For each argument, a local variable named |
7320 | .I name | |
7321 | is created, and assigned | |
726f6388 | 7322 | .IR value . |
bb70624e | 7323 | The \fIoption\fP can be any of the options accepted by \fBdeclare\fP. |
726f6388 JA |
7324 | When |
7325 | .B local | |
7326 | is used within a function, it causes the variable | |
7327 | .I name | |
7328 | to have a visible scope restricted to that function and its children. | |
7329 | With no operands, | |
7330 | .B local | |
7331 | writes a list of local variables to the standard output. It is | |
7332 | an error to use | |
7333 | .B local | |
7334 | when not within a function. The return status is 0 unless | |
7335 | .B local | |
bb70624e | 7336 | is used outside a function, an invalid |
726f6388 | 7337 | .I name |
bb70624e JA |
7338 | is supplied, or |
7339 | \fIname\fP is a readonly variable. | |
726f6388 JA |
7340 | .TP |
7341 | .B logout | |
7342 | Exit a login shell. | |
7343 | .TP | |
ccc6cda3 | 7344 | \fBpopd\fP [\-\fBn\fP] [+\fIn\fP] [\-\fIn\fP] |
726f6388 JA |
7345 | Removes entries from the directory stack. With no arguments, |
7346 | removes the top directory from the stack, and performs a | |
7347 | .B cd | |
7348 | to the new top directory. | |
ccc6cda3 | 7349 | Arguments, if supplied, have the following meanings: |
726f6388 JA |
7350 | .RS |
7351 | .PD 0 | |
7352 | .TP | |
d3ad40de CR |
7353 | .B \-n |
7354 | Suppresses the normal change of directory when removing directories | |
7355 | from the stack, so that only the stack is manipulated. | |
7356 | .TP | |
ccc6cda3 JA |
7357 | \fB+\fP\fIn\fP |
7358 | Removes the \fIn\fPth entry counting from the left of the list | |
726f6388 JA |
7359 | shown by |
7360 | .BR dirs , | |
bb70624e JA |
7361 | starting with zero. For example: |
7362 | .if n ``popd +0'' | |
7363 | .if t \f(CWpopd +0\fP | |
7364 | removes the first directory, | |
7365 | .if n ``popd +1'' | |
7366 | .if t \f(CWpopd +1\fP | |
7367 | the second. | |
726f6388 | 7368 | .TP |
ccc6cda3 JA |
7369 | \fB\-\fP\fIn\fP |
7370 | Removes the \fIn\fPth entry counting from the right of the list | |
726f6388 JA |
7371 | shown by |
7372 | .BR dirs , | |
bb70624e JA |
7373 | starting with zero. For example: |
7374 | .if n ``popd -0'' | |
7375 | .if t \f(CWpopd -0\fP | |
7376 | removes the last directory, | |
7377 | .if n ``popd -1'' | |
7378 | .if t \f(CWpopd -1\fP | |
7379 | the next to last. | |
726f6388 JA |
7380 | .PD |
7381 | .PP | |
7382 | If the | |
7383 | .B popd | |
7384 | command is successful, a | |
7385 | .B dirs | |
7386 | is performed as well, and the return status is 0. | |
7387 | .B popd | |
cce855bc | 7388 | returns false if an invalid option is encountered, the directory stack |
726f6388 JA |
7389 | is empty, a non-existent directory stack entry is specified, or the |
7390 | directory change fails. | |
7391 | .RE | |
7392 | .TP | |
3ee6b87d | 7393 | \fBprintf\fP [\fB\-v\fP \fIvar\fP] \fIformat\fP [\fIarguments\fP] |
cce855bc JA |
7394 | Write the formatted \fIarguments\fP to the standard output under the |
7395 | control of the \fIformat\fP. | |
7396 | The \fIformat\fP is a character string which contains three types of objects: | |
7397 | plain characters, which are simply copied to standard output, character | |
7398 | escape sequences, which are converted and copied to the standard output, and | |
7399 | format specifications, each of which causes printing of the next successive | |
7400 | \fIargument\fP. | |
f73dda09 | 7401 | In addition to the standard \fIprintf\fP(1) formats, \fB%b\fP causes |
cce855bc | 7402 | \fBprintf\fP to expand backslash escape sequences in the corresponding |
5e13499c | 7403 | \fIargument\fP (except that \fB\ec\fP terminates output, backslashes in |
20587658 | 7404 | \fB\e\(aq\fP, \fB\e"\fP, and \fB\e?\fP are not removed, and octal escapes |
5e13499c CR |
7405 | beginning with \fB\e0\fP may contain up to four digits), |
7406 | and \fB%q\fP causes \fBprintf\fP to output the corresponding | |
cce855bc JA |
7407 | \fIargument\fP in a format that can be reused as shell input. |
7408 | .sp 1 | |
3ee6b87d CR |
7409 | The \fB\-v\fP option causes the output to be assigned to the variable |
7410 | \fIvar\fP rather than being printed to the standard output. | |
7411 | .sp 1 | |
cce855bc JA |
7412 | The \fIformat\fP is reused as necessary to consume all of the \fIarguments\fP. |
7413 | If the \fIformat\fP requires more \fIarguments\fP than are supplied, the | |
7414 | extra format specifications behave as if a zero value or null string, as | |
bb70624e JA |
7415 | appropriate, had been supplied. The return value is zero on success, |
7416 | non-zero on failure. | |
cce855bc | 7417 | .TP |
d3ad40de | 7418 | \fBpushd\fP [\fB\-n\fP] [+\fIn\fP] [\-\fIn\fP] |
7117c2d2 | 7419 | .PD 0 |
726f6388 | 7420 | .TP |
d3ad40de | 7421 | \fBpushd\fP [\fB\-n\fP] [\fIdir\fP] |
726f6388 JA |
7422 | .PD |
7423 | Adds a directory to the top of the directory stack, or rotates | |
7424 | the stack, making the new top of the stack the current working | |
7425 | directory. With no arguments, exchanges the top two directories | |
7426 | and returns 0, unless the directory stack is empty. | |
ccc6cda3 | 7427 | Arguments, if supplied, have the following meanings: |
726f6388 JA |
7428 | .RS |
7429 | .PD 0 | |
7430 | .TP | |
d3ad40de CR |
7431 | .B \-n |
7432 | Suppresses the normal change of directory when adding directories | |
7433 | to the stack, so that only the stack is manipulated. | |
7434 | .TP | |
ccc6cda3 | 7435 | \fB+\fP\fIn\fP |
726f6388 JA |
7436 | Rotates the stack so that the \fIn\fPth directory |
7437 | (counting from the left of the list shown by | |
d166f048 JA |
7438 | .BR dirs , |
7439 | starting with zero) | |
726f6388 JA |
7440 | is at the top. |
7441 | .TP | |
ccc6cda3 | 7442 | \fB\-\fP\fIn\fP |
726f6388 | 7443 | Rotates the stack so that the \fIn\fPth directory |
d166f048 JA |
7444 | (counting from the right of the list shown by |
7445 | .BR dirs , | |
7446 | starting with zero) is at the top. | |
726f6388 | 7447 | .TP |
bb70624e | 7448 | .I dir |
ccc6cda3 | 7449 | Adds |
726f6388 JA |
7450 | .I dir |
7451 | to the directory stack at the top, making it the | |
7452 | new current working directory. | |
7453 | .PD | |
7454 | .PP | |
7455 | If the | |
7456 | .B pushd | |
7457 | command is successful, a | |
7458 | .B dirs | |
7459 | is performed as well. | |
7460 | If the first form is used, | |
7461 | .B pushd | |
7462 | returns 0 unless the cd to | |
7463 | .I dir | |
7464 | fails. With the second form, | |
7465 | .B pushd | |
7466 | returns 0 unless the directory stack is empty, | |
ccc6cda3 | 7467 | a non-existent directory stack element is specified, |
726f6388 JA |
7468 | or the directory change to the specified new current directory |
7469 | fails. | |
7470 | .RE | |
7471 | .TP | |
ccc6cda3 | 7472 | \fBpwd\fP [\fB\-LP\fP] |
bb70624e JA |
7473 | Print the absolute pathname of the current working directory. |
7474 | The pathname printed contains no symbolic links if the | |
726f6388 | 7475 | .B \-P |
ccc6cda3 JA |
7476 | option is supplied or the |
7477 | .B \-o physical | |
726f6388 JA |
7478 | option to the |
7479 | .B set | |
ccc6cda3 JA |
7480 | builtin command is enabled. |
7481 | If the | |
7482 | .B \-L | |
bb70624e | 7483 | option is used, the pathname printed may contain symbolic links. |
ccc6cda3 | 7484 | The return status is 0 unless an error occurs while |
cce855bc JA |
7485 | reading the name of the current directory or an |
7486 | invalid option is supplied. | |
726f6388 | 7487 | .TP |
d3ad40de | 7488 | \fBread\fP [\fB\-ers\fP] [\fB\-a\fP \fIaname\fP] [\fB\-d\fP \fIdelim\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 |
7489 | One line is read from the standard input, or from the file descriptor |
7490 | \fIfd\fP supplied as an argument to the \fB\-u\fP option, and the first word | |
726f6388 JA |
7491 | is assigned to the first |
7492 | .IR name , | |
7493 | the second word to the second | |
7494 | .IR name , | |
cce855bc JA |
7495 | and so on, with leftover words and their intervening separators assigned |
7496 | to the last | |
726f6388 | 7497 | .IR name . |
7117c2d2 | 7498 | If there are fewer words read from the input stream than names, |
cce855bc JA |
7499 | the remaining names are assigned empty values. |
7500 | The characters in | |
726f6388 JA |
7501 | .SM |
7502 | .B IFS | |
cce855bc | 7503 | are used to split the line into words. |
b72432fd JA |
7504 | The backslash character (\fB\e\fP) may be used to remove any special |
7505 | meaning for the next character read and for line continuation. | |
cce855bc | 7506 | Options, if supplied, have the following meanings: |
ccc6cda3 JA |
7507 | .RS |
7508 | .PD 0 | |
7509 | .TP | |
bb70624e | 7510 | .B \-a \fIaname\fP |
ccc6cda3 JA |
7511 | The words are assigned to sequential indices |
7512 | of the array variable | |
7513 | .IR aname , | |
7514 | starting at 0. | |
7515 | .I aname | |
7516 | is unset before any new values are assigned. | |
cce855bc | 7517 | Other \fIname\fP arguments are ignored. |
ccc6cda3 | 7518 | .TP |
bb70624e JA |
7519 | .B \-d \fIdelim\fP |
7520 | The first character of \fIdelim\fP is used to terminate the input line, | |
7521 | rather than newline. | |
7522 | .TP | |
ccc6cda3 JA |
7523 | .B \-e |
7524 | If the standard input | |
7525 | is coming from a terminal, | |
7526 | .B readline | |
7527 | (see | |
7528 | .SM | |
7529 | .B READLINE | |
7530 | above) is used to obtain the line. | |
bb70624e JA |
7531 | .TP |
7532 | .B \-n \fInchars\fP | |
7533 | \fBread\fP returns after reading \fInchars\fP characters rather than | |
7534 | waiting for a complete line of input. | |
7535 | .TP | |
7536 | .B \-p \fIprompt\fP | |
f73dda09 | 7537 | Display \fIprompt\fP on standard error, without a |
bb70624e JA |
7538 | trailing newline, before attempting to read any input. The prompt |
7539 | is displayed only if input is coming from a terminal. | |
7540 | .TP | |
7541 | .B \-r | |
7542 | Backslash does not act as an escape character. | |
7543 | The backslash is considered to be part of the line. | |
7544 | In particular, a backslash-newline pair may not be used as a line | |
7545 | continuation. | |
7546 | .TP | |
7547 | .B \-s | |
7548 | Silent mode. If input is coming from a terminal, characters are | |
7549 | not echoed. | |
7550 | .TP | |
7551 | .B \-t \fItimeout\fP | |
7552 | Cause \fBread\fP to time out and return failure if a complete line of | |
7553 | input is not read within \fItimeout\fP seconds. | |
7554 | This option has no effect if \fBread\fP is not reading input from the | |
7555 | terminal or a pipe. | |
7117c2d2 | 7556 | .TP |
0f445e6c | 7557 | .B \-u \fIfd\fP |
7117c2d2 | 7558 | Read input from file descriptor \fIfd\fP. |
ccc6cda3 JA |
7559 | .PD |
7560 | .PP | |
7561 | If no | |
726f6388 JA |
7562 | .I names |
7563 | are supplied, the line read is assigned to the variable | |
7564 | .SM | |
7565 | .BR REPLY . | |
7117c2d2 JA |
7566 | The return code is zero, unless end-of-file is encountered, \fBread\fP |
7567 | times out, or an invalid file descriptor is supplied as the argument to | |
7568 | \fB\-u\fP. | |
ccc6cda3 | 7569 | .RE |
726f6388 | 7570 | .TP |
d3a24ed2 | 7571 | \fBreadonly\fP [\fB\-apf\fP] [\fIname\fP[=\fIword\fP] ...] |
726f6388 JA |
7572 | .PD |
7573 | The given | |
ccc6cda3 JA |
7574 | \fInames\fP are marked readonly; the values of these |
7575 | .I names | |
726f6388 JA |
7576 | may not be changed by subsequent assignment. |
7577 | If the | |
7578 | .B \-f | |
7579 | option is supplied, the functions corresponding to the | |
7580 | \fInames\fP are so | |
ccc6cda3 JA |
7581 | marked. |
7582 | The | |
7583 | .B \-a | |
7584 | option restricts the variables to arrays. | |
7585 | If no | |
7586 | .I name | |
7587 | arguments are given, or if the | |
726f6388 | 7588 | .B \-p |
ccc6cda3 | 7589 | option is supplied, a list of all readonly names is printed. |
cce855bc JA |
7590 | The |
7591 | .B \-p | |
bb70624e JA |
7592 | option causes output to be displayed in a format that |
7593 | may be reused as input. | |
d3a24ed2 CR |
7594 | If a variable name is followed by =\fIword\fP, the value of |
7595 | the variable is set to \fIword\fP. | |
cce855bc | 7596 | The return status is 0 unless an invalid option is encountered, |
ccc6cda3 JA |
7597 | one of the |
7598 | .I names | |
cce855bc | 7599 | is not a valid shell variable name, or |
726f6388 JA |
7600 | .B \-f |
7601 | is supplied with a | |
7602 | .I name | |
7603 | that is not a function. | |
7604 | .TP | |
7605 | \fBreturn\fP [\fIn\fP] | |
7606 | Causes a function to exit with the return value specified by | |
7607 | .IR n . | |
7608 | If | |
7609 | .I n | |
7610 | is omitted, the return status is that of the last command | |
7611 | executed in the function body. If used outside a function, | |
7612 | but during execution of a script by the | |
7613 | .B . | |
7614 | (\fBsource\fP) command, it causes the shell to stop executing | |
7615 | that script and return either | |
7616 | .I n | |
7617 | or the exit status of the last command executed within the | |
7618 | script as the exit status of the script. If used outside a | |
7619 | function and not during execution of a script by \fB.\fP\^, | |
7620 | the return status is false. | |
d3a24ed2 CR |
7621 | Any command associated with the \fBRETURN\fP trap is executed |
7622 | before execution resumes after the function or script. | |
726f6388 | 7623 | .TP |
d3ad40de CR |
7624 | \fBset\fP [\fB\-\-abefhkmnptuvxBCEHPT\fP] [\fB\-o\fP \fIoption\fP] [\fIarg\fP ...] |
7625 | .PD 0 | |
7626 | .TP | |
7627 | \fBset\fP [\fB+abefhkmnptuvxBCEHPT\fP] [\fB+o\fP \fIoption\fP] [\fIarg\fP ...] | |
7628 | .PD | |
ccc6cda3 | 7629 | Without options, the name and value of each shell variable are displayed |
54cdd75a CR |
7630 | in a format that can be reused as input |
7631 | for setting or resetting the currently-set variables. | |
7632 | Read-only variables cannot be reset. | |
7633 | In \fIposix mode\fP, only shell variables are listed. | |
cce855bc | 7634 | The output is sorted according to the current locale. |
ccc6cda3 JA |
7635 | When options are specified, they set or unset shell attributes. |
7636 | Any arguments remaining after the options are processed are treated | |
7637 | as values for the positional parameters and are assigned, in order, to | |
7638 | .BR $1 , | |
7639 | .BR $2 , | |
7640 | .B ... | |
7641 | .BR $\fIn\fP . | |
7642 | Options, if specified, have the following meanings: | |
726f6388 JA |
7643 | .RS |
7644 | .PD 0 | |
7645 | .TP 8 | |
7646 | .B \-a | |
5e13499c CR |
7647 | Automatically mark variables and functions which are modified or |
7648 | created for export to the environment of subsequent commands. | |
726f6388 JA |
7649 | .TP 8 |
7650 | .B \-b | |
ccc6cda3 JA |
7651 | Report the status of terminated background jobs |
7652 | immediately, rather than before the next primary prompt. This is | |
7653 | effective only when job control is enabled. | |
726f6388 JA |
7654 | .TP 8 |
7655 | .B \-e | |
ccc6cda3 | 7656 | Exit immediately if a \fIsimple command\fP (see |
726f6388 JA |
7657 | .SM |
7658 | .B SHELL GRAMMAR | |
d3a24ed2 CR |
7659 | above) exits with a non-zero status. |
7660 | The shell does not exit if the | |
7661 | command that fails is part of the command list immediately following a | |
7662 | .B while | |
726f6388 | 7663 | or |
d3a24ed2 CR |
7664 | .B until |
7665 | keyword, | |
7666 | part of the test in an | |
d3ad40de | 7667 | .B if |
726f6388 JA |
7668 | statement, part of a |
7669 | .B && | |
7670 | or | |
ccc6cda3 | 7671 | .B \(bv\(bv |
d3ad40de CR |
7672 | list, |
7673 | any command in a pipeline but the last, | |
7674 | or if the command's return value is | |
726f6388 JA |
7675 | being inverted via |
7676 | .BR ! . | |
53ac45a3 CR |
7677 | Failing simple commands that are part of shell functions or command lists |
7678 | enclosed in braces or parentheses satisfying the above conditions do not | |
7679 | cause the shell to exit. | |
f73dda09 | 7680 | A trap on \fBERR\fP, if set, is executed before the shell exits. |
726f6388 JA |
7681 | .TP 8 |
7682 | .B \-f | |
7683 | Disable pathname expansion. | |
7684 | .TP 8 | |
7685 | .B \-h | |
ccc6cda3 | 7686 | Remember the location of commands as they are looked up for execution. |
cce855bc | 7687 | This is enabled by default. |
726f6388 JA |
7688 | .TP 8 |
7689 | .B \-k | |
ccc6cda3 JA |
7690 | All arguments in the form of assignment statements |
7691 | are placed in the environment for a command, not just | |
7692 | those that precede the command name. | |
726f6388 JA |
7693 | .TP 8 |
7694 | .B \-m | |
cce855bc | 7695 | Monitor mode. Job control is enabled. This option is on |
726f6388 JA |
7696 | by default for interactive shells on systems that support |
7697 | it (see | |
7698 | .SM | |
7699 | .B JOB CONTROL | |
7700 | above). Background processes run in a separate process | |
7701 | group and a line containing their exit status is printed | |
7702 | upon their completion. | |
7703 | .TP 8 | |
7704 | .B \-n | |
7705 | Read commands but do not execute them. This may be used to | |
ccc6cda3 | 7706 | check a shell script for syntax errors. This is ignored by |
726f6388 JA |
7707 | interactive shells. |
7708 | .TP 8 | |
ccc6cda3 JA |
7709 | .B \-o \fIoption\-name\fP |
7710 | The \fIoption\-name\fP can be one of the following: | |
726f6388 JA |
7711 | .RS |
7712 | .TP 8 | |
7713 | .B allexport | |
7714 | Same as | |
7715 | .BR \-a . | |
7716 | .TP 8 | |
7717 | .B braceexpand | |
ccc6cda3 JA |
7718 | Same as |
7719 | .BR \-B . | |
726f6388 JA |
7720 | .TP 8 |
7721 | .B emacs | |
7722 | Use an emacs-style command line editing interface. This is enabled | |
7723 | by default when the shell is interactive, unless the shell is started | |
7724 | with the | |
ccc6cda3 | 7725 | .B \-\-noediting |
726f6388 JA |
7726 | option. |
7727 | .TP 8 | |
d3a24ed2 CR |
7728 | .B errtrace |
7729 | Same as | |
7730 | .BR \-E . | |
7731 | .TP 8 | |
7732 | .B functrace | |
7733 | Same as | |
7734 | .BR \-T . | |
7735 | .TP 8 | |
726f6388 JA |
7736 | .B errexit |
7737 | Same as | |
7738 | .BR \-e . | |
7739 | .TP 8 | |
ccc6cda3 JA |
7740 | .B hashall |
7741 | Same as | |
7742 | .BR \-h . | |
7743 | .TP 8 | |
726f6388 JA |
7744 | .B histexpand |
7745 | Same as | |
7746 | .BR \-H . | |
7747 | .TP 8 | |
ccc6cda3 JA |
7748 | .B history |
7749 | Enable command history, as described above under | |
7750 | .SM | |
7751 | .BR HISTORY . | |
7752 | This option is on by default in interactive shells. | |
7753 | .TP 8 | |
726f6388 | 7754 | .B ignoreeof |
28ef6c31 JA |
7755 | The effect is as if the shell command |
7756 | .if t \f(CWIGNOREEOF=10\fP | |
7757 | .if n ``IGNOREEOF=10'' | |
7758 | had been executed | |
726f6388 JA |
7759 | (see |
7760 | .B Shell Variables | |
7761 | above). | |
7762 | .TP 8 | |
ccc6cda3 JA |
7763 | .B keyword |
7764 | Same as | |
7765 | .BR \-k . | |
726f6388 JA |
7766 | .TP 8 |
7767 | .B monitor | |
7768 | Same as | |
7769 | .BR \-m . | |
7770 | .TP 8 | |
7771 | .B noclobber | |
7772 | Same as | |
7773 | .BR \-C . | |
7774 | .TP 8 | |
7775 | .B noexec | |
7776 | Same as | |
7777 | .BR \-n . | |
7778 | .TP 8 | |
7779 | .B noglob | |
7780 | Same as | |
7781 | .BR \-f . | |
f73dda09 JA |
7782 | .B nolog |
7783 | Currently ignored. | |
726f6388 | 7784 | .TP 8 |
726f6388 JA |
7785 | .B notify |
7786 | Same as | |
7787 | .BR \-b . | |
7788 | .TP 8 | |
7789 | .B nounset | |
7790 | Same as | |
7791 | .BR \-u . | |
7792 | .TP 8 | |
ccc6cda3 JA |
7793 | .B onecmd |
7794 | Same as | |
7795 | .BR \-t . | |
7796 | .TP 8 | |
726f6388 JA |
7797 | .B physical |
7798 | Same as | |
7799 | .BR \-P . | |
7800 | .TP 8 | |
d3a24ed2 CR |
7801 | .B pipefail |
7802 | If set, the return value of a pipeline is the value of the last | |
7803 | (rightmost) command to exit with a non-zero status, or zero if all | |
7804 | commands in the pipeline exit successfully. | |
7805 | This option is disabled by default. | |
7806 | .TP 8 | |
726f6388 | 7807 | .B posix |
ccc6cda3 JA |
7808 | Change the behavior of |
7809 | .B bash | |
7810 | where the default operation differs | |
ac18b312 | 7811 | from the POSIX standard to match the standard (\fIposix mode\fP). |
726f6388 JA |
7812 | .TP 8 |
7813 | .B privileged | |
7814 | Same as | |
7815 | .BR \-p . | |
7816 | .TP 8 | |
7817 | .B verbose | |
7818 | Same as | |
7819 | .BR \-v . | |
7820 | .TP 8 | |
7821 | .B vi | |
7822 | Use a vi-style command line editing interface. | |
7823 | .TP 8 | |
7824 | .B xtrace | |
7825 | Same as | |
7826 | .BR \-x . | |
ccc6cda3 | 7827 | .sp .5 |
726f6388 | 7828 | .PP |
ccc6cda3 JA |
7829 | If |
7830 | .B \-o | |
7831 | is supplied with no \fIoption\-name\fP, the values of the current options are | |
726f6388 | 7832 | printed. |
ccc6cda3 JA |
7833 | If |
7834 | .B +o | |
7835 | is supplied with no \fIoption\-name\fP, a series of | |
7836 | .B set | |
7837 | commands to recreate the current option settings is displayed on | |
7838 | the standard output. | |
726f6388 JA |
7839 | .RE |
7840 | .TP 8 | |
7841 | .B \-p | |
7842 | Turn on | |
7843 | .I privileged | |
7844 | mode. In this mode, the | |
bb70624e | 7845 | .SM |
726f6388 | 7846 | .B $ENV |
b72432fd | 7847 | and |
bb70624e | 7848 | .SM |
b72432fd JA |
7849 | .B $BASH_ENV |
7850 | files are not processed, shell functions are not inherited from the | |
bb70624e JA |
7851 | environment, and the |
7852 | .SM | |
7853 | .B SHELLOPTS | |
7854 | variable, if it appears in the environment, is ignored. | |
b72432fd JA |
7855 | If the shell is started with the effective user (group) id not equal to the |
7856 | real user (group) id, and the \fB\-p\fP option is not supplied, these actions | |
7857 | are taken and the effective user id is set to the real user id. | |
7858 | If the \fB\-p\fP option is supplied at startup, the effective user id is | |
7859 | not reset. | |
cce855bc | 7860 | Turning this option off causes the effective user |
726f6388 JA |
7861 | and group ids to be set to the real user and group ids. |
7862 | .TP 8 | |
7863 | .B \-t | |
7864 | Exit after reading and executing one command. | |
7865 | .TP 8 | |
7866 | .B \-u | |
7867 | Treat unset variables as an error when performing | |
7868 | parameter expansion. If expansion is attempted on an | |
7869 | unset variable, the shell prints an error message, and, | |
ccc6cda3 | 7870 | if not interactive, exits with a non-zero status. |
726f6388 JA |
7871 | .TP 8 |
7872 | .B \-v | |
7873 | Print shell input lines as they are read. | |
7874 | .TP 8 | |
7875 | .B \-x | |
ccc6cda3 | 7876 | After expanding each \fIsimple command\fP, |
d3a24ed2 CR |
7877 | \fBfor\fP command, \fBcase\fP command, \fBselect\fP command, or |
7878 | arithmetic \fBfor\fP command, display the expanded value of | |
726f6388 JA |
7879 | .SM |
7880 | .BR PS4 , | |
d3a24ed2 CR |
7881 | followed by the command and its expanded arguments |
7882 | or associated word list. | |
726f6388 | 7883 | .TP 8 |
ccc6cda3 JA |
7884 | .B \-B |
7885 | The shell performs brace expansion (see | |
7886 | .B Brace Expansion | |
7887 | above). This is on by default. | |
726f6388 JA |
7888 | .TP 8 |
7889 | .B \-C | |
ccc6cda3 JA |
7890 | If set, |
7891 | .B bash | |
7892 | does not overwrite an existing file with the | |
7893 | .BR > , | |
7894 | .BR >& , | |
7895 | and | |
7896 | .B <> | |
7897 | redirection operators. This may be overridden when | |
7898 | creating output files by using the redirection operator | |
7899 | .B >| | |
7900 | instead of | |
7901 | .BR > . | |
726f6388 | 7902 | .TP 8 |
d3a24ed2 CR |
7903 | .B \-E |
7904 | If set, any trap on \fBERR\fP is inherited by shell functions, command | |
7905 | substitutions, and commands executed in a subshell environment. | |
7906 | The \fBERR\fP trap is normally not inherited in such cases. | |
7907 | .TP 8 | |
726f6388 JA |
7908 | .B \-H |
7909 | Enable | |
7910 | .B ! | |
cce855bc | 7911 | style history substitution. This option is on by |
726f6388 JA |
7912 | default when the shell is interactive. |
7913 | .TP 8 | |
7914 | .B \-P | |
ccc6cda3 JA |
7915 | If set, the shell does not follow symbolic links when executing |
7916 | commands such as | |
726f6388 | 7917 | .B cd |
ccc6cda3 JA |
7918 | that change the current working directory. It uses the |
7919 | physical directory structure instead. By default, | |
7920 | .B bash | |
7921 | follows the logical chain of directories when performing commands | |
7922 | which change the current directory. | |
726f6388 | 7923 | .TP 8 |
d3a24ed2 | 7924 | .B \-T |
76a8d78d CR |
7925 | If set, any traps on \fBDEBUG\fP and \fBRETURN\fP are inherited by shell |
7926 | functions, command substitutions, and commands executed in a | |
7927 | subshell environment. | |
7928 | The \fBDEBUG\fP and \fBRETURN\fP traps are normally not inherited | |
7929 | in such cases. | |
d3a24ed2 | 7930 | .TP 8 |
726f6388 | 7931 | .B \-\- |
cce855bc | 7932 | If no arguments follow this option, then the positional parameters are |
726f6388 JA |
7933 | unset. Otherwise, the positional parameters are set to the |
7934 | \fIarg\fPs, even if some of them begin with a | |
7935 | .BR \- . | |
7936 | .TP 8 | |
7937 | .B \- | |
7938 | Signal the end of options, cause all remaining \fIarg\fPs to be | |
7939 | assigned to the positional parameters. The | |
7940 | .B \-x | |
7941 | and | |
7942 | .B \-v | |
7943 | options are turned off. | |
7944 | If there are no \fIarg\fPs, | |
7945 | the positional parameters remain unchanged. | |
7946 | .PD | |
7947 | .PP | |
cce855bc JA |
7948 | The options are off by default unless otherwise noted. |
7949 | Using + rather than \- causes these options to be turned off. | |
7950 | The options can also be specified as arguments to an invocation of | |
7951 | the shell. | |
7952 | The current set of options may be found in | |
726f6388 | 7953 | .BR $\- . |
cce855bc | 7954 | The return status is always true unless an invalid option is encountered. |
726f6388 JA |
7955 | .RE |
7956 | .TP | |
7957 | \fBshift\fP [\fIn\fP] | |
7958 | The positional parameters from \fIn\fP+1 ... are renamed to | |
7959 | .B $1 | |
7960 | .B .... | |
7961 | Parameters represented by the numbers \fB$#\fP | |
7962 | down to \fB$#\fP\-\fIn\fP+1 are unset. | |
ccc6cda3 JA |
7963 | .I n |
7964 | must be a non-negative number less than or equal to \fB$#\fP. | |
726f6388 JA |
7965 | If |
7966 | .I n | |
7967 | is 0, no parameters are changed. | |
7968 | If | |
7969 | .I n | |
7970 | is not given, it is assumed to be 1. | |
726f6388 JA |
7971 | If |
7972 | .I n | |
7973 | is greater than \fB$#\fP, the positional parameters are not changed. | |
ccc6cda3 | 7974 | The return status is greater than zero if |
726f6388 JA |
7975 | .I n |
7976 | is greater than | |
7977 | .B $# | |
ccc6cda3 JA |
7978 | or less than zero; otherwise 0. |
7979 | .TP | |
7980 | \fBshopt\fP [\fB\-pqsu\fP] [\fB\-o\fP] [\fIoptname\fP ...] | |
7981 | Toggle the values of variables controlling optional shell behavior. | |
7982 | With no options, or with the | |
7983 | .B \-p | |
7984 | option, a list of all settable options is displayed, with | |
cce855bc JA |
7985 | an indication of whether or not each is set. |
7986 | The \fB\-p\fP option causes output to be displayed in a form that | |
7987 | may be reused as input. | |
7988 | Other options have the following meanings: | |
ccc6cda3 JA |
7989 | .RS |
7990 | .PD 0 | |
7991 | .TP | |
7992 | .B \-s | |
7993 | Enable (set) each \fIoptname\fP. | |
7994 | .TP | |
7995 | .B \-u | |
7996 | Disable (unset) each \fIoptname\fP. | |
7997 | .TP | |
7998 | .B \-q | |
7999 | Suppresses normal output (quiet mode); the return status indicates | |
8000 | whether the \fIoptname\fP is set or unset. | |
8001 | If multiple \fIoptname\fP arguments are given with | |
8002 | .BR \-q , | |
8003 | the return status is zero if all \fIoptnames\fP are enabled; non-zero | |
8004 | otherwise. | |
8005 | .TP | |
8006 | .B \-o | |
8007 | Restricts the values of \fIoptname\fP to be those defined for the | |
8008 | .B \-o | |
8009 | option to the | |
8010 | .B set | |
8011 | builtin. | |
8012 | .PD | |
8013 | .PP | |
8014 | If either | |
8015 | .B \-s | |
8016 | or | |
8017 | .B \-u | |
8018 | is used with no \fIoptname\fP arguments, the display is limited to | |
8019 | those options which are set or unset, respectively. | |
8020 | Unless otherwise noted, the \fBshopt\fP options are disabled (unset) | |
8021 | by default. | |
8022 | .PP | |
8023 | The return status when listing options is zero if all \fIoptnames\fP | |
8024 | are enabled, non-zero otherwise. When setting or unsetting options, | |
cce855bc | 8025 | the return status is zero unless an \fIoptname\fP is not a valid shell |
ccc6cda3 JA |
8026 | option. |
8027 | .PP | |
8028 | The list of \fBshopt\fP options is: | |
8029 | .if t .sp .5v | |
8030 | .if n .sp 1v | |
8031 | .PD 0 | |
8032 | .TP 8 | |
d3ad40de CR |
8033 | .B autocd |
8034 | If set, a command name that is the name of a directory is executed as if | |
8035 | it were the argument to the \fBcd\fP command. | |
8036 | This option is only used by interactive shells. | |
8037 | .TP 8 | |
ccc6cda3 JA |
8038 | .B cdable_vars |
8039 | If set, an argument to the | |
8040 | .B cd | |
8041 | builtin command that | |
8042 | is not a directory is assumed to be the name of a variable whose | |
8043 | value is the directory to change to. | |
8044 | .TP 8 | |
8045 | .B cdspell | |
8046 | If set, minor errors in the spelling of a directory component in a | |
8047 | .B cd | |
8048 | command will be corrected. | |
8049 | The errors checked for are transposed characters, | |
8050 | a missing character, and one character too many. | |
8051 | If a correction is found, the corrected file name is printed, | |
8052 | and the command proceeds. | |
d166f048 | 8053 | This option is only used by interactive shells. |
ccc6cda3 JA |
8054 | .TP 8 |
8055 | .B checkhash | |
8056 | If set, \fBbash\fP checks that a command found in the hash | |
8057 | table exists before trying to execute it. If a hashed command no | |
8058 | longer exists, a normal path search is performed. | |
8059 | .TP 8 | |
d3ad40de CR |
8060 | .B checkjobs |
8061 | If set, bash lists the status of any stopped and running jobs before | |
8062 | exiting an interactive shell. If any jobs are running, this causes | |
8063 | the exit to be deferred until a second exit is attempted without an | |
8064 | intervening command (see \fBJOB CONTROL\fP above). The shell always | |
8065 | postpones exiting if any jobs are stopped. | |
8066 | .TP 8 | |
ccc6cda3 JA |
8067 | .B checkwinsize |
8068 | If set, \fBbash\fP checks the window size after each command | |
8069 | and, if necessary, updates the values of | |
8070 | .SM | |
8071 | .B LINES | |
8072 | and | |
8073 | .SM | |
8074 | .BR COLUMNS . | |
8075 | .TP 8 | |
8076 | .B cmdhist | |
8077 | If set, | |
8078 | .B bash | |
8079 | attempts to save all lines of a multiple-line | |
8080 | command in the same history entry. This allows | |
8081 | easy re-editing of multi-line commands. | |
8082 | .TP 8 | |
8083 | .B dotglob | |
8084 | If set, | |
8085 | .B bash | |
8086 | includes filenames beginning with a `.' in the results of pathname | |
8087 | expansion. | |
8088 | .TP 8 | |
8089 | .B execfail | |
8090 | If set, a non-interactive shell will not exit if | |
8091 | it cannot execute the file specified as an argument to the | |
8092 | .B exec | |
8093 | builtin command. An interactive shell does not exit if | |
8094 | .B exec | |
8095 | fails. | |
8096 | .TP 8 | |
8097 | .B expand_aliases | |
8098 | If set, aliases are expanded as described above under | |
8099 | .SM | |
8100 | .BR ALIASES . | |
8101 | This option is enabled by default for interactive shells. | |
8102 | .TP 8 | |
d3a24ed2 CR |
8103 | .B extdebug |
8104 | If set, behavior intended for use by debuggers is enabled: | |
8105 | .RS | |
8106 | .TP | |
8107 | .B 1. | |
8108 | The \fB\-F\fP option to the \fBdeclare\fP builtin displays the source | |
8109 | file name and line number corresponding to each function name supplied | |
8110 | as an argument. | |
8111 | .TP | |
8112 | .B 2. | |
8113 | If the command run by the \fBDEBUG\fP trap returns a non-zero value, the | |
8114 | next command is skipped and not executed. | |
8115 | .TP | |
8116 | .B 3. | |
8117 | If the command run by the \fBDEBUG\fP trap returns a value of 2, and the | |
8118 | shell is executing in a subroutine (a shell function or a shell script | |
8119 | executed by the \fB.\fP or \fBsource\fP builtins), a call to | |
8120 | \fBreturn\fP is simulated. | |
2206f89a CR |
8121 | .TP |
8122 | .B 4. | |
8123 | \fBBASH_ARGC\fP and \fBBASH_ARGV\fP are updated as described in their | |
8124 | descriptions above. | |
8125 | .TP | |
8126 | .B 5. | |
8127 | Function tracing is enabled: command substitution, shell functions, and | |
8128 | subshells invoked with \fB(\fP \fIcommand\fP \fB)\fP inherit the | |
8129 | \fBDEBUG\fP and \fBRETURN\fP traps. | |
8130 | .TP | |
8131 | .B 6. | |
8132 | Error tracing is enabled: command substitution, shell functions, and | |
8133 | subshells invoked with \fB(\fP \fIcommand\fP \fB)\fP inherit the | |
8134 | \fBERROR\fP trap. | |
d3a24ed2 CR |
8135 | .RE |
8136 | .TP 8 | |
cce855bc JA |
8137 | .B extglob |
8138 | If set, the extended pattern matching features described above under | |
8139 | \fBPathname Expansion\fP are enabled. | |
8140 | .TP 8 | |
d3a24ed2 | 8141 | .B extquote |
20587658 | 8142 | If set, \fB$\fP\(aq\fIstring\fP\(aq and \fB$\fP"\fIstring\fP" quoting is |
d3a24ed2 CR |
8143 | performed within \fB${\fP\fIparameter\fP\fB}\fP expansions |
8144 | enclosed in double quotes. This option is enabled by default. | |
8145 | .TP 8 | |
8146 | .B failglob | |
8147 | If set, patterns which fail to match filenames during pathname expansion | |
8148 | result in an expansion error. | |
8149 | .TP 8 | |
8150 | .B force_fignore | |
8151 | If set, the suffixes specified by the \fBFIGNORE\fP shell variable | |
8152 | cause words to be ignored when performing word completion even if | |
8153 | the ignored words are the only possible completions. | |
8154 | See | |
8155 | .SM | |
8156 | \fBSHELL VARIABLES\fP | |
8157 | above for a description of \fBFIGNORE\fP. | |
8158 | This option is enabled by default. | |
8159 | .TP 8 | |
8160 | .B gnu_errfmt | |
8161 | If set, shell error messages are written in the standard GNU error | |
8162 | message format. | |
8163 | .TP 8 | |
ccc6cda3 JA |
8164 | .B histappend |
8165 | If set, the history list is appended to the file named by the value | |
8166 | of the | |
8167 | .B HISTFILE | |
8168 | variable when the shell exits, rather than overwriting the file. | |
8169 | .TP 8 | |
8170 | .B histreedit | |
8171 | If set, and | |
8172 | .B readline | |
8173 | is being used, a user is given the opportunity to re-edit a | |
8174 | failed history substitution. | |
8175 | .TP 8 | |
8176 | .B histverify | |
8177 | If set, and | |
8178 | .B readline | |
8179 | is being used, the results of history substitution are not immediately | |
8180 | passed to the shell parser. Instead, the resulting line is loaded into | |
8181 | the \fBreadline\fP editing buffer, allowing further modification. | |
8182 | .TP 8 | |
8183 | .B hostcomplete | |
8184 | If set, and | |
8185 | .B readline | |
cce855bc JA |
8186 | is being used, \fBbash\fP will attempt to perform hostname completion when a |
8187 | word containing a \fB@\fP is being completed (see | |
ccc6cda3 JA |
8188 | .B Completing |
8189 | under | |
8190 | .SM | |
8191 | .B READLINE | |
8192 | above). | |
8193 | This is enabled by default. | |
8194 | .TP 8 | |
cce855bc JA |
8195 | .B huponexit |
8196 | If set, \fBbash\fP will send | |
8197 | .SM | |
8198 | .B SIGHUP | |
8199 | to all jobs when an interactive login shell exits. | |
8200 | .TP 8 | |
ccc6cda3 JA |
8201 | .B interactive_comments |
8202 | If set, allow a word beginning with | |
8203 | .B # | |
8204 | to cause that word and all remaining characters on that | |
8205 | line to be ignored in an interactive shell (see | |
8206 | .SM | |
8207 | .B COMMENTS | |
8208 | above). This option is enabled by default. | |
8209 | .TP 8 | |
8210 | .B lithist | |
8211 | If set, and the | |
8212 | .B cmdhist | |
8213 | option is enabled, multi-line commands are saved to the history with | |
8214 | embedded newlines rather than using semicolon separators where possible. | |
8215 | .TP 8 | |
f73dda09 JA |
8216 | .B login_shell |
8217 | The shell sets this option if it is started as a login shell (see | |
8218 | .SM | |
8219 | .B "INVOCATION" | |
8220 | above). | |
8221 | The value may not be changed. | |
8222 | .TP 8 | |
ccc6cda3 JA |
8223 | .B mailwarn |
8224 | If set, and a file that \fBbash\fP is checking for mail has been | |
8225 | accessed since the last time it was checked, the message ``The mail in | |
8226 | \fImailfile\fP has been read'' is displayed. | |
8227 | .TP 8 | |
bb70624e JA |
8228 | .B no_empty_cmd_completion |
8229 | If set, and | |
8230 | .B readline | |
8231 | is being used, | |
8232 | .B bash | |
8233 | will not attempt to search the \fBPATH\fP for possible completions when | |
8234 | completion is attempted on an empty line. | |
8235 | .TP 8 | |
cce855bc JA |
8236 | .B nocaseglob |
8237 | If set, | |
8238 | .B bash | |
8239 | matches filenames in a case\-insensitive fashion when performing pathname | |
8240 | expansion (see | |
8241 | .B Pathname Expansion | |
8242 | above). | |
8243 | .TP 8 | |
2206f89a CR |
8244 | .B nocasematch |
8245 | If set, | |
8246 | .B bash | |
8247 | matches patterns in a case\-insensitive fashion when performing matching | |
8248 | while executing \fBcase\fP or \fB[[\fP conditional commands. | |
8249 | .TP 8 | |
ccc6cda3 JA |
8250 | .B nullglob |
8251 | If set, | |
8252 | .B bash | |
8253 | allows patterns which match no | |
8254 | files (see | |
8255 | .B Pathname Expansion | |
8256 | above) | |
8257 | to expand to a null string, rather than themselves. | |
8258 | .TP 8 | |
bb70624e JA |
8259 | .B progcomp |
8260 | If set, the programmable completion facilities (see | |
8261 | \fBProgrammable Completion\fP above) are enabled. | |
8262 | This option is enabled by default. | |
8263 | .TP 8 | |
ccc6cda3 | 8264 | .B promptvars |
d3a24ed2 CR |
8265 | If set, prompt strings undergo |
8266 | parameter expansion, command substitution, arithmetic | |
8267 | expansion, and quote removal after being expanded as described in | |
ccc6cda3 JA |
8268 | .SM |
8269 | .B PROMPTING | |
8270 | above. This option is enabled by default. | |
8271 | .TP 8 | |
b72432fd JA |
8272 | .B restricted_shell |
8273 | The shell sets this option if it is started in restricted mode (see | |
8274 | .SM | |
8275 | .B "RESTRICTED SHELL" | |
8276 | below). | |
8277 | The value may not be changed. | |
8278 | This is not reset when the startup files are executed, allowing | |
8279 | the startup files to discover whether or not a shell is restricted. | |
8280 | .TP 8 | |
ccc6cda3 JA |
8281 | .B shift_verbose |
8282 | If set, the | |
8283 | .B shift | |
8284 | builtin prints an error message when the shift count exceeds the | |
8285 | number of positional parameters. | |
8286 | .TP 8 | |
8287 | .B sourcepath | |
8288 | If set, the | |
8289 | \fBsource\fP (\fB.\fP) builtin uses the value of | |
8290 | .SM | |
8291 | .B PATH | |
8292 | to find the directory containing the file supplied as an argument. | |
cce855bc | 8293 | This option is enabled by default. |
bb70624e JA |
8294 | .TP 8 |
8295 | .B xpg_echo | |
8296 | If set, the \fBecho\fP builtin expands backslash-escape sequences | |
8297 | by default. | |
ccc6cda3 | 8298 | .RE |
726f6388 JA |
8299 | .TP |
8300 | \fBsuspend\fP [\fB\-f\fP] | |
8301 | Suspend the execution of this shell until it receives a | |
8302 | .SM | |
8303 | .B SIGCONT | |
8304 | signal. The | |
8305 | .B \-f | |
8306 | option says not to complain if this is | |
8307 | a login shell; just suspend anyway. The return status is 0 unless | |
8308 | the shell is a login shell and | |
8309 | .B \-f | |
8310 | is not supplied, or if job control is not enabled. | |
8311 | .TP | |
726f6388 | 8312 | \fBtest\fP \fIexpr\fP |
7117c2d2 | 8313 | .PD 0 |
726f6388 JA |
8314 | .TP |
8315 | \fB[\fP \fIexpr\fP \fB]\fP | |
ccc6cda3 | 8316 | Return a status of 0 or 1 depending on |
726f6388 JA |
8317 | the evaluation of the conditional expression |
8318 | .IR expr . | |
cce855bc JA |
8319 | Each operator and operand must be a separate argument. |
8320 | Expressions are composed of the primaries described above under | |
8321 | .SM | |
8322 | .BR "CONDITIONAL EXPRESSIONS" . | |
3ffb039a CR |
8323 | \fBtest\fP does not accept any options, nor does it accept and ignore |
8324 | an argument of \fB\-\-\fP as signifying the end of options. | |
cce855bc JA |
8325 | .if t .sp 0.5 |
8326 | .if n .sp 1 | |
8327 | Expressions may be combined using the following operators, listed | |
8328 | in decreasing order of precedence. | |
641d8f00 | 8329 | The evaluation depends on the number of arguments; see below. |
726f6388 JA |
8330 | .RS |
8331 | .PD 0 | |
8332 | .TP | |
726f6388 JA |
8333 | .B ! \fIexpr\fP |
8334 | True if | |
8335 | .I expr | |
8336 | is false. | |
8337 | .TP | |
cce855bc JA |
8338 | .B ( \fIexpr\fP ) |
8339 | Returns the value of \fIexpr\fP. | |
8340 | This may be used to override the normal precedence of operators. | |
8341 | .TP | |
726f6388 JA |
8342 | \fIexpr1\fP \-\fBa\fP \fIexpr2\fP |
8343 | True if both | |
8344 | .I expr1 | |
cce855bc | 8345 | and |
726f6388 JA |
8346 | .I expr2 |
8347 | are true. | |
8348 | .TP | |
8349 | \fIexpr1\fP \-\fBo\fP \fIexpr2\fP | |
8350 | True if either | |
8351 | .I expr1 | |
cce855bc | 8352 | or |
726f6388 JA |
8353 | .I expr2 |
8354 | is true. | |
cce855bc JA |
8355 | .PD |
8356 | .PP | |
8357 | \fBtest\fP and \fB[\fP evaluate conditional | |
8358 | expressions using a set of rules based on the number of arguments. | |
8359 | .if t .sp 0.5 | |
8360 | .if n .sp 1 | |
8361 | .PD 0 | |
726f6388 | 8362 | .TP |
cce855bc JA |
8363 | 0 arguments |
8364 | The expression is false. | |
8365 | .TP | |
8366 | 1 argument | |
8367 | The expression is true if and only if the argument is not null. | |
8368 | .TP | |
8369 | 2 arguments | |
8370 | If the first argument is \fB!\fP, the expression is true if and | |
8371 | only if the second argument is null. | |
8372 | If the first argument is one of the unary conditional operators listed above | |
8373 | under | |
726f6388 | 8374 | .SM |
cce855bc JA |
8375 | .BR "CONDITIONAL EXPRESSIONS" , |
8376 | the expression is true if the unary test is true. | |
8377 | If the first argument is not a valid unary conditional operator, the expression | |
8378 | is false. | |
8379 | .TP | |
8380 | 3 arguments | |
8381 | If the second argument is one of the binary conditional operators listed above | |
8382 | under | |
8383 | .SM | |
8384 | .BR "CONDITIONAL EXPRESSIONS" , | |
8385 | the result of the expression is the result of the binary test using | |
8386 | the first and third arguments as operands. | |
641d8f00 CR |
8387 | The \fB\-a\fP and \fB\-o\fP operators are considered binary operators |
8388 | when there are three arguments. | |
cce855bc JA |
8389 | If the first argument is \fB!\fP, the value is the negation of |
8390 | the two-argument test using the second and third arguments. | |
8391 | If the first argument is exactly \fB(\fP and the third argument is | |
8392 | exactly \fB)\fP, the result is the one-argument test of the second | |
8393 | argument. | |
8394 | Otherwise, the expression is false. | |
cce855bc JA |
8395 | .TP |
8396 | 4 arguments | |
8397 | If the first argument is \fB!\fP, the result is the negation of | |
8398 | the three-argument expression composed of the remaining arguments. | |
8399 | Otherwise, the expression is parsed and evaluated according to | |
8400 | precedence using the rules listed above. | |
8401 | .TP | |
8402 | 5 or more arguments | |
8403 | The expression is parsed and evaluated according to precedence | |
8404 | using the rules listed above. | |
726f6388 | 8405 | .RE |
cce855bc | 8406 | .PD |
726f6388 JA |
8407 | .TP |
8408 | .B times | |
8409 | Print the accumulated user and system times for the shell and | |
8410 | for processes run from the shell. The return status is 0. | |
8411 | .TP | |
61deeb13 | 8412 | \fBtrap\fP [\fB\-lp\fP] [[\fIarg\fP] \fIsigspec\fP ...] |
726f6388 JA |
8413 | The command |
8414 | .I arg | |
8415 | is to be read and executed when the shell receives | |
8416 | signal(s) | |
8417 | .IR sigspec . | |
8418 | If | |
8419 | .I arg | |
61deeb13 | 8420 | is absent (and there is a single \fIsigspec\fP) or |
726f6388 | 8421 | .BR \- , |
61deeb13 CR |
8422 | each specified signal is |
8423 | reset to its original disposition (the value it had | |
d166f048 JA |
8424 | upon entrance to the shell). |
8425 | If | |
726f6388 | 8426 | .I arg |
d166f048 JA |
8427 | is the null string the signal specified by each |
8428 | .I sigspec | |
8429 | is ignored by the shell and by the commands it invokes. | |
ccc6cda3 JA |
8430 | If |
8431 | .I arg | |
bb70624e | 8432 | is not present and |
ccc6cda3 | 8433 | .B \-p |
bb70624e | 8434 | has been supplied, then the trap commands associated with each |
ccc6cda3 | 8435 | .I sigspec |
bb70624e JA |
8436 | are displayed. |
8437 | If no arguments are supplied or if only | |
ccc6cda3 JA |
8438 | .B \-p |
8439 | is given, | |
8440 | .B trap | |
61deeb13 | 8441 | prints the list of commands associated with each signal. |
d3a24ed2 CR |
8442 | The |
8443 | .B \-l | |
8444 | option causes the shell to print a list of signal names and | |
8445 | their corresponding numbers. | |
d166f048 | 8446 | Each |
726f6388 JA |
8447 | .I sigspec |
8448 | is either | |
d166f048 | 8449 | a signal name defined in <\fIsignal.h\fP>, or a signal number. |
61deeb13 | 8450 | Signal names are case insensitive and the SIG prefix is optional. |
d166f048 | 8451 | If a |
726f6388 JA |
8452 | .I sigspec |
8453 | is | |
8454 | .SM | |
8455 | .B EXIT | |
8456 | (0) the command | |
8457 | .I arg | |
f73dda09 JA |
8458 | is executed on exit from the shell. |
8459 | If a | |
ccc6cda3 JA |
8460 | .I sigspec |
8461 | is | |
8462 | .SM | |
8463 | .BR DEBUG , | |
8464 | the command | |
8465 | .I arg | |
d3a24ed2 CR |
8466 | is executed before every \fIsimple command\fP, \fIfor\fP command, |
8467 | \fIcase\fP command, \fIselect\fP command, every arithmetic \fIfor\fP | |
8468 | command, and before the first command executes in a shell function (see | |
ccc6cda3 JA |
8469 | .SM |
8470 | .B SHELL GRAMMAR | |
8471 | above). | |
40b074c6 | 8472 | Refer to the description of the \fBextdebug\fP option to the |
d3a24ed2 | 8473 | \fBshopt\fP builtin for details of its effect on the \fBDEBUG\fP trap. |
f73dda09 JA |
8474 | If a |
8475 | .I sigspec | |
8476 | is | |
8477 | .SM | |
8478 | .BR ERR , | |
8479 | the command | |
8480 | .I arg | |
5e13499c CR |
8481 | is executed whenever a simple command has a non\-zero exit status, |
8482 | subject to the following conditions. | |
f73dda09 JA |
8483 | The |
8484 | .SM | |
d3a24ed2 CR |
8485 | .B ERR |
8486 | trap is not executed if the failed | |
8487 | command is part of the command list immediately following a | |
8488 | .B while | |
f73dda09 | 8489 | or |
d3a24ed2 CR |
8490 | .B until |
8491 | keyword, | |
8492 | part of the test in an | |
f73dda09 JA |
8493 | .I if |
8494 | statement, part of a | |
8495 | .B && | |
8496 | or | |
8497 | .B \(bv\(bv | |
8498 | list, or if the command's return value is | |
8499 | being inverted via | |
8500 | .BR ! . | |
5e13499c | 8501 | These are the same conditions obeyed by the \fBerrexit\fP option. |
d3a24ed2 CR |
8502 | If a |
8503 | .I sigspec | |
8504 | is | |
8505 | .SM | |
8506 | .BR RETURN , | |
8507 | the command | |
8508 | .I arg | |
8509 | is executed each time a shell function or a script executed with the | |
8510 | \fB.\fP or \fBsource\fP builtins finishes executing. | |
726f6388 | 8511 | Signals ignored upon entry to the shell cannot be trapped or reset. |
d3ad40de CR |
8512 | Trapped signals that are not being ignored are reset to their original |
8513 | values in a child process when it is created. | |
d166f048 | 8514 | The return status is false if any |
ccc6cda3 JA |
8515 | .I sigspec |
8516 | is invalid; otherwise | |
726f6388 JA |
8517 | .B trap |
8518 | returns true. | |
8519 | .TP | |
7117c2d2 | 8520 | \fBtype\fP [\fB\-aftpP\fP] \fIname\fP [\fIname\fP ...] |
726f6388 JA |
8521 | With no options, |
8522 | indicate how each | |
8523 | .I name | |
8524 | would be interpreted if used as a command name. | |
8525 | If the | |
cce855bc JA |
8526 | .B \-t |
8527 | option is used, | |
726f6388 | 8528 | .B type |
ccc6cda3 | 8529 | prints a string which is one of |
726f6388 JA |
8530 | .IR alias , |
8531 | .IR keyword , | |
8532 | .IR function , | |
8533 | .IR builtin , | |
8534 | or | |
8535 | .I file | |
8536 | if | |
8537 | .I name | |
8538 | is an alias, shell reserved word, function, builtin, or disk file, | |
ccc6cda3 JA |
8539 | respectively. |
8540 | If the | |
8541 | .I name | |
8542 | is not found, then nothing is printed, and an exit status of false | |
8543 | is returned. | |
726f6388 | 8544 | If the |
cce855bc JA |
8545 | .B \-p |
8546 | option is used, | |
726f6388 JA |
8547 | .B type |
8548 | either returns the name of the disk file | |
8549 | that would be executed if | |
8550 | .I name | |
8551 | were specified as a command name, | |
28ef6c31 JA |
8552 | or nothing if |
8553 | .if t \f(CWtype -t name\fP | |
8554 | .if n ``type -t name'' | |
726f6388 JA |
8555 | would not return |
8556 | .IR file . | |
7117c2d2 JA |
8557 | The |
8558 | .B \-P | |
8559 | option forces a | |
8560 | .SM | |
8561 | .B PATH | |
8562 | search for each \fIname\fP, even if | |
8563 | .if t \f(CWtype -t name\fP | |
8564 | .if n ``type -t name'' | |
8565 | would not return | |
8566 | .IR file . | |
726f6388 | 8567 | If a command is hashed, |
cce855bc | 8568 | .B \-p |
7117c2d2 JA |
8569 | and |
8570 | .B \-P | |
8571 | print the hashed value, not necessarily the file that appears | |
726f6388 JA |
8572 | first in |
8573 | .SM | |
8574 | .BR PATH . | |
8575 | If the | |
cce855bc JA |
8576 | .B \-a |
8577 | option is used, | |
726f6388 JA |
8578 | .B type |
8579 | prints all of the places that contain | |
8580 | an executable named | |
8581 | .IR name . | |
8582 | This includes aliases and functions, | |
8583 | if and only if the | |
cce855bc JA |
8584 | .B \-p |
8585 | option is not also used. | |
726f6388 JA |
8586 | The table of hashed commands is not consulted |
8587 | when using | |
cce855bc | 8588 | .BR \-a . |
7117c2d2 JA |
8589 | The |
8590 | .B \-f | |
8591 | option suppresses shell function lookup, as with the \fBcommand\fP builtin. | |
726f6388 JA |
8592 | .B type |
8593 | returns true if any of the arguments are found, false if | |
8594 | none are found. | |
8595 | .TP | |
dc8fbaf9 | 8596 | \fBulimit\fP [\fB\-SHacdefilmnpqrstuvx\fP [\fIlimit\fP]] |
ccc6cda3 | 8597 | Provides control over the resources available to the shell and to |
f73dda09 | 8598 | processes started by it, on systems that allow such control. |
ccc6cda3 | 8599 | The \fB\-H\fP and \fB\-S\fP options specify that the hard or soft limit is |
79e6c7dc CR |
8600 | set for the given resource. |
8601 | A hard limit cannot be increased by a non-root user once it is set; | |
8602 | a soft limit may be increased up to the value of the hard limit. | |
ccc6cda3 JA |
8603 | If neither \fB\-H\fP nor \fB\-S\fP is specified, both the soft and hard |
8604 | limits are set. | |
f73dda09 JA |
8605 | The value of |
8606 | .I limit | |
8607 | can be a number in the unit specified for the resource | |
8608 | or one of the special values | |
8609 | .BR hard , | |
8610 | .BR soft , | |
8611 | or | |
8612 | .BR unlimited , | |
8613 | which stand for the current hard limit, the current soft limit, and | |
8614 | no limit, respectively. | |
ccc6cda3 | 8615 | If |
726f6388 JA |
8616 | .I limit |
8617 | is omitted, the current value of the soft limit of the resource is | |
ccc6cda3 JA |
8618 | printed, unless the \fB\-H\fP option is given. When more than one |
8619 | resource is specified, the limit name and unit are printed before the value. | |
726f6388 JA |
8620 | Other options are interpreted as follows: |
8621 | .RS | |
8622 | .PD 0 | |
8623 | .TP | |
8624 | .B \-a | |
ccc6cda3 | 8625 | All current limits are reported |
726f6388 JA |
8626 | .TP |
8627 | .B \-c | |
ccc6cda3 | 8628 | The maximum size of core files created |
726f6388 JA |
8629 | .TP |
8630 | .B \-d | |
ccc6cda3 | 8631 | The maximum size of a process's data segment |
726f6388 | 8632 | .TP |
dc8fbaf9 CR |
8633 | .B \-e |
8634 | The maximum scheduling priority ("nice") | |
8635 | .TP | |
726f6388 | 8636 | .B \-f |
d3ad40de | 8637 | The maximum size of files written by the shell and its children |
726f6388 | 8638 | .TP |
af12dacd CR |
8639 | .B \-i |
8640 | The maximum number of pending signals | |
8641 | .TP | |
ccc6cda3 JA |
8642 | .B \-l |
8643 | The maximum size that may be locked into memory | |
726f6388 | 8644 | .TP |
ccc6cda3 JA |
8645 | .B \-m |
8646 | The maximum resident set size | |
726f6388 | 8647 | .TP |
ccc6cda3 JA |
8648 | .B \-n |
8649 | The maximum number of open file descriptors (most systems do not | |
8650 | allow this value to be set) | |
726f6388 JA |
8651 | .TP |
8652 | .B \-p | |
ccc6cda3 | 8653 | The pipe size in 512-byte blocks (this may not be set) |
726f6388 | 8654 | .TP |
af12dacd CR |
8655 | .B \-q |
8656 | The maximum number of bytes in POSIX message queues | |
8657 | .TP | |
dc8fbaf9 CR |
8658 | .B \-r |
8659 | The maximum real-time scheduling priority | |
8660 | .TP | |
ccc6cda3 JA |
8661 | .B \-s |
8662 | The maximum stack size | |
8663 | .TP | |
8664 | .B \-t | |
8665 | The maximum amount of cpu time in seconds | |
726f6388 JA |
8666 | .TP |
8667 | .B \-u | |
ccc6cda3 | 8668 | The maximum number of processes available to a single user |
726f6388 JA |
8669 | .TP |
8670 | .B \-v | |
8671 | The maximum amount of virtual memory available to the shell | |
af12dacd CR |
8672 | .TP |
8673 | .B \-x | |
8674 | The maximum number of file locks | |
726f6388 JA |
8675 | .PD |
8676 | .PP | |
ccc6cda3 | 8677 | If |
726f6388 JA |
8678 | .I limit |
8679 | is given, it is the new value of the specified resource (the | |
8680 | .B \-a | |
8681 | option is display only). | |
8682 | If no option is given, then | |
8683 | .B \-f | |
8684 | is assumed. Values are in 1024-byte increments, except for | |
8685 | .BR \-t , | |
8686 | which is in seconds, | |
8687 | .BR \-p , | |
8688 | which is in units of 512-byte blocks, | |
8689 | and | |
8690 | .B \-n | |
8691 | and | |
8692 | .BR \-u , | |
f73dda09 JA |
8693 | which are unscaled values. |
8694 | The return status is 0 unless an invalid option or argument is supplied, | |
8695 | or an error occurs while setting a new limit. | |
726f6388 JA |
8696 | .RE |
8697 | .TP | |
cce855bc | 8698 | \fBumask\fP [\fB\-p\fP] [\fB\-S\fP] [\fImode\fP] |
726f6388 JA |
8699 | The user file-creation mask is set to |
8700 | .IR mode . | |
8701 | If | |
8702 | .I mode | |
8703 | begins with a digit, it | |
8704 | is interpreted as an octal number; otherwise | |
8705 | it is interpreted as a symbolic mode mask similar | |
8706 | to that accepted by | |
8707 | .IR chmod (1). | |
8708 | If | |
8709 | .I mode | |
bb70624e | 8710 | is omitted, the current value of the mask is printed. |
ccc6cda3 | 8711 | The |
726f6388 JA |
8712 | .B \-S |
8713 | option causes the mask to be printed in symbolic form; the | |
8714 | default output is an octal number. | |
cce855bc JA |
8715 | If the |
8716 | .B \-p | |
8717 | option is supplied, and | |
8718 | .I mode | |
8719 | is omitted, the output is in a form that may be reused as input. | |
ccc6cda3 | 8720 | The return status is 0 if the mode was successfully changed or if |
726f6388 JA |
8721 | no \fImode\fP argument was supplied, and false otherwise. |
8722 | .TP | |
8723 | \fBunalias\fP [\-\fBa\fP] [\fIname\fP ...] | |
bb70624e | 8724 | Remove each \fIname\fP from the list of defined aliases. If |
726f6388 JA |
8725 | .B \-a |
8726 | is supplied, all alias definitions are removed. The return | |
8727 | value is true unless a supplied | |
8728 | .I name | |
8729 | is not a defined alias. | |
8730 | .TP | |
8731 | \fBunset\fP [\-\fBfv\fP] [\fIname\fP ...] | |
8732 | For each | |
8733 | .IR name , | |
ccc6cda3 JA |
8734 | remove the corresponding variable or function. |
8735 | If no options are supplied, or the | |
8736 | .B \-v | |
8737 | option is given, each | |
8738 | .I name | |
8739 | refers to a shell variable. | |
8740 | Read-only variables may not be unset. | |
8741 | If | |
726f6388 | 8742 | .B \-f |
f75912ae | 8743 | is specified, each |
ccc6cda3 JA |
8744 | .I name |
8745 | refers to a shell function, and the function definition | |
8746 | is removed. | |
8747 | Each unset variable or function is removed from the environment | |
8748 | passed to subsequent commands. | |
8749 | If any of | |
726f6388 JA |
8750 | .SM |
8751 | .BR RANDOM , | |
8752 | .SM | |
8753 | .BR SECONDS , | |
8754 | .SM | |
8755 | .BR LINENO , | |
ccc6cda3 JA |
8756 | .SM |
8757 | .BR HISTCMD , | |
bb70624e JA |
8758 | .SM |
8759 | .BR FUNCNAME , | |
8760 | .SM | |
8761 | .BR GROUPS , | |
726f6388 JA |
8762 | or |
8763 | .SM | |
ccc6cda3 | 8764 | .B DIRSTACK |
726f6388 JA |
8765 | are unset, they lose their special properties, even if they are |
8766 | subsequently reset. The exit status is true unless a | |
8767 | .I name | |
d3a24ed2 | 8768 | is readonly. |
726f6388 | 8769 | .TP |
d90269dd CR |
8770 | \fBwait\fP [\fIn ...\fP] |
8771 | Wait for each specified process and return its termination status. | |
8772 | Each | |
726f6388 JA |
8773 | .I n |
8774 | may be a process | |
8775 | ID or a job specification; if a job spec is given, all processes | |
8776 | in that job's pipeline are waited for. If | |
8777 | .I n | |
8778 | is not given, all currently active child processes | |
8779 | are waited for, and the return status is zero. If | |
8780 | .I n | |
ccc6cda3 | 8781 | specifies a non-existent process or job, the return status is |
726f6388 JA |
8782 | 127. Otherwise, the return status is the exit status of the last |
8783 | process or job waited for. | |
8784 | .\" bash_builtins | |
8785 | .if \n(zZ=1 .ig zZ | |
ccc6cda3 | 8786 | .SH "RESTRICTED SHELL" |
bb70624e JA |
8787 | .\" rbash.1 |
8788 | .zY | |
726f6388 | 8789 | .PP |
ccc6cda3 | 8790 | If |
726f6388 | 8791 | .B bash |
ccc6cda3 JA |
8792 | is started with the name |
8793 | .BR rbash , | |
8794 | or the | |
8795 | .B \-r | |
8796 | option is supplied at invocation, | |
8797 | the shell becomes restricted. | |
8798 | A restricted shell is used to | |
8799 | set up an environment more controlled than the standard shell. | |
8800 | It behaves identically to | |
8801 | .B bash | |
cce855bc | 8802 | with the exception that the following are disallowed or not performed: |
ccc6cda3 JA |
8803 | .IP \(bu |
8804 | changing directories with \fBcd\fP | |
8805 | .IP \(bu | |
8806 | setting or unsetting the values of | |
b72432fd JA |
8807 | .BR SHELL , |
8808 | .BR PATH , | |
8809 | .BR ENV , | |
ccc6cda3 | 8810 | or |
b72432fd | 8811 | .B BASH_ENV |
ccc6cda3 JA |
8812 | .IP \(bu |
8813 | specifying command names containing | |
8814 | .B / | |
8815 | .IP \(bu | |
8816 | specifying a file name containing a | |
8817 | .B / | |
8818 | as an argument to the | |
8819 | .B . | |
8820 | builtin command | |
8821 | .IP \(bu | |
bb70624e JA |
8822 | Specifying a filename containing a slash as an argument to the |
8823 | .B \-p | |
8824 | option to the | |
8825 | .B hash | |
8826 | builtin command | |
8827 | .IP \(bu | |
ccc6cda3 JA |
8828 | importing function definitions from the shell environment at startup |
8829 | .IP \(bu | |
cce855bc JA |
8830 | parsing the value of \fBSHELLOPTS\fP from the shell environment at startup |
8831 | .IP \(bu | |
ccc6cda3 JA |
8832 | redirecting output using the >, >|, <>, >&, &>, and >> redirection operators |
8833 | .IP \(bu | |
8834 | using the | |
8835 | .B exec | |
8836 | builtin command to replace the shell with another command | |
8837 | .IP \(bu | |
8838 | adding or deleting builtin commands with the | |
8839 | .B \-f | |
726f6388 | 8840 | and |
ccc6cda3 JA |
8841 | .B \-d |
8842 | options to the | |
8843 | .B enable | |
8844 | builtin command | |
8845 | .IP \(bu | |
7117c2d2 JA |
8846 | Using the \fBenable\fP builtin command to enable disabled shell builtins |
8847 | .IP \(bu | |
ccc6cda3 JA |
8848 | specifying the |
8849 | .B \-p | |
8850 | option to the | |
8851 | .B command | |
8852 | builtin command | |
8853 | .IP \(bu | |
8854 | turning off restricted mode with | |
cce855bc | 8855 | \fBset +r\fP or \fBset +o restricted\fP. |
726f6388 | 8856 | .PP |
ccc6cda3 JA |
8857 | These restrictions are enforced after any startup files are read. |
8858 | .PP | |
61deeb13 CR |
8859 | .ie \n(zY=1 When a command that is found to be a shell script is executed, |
8860 | .el \{ When a command that is found to be a shell script is executed | |
8861 | (see | |
ccc6cda3 JA |
8862 | .SM |
8863 | .B "COMMAND EXECUTION" | |
8864 | above), | |
61deeb13 | 8865 | \} |
ccc6cda3 JA |
8866 | .B rbash |
8867 | turns off any restrictions in the shell spawned to execute the | |
8868 | script. | |
bb70624e JA |
8869 | .\" end of rbash.1 |
8870 | .if \n(zY=1 .ig zY | |
726f6388 JA |
8871 | .SH "SEE ALSO" |
8872 | .PD 0 | |
8873 | .TP | |
bb70624e | 8874 | \fIBash Reference Manual\fP, Brian Fox and Chet Ramey |
726f6388 JA |
8875 | .TP |
8876 | \fIThe Gnu Readline Library\fP, Brian Fox and Chet Ramey | |
8877 | .TP | |
8878 | \fIThe Gnu History Library\fP, Brian Fox and Chet Ramey | |
8879 | .TP | |
726f6388 JA |
8880 | \fIPortable Operating System Interface (POSIX) Part 2: Shell and Utilities\fP, IEEE |
8881 | .TP | |
8882 | \fIsh\fP(1), \fIksh\fP(1), \fIcsh\fP(1) | |
8883 | .TP | |
8884 | \fIemacs\fP(1), \fIvi\fP(1) | |
8885 | .TP | |
8886 | \fIreadline\fP(3) | |
8887 | .PD | |
8888 | .SH FILES | |
8889 | .PD 0 | |
8890 | .TP | |
8891 | .FN /bin/bash | |
8892 | The \fBbash\fP executable | |
8893 | .TP | |
8894 | .FN /etc/profile | |
8895 | The systemwide initialization file, executed for login shells | |
8896 | .TP | |
8897 | .FN ~/.bash_profile | |
8898 | The personal initialization file, executed for login shells | |
8899 | .TP | |
8900 | .FN ~/.bashrc | |
8901 | The individual per-interactive-shell startup file | |
8902 | .TP | |
b72432fd JA |
8903 | .FN ~/.bash_logout |
8904 | The individual login shell cleanup file, executed when a login shell exits | |
8905 | .TP | |
726f6388 JA |
8906 | .FN ~/.inputrc |
8907 | Individual \fIreadline\fP initialization file | |
8908 | .PD | |
8909 | .SH AUTHORS | |
ccc6cda3 | 8910 | Brian Fox, Free Software Foundation |
726f6388 | 8911 | .br |
bb70624e | 8912 | bfox@gnu.org |
726f6388 JA |
8913 | .PP |
8914 | Chet Ramey, Case Western Reserve University | |
8915 | .br | |
e225d5a9 | 8916 | chet@po.cwru.edu |
726f6388 JA |
8917 | .SH BUG REPORTS |
8918 | If you find a bug in | |
8919 | .B bash, | |
8920 | you should report it. But first, you should | |
8921 | make sure that it really is a bug, and that it appears in the latest | |
8922 | version of | |
d3a24ed2 CR |
8923 | .BR bash . |
8924 | The latest version is always available from | |
8925 | \fIftp://ftp.gnu.org/pub/bash/\fP. | |
726f6388 JA |
8926 | .PP |
8927 | Once you have determined that a bug actually exists, use the | |
8928 | .I bashbug | |
8929 | command to submit a bug report. | |
d166f048 | 8930 | If you have a fix, you are encouraged to mail that as well! |
726f6388 | 8931 | Suggestions and `philosophical' bug reports may be mailed |
cce855bc | 8932 | to \fIbug-bash@gnu.org\fP or posted to the Usenet |
726f6388 JA |
8933 | newsgroup |
8934 | .BR gnu.bash.bug . | |
8935 | .PP | |
8936 | ALL bug reports should include: | |
8937 | .PP | |
8938 | .PD 0 | |
8939 | .TP 20 | |
8940 | The version number of \fBbash\fR | |
8941 | .TP | |
8942 | The hardware and operating system | |
8943 | .TP | |
8944 | The compiler used to compile | |
8945 | .TP | |
8946 | A description of the bug behaviour | |
8947 | .TP | |
8948 | A short script or `recipe' which exercises the bug | |
8949 | .PD | |
8950 | .PP | |
8951 | .I bashbug | |
8952 | inserts the first three items automatically into the template | |
8953 | it provides for filing a bug report. | |
8954 | .PP | |
8955 | Comments and bug reports concerning | |
8956 | this manual page should be directed to | |
e225d5a9 | 8957 | .IR chet@po.cwru.edu . |
726f6388 JA |
8958 | .SH BUGS |
8959 | .PP | |
8960 | It's too big and too slow. | |
8961 | .PP | |
8962 | There are some subtle differences between | |
8963 | .B bash | |
8964 | and traditional versions of | |
8965 | .BR sh , | |
8966 | mostly because of the | |
8967 | .SM | |
8968 | .B POSIX | |
8969 | specification. | |
8970 | .PP | |
8971 | Aliases are confusing in some uses. | |
ccc6cda3 JA |
8972 | .PP |
8973 | Shell builtin commands and functions are not stoppable/restartable. | |
8974 | .PP | |
8975 | Compound commands and command sequences of the form `a ; b ; c' | |
8976 | are not handled gracefully when process suspension is attempted. | |
8977 | When a process is stopped, the shell immediately executes the next | |
8978 | command in the sequence. | |
8979 | It suffices to place the sequence of commands between | |
8980 | parentheses to force it into a subshell, which may be stopped as | |
8981 | a unit. | |
8982 | .PP | |
8983 | Commands inside of \fB$(\fP...\fB)\fP command substitution are not | |
8984 | parsed until substitution is attempted. This will delay error | |
704a1a2a CR |
8985 | reporting until some time after the command is entered. For example, |
8986 | unmatched parentheses, even inside shell comments, will result in | |
8987 | error messages while the construct is being read. | |
ccc6cda3 JA |
8988 | .PP |
8989 | Array variables may not (yet) be exported. | |
726f6388 | 8990 | .zZ |
bb70624e | 8991 | .zY |