]>
Commit | Line | Data |
---|---|---|
761783bf | 1 | This is bashref.info, produced by makeinfo version 4.7 from |
56299fa5 | 2 | /Users/chet/src/bash/src/doc/bashref.texi. |
e8ce775d | 3 | |
761783bf CR |
4 | This text is a brief description of the features that are present in |
5 | the Bash shell (version 3.0, 27 July 2004). | |
d3a24ed2 | 6 | |
761783bf CR |
7 | This is Edition 3.0, last updated 27 July 2004, of `The GNU Bash |
8 | Reference Manual', for `Bash', Version 3.0. | |
d3a24ed2 | 9 | |
9f422431 | 10 | Copyright (C) 1988-2004 Free Software Foundation, Inc. |
d3a24ed2 CR |
11 | |
12 | Permission is granted to make and distribute verbatim copies of this | |
13 | manual provided the copyright notice and this permission notice are | |
14 | preserved on all copies. | |
15 | ||
16 | Permission is granted to copy, distribute and/or modify this | |
17 | document under the terms of the GNU Free Documentation License, | |
18 | Version 1.1 or any later version published by the Free Software | |
19 | Foundation; with no Invariant Sections, with the Front-Cover texts | |
20 | being "A GNU Manual," and with the Back-Cover Texts as in (a) | |
21 | below. A copy of the license is included in the section entitled | |
22 | "GNU Free Documentation License." | |
23 | ||
24 | (a) The FSF's Back-Cover Text is: "You have freedom to copy and | |
25 | modify this GNU Manual, like GNU software. Copies published by | |
26 | the Free Software Foundation raise funds for GNU development." | |
761783bf | 27 | |
d3a24ed2 | 28 | INFO-DIR-SECTION Basics |
e8ce775d | 29 | START-INFO-DIR-ENTRY |
cce855bc | 30 | * Bash: (bash). The GNU Bourne-Again SHell. |
e8ce775d | 31 | END-INFO-DIR-ENTRY |
ccc6cda3 | 32 | |
ccc6cda3 JA |
33 | \1f |
34 | File: bashref.info, Node: Top, Next: Introduction, Prev: (dir), Up: (dir) | |
35 | ||
36 | Bash Features | |
37 | ************* | |
38 | ||
761783bf CR |
39 | This text is a brief description of the features that are present in |
40 | the Bash shell (version 3.0, 27 July 2004).. | |
ccc6cda3 | 41 | |
761783bf CR |
42 | This is Edition 3.0, last updated 27 July 2004, of `The GNU Bash |
43 | Reference Manual', for `Bash', Version 3.0. | |
ccc6cda3 JA |
44 | |
45 | Bash contains features that appear in other popular shells, and some | |
46 | features that only appear in Bash. Some of the shells that Bash has | |
47 | borrowed concepts from are the Bourne Shell (`sh'), the Korn Shell | |
48 | (`ksh'), and the C-shell (`csh' and its successor, `tcsh'). The | |
49 | following menu breaks the features up into categories based upon which | |
50 | one of these other shells inspired the feature. | |
51 | ||
52 | This manual is meant as a brief introduction to features found in | |
53 | Bash. The Bash manual page should be used as the definitive reference | |
54 | on shell behavior. | |
55 | ||
56 | * Menu: | |
57 | ||
58 | * Introduction:: An introduction to the shell. | |
59 | ||
60 | * Definitions:: Some definitions used in the rest of this | |
61 | manual. | |
62 | ||
63 | * Basic Shell Features:: The shell "building blocks". | |
64 | ||
bb70624e JA |
65 | * Shell Builtin Commands:: Commands that are a part of the shell. |
66 | ||
67 | * Shell Variables:: Variables used or set by Bash. | |
ccc6cda3 | 68 | |
ccc6cda3 JA |
69 | * Bash Features:: Features found only in Bash. |
70 | ||
71 | * Job Control:: A chapter describing what job control is | |
72 | and how Bash allows you to use it. | |
73 | ||
74 | * Using History Interactively:: Chapter dealing with history expansion | |
75 | rules. | |
76 | ||
77 | * Command Line Editing:: Chapter describing the command line | |
78 | editing features. | |
79 | ||
80 | * Installing Bash:: How to build and install Bash on your system. | |
81 | ||
82 | * Reporting Bugs:: How to report bugs in Bash. | |
83 | ||
bb70624e JA |
84 | * Major Differences From The Bourne Shell:: A terse list of the differences |
85 | between Bash and historical | |
86 | versions of /bin/sh. | |
87 | ||
d3a24ed2 CR |
88 | * Copying This Manual:: Copying this manual. |
89 | ||
ccc6cda3 JA |
90 | * Builtin Index:: Index of Bash builtin commands. |
91 | ||
92 | * Reserved Word Index:: Index of Bash reserved words. | |
93 | ||
94 | * Variable Index:: Quick reference helps you find the | |
95 | variable you want. | |
96 | ||
97 | * Function Index:: Index of bindable Readline functions. | |
98 | ||
99 | * Concept Index:: General index for concepts described in | |
100 | this manual. | |
101 | ||
102 | \1f | |
103 | File: bashref.info, Node: Introduction, Next: Definitions, Prev: Top, Up: Top | |
104 | ||
761783bf CR |
105 | 1 Introduction |
106 | ************** | |
ccc6cda3 JA |
107 | |
108 | * Menu: | |
109 | ||
110 | * What is Bash?:: A short description of Bash. | |
111 | ||
112 | * What is a shell?:: A brief introduction to shells. | |
113 | ||
114 | \1f | |
115 | File: bashref.info, Node: What is Bash?, Next: What is a shell?, Up: Introduction | |
116 | ||
761783bf CR |
117 | 1.1 What is Bash? |
118 | ================= | |
ccc6cda3 | 119 | |
761783bf | 120 | Bash is the shell, or command language interpreter, for the GNU |
bb70624e JA |
121 | operating system. The name is an acronym for the `Bourne-Again SHell', |
122 | a pun on Stephen Bourne, the author of the direct ancestor of the | |
d3a24ed2 CR |
123 | current Unix shell `sh', which appeared in the Seventh Edition Bell |
124 | Labs Research version of Unix. | |
ccc6cda3 | 125 | |
bb70624e JA |
126 | Bash is largely compatible with `sh' and incorporates useful |
127 | features from the Korn shell `ksh' and the C shell `csh'. It is | |
128 | intended to be a conformant implementation of the IEEE POSIX Shell and | |
129 | Tools specification (IEEE Working Group 1003.2). It offers functional | |
ccc6cda3 JA |
130 | improvements over `sh' for both interactive and programming use. |
131 | ||
bb70624e JA |
132 | While the GNU operating system provides other shells, including a |
133 | version of `csh', Bash is the default shell. Like other GNU software, | |
134 | Bash is quite portable. It currently runs on nearly every version of | |
135 | Unix and a few other operating systems - independently-supported ports | |
d3a24ed2 | 136 | exist for MS-DOS, OS/2, and Windows platforms. |
ccc6cda3 JA |
137 | |
138 | \1f | |
139 | File: bashref.info, Node: What is a shell?, Prev: What is Bash?, Up: Introduction | |
140 | ||
761783bf CR |
141 | 1.2 What is a shell? |
142 | ==================== | |
ccc6cda3 | 143 | |
761783bf | 144 | At its base, a shell is simply a macro processor that executes |
d3a24ed2 CR |
145 | commands. The term macro processor means functionality where text and |
146 | symbols are expanded to create larger expressions. | |
147 | ||
148 | A Unix shell is both a command interpreter and a programming | |
149 | language. As a command interpreter, the shell provides the user | |
150 | interface to the rich set of GNU utilities. The programming language | |
151 | features allow these utilitites to be combined. Files containing | |
cce855bc | 152 | commands can be created, and become commands themselves. These new |
bb70624e | 153 | commands have the same status as system commands in directories such as |
d3a24ed2 CR |
154 | `/bin', allowing users or groups to establish custom environments to |
155 | automate their common tasks. | |
156 | ||
157 | Shells may be used interactively or non-interactively. In | |
158 | interactive mode, they accept input typed from the keyboard. When | |
159 | executing non-interactively, shells execute commands read from a file. | |
ccc6cda3 | 160 | |
bb70624e | 161 | A shell allows execution of GNU commands, both synchronously and |
cce855bc JA |
162 | asynchronously. The shell waits for synchronous commands to complete |
163 | before accepting more input; asynchronous commands continue to execute | |
164 | in parallel with the shell while it reads and executes additional | |
165 | commands. The "redirection" constructs permit fine-grained control of | |
bb70624e | 166 | the input and output of those commands. Moreover, the shell allows |
d3a24ed2 | 167 | control over the contents of commands' environments. |
bb70624e JA |
168 | |
169 | Shells also provide a small set of built-in commands ("builtins") | |
170 | implementing functionality impossible or inconvenient to obtain via | |
171 | separate utilities. For example, `cd', `break', `continue', and | |
172 | `exec') cannot be implemented outside of the shell because they | |
173 | directly manipulate the shell itself. The `history', `getopts', | |
174 | `kill', or `pwd' builtins, among others, could be implemented in | |
175 | separate utilities, but they are more convenient to use as builtin | |
176 | commands. All of the shell builtins are described in subsequent | |
177 | sections. | |
ccc6cda3 JA |
178 | |
179 | While executing commands is essential, most of the power (and | |
180 | complexity) of shells is due to their embedded programming languages. | |
181 | Like any high-level language, the shell provides variables, flow | |
182 | control constructs, quoting, and functions. | |
183 | ||
bb70624e JA |
184 | Shells offer features geared specifically for interactive use rather |
185 | than to augment the programming language. These interactive features | |
d3a24ed2 CR |
186 | include job control, command line editing, command history and aliases. |
187 | Each of these features is described in this manual. | |
ccc6cda3 JA |
188 | |
189 | \1f | |
190 | File: bashref.info, Node: Definitions, Next: Basic Shell Features, Prev: Introduction, Up: Top | |
191 | ||
761783bf CR |
192 | 2 Definitions |
193 | ************* | |
ccc6cda3 | 194 | |
761783bf | 195 | These definitions are used throughout the remainder of this manual. |
ccc6cda3 JA |
196 | |
197 | `POSIX' | |
198 | A family of open system standards based on Unix. Bash is | |
199 | concerned with POSIX 1003.2, the Shell and Tools Standard. | |
200 | ||
201 | `blank' | |
202 | A space or tab character. | |
203 | ||
204 | `builtin' | |
205 | A command that is implemented internally by the shell itself, | |
206 | rather than by an executable program somewhere in the file system. | |
207 | ||
208 | `control operator' | |
209 | A `word' that performs a control function. It is a `newline' or | |
210 | one of the following: `||', `&&', `&', `;', `;;', `|', `(', or `)'. | |
211 | ||
212 | `exit status' | |
f73dda09 JA |
213 | The value returned by a command to its caller. The value is |
214 | restricted to eight bits, so the maximum value is 255. | |
ccc6cda3 JA |
215 | |
216 | `field' | |
217 | A unit of text that is the result of one of the shell expansions. | |
218 | After expansion, when executing a command, the resulting fields | |
219 | are used as the command name and arguments. | |
220 | ||
221 | `filename' | |
222 | A string of characters used to identify a file. | |
223 | ||
224 | `job' | |
225 | A set of processes comprising a pipeline, and any processes | |
226 | descended from it, that are all in the same process group. | |
227 | ||
228 | `job control' | |
d166f048 JA |
229 | A mechanism by which users can selectively stop (suspend) and |
230 | restart (resume) execution of processes. | |
ccc6cda3 JA |
231 | |
232 | `metacharacter' | |
233 | A character that, when unquoted, separates words. A metacharacter | |
234 | is a `blank' or one of the following characters: `|', `&', `;', | |
235 | `(', `)', `<', or `>'. | |
236 | ||
237 | `name' | |
238 | A `word' consisting solely of letters, numbers, and underscores, | |
239 | and beginning with a letter or underscore. `Name's are used as | |
240 | shell variable and function names. Also referred to as an | |
241 | `identifier'. | |
242 | ||
243 | `operator' | |
244 | A `control operator' or a `redirection operator'. *Note | |
245 | Redirections::, for a list of redirection operators. | |
246 | ||
247 | `process group' | |
248 | A collection of related processes each having the same process | |
249 | group ID. | |
250 | ||
251 | `process group ID' | |
252 | A unique identifer that represents a `process group' during its | |
253 | lifetime. | |
254 | ||
255 | `reserved word' | |
256 | A `word' that has a special meaning to the shell. Most reserved | |
257 | words introduce shell flow control constructs, such as `for' and | |
258 | `while'. | |
259 | ||
260 | `return status' | |
261 | A synonym for `exit status'. | |
262 | ||
263 | `signal' | |
bb70624e | 264 | A mechanism by which a process may be notified by the kernel of an |
ccc6cda3 JA |
265 | event occurring in the system. |
266 | ||
267 | `special builtin' | |
268 | A shell builtin command that has been classified as special by the | |
bb70624e | 269 | POSIX 1003.2 standard. |
ccc6cda3 JA |
270 | |
271 | `token' | |
272 | A sequence of characters considered a single unit by the shell. | |
273 | It is either a `word' or an `operator'. | |
274 | ||
275 | `word' | |
276 | A `token' that is not an `operator'. | |
277 | ||
278 | \1f | |
bb70624e | 279 | File: bashref.info, Node: Basic Shell Features, Next: Shell Builtin Commands, Prev: Definitions, Up: Top |
ccc6cda3 | 280 | |
761783bf CR |
281 | 3 Basic Shell Features |
282 | ********************** | |
ccc6cda3 | 283 | |
761783bf CR |
284 | Bash is an acronym for `Bourne-Again SHell'. The Bourne shell is the |
285 | traditional Unix shell originally written by Stephen Bourne. All of | |
286 | the Bourne shell builtin commands are available in Bash, The rules for | |
287 | evaluation and quoting are taken from the POSIX specification for the | |
288 | `standard' Unix shell. | |
ccc6cda3 | 289 | |
cce855bc | 290 | This chapter briefly summarizes the shell's `building blocks': |
ccc6cda3 JA |
291 | commands, control structures, shell functions, shell parameters, shell |
292 | expansions, redirections, which are a way to direct input and output | |
293 | from and to named files, and how the shell executes commands. | |
294 | ||
295 | * Menu: | |
296 | ||
297 | * Shell Syntax:: What your input means to the shell. | |
cce855bc | 298 | * Shell Commands:: The types of commands you can use. |
ccc6cda3 | 299 | * Shell Functions:: Grouping commands by name. |
d3a24ed2 CR |
300 | * Shell Parameters:: How the shell stores values. |
301 | * Shell Expansions:: How Bash expands parameters and the various | |
ccc6cda3 JA |
302 | expansions available. |
303 | * Redirections:: A way to control where input and output go. | |
304 | * Executing Commands:: What happens when you run a command. | |
305 | * Shell Scripts:: Executing files of shell commands. | |
306 | ||
307 | \1f | |
cce855bc | 308 | File: bashref.info, Node: Shell Syntax, Next: Shell Commands, Up: Basic Shell Features |
ccc6cda3 | 309 | |
761783bf CR |
310 | 3.1 Shell Syntax |
311 | ================ | |
ccc6cda3 JA |
312 | |
313 | * Menu: | |
314 | ||
315 | * Shell Operation:: The basic operation of the shell. | |
316 | ||
317 | * Quoting:: How to remove the special meaning from characters. | |
318 | ||
319 | * Comments:: How to specify comments. | |
320 | ||
bb70624e JA |
321 | When the shell reads input, it proceeds through a sequence of |
322 | operations. If the input indicates the beginning of a comment, the | |
323 | shell ignores the comment symbol (`#'), and the rest of that line. | |
324 | ||
325 | Otherwise, roughly speaking, the shell reads its input and divides | |
326 | the input into words and operators, employing the quoting rules to | |
327 | select which meanings to assign various words and characters. | |
328 | ||
329 | The shell then parses these tokens into commands and other | |
330 | constructs, removes the special meaning of certain words or characters, | |
331 | expands others, redirects input and output as needed, executes the | |
332 | specified command, waits for the command's exit status, and makes that | |
333 | exit status available for further inspection or processing. | |
334 | ||
ccc6cda3 JA |
335 | \1f |
336 | File: bashref.info, Node: Shell Operation, Next: Quoting, Up: Shell Syntax | |
337 | ||
761783bf CR |
338 | 3.1.1 Shell Operation |
339 | --------------------- | |
ccc6cda3 | 340 | |
761783bf | 341 | The following is a brief description of the shell's operation when it |
ccc6cda3 JA |
342 | reads and executes a command. Basically, the shell does the following: |
343 | ||
28ef6c31 | 344 | 1. Reads its input from a file (*note Shell Scripts::), from a string |
ccc6cda3 | 345 | supplied as an argument to the `-c' invocation option (*note |
28ef6c31 | 346 | Invoking Bash::), or from the user's terminal. |
ccc6cda3 JA |
347 | |
348 | 2. Breaks the input into words and operators, obeying the quoting | |
cce855bc | 349 | rules described in *Note Quoting::. These tokens are separated by |
ccc6cda3 | 350 | `metacharacters'. Alias expansion is performed by this step |
28ef6c31 | 351 | (*note Aliases::). |
ccc6cda3 | 352 | |
cce855bc | 353 | 3. Parses the tokens into simple and compound commands (*note Shell |
28ef6c31 | 354 | Commands::). |
ccc6cda3 | 355 | |
28ef6c31 | 356 | 4. Performs the various shell expansions (*note Shell Expansions::), |
ccc6cda3 | 357 | breaking the expanded tokens into lists of filenames (*note |
28ef6c31 | 358 | Filename Expansion::) and commands and arguments. |
ccc6cda3 | 359 | |
28ef6c31 | 360 | 5. Performs any necessary redirections (*note Redirections::) and |
ccc6cda3 JA |
361 | removes the redirection operators and their operands from the |
362 | argument list. | |
363 | ||
28ef6c31 | 364 | 6. Executes the command (*note Executing Commands::). |
ccc6cda3 JA |
365 | |
366 | 7. Optionally waits for the command to complete and collects its exit | |
28ef6c31 | 367 | status (*note Exit Status::). |
ccc6cda3 JA |
368 | |
369 | ||
370 | \1f | |
371 | File: bashref.info, Node: Quoting, Next: Comments, Prev: Shell Operation, Up: Shell Syntax | |
372 | ||
761783bf CR |
373 | 3.1.2 Quoting |
374 | ------------- | |
ccc6cda3 JA |
375 | |
376 | * Menu: | |
377 | ||
378 | * Escape Character:: How to remove the special meaning from a single | |
379 | character. | |
380 | * Single Quotes:: How to inhibit all interpretation of a sequence | |
381 | of characters. | |
382 | * Double Quotes:: How to suppress most of the interpretation of a | |
383 | sequence of characters. | |
384 | * ANSI-C Quoting:: How to expand ANSI-C sequences in quoted strings. | |
385 | ||
386 | * Locale Translation:: How to translate strings into different languages. | |
387 | ||
388 | Quoting is used to remove the special meaning of certain characters | |
389 | or words to the shell. Quoting can be used to disable special | |
390 | treatment for special characters, to prevent reserved words from being | |
391 | recognized as such, and to prevent parameter expansion. | |
392 | ||
28ef6c31 | 393 | Each of the shell metacharacters (*note Definitions::) has special |
cce855bc | 394 | meaning to the shell and must be quoted if it is to represent itself. |
bb70624e JA |
395 | When the command history expansion facilities are being used, the |
396 | HISTORY EXPANSION character, usually `!', must be quoted to prevent | |
28ef6c31 | 397 | history expansion. *Note Bash History Facilities::, for more details |
d3a24ed2 CR |
398 | concerning history expansion. |
399 | ||
400 | There are three quoting mechanisms: the ESCAPE CHARACTER, single | |
401 | quotes, and double quotes. | |
ccc6cda3 JA |
402 | |
403 | \1f | |
404 | File: bashref.info, Node: Escape Character, Next: Single Quotes, Up: Quoting | |
405 | ||
761783bf CR |
406 | 3.1.2.1 Escape Character |
407 | ........................ | |
ccc6cda3 | 408 | |
761783bf CR |
409 | A non-quoted backslash `\' is the Bash escape character. It preserves |
410 | the literal value of the next character that follows, with the | |
411 | exception of `newline'. If a `\newline' pair appears, and the | |
cce855bc JA |
412 | backslash itself is not quoted, the `\newline' is treated as a line |
413 | continuation (that is, it is removed from the input stream and | |
414 | effectively ignored). | |
ccc6cda3 JA |
415 | |
416 | \1f | |
417 | File: bashref.info, Node: Single Quotes, Next: Double Quotes, Prev: Escape Character, Up: Quoting | |
418 | ||
761783bf CR |
419 | 3.1.2.2 Single Quotes |
420 | ..................... | |
ccc6cda3 | 421 | |
761783bf CR |
422 | Enclosing characters in single quotes (`'') preserves the literal value |
423 | of each character within the quotes. A single quote may not occur | |
bb70624e | 424 | between single quotes, even when preceded by a backslash. |
ccc6cda3 JA |
425 | |
426 | \1f | |
427 | File: bashref.info, Node: Double Quotes, Next: ANSI-C Quoting, Prev: Single Quotes, Up: Quoting | |
428 | ||
761783bf CR |
429 | 3.1.2.3 Double Quotes |
430 | ..................... | |
ccc6cda3 | 431 | |
761783bf CR |
432 | Enclosing characters in double quotes (`"') preserves the literal value |
433 | of all characters within the quotes, with the exception of `$', ``', | |
434 | and `\'. The characters `$' and ``' retain their special meaning | |
28ef6c31 JA |
435 | within double quotes (*note Shell Expansions::). The backslash retains |
436 | its special meaning only when followed by one of the following | |
bb70624e JA |
437 | characters: `$', ``', `"', `\', or `newline'. Within double quotes, |
438 | backslashes that are followed by one of these characters are removed. | |
439 | Backslashes preceding characters without a special meaning are left | |
440 | unmodified. A double quote may be quoted within double quotes by | |
d3a24ed2 CR |
441 | preceding it with a backslash. When command history is being used, the |
442 | double quote may not be used to quote the history expansion character. | |
ccc6cda3 JA |
443 | |
444 | The special parameters `*' and `@' have special meaning when in | |
28ef6c31 | 445 | double quotes (*note Shell Parameter Expansion::). |
ccc6cda3 JA |
446 | |
447 | \1f | |
448 | File: bashref.info, Node: ANSI-C Quoting, Next: Locale Translation, Prev: Double Quotes, Up: Quoting | |
449 | ||
761783bf CR |
450 | 3.1.2.4 ANSI-C Quoting |
451 | ...................... | |
ccc6cda3 | 452 | |
761783bf CR |
453 | Words of the form `$'STRING'' are treated specially. The word expands |
454 | to STRING, with backslash-escaped characters replaced as specified by | |
455 | the ANSI C standard. Backslash escape sequences, if present, are | |
456 | decoded as follows: | |
ccc6cda3 JA |
457 | |
458 | `\a' | |
459 | alert (bell) | |
460 | ||
461 | `\b' | |
462 | backspace | |
463 | ||
464 | `\e' | |
465 | an escape character (not ANSI C) | |
466 | ||
467 | `\f' | |
468 | form feed | |
469 | ||
470 | `\n' | |
471 | newline | |
472 | ||
473 | `\r' | |
474 | carriage return | |
475 | ||
476 | `\t' | |
477 | horizontal tab | |
478 | ||
479 | `\v' | |
480 | vertical tab | |
481 | ||
482 | `\\' | |
483 | backslash | |
484 | ||
bb70624e JA |
485 | `\'' |
486 | single quote | |
487 | ||
ccc6cda3 | 488 | `\NNN' |
f73dda09 | 489 | the eight-bit character whose value is the octal value NNN (one to |
cce855bc JA |
490 | three digits) |
491 | ||
f73dda09 JA |
492 | `\xHH' |
493 | the eight-bit character whose value is the hexadecimal value HH | |
494 | (one or two hex digits) | |
ccc6cda3 | 495 | |
7117c2d2 JA |
496 | `\cX' |
497 | a control-X character | |
498 | ||
bb70624e JA |
499 | The expanded result is single-quoted, as if the dollar sign had not |
500 | been present. | |
ccc6cda3 JA |
501 | |
502 | \1f | |
503 | File: bashref.info, Node: Locale Translation, Prev: ANSI-C Quoting, Up: Quoting | |
504 | ||
761783bf CR |
505 | 3.1.2.5 Locale-Specific Translation |
506 | ................................... | |
ccc6cda3 | 507 | |
761783bf CR |
508 | A double-quoted string preceded by a dollar sign (`$') will cause the |
509 | string to be translated according to the current locale. If the | |
ccc6cda3 JA |
510 | current locale is `C' or `POSIX', the dollar sign is ignored. If the |
511 | string is translated and replaced, the replacement is double-quoted. | |
512 | ||
28ef6c31 JA |
513 | Some systems use the message catalog selected by the `LC_MESSAGES' |
514 | shell variable. Others create the name of the message catalog from the | |
515 | value of the `TEXTDOMAIN' shell variable, possibly adding a suffix of | |
516 | `.mo'. If you use the `TEXTDOMAIN' variable, you may need to set the | |
517 | `TEXTDOMAINDIR' variable to the location of the message catalog files. | |
f73dda09 JA |
518 | Still others use both variables in this fashion: |
519 | `TEXTDOMAINDIR'/`LC_MESSAGES'/LC_MESSAGES/`TEXTDOMAIN'.mo. | |
28ef6c31 | 520 | |
ccc6cda3 JA |
521 | \1f |
522 | File: bashref.info, Node: Comments, Prev: Quoting, Up: Shell Syntax | |
523 | ||
761783bf CR |
524 | 3.1.3 Comments |
525 | -------------- | |
ccc6cda3 | 526 | |
761783bf | 527 | In a non-interactive shell, or an interactive shell in which the |
ccc6cda3 | 528 | `interactive_comments' option to the `shopt' builtin is enabled (*note |
28ef6c31 | 529 | Bash Builtins::), a word beginning with `#' causes that word and all |
ccc6cda3 JA |
530 | remaining characters on that line to be ignored. An interactive shell |
531 | without the `interactive_comments' option enabled does not allow | |
532 | comments. The `interactive_comments' option is on by default in | |
bb70624e JA |
533 | interactive shells. *Note Interactive Shells::, for a description of |
534 | what makes a shell interactive. | |
cce855bc JA |
535 | |
536 | \1f | |
537 | File: bashref.info, Node: Shell Commands, Next: Shell Functions, Prev: Shell Syntax, Up: Basic Shell Features | |
538 | ||
761783bf CR |
539 | 3.2 Shell Commands |
540 | ================== | |
cce855bc | 541 | |
761783bf | 542 | A simple shell command such as `echo a b c' consists of the command |
bb70624e JA |
543 | itself followed by arguments, separated by spaces. |
544 | ||
545 | More complex shell commands are composed of simple commands arranged | |
546 | together in a variety of ways: in a pipeline in which the output of one | |
547 | command becomes the input of a second, in a loop or conditional | |
548 | construct, or in some other grouping. | |
549 | ||
cce855bc JA |
550 | * Menu: |
551 | ||
552 | * Simple Commands:: The most common type of command. | |
553 | * Pipelines:: Connecting the input and output of several | |
554 | commands. | |
555 | * Lists:: How to execute commands sequentially. | |
d3a24ed2 | 556 | * Compound Commands:: Shell commands for control flow. |
ccc6cda3 JA |
557 | |
558 | \1f | |
cce855bc | 559 | File: bashref.info, Node: Simple Commands, Next: Pipelines, Up: Shell Commands |
ccc6cda3 | 560 | |
761783bf CR |
561 | 3.2.1 Simple Commands |
562 | --------------------- | |
ccc6cda3 | 563 | |
761783bf CR |
564 | A simple command is the kind of command encountered most often. It's |
565 | just a sequence of words separated by `blank's, terminated by one of | |
566 | the shell's control operators (*note Definitions::). The first word | |
28ef6c31 | 567 | generally specifies a command to be executed, with the rest of the |
bb70624e | 568 | words being that command's arguments. |
ccc6cda3 | 569 | |
28ef6c31 | 570 | The return status (*note Exit Status::) of a simple command is its |
bb70624e JA |
571 | exit status as provided by the POSIX 1003.1 `waitpid' function, or |
572 | 128+N if the command was terminated by signal N. | |
ccc6cda3 JA |
573 | |
574 | \1f | |
cce855bc | 575 | File: bashref.info, Node: Pipelines, Next: Lists, Prev: Simple Commands, Up: Shell Commands |
ccc6cda3 | 576 | |
761783bf CR |
577 | 3.2.2 Pipelines |
578 | --------------- | |
ccc6cda3 | 579 | |
761783bf | 580 | A `pipeline' is a sequence of simple commands separated by `|'. |
ccc6cda3 JA |
581 | |
582 | The format for a pipeline is | |
583 | [`time' [`-p']] [`!'] COMMAND1 [`|' COMMAND2 ...] | |
584 | ||
f73dda09 JA |
585 | The output of each command in the pipeline is connected via a pipe to |
586 | the input of the next command. That is, each command reads the | |
587 | previous command's output. | |
ccc6cda3 JA |
588 | |
589 | The reserved word `time' causes timing statistics to be printed for | |
cce855bc JA |
590 | the pipeline once it finishes. The statistics currently consist of |
591 | elapsed (wall-clock) time and user and system time consumed by the | |
592 | command's execution. The `-p' option changes the output format to that | |
593 | specified by POSIX. The `TIMEFORMAT' variable may be set to a format | |
594 | string that specifies how the timing information should be displayed. | |
595 | *Note Bash Variables::, for a description of the available formats. | |
596 | The use of `time' as a reserved word permits the timing of shell | |
597 | builtins, shell functions, and pipelines. An external `time' command | |
598 | cannot time these easily. | |
599 | ||
28ef6c31 | 600 | If the pipeline is not executed asynchronously (*note Lists::), the |
cce855bc | 601 | shell waits for all commands in the pipeline to complete. |
ccc6cda3 | 602 | |
cce855bc | 603 | Each command in a pipeline is executed in its own subshell (*note |
28ef6c31 | 604 | Command Execution Environment::). The exit status of a pipeline is the |
5e13499c CR |
605 | exit status of the last command in the pipeline, unless the `pipefail' |
606 | option is enabled (*note The Set Builtin::). If `pipefail' is enabled, | |
607 | the pipeline's return status is the value of the last (rightmost) | |
608 | command to exit with a non-zero status, or zero if all commands exit | |
609 | successfully. If the reserved word `!' precedes the pipeline, the exit | |
610 | status is the logical negation of the exit status as described above. | |
611 | The shell waits for all commands in the pipeline to terminate before | |
612 | returning a value. | |
ccc6cda3 JA |
613 | |
614 | \1f | |
d3a24ed2 | 615 | File: bashref.info, Node: Lists, Next: Compound Commands, Prev: Pipelines, Up: Shell Commands |
ccc6cda3 | 616 | |
761783bf CR |
617 | 3.2.3 Lists of Commands |
618 | ----------------------- | |
ccc6cda3 | 619 | |
761783bf CR |
620 | A `list' is a sequence of one or more pipelines separated by one of the |
621 | operators `;', `&', `&&', or `||', and optionally terminated by one of | |
622 | `;', `&', or a `newline'. | |
ccc6cda3 JA |
623 | |
624 | Of these list operators, `&&' and `||' have equal precedence, | |
625 | followed by `;' and `&', which have equal precedence. | |
626 | ||
7117c2d2 JA |
627 | A sequence of one or more newlines may appear in a `list' to delimit |
628 | commands, equivalent to a semicolon. | |
629 | ||
ccc6cda3 | 630 | If a command is terminated by the control operator `&', the shell |
cce855bc JA |
631 | executes the command asynchronously in a subshell. This is known as |
632 | executing the command in the BACKGROUND. The shell does not wait for | |
bb70624e | 633 | the command to finish, and the return status is 0 (true). When job |
28ef6c31 | 634 | control is not active (*note Job Control::), the standard input for |
bb70624e JA |
635 | asynchronous commands, in the absence of any explicit redirections, is |
636 | redirected from `/dev/null'. | |
cce855bc JA |
637 | |
638 | Commands separated by a `;' are executed sequentially; the shell | |
639 | waits for each command to terminate in turn. The return status is the | |
640 | exit status of the last command executed. | |
ccc6cda3 JA |
641 | |
642 | The control operators `&&' and `||' denote AND lists and OR lists, | |
643 | respectively. An AND list has the form | |
bb70624e | 644 | COMMAND1 && COMMAND2 |
ccc6cda3 | 645 | |
bb70624e JA |
646 | COMMAND2 is executed if, and only if, COMMAND1 returns an exit status |
647 | of zero. | |
ccc6cda3 JA |
648 | |
649 | An OR list has the form | |
bb70624e | 650 | COMMAND1 || COMMAND2 |
ccc6cda3 | 651 | |
bb70624e | 652 | COMMAND2 is executed if, and only if, COMMAND1 returns a non-zero exit |
ccc6cda3 JA |
653 | status. |
654 | ||
655 | The return status of AND and OR lists is the exit status of the last | |
656 | command executed in the list. | |
657 | ||
658 | \1f | |
d3a24ed2 CR |
659 | File: bashref.info, Node: Compound Commands, Prev: Lists, Up: Shell Commands |
660 | ||
761783bf CR |
661 | 3.2.4 Compound Commands |
662 | ----------------------- | |
d3a24ed2 CR |
663 | |
664 | * Menu: | |
665 | ||
666 | * Looping Constructs:: Shell commands for iterative action. | |
667 | * Conditional Constructs:: Shell commands for conditional execution. | |
668 | * Command Grouping:: Ways to group commands. | |
669 | ||
670 | Compound commands are the shell programming constructs. Each | |
671 | construct begins with a reserved word or control operator and is | |
672 | terminated by a corresponding reserved word or operator. Any | |
673 | redirections (*note Redirections::) associated with a compound command | |
674 | apply to all commands within that compound command unless explicitly | |
675 | overridden. | |
676 | ||
677 | Bash provides looping constructs, conditional commands, and | |
678 | mechanisms to group commands and execute them as a unit. | |
679 | ||
680 | \1f | |
681 | File: bashref.info, Node: Looping Constructs, Next: Conditional Constructs, Up: Compound Commands | |
ccc6cda3 | 682 | |
761783bf CR |
683 | 3.2.4.1 Looping Constructs |
684 | .......................... | |
ccc6cda3 | 685 | |
761783bf | 686 | Bash supports the following looping constructs. |
ccc6cda3 | 687 | |
bb70624e | 688 | Note that wherever a `;' appears in the description of a command's |
cce855bc JA |
689 | syntax, it may be replaced with one or more newlines. |
690 | ||
ccc6cda3 JA |
691 | `until' |
692 | The syntax of the `until' command is: | |
693 | until TEST-COMMANDS; do CONSEQUENT-COMMANDS; done | |
cce855bc JA |
694 | Execute CONSEQUENT-COMMANDS as long as TEST-COMMANDS has an exit |
695 | status which is not zero. The return status is the exit status of | |
696 | the last command executed in CONSEQUENT-COMMANDS, or zero if none | |
697 | was executed. | |
ccc6cda3 JA |
698 | |
699 | `while' | |
700 | The syntax of the `while' command is: | |
701 | while TEST-COMMANDS; do CONSEQUENT-COMMANDS; done | |
702 | ||
cce855bc JA |
703 | Execute CONSEQUENT-COMMANDS as long as TEST-COMMANDS has an exit |
704 | status of zero. The return status is the exit status of the last | |
705 | command executed in CONSEQUENT-COMMANDS, or zero if none was | |
706 | executed. | |
ccc6cda3 JA |
707 | |
708 | `for' | |
709 | The syntax of the `for' command is: | |
710 | ||
711 | for NAME [in WORDS ...]; do COMMANDS; done | |
cce855bc JA |
712 | Expand WORDS, and execute COMMANDS once for each member in the |
713 | resultant list, with NAME bound to the current member. If `in | |
bb70624e JA |
714 | WORDS' is not present, the `for' command executes the COMMANDS |
715 | once for each positional parameter that is set, as if `in "$@"' | |
28ef6c31 | 716 | had been specified (*note Special Parameters::). The return |
bb70624e JA |
717 | status is the exit status of the last command that executes. If |
718 | there are no items in the expansion of WORDS, no commands are | |
719 | executed, and the return status is zero. | |
720 | ||
721 | An alternate form of the `for' command is also supported: | |
722 | ||
723 | for (( EXPR1 ; EXPR2 ; EXPR3 )) ; do COMMANDS ; done | |
724 | First, the arithmetic expression EXPR1 is evaluated according to | |
28ef6c31 | 725 | the rules described below (*note Shell Arithmetic::). The |
bb70624e JA |
726 | arithmetic expression EXPR2 is then evaluated repeatedly until it |
727 | evaluates to zero. Each time EXPR2 evaluates to a non-zero value, | |
728 | COMMANDS are executed and the arithmetic expression EXPR3 is | |
729 | evaluated. If any expression is omitted, it behaves as if it | |
730 | evaluates to 1. The return value is the exit status of the last | |
731 | command in LIST that is executed, or false if any of the | |
732 | expressions is invalid. | |
ccc6cda3 | 733 | |
761783bf | 734 | |
28ef6c31 | 735 | The `break' and `continue' builtins (*note Bourne Shell Builtins::) |
ccc6cda3 JA |
736 | may be used to control loop execution. |
737 | ||
738 | \1f | |
d3a24ed2 | 739 | File: bashref.info, Node: Conditional Constructs, Next: Command Grouping, Prev: Looping Constructs, Up: Compound Commands |
ccc6cda3 | 740 | |
761783bf CR |
741 | 3.2.4.2 Conditional Constructs |
742 | .............................. | |
ccc6cda3 JA |
743 | |
744 | `if' | |
745 | The syntax of the `if' command is: | |
746 | ||
747 | if TEST-COMMANDS; then | |
748 | CONSEQUENT-COMMANDS; | |
749 | [elif MORE-TEST-COMMANDS; then | |
750 | MORE-CONSEQUENTS;] | |
751 | [else ALTERNATE-CONSEQUENTS;] | |
752 | fi | |
753 | ||
cce855bc JA |
754 | The TEST-COMMANDS list is executed, and if its return status is |
755 | zero, the CONSEQUENT-COMMANDS list is executed. If TEST-COMMANDS | |
756 | returns a non-zero status, each `elif' list is executed in turn, | |
757 | and if its exit status is zero, the corresponding MORE-CONSEQUENTS | |
758 | is executed and the command completes. If `else | |
759 | ALTERNATE-CONSEQUENTS' is present, and the final command in the | |
760 | final `if' or `elif' clause has a non-zero exit status, then | |
761 | ALTERNATE-CONSEQUENTS is executed. The return status is the exit | |
762 | status of the last command executed, or zero if no condition | |
763 | tested true. | |
ccc6cda3 JA |
764 | |
765 | `case' | |
766 | The syntax of the `case' command is: | |
767 | ||
cce855bc | 768 | `case WORD in [ [(] PATTERN [| PATTERN]...) COMMAND-LIST ;;]... esac' |
ccc6cda3 | 769 | |
cce855bc JA |
770 | `case' will selectively execute the COMMAND-LIST corresponding to |
771 | the first PATTERN that matches WORD. The `|' is used to separate | |
772 | multiple patterns, and the `)' operator terminates a pattern list. | |
773 | A list of patterns and an associated command-list is known as a | |
774 | CLAUSE. Each clause must be terminated with `;;'. The WORD | |
775 | undergoes tilde expansion, parameter expansion, command | |
776 | substitution, arithmetic expansion, and quote removal before | |
777 | matching is attempted. Each PATTERN undergoes tilde expansion, | |
778 | parameter expansion, command substitution, and arithmetic | |
779 | expansion. | |
780 | ||
781 | There may be an arbitrary number of `case' clauses, each terminated | |
782 | by a `;;'. The first pattern that matches determines the | |
783 | command-list that is executed. | |
ccc6cda3 JA |
784 | |
785 | Here is an example using `case' in a script that could be used to | |
786 | describe one interesting feature of an animal: | |
787 | ||
788 | echo -n "Enter the name of an animal: " | |
789 | read ANIMAL | |
790 | echo -n "The $ANIMAL has " | |
791 | case $ANIMAL in | |
792 | horse | dog | cat) echo -n "four";; | |
793 | man | kangaroo ) echo -n "two";; | |
794 | *) echo -n "an unknown number of";; | |
795 | esac | |
796 | echo " legs." | |
797 | ||
cce855bc JA |
798 | The return status is zero if no PATTERN is matched. Otherwise, the |
799 | return status is the exit status of the COMMAND-LIST executed. | |
800 | ||
801 | `select' | |
802 | The `select' construct allows the easy generation of menus. It | |
803 | has almost the same syntax as the `for' command: | |
804 | ||
805 | select NAME [in WORDS ...]; do COMMANDS; done | |
806 | ||
807 | The list of words following `in' is expanded, generating a list of | |
808 | items. The set of expanded words is printed on the standard error | |
809 | output stream, each preceded by a number. If the `in WORDS' is | |
810 | omitted, the positional parameters are printed, as if `in "$@"' | |
811 | had been specifed. The `PS3' prompt is then displayed and a line | |
812 | is read from the standard input. If the line consists of a number | |
813 | corresponding to one of the displayed words, then the value of | |
814 | NAME is set to that word. If the line is empty, the words and | |
815 | prompt are displayed again. If `EOF' is read, the `select' | |
816 | command completes. Any other value read causes NAME to be set to | |
817 | null. The line read is saved in the variable `REPLY'. | |
818 | ||
f73dda09 JA |
819 | The COMMANDS are executed after each selection until a `break' |
820 | command is executed, at which point the `select' command completes. | |
cce855bc JA |
821 | |
822 | Here is an example that allows the user to pick a filename from the | |
823 | current directory, and displays the name and index of the file | |
824 | selected. | |
825 | ||
826 | select fname in *; | |
827 | do | |
828 | echo you picked $fname \($REPLY\) | |
829 | break; | |
830 | done | |
831 | ||
ccc6cda3 JA |
832 | `((...))' |
833 | (( EXPRESSION )) | |
834 | ||
cce855bc | 835 | The arithmetic EXPRESSION is evaluated according to the rules |
28ef6c31 | 836 | described below (*note Shell Arithmetic::). If the value of the |
cce855bc JA |
837 | expression is non-zero, the return status is 0; otherwise the |
838 | return status is 1. This is exactly equivalent to | |
ccc6cda3 | 839 | let "EXPRESSION" |
cce855bc JA |
840 | *Note Bash Builtins::, for a full description of the `let' builtin. |
841 | ||
842 | `[[...]]' | |
843 | [[ EXPRESSION ]] | |
844 | ||
845 | Return a status of 0 or 1 depending on the evaluation of the | |
846 | conditional expression EXPRESSION. Expressions are composed of | |
847 | the primaries described below in *Note Bash Conditional | |
848 | Expressions::. Word splitting and filename expansion are not | |
849 | performed on the words between the `[[' and `]]'; tilde expansion, | |
850 | parameter and variable expansion, arithmetic expansion, command | |
851 | substitution, process substitution, and quote removal are | |
d3a24ed2 CR |
852 | performed. Conditional operators such as `-f' must be unquoted to |
853 | be recognized as primaries. | |
cce855bc JA |
854 | |
855 | When the `==' and `!=' operators are used, the string to the right | |
856 | of the operator is considered a pattern and matched according to | |
857 | the rules described below in *Note Pattern Matching::. The return | |
858 | value is 0 if the string matches or does not match the pattern, | |
859 | respectively, and 1 otherwise. Any part of the pattern may be | |
860 | quoted to force it to be matched as a string. | |
861 | ||
5e13499c CR |
862 | An additional binary operator, `=~', is available, with the same |
863 | precedence as `==' and `!='. When it is used, the string to the | |
864 | right of the operator is considered an extended regular expression | |
865 | and matched accordingly (as in regex3)). The return value is 0 if | |
866 | the string matches the pattern, and 1 otherwise. If the regular | |
867 | expression is syntactically incorrect, the conditional | |
868 | expression's return value is 2. If the shell option `nocaseglob' | |
869 | (see the description of `shopt' in *Note Bash Builtins::) is | |
870 | enabled, the match is performed without regard to the case of | |
871 | alphabetic characters. Substrings matched by parenthesized | |
872 | subexpressions within the regular expression are saved in the | |
873 | array variable `BASH_REMATCH'. The element of `BASH_REMATCH' with | |
874 | index 0 is the portion of the string matching the entire regular | |
875 | expression. The element of `BASH_REMATCH' with index N is the | |
876 | portion of the string matching the Nth parenthesized subexpression. | |
877 | ||
cce855bc JA |
878 | Expressions may be combined using the following operators, listed |
879 | in decreasing order of precedence: | |
880 | ||
881 | `( EXPRESSION )' | |
882 | Returns the value of EXPRESSION. This may be used to | |
883 | override the normal precedence of operators. | |
884 | ||
885 | `! EXPRESSION' | |
886 | True if EXPRESSION is false. | |
887 | ||
888 | `EXPRESSION1 && EXPRESSION2' | |
889 | True if both EXPRESSION1 and EXPRESSION2 are true. | |
890 | ||
891 | `EXPRESSION1 || EXPRESSION2' | |
892 | True if either EXPRESSION1 or EXPRESSION2 is true. | |
7117c2d2 JA |
893 | The `&&' and `||' operators do not evaluate EXPRESSION2 if the |
894 | value of EXPRESSION1 is sufficient to determine the return value | |
895 | of the entire conditional expression. | |
ccc6cda3 | 896 | |
761783bf | 897 | |
ccc6cda3 | 898 | \1f |
d3a24ed2 | 899 | File: bashref.info, Node: Command Grouping, Prev: Conditional Constructs, Up: Compound Commands |
ccc6cda3 | 900 | |
761783bf CR |
901 | 3.2.4.3 Grouping Commands |
902 | ......................... | |
ccc6cda3 | 903 | |
761783bf CR |
904 | Bash provides two ways to group a list of commands to be executed as a |
905 | unit. When commands are grouped, redirections may be applied to the | |
ccc6cda3 JA |
906 | entire command list. For example, the output of all the commands in |
907 | the list may be redirected to a single stream. | |
908 | ||
909 | `()' | |
910 | ( LIST ) | |
911 | ||
912 | Placing a list of commands between parentheses causes a subshell | |
d3a24ed2 CR |
913 | environment to be created (*note Command Execution Environment::), |
914 | and each of the commands in LIST to be executed in that subshell. | |
915 | Since the LIST is executed in a subshell, variable assignments do | |
916 | not remain in effect after the subshell completes. | |
ccc6cda3 JA |
917 | |
918 | `{}' | |
919 | { LIST; } | |
920 | ||
921 | Placing a list of commands between curly braces causes the list to | |
922 | be executed in the current shell context. No subshell is created. | |
cce855bc | 923 | The semicolon (or newline) following LIST is required. |
ccc6cda3 JA |
924 | |
925 | In addition to the creation of a subshell, there is a subtle | |
926 | difference between these two constructs due to historical reasons. The | |
927 | braces are `reserved words', so they must be separated from the LIST by | |
928 | `blank's. The parentheses are `operators', and are recognized as | |
d166f048 JA |
929 | separate tokens by the shell even if they are not separated from the |
930 | LIST by whitespace. | |
ccc6cda3 JA |
931 | |
932 | The exit status of both of these constructs is the exit status of | |
933 | LIST. | |
934 | ||
935 | \1f | |
cce855bc | 936 | File: bashref.info, Node: Shell Functions, Next: Shell Parameters, Prev: Shell Commands, Up: Basic Shell Features |
ccc6cda3 | 937 | |
761783bf CR |
938 | 3.3 Shell Functions |
939 | =================== | |
ccc6cda3 | 940 | |
761783bf CR |
941 | Shell functions are a way to group commands for later execution using a |
942 | single name for the group. They are executed just like a "regular" | |
943 | command. When the name of a shell function is used as a simple command | |
944 | name, the list of commands associated with that function name is | |
945 | executed. Shell functions are executed in the current shell context; | |
946 | no new process is created to interpret them. | |
ccc6cda3 | 947 | |
761783bf | 948 | Functions are declared using this syntax: |
d3a24ed2 | 949 | [ `function' ] NAME () COMPOUND-COMMAND [ REDIRECTIONS ] |
ccc6cda3 JA |
950 | |
951 | This defines a shell function named NAME. The reserved word | |
cce855bc | 952 | `function' is optional. If the `function' reserved word is supplied, |
d3a24ed2 CR |
953 | the parentheses are optional. The BODY of the function is the compound |
954 | command COMPOUND-COMMAND (*note Compound Commands::). That command is | |
955 | usually a LIST enclosed between { and }, but may be any compound | |
956 | command listed above. COMPOUND-COMMAND is executed whenever NAME is | |
957 | specified as the name of a command. Any redirections (*note | |
958 | Redirections::) associated with the shell function are performed when | |
959 | the function is executed. | |
960 | ||
961 | The exit status of a function definition is zero unless a syntax | |
962 | error occurs or a readonly function with the same name already exists. | |
963 | When executed, the exit status of a function is the exit status of the | |
964 | last command executed in the body. | |
965 | ||
966 | Note that for historical reasons, in the most common usage the curly | |
967 | braces that surround the body of the function must be separated from | |
968 | the body by `blank's or newlines. This is because the braces are | |
969 | reserved words and are only recognized as such when they are separated | |
970 | by whitespace. Also, when using the braces, the LIST must be | |
971 | terminated by a semicolon, a `&', or a newline. | |
bb70624e | 972 | |
ccc6cda3 JA |
973 | When a function is executed, the arguments to the function become |
974 | the positional parameters during its execution (*note Positional | |
28ef6c31 | 975 | Parameters::). The special parameter `#' that expands to the number of |
de8913bd | 976 | positional parameters is updated to reflect the change. Special |
d3a24ed2 CR |
977 | parameter `0' is unchanged. The first element of the `FUNCNAME' |
978 | variable is set to the name of the function while the function is | |
979 | executing. All other aspects of the shell execution environment are | |
980 | identical between a function and its caller with the exception that the | |
981 | `DEBUG' trap below) is not inherited unless the function has been given | |
982 | the `trace' attribute using the `declare' builtin or the `-o functrace' | |
983 | option has been enabled with the `set' builtin, (in which case all | |
984 | functions inherit the `DEBUG' trap). *Note Bourne Shell Builtins::, | |
985 | for the description of the `trap' builtin. | |
ccc6cda3 JA |
986 | |
987 | If the builtin command `return' is executed in a function, the | |
988 | function completes and execution resumes with the next command after | |
d3a24ed2 CR |
989 | the function call. Any command associated with the `RETURN' trap is |
990 | executed before execution resumes. When a function completes, the | |
991 | values of the positional parameters and the special parameter `#' are | |
992 | restored to the values they had prior to the function's execution. If | |
993 | a numeric argument is given to `return', that is the function's return | |
994 | status; otherwise the function's return status is the exit status of | |
995 | the last command executed before the `return'. | |
ccc6cda3 JA |
996 | |
997 | Variables local to the function may be declared with the `local' | |
998 | builtin. These variables are visible only to the function and the | |
999 | commands it invokes. | |
1000 | ||
d3a24ed2 CR |
1001 | Function names and definitions may be listed with the `-f' option to |
1002 | the `declare' or `typeset' builtin commands (*note Bash Builtins::). | |
1003 | The `-F' option to `declare' or `typeset' will list the function names | |
1004 | only (and optionally the source file and line number, if the `extdebug' | |
1005 | shell option is enabled). Functions may be exported so that subshells | |
1006 | automatically have them defined with the `-f' option to the `export' | |
1007 | builtin (*note Bourne Shell Builtins::). Note that shell functions and | |
1008 | variables with the same name may result in multiple identically-named | |
1009 | entries in the environment passed to the shell's children. Care should | |
1010 | be taken in cases where this may cause a problem. | |
1011 | ||
ccc6cda3 JA |
1012 | Functions may be recursive. No limit is placed on the number of |
1013 | recursive calls. | |
1014 | ||
1015 | \1f | |
1016 | File: bashref.info, Node: Shell Parameters, Next: Shell Expansions, Prev: Shell Functions, Up: Basic Shell Features | |
1017 | ||
761783bf CR |
1018 | 3.4 Shell Parameters |
1019 | ==================== | |
ccc6cda3 JA |
1020 | |
1021 | * Menu: | |
1022 | ||
1023 | * Positional Parameters:: The shell's command-line arguments. | |
d3a24ed2 | 1024 | * Special Parameters:: Parameters denoted by special characters. |
ccc6cda3 JA |
1025 | |
1026 | A PARAMETER is an entity that stores values. It can be a `name', a | |
d3a24ed2 CR |
1027 | number, or one of the special characters listed below. A VARIABLE is a |
1028 | parameter denoted by a `name'. A variable has a VALUE and zero or more | |
1029 | ATTRIBUTES. Attributes are assigned using the `declare' builtin command | |
1030 | (see the description of the `declare' builtin in *Note Bash Builtins::). | |
ccc6cda3 JA |
1031 | |
1032 | A parameter is set if it has been assigned a value. The null string | |
1033 | is a valid value. Once a variable is set, it may be unset only by using | |
1034 | the `unset' builtin command. | |
1035 | ||
1036 | A variable may be assigned to by a statement of the form | |
1037 | NAME=[VALUE] | |
761783bf | 1038 | If VALUE is not given, the variable is assigned the null string. All |
ccc6cda3 JA |
1039 | VALUEs undergo tilde expansion, parameter and variable expansion, |
1040 | command substitution, arithmetic expansion, and quote removal (detailed | |
f73dda09 | 1041 | below). If the variable has its `integer' attribute set, then VALUE is |
d3a24ed2 CR |
1042 | evaluated as an arithmetic expression even if the `$((...))' expansion |
1043 | is not used (*note Arithmetic Expansion::). Word splitting is not | |
1044 | performed, with the exception of `"$@"' as explained below. Filename | |
1045 | expansion is not performed. Assignment statements may also appear as | |
5e13499c CR |
1046 | arguments to the `alias', `declare', `typeset', `export', `readonly', |
1047 | and `local' builtin commands. | |
ccc6cda3 JA |
1048 | |
1049 | \1f | |
1050 | File: bashref.info, Node: Positional Parameters, Next: Special Parameters, Up: Shell Parameters | |
1051 | ||
761783bf CR |
1052 | 3.4.1 Positional Parameters |
1053 | --------------------------- | |
ccc6cda3 | 1054 | |
761783bf | 1055 | A POSITIONAL PARAMETER is a parameter denoted by one or more digits, |
ccc6cda3 JA |
1056 | other than the single digit `0'. Positional parameters are assigned |
1057 | from the shell's arguments when it is invoked, and may be reassigned | |
cce855bc | 1058 | using the `set' builtin command. Positional parameter `N' may be |
bb70624e JA |
1059 | referenced as `${N}', or as `$N' when `N' consists of a single digit. |
1060 | Positional parameters may not be assigned to with assignment statements. | |
1061 | The `set' and `shift' builtins are used to set and unset them (*note | |
28ef6c31 JA |
1062 | Shell Builtin Commands::). The positional parameters are temporarily |
1063 | replaced when a shell function is executed (*note Shell Functions::). | |
ccc6cda3 JA |
1064 | |
1065 | When a positional parameter consisting of more than a single digit | |
1066 | is expanded, it must be enclosed in braces. | |
1067 | ||
1068 | \1f | |
1069 | File: bashref.info, Node: Special Parameters, Prev: Positional Parameters, Up: Shell Parameters | |
1070 | ||
761783bf CR |
1071 | 3.4.2 Special Parameters |
1072 | ------------------------ | |
ccc6cda3 | 1073 | |
761783bf | 1074 | The shell treats several parameters specially. These parameters may |
ccc6cda3 JA |
1075 | only be referenced; assignment to them is not allowed. |
1076 | ||
1077 | `*' | |
1078 | Expands to the positional parameters, starting from one. When the | |
1079 | expansion occurs within double quotes, it expands to a single word | |
1080 | with the value of each parameter separated by the first character | |
1081 | of the `IFS' special variable. That is, `"$*"' is equivalent to | |
1082 | `"$1C$2C..."', where C is the first character of the value of the | |
d166f048 JA |
1083 | `IFS' variable. If `IFS' is unset, the parameters are separated |
1084 | by spaces. If `IFS' is null, the parameters are joined without | |
1085 | intervening separators. | |
ccc6cda3 JA |
1086 | |
1087 | `@' | |
1088 | Expands to the positional parameters, starting from one. When the | |
cce855bc | 1089 | expansion occurs within double quotes, each parameter expands to a |
ccc6cda3 JA |
1090 | separate word. That is, `"$@"' is equivalent to `"$1" "$2" ...'. |
1091 | When there are no positional parameters, `"$@"' and `$@' expand to | |
1092 | nothing (i.e., they are removed). | |
1093 | ||
1094 | `#' | |
1095 | Expands to the number of positional parameters in decimal. | |
1096 | ||
1097 | `?' | |
1098 | Expands to the exit status of the most recently executed foreground | |
1099 | pipeline. | |
1100 | ||
1101 | `-' | |
bb70624e JA |
1102 | (A hyphen.) Expands to the current option flags as specified upon |
1103 | invocation, by the `set' builtin command, or those set by the | |
1104 | shell itself (such as the `-i' option). | |
ccc6cda3 JA |
1105 | |
1106 | `$' | |
1107 | Expands to the process ID of the shell. In a `()' subshell, it | |
cce855bc | 1108 | expands to the process ID of the invoking shell, not the subshell. |
ccc6cda3 JA |
1109 | |
1110 | `!' | |
1111 | Expands to the process ID of the most recently executed background | |
1112 | (asynchronous) command. | |
1113 | ||
1114 | `0' | |
1115 | Expands to the name of the shell or shell script. This is set at | |
cce855bc | 1116 | shell initialization. If Bash is invoked with a file of commands |
28ef6c31 JA |
1117 | (*note Shell Scripts::), `$0' is set to the name of that file. If |
1118 | Bash is started with the `-c' option (*note Invoking Bash::), then | |
1119 | `$0' is set to the first argument after the string to be executed, | |
1120 | if one is present. Otherwise, it is set to the filename used to | |
1121 | invoke Bash, as given by argument zero. | |
ccc6cda3 JA |
1122 | |
1123 | `_' | |
bb70624e JA |
1124 | (An underscore.) At shell startup, set to the absolute filename |
1125 | of the shell or shell script being executed as passed in the | |
1126 | argument list. Subsequently, expands to the last argument to the | |
1127 | previous command, after expansion. Also set to the full pathname | |
1128 | of each command executed and placed in the environment exported to | |
1129 | that command. When checking mail, this parameter holds the name | |
1130 | of the mail file. | |
ccc6cda3 JA |
1131 | |
1132 | \1f | |
1133 | File: bashref.info, Node: Shell Expansions, Next: Redirections, Prev: Shell Parameters, Up: Basic Shell Features | |
1134 | ||
761783bf CR |
1135 | 3.5 Shell Expansions |
1136 | ==================== | |
ccc6cda3 | 1137 | |
761783bf CR |
1138 | Expansion is performed on the command line after it has been split into |
1139 | `token's. There are seven kinds of expansion performed: | |
ccc6cda3 JA |
1140 | * brace expansion |
1141 | ||
1142 | * tilde expansion | |
1143 | ||
1144 | * parameter and variable expansion | |
1145 | ||
1146 | * command substitution | |
1147 | ||
1148 | * arithmetic expansion | |
1149 | ||
1150 | * word splitting | |
1151 | ||
1152 | * filename expansion | |
1153 | ||
1154 | * Menu: | |
1155 | ||
cce855bc JA |
1156 | * Brace Expansion:: Expansion of expressions within braces. |
1157 | * Tilde Expansion:: Expansion of the ~ character. | |
ccc6cda3 JA |
1158 | * Shell Parameter Expansion:: How Bash expands variables to their values. |
1159 | * Command Substitution:: Using the output of a command as an argument. | |
cce855bc | 1160 | * Arithmetic Expansion:: How to use arithmetic in shell expansions. |
ccc6cda3 JA |
1161 | * Process Substitution:: A way to write and read to and from a |
1162 | command. | |
1163 | * Word Splitting:: How the results of expansion are split into separate | |
1164 | arguments. | |
1165 | * Filename Expansion:: A shorthand for specifying filenames matching patterns. | |
1166 | * Quote Removal:: How and when quote characters are removed from | |
1167 | words. | |
1168 | ||
ccc6cda3 JA |
1169 | The order of expansions is: brace expansion, tilde expansion, |
1170 | parameter, variable, and arithmetic expansion and command substitution | |
1171 | (done in a left-to-right fashion), word splitting, and filename | |
1172 | expansion. | |
1173 | ||
1174 | On systems that can support it, there is an additional expansion | |
1175 | available: PROCESS SUBSTITUTION. This is performed at the same time as | |
cce855bc | 1176 | parameter, variable, and arithmetic expansion and command substitution. |
ccc6cda3 JA |
1177 | |
1178 | Only brace expansion, word splitting, and filename expansion can | |
1179 | change the number of words of the expansion; other expansions expand a | |
1180 | single word to a single word. The only exceptions to this are the | |
28ef6c31 JA |
1181 | expansions of `"$@"' (*note Special Parameters::) and `"${NAME[@]}"' |
1182 | (*note Arrays::). | |
ccc6cda3 | 1183 | |
28ef6c31 | 1184 | After all expansions, `quote removal' (*note Quote Removal::) is |
ccc6cda3 JA |
1185 | performed. |
1186 | ||
1187 | \1f | |
cce855bc JA |
1188 | File: bashref.info, Node: Brace Expansion, Next: Tilde Expansion, Up: Shell Expansions |
1189 | ||
761783bf CR |
1190 | 3.5.1 Brace Expansion |
1191 | --------------------- | |
cce855bc | 1192 | |
761783bf | 1193 | Brace expansion is a mechanism by which arbitrary strings may be |
cce855bc | 1194 | generated. This mechanism is similar to FILENAME EXPANSION (*note |
28ef6c31 | 1195 | Filename Expansion::), but the file names generated need not exist. |
cce855bc | 1196 | Patterns to be brace expanded take the form of an optional PREAMBLE, |
d3a24ed2 CR |
1197 | followed by either a series of comma-separated strings or a sequnce |
1198 | expression between a pair of braces, followed by an optional POSTSCRIPT. | |
1199 | The preamble is prefixed to each string contained within the braces, and | |
1200 | the postscript is then appended to each resulting string, expanding left | |
1201 | to right. | |
cce855bc JA |
1202 | |
1203 | Brace expansions may be nested. The results of each expanded string | |
1204 | are not sorted; left to right order is preserved. For example, | |
1205 | bash$ echo a{d,c,b}e | |
1206 | ade ace abe | |
1207 | ||
d3a24ed2 CR |
1208 | A sequence expression takes the form `{X..Y}', where X and Y are |
1209 | either integers or single characters. When integers are supplied, the | |
1210 | expression expands to each number between X and Y, inclusive. When | |
1211 | characters are supplied, the expression expands to each character | |
1212 | lexicographically between X and Y, inclusive. Note that both X and Y | |
1213 | must be of the same type. | |
1214 | ||
cce855bc JA |
1215 | Brace expansion is performed before any other expansions, and any |
1216 | characters special to other expansions are preserved in the result. It | |
1217 | is strictly textual. Bash does not apply any syntactic interpretation | |
bb70624e JA |
1218 | to the context of the expansion or the text between the braces. To |
1219 | avoid conflicts with parameter expansion, the string `${' is not | |
1220 | considered eligible for brace expansion. | |
cce855bc JA |
1221 | |
1222 | A correctly-formed brace expansion must contain unquoted opening and | |
d3a24ed2 CR |
1223 | closing braces, and at least one unquoted comma or a valid sequence |
1224 | expression. Any incorrectly formed brace expansion is left unchanged. | |
1225 | ||
1226 | A { or `,' may be quoted with a backslash to prevent its being | |
1227 | considered part of a brace expression. To avoid conflicts with | |
1228 | parameter expansion, the string `${' is not considered eligible for | |
1229 | brace expansion. | |
cce855bc JA |
1230 | |
1231 | This construct is typically used as shorthand when the common prefix | |
1232 | of the strings to be generated is longer than in the above example: | |
1233 | mkdir /usr/local/src/bash/{old,new,dist,bugs} | |
1234 | or | |
1235 | chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}} | |
1236 | ||
1237 | \1f | |
1238 | File: bashref.info, Node: Tilde Expansion, Next: Shell Parameter Expansion, Prev: Brace Expansion, Up: Shell Expansions | |
1239 | ||
761783bf CR |
1240 | 3.5.2 Tilde Expansion |
1241 | --------------------- | |
cce855bc | 1242 | |
761783bf | 1243 | If a word begins with an unquoted tilde character (`~'), all of the |
cce855bc JA |
1244 | characters up to the first unquoted slash (or all characters, if there |
1245 | is no unquoted slash) are considered a TILDE-PREFIX. If none of the | |
1246 | characters in the tilde-prefix are quoted, the characters in the | |
1247 | tilde-prefix following the tilde are treated as a possible LOGIN NAME. | |
1248 | If this login name is the null string, the tilde is replaced with the | |
1249 | value of the `HOME' shell variable. If `HOME' is unset, the home | |
1250 | directory of the user executing the shell is substituted instead. | |
1251 | Otherwise, the tilde-prefix is replaced with the home directory | |
1252 | associated with the specified login name. | |
1253 | ||
1254 | If the tilde-prefix is `~+', the value of the shell variable `PWD' | |
1255 | replaces the tilde-prefix. If the tilde-prefix is `~-', the value of | |
1256 | the shell variable `OLDPWD', if it is set, is substituted. | |
1257 | ||
1258 | If the characters following the tilde in the tilde-prefix consist of | |
1259 | a number N, optionally prefixed by a `+' or a `-', the tilde-prefix is | |
1260 | replaced with the corresponding element from the directory stack, as it | |
1261 | would be displayed by the `dirs' builtin invoked with the characters | |
1262 | following tilde in the tilde-prefix as an argument (*note The Directory | |
28ef6c31 | 1263 | Stack::). If the tilde-prefix, sans the tilde, consists of a number |
cce855bc JA |
1264 | without a leading `+' or `-', `+' is assumed. |
1265 | ||
1266 | If the login name is invalid, or the tilde expansion fails, the word | |
1267 | is left unchanged. | |
1268 | ||
1269 | Each variable assignment is checked for unquoted tilde-prefixes | |
1270 | immediately following a `:' or `='. In these cases, tilde expansion is | |
1271 | also performed. Consequently, one may use file names with tildes in | |
1272 | assignments to `PATH', `MAILPATH', and `CDPATH', and the shell assigns | |
1273 | the expanded value. | |
1274 | ||
1275 | The following table shows how Bash treats unquoted tilde-prefixes: | |
1276 | ||
1277 | `~' | |
1278 | The value of `$HOME' | |
1279 | ||
1280 | `~/foo' | |
1281 | `$HOME/foo' | |
1282 | ||
1283 | `~fred/foo' | |
1284 | The subdirectory `foo' of the home directory of the user `fred' | |
1285 | ||
1286 | `~+/foo' | |
1287 | `$PWD/foo' | |
1288 | ||
1289 | `~-/foo' | |
1290 | `${OLDPWD-'~-'}/foo' | |
1291 | ||
1292 | `~N' | |
1293 | The string that would be displayed by `dirs +N' | |
1294 | ||
1295 | `~+N' | |
1296 | The string that would be displayed by `dirs +N' | |
1297 | ||
1298 | `~-N' | |
1299 | The string that would be displayed by `dirs -N' | |
1300 | ||
761783bf | 1301 | |
cce855bc JA |
1302 | \1f |
1303 | File: bashref.info, Node: Shell Parameter Expansion, Next: Command Substitution, Prev: Tilde Expansion, Up: Shell Expansions | |
ccc6cda3 | 1304 | |
761783bf CR |
1305 | 3.5.3 Shell Parameter Expansion |
1306 | ------------------------------- | |
ccc6cda3 | 1307 | |
761783bf CR |
1308 | The `$' character introduces parameter expansion, command substitution, |
1309 | or arithmetic expansion. The parameter name or symbol to be expanded | |
1310 | may be enclosed in braces, which are optional but serve to protect the | |
1311 | variable to be expanded from characters immediately following it which | |
1312 | could be interpreted as part of the name. | |
ccc6cda3 | 1313 | |
cce855bc JA |
1314 | When braces are used, the matching ending brace is the first `}' not |
1315 | escaped by a backslash or within a quoted string, and not within an | |
1316 | embedded arithmetic expansion, command substitution, or parameter | |
1317 | expansion. | |
1318 | ||
ccc6cda3 JA |
1319 | The basic form of parameter expansion is ${PARAMETER}. The value of |
1320 | PARAMETER is substituted. The braces are required when PARAMETER is a | |
1321 | positional parameter with more than one digit, or when PARAMETER is | |
1322 | followed by a character that is not to be interpreted as part of its | |
1323 | name. | |
1324 | ||
1325 | If the first character of PARAMETER is an exclamation point, a level | |
1326 | of variable indirection is introduced. Bash uses the value of the | |
1327 | variable formed from the rest of PARAMETER as the name of the variable; | |
d166f048 JA |
1328 | this variable is then expanded and that value is used in the rest of |
1329 | the substitution, rather than the value of PARAMETER itself. This is | |
d3a24ed2 CR |
1330 | known as `indirect expansion'. The exceptions to this are the |
1331 | expansions of ${!PREFIX*} and ${!NAME[@]} described below. The | |
1332 | exclamation point must immediately follow the left brace in order to | |
1333 | introduce indirection. | |
ccc6cda3 JA |
1334 | |
1335 | In each of the cases below, WORD is subject to tilde expansion, | |
1336 | parameter expansion, command substitution, and arithmetic expansion. | |
bb70624e JA |
1337 | |
1338 | When not performing substring expansion, Bash tests for a parameter | |
ccc6cda3 | 1339 | that is unset or null; omitting the colon results in a test only for a |
bb70624e JA |
1340 | parameter that is unset. Put another way, if the colon is included, |
1341 | the operator tests for both existence and that the value is not null; | |
1342 | if the colon is omitted, the operator tests only for existence. | |
ccc6cda3 JA |
1343 | |
1344 | `${PARAMETER:-WORD}' | |
1345 | If PARAMETER is unset or null, the expansion of WORD is | |
1346 | substituted. Otherwise, the value of PARAMETER is substituted. | |
1347 | ||
1348 | `${PARAMETER:=WORD}' | |
1349 | If PARAMETER is unset or null, the expansion of WORD is assigned | |
1350 | to PARAMETER. The value of PARAMETER is then substituted. | |
de8913bd CR |
1351 | Positional parameters and special parameters may not be assigned to |
1352 | in this way. | |
ccc6cda3 JA |
1353 | |
1354 | `${PARAMETER:?WORD}' | |
1355 | If PARAMETER is null or unset, the expansion of WORD (or a message | |
1356 | to that effect if WORD is not present) is written to the standard | |
1357 | error and the shell, if it is not interactive, exits. Otherwise, | |
1358 | the value of PARAMETER is substituted. | |
1359 | ||
1360 | `${PARAMETER:+WORD}' | |
1361 | If PARAMETER is null or unset, nothing is substituted, otherwise | |
1362 | the expansion of WORD is substituted. | |
1363 | ||
1364 | `${PARAMETER:OFFSET}' | |
1365 | `${PARAMETER:OFFSET:LENGTH}' | |
bb70624e | 1366 | Expands to up to LENGTH characters of PARAMETER starting at the |
cce855bc | 1367 | character specified by OFFSET. If LENGTH is omitted, expands to |
bb70624e | 1368 | the substring of PARAMETER starting at the character specified by |
cce855bc | 1369 | OFFSET. LENGTH and OFFSET are arithmetic expressions (*note Shell |
28ef6c31 | 1370 | Arithmetic::). This is referred to as Substring Expansion. |
ccc6cda3 JA |
1371 | |
1372 | LENGTH must evaluate to a number greater than or equal to zero. | |
1373 | If OFFSET evaluates to a number less than zero, the value is used | |
1374 | as an offset from the end of the value of PARAMETER. If PARAMETER | |
1375 | is `@', the result is LENGTH positional parameters beginning at | |
1376 | OFFSET. If PARAMETER is an array name indexed by `@' or `*', the | |
1377 | result is the LENGTH members of the array beginning with | |
cce855bc JA |
1378 | `${PARAMETER[OFFSET]}'. Substring indexing is zero-based unless |
1379 | the positional parameters are used, in which case the indexing | |
1380 | starts at 1. | |
ccc6cda3 | 1381 | |
bb70624e | 1382 | `${!PREFIX*}' |
d3a24ed2 | 1383 | `${!PREFIX@}' |
bb70624e JA |
1384 | Expands to the names of variables whose names begin with PREFIX, |
1385 | separated by the first character of the `IFS' special variable. | |
1386 | ||
d3a24ed2 CR |
1387 | `${!NAME[@]}' |
1388 | `${!NAME[*]}' | |
1389 | If NAME is an array variable, expands to the list of array indices | |
1390 | (keys) assigned in NAME. If NAME is not an array, expands to 0 if | |
1391 | NAME is set and null otherwise. When `@' is used and the | |
1392 | expansion appears within double quotes, each key expands to a | |
1393 | separate word. | |
1394 | ||
ccc6cda3 | 1395 | `${#PARAMETER}' |
cce855bc JA |
1396 | The length in characters of the expanded value of PARAMETER is |
1397 | substituted. If PARAMETER is `*' or `@', the value substituted is | |
1398 | the number of positional parameters. If PARAMETER is an array | |
1399 | name subscripted by `*' or `@', the value substituted is the | |
1400 | number of elements in the array. | |
ccc6cda3 JA |
1401 | |
1402 | `${PARAMETER#WORD}' | |
1403 | `${PARAMETER##WORD}' | |
1404 | The WORD is expanded to produce a pattern just as in filename | |
28ef6c31 | 1405 | expansion (*note Filename Expansion::). If the pattern matches |
cce855bc JA |
1406 | the beginning of the expanded value of PARAMETER, then the result |
1407 | of the expansion is the expanded value of PARAMETER with the | |
1408 | shortest matching pattern (the `#' case) or the longest matching | |
1409 | pattern (the `##' case) deleted. If PARAMETER is `@' or `*', the | |
1410 | pattern removal operation is applied to each positional parameter | |
1411 | in turn, and the expansion is the resultant list. If PARAMETER is | |
1412 | an array variable subscripted with `@' or `*', the pattern removal | |
1413 | operation is applied to each member of the array in turn, and the | |
1414 | expansion is the resultant list. | |
ccc6cda3 JA |
1415 | |
1416 | `${PARAMETER%WORD}' | |
1417 | `${PARAMETER%%WORD}' | |
1418 | The WORD is expanded to produce a pattern just as in filename | |
cce855bc JA |
1419 | expansion. If the pattern matches a trailing portion of the |
1420 | expanded value of PARAMETER, then the result of the expansion is | |
1421 | the value of PARAMETER with the shortest matching pattern (the `%' | |
1422 | case) or the longest matching pattern (the `%%' case) deleted. If | |
1423 | PARAMETER is `@' or `*', the pattern removal operation is applied | |
1424 | to each positional parameter in turn, and the expansion is the | |
1425 | resultant list. If PARAMETER is an array variable subscripted | |
1426 | with `@' or `*', the pattern removal operation is applied to each | |
1427 | member of the array in turn, and the expansion is the resultant | |
1428 | list. | |
ccc6cda3 JA |
1429 | |
1430 | `${PARAMETER/PATTERN/STRING}' | |
1431 | `${PARAMETER//PATTERN/STRING}' | |
1432 | The PATTERN is expanded to produce a pattern just as in filename | |
1433 | expansion. PARAMETER is expanded and the longest match of PATTERN | |
1434 | against its value is replaced with STRING. In the first form, | |
1435 | only the first match is replaced. The second form causes all | |
1436 | matches of PATTERN to be replaced with STRING. If PATTERN begins | |
b72432fd JA |
1437 | with `#', it must match at the beginning of the expanded value of |
1438 | PARAMETER. If PATTERN begins with `%', it must match at the end | |
1439 | of the expanded value of PARAMETER. If STRING is null, matches of | |
1440 | PATTERN are deleted and the `/' following PATTERN may be omitted. | |
1441 | If PARAMETER is `@' or `*', the substitution operation is applied | |
1442 | to each positional parameter in turn, and the expansion is the | |
1443 | resultant list. If PARAMETER is an array variable subscripted | |
1444 | with `@' or `*', the substitution operation is applied to each | |
1445 | member of the array in turn, and the expansion is the resultant | |
1446 | list. | |
ccc6cda3 | 1447 | |
761783bf | 1448 | |
ccc6cda3 | 1449 | \1f |
cce855bc | 1450 | File: bashref.info, Node: Command Substitution, Next: Arithmetic Expansion, Prev: Shell Parameter Expansion, Up: Shell Expansions |
ccc6cda3 | 1451 | |
761783bf CR |
1452 | 3.5.4 Command Substitution |
1453 | -------------------------- | |
ccc6cda3 | 1454 | |
761783bf | 1455 | Command substitution allows the output of a command to replace the |
bb70624e JA |
1456 | command itself. Command substitution occurs when a command is enclosed |
1457 | as follows: | |
ccc6cda3 | 1458 | $(COMMAND) |
761783bf | 1459 | or |
ccc6cda3 JA |
1460 | `COMMAND` |
1461 | ||
1462 | Bash performs the expansion by executing COMMAND and replacing the | |
1463 | command substitution with the standard output of the command, with any | |
cce855bc JA |
1464 | trailing newlines deleted. Embedded newlines are not deleted, but they |
1465 | may be removed during word splitting. The command substitution `$(cat | |
1466 | FILE)' can be replaced by the equivalent but faster `$(< FILE)'. | |
ccc6cda3 JA |
1467 | |
1468 | When the old-style backquote form of substitution is used, backslash | |
1469 | retains its literal meaning except when followed by `$', ``', or `\'. | |
cce855bc JA |
1470 | The first backquote not preceded by a backslash terminates the command |
1471 | substitution. When using the `$(COMMAND)' form, all characters between | |
1472 | the parentheses make up the command; none are treated specially. | |
ccc6cda3 | 1473 | |
cce855bc JA |
1474 | Command substitutions may be nested. To nest when using the |
1475 | backquoted form, escape the inner backquotes with backslashes. | |
ccc6cda3 JA |
1476 | |
1477 | If the substitution appears within double quotes, word splitting and | |
1478 | filename expansion are not performed on the results. | |
1479 | ||
1480 | \1f | |
cce855bc JA |
1481 | File: bashref.info, Node: Arithmetic Expansion, Next: Process Substitution, Prev: Command Substitution, Up: Shell Expansions |
1482 | ||
761783bf CR |
1483 | 3.5.5 Arithmetic Expansion |
1484 | -------------------------- | |
cce855bc | 1485 | |
761783bf CR |
1486 | Arithmetic expansion allows the evaluation of an arithmetic expression |
1487 | and the substitution of the result. The format for arithmetic | |
1488 | expansion is: | |
cce855bc JA |
1489 | |
1490 | $(( EXPRESSION )) | |
1491 | ||
1492 | The expression is treated as if it were within double quotes, but a | |
1493 | double quote inside the parentheses is not treated specially. All | |
1494 | tokens in the expression undergo parameter expansion, command | |
d3a24ed2 | 1495 | substitution, and quote removal. Arithmetic expansions may be nested. |
cce855bc JA |
1496 | |
1497 | The evaluation is performed according to the rules listed below | |
28ef6c31 | 1498 | (*note Shell Arithmetic::). If the expression is invalid, Bash prints |
cce855bc JA |
1499 | a message indicating failure to the standard error and no substitution |
1500 | occurs. | |
1501 | ||
1502 | \1f | |
1503 | File: bashref.info, Node: Process Substitution, Next: Word Splitting, Prev: Arithmetic Expansion, Up: Shell Expansions | |
ccc6cda3 | 1504 | |
761783bf CR |
1505 | 3.5.6 Process Substitution |
1506 | -------------------------- | |
ccc6cda3 | 1507 | |
761783bf CR |
1508 | Process substitution is supported on systems that support named pipes |
1509 | (FIFOs) or the `/dev/fd' method of naming open files. It takes the | |
1510 | form of | |
ccc6cda3 | 1511 | <(LIST) |
761783bf | 1512 | or |
ccc6cda3 | 1513 | >(LIST) |
761783bf CR |
1514 | The process LIST is run with its input or output connected to a FIFO |
1515 | or some file in `/dev/fd'. The name of this file is passed as an | |
1516 | argument to the current command as the result of the expansion. If the | |
ccc6cda3 JA |
1517 | `>(LIST)' form is used, writing to the file will provide input for |
1518 | LIST. If the `<(LIST)' form is used, the file passed as an argument | |
bb70624e JA |
1519 | should be read to obtain the output of LIST. Note that no space may |
1520 | appear between the `<' or `>' and the left parenthesis, otherwise the | |
1521 | construct would be interpreted as a redirection. | |
ccc6cda3 | 1522 | |
cce855bc JA |
1523 | When available, process substitution is performed simultaneously with |
1524 | parameter and variable expansion, command substitution, and arithmetic | |
1525 | expansion. | |
ccc6cda3 JA |
1526 | |
1527 | \1f | |
1528 | File: bashref.info, Node: Word Splitting, Next: Filename Expansion, Prev: Process Substitution, Up: Shell Expansions | |
1529 | ||
761783bf CR |
1530 | 3.5.7 Word Splitting |
1531 | -------------------- | |
ccc6cda3 | 1532 | |
761783bf | 1533 | The shell scans the results of parameter expansion, command |
ccc6cda3 JA |
1534 | substitution, and arithmetic expansion that did not occur within double |
1535 | quotes for word splitting. | |
1536 | ||
1537 | The shell treats each character of `$IFS' as a delimiter, and splits | |
1538 | the results of the other expansions into words on these characters. If | |
1539 | `IFS' is unset, or its value is exactly `<space><tab><newline>', the | |
1540 | default, then any sequence of `IFS' characters serves to delimit words. | |
1541 | If `IFS' has a value other than the default, then sequences of the | |
1542 | whitespace characters `space' and `tab' are ignored at the beginning | |
1543 | and end of the word, as long as the whitespace character is in the | |
1544 | value of `IFS' (an `IFS' whitespace character). Any character in `IFS' | |
1545 | that is not `IFS' whitespace, along with any adjacent `IFS' whitespace | |
1546 | characters, delimits a field. A sequence of `IFS' whitespace | |
1547 | characters is also treated as a delimiter. If the value of `IFS' is | |
1548 | null, no word splitting occurs. | |
1549 | ||
1550 | Explicit null arguments (`""' or `''') are retained. Unquoted | |
bb70624e | 1551 | implicit null arguments, resulting from the expansion of parameters |
ccc6cda3 JA |
1552 | that have no values, are removed. If a parameter with no value is |
1553 | expanded within double quotes, a null argument results and is retained. | |
1554 | ||
1555 | Note that if no expansion occurs, no splitting is performed. | |
1556 | ||
1557 | \1f | |
1558 | File: bashref.info, Node: Filename Expansion, Next: Quote Removal, Prev: Word Splitting, Up: Shell Expansions | |
1559 | ||
761783bf CR |
1560 | 3.5.8 Filename Expansion |
1561 | ------------------------ | |
ccc6cda3 | 1562 | |
cce855bc JA |
1563 | * Menu: |
1564 | ||
1565 | * Pattern Matching:: How the shell matches patterns. | |
1566 | ||
ccc6cda3 | 1567 | After word splitting, unless the `-f' option has been set (*note The |
28ef6c31 | 1568 | Set Builtin::), Bash scans each word for the characters `*', `?', and |
bb70624e JA |
1569 | `['. If one of these characters appears, then the word is regarded as |
1570 | a PATTERN, and replaced with an alphabetically sorted list of file | |
ccc6cda3 | 1571 | names matching the pattern. If no matching file names are found, and |
cce855bc JA |
1572 | the shell option `nullglob' is disabled, the word is left unchanged. |
1573 | If the `nullglob' option is set, and no matches are found, the word is | |
5e13499c CR |
1574 | removed. If the `failglob' shell option is set, and no matches are |
1575 | found, an error message is printed and the command is not executed. If | |
1576 | the shell option `nocaseglob' is enabled, the match is performed | |
1577 | without regard to the case of alphabetic characters. | |
cce855bc | 1578 | |
28ef6c31 JA |
1579 | When a pattern is used for filename generation, the character `.' at |
1580 | the start of a filename or immediately following a slash must be | |
cce855bc JA |
1581 | matched explicitly, unless the shell option `dotglob' is set. When |
1582 | matching a file name, the slash character must always be matched | |
1583 | explicitly. In other cases, the `.' character is not treated specially. | |
1584 | ||
1585 | See the description of `shopt' in *Note Bash Builtins::, for a | |
5e13499c CR |
1586 | description of the `nocaseglob', `nullglob', `failglob', and `dotglob' |
1587 | options. | |
ccc6cda3 JA |
1588 | |
1589 | The `GLOBIGNORE' shell variable may be used to restrict the set of | |
cce855bc | 1590 | filenames matching a pattern. If `GLOBIGNORE' is set, each matching |
ccc6cda3 | 1591 | filename that also matches one of the patterns in `GLOBIGNORE' is |
28ef6c31 | 1592 | removed from the list of matches. The filenames `.' and `..' are |
d3a24ed2 CR |
1593 | always ignored when `GLOBIGNORE' is set and not null. However, setting |
1594 | `GLOBIGNORE' to a non-null value has the effect of enabling the | |
1595 | `dotglob' shell option, so all other filenames beginning with a `.' | |
1596 | will match. To get the old behavior of ignoring filenames beginning | |
1597 | with a `.', make `.*' one of the patterns in `GLOBIGNORE'. The | |
1598 | `dotglob' option is disabled when `GLOBIGNORE' is unset. | |
ccc6cda3 | 1599 | |
cce855bc JA |
1600 | \1f |
1601 | File: bashref.info, Node: Pattern Matching, Up: Filename Expansion | |
1602 | ||
761783bf CR |
1603 | 3.5.8.1 Pattern Matching |
1604 | ........................ | |
cce855bc | 1605 | |
761783bf CR |
1606 | Any character that appears in a pattern, other than the special pattern |
1607 | characters described below, matches itself. The NUL character may not | |
1608 | occur in a pattern. A backslash escapes the following character; the | |
1609 | escaping backslash is discarded when matching. The special pattern | |
1610 | characters must be quoted if they are to be matched literally. | |
cce855bc | 1611 | |
ccc6cda3 JA |
1612 | The special pattern characters have the following meanings: |
1613 | `*' | |
1614 | Matches any string, including the null string. | |
1615 | ||
1616 | `?' | |
1617 | Matches any single character. | |
1618 | ||
1619 | `[...]' | |
1620 | Matches any one of the enclosed characters. A pair of characters | |
28ef6c31 JA |
1621 | separated by a hyphen denotes a RANGE EXPRESSION; any character |
1622 | that sorts between those two characters, inclusive, using the | |
1623 | current locale's collating sequence and character set, is matched. | |
1624 | If the first character following the `[' is a `!' or a `^' then | |
1625 | any character not enclosed is matched. A `-' may be matched by | |
1626 | including it as the first or last character in the set. A `]' may | |
1627 | be matched by including it as the first character in the set. The | |
1628 | sorting order of characters in range expressions is determined by | |
1629 | the current locale and the value of the `LC_COLLATE' shell | |
1630 | variable, if set. | |
1631 | ||
1632 | For example, in the default C locale, `[a-dx-z]' is equivalent to | |
1633 | `[abcdxyz]'. Many locales sort characters in dictionary order, | |
1634 | and in these locales `[a-dx-z]' is typically not equivalent to | |
1635 | `[abcdxyz]'; it might be equivalent to `[aBbCcDdxXyYz]', for | |
1636 | example. To obtain the traditional interpretation of ranges in | |
1637 | bracket expressions, you can force the use of the C locale by | |
1638 | setting the `LC_COLLATE' or `LC_ALL' environment variable to the | |
1639 | value `C'. | |
ccc6cda3 | 1640 | |
cce855bc JA |
1641 | Within `[' and `]', CHARACTER CLASSES can be specified using the |
1642 | syntax `[:'CLASS`:]', where CLASS is one of the following classes | |
bb70624e | 1643 | defined in the POSIX 1003.2 standard: |
cce855bc | 1644 | alnum alpha ascii blank cntrl digit graph lower |
7117c2d2 | 1645 | print punct space upper word xdigit |
cce855bc | 1646 | A character class matches any character belonging to that class. |
7117c2d2 JA |
1647 | The `word' character class matches letters, digits, and the |
1648 | character `_'. | |
cce855bc JA |
1649 | |
1650 | Within `[' and `]', an EQUIVALENCE CLASS can be specified using | |
1651 | the syntax `[='C`=]', which matches all characters with the same | |
1652 | collation weight (as defined by the current locale) as the | |
1653 | character C. | |
1654 | ||
28ef6c31 | 1655 | Within `[' and `]', the syntax `[.'SYMBOL`.]' matches the |
cce855bc JA |
1656 | collating symbol SYMBOL. |
1657 | ||
1658 | If the `extglob' shell option is enabled using the `shopt' builtin, | |
1659 | several extended pattern matching operators are recognized. In the | |
1660 | following description, a PATTERN-LIST is a list of one or more patterns | |
1661 | separated by a `|'. Composite patterns may be formed using one or more | |
1662 | of the following sub-patterns: | |
1663 | ||
1664 | `?(PATTERN-LIST)' | |
1665 | Matches zero or one occurrence of the given patterns. | |
1666 | ||
1667 | `*(PATTERN-LIST)' | |
1668 | Matches zero or more occurrences of the given patterns. | |
1669 | ||
1670 | `+(PATTERN-LIST)' | |
1671 | Matches one or more occurrences of the given patterns. | |
1672 | ||
1673 | `@(PATTERN-LIST)' | |
1674 | Matches exactly one of the given patterns. | |
1675 | ||
1676 | `!(PATTERN-LIST)' | |
1677 | Matches anything except one of the given patterns. | |
1678 | ||
ccc6cda3 JA |
1679 | \1f |
1680 | File: bashref.info, Node: Quote Removal, Prev: Filename Expansion, Up: Shell Expansions | |
1681 | ||
761783bf CR |
1682 | 3.5.9 Quote Removal |
1683 | ------------------- | |
ccc6cda3 | 1684 | |
761783bf | 1685 | After the preceding expansions, all unquoted occurrences of the |
ccc6cda3 JA |
1686 | characters `\', `'', and `"' that did not result from one of the above |
1687 | expansions are removed. | |
1688 | ||
1689 | \1f | |
1690 | File: bashref.info, Node: Redirections, Next: Executing Commands, Prev: Shell Expansions, Up: Basic Shell Features | |
1691 | ||
761783bf CR |
1692 | 3.6 Redirections |
1693 | ================ | |
ccc6cda3 | 1694 | |
761783bf | 1695 | Before a command is executed, its input and output may be REDIRECTED |
ccc6cda3 JA |
1696 | using a special notation interpreted by the shell. Redirection may |
1697 | also be used to open and close files for the current shell execution | |
1698 | environment. The following redirection operators may precede or appear | |
1699 | anywhere within a simple command or may follow a command. Redirections | |
1700 | are processed in the order they appear, from left to right. | |
1701 | ||
1702 | In the following descriptions, if the file descriptor number is | |
1703 | omitted, and the first character of the redirection operator is `<', | |
1704 | the redirection refers to the standard input (file descriptor 0). If | |
1705 | the first character of the redirection operator is `>', the redirection | |
1706 | refers to the standard output (file descriptor 1). | |
1707 | ||
cce855bc JA |
1708 | The word following the redirection operator in the following |
1709 | descriptions, unless otherwise noted, is subjected to brace expansion, | |
1710 | tilde expansion, parameter expansion, command substitution, arithmetic | |
bb70624e JA |
1711 | expansion, quote removal, filename expansion, and word splitting. If |
1712 | it expands to more than one word, Bash reports an error. | |
ccc6cda3 JA |
1713 | |
1714 | Note that the order of redirections is significant. For example, | |
1715 | the command | |
1716 | ls > DIRLIST 2>&1 | |
761783bf | 1717 | directs both standard output (file descriptor 1) and standard error |
bb70624e | 1718 | (file descriptor 2) to the file DIRLIST, while the command |
ccc6cda3 | 1719 | ls 2>&1 > DIRLIST |
761783bf CR |
1720 | directs only the standard output to file DIRLIST, because the |
1721 | standard error was duplicated as standard output before the standard | |
1722 | output was redirected to DIRLIST. | |
ccc6cda3 | 1723 | |
bb70624e JA |
1724 | Bash handles several filenames specially when they are used in |
1725 | redirections, as described in the following table: | |
1726 | ||
1727 | `/dev/fd/FD' | |
1728 | If FD is a valid integer, file descriptor FD is duplicated. | |
1729 | ||
1730 | `/dev/stdin' | |
1731 | File descriptor 0 is duplicated. | |
1732 | ||
1733 | `/dev/stdout' | |
1734 | File descriptor 1 is duplicated. | |
1735 | ||
1736 | `/dev/stderr' | |
1737 | File descriptor 2 is duplicated. | |
1738 | ||
1739 | `/dev/tcp/HOST/PORT' | |
1740 | If HOST is a valid hostname or Internet address, and PORT is an | |
f73dda09 JA |
1741 | integer port number or service name, Bash attempts to open a TCP |
1742 | connection to the corresponding socket. | |
bb70624e JA |
1743 | |
1744 | `/dev/udp/HOST/PORT' | |
1745 | If HOST is a valid hostname or Internet address, and PORT is an | |
f73dda09 JA |
1746 | integer port number or service name, Bash attempts to open a UDP |
1747 | connection to the corresponding socket. | |
bb70624e | 1748 | |
761783bf | 1749 | |
cce855bc JA |
1750 | A failure to open or create a file causes the redirection to fail. |
1751 | ||
761783bf CR |
1752 | 3.6.1 Redirecting Input |
1753 | ----------------------- | |
ccc6cda3 | 1754 | |
761783bf | 1755 | Redirection of input causes the file whose name results from the |
ccc6cda3 JA |
1756 | expansion of WORD to be opened for reading on file descriptor `n', or |
1757 | the standard input (file descriptor 0) if `n' is not specified. | |
1758 | ||
1759 | The general format for redirecting input is: | |
7117c2d2 | 1760 | [N]<WORD |
ccc6cda3 | 1761 | |
761783bf CR |
1762 | 3.6.2 Redirecting Output |
1763 | ------------------------ | |
ccc6cda3 | 1764 | |
761783bf | 1765 | Redirection of output causes the file whose name results from the |
7117c2d2 JA |
1766 | expansion of WORD to be opened for writing on file descriptor N, or the |
1767 | standard output (file descriptor 1) if N is not specified. If the file | |
1768 | does not exist it is created; if it does exist it is truncated to zero | |
1769 | size. | |
ccc6cda3 JA |
1770 | |
1771 | The general format for redirecting output is: | |
7117c2d2 | 1772 | [N]>[|]WORD |
ccc6cda3 | 1773 | |
cce855bc JA |
1774 | If the redirection operator is `>', and the `noclobber' option to |
1775 | the `set' builtin has been enabled, the redirection will fail if the | |
bb70624e | 1776 | file whose name results from the expansion of WORD exists and is a |
cce855bc JA |
1777 | regular file. If the redirection operator is `>|', or the redirection |
1778 | operator is `>' and the `noclobber' option is not enabled, the | |
1779 | redirection is attempted even if the file named by WORD exists. | |
ccc6cda3 | 1780 | |
761783bf CR |
1781 | 3.6.3 Appending Redirected Output |
1782 | --------------------------------- | |
ccc6cda3 | 1783 | |
761783bf | 1784 | Redirection of output in this fashion causes the file whose name |
ccc6cda3 | 1785 | results from the expansion of WORD to be opened for appending on file |
7117c2d2 JA |
1786 | descriptor N, or the standard output (file descriptor 1) if N is not |
1787 | specified. If the file does not exist it is created. | |
ccc6cda3 JA |
1788 | |
1789 | The general format for appending output is: | |
7117c2d2 | 1790 | [N]>>WORD |
ccc6cda3 | 1791 | |
761783bf CR |
1792 | 3.6.4 Redirecting Standard Output and Standard Error |
1793 | ---------------------------------------------------- | |
ccc6cda3 | 1794 | |
761783bf | 1795 | Bash allows both the standard output (file descriptor 1) and the |
ccc6cda3 JA |
1796 | standard error output (file descriptor 2) to be redirected to the file |
1797 | whose name is the expansion of WORD with this construct. | |
1798 | ||
1799 | There are two formats for redirecting standard output and standard | |
1800 | error: | |
1801 | &>WORD | |
761783bf | 1802 | and |
ccc6cda3 | 1803 | >&WORD |
761783bf | 1804 | Of the two forms, the first is preferred. This is semantically |
ccc6cda3 JA |
1805 | equivalent to |
1806 | >WORD 2>&1 | |
1807 | ||
761783bf CR |
1808 | 3.6.5 Here Documents |
1809 | -------------------- | |
ccc6cda3 | 1810 | |
761783bf | 1811 | This type of redirection instructs the shell to read input from the |
ccc6cda3 JA |
1812 | current source until a line containing only WORD (with no trailing |
1813 | blanks) is seen. All of the lines read up to that point are then used | |
1814 | as the standard input for a command. | |
1815 | ||
7117c2d2 | 1816 | The format of here-documents is: |
ccc6cda3 JA |
1817 | <<[-]WORD |
1818 | HERE-DOCUMENT | |
1819 | DELIMITER | |
1820 | ||
bb70624e JA |
1821 | No parameter expansion, command substitution, arithmetic expansion, |
1822 | or filename expansion is performed on WORD. If any characters in WORD | |
ccc6cda3 | 1823 | are quoted, the DELIMITER is the result of quote removal on WORD, and |
cce855bc JA |
1824 | the lines in the here-document are not expanded. If WORD is unquoted, |
1825 | all lines of the here-document are subjected to parameter expansion, | |
1826 | command substitution, and arithmetic expansion. In the latter case, | |
bb70624e JA |
1827 | the character sequence `\newline' is ignored, and `\' must be used to |
1828 | quote the characters `\', `$', and ``'. | |
ccc6cda3 JA |
1829 | |
1830 | If the redirection operator is `<<-', then all leading tab | |
1831 | characters are stripped from input lines and the line containing | |
1832 | DELIMITER. This allows here-documents within shell scripts to be | |
1833 | indented in a natural fashion. | |
1834 | ||
761783bf CR |
1835 | 3.6.6 Here Strings |
1836 | ------------------ | |
7117c2d2 | 1837 | |
761783bf | 1838 | A variant of here documents, the format is: |
7117c2d2 JA |
1839 | <<< WORD |
1840 | ||
1841 | The WORD is expanded and supplied to the command on its standard | |
1842 | input. | |
1843 | ||
761783bf CR |
1844 | 3.6.7 Duplicating File Descriptors |
1845 | ---------------------------------- | |
ccc6cda3 | 1846 | |
761783bf | 1847 | The redirection operator |
7117c2d2 | 1848 | [N]<&WORD |
761783bf CR |
1849 | is used to duplicate input file descriptors. If WORD expands to one |
1850 | or more digits, the file descriptor denoted by N is made to be a copy | |
1851 | of that file descriptor. If the digits in WORD do not specify a file | |
cce855bc | 1852 | descriptor open for input, a redirection error occurs. If WORD |
7117c2d2 JA |
1853 | evaluates to `-', file descriptor N is closed. If N is not specified, |
1854 | the standard input (file descriptor 0) is used. | |
ccc6cda3 JA |
1855 | |
1856 | The operator | |
7117c2d2 | 1857 | [N]>&WORD |
761783bf | 1858 | is used similarly to duplicate output file descriptors. If N is not |
cce855bc JA |
1859 | specified, the standard output (file descriptor 1) is used. If the |
1860 | digits in WORD do not specify a file descriptor open for output, a | |
7117c2d2 JA |
1861 | redirection error occurs. As a special case, if N is omitted, and WORD |
1862 | does not expand to one or more digits, the standard output and standard | |
1863 | error are redirected as described previously. | |
1864 | ||
761783bf CR |
1865 | 3.6.8 Moving File Descriptors |
1866 | ----------------------------- | |
7117c2d2 | 1867 | |
761783bf | 1868 | The redirection operator |
7117c2d2 | 1869 | [N]<&DIGIT- |
761783bf CR |
1870 | moves the file descriptor DIGIT to file descriptor N, or the |
1871 | standard input (file descriptor 0) if N is not specified. DIGIT is | |
1872 | closed after being duplicated to N. | |
7117c2d2 JA |
1873 | |
1874 | Similarly, the redirection operator | |
1875 | [N]>&DIGIT- | |
761783bf CR |
1876 | moves the file descriptor DIGIT to file descriptor N, or the |
1877 | standard output (file descriptor 1) if N is not specified. | |
7117c2d2 | 1878 | |
761783bf CR |
1879 | 3.6.9 Opening File Descriptors for Reading and Writing |
1880 | ------------------------------------------------------ | |
ccc6cda3 | 1881 | |
761783bf | 1882 | The redirection operator |
7117c2d2 | 1883 | [N]<>WORD |
761783bf | 1884 | causes the file whose name is the expansion of WORD to be opened for |
7117c2d2 JA |
1885 | both reading and writing on file descriptor N, or on file descriptor 0 |
1886 | if N is not specified. If the file does not exist, it is created. | |
ccc6cda3 JA |
1887 | |
1888 | \1f | |
1889 | File: bashref.info, Node: Executing Commands, Next: Shell Scripts, Prev: Redirections, Up: Basic Shell Features | |
1890 | ||
761783bf CR |
1891 | 3.7 Executing Commands |
1892 | ====================== | |
ccc6cda3 JA |
1893 | |
1894 | * Menu: | |
1895 | ||
cce855bc JA |
1896 | * Simple Command Expansion:: How Bash expands simple commands before |
1897 | executing them. | |
1898 | ||
ccc6cda3 JA |
1899 | * Command Search and Execution:: How Bash finds commands and runs them. |
1900 | ||
cce855bc JA |
1901 | * Command Execution Environment:: The environment in which Bash |
1902 | executes commands that are not | |
1903 | shell builtins. | |
1904 | ||
ccc6cda3 JA |
1905 | * Environment:: The environment given to a command. |
1906 | ||
1907 | * Exit Status:: The status returned by commands and how Bash | |
1908 | interprets it. | |
1909 | ||
1910 | * Signals:: What happens when Bash or a command it runs | |
1911 | receives a signal. | |
1912 | ||
1913 | \1f | |
cce855bc JA |
1914 | File: bashref.info, Node: Simple Command Expansion, Next: Command Search and Execution, Up: Executing Commands |
1915 | ||
761783bf CR |
1916 | 3.7.1 Simple Command Expansion |
1917 | ------------------------------ | |
cce855bc | 1918 | |
761783bf | 1919 | When a simple command is executed, the shell performs the following |
cce855bc JA |
1920 | expansions, assignments, and redirections, from left to right. |
1921 | ||
1922 | 1. The words that the parser has marked as variable assignments (those | |
1923 | preceding the command name) and redirections are saved for later | |
1924 | processing. | |
1925 | ||
1926 | 2. The words that are not variable assignments or redirections are | |
28ef6c31 | 1927 | expanded (*note Shell Expansions::). If any words remain after |
cce855bc JA |
1928 | expansion, the first word is taken to be the name of the command |
1929 | and the remaining words are the arguments. | |
1930 | ||
1931 | 3. Redirections are performed as described above (*note | |
28ef6c31 | 1932 | Redirections::). |
cce855bc JA |
1933 | |
1934 | 4. The text after the `=' in each variable assignment undergoes tilde | |
1935 | expansion, parameter expansion, command substitution, arithmetic | |
1936 | expansion, and quote removal before being assigned to the variable. | |
1937 | ||
1938 | If no command name results, the variable assignments affect the | |
1939 | current shell environment. Otherwise, the variables are added to the | |
1940 | environment of the executed command and do not affect the current shell | |
1941 | environment. If any of the assignments attempts to assign a value to a | |
1942 | readonly variable, an error occurs, and the command exits with a | |
1943 | non-zero status. | |
1944 | ||
1945 | If no command name results, redirections are performed, but do not | |
1946 | affect the current shell environment. A redirection error causes the | |
1947 | command to exit with a non-zero status. | |
1948 | ||
1949 | If there is a command name left after expansion, execution proceeds | |
1950 | as described below. Otherwise, the command exits. If one of the | |
1951 | expansions contained a command substitution, the exit status of the | |
1952 | command is the exit status of the last command substitution performed. | |
1953 | If there were no command substitutions, the command exits with a status | |
1954 | of zero. | |
1955 | ||
1956 | \1f | |
1957 | File: bashref.info, Node: Command Search and Execution, Next: Command Execution Environment, Prev: Simple Command Expansion, Up: Executing Commands | |
ccc6cda3 | 1958 | |
761783bf CR |
1959 | 3.7.2 Command Search and Execution |
1960 | ---------------------------------- | |
ccc6cda3 | 1961 | |
761783bf | 1962 | After a command has been split into words, if it results in a simple |
ccc6cda3 JA |
1963 | command and an optional list of arguments, the following actions are |
1964 | taken. | |
1965 | ||
1966 | 1. If the command name contains no slashes, the shell attempts to | |
1967 | locate it. If there exists a shell function by that name, that | |
bb70624e | 1968 | function is invoked as described in *Note Shell Functions::. |
ccc6cda3 JA |
1969 | |
1970 | 2. If the name does not match a function, the shell searches for it | |
1971 | in the list of shell builtins. If a match is found, that builtin | |
1972 | is invoked. | |
1973 | ||
1974 | 3. If the name is neither a shell function nor a builtin, and | |
1975 | contains no slashes, Bash searches each element of `$PATH' for a | |
1976 | directory containing an executable file by that name. Bash uses a | |
cce855bc JA |
1977 | hash table to remember the full pathnames of executable files to |
1978 | avoid multiple `PATH' searches (see the description of `hash' in | |
1979 | *Note Bourne Shell Builtins::). A full search of the directories | |
ccc6cda3 JA |
1980 | in `$PATH' is performed only if the command is not found in the |
1981 | hash table. If the search is unsuccessful, the shell prints an | |
cce855bc | 1982 | error message and returns an exit status of 127. |
ccc6cda3 JA |
1983 | |
1984 | 4. If the search is successful, or if the command name contains one | |
cce855bc JA |
1985 | or more slashes, the shell executes the named program in a |
1986 | separate execution environment. Argument 0 is set to the name | |
1987 | given, and the remaining arguments to the command are set to the | |
1988 | arguments supplied, if any. | |
ccc6cda3 JA |
1989 | |
1990 | 5. If this execution fails because the file is not in executable | |
cce855bc JA |
1991 | format, and the file is not a directory, it is assumed to be a |
1992 | SHELL SCRIPT and the shell executes it as described in *Note Shell | |
1993 | Scripts::. | |
1994 | ||
1995 | 6. If the command was not begun asynchronously, the shell waits for | |
1996 | the command to complete and collects its exit status. | |
1997 | ||
1998 | ||
1999 | \1f | |
2000 | File: bashref.info, Node: Command Execution Environment, Next: Environment, Prev: Command Search and Execution, Up: Executing Commands | |
2001 | ||
761783bf CR |
2002 | 3.7.3 Command Execution Environment |
2003 | ----------------------------------- | |
cce855bc | 2004 | |
761783bf | 2005 | The shell has an EXECUTION ENVIRONMENT, which consists of the following: |
cce855bc JA |
2006 | |
2007 | * open files inherited by the shell at invocation, as modified by | |
2008 | redirections supplied to the `exec' builtin | |
2009 | ||
2010 | * the current working directory as set by `cd', `pushd', or `popd', | |
2011 | or inherited by the shell at invocation | |
2012 | ||
2013 | * the file creation mode mask as set by `umask' or inherited from | |
2014 | the shell's parent | |
2015 | ||
2016 | * current traps set by `trap' | |
2017 | ||
2018 | * shell parameters that are set by variable assignment or with `set' | |
2019 | or inherited from the shell's parent in the environment | |
2020 | ||
2021 | * shell functions defined during execution or inherited from the | |
2022 | shell's parent in the environment | |
2023 | ||
2024 | * options enabled at invocation (either by default or with | |
2025 | command-line arguments) or by `set' | |
2026 | ||
2027 | * options enabled by `shopt' | |
2028 | ||
28ef6c31 | 2029 | * shell aliases defined with `alias' (*note Aliases::) |
cce855bc JA |
2030 | |
2031 | * various process IDs, including those of background jobs (*note | |
28ef6c31 JA |
2032 | Lists::), the value of `$$', and the value of `$PPID' |
2033 | ||
cce855bc JA |
2034 | |
2035 | When a simple command other than a builtin or shell function is to | |
2036 | be executed, it is invoked in a separate execution environment that | |
2037 | consists of the following. Unless otherwise noted, the values are | |
2038 | inherited from the shell. | |
2039 | ||
2040 | * the shell's open files, plus any modifications and additions | |
2041 | specified by redirections to the command | |
2042 | ||
2043 | * the current working directory | |
2044 | ||
2045 | * the file creation mode mask | |
2046 | ||
d3a24ed2 CR |
2047 | * shell variables and functions marked for export, along with |
2048 | variables exported for the command, passed in the environment | |
2049 | (*note Environment::) | |
cce855bc JA |
2050 | |
2051 | * traps caught by the shell are reset to the values inherited from | |
2052 | the shell's parent, and traps ignored by the shell are ignored | |
2053 | ||
28ef6c31 | 2054 | |
cce855bc JA |
2055 | A command invoked in this separate environment cannot affect the |
2056 | shell's execution environment. | |
2057 | ||
d3a24ed2 CR |
2058 | Command substitution, commands grouped with parentheses, and |
2059 | asynchronous commands are invoked in a subshell environment that is a | |
2060 | duplicate of the shell environment, except that traps caught by the | |
2061 | shell are reset to the values that the shell inherited from its parent | |
2062 | at invocation. Builtin commands that are invoked as part of a pipeline | |
2063 | are also executed in a subshell environment. Changes made to the | |
2064 | subshell environment cannot affect the shell's execution environment. | |
ccc6cda3 | 2065 | |
f73dda09 JA |
2066 | If a command is followed by a `&' and job control is not active, the |
2067 | default standard input for the command is the empty file `/dev/null'. | |
2068 | Otherwise, the invoked command inherits the file descriptors of the | |
2069 | calling shell as modified by redirections. | |
2070 | ||
ccc6cda3 | 2071 | \1f |
cce855bc | 2072 | File: bashref.info, Node: Environment, Next: Exit Status, Prev: Command Execution Environment, Up: Executing Commands |
ccc6cda3 | 2073 | |
761783bf CR |
2074 | 3.7.4 Environment |
2075 | ----------------- | |
ccc6cda3 | 2076 | |
761783bf | 2077 | When a program is invoked it is given an array of strings called the |
ccc6cda3 JA |
2078 | ENVIRONMENT. This is a list of name-value pairs, of the form |
2079 | `name=value'. | |
2080 | ||
bb70624e | 2081 | Bash provides several ways to manipulate the environment. On |
ccc6cda3 JA |
2082 | invocation, the shell scans its own environment and creates a parameter |
2083 | for each name found, automatically marking it for EXPORT to child | |
2084 | processes. Executed commands inherit the environment. The `export' | |
2085 | and `declare -x' commands allow parameters and functions to be added to | |
2086 | and deleted from the environment. If the value of a parameter in the | |
2087 | environment is modified, the new value becomes part of the environment, | |
2088 | replacing the old. The environment inherited by any executed command | |
2089 | consists of the shell's initial environment, whose values may be | |
cce855bc JA |
2090 | modified in the shell, less any pairs removed by the `unset' and |
2091 | `export -n' commands, plus any additions via the `export' and `declare | |
2092 | -x' commands. | |
ccc6cda3 JA |
2093 | |
2094 | The environment for any simple command or function may be augmented | |
2095 | temporarily by prefixing it with parameter assignments, as described in | |
2096 | *Note Shell Parameters::. These assignment statements affect only the | |
2097 | environment seen by that command. | |
2098 | ||
28ef6c31 | 2099 | If the `-k' option is set (*note The Set Builtin::), then all |
ccc6cda3 JA |
2100 | parameter assignments are placed in the environment for a command, not |
2101 | just those that precede the command name. | |
2102 | ||
2103 | When Bash invokes an external command, the variable `$_' is set to | |
2104 | the full path name of the command and passed to that command in its | |
2105 | environment. | |
2106 | ||
2107 | \1f | |
2108 | File: bashref.info, Node: Exit Status, Next: Signals, Prev: Environment, Up: Executing Commands | |
2109 | ||
761783bf CR |
2110 | 3.7.5 Exit Status |
2111 | ----------------- | |
ccc6cda3 | 2112 | |
761783bf CR |
2113 | For the shell's purposes, a command which exits with a zero exit status |
2114 | has succeeded. A non-zero exit status indicates failure. This | |
cce855bc JA |
2115 | seemingly counter-intuitive scheme is used so there is one well-defined |
2116 | way to indicate success and a variety of ways to indicate various | |
2117 | failure modes. When a command terminates on a fatal signal whose | |
2118 | number is N, Bash uses the value 128+N as the exit status. | |
ccc6cda3 JA |
2119 | |
2120 | If a command is not found, the child process created to execute it | |
2121 | returns a status of 127. If a command is found but is not executable, | |
2122 | the return status is 126. | |
2123 | ||
cce855bc JA |
2124 | If a command fails because of an error during expansion or |
2125 | redirection, the exit status is greater than zero. | |
2126 | ||
ccc6cda3 | 2127 | The exit status is used by the Bash conditional commands (*note |
28ef6c31 JA |
2128 | Conditional Constructs::) and some of the list constructs (*note |
2129 | Lists::). | |
ccc6cda3 JA |
2130 | |
2131 | All of the Bash builtins return an exit status of zero if they | |
2132 | succeed and a non-zero status on failure, so they may be used by the | |
cce855bc JA |
2133 | conditional and list constructs. All builtins return an exit status of |
2134 | 2 to indicate incorrect usage. | |
ccc6cda3 JA |
2135 | |
2136 | \1f | |
2137 | File: bashref.info, Node: Signals, Prev: Exit Status, Up: Executing Commands | |
2138 | ||
761783bf CR |
2139 | 3.7.6 Signals |
2140 | ------------- | |
ccc6cda3 | 2141 | |
761783bf | 2142 | When Bash is interactive, in the absence of any traps, it ignores |
cce855bc JA |
2143 | `SIGTERM' (so that `kill 0' does not kill an interactive shell), and |
2144 | `SIGINT' is caught and handled (so that the `wait' builtin is | |
2145 | interruptible). When Bash receives a `SIGINT', it breaks out of any | |
2146 | executing loops. In all cases, Bash ignores `SIGQUIT'. If job control | |
28ef6c31 | 2147 | is in effect (*note Job Control::), Bash ignores `SIGTTIN', `SIGTTOU', |
cce855bc | 2148 | and `SIGTSTP'. |
ccc6cda3 | 2149 | |
5e13499c CR |
2150 | Non-builtin commands started by Bash have signal handlers set to the |
2151 | values inherited by the shell from its parent. When job control is not | |
2152 | in effect, asynchronous commands ignore `SIGINT' and `SIGQUIT' in | |
2153 | addition to these inherited handlers. Commands run as a result of | |
2154 | command substitution ignore the keyboard-generated job control signals | |
2155 | `SIGTTIN', `SIGTTOU', and `SIGTSTP'. | |
ccc6cda3 JA |
2156 | |
2157 | The shell exits by default upon receipt of a `SIGHUP'. Before | |
f73dda09 JA |
2158 | exiting, an interactive shell resends the `SIGHUP' to all jobs, running |
2159 | or stopped. Stopped jobs are sent `SIGCONT' to ensure that they receive | |
2160 | the `SIGHUP'. To prevent the shell from sending the `SIGHUP' signal to | |
2161 | a particular job, it should be removed from the jobs table with the | |
28ef6c31 | 2162 | `disown' builtin (*note Job Control Builtins::) or marked to not |
cce855bc JA |
2163 | receive `SIGHUP' using `disown -h'. |
2164 | ||
2165 | If the `huponexit' shell option has been set with `shopt' (*note | |
28ef6c31 JA |
2166 | Bash Builtins::), Bash sends a `SIGHUP' to all jobs when an interactive |
2167 | login shell exits. | |
cce855bc | 2168 | |
5e13499c CR |
2169 | If Bash is waiting for a command to complete and receives a signal |
2170 | for which a trap has been set, the trap will not be executed until the | |
2171 | command completes. When Bash is waiting for an asynchronous command | |
2172 | via the `wait' builtin, the reception of a signal for which a trap has | |
2173 | been set will cause the `wait' builtin to return immediately with an | |
2174 | exit status greater than 128, immediately after which the trap is | |
2175 | executed. | |
ccc6cda3 JA |
2176 | |
2177 | \1f | |
2178 | File: bashref.info, Node: Shell Scripts, Prev: Executing Commands, Up: Basic Shell Features | |
2179 | ||
761783bf CR |
2180 | 3.8 Shell Scripts |
2181 | ================= | |
ccc6cda3 | 2182 | |
761783bf CR |
2183 | A shell script is a text file containing shell commands. When such a |
2184 | file is used as the first non-option argument when invoking Bash, and | |
28ef6c31 | 2185 | neither the `-c' nor `-s' option is supplied (*note Invoking Bash::), |
ccc6cda3 | 2186 | Bash reads and executes commands from the file, then exits. This mode |
f73dda09 JA |
2187 | of operation creates a non-interactive shell. The shell first searches |
2188 | for the file in the current directory, and looks in the directories in | |
2189 | `$PATH' if not found there. | |
2190 | ||
2191 | When Bash runs a shell script, it sets the special parameter `0' to | |
2192 | the name of the file, rather than the name of the shell, and the | |
2193 | positional parameters are set to the remaining arguments, if any are | |
2194 | given. If no additional arguments are supplied, the positional | |
2195 | parameters are unset. | |
ccc6cda3 JA |
2196 | |
2197 | A shell script may be made executable by using the `chmod' command | |
2198 | to turn on the execute bit. When Bash finds such a file while | |
2199 | searching the `$PATH' for a command, it spawns a subshell to execute | |
2200 | it. In other words, executing | |
2201 | filename ARGUMENTS | |
761783bf | 2202 | is equivalent to executing |
ccc6cda3 JA |
2203 | bash filename ARGUMENTS |
2204 | ||
2205 | if `filename' is an executable shell script. This subshell | |
2206 | reinitializes itself, so that the effect is as if a new shell had been | |
cce855bc JA |
2207 | invoked to interpret the script, with the exception that the locations |
2208 | of commands remembered by the parent (see the description of `hash' in | |
2209 | *Note Bourne Shell Builtins::) are retained by the child. | |
ccc6cda3 | 2210 | |
bb70624e JA |
2211 | Most versions of Unix make this a part of the operating system's |
2212 | command execution mechanism. If the first line of a script begins with | |
2213 | the two characters `#!', the remainder of the line specifies an | |
2214 | interpreter for the program. Thus, you can specify Bash, `awk', Perl, | |
2215 | or some other interpreter and write the rest of the script file in that | |
2216 | language. | |
2217 | ||
2218 | The arguments to the interpreter consist of a single optional | |
2219 | argument following the interpreter name on the first line of the script | |
2220 | file, followed by the name of the script file, followed by the rest of | |
2221 | the arguments. Bash will perform this action on operating systems that | |
2222 | do not handle it themselves. Note that some older versions of Unix | |
2223 | limit the interpreter name and argument to a maximum of 32 characters. | |
2224 | ||
2225 | Bash scripts often begin with `#! /bin/bash' (assuming that Bash has | |
2226 | been installed in `/bin'), since this ensures that Bash will be used to | |
2227 | interpret the script, even if it is executed under another shell. | |
ccc6cda3 JA |
2228 | |
2229 | \1f | |
bb70624e | 2230 | File: bashref.info, Node: Shell Builtin Commands, Next: Shell Variables, Prev: Basic Shell Features, Up: Top |
ccc6cda3 | 2231 | |
761783bf CR |
2232 | 4 Shell Builtin Commands |
2233 | ************************ | |
ccc6cda3 JA |
2234 | |
2235 | * Menu: | |
2236 | ||
2237 | * Bourne Shell Builtins:: Builtin commands inherited from the Bourne | |
2238 | Shell. | |
bb70624e JA |
2239 | * Bash Builtins:: Table of builtins specific to Bash. |
2240 | * The Set Builtin:: This builtin is so overloaded it | |
2241 | deserves its own section. | |
2242 | * Special Builtins:: Builtin commands classified specially by | |
2243 | POSIX.2. | |
2244 | ||
2245 | Builtin commands are contained within the shell itself. When the | |
2246 | name of a builtin command is used as the first word of a simple command | |
28ef6c31 | 2247 | (*note Simple Commands::), the shell executes the command directly, |
bb70624e JA |
2248 | without invoking another program. Builtin commands are necessary to |
2249 | implement functionality impossible or inconvenient to obtain with | |
2250 | separate utilities. | |
ccc6cda3 | 2251 | |
bb70624e JA |
2252 | This section briefly the builtins which Bash inherits from the |
2253 | Bourne Shell, as well as the builtin commands which are unique to or | |
2254 | have been extended in Bash. | |
2255 | ||
2256 | Several builtin commands are described in other chapters: builtin | |
2257 | commands which provide the Bash interface to the job control facilities | |
28ef6c31 JA |
2258 | (*note Job Control Builtins::), the directory stack (*note Directory |
2259 | Stack Builtins::), the command history (*note Bash History Builtins::), | |
2260 | and the programmable completion facilities (*note Programmable | |
2261 | Completion Builtins::). | |
bb70624e JA |
2262 | |
2263 | Many of the builtins have been extended by POSIX or Bash. | |
ccc6cda3 | 2264 | |
c2258e1c CR |
2265 | Unless otherwise noted, each builtin command documented as accepting |
2266 | options preceded by `-' accepts `--' to signify the end of the options. | |
2267 | ||
ccc6cda3 | 2268 | \1f |
bb70624e | 2269 | File: bashref.info, Node: Bourne Shell Builtins, Next: Bash Builtins, Up: Shell Builtin Commands |
ccc6cda3 | 2270 | |
761783bf CR |
2271 | 4.1 Bourne Shell Builtins |
2272 | ========================= | |
ccc6cda3 | 2273 | |
761783bf | 2274 | The following shell builtin commands are inherited from the Bourne |
ccc6cda3 JA |
2275 | Shell. These commands are implemented as specified by the POSIX 1003.2 |
2276 | standard. | |
2277 | ||
bb70624e | 2278 | `: (a colon)' |
ccc6cda3 JA |
2279 | : [ARGUMENTS] |
2280 | Do nothing beyond expanding ARGUMENTS and performing redirections. | |
cce855bc | 2281 | The return status is zero. |
ccc6cda3 | 2282 | |
bb70624e | 2283 | `. (a period)' |
b72432fd | 2284 | . FILENAME [ARGUMENTS] |
ccc6cda3 | 2285 | Read and execute commands from the FILENAME argument in the |
cce855bc | 2286 | current shell context. If FILENAME does not contain a slash, the |
28ef6c31 JA |
2287 | `PATH' variable is used to find FILENAME. When Bash is not in |
2288 | POSIX mode, the current directory is searched if FILENAME is not | |
2289 | found in `$PATH'. If any ARGUMENTS are supplied, they become the | |
2290 | positional parameters when FILENAME is executed. Otherwise the | |
2291 | positional parameters are unchanged. The return status is the | |
2292 | exit status of the last command executed, or zero if no commands | |
2293 | are executed. If FILENAME is not found, or cannot be read, the | |
2294 | return status is non-zero. This builtin is equivalent to `source'. | |
ccc6cda3 JA |
2295 | |
2296 | `break' | |
2297 | break [N] | |
2298 | Exit from a `for', `while', `until', or `select' loop. If N is | |
cce855bc JA |
2299 | supplied, the Nth enclosing loop is exited. N must be greater |
2300 | than or equal to 1. The return status is zero unless N is not | |
2301 | greater than or equal to 1. | |
ccc6cda3 JA |
2302 | |
2303 | `cd' | |
7117c2d2 | 2304 | cd [-L|-P] [DIRECTORY] |
ccc6cda3 JA |
2305 | Change the current working directory to DIRECTORY. If DIRECTORY |
2306 | is not given, the value of the `HOME' shell variable is used. If | |
2307 | the shell variable `CDPATH' exists, it is used as a search path. | |
d3a24ed2 CR |
2308 | If DIRECTORY begins with a slash, `CDPATH' is not used. |
2309 | ||
2310 | The `-P' option means to not follow symbolic links; symbolic links | |
2311 | are followed by default or with the `-L' option. If DIRECTORY is | |
2312 | `-', it is equivalent to `$OLDPWD'. | |
2313 | ||
2314 | If a non-empty directory name from `CDPATH' is used, or if `-' is | |
2315 | the first argument, and the directory change is successful, the | |
2316 | absolute pathname of the new working directory is written to the | |
2317 | standard output. | |
2318 | ||
2319 | The return status is zero if the directory is successfully changed, | |
2320 | non-zero otherwise. | |
ccc6cda3 JA |
2321 | |
2322 | `continue' | |
2323 | continue [N] | |
2324 | Resume the next iteration of an enclosing `for', `while', `until', | |
2325 | or `select' loop. If N is supplied, the execution of the Nth | |
cce855bc JA |
2326 | enclosing loop is resumed. N must be greater than or equal to 1. |
2327 | The return status is zero unless N is not greater than or equal to | |
2328 | 1. | |
ccc6cda3 JA |
2329 | |
2330 | `eval' | |
2331 | eval [ARGUMENTS] | |
2332 | The arguments are concatenated together into a single command, | |
cce855bc JA |
2333 | which is then read and executed, and its exit status returned as |
2334 | the exit status of `eval'. If there are no arguments or only | |
2335 | empty arguments, the return status is zero. | |
ccc6cda3 JA |
2336 | |
2337 | `exec' | |
cce855bc JA |
2338 | exec [-cl] [-a NAME] [COMMAND [ARGUMENTS]] |
2339 | If COMMAND is supplied, it replaces the shell without creating a | |
2340 | new process. If the `-l' option is supplied, the shell places a | |
bb70624e JA |
2341 | dash at the beginning of the zeroth arg passed to COMMAND. This |
2342 | is what the `login' program does. The `-c' option causes COMMAND | |
2343 | to be executed with an empty environment. If `-a' is supplied, | |
2344 | the shell passes NAME as the zeroth argument to COMMAND. If no | |
cce855bc JA |
2345 | COMMAND is specified, redirections may be used to affect the |
2346 | current shell environment. If there are no redirection errors, the | |
2347 | return status is zero; otherwise the return status is non-zero. | |
ccc6cda3 JA |
2348 | |
2349 | `exit' | |
2350 | exit [N] | |
bb70624e JA |
2351 | Exit the shell, returning a status of N to the shell's parent. If |
2352 | N is omitted, the exit status is that of the last command executed. | |
cce855bc | 2353 | Any trap on `EXIT' is executed before the shell terminates. |
ccc6cda3 JA |
2354 | |
2355 | `export' | |
2356 | export [-fn] [-p] [NAME[=VALUE]] | |
2357 | Mark each NAME to be passed to child processes in the environment. | |
2358 | If the `-f' option is supplied, the NAMEs refer to shell | |
cce855bc JA |
2359 | functions; otherwise the names refer to shell variables. The `-n' |
2360 | option means to no longer mark each NAME for export. If no NAMES | |
2361 | are supplied, or if the `-p' option is given, a list of exported | |
2362 | names is displayed. The `-p' option displays output in a form | |
d3a24ed2 CR |
2363 | that may be reused as input. If a variable name is followed by |
2364 | =VALUE, the value of the variable is set to VALUE. | |
2365 | ||
2366 | The return status is zero unless an invalid option is supplied, | |
2367 | one of the names is not a valid shell variable name, or `-f' is | |
2368 | supplied with a name that is not a shell function. | |
ccc6cda3 JA |
2369 | |
2370 | `getopts' | |
2371 | getopts OPTSTRING NAME [ARGS] | |
2372 | `getopts' is used by shell scripts to parse positional parameters. | |
bb70624e JA |
2373 | OPTSTRING contains the option characters to be recognized; if a |
2374 | character is followed by a colon, the option is expected to have an | |
2375 | argument, which should be separated from it by white space. The | |
2376 | colon (`:') and question mark (`?') may not be used as option | |
2377 | characters. Each time it is invoked, `getopts' places the next | |
2378 | option in the shell variable NAME, initializing NAME if it does | |
2379 | not exist, and the index of the next argument to be processed into | |
2380 | the variable `OPTIND'. `OPTIND' is initialized to 1 each time the | |
2381 | shell or a shell script is invoked. When an option requires an | |
2382 | argument, `getopts' places that argument into the variable | |
2383 | `OPTARG'. The shell does not reset `OPTIND' automatically; it | |
2384 | must be manually reset between multiple calls to `getopts' within | |
2385 | the same shell invocation if a new set of parameters is to be used. | |
ccc6cda3 | 2386 | |
cce855bc JA |
2387 | When the end of options is encountered, `getopts' exits with a |
2388 | return value greater than zero. `OPTIND' is set to the index of | |
2389 | the first non-option argument, and `name' is set to `?'. | |
2390 | ||
2391 | `getopts' normally parses the positional parameters, but if more | |
2392 | arguments are given in ARGS, `getopts' parses those instead. | |
2393 | ||
ccc6cda3 JA |
2394 | `getopts' can report errors in two ways. If the first character of |
2395 | OPTSTRING is a colon, SILENT error reporting is used. In normal | |
cce855bc | 2396 | operation diagnostic messages are printed when invalid options or |
ccc6cda3 | 2397 | missing option arguments are encountered. If the variable `OPTERR' |
cce855bc | 2398 | is set to 0, no error messages will be displayed, even if the first |
ccc6cda3 JA |
2399 | character of `optstring' is not a colon. |
2400 | ||
cce855bc | 2401 | If an invalid option is seen, `getopts' places `?' into NAME and, |
ccc6cda3 JA |
2402 | if not silent, prints an error message and unsets `OPTARG'. If |
2403 | `getopts' is silent, the option character found is placed in | |
2404 | `OPTARG' and no diagnostic message is printed. | |
2405 | ||
2406 | If a required argument is not found, and `getopts' is not silent, | |
2407 | a question mark (`?') is placed in NAME, `OPTARG' is unset, and a | |
2408 | diagnostic message is printed. If `getopts' is silent, then a | |
2409 | colon (`:') is placed in NAME and `OPTARG' is set to the option | |
2410 | character found. | |
2411 | ||
ccc6cda3 | 2412 | `hash' |
7117c2d2 | 2413 | hash [-'r] [-p FILENAME] [-dt] [NAME] |
cce855bc JA |
2414 | Remember the full pathnames of commands specified as NAME |
2415 | arguments, so they need not be searched for on subsequent | |
2416 | invocations. The commands are found by searching through the | |
2417 | directories listed in `$PATH'. The `-p' option inhibits the path | |
2418 | search, and FILENAME is used as the location of NAME. The `-r' | |
7117c2d2 JA |
2419 | option causes the shell to forget all remembered locations. The |
2420 | `-d' option causes the shell to forget the remembered location of | |
2421 | each NAME. If the `-t' option is supplied, the full pathname to | |
2422 | which each NAME corresponds is printed. If multiple NAME | |
2423 | arguments are supplied with `-t' the NAME is printed before the | |
2424 | hashed full pathname. The `-l' option causes output to be | |
2425 | displayed in a format that may be reused as input. If no | |
2426 | arguments are given, or if only `-l' is supplied, information | |
2427 | about remembered commands is printed. The return status is zero | |
2428 | unless a NAME is not found or an invalid option is supplied. | |
ccc6cda3 JA |
2429 | |
2430 | `pwd' | |
2431 | pwd [-LP] | |
bb70624e JA |
2432 | Print the absolute pathname of the current working directory. If |
2433 | the `-P' option is supplied, the pathname printed will not contain | |
2434 | symbolic links. If the `-L' option is supplied, the pathname | |
2435 | printed may contain symbolic links. The return status is zero | |
2436 | unless an error is encountered while determining the name of the | |
2437 | current directory or an invalid option is supplied. | |
ccc6cda3 JA |
2438 | |
2439 | `readonly' | |
d3a24ed2 | 2440 | readonly [-apf] [NAME[=VALUE]] ... |
cce855bc JA |
2441 | Mark each NAME as readonly. The values of these names may not be |
2442 | changed by subsequent assignment. If the `-f' option is supplied, | |
2443 | each NAME refers to a shell function. The `-a' option means each | |
2444 | NAME refers to an array variable. If no NAME arguments are given, | |
2445 | or if the `-p' option is supplied, a list of all readonly names is | |
2446 | printed. The `-p' option causes output to be displayed in a | |
d3a24ed2 CR |
2447 | format that may be reused as input. If a variable name is |
2448 | followed by =VALUE, the value of the variable is set to VALUE. | |
2449 | The return status is zero unless an invalid option is supplied, | |
2450 | one of the NAME arguments is not a valid shell variable or | |
2451 | function name, or the `-f' option is supplied with a name that is | |
2452 | not a shell function. | |
ccc6cda3 JA |
2453 | |
2454 | `return' | |
2455 | return [N] | |
bb70624e JA |
2456 | Cause a shell function to exit with the return value N. If N is |
2457 | not supplied, the return value is the exit status of the last | |
2458 | command executed in the function. This may also be used to | |
2459 | terminate execution of a script being executed with the `.' (or | |
2460 | `source') builtin, returning either N or the exit status of the | |
cce855bc | 2461 | last command executed within the script as the exit status of the |
d3a24ed2 CR |
2462 | script. Any command associated with the `RETURN' trap is executed |
2463 | before execution resumes after the function or script. The return | |
2464 | status is non-zero if `return' is used outside a function and not | |
2465 | during the execution of a script by `.' or `source'. | |
ccc6cda3 JA |
2466 | |
2467 | `shift' | |
2468 | shift [N] | |
cce855bc JA |
2469 | Shift the positional parameters to the left by N. The positional |
2470 | parameters from N+1 ... `$#' are renamed to `$1' ... `$#'-N+1. | |
2471 | Parameters represented by the numbers `$#' to N+1 are unset. N | |
2472 | must be a non-negative number less than or equal to `$#'. If N is | |
2473 | zero or greater than `$#', the positional parameters are not | |
bb70624e JA |
2474 | changed. If N is not supplied, it is assumed to be 1. The return |
2475 | status is zero unless N is greater than `$#' or less than zero, | |
2476 | non-zero otherwise. | |
ccc6cda3 JA |
2477 | |
2478 | `test' | |
2479 | `[' | |
cce855bc JA |
2480 | Evaluate a conditional expression EXPR. Each operator and operand |
2481 | must be a separate argument. Expressions are composed of the | |
2482 | primaries described below in *Note Bash Conditional Expressions::. | |
2483 | ||
bb70624e JA |
2484 | When the `[' form is used, the last argument to the command must |
2485 | be a `]'. | |
2486 | ||
cce855bc JA |
2487 | Expressions may be combined using the following operators, listed |
2488 | in decreasing order of precedence. | |
2489 | ||
2490 | `! EXPR' | |
2491 | True if EXPR is false. | |
2492 | ||
2493 | `( EXPR )' | |
2494 | Returns the value of EXPR. This may be used to override the | |
2495 | normal precedence of operators. | |
2496 | ||
2497 | `EXPR1 -a EXPR2' | |
2498 | True if both EXPR1 and EXPR2 are true. | |
2499 | ||
2500 | `EXPR1 -o EXPR2' | |
2501 | True if either EXPR1 or EXPR2 is true. | |
2502 | ||
2503 | The `test' and `[' builtins evaluate conditional expressions using | |
2504 | a set of rules based on the number of arguments. | |
2505 | ||
2506 | 0 arguments | |
2507 | The expression is false. | |
2508 | ||
2509 | 1 argument | |
2510 | The expression is true if and only if the argument is not | |
2511 | null. | |
2512 | ||
2513 | 2 arguments | |
2514 | If the first argument is `!', the expression is true if and | |
2515 | only if the second argument is null. If the first argument | |
2516 | is one of the unary conditional operators (*note Bash | |
28ef6c31 | 2517 | Conditional Expressions::), the expression is true if the |
cce855bc JA |
2518 | unary test is true. If the first argument is not a valid |
2519 | unary operator, the expression is false. | |
2520 | ||
2521 | 3 arguments | |
2522 | If the second argument is one of the binary conditional | |
28ef6c31 | 2523 | operators (*note Bash Conditional Expressions::), the result |
cce855bc JA |
2524 | of the expression is the result of the binary test using the |
2525 | first and third arguments as operands. If the first argument | |
2526 | is `!', the value is the negation of the two-argument test | |
2527 | using the second and third arguments. If the first argument | |
2528 | is exactly `(' and the third argument is exactly `)', the | |
2529 | result is the one-argument test of the second argument. | |
2530 | Otherwise, the expression is false. The `-a' and `-o' | |
2531 | operators are considered binary operators in this case. | |
2532 | ||
2533 | 4 arguments | |
2534 | If the first argument is `!', the result is the negation of | |
2535 | the three-argument expression composed of the remaining | |
2536 | arguments. Otherwise, the expression is parsed and evaluated | |
2537 | according to precedence using the rules listed above. | |
2538 | ||
2539 | 5 or more arguments | |
2540 | The expression is parsed and evaluated according to precedence | |
2541 | using the rules listed above. | |
ccc6cda3 JA |
2542 | |
2543 | `times' | |
2544 | times | |
2545 | Print out the user and system times used by the shell and its | |
cce855bc | 2546 | children. The return status is zero. |
ccc6cda3 JA |
2547 | |
2548 | `trap' | |
d166f048 | 2549 | trap [-lp] [ARG] [SIGSPEC ...] |
ccc6cda3 | 2550 | The commands in ARG are to be read and executed when the shell |
9f422431 CR |
2551 | receives signal SIGSPEC. If ARG is absent (and there is a single |
2552 | SIGSPEC) or equal to `-', each specified signal's disposition is | |
2553 | reset to the value it had when the shell was started. If ARG is | |
2554 | the null string, then the signal specified by each SIGSPEC is | |
2555 | ignored by the shell and commands it invokes. If ARG is not | |
2556 | present and `-p' has been supplied, the shell displays the trap | |
2557 | commands associated with each SIGSPEC. If no arguments are | |
2558 | supplied, or only `-p' is given, `trap' prints the list of commands | |
2559 | associated with each signal number in a form that may be reused as | |
2560 | shell input. The `-l' option causes the shell to print a list of | |
2561 | signal names and their corresponding numbers. Each SIGSPEC is | |
2562 | either a signal name or a signal number. Signal names are case | |
2563 | insensitive and the `SIG' prefix is optional. If a SIGSPEC is `0' | |
d3a24ed2 CR |
2564 | or `EXIT', ARG is executed when the shell exits. If a SIGSPEC is |
2565 | `DEBUG', the command ARG is executed before every simple command, | |
2566 | `for' command, `case' command, `select' command, every arithmetic | |
2567 | `for' command, and before the first command executes in a shell | |
2568 | function. Refer to the description of the `extglob' option to the | |
2569 | `shopt' builtin (*note Bash Builtins::) for details of its effect | |
2570 | on the `DEBUG' trap. If a SIGSPEC is `ERR', the command ARG is | |
5e13499c CR |
2571 | executed whenever a simple command has a non-zero exit status, |
2572 | subject to the following conditions. The `ERR' trap is not | |
2573 | executed if the failed command is part of the command list | |
2574 | immediately following an `until' or `while' keyword, part of the | |
2575 | test in an `if' statement, part of a `&&' or `||' list, or if the | |
2576 | command's return status is being inverted using `!'. These are | |
2577 | the same conditions obeyed by the `errexit' option. If a SIGSPEC | |
2578 | is `RETURN', the command ARG is executed each time a shell | |
2579 | function or a script executed with the `.' or `source' builtins | |
2580 | finishes executing. | |
d3a24ed2 | 2581 | |
ccc6cda3 JA |
2582 | Signals ignored upon entry to the shell cannot be trapped or reset. |
2583 | Trapped signals are reset to their original values in a child | |
2584 | process when it is created. | |
2585 | ||
cce855bc JA |
2586 | The return status is zero unless a SIGSPEC does not specify a |
2587 | valid signal. | |
2588 | ||
ccc6cda3 | 2589 | `umask' |
cce855bc | 2590 | umask [-p] [-S] [MODE] |
ccc6cda3 JA |
2591 | Set the shell process's file creation mask to MODE. If MODE |
2592 | begins with a digit, it is interpreted as an octal number; if not, | |
2593 | it is interpreted as a symbolic mode mask similar to that accepted | |
2594 | by the `chmod' command. If MODE is omitted, the current value of | |
2595 | the mask is printed. If the `-S' option is supplied without a | |
cce855bc JA |
2596 | MODE argument, the mask is printed in a symbolic format. If the |
2597 | `-p' option is supplied, and MODE is omitted, the output is in a | |
2598 | form that may be reused as input. The return status is zero if | |
2599 | the mode is successfully changed or if no MODE argument is | |
2600 | supplied, and non-zero otherwise. | |
ccc6cda3 | 2601 | |
bb70624e JA |
2602 | Note that when the mode is interpreted as an octal number, each |
2603 | number of the umask is subtracted from `7'. Thus, a umask of `022' | |
2604 | results in permissions of `755'. | |
2605 | ||
ccc6cda3 JA |
2606 | `unset' |
2607 | unset [-fv] [NAME] | |
2608 | Each variable or function NAME is removed. If no options are | |
2609 | supplied, or the `-v' option is given, each NAME refers to a shell | |
2610 | variable. If the `-f' option is given, the NAMEs refer to shell | |
cce855bc JA |
2611 | functions, and the function definition is removed. Readonly |
2612 | variables and functions may not be unset. The return status is | |
d3a24ed2 | 2613 | zero unless a NAME is readonly. |
ccc6cda3 JA |
2614 | |
2615 | \1f | |
bb70624e | 2616 | File: bashref.info, Node: Bash Builtins, Next: The Set Builtin, Prev: Bourne Shell Builtins, Up: Shell Builtin Commands |
ccc6cda3 | 2617 | |
761783bf CR |
2618 | 4.2 Bash Builtin Commands |
2619 | ========================= | |
ccc6cda3 | 2620 | |
761783bf | 2621 | This section describes builtin commands which are unique to or have |
bb70624e JA |
2622 | been extended in Bash. Some of these commands are specified in the |
2623 | POSIX 1003.2 standard. | |
ccc6cda3 | 2624 | |
bb70624e JA |
2625 | `alias' |
2626 | alias [`-p'] [NAME[=VALUE] ...] | |
ccc6cda3 | 2627 | |
bb70624e JA |
2628 | Without arguments or with the `-p' option, `alias' prints the list |
2629 | of aliases on the standard output in a form that allows them to be | |
2630 | reused as input. If arguments are supplied, an alias is defined | |
2631 | for each NAME whose VALUE is given. If no VALUE is given, the name | |
2632 | and value of the alias is printed. Aliases are described in *Note | |
2633 | Aliases::. | |
ccc6cda3 | 2634 | |
bb70624e JA |
2635 | `bind' |
2636 | bind [-m KEYMAP] [-lpsvPSV] | |
2637 | bind [-m KEYMAP] [-q FUNCTION] [-u FUNCTION] [-r KEYSEQ] | |
2638 | bind [-m KEYMAP] -f FILENAME | |
2639 | bind [-m KEYMAP] -x KEYSEQ:SHELL-COMMAND | |
2640 | bind [-m KEYMAP] KEYSEQ:FUNCTION-NAME | |
7117c2d2 | 2641 | bind READLINE-COMMAND |
ccc6cda3 | 2642 | |
28ef6c31 | 2643 | Display current Readline (*note Command Line Editing::) key and |
7117c2d2 JA |
2644 | function bindings, bind a key sequence to a Readline function or |
2645 | macro, or set a Readline variable. Each non-option argument is a | |
2646 | command as it would appear in a a Readline initialization file | |
2647 | (*note Readline Init File::), but each binding or command must be | |
2648 | passed as a separate argument; e.g., | |
bb70624e JA |
2649 | `"\C-x\C-r":re-read-init-file'. Options, if supplied, have the |
2650 | following meanings: | |
ccc6cda3 | 2651 | |
bb70624e JA |
2652 | `-m KEYMAP' |
2653 | Use KEYMAP as the keymap to be affected by the subsequent | |
2654 | bindings. Acceptable KEYMAP names are `emacs', | |
28ef6c31 | 2655 | `emacs-standard', `emacs-meta', `emacs-ctlx', `vi', `vi-move', |
bb70624e JA |
2656 | `vi-command', and `vi-insert'. `vi' is equivalent to |
2657 | `vi-command'; `emacs' is equivalent to `emacs-standard'. | |
cce855bc | 2658 | |
bb70624e JA |
2659 | `-l' |
2660 | List the names of all Readline functions. | |
cce855bc | 2661 | |
bb70624e JA |
2662 | `-p' |
2663 | Display Readline function names and bindings in such a way | |
2664 | that they can be used as input or in a Readline | |
2665 | initialization file. | |
cce855bc | 2666 | |
bb70624e JA |
2667 | `-P' |
2668 | List current Readline function names and bindings. | |
cce855bc | 2669 | |
bb70624e JA |
2670 | `-v' |
2671 | Display Readline variable names and values in such a way that | |
2672 | they can be used as input or in a Readline initialization | |
2673 | file. | |
ccc6cda3 | 2674 | |
bb70624e JA |
2675 | `-V' |
2676 | List current Readline variable names and values. | |
ccc6cda3 | 2677 | |
bb70624e JA |
2678 | `-s' |
2679 | Display Readline key sequences bound to macros and the | |
2680 | strings they output in such a way that they can be used as | |
2681 | input or in a Readline initialization file. | |
ccc6cda3 | 2682 | |
bb70624e JA |
2683 | `-S' |
2684 | Display Readline key sequences bound to macros and the | |
2685 | strings they output. | |
ccc6cda3 | 2686 | |
bb70624e JA |
2687 | `-f FILENAME' |
2688 | Read key bindings from FILENAME. | |
ccc6cda3 | 2689 | |
bb70624e JA |
2690 | `-q FUNCTION' |
2691 | Query about which keys invoke the named FUNCTION. | |
ccc6cda3 | 2692 | |
bb70624e JA |
2693 | `-u FUNCTION' |
2694 | Unbind all keys bound to the named FUNCTION. | |
ccc6cda3 | 2695 | |
bb70624e JA |
2696 | `-r KEYSEQ' |
2697 | Remove any current binding for KEYSEQ. | |
ccc6cda3 | 2698 | |
bb70624e JA |
2699 | `-x KEYSEQ:SHELL-COMMAND' |
2700 | Cause SHELL-COMMAND to be executed whenever KEYSEQ is entered. | |
ccc6cda3 | 2701 | |
761783bf | 2702 | |
bb70624e JA |
2703 | The return status is zero unless an invalid option is supplied or |
2704 | an error occurs. | |
ccc6cda3 | 2705 | |
bb70624e JA |
2706 | `builtin' |
2707 | builtin [SHELL-BUILTIN [ARGS]] | |
2708 | Run a shell builtin, passing it ARGS, and return its exit status. | |
2709 | This is useful when defining a shell function with the same name | |
2710 | as a shell builtin, retaining the functionality of the builtin | |
2711 | within the function. The return status is non-zero if | |
2712 | SHELL-BUILTIN is not a shell builtin command. | |
ccc6cda3 | 2713 | |
d3a24ed2 CR |
2714 | `caller' |
2715 | caller [EXPR] | |
2716 | Returns the context of any active subroutine call (a shell | |
5e13499c | 2717 | function or a script executed with the `.' or `source' builtins). |
d3a24ed2 CR |
2718 | |
2719 | Without EXPR, `caller' displays the line number and source | |
2720 | filename of the current subroutine call. If a non-negative | |
2721 | integer is supplied as EXPR, `caller' displays the line number, | |
2722 | subroutine name, and source file corresponding to that position in | |
2723 | the current execution call stack. This extra information may be | |
2724 | used, for example, to print a stack trace. The current frame is | |
2725 | frame 0. | |
2726 | ||
2727 | The return value is 0 unless the shell is not executing a | |
2728 | subroutine call or EXPR does not correspond to a valid position in | |
2729 | the call stack. | |
2730 | ||
bb70624e JA |
2731 | `command' |
2732 | command [-pVv] COMMAND [ARGUMENTS ...] | |
2733 | Runs COMMAND with ARGUMENTS ignoring any shell function named | |
2734 | COMMAND. Only shell builtin commands or commands found by | |
2735 | searching the `PATH' are executed. If there is a shell function | |
2736 | named `ls', running `command ls' within the function will execute | |
2737 | the external command `ls' instead of calling the function | |
2738 | recursively. The `-p' option means to use a default value for | |
28ef6c31 | 2739 | `PATH' that is guaranteed to find all of the standard utilities. |
bb70624e JA |
2740 | The return status in this case is 127 if COMMAND cannot be found |
2741 | or an error occurred, and the exit status of COMMAND otherwise. | |
ccc6cda3 | 2742 | |
bb70624e JA |
2743 | If either the `-V' or `-v' option is supplied, a description of |
2744 | COMMAND is printed. The `-v' option causes a single word | |
2745 | indicating the command or file name used to invoke COMMAND to be | |
2746 | displayed; the `-V' option produces a more verbose description. | |
2747 | In this case, the return status is zero if COMMAND is found, and | |
2748 | non-zero if not. | |
ccc6cda3 | 2749 | |
bb70624e | 2750 | `declare' |
d3a24ed2 | 2751 | declare [-afFirtx] [-p] [NAME[=VALUE] ...] |
ccc6cda3 | 2752 | |
bb70624e JA |
2753 | Declare variables and give them attributes. If no NAMEs are |
2754 | given, then display the values of variables instead. | |
ccc6cda3 | 2755 | |
bb70624e JA |
2756 | The `-p' option will display the attributes and values of each |
2757 | NAME. When `-p' is used, additional options are ignored. The | |
2758 | `-F' option inhibits the display of function definitions; only the | |
d3a24ed2 CR |
2759 | function name and attributes are printed. If the `extdebug' shell |
2760 | option is enabled using `shopt' (*note Bash Builtins::), the | |
2761 | source file name and line number where the function is defined are | |
2762 | displayed as well. `-F' implies `-f'. The following options can | |
2763 | be used to restrict output to variables with the specified | |
2764 | attributes or to give variables attributes: | |
ccc6cda3 | 2765 | |
bb70624e | 2766 | `-a' |
28ef6c31 | 2767 | Each NAME is an array variable (*note Arrays::). |
ccc6cda3 | 2768 | |
bb70624e JA |
2769 | `-f' |
2770 | Use function names only. | |
ccc6cda3 | 2771 | |
bb70624e JA |
2772 | `-i' |
2773 | The variable is to be treated as an integer; arithmetic | |
28ef6c31 | 2774 | evaluation (*note Shell Arithmetic::) is performed when the |
bb70624e | 2775 | variable is assigned a value. |
ccc6cda3 | 2776 | |
bb70624e JA |
2777 | `-r' |
2778 | Make NAMEs readonly. These names cannot then be assigned | |
2779 | values by subsequent assignment statements or unset. | |
ccc6cda3 | 2780 | |
7117c2d2 JA |
2781 | `-t' |
2782 | Give each NAME the `trace' attribute. Traced functions | |
2783 | inherit the `DEBUG' trap from the calling shell. The trace | |
2784 | attribute has no special meaning for variables. | |
2785 | ||
bb70624e JA |
2786 | `-x' |
2787 | Mark each NAME for export to subsequent commands via the | |
2788 | environment. | |
ccc6cda3 | 2789 | |
bb70624e JA |
2790 | Using `+' instead of `-' turns off the attribute instead. When |
2791 | used in a function, `declare' makes each NAME local, as with the | |
d3a24ed2 CR |
2792 | `local' command. If a variable name is followed by =VALUE, the |
2793 | value of the variable is set to VALUE. | |
ccc6cda3 | 2794 | |
bb70624e JA |
2795 | The return status is zero unless an invalid option is encountered, |
2796 | an attempt is made to define a function using `-f foo=bar', an | |
2797 | attempt is made to assign a value to a readonly variable, an | |
2798 | attempt is made to assign a value to an array variable without | |
28ef6c31 | 2799 | using the compound assignment syntax (*note Arrays::), one of the |
bb70624e JA |
2800 | NAMES is not a valid shell variable name, an attempt is made to |
2801 | turn off readonly status for a readonly variable, an attempt is | |
2802 | made to turn off array status for an array variable, or an attempt | |
2803 | is made to display a non-existent function with `-f'. | |
ccc6cda3 | 2804 | |
bb70624e JA |
2805 | `echo' |
2806 | echo [-neE] [ARG ...] | |
2807 | Output the ARGs, separated by spaces, terminated with a newline. | |
2808 | The return status is always 0. If `-n' is specified, the trailing | |
2809 | newline is suppressed. If the `-e' option is given, | |
2810 | interpretation of the following backslash-escaped characters is | |
2811 | enabled. The `-E' option disables the interpretation of these | |
2812 | escape characters, even on systems where they are interpreted by | |
2813 | default. The `xpg_echo' shell option may be used to dynamically | |
2814 | determine whether or not `echo' expands these escape characters by | |
2815 | default. `echo' interprets the following escape sequences: | |
2816 | `\a' | |
2817 | alert (bell) | |
ccc6cda3 | 2818 | |
bb70624e JA |
2819 | `\b' |
2820 | backspace | |
ccc6cda3 | 2821 | |
bb70624e JA |
2822 | `\c' |
2823 | suppress trailing newline | |
ccc6cda3 | 2824 | |
bb70624e JA |
2825 | `\e' |
2826 | escape | |
ccc6cda3 | 2827 | |
bb70624e JA |
2828 | `\f' |
2829 | form feed | |
ccc6cda3 | 2830 | |
bb70624e JA |
2831 | `\n' |
2832 | new line | |
ccc6cda3 | 2833 | |
bb70624e JA |
2834 | `\r' |
2835 | carriage return | |
ccc6cda3 | 2836 | |
bb70624e JA |
2837 | `\t' |
2838 | horizontal tab | |
ccc6cda3 | 2839 | |
bb70624e JA |
2840 | `\v' |
2841 | vertical tab | |
ccc6cda3 | 2842 | |
bb70624e JA |
2843 | `\\' |
2844 | backslash | |
ccc6cda3 | 2845 | |
7117c2d2 JA |
2846 | `\0NNN' |
2847 | the eight-bit character whose value is the octal value NNN | |
2848 | (zero to three octal digits) | |
2849 | ||
bb70624e | 2850 | `\NNN' |
f73dda09 | 2851 | the eight-bit character whose value is the octal value NNN |
7117c2d2 | 2852 | (one to three octal digits) |
ccc6cda3 | 2853 | |
f73dda09 JA |
2854 | `\xHH' |
2855 | the eight-bit character whose value is the hexadecimal value | |
2856 | HH (one or two hex digits) | |
2857 | ||
bb70624e JA |
2858 | `enable' |
2859 | enable [-n] [-p] [-f FILENAME] [-ads] [NAME ...] | |
2860 | Enable and disable builtin shell commands. Disabling a builtin | |
2861 | allows a disk command which has the same name as a shell builtin | |
2862 | to be executed without specifying a full pathname, even though the | |
2863 | shell normally searches for builtins before disk commands. If | |
2864 | `-n' is used, the NAMEs become disabled. Otherwise NAMEs are | |
2865 | enabled. For example, to use the `test' binary found via `$PATH' | |
2866 | instead of the shell builtin version, type `enable -n test'. | |
ccc6cda3 | 2867 | |
bb70624e JA |
2868 | If the `-p' option is supplied, or no NAME arguments appear, a |
2869 | list of shell builtins is printed. With no other arguments, the | |
2870 | list consists of all enabled shell builtins. The `-a' option | |
2871 | means to list each builtin with an indication of whether or not it | |
2872 | is enabled. | |
ccc6cda3 | 2873 | |
bb70624e JA |
2874 | The `-f' option means to load the new builtin command NAME from |
2875 | shared object FILENAME, on systems that support dynamic loading. | |
2876 | The `-d' option will delete a builtin loaded with `-f'. | |
ccc6cda3 | 2877 | |
bb70624e JA |
2878 | If there are no options, a list of the shell builtins is displayed. |
2879 | The `-s' option restricts `enable' to the POSIX special builtins. | |
2880 | If `-s' is used with `-f', the new builtin becomes a special | |
28ef6c31 | 2881 | builtin (*note Special Builtins::). |
ccc6cda3 | 2882 | |
bb70624e JA |
2883 | The return status is zero unless a NAME is not a shell builtin or |
2884 | there is an error loading a new builtin from a shared object. | |
ccc6cda3 | 2885 | |
bb70624e JA |
2886 | `help' |
2887 | help [-s] [PATTERN] | |
2888 | Display helpful information about builtin commands. If PATTERN is | |
2889 | specified, `help' gives detailed help on all commands matching | |
2890 | PATTERN, otherwise a list of the builtins is printed. The `-s' | |
2891 | option restricts the information displayed to a short usage | |
2892 | synopsis. The return status is zero unless no command matches | |
2893 | PATTERN. | |
ccc6cda3 | 2894 | |
bb70624e JA |
2895 | `let' |
2896 | let EXPRESSION [EXPRESSION] | |
2897 | The `let' builtin allows arithmetic to be performed on shell | |
2898 | variables. Each EXPRESSION is evaluated according to the rules | |
2899 | given below in *Note Shell Arithmetic::. If the last EXPRESSION | |
2900 | evaluates to 0, `let' returns 1; otherwise 0 is returned. | |
ccc6cda3 | 2901 | |
bb70624e | 2902 | `local' |
d3a24ed2 | 2903 | local [OPTION] NAME[=VALUE] ... |
bb70624e JA |
2904 | For each argument, a local variable named NAME is created, and |
2905 | assigned VALUE. The OPTION can be any of the options accepted by | |
2906 | `declare'. `local' can only be used within a function; it makes | |
2907 | the variable NAME have a visible scope restricted to that function | |
2908 | and its children. The return status is zero unless `local' is | |
2909 | used outside a function, an invalid NAME is supplied, or NAME is a | |
2910 | readonly variable. | |
ccc6cda3 | 2911 | |
bb70624e JA |
2912 | `logout' |
2913 | logout [N] | |
2914 | Exit a login shell, returning a status of N to the shell's parent. | |
ccc6cda3 | 2915 | |
bb70624e JA |
2916 | `printf' |
2917 | `printf' FORMAT [ARGUMENTS] | |
2918 | Write the formatted ARGUMENTS to the standard output under the | |
2919 | control of the FORMAT. The FORMAT is a character string which | |
2920 | contains three types of objects: plain characters, which are | |
2921 | simply copied to standard output, character escape sequences, | |
2922 | which are converted and copied to the standard output, and format | |
2923 | specifications, each of which causes printing of the next | |
2924 | successive ARGUMENT. In addition to the standard `printf(1)' | |
2925 | formats, `%b' causes `printf' to expand backslash escape sequences | |
5e13499c CR |
2926 | in the corresponding ARGUMENT, (except that `\c' terminates |
2927 | output, backslashes in `\'', `\"', and `\?' are not removed, and | |
2928 | octal escapes beginning with `\0' may contain up to four digits), | |
2929 | and `%q' causes `printf' to output the corresponding ARGUMENT in a | |
2930 | format that can be reused as shell input. | |
ccc6cda3 | 2931 | |
bb70624e JA |
2932 | The FORMAT is reused as necessary to consume all of the ARGUMENTS. |
2933 | If the FORMAT requires more ARGUMENTS than are supplied, the extra | |
2934 | format specifications behave as if a zero value or null string, as | |
2935 | appropriate, had been supplied. The return value is zero on | |
2936 | success, non-zero on failure. | |
ccc6cda3 | 2937 | |
bb70624e | 2938 | `read' |
7117c2d2 JA |
2939 | read [-ers] [-a ANAME] [-d DELIM] [-n NCHARS] [-p PROMPT] [-t TIMEOUT] [-u FD] [NAME ...] |
2940 | One line is read from the standard input, or from the file | |
2941 | descriptor FD supplied as an argument to the `-u' option, and the | |
2942 | first word is assigned to the first NAME, the second word to the | |
2943 | second NAME, and so on, with leftover words and their intervening | |
2944 | separators assigned to the last NAME. If there are fewer words | |
2945 | read from the input stream than names, the remaining names are | |
2946 | assigned empty values. The characters in the value of the `IFS' | |
2947 | variable are used to split the line into words. The backslash | |
2948 | character `\' may be used to remove any special meaning for the | |
2949 | next character read and for line continuation. If no names are | |
2950 | supplied, the line read is assigned to the variable `REPLY'. The | |
2951 | return code is zero, unless end-of-file is encountered, `read' | |
2952 | times out, or an invalid file descriptor is supplied as the | |
2953 | argument to `-u'. Options, if supplied, have the following | |
2954 | meanings: | |
ccc6cda3 | 2955 | |
bb70624e JA |
2956 | `-a ANAME' |
2957 | The words are assigned to sequential indices of the array | |
2958 | variable ANAME, starting at 0. All elements are removed from | |
2959 | ANAME before the assignment. Other NAME arguments are | |
2960 | ignored. | |
ccc6cda3 | 2961 | |
bb70624e JA |
2962 | `-d DELIM' |
2963 | The first character of DELIM is used to terminate the input | |
2964 | line, rather than newline. | |
ccc6cda3 | 2965 | |
bb70624e | 2966 | `-e' |
28ef6c31 JA |
2967 | Readline (*note Command Line Editing::) is used to obtain the |
2968 | line. | |
ccc6cda3 | 2969 | |
bb70624e JA |
2970 | `-n NCHARS' |
2971 | `read' returns after reading NCHARS characters rather than | |
2972 | waiting for a complete line of input. | |
cce855bc | 2973 | |
bb70624e JA |
2974 | `-p PROMPT' |
2975 | Display PROMPT, without a trailing newline, before attempting | |
2976 | to read any input. The prompt is displayed only if input is | |
2977 | coming from a terminal. | |
ccc6cda3 | 2978 | |
bb70624e JA |
2979 | `-r' |
2980 | If this option is given, backslash does not act as an escape | |
2981 | character. The backslash is considered to be part of the | |
2982 | line. In particular, a backslash-newline pair may not be | |
2983 | used as a line continuation. | |
ccc6cda3 | 2984 | |
bb70624e JA |
2985 | `-s' |
2986 | Silent mode. If input is coming from a terminal, characters | |
2987 | are not echoed. | |
cce855bc | 2988 | |
bb70624e JA |
2989 | `-t TIMEOUT' |
2990 | Cause `read' to time out and return failure if a complete | |
2991 | line of input is not read within TIMEOUT seconds. This | |
2992 | option has no effect if `read' is not reading input from the | |
2993 | terminal or a pipe. | |
cce855bc | 2994 | |
7117c2d2 JA |
2995 | `-u FD' |
2996 | Read input from file descriptor FD. | |
2997 | ||
761783bf | 2998 | |
bb70624e JA |
2999 | `shopt' |
3000 | shopt [-pqsu] [-o] [OPTNAME ...] | |
3001 | Toggle the values of variables controlling optional shell behavior. | |
3002 | With no options, or with the `-p' option, a list of all settable | |
3003 | options is displayed, with an indication of whether or not each is | |
3004 | set. The `-p' option causes output to be displayed in a form that | |
3005 | may be reused as input. Other options have the following meanings: | |
cce855bc | 3006 | |
bb70624e JA |
3007 | `-s' |
3008 | Enable (set) each OPTNAME. | |
ccc6cda3 | 3009 | |
bb70624e JA |
3010 | `-u' |
3011 | Disable (unset) each OPTNAME. | |
ccc6cda3 | 3012 | |
bb70624e JA |
3013 | `-q' |
3014 | Suppresses normal output; the return status indicates whether | |
3015 | the OPTNAME is set or unset. If multiple OPTNAME arguments | |
3016 | are given with `-q', the return status is zero if all | |
3017 | OPTNAMES are enabled; non-zero otherwise. | |
ccc6cda3 | 3018 | |
bb70624e JA |
3019 | `-o' |
3020 | Restricts the values of OPTNAME to be those defined for the | |
28ef6c31 | 3021 | `-o' option to the `set' builtin (*note The Set Builtin::). |
ccc6cda3 | 3022 | |
bb70624e JA |
3023 | If either `-s' or `-u' is used with no OPTNAME arguments, the |
3024 | display is limited to those options which are set or unset, | |
3025 | respectively. | |
ccc6cda3 | 3026 | |
bb70624e JA |
3027 | Unless otherwise noted, the `shopt' options are disabled (off) by |
3028 | default. | |
ccc6cda3 | 3029 | |
bb70624e JA |
3030 | The return status when listing options is zero if all OPTNAMES are |
3031 | enabled, non-zero otherwise. When setting or unsetting options, | |
3032 | the return status is zero unless an OPTNAME is not a valid shell | |
3033 | option. | |
ccc6cda3 | 3034 | |
bb70624e JA |
3035 | The list of `shopt' options is: |
3036 | `cdable_vars' | |
3037 | If this is set, an argument to the `cd' builtin command that | |
3038 | is not a directory is assumed to be the name of a variable | |
3039 | whose value is the directory to change to. | |
ccc6cda3 | 3040 | |
bb70624e JA |
3041 | `cdspell' |
3042 | If set, minor errors in the spelling of a directory component | |
3043 | in a `cd' command will be corrected. The errors checked for | |
3044 | are transposed characters, a missing character, and a | |
3045 | character too many. If a correction is found, the corrected | |
3046 | path is printed, and the command proceeds. This option is | |
3047 | only used by interactive shells. | |
ccc6cda3 | 3048 | |
bb70624e JA |
3049 | `checkhash' |
3050 | If this is set, Bash checks that a command found in the hash | |
3051 | table exists before trying to execute it. If a hashed | |
3052 | command no longer exists, a normal path search is performed. | |
ccc6cda3 | 3053 | |
bb70624e JA |
3054 | `checkwinsize' |
3055 | If set, Bash checks the window size after each command and, | |
3056 | if necessary, updates the values of `LINES' and `COLUMNS'. | |
ccc6cda3 | 3057 | |
bb70624e JA |
3058 | `cmdhist' |
3059 | If set, Bash attempts to save all lines of a multiple-line | |
3060 | command in the same history entry. This allows easy | |
3061 | re-editing of multi-line commands. | |
cce855bc | 3062 | |
bb70624e JA |
3063 | `dotglob' |
3064 | If set, Bash includes filenames beginning with a `.' in the | |
3065 | results of filename expansion. | |
cce855bc | 3066 | |
bb70624e JA |
3067 | `execfail' |
3068 | If this is set, a non-interactive shell will not exit if it | |
3069 | cannot execute the file specified as an argument to the `exec' | |
3070 | builtin command. An interactive shell does not exit if `exec' | |
3071 | fails. | |
ccc6cda3 | 3072 | |
bb70624e JA |
3073 | `expand_aliases' |
3074 | If set, aliases are expanded as described below under Aliases, | |
3075 | *Note Aliases::. This option is enabled by default for | |
3076 | interactive shells. | |
ccc6cda3 | 3077 | |
d3a24ed2 CR |
3078 | `extdebug' |
3079 | If set, behavior intended for use by debuggers is enabled: | |
3080 | ||
3081 | 1. The `-F' option to the `declare' builtin (*note Bash | |
3082 | Builtins::) displays the source file name and line | |
3083 | number corresponding to each function name supplied as | |
3084 | an argument. | |
3085 | ||
3086 | 2. If the command run by the `DEBUG' trap returns a | |
3087 | non-zero value, the next command is skipped and not | |
3088 | executed. | |
3089 | ||
3090 | 3. If the command run by the `DEBUG' trap returns a value | |
3091 | of 2, and the shell is executing in a subroutine (a | |
3092 | shell function or a shell script executed by the `.' or | |
3093 | `source' builtins), a call to `return' is simulated. | |
3094 | ||
bb70624e JA |
3095 | `extglob' |
3096 | If set, the extended pattern matching features described above | |
28ef6c31 | 3097 | (*note Pattern Matching::) are enabled. |
ccc6cda3 | 3098 | |
d3a24ed2 CR |
3099 | `extquote' |
3100 | If set, `$'STRING'' and `$"STRING"' quoting is performed | |
3101 | within `${PARAMETER}' expansions enclosed in double quotes. | |
3102 | This option is enabled by default. | |
3103 | ||
5e13499c CR |
3104 | `failglob' |
3105 | If set, patterns which fail to match filenames during | |
3106 | pathname expansion result in an expansion error. | |
3107 | ||
d3a24ed2 CR |
3108 | `force_fignore' |
3109 | If set, the suffixes specified by the `FIGNORE' shell variable | |
3110 | cause words to be ignored when performing word completion | |
3111 | even if the ignored words are the only possible completions. | |
3112 | *Note Bash Variables::, for a description of `FIGNORE'. This | |
3113 | option is enabled by default. | |
3114 | ||
3115 | `gnu_errfmt' | |
3116 | If set, shell error messages are written in the standard GNU | |
3117 | error message format. | |
3118 | ||
bb70624e JA |
3119 | `histappend' |
3120 | If set, the history list is appended to the file named by the | |
3121 | value of the `HISTFILE' variable when the shell exits, rather | |
3122 | than overwriting the file. | |
ccc6cda3 | 3123 | |
bb70624e JA |
3124 | `histreedit' |
3125 | If set, and Readline is being used, a user is given the | |
3126 | opportunity to re-edit a failed history substitution. | |
ccc6cda3 | 3127 | |
bb70624e JA |
3128 | `histverify' |
3129 | If set, and Readline is being used, the results of history | |
3130 | substitution are not immediately passed to the shell parser. | |
3131 | Instead, the resulting line is loaded into the Readline | |
3132 | editing buffer, allowing further modification. | |
ccc6cda3 | 3133 | |
bb70624e JA |
3134 | `hostcomplete' |
3135 | If set, and Readline is being used, Bash will attempt to | |
3136 | perform hostname completion when a word containing a `@' is | |
28ef6c31 | 3137 | being completed (*note Commands For Completion::). This |
bb70624e | 3138 | option is enabled by default. |
ccc6cda3 | 3139 | |
bb70624e JA |
3140 | `huponexit' |
3141 | If set, Bash will send `SIGHUP' to all jobs when an | |
28ef6c31 | 3142 | interactive login shell exits (*note Signals::). |
ccc6cda3 | 3143 | |
bb70624e JA |
3144 | `interactive_comments' |
3145 | Allow a word beginning with `#' to cause that word and all | |
3146 | remaining characters on that line to be ignored in an | |
3147 | interactive shell. This option is enabled by default. | |
ccc6cda3 | 3148 | |
bb70624e JA |
3149 | `lithist' |
3150 | If enabled, and the `cmdhist' option is enabled, multi-line | |
3151 | commands are saved to the history with embedded newlines | |
3152 | rather than using semicolon separators where possible. | |
ccc6cda3 | 3153 | |
f73dda09 JA |
3154 | `login_shell' |
3155 | The shell sets this option if it is started as a login shell | |
3156 | (*note Invoking Bash::). The value may not be changed. | |
3157 | ||
bb70624e JA |
3158 | `mailwarn' |
3159 | If set, and a file that Bash is checking for mail has been | |
3160 | accessed since the last time it was checked, the message | |
3161 | `"The mail in MAILFILE has been read"' is displayed. | |
ccc6cda3 | 3162 | |
bb70624e JA |
3163 | `no_empty_cmd_completion' |
3164 | If set, and Readline is being used, Bash will not attempt to | |
3165 | search the `PATH' for possible completions when completion is | |
3166 | attempted on an empty line. | |
ccc6cda3 | 3167 | |
bb70624e JA |
3168 | `nocaseglob' |
3169 | If set, Bash matches filenames in a case-insensitive fashion | |
3170 | when performing filename expansion. | |
ccc6cda3 | 3171 | |
bb70624e JA |
3172 | `nullglob' |
3173 | If set, Bash allows filename patterns which match no files to | |
3174 | expand to a null string, rather than themselves. | |
ccc6cda3 | 3175 | |
bb70624e JA |
3176 | `progcomp' |
3177 | If set, the programmable completion facilities (*note | |
28ef6c31 | 3178 | Programmable Completion::) are enabled. This option is |
bb70624e | 3179 | enabled by default. |
ccc6cda3 | 3180 | |
bb70624e | 3181 | `promptvars' |
d3a24ed2 CR |
3182 | If set, prompt strings undergo parameter expansion, command |
3183 | substitution, arithmetic expansion, and quote removal after | |
3184 | being expanded as described below (*note Printing a Prompt::). | |
bb70624e | 3185 | This option is enabled by default. |
ccc6cda3 | 3186 | |
bb70624e JA |
3187 | `restricted_shell' |
3188 | The shell sets this option if it is started in restricted mode | |
28ef6c31 JA |
3189 | (*note The Restricted Shell::). The value may not be changed. |
3190 | This is not reset when the startup files are executed, | |
3191 | allowing the startup files to discover whether or not a shell | |
3192 | is restricted. | |
ccc6cda3 | 3193 | |
bb70624e JA |
3194 | `shift_verbose' |
3195 | If this is set, the `shift' builtin prints an error message | |
3196 | when the shift count exceeds the number of positional | |
3197 | parameters. | |
ccc6cda3 | 3198 | |
bb70624e JA |
3199 | `sourcepath' |
3200 | If set, the `source' builtin uses the value of `PATH' to find | |
3201 | the directory containing the file supplied as an argument. | |
3202 | This option is enabled by default. | |
ccc6cda3 | 3203 | |
bb70624e JA |
3204 | `xpg_echo' |
3205 | If set, the `echo' builtin expands backslash-escape sequences | |
3206 | by default. | |
ccc6cda3 | 3207 | |
761783bf | 3208 | |
bb70624e JA |
3209 | The return status when listing options is zero if all OPTNAMES are |
3210 | enabled, non-zero otherwise. When setting or unsetting options, | |
3211 | the return status is zero unless an OPTNAME is not a valid shell | |
3212 | option. | |
ccc6cda3 | 3213 | |
bb70624e JA |
3214 | `source' |
3215 | source FILENAME | |
28ef6c31 | 3216 | A synonym for `.' (*note Bourne Shell Builtins::). |
ccc6cda3 | 3217 | |
bb70624e | 3218 | `type' |
7117c2d2 | 3219 | type [-afptP] [NAME ...] |
bb70624e JA |
3220 | For each NAME, indicate how it would be interpreted if used as a |
3221 | command name. | |
cce855bc | 3222 | |
bb70624e JA |
3223 | If the `-t' option is used, `type' prints a single word which is |
3224 | one of `alias', `function', `builtin', `file' or `keyword', if | |
3225 | NAME is an alias, shell function, shell builtin, disk file, or | |
3226 | shell reserved word, respectively. If the NAME is not found, then | |
3227 | nothing is printed, and `type' returns a failure status. | |
ccc6cda3 | 3228 | |
bb70624e JA |
3229 | If the `-p' option is used, `type' either returns the name of the |
3230 | disk file that would be executed, or nothing if `-t' would not | |
3231 | return `file'. | |
ccc6cda3 | 3232 | |
7117c2d2 JA |
3233 | The `-P' option forces a path search for each NAME, even if `-t' |
3234 | would not return `file'. | |
3235 | ||
3236 | If a command is hashed, `-p' and `-P' print the hashed value, not | |
3237 | necessarily the file that appears first in `$PATH'. | |
3238 | ||
bb70624e JA |
3239 | If the `-a' option is used, `type' returns all of the places that |
3240 | contain an executable named FILE. This includes aliases and | |
3241 | functions, if and only if the `-p' option is not also used. | |
ccc6cda3 | 3242 | |
7117c2d2 JA |
3243 | If the `-f' option is used, `type' does not attempt to find shell |
3244 | functions, as with the `command' builtin. | |
3245 | ||
bb70624e JA |
3246 | The return status is zero if any of the NAMES are found, non-zero |
3247 | if none are found. | |
ccc6cda3 | 3248 | |
bb70624e | 3249 | `typeset' |
d3a24ed2 | 3250 | typeset [-afFrxi] [-p] [NAME[=VALUE] ...] |
bb70624e JA |
3251 | The `typeset' command is supplied for compatibility with the Korn |
3252 | shell; however, it has been deprecated in favor of the `declare' | |
3253 | builtin command. | |
ccc6cda3 | 3254 | |
bb70624e JA |
3255 | `ulimit' |
3256 | ulimit [-acdflmnpstuvSH] [LIMIT] | |
3257 | `ulimit' provides control over the resources available to processes | |
3258 | started by the shell, on systems that allow such control. If an | |
3259 | option is given, it is interpreted as follows: | |
3260 | `-S' | |
3261 | Change and report the soft limit associated with a resource. | |
ccc6cda3 | 3262 | |
bb70624e JA |
3263 | `-H' |
3264 | Change and report the hard limit associated with a resource. | |
ccc6cda3 | 3265 | |
bb70624e JA |
3266 | `-a' |
3267 | All current limits are reported. | |
ccc6cda3 | 3268 | |
bb70624e JA |
3269 | `-c' |
3270 | The maximum size of core files created. | |
ccc6cda3 | 3271 | |
bb70624e JA |
3272 | `-d' |
3273 | The maximum size of a process's data segment. | |
ccc6cda3 | 3274 | |
bb70624e JA |
3275 | `-f' |
3276 | The maximum size of files created by the shell. | |
ccc6cda3 | 3277 | |
bb70624e JA |
3278 | `-l' |
3279 | The maximum size that may be locked into memory. | |
ccc6cda3 | 3280 | |
bb70624e JA |
3281 | `-m' |
3282 | The maximum resident set size. | |
ccc6cda3 | 3283 | |
bb70624e JA |
3284 | `-n' |
3285 | The maximum number of open file descriptors. | |
ccc6cda3 | 3286 | |
bb70624e JA |
3287 | `-p' |
3288 | The pipe buffer size. | |
ccc6cda3 | 3289 | |
bb70624e JA |
3290 | `-s' |
3291 | The maximum stack size. | |
ccc6cda3 | 3292 | |
bb70624e JA |
3293 | `-t' |
3294 | The maximum amount of cpu time in seconds. | |
ccc6cda3 | 3295 | |
bb70624e JA |
3296 | `-u' |
3297 | The maximum number of processes available to a single user. | |
cce855bc | 3298 | |
bb70624e JA |
3299 | `-v' |
3300 | The maximum amount of virtual memory available to the process. | |
ccc6cda3 | 3301 | |
761783bf | 3302 | |
f73dda09 JA |
3303 | If LIMIT is given, it is the new value of the specified resource; |
3304 | the special LIMIT values `hard', `soft', and `unlimited' stand for | |
3305 | the current hard limit, the current soft limit, and no limit, | |
3306 | respectively. Otherwise, the current value of the soft limit for | |
3307 | the specified resource is printed, unless the `-H' option is | |
3308 | supplied. When setting new limits, if neither `-H' nor `-S' is | |
3309 | supplied, both the hard and soft limits are set. If no option is | |
3310 | given, then `-f' is assumed. Values are in 1024-byte increments, | |
3311 | except for `-t', which is in seconds, `-p', which is in units of | |
3312 | 512-byte blocks, and `-n' and `-u', which are unscaled values. | |
ccc6cda3 | 3313 | |
f73dda09 JA |
3314 | The return status is zero unless an invalid option or argument is |
3315 | supplied, or an error occurs while setting a new limit. | |
ccc6cda3 | 3316 | |
bb70624e JA |
3317 | `unalias' |
3318 | unalias [-a] [NAME ... ] | |
ccc6cda3 | 3319 | |
bb70624e JA |
3320 | Remove each NAME from the list of aliases. If `-a' is supplied, |
3321 | all aliases are removed. Aliases are described in *Note Aliases::. | |
ccc6cda3 | 3322 | |
761783bf | 3323 | |
bb70624e JA |
3324 | \1f |
3325 | File: bashref.info, Node: The Set Builtin, Next: Special Builtins, Prev: Bash Builtins, Up: Shell Builtin Commands | |
ccc6cda3 | 3326 | |
761783bf CR |
3327 | 4.3 The Set Builtin |
3328 | =================== | |
ccc6cda3 | 3329 | |
761783bf | 3330 | This builtin is so complicated that it deserves its own section. |
ccc6cda3 | 3331 | |
bb70624e JA |
3332 | `set' |
3333 | set [--abefhkmnptuvxBCHP] [-o OPTION] [ARGUMENT ...] | |
ccc6cda3 | 3334 | |
bb70624e JA |
3335 | If no options or arguments are supplied, `set' displays the names |
3336 | and values of all shell variables and functions, sorted according | |
3337 | to the current locale, in a format that may be reused as input. | |
ccc6cda3 | 3338 | |
bb70624e JA |
3339 | When options are supplied, they set or unset shell attributes. |
3340 | Options, if specified, have the following meanings: | |
ccc6cda3 | 3341 | |
bb70624e | 3342 | `-a' |
28ef6c31 JA |
3343 | Mark variables and function which are modified or created for |
3344 | export to the environment of subsequent commands. | |
ccc6cda3 | 3345 | |
bb70624e JA |
3346 | `-b' |
3347 | Cause the status of terminated background jobs to be reported | |
3348 | immediately, rather than before printing the next primary | |
3349 | prompt. | |
ccc6cda3 | 3350 | |
bb70624e JA |
3351 | `-e' |
3352 | Exit immediately if a simple command (*note Simple | |
28ef6c31 | 3353 | Commands::) exits with a non-zero status, unless the command |
d3a24ed2 CR |
3354 | that fails is part of the command list immediately following |
3355 | a `while' or `until' keyword, part of the test in an `if' | |
3356 | statement, part of a `&&' or `||' list, or if the command's | |
3357 | return status is being inverted using `!'. A trap on `ERR', | |
3358 | if set, is executed before the shell exits. | |
ccc6cda3 | 3359 | |
bb70624e JA |
3360 | `-f' |
3361 | Disable file name generation (globbing). | |
ccc6cda3 | 3362 | |
bb70624e JA |
3363 | `-h' |
3364 | Locate and remember (hash) commands as they are looked up for | |
3365 | execution. This option is enabled by default. | |
ccc6cda3 | 3366 | |
bb70624e JA |
3367 | `-k' |
3368 | All arguments in the form of assignment statements are placed | |
3369 | in the environment for a command, not just those that precede | |
3370 | the command name. | |
ccc6cda3 | 3371 | |
bb70624e | 3372 | `-m' |
28ef6c31 | 3373 | Job control is enabled (*note Job Control::). |
b72432fd | 3374 | |
bb70624e JA |
3375 | `-n' |
3376 | Read commands but do not execute them; this may be used to | |
3377 | check a script for syntax errors. This option is ignored by | |
3378 | interactive shells. | |
ccc6cda3 | 3379 | |
bb70624e JA |
3380 | `-o OPTION-NAME' |
3381 | Set the option corresponding to OPTION-NAME: | |
ccc6cda3 | 3382 | |
bb70624e JA |
3383 | `allexport' |
3384 | Same as `-a'. | |
ccc6cda3 | 3385 | |
bb70624e JA |
3386 | `braceexpand' |
3387 | Same as `-B'. | |
ccc6cda3 | 3388 | |
bb70624e JA |
3389 | `emacs' |
3390 | Use an `emacs'-style line editing interface (*note | |
28ef6c31 | 3391 | Command Line Editing::). |
ccc6cda3 | 3392 | |
bb70624e JA |
3393 | `errexit' |
3394 | Same as `-e'. | |
d166f048 | 3395 | |
d3a24ed2 CR |
3396 | `errtrace' |
3397 | Same as `-E'. | |
3398 | ||
3399 | `functrace' | |
3400 | Same as `-T'. | |
3401 | ||
bb70624e JA |
3402 | `hashall' |
3403 | Same as `-h'. | |
d166f048 | 3404 | |
bb70624e JA |
3405 | `histexpand' |
3406 | Same as `-H'. | |
ccc6cda3 | 3407 | |
bb70624e JA |
3408 | `history' |
3409 | Enable command history, as described in *Note Bash | |
3410 | History Facilities::. This option is on by default in | |
3411 | interactive shells. | |
ccc6cda3 | 3412 | |
bb70624e JA |
3413 | `ignoreeof' |
3414 | An interactive shell will not exit upon reading EOF. | |
ccc6cda3 | 3415 | |
bb70624e JA |
3416 | `keyword' |
3417 | Same as `-k'. | |
ccc6cda3 | 3418 | |
bb70624e JA |
3419 | `monitor' |
3420 | Same as `-m'. | |
ccc6cda3 | 3421 | |
bb70624e JA |
3422 | `noclobber' |
3423 | Same as `-C'. | |
ccc6cda3 | 3424 | |
bb70624e JA |
3425 | `noexec' |
3426 | Same as `-n'. | |
ccc6cda3 | 3427 | |
bb70624e JA |
3428 | `noglob' |
3429 | Same as `-f'. | |
ccc6cda3 | 3430 | |
f73dda09 JA |
3431 | `nolog' |
3432 | Currently ignored. | |
3433 | ||
bb70624e JA |
3434 | `notify' |
3435 | Same as `-b'. | |
ccc6cda3 | 3436 | |
bb70624e JA |
3437 | `nounset' |
3438 | Same as `-u'. | |
ccc6cda3 | 3439 | |
bb70624e JA |
3440 | `onecmd' |
3441 | Same as `-t'. | |
ccc6cda3 | 3442 | |
bb70624e JA |
3443 | `physical' |
3444 | Same as `-P'. | |
ccc6cda3 | 3445 | |
5e13499c CR |
3446 | `pipefail' |
3447 | If set, the return value of a pipeline is the value of | |
3448 | the last (rightmost) command to exit with a non-zero | |
3449 | status, or zero if all commands in the pipeline exit | |
3450 | successfully. This option is disabled by default. | |
3451 | ||
bb70624e JA |
3452 | `posix' |
3453 | Change the behavior of Bash where the default operation | |
3454 | differs from the POSIX 1003.2 standard to match the | |
28ef6c31 JA |
3455 | standard (*note Bash POSIX Mode::). This is intended to |
3456 | make Bash behave as a strict superset of that standard. | |
ccc6cda3 | 3457 | |
bb70624e JA |
3458 | `privileged' |
3459 | Same as `-p'. | |
ccc6cda3 | 3460 | |
bb70624e JA |
3461 | `verbose' |
3462 | Same as `-v'. | |
cce855bc | 3463 | |
bb70624e JA |
3464 | `vi' |
3465 | Use a `vi'-style line editing interface. | |
ccc6cda3 | 3466 | |
bb70624e JA |
3467 | `xtrace' |
3468 | Same as `-x'. | |
cce855bc | 3469 | |
bb70624e JA |
3470 | `-p' |
3471 | Turn on privileged mode. In this mode, the `$BASH_ENV' and | |
3472 | `$ENV' files are not processed, shell functions are not | |
3473 | inherited from the environment, and the `SHELLOPTS' variable, | |
3474 | if it appears in the environment, is ignored. If the shell | |
3475 | is started with the effective user (group) id not equal to the | |
3476 | real user (group) id, and the `-p' option is not supplied, | |
3477 | these actions are taken and the effective user id is set to | |
3478 | the real user id. If the `-p' option is supplied at startup, | |
3479 | the effective user id is not reset. Turning this option off | |
3480 | causes the effective user and group ids to be set to the real | |
3481 | user and group ids. | |
ccc6cda3 | 3482 | |
bb70624e JA |
3483 | `-t' |
3484 | Exit after reading and executing one command. | |
ccc6cda3 | 3485 | |
bb70624e JA |
3486 | `-u' |
3487 | Treat unset variables as an error when performing parameter | |
3488 | expansion. An error message will be written to the standard | |
3489 | error, and a non-interactive shell will exit. | |
ccc6cda3 | 3490 | |
bb70624e JA |
3491 | `-v' |
3492 | Print shell input lines as they are read. | |
ccc6cda3 | 3493 | |
bb70624e | 3494 | `-x' |
d3a24ed2 CR |
3495 | Print a trace of simple commands, \fBfor\fP commands, |
3496 | \fBcase\fP commands, \fBselect\fP commands, and arithmetic | |
3497 | \fBfor\fP commands and their arguments or associated word | |
3498 | lists after they are expanded and before they are executed. | |
3499 | The value of the `PS4' variable is expanded and the resultant | |
3500 | value is printed before the command and its expanded | |
3501 | arguments. | |
ccc6cda3 | 3502 | |
bb70624e JA |
3503 | `-B' |
3504 | The shell will perform brace expansion (*note Brace | |
28ef6c31 | 3505 | Expansion::). This option is on by default. |
ccc6cda3 | 3506 | |
bb70624e JA |
3507 | `-C' |
3508 | Prevent output redirection using `>', `>&', and `<>' from | |
3509 | overwriting existing files. | |
ccc6cda3 | 3510 | |
d3a24ed2 CR |
3511 | `-E' |
3512 | If set, any trap on `ERR' is inherited by shell functions, | |
3513 | command substitutions, and commands executed in a subshell | |
3514 | environment. The `ERR' trap is normally not inherited in | |
3515 | such cases. | |
3516 | ||
bb70624e JA |
3517 | `-H' |
3518 | Enable `!' style history substitution (*note History | |
28ef6c31 JA |
3519 | Interaction::). This option is on by default for interactive |
3520 | shells. | |
ccc6cda3 | 3521 | |
bb70624e JA |
3522 | `-P' |
3523 | If set, do not follow symbolic links when performing commands | |
3524 | such as `cd' which change the current directory. The | |
3525 | physical directory is used instead. By default, Bash follows | |
3526 | the logical chain of directories when performing commands | |
3527 | which change the current directory. | |
ccc6cda3 | 3528 | |
bb70624e JA |
3529 | For example, if `/usr/sys' is a symbolic link to |
3530 | `/usr/local/sys' then: | |
3531 | $ cd /usr/sys; echo $PWD | |
3532 | /usr/sys | |
3533 | $ cd ..; pwd | |
3534 | /usr | |
ccc6cda3 | 3535 | |
bb70624e JA |
3536 | If `set -P' is on, then: |
3537 | $ cd /usr/sys; echo $PWD | |
3538 | /usr/local/sys | |
3539 | $ cd ..; pwd | |
3540 | /usr/local | |
ccc6cda3 | 3541 | |
d3a24ed2 CR |
3542 | `-T' |
3543 | If set, any trap on `DEBUG' is inherited by shell functions, | |
3544 | command substitutions, and commands executed in a subshell | |
3545 | environment. The `DEBUG' trap is normally not inherited in | |
3546 | such cases. | |
3547 | ||
bb70624e JA |
3548 | `--' |
3549 | If no arguments follow this option, then the positional | |
3550 | parameters are unset. Otherwise, the positional parameters | |
3551 | are set to the ARGUMENTS, even if some of them begin with a | |
3552 | `-'. | |
ccc6cda3 | 3553 | |
bb70624e JA |
3554 | `-' |
3555 | Signal the end of options, cause all remaining ARGUMENTS to | |
3556 | be assigned to the positional parameters. The `-x' and `-v' | |
3557 | options are turned off. If there are no arguments, the | |
3558 | positional parameters remain unchanged. | |
ccc6cda3 | 3559 | |
bb70624e JA |
3560 | Using `+' rather than `-' causes these options to be turned off. |
3561 | The options can also be used upon invocation of the shell. The | |
3562 | current set of options may be found in `$-'. | |
cce855bc | 3563 | |
bb70624e JA |
3564 | The remaining N ARGUMENTS are positional parameters and are |
3565 | assigned, in order, to `$1', `$2', ... `$N'. The special | |
3566 | parameter `#' is set to N. | |
ccc6cda3 | 3567 | |
bb70624e JA |
3568 | The return status is always zero unless an invalid option is |
3569 | supplied. | |
ccc6cda3 | 3570 | |
bb70624e JA |
3571 | \1f |
3572 | File: bashref.info, Node: Special Builtins, Prev: The Set Builtin, Up: Shell Builtin Commands | |
ccc6cda3 | 3573 | |
761783bf CR |
3574 | 4.4 Special Builtins |
3575 | ==================== | |
ccc6cda3 | 3576 | |
761783bf | 3577 | For historical reasons, the POSIX 1003.2 standard has classified |
28ef6c31 | 3578 | several builtin commands as _special_. When Bash is executing in POSIX |
bb70624e JA |
3579 | mode, the special builtins differ from other builtin commands in three |
3580 | respects: | |
ccc6cda3 | 3581 | |
bb70624e JA |
3582 | 1. Special builtins are found before shell functions during command |
3583 | lookup. | |
ccc6cda3 | 3584 | |
bb70624e JA |
3585 | 2. If a special builtin returns an error status, a non-interactive |
3586 | shell exits. | |
ccc6cda3 | 3587 | |
bb70624e JA |
3588 | 3. Assignment statements preceding the command stay in effect in the |
3589 | shell environment after the command completes. | |
ccc6cda3 | 3590 | |
bb70624e JA |
3591 | When Bash is not executing in POSIX mode, these builtins behave no |
3592 | differently than the rest of the Bash builtin commands. The Bash POSIX | |
3593 | mode is described in *Note Bash POSIX Mode::. | |
ccc6cda3 | 3594 | |
bb70624e JA |
3595 | These are the POSIX special builtins: |
3596 | break : . continue eval exec exit export readonly return set | |
3597 | shift trap unset | |
ccc6cda3 | 3598 | |
bb70624e JA |
3599 | \1f |
3600 | File: bashref.info, Node: Shell Variables, Next: Bash Features, Prev: Shell Builtin Commands, Up: Top | |
cce855bc | 3601 | |
761783bf CR |
3602 | 5 Shell Variables |
3603 | ***************** | |
ccc6cda3 | 3604 | |
bb70624e | 3605 | * Menu: |
ccc6cda3 | 3606 | |
bb70624e JA |
3607 | * Bourne Shell Variables:: Variables which Bash uses in the same way |
3608 | as the Bourne Shell. | |
3609 | * Bash Variables:: List of variables that exist in Bash. | |
ccc6cda3 | 3610 | |
bb70624e JA |
3611 | This chapter describes the shell variables that Bash uses. Bash |
3612 | automatically assigns default values to a number of variables. | |
cce855bc | 3613 | |
bb70624e JA |
3614 | \1f |
3615 | File: bashref.info, Node: Bourne Shell Variables, Next: Bash Variables, Up: Shell Variables | |
ccc6cda3 | 3616 | |
761783bf CR |
3617 | 5.1 Bourne Shell Variables |
3618 | ========================== | |
cce855bc | 3619 | |
761783bf CR |
3620 | Bash uses certain shell variables in the same way as the Bourne shell. |
3621 | In some cases, Bash assigns a default value to the variable. | |
cce855bc | 3622 | |
bb70624e JA |
3623 | `CDPATH' |
3624 | A colon-separated list of directories used as a search path for | |
3625 | the `cd' builtin command. | |
ccc6cda3 | 3626 | |
bb70624e JA |
3627 | `HOME' |
3628 | The current user's home directory; the default for the `cd' builtin | |
3629 | command. The value of this variable is also used by tilde | |
28ef6c31 | 3630 | expansion (*note Tilde Expansion::). |
ccc6cda3 | 3631 | |
bb70624e JA |
3632 | `IFS' |
3633 | A list of characters that separate fields; used when the shell | |
3634 | splits words as part of expansion. | |
ccc6cda3 | 3635 | |
bb70624e JA |
3636 | `MAIL' |
3637 | If this parameter is set to a filename and the `MAILPATH' variable | |
3638 | is not set, Bash informs the user of the arrival of mail in the | |
3639 | specified file. | |
cce855bc | 3640 | |
bb70624e JA |
3641 | `MAILPATH' |
3642 | A colon-separated list of filenames which the shell periodically | |
3643 | checks for new mail. Each list entry can specify the message that | |
3644 | is printed when new mail arrives in the mail file by separating | |
3645 | the file name from the message with a `?'. When used in the text | |
3646 | of the message, `$_' expands to the name of the current mail file. | |
cce855bc | 3647 | |
bb70624e JA |
3648 | `OPTARG' |
3649 | The value of the last option argument processed by the `getopts' | |
3650 | builtin. | |
ccc6cda3 | 3651 | |
bb70624e JA |
3652 | `OPTIND' |
3653 | The index of the last option argument processed by the `getopts' | |
3654 | builtin. | |
ccc6cda3 | 3655 | |
bb70624e JA |
3656 | `PATH' |
3657 | A colon-separated list of directories in which the shell looks for | |
d3a24ed2 CR |
3658 | commands. A zero-length (null) directory name in the value of |
3659 | `PATH' indicates the current directory. A null directory name may | |
3660 | appear as two adjacent colons, or as an initial or trailing colon. | |
ccc6cda3 | 3661 | |
bb70624e JA |
3662 | `PS1' |
3663 | The primary prompt string. The default value is `\s-\v\$ '. | |
3664 | *Note Printing a Prompt::, for the complete list of escape | |
3665 | sequences that are expanded before `PS1' is displayed. | |
ccc6cda3 | 3666 | |
bb70624e JA |
3667 | `PS2' |
3668 | The secondary prompt string. The default value is `> '. | |
ccc6cda3 | 3669 | |
761783bf | 3670 | |
bb70624e JA |
3671 | \1f |
3672 | File: bashref.info, Node: Bash Variables, Prev: Bourne Shell Variables, Up: Shell Variables | |
ccc6cda3 | 3673 | |
761783bf CR |
3674 | 5.2 Bash Variables |
3675 | ================== | |
ccc6cda3 | 3676 | |
761783bf | 3677 | These variables are set or used by Bash, but other shells do not |
bb70624e | 3678 | normally treat them specially. |
ccc6cda3 | 3679 | |
bb70624e JA |
3680 | A few variables used by Bash are described in different chapters: |
3681 | variables for controlling the job control facilities (*note Job Control | |
28ef6c31 | 3682 | Variables::). |
ccc6cda3 | 3683 | |
bb70624e JA |
3684 | `BASH' |
3685 | The full pathname used to execute the current instance of Bash. | |
ccc6cda3 | 3686 | |
d3a24ed2 CR |
3687 | `BASH_ARGC' |
3688 | An array variable whose values are the number of parameters in each | |
3689 | frame of the current bash execution call stack. The number of | |
3690 | parameters to the current subroutine (shell function or script | |
3691 | executed with `.' or `source') is at the top of the stack. When a | |
3692 | subroutine is executed, the number of parameters passed is pushed | |
3693 | onto `BASH_ARGC'. | |
3694 | ||
3695 | `BASH_ARGV' | |
3696 | An array variable containing all of the parameters in the current | |
3697 | bash execution call stack. The final parameter of the last | |
3698 | subroutine call is at the top of the stack; the first parameter of | |
3699 | the initial call is at the bottom. When a subroutine is executed, | |
3700 | the parameters supplied are pushed onto `BASH_ARGV'. | |
3701 | ||
3702 | `BASH_COMMAND' | |
3703 | The command currently being executed or about to be executed, | |
3704 | unless the shell is executing a command as the result of a trap, | |
3705 | in which case it is the command executing at the time of the trap. | |
3706 | ||
bb70624e JA |
3707 | `BASH_ENV' |
3708 | If this variable is set when Bash is invoked to execute a shell | |
3709 | script, its value is expanded and used as the name of a startup | |
3710 | file to read before executing the script. *Note Bash Startup | |
3711 | Files::. | |
ccc6cda3 | 3712 | |
d3a24ed2 CR |
3713 | `BASH_EXECUTION_STRING' |
3714 | The command argument to the `-c' invocation option. | |
3715 | ||
3716 | `BASH_LINENO' | |
3717 | An array variable whose members are the line numbers in source | |
3718 | files corresponding to each member of FUNCNAME. | |
3719 | `${BASH_LINENO[$i]}' is the line number in the source file where | |
3720 | `${FUNCNAME[$i + 1]}' was called. The corresponding source file | |
3721 | name is `${BASH_SOURCE[$i + 1]}'. Use `LINENO' to obtain the | |
3722 | current line number. | |
3723 | ||
5e13499c CR |
3724 | `BASH_REMATCH' |
3725 | An array variable whose members are assigned by the `=~' binary | |
3726 | operator to the `[[' conditional command (*note Conditional | |
3727 | Constructs::). The element with index 0 is the portion of the | |
3728 | string matching the entire regular expression. The element with | |
3729 | index N is the portion of the string matching the Nth | |
3730 | parenthesized subexpression. This variable is read-only. | |
3731 | ||
d3a24ed2 CR |
3732 | `BASH_SOURCE' |
3733 | An array variable whose members are the source filenames | |
3734 | corresponding to the elements in the `FUNCNAME' array variable. | |
3735 | ||
3736 | `BASH_SUBSHELL' | |
3737 | Incremented by one each time a subshell or subshell environment is | |
3738 | spawned. The initial value is 0. | |
ccc6cda3 | 3739 | |
bb70624e | 3740 | `BASH_VERSINFO' |
28ef6c31 | 3741 | A readonly array variable (*note Arrays::) whose members hold |
bb70624e JA |
3742 | version information for this instance of Bash. The values |
3743 | assigned to the array members are as follows: | |
ccc6cda3 | 3744 | |
bb70624e JA |
3745 | `BASH_VERSINFO[0]' |
3746 | The major version number (the RELEASE). | |
ccc6cda3 | 3747 | |
bb70624e JA |
3748 | `BASH_VERSINFO[1]' |
3749 | The minor version number (the VERSION). | |
ccc6cda3 | 3750 | |
bb70624e JA |
3751 | `BASH_VERSINFO[2]' |
3752 | The patch level. | |
ccc6cda3 | 3753 | |
bb70624e JA |
3754 | `BASH_VERSINFO[3]' |
3755 | The build version. | |
ccc6cda3 | 3756 | |
bb70624e JA |
3757 | `BASH_VERSINFO[4]' |
3758 | The release status (e.g., BETA1). | |
ccc6cda3 | 3759 | |
bb70624e JA |
3760 | `BASH_VERSINFO[5]' |
3761 | The value of `MACHTYPE'. | |
ccc6cda3 | 3762 | |
761783bf | 3763 | |
d3a24ed2 CR |
3764 | `BASH_VERSION' |
3765 | The version number of the current instance of Bash. | |
3766 | ||
f73dda09 JA |
3767 | `COLUMNS' |
3768 | Used by the `select' builtin command to determine the terminal | |
3769 | width when printing selection lists. Automatically set upon | |
3770 | receipt of a `SIGWINCH'. | |
bb70624e JA |
3771 | |
3772 | `COMP_CWORD' | |
3773 | An index into `${COMP_WORDS}' of the word containing the current | |
3774 | cursor position. This variable is available only in shell | |
3775 | functions invoked by the programmable completion facilities (*note | |
28ef6c31 | 3776 | Programmable Completion::). |
bb70624e JA |
3777 | |
3778 | `COMP_LINE' | |
3779 | The current command line. This variable is available only in | |
3780 | shell functions and external commands invoked by the programmable | |
28ef6c31 | 3781 | completion facilities (*note Programmable Completion::). |
bb70624e JA |
3782 | |
3783 | `COMP_POINT' | |
3784 | The index of the current cursor position relative to the beginning | |
3785 | of the current command. If the current cursor position is at the | |
3786 | end of the current command, the value of this variable is equal to | |
3787 | `${#COMP_LINE}'. This variable is available only in shell | |
3788 | functions and external commands invoked by the programmable | |
28ef6c31 | 3789 | completion facilities (*note Programmable Completion::). |
bb70624e | 3790 | |
d3a24ed2 CR |
3791 | `COMP_WORDBREAKS' |
3792 | The set of characters that the Readline library treats as word | |
3793 | separators when performing word completion. If `COMP_WORDBREAKS' | |
3794 | is unset, it loses its special properties, even if it is | |
3795 | subsequently reset. | |
3796 | ||
f73dda09 JA |
3797 | `COMP_WORDS' |
3798 | An array variable consisting of the individual words in the | |
3799 | current command line. This variable is available only in shell | |
3800 | functions invoked by the programmable completion facilities (*note | |
3801 | Programmable Completion::). | |
3802 | ||
bb70624e JA |
3803 | `COMPREPLY' |
3804 | An array variable from which Bash reads the possible completions | |
3805 | generated by a shell function invoked by the programmable | |
28ef6c31 | 3806 | completion facility (*note Programmable Completion::). |
ccc6cda3 | 3807 | |
bb70624e JA |
3808 | `DIRSTACK' |
3809 | An array variable containing the current contents of the directory | |
3810 | stack. Directories appear in the stack in the order they are | |
3811 | displayed by the `dirs' builtin. Assigning to members of this | |
3812 | array variable may be used to modify directories already in the | |
3813 | stack, but the `pushd' and `popd' builtins must be used to add and | |
3814 | remove directories. Assignment to this variable will not change | |
3815 | the current directory. If `DIRSTACK' is unset, it loses its | |
3816 | special properties, even if it is subsequently reset. | |
cce855bc | 3817 | |
d3a24ed2 CR |
3818 | `EMACS' |
3819 | If Bash finds this variable in the environment when the shell | |
3820 | starts with value `t', it assumes that the shell is running in an | |
3821 | emacs shell buffer and disables line editing. | |
3822 | ||
bb70624e JA |
3823 | `EUID' |
3824 | The numeric effective user id of the current user. This variable | |
3825 | is readonly. | |
cce855bc | 3826 | |
bb70624e JA |
3827 | `FCEDIT' |
3828 | The editor used as a default by the `-e' option to the `fc' | |
3829 | builtin command. | |
ccc6cda3 | 3830 | |
bb70624e JA |
3831 | `FIGNORE' |
3832 | A colon-separated list of suffixes to ignore when performing | |
3833 | filename completion. A file name whose suffix matches one of the | |
3834 | entries in `FIGNORE' is excluded from the list of matched file | |
3835 | names. A sample value is `.o:~' | |
ccc6cda3 | 3836 | |
f73dda09 | 3837 | `FUNCNAME' |
d3a24ed2 CR |
3838 | An array variable containing the names of all shell functions |
3839 | currently in the execution call stack. The element with index 0 | |
3840 | is the name of any currently-executing shell function. The | |
3841 | bottom-most element is "main". This variable exists only when a | |
3842 | shell function is executing. Assignments to `FUNCNAME' have no | |
3843 | effect and return an error status. If `FUNCNAME' is unset, it | |
3844 | loses its special properties, even if it is subsequently reset. | |
f73dda09 | 3845 | |
bb70624e JA |
3846 | `GLOBIGNORE' |
3847 | A colon-separated list of patterns defining the set of filenames to | |
3848 | be ignored by filename expansion. If a filename matched by a | |
3849 | filename expansion pattern also matches one of the patterns in | |
3850 | `GLOBIGNORE', it is removed from the list of matches. | |
ccc6cda3 | 3851 | |
bb70624e JA |
3852 | `GROUPS' |
3853 | An array variable containing the list of groups of which the | |
3854 | current user is a member. Assignments to `GROUPS' have no effect | |
28ef6c31 | 3855 | and return an error status. If `GROUPS' is unset, it loses its |
bb70624e | 3856 | special properties, even if it is subsequently reset. |
ccc6cda3 | 3857 | |
bb70624e JA |
3858 | `histchars' |
3859 | Up to three characters which control history expansion, quick | |
28ef6c31 JA |
3860 | substitution, and tokenization (*note History Interaction::). The |
3861 | first character is the HISTORY EXPANSION character, that is, the | |
3862 | character which signifies the start of a history expansion, | |
bb70624e JA |
3863 | normally `!'. The second character is the character which |
3864 | signifies `quick substitution' when seen as the first character on | |
3865 | a line, normally `^'. The optional third character is the | |
3866 | character which indicates that the remainder of the line is a | |
3867 | comment when found as the first character of a word, usually `#'. | |
3868 | The history comment character causes history substitution to be | |
3869 | skipped for the remaining words on the line. It does not | |
3870 | necessarily cause the shell parser to treat the rest of the line | |
3871 | as a comment. | |
cce855bc | 3872 | |
bb70624e JA |
3873 | `HISTCMD' |
3874 | The history number, or index in the history list, of the current | |
3875 | command. If `HISTCMD' is unset, it loses its special properties, | |
3876 | even if it is subsequently reset. | |
ccc6cda3 | 3877 | |
bb70624e | 3878 | `HISTCONTROL' |
d3a24ed2 CR |
3879 | A colon-separated list of values controlling how commands are |
3880 | saved on the history list. If the list of values includes | |
3881 | `ignorespace', lines which begin with a space character are not | |
3882 | saved in the history list. A value of `ignoredups' causes lines | |
3883 | which match the previous history entry to not be saved. A value | |
3884 | of `ignoreboth' is shorthand for `ignorespace' and `ignoredups'. | |
3885 | A value of `erasedups' causes all previous lines matching the | |
3886 | current line to be removed from the history list before that line | |
3887 | is saved. Any value not in the above list is ignored. If | |
3888 | `HISTCONTROL' is unset, or does not include a valid value, all | |
3889 | lines read by the shell parser are saved on the history list, | |
3890 | subject to the value of `HISTIGNORE'. The second and subsequent | |
3891 | lines of a multi-line compound command are not tested, and are | |
3892 | added to the history regardless of the value of `HISTCONTROL'. | |
ccc6cda3 | 3893 | |
f73dda09 JA |
3894 | `HISTFILE' |
3895 | The name of the file to which the command history is saved. The | |
3896 | default value is `~/.bash_history'. | |
3897 | ||
3898 | `HISTFILESIZE' | |
3899 | The maximum number of lines contained in the history file. When | |
3900 | this variable is assigned a value, the history file is truncated, | |
3901 | if necessary, to contain no more than that number of lines. The | |
3902 | history file is also truncated to this size after writing it when | |
3903 | an interactive shell exits. The default value is 500. | |
3904 | ||
bb70624e JA |
3905 | `HISTIGNORE' |
3906 | A colon-separated list of patterns used to decide which command | |
3907 | lines should be saved on the history list. Each pattern is | |
3908 | anchored at the beginning of the line and must match the complete | |
3909 | line (no implicit `*' is appended). Each pattern is tested | |
3910 | against the line after the checks specified by `HISTCONTROL' are | |
3911 | applied. In addition to the normal shell pattern matching | |
3912 | characters, `&' matches the previous history line. `&' may be | |
3913 | escaped using a backslash; the backslash is removed before | |
3914 | attempting a match. The second and subsequent lines of a | |
3915 | multi-line compound command are not tested, and are added to the | |
3916 | history regardless of the value of `HISTIGNORE'. | |
cce855bc | 3917 | |
bb70624e JA |
3918 | `HISTIGNORE' subsumes the function of `HISTCONTROL'. A pattern of |
3919 | `&' is identical to `ignoredups', and a pattern of `[ ]*' is | |
3920 | identical to `ignorespace'. Combining these two patterns, | |
3921 | separating them with a colon, provides the functionality of | |
3922 | `ignoreboth'. | |
ccc6cda3 | 3923 | |
bb70624e JA |
3924 | `HISTSIZE' |
3925 | The maximum number of commands to remember on the history list. | |
3926 | The default value is 500. | |
b72432fd | 3927 | |
d3a24ed2 CR |
3928 | `HISTTIMEFORMAT' |
3929 | If this variable is set and not null, its value is used as a | |
3930 | format string for STRFTIME to print the time stamp associated with | |
3931 | each history entry displayed by the `history' builtin. If this | |
3932 | variable is set, time stamps are written to the history file so | |
3933 | they may be preserved across shell sessions. | |
3934 | ||
bb70624e JA |
3935 | `HOSTFILE' |
3936 | Contains the name of a file in the same format as `/etc/hosts' that | |
3937 | should be read when the shell needs to complete a hostname. The | |
3938 | list of possible hostname completions may be changed while the | |
3939 | shell is running; the next time hostname completion is attempted | |
3940 | after the value is changed, Bash adds the contents of the new file | |
3941 | to the existing list. If `HOSTFILE' is set, but has no value, | |
3942 | Bash attempts to read `/etc/hosts' to obtain the list of possible | |
3943 | hostname completions. When `HOSTFILE' is unset, the hostname list | |
3944 | is cleared. | |
cce855bc | 3945 | |
bb70624e JA |
3946 | `HOSTNAME' |
3947 | The name of the current host. | |
cce855bc | 3948 | |
bb70624e JA |
3949 | `HOSTTYPE' |
3950 | A string describing the machine Bash is running on. | |
ccc6cda3 | 3951 | |
bb70624e JA |
3952 | `IGNOREEOF' |
3953 | Controls the action of the shell on receipt of an `EOF' character | |
3954 | as the sole input. If set, the value denotes the number of | |
3955 | consecutive `EOF' characters that can be read as the first | |
3956 | character on an input line before the shell will exit. If the | |
3957 | variable exists but does not have a numeric value (or has no | |
3958 | value) then the default is 10. If the variable does not exist, | |
3959 | then `EOF' signifies the end of input to the shell. This is only | |
3960 | in effect for interactive shells. | |
ccc6cda3 | 3961 | |
bb70624e JA |
3962 | `INPUTRC' |
3963 | The name of the Readline initialization file, overriding the | |
3964 | default of `~/.inputrc'. | |
ccc6cda3 | 3965 | |
bb70624e JA |
3966 | `LANG' |
3967 | Used to determine the locale category for any category not | |
3968 | specifically selected with a variable starting with `LC_'. | |
ccc6cda3 | 3969 | |
bb70624e JA |
3970 | `LC_ALL' |
3971 | This variable overrides the value of `LANG' and any other `LC_' | |
3972 | variable specifying a locale category. | |
cce855bc | 3973 | |
bb70624e JA |
3974 | `LC_COLLATE' |
3975 | This variable determines the collation order used when sorting the | |
3976 | results of filename expansion, and determines the behavior of | |
3977 | range expressions, equivalence classes, and collating sequences | |
3978 | within filename expansion and pattern matching (*note Filename | |
28ef6c31 | 3979 | Expansion::). |
ccc6cda3 | 3980 | |
bb70624e JA |
3981 | `LC_CTYPE' |
3982 | This variable determines the interpretation of characters and the | |
3983 | behavior of character classes within filename expansion and pattern | |
28ef6c31 | 3984 | matching (*note Filename Expansion::). |
ccc6cda3 | 3985 | |
bb70624e JA |
3986 | `LC_MESSAGES' |
3987 | This variable determines the locale used to translate double-quoted | |
28ef6c31 | 3988 | strings preceded by a `$' (*note Locale Translation::). |
ccc6cda3 | 3989 | |
bb70624e JA |
3990 | `LC_NUMERIC' |
3991 | This variable determines the locale category used for number | |
3992 | formatting. | |
ccc6cda3 | 3993 | |
f73dda09 JA |
3994 | `LINENO' |
3995 | The line number in the script or shell function currently | |
3996 | executing. | |
3997 | ||
28ef6c31 JA |
3998 | `LINES' |
3999 | Used by the `select' builtin command to determine the column length | |
4000 | for printing selection lists. Automatically set upon receipt of a | |
4001 | `SIGWINCH'. | |
4002 | ||
bb70624e JA |
4003 | `MACHTYPE' |
4004 | A string that fully describes the system type on which Bash is | |
4005 | executing, in the standard GNU CPU-COMPANY-SYSTEM format. | |
ccc6cda3 | 4006 | |
bb70624e JA |
4007 | `MAILCHECK' |
4008 | How often (in seconds) that the shell should check for mail in the | |
28ef6c31 JA |
4009 | files specified in the `MAILPATH' or `MAIL' variables. The |
4010 | default is 60 seconds. When it is time to check for mail, the | |
4011 | shell does so before displaying the primary prompt. If this | |
4012 | variable is unset, or set to a value that is not a number greater | |
4013 | than or equal to zero, the shell disables mail checking. | |
ccc6cda3 | 4014 | |
bb70624e JA |
4015 | `OLDPWD' |
4016 | The previous working directory as set by the `cd' builtin. | |
ccc6cda3 | 4017 | |
bb70624e JA |
4018 | `OPTERR' |
4019 | If set to the value 1, Bash displays error messages generated by | |
4020 | the `getopts' builtin command. | |
ccc6cda3 | 4021 | |
bb70624e JA |
4022 | `OSTYPE' |
4023 | A string describing the operating system Bash is running on. | |
ccc6cda3 | 4024 | |
bb70624e | 4025 | `PIPESTATUS' |
28ef6c31 | 4026 | An array variable (*note Arrays::) containing a list of exit |
bb70624e JA |
4027 | status values from the processes in the most-recently-executed |
4028 | foreground pipeline (which may contain only a single command). | |
ccc6cda3 | 4029 | |
f73dda09 JA |
4030 | `POSIXLY_CORRECT' |
4031 | If this variable is in the environment when `bash' starts, the | |
4032 | shell enters POSIX mode (*note Bash POSIX Mode::) before reading | |
4033 | the startup files, as if the `--posix' invocation option had been | |
4034 | supplied. If it is set while the shell is running, `bash' enables | |
4035 | POSIX mode, as if the command | |
4036 | `set -o posix' | |
f73dda09 JA |
4037 | had been executed. |
4038 | ||
bb70624e JA |
4039 | `PPID' |
4040 | The process ID of the shell's parent process. This variable is | |
4041 | readonly. | |
ccc6cda3 | 4042 | |
bb70624e JA |
4043 | `PROMPT_COMMAND' |
4044 | If set, the value is interpreted as a command to execute before | |
4045 | the printing of each primary prompt (`$PS1'). | |
ccc6cda3 | 4046 | |
bb70624e JA |
4047 | `PS3' |
4048 | The value of this variable is used as the prompt for the `select' | |
4049 | command. If this variable is not set, the `select' command | |
4050 | prompts with `#? ' | |
ccc6cda3 | 4051 | |
bb70624e JA |
4052 | `PS4' |
4053 | The value is the prompt printed before the command line is echoed | |
28ef6c31 | 4054 | when the `-x' option is set (*note The Set Builtin::). The first |
bb70624e JA |
4055 | character of `PS4' is replicated multiple times, as necessary, to |
4056 | indicate multiple levels of indirection. The default is `+ '. | |
ccc6cda3 | 4057 | |
bb70624e JA |
4058 | `PWD' |
4059 | The current working directory as set by the `cd' builtin. | |
ccc6cda3 | 4060 | |
bb70624e JA |
4061 | `RANDOM' |
4062 | Each time this parameter is referenced, a random integer between 0 | |
4063 | and 32767 is generated. Assigning a value to this variable seeds | |
4064 | the random number generator. | |
cce855bc | 4065 | |
bb70624e JA |
4066 | `REPLY' |
4067 | The default variable for the `read' builtin. | |
ccc6cda3 | 4068 | |
bb70624e JA |
4069 | `SECONDS' |
4070 | This variable expands to the number of seconds since the shell was | |
4071 | started. Assignment to this variable resets the count to the | |
4072 | value assigned, and the expanded value becomes the value assigned | |
4073 | plus the number of seconds since the assignment. | |
ccc6cda3 | 4074 | |
9f422431 CR |
4075 | `SHELL' |
4076 | The full pathname to the shell is kept in this environment | |
4077 | variable. If it is not set when the shell starts, Bash assigns to | |
4078 | it the full pathname of the current user's login shell. | |
4079 | ||
bb70624e JA |
4080 | `SHELLOPTS' |
4081 | A colon-separated list of enabled shell options. Each word in the | |
4082 | list is a valid argument for the `-o' option to the `set' builtin | |
28ef6c31 | 4083 | command (*note The Set Builtin::). The options appearing in |
bb70624e JA |
4084 | `SHELLOPTS' are those reported as `on' by `set -o'. If this |
4085 | variable is in the environment when Bash starts up, each shell | |
4086 | option in the list will be enabled before reading any startup | |
4087 | files. This variable is readonly. | |
ccc6cda3 | 4088 | |
bb70624e JA |
4089 | `SHLVL' |
4090 | Incremented by one each time a new instance of Bash is started. | |
4091 | This is intended to be a count of how deeply your Bash shells are | |
4092 | nested. | |
cce855bc | 4093 | |
bb70624e JA |
4094 | `TIMEFORMAT' |
4095 | The value of this parameter is used as a format string specifying | |
4096 | how the timing information for pipelines prefixed with the `time' | |
4097 | reserved word should be displayed. The `%' character introduces an | |
4098 | escape sequence that is expanded to a time value or other | |
4099 | information. The escape sequences and their meanings are as | |
4100 | follows; the braces denote optional portions. | |
cce855bc | 4101 | |
bb70624e JA |
4102 | `%%' |
4103 | A literal `%'. | |
ccc6cda3 | 4104 | |
bb70624e JA |
4105 | `%[P][l]R' |
4106 | The elapsed time in seconds. | |
ccc6cda3 | 4107 | |
bb70624e JA |
4108 | `%[P][l]U' |
4109 | The number of CPU seconds spent in user mode. | |
ccc6cda3 | 4110 | |
bb70624e JA |
4111 | `%[P][l]S' |
4112 | The number of CPU seconds spent in system mode. | |
ccc6cda3 | 4113 | |
bb70624e JA |
4114 | `%P' |
4115 | The CPU percentage, computed as (%U + %S) / %R. | |
ccc6cda3 | 4116 | |
bb70624e JA |
4117 | The optional P is a digit specifying the precision, the number of |
4118 | fractional digits after a decimal point. A value of 0 causes no | |
4119 | decimal point or fraction to be output. At most three places | |
4120 | after the decimal point may be specified; values of P greater than | |
4121 | 3 are changed to 3. If P is not specified, the value 3 is used. | |
ccc6cda3 | 4122 | |
bb70624e JA |
4123 | The optional `l' specifies a longer format, including minutes, of |
4124 | the form MMmSS.FFs. The value of P determines whether or not the | |
4125 | fraction is included. | |
ccc6cda3 | 4126 | |
bb70624e JA |
4127 | If this variable is not set, Bash acts as if it had the value |
4128 | `$'\nreal\t%3lR\nuser\t%3lU\nsys\t%3lS'' | |
4129 | If the value is null, no timing information is displayed. A | |
4130 | trailing newline is added when the format string is displayed. | |
ccc6cda3 | 4131 | |
bb70624e | 4132 | `TMOUT' |
7117c2d2 JA |
4133 | If set to a value greater than zero, `TMOUT' is treated as the |
4134 | default timeout for the `read' builtin (*note Bash Builtins::). | |
4135 | The `select' command (*note Conditional Constructs::) terminates | |
4136 | if input does not arrive after `TMOUT' seconds when input is coming | |
4137 | from a terminal. | |
4138 | ||
4139 | In an interative shell, the value is interpreted as the number of | |
4140 | seconds to wait for input after issuing the primary prompt when | |
4141 | the shell is interactive. Bash terminates after that number of | |
4142 | seconds if input does not arrive. | |
ccc6cda3 | 4143 | |
bb70624e JA |
4144 | `UID' |
4145 | The numeric real user id of the current user. This variable is | |
4146 | readonly. | |
ccc6cda3 | 4147 | |
761783bf | 4148 | |
bb70624e JA |
4149 | \1f |
4150 | File: bashref.info, Node: Bash Features, Next: Job Control, Prev: Shell Variables, Up: Top | |
ccc6cda3 | 4151 | |
761783bf CR |
4152 | 6 Bash Features |
4153 | *************** | |
ccc6cda3 | 4154 | |
761783bf | 4155 | This section describes features unique to Bash. |
ccc6cda3 | 4156 | |
bb70624e | 4157 | * Menu: |
ccc6cda3 | 4158 | |
bb70624e JA |
4159 | * Invoking Bash:: Command line options that you can give |
4160 | to Bash. | |
4161 | * Bash Startup Files:: When and how Bash executes scripts. | |
4162 | * Interactive Shells:: What an interactive shell is. | |
4163 | * Bash Conditional Expressions:: Primitives used in composing expressions for | |
4164 | the `test' builtin. | |
4165 | * Shell Arithmetic:: Arithmetic on shell variables. | |
4166 | * Aliases:: Substituting one command for another. | |
4167 | * Arrays:: Array Variables. | |
4168 | * The Directory Stack:: History of visited directories. | |
4169 | * Printing a Prompt:: Controlling the PS1 string. | |
4170 | * The Restricted Shell:: A more controlled mode of shell execution. | |
4171 | * Bash POSIX Mode:: Making Bash behave more closely to what | |
4172 | the POSIX standard specifies. | |
ccc6cda3 | 4173 | |
bb70624e JA |
4174 | \1f |
4175 | File: bashref.info, Node: Invoking Bash, Next: Bash Startup Files, Up: Bash Features | |
ccc6cda3 | 4176 | |
761783bf CR |
4177 | 6.1 Invoking Bash |
4178 | ================= | |
ccc6cda3 | 4179 | |
f73dda09 JA |
4180 | bash [long-opt] [-ir] [-abefhkmnptuvxdBCDHP] [-o OPTION] [-O SHOPT_OPTION] [ARGUMENT ...] |
4181 | bash [long-opt] [-abefhkmnptuvxdBCDHP] [-o OPTION] [-O SHOPT_OPTION] -c STRING [ARGUMENT ...] | |
4182 | bash [long-opt] -s [-abefhkmnptuvxdBCDHP] [-o OPTION] [-O SHOPT_OPTION] [ARGUMENT ...] | |
ccc6cda3 | 4183 | |
bb70624e | 4184 | In addition to the single-character shell command-line options |
28ef6c31 | 4185 | (*note The Set Builtin::), there are several multi-character options |
bb70624e | 4186 | that you can use. These options must appear on the command line before |
7117c2d2 | 4187 | the single-character options to be recognized. |
ccc6cda3 | 4188 | |
d3a24ed2 CR |
4189 | `--debugger' |
4190 | Arrange for the debugger profile to be executed before the shell | |
4191 | starts. Turns on extended debugging mode (see *Note Bash | |
4192 | Builtins:: for a description of the `extdebug' option to the | |
4193 | `shopt' builtin) and shell function tracing (see *Note The Set | |
4194 | Builtin:: for a description of the `-o functrace' option). | |
4195 | ||
bb70624e JA |
4196 | `--dump-po-strings' |
4197 | A list of all double-quoted strings preceded by `$' is printed on | |
4198 | the standard ouput in the GNU `gettext' PO (portable object) file | |
4199 | format. Equivalent to `-D' except for the output format. | |
ccc6cda3 | 4200 | |
bb70624e JA |
4201 | `--dump-strings' |
4202 | Equivalent to `-D'. | |
ccc6cda3 | 4203 | |
bb70624e JA |
4204 | `--help' |
4205 | Display a usage message on standard output and exit sucessfully. | |
ccc6cda3 | 4206 | |
28ef6c31 JA |
4207 | `--init-file FILENAME' |
4208 | `--rcfile FILENAME' | |
4209 | Execute commands from FILENAME (instead of `~/.bashrc') in an | |
4210 | interactive shell. | |
4211 | ||
bb70624e | 4212 | `--login' |
7117c2d2 | 4213 | Equivalent to `-l'. |
ccc6cda3 | 4214 | |
bb70624e | 4215 | `--noediting' |
28ef6c31 | 4216 | Do not use the GNU Readline library (*note Command Line Editing::) |
bb70624e | 4217 | to read command lines when the shell is interactive. |
ccc6cda3 | 4218 | |
bb70624e JA |
4219 | `--noprofile' |
4220 | Don't load the system-wide startup file `/etc/profile' or any of | |
4221 | the personal initialization files `~/.bash_profile', | |
4222 | `~/.bash_login', or `~/.profile' when Bash is invoked as a login | |
4223 | shell. | |
ccc6cda3 | 4224 | |
bb70624e JA |
4225 | `--norc' |
4226 | Don't read the `~/.bashrc' initialization file in an interactive | |
4227 | shell. This is on by default if the shell is invoked as `sh'. | |
ccc6cda3 | 4228 | |
bb70624e JA |
4229 | `--posix' |
4230 | Change the behavior of Bash where the default operation differs | |
4231 | from the POSIX 1003.2 standard to match the standard. This is | |
4232 | intended to make Bash behave as a strict superset of that | |
4233 | standard. *Note Bash POSIX Mode::, for a description of the Bash | |
4234 | POSIX mode. | |
ccc6cda3 | 4235 | |
bb70624e | 4236 | `--restricted' |
28ef6c31 | 4237 | Make the shell a restricted shell (*note The Restricted Shell::). |
ccc6cda3 | 4238 | |
bb70624e JA |
4239 | `--verbose' |
4240 | Equivalent to `-v'. Print shell input lines as they're read. | |
ccc6cda3 | 4241 | |
bb70624e JA |
4242 | `--version' |
4243 | Show version information for this instance of Bash on the standard | |
4244 | output and exit successfully. | |
ccc6cda3 | 4245 | |
761783bf | 4246 | |
bb70624e JA |
4247 | There are several single-character options that may be supplied at |
4248 | invocation which are not available with the `set' builtin. | |
ccc6cda3 | 4249 | |
bb70624e JA |
4250 | `-c STRING' |
4251 | Read and execute commands from STRING after processing the | |
4252 | options, then exit. Any remaining arguments are assigned to the | |
4253 | positional parameters, starting with `$0'. | |
ccc6cda3 | 4254 | |
bb70624e JA |
4255 | `-i' |
4256 | Force the shell to run interactively. Interactive shells are | |
4257 | described in *Note Interactive Shells::. | |
ccc6cda3 | 4258 | |
7117c2d2 JA |
4259 | `-l' |
4260 | Make this shell act as if it had been directly invoked by login. | |
4261 | When the shell is interactive, this is equivalent to starting a | |
4262 | login shell with `exec -l bash'. When the shell is not | |
4263 | interactive, the login shell startup files will be executed. | |
4264 | `exec bash -l' or `exec bash --login' will replace the current | |
4265 | shell with a Bash login shell. *Note Bash Startup Files::, for a | |
4266 | description of the special behavior of a login shell. | |
4267 | ||
bb70624e | 4268 | `-r' |
28ef6c31 | 4269 | Make the shell a restricted shell (*note The Restricted Shell::). |
ccc6cda3 | 4270 | |
bb70624e JA |
4271 | `-s' |
4272 | If this option is present, or if no arguments remain after option | |
4273 | processing, then commands are read from the standard input. This | |
4274 | option allows the positional parameters to be set when invoking an | |
4275 | interactive shell. | |
ccc6cda3 | 4276 | |
bb70624e JA |
4277 | `-D' |
4278 | A list of all double-quoted strings preceded by `$' is printed on | |
4279 | the standard ouput. These are the strings that are subject to | |
4280 | language translation when the current locale is not `C' or `POSIX' | |
28ef6c31 | 4281 | (*note Locale Translation::). This implies the `-n' option; no |
bb70624e | 4282 | commands will be executed. |
ccc6cda3 | 4283 | |
f73dda09 JA |
4284 | `[-+]O [SHOPT_OPTION]' |
4285 | SHOPT_OPTION is one of the shell options accepted by the `shopt' | |
4286 | builtin (*note Shell Builtin Commands::). If SHOPT_OPTION is | |
4287 | present, `-O' sets the value of that option; `+O' unsets it. If | |
4288 | SHOPT_OPTION is not supplied, the names and values of the shell | |
4289 | options accepted by `shopt' are printed on the standard output. | |
4290 | If the invocation option is `+O', the output is displayed in a | |
4291 | format that may be reused as input. | |
4292 | ||
bb70624e JA |
4293 | `--' |
4294 | A `--' signals the end of options and disables further option | |
4295 | processing. Any arguments after the `--' are treated as filenames | |
4296 | and arguments. | |
ccc6cda3 | 4297 | |
761783bf | 4298 | |
f73dda09 JA |
4299 | A _login_ shell is one whose first character of argument zero is |
4300 | `-', or one invoked with the `--login' option. | |
4301 | ||
28ef6c31 | 4302 | An _interactive_ shell is one started without non-option arguments, |
bb70624e JA |
4303 | unless `-s' is specified, without specifying the `-c' option, and whose |
4304 | input and output are both connected to terminals (as determined by | |
4305 | `isatty(3)'), or one started with the `-i' option. *Note Interactive | |
28ef6c31 | 4306 | Shells::, for more information. |
ccc6cda3 | 4307 | |
bb70624e JA |
4308 | If arguments remain after option processing, and neither the `-c' |
4309 | nor the `-s' option has been supplied, the first argument is assumed to | |
28ef6c31 JA |
4310 | be the name of a file containing shell commands (*note Shell Scripts::). |
4311 | When Bash is invoked in this fashion, `$0' is set to the name of the | |
4312 | file, and the positional parameters are set to the remaining arguments. | |
4313 | Bash reads and executes commands from this file, then exits. Bash's | |
4314 | exit status is the exit status of the last command executed in the | |
4315 | script. If no commands are executed, the exit status is 0. | |
ccc6cda3 | 4316 | |
bb70624e JA |
4317 | \1f |
4318 | File: bashref.info, Node: Bash Startup Files, Next: Interactive Shells, Prev: Invoking Bash, Up: Bash Features | |
ccc6cda3 | 4319 | |
761783bf CR |
4320 | 6.2 Bash Startup Files |
4321 | ====================== | |
ccc6cda3 | 4322 | |
761783bf CR |
4323 | This section describs how Bash executes its startup files. If any of |
4324 | the files exist but cannot be read, Bash reports an error. Tildes are | |
4325 | expanded in file names as described above under Tilde Expansion (*note | |
4326 | Tilde Expansion::). | |
ccc6cda3 | 4327 | |
bb70624e | 4328 | Interactive shells are described in *Note Interactive Shells::. |
ccc6cda3 | 4329 | |
bb70624e JA |
4330 | Invoked as an interactive login shell, or with `--login' |
4331 | ........................................................ | |
cce855bc | 4332 | |
761783bf | 4333 | When Bash is invoked as an interactive login shell, or as a |
bb70624e JA |
4334 | non-interactive shell with the `--login' option, it first reads and |
4335 | executes commands from the file `/etc/profile', if that file exists. | |
4336 | After reading that file, it looks for `~/.bash_profile', | |
4337 | `~/.bash_login', and `~/.profile', in that order, and reads and | |
4338 | executes commands from the first one that exists and is readable. The | |
4339 | `--noprofile' option may be used when the shell is started to inhibit | |
4340 | this behavior. | |
ccc6cda3 | 4341 | |
bb70624e JA |
4342 | When a login shell exits, Bash reads and executes commands from the |
4343 | file `~/.bash_logout', if it exists. | |
ccc6cda3 | 4344 | |
bb70624e JA |
4345 | Invoked as an interactive non-login shell |
4346 | ......................................... | |
ccc6cda3 | 4347 | |
761783bf | 4348 | When an interactive shell that is not a login shell is started, Bash |
bb70624e JA |
4349 | reads and executes commands from `~/.bashrc', if that file exists. |
4350 | This may be inhibited by using the `--norc' option. The `--rcfile | |
4351 | FILE' option will force Bash to read and execute commands from FILE | |
4352 | instead of `~/.bashrc'. | |
ccc6cda3 | 4353 | |
bb70624e JA |
4354 | So, typically, your `~/.bash_profile' contains the line |
4355 | `if [ -f ~/.bashrc ]; then . ~/.bashrc; fi' | |
761783bf | 4356 | after (or before) any login-specific initializations. |
ccc6cda3 | 4357 | |
bb70624e JA |
4358 | Invoked non-interactively |
4359 | ......................... | |
ccc6cda3 | 4360 | |
761783bf | 4361 | When Bash is started non-interactively, to run a shell script, for |
bb70624e JA |
4362 | example, it looks for the variable `BASH_ENV' in the environment, |
4363 | expands its value if it appears there, and uses the expanded value as | |
4364 | the name of a file to read and execute. Bash behaves as if the | |
4365 | following command were executed: | |
4366 | `if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi' | |
761783bf CR |
4367 | but the value of the `PATH' variable is not used to search for the |
4368 | file name. | |
ccc6cda3 | 4369 | |
28ef6c31 JA |
4370 | As noted above, if a non-interactive shell is invoked with the |
4371 | `--login' option, Bash attempts to read and execute commands from the | |
4372 | login shell startup files. | |
4373 | ||
bb70624e JA |
4374 | Invoked with name `sh' |
4375 | ...................... | |
ccc6cda3 | 4376 | |
761783bf | 4377 | If Bash is invoked with the name `sh', it tries to mimic the startup |
bb70624e JA |
4378 | behavior of historical versions of `sh' as closely as possible, while |
4379 | conforming to the POSIX standard as well. | |
ccc6cda3 | 4380 | |
bb70624e JA |
4381 | When invoked as an interactive login shell, or as a non-interactive |
4382 | shell with the `--login' option, it first attempts to read and execute | |
4383 | commands from `/etc/profile' and `~/.profile', in that order. The | |
4384 | `--noprofile' option may be used to inhibit this behavior. When | |
4385 | invoked as an interactive shell with the name `sh', Bash looks for the | |
4386 | variable `ENV', expands its value if it is defined, and uses the | |
4387 | expanded value as the name of a file to read and execute. Since a | |
4388 | shell invoked as `sh' does not attempt to read and execute commands | |
4389 | from any other startup files, the `--rcfile' option has no effect. A | |
4390 | non-interactive shell invoked with the name `sh' does not attempt to | |
4391 | read any other startup files. | |
ccc6cda3 | 4392 | |
bb70624e JA |
4393 | When invoked as `sh', Bash enters POSIX mode after the startup files |
4394 | are read. | |
b72432fd | 4395 | |
bb70624e JA |
4396 | Invoked in POSIX mode |
4397 | ..................... | |
ccc6cda3 | 4398 | |
761783bf CR |
4399 | When Bash is started in POSIX mode, as with the `--posix' command line |
4400 | option, it follows the POSIX standard for startup files. In this mode, | |
4401 | interactive shells expand the `ENV' variable and commands are read and | |
4402 | executed from the file whose name is the expanded value. No other | |
4403 | startup files are read. | |
ccc6cda3 | 4404 | |
bb70624e JA |
4405 | Invoked by remote shell daemon |
4406 | .............................. | |
ccc6cda3 | 4407 | |
761783bf | 4408 | Bash attempts to determine when it is being run by the remote shell |
bb70624e JA |
4409 | daemon, usually `rshd'. If Bash determines it is being run by rshd, it |
4410 | reads and executes commands from `~/.bashrc', if that file exists and | |
4411 | is readable. It will not do this if invoked as `sh'. The `--norc' | |
4412 | option may be used to inhibit this behavior, and the `--rcfile' option | |
4413 | may be used to force another file to be read, but `rshd' does not | |
4414 | generally invoke the shell with those options or allow them to be | |
4415 | specified. | |
ccc6cda3 | 4416 | |
bb70624e JA |
4417 | Invoked with unequal effective and real UID/GIDs |
4418 | ................................................ | |
4419 | ||
761783bf CR |
4420 | If Bash is started with the effective user (group) id not equal to the |
4421 | real user (group) id, and the `-p' option is not supplied, no startup | |
4422 | files are read, shell functions are not inherited from the environment, | |
4423 | the `SHELLOPTS' variable, if it appears in the environment, is ignored, | |
4424 | and the effective user id is set to the real user id. If the `-p' | |
4425 | option is supplied at invocation, the startup behavior is the same, but | |
4426 | the effective user id is not reset. | |
bb70624e JA |
4427 | |
4428 | \1f | |
4429 | File: bashref.info, Node: Interactive Shells, Next: Bash Conditional Expressions, Prev: Bash Startup Files, Up: Bash Features | |
4430 | ||
761783bf CR |
4431 | 6.3 Interactive Shells |
4432 | ====================== | |
bb70624e JA |
4433 | |
4434 | * Menu: | |
4435 | ||
4436 | * What is an Interactive Shell?:: What determines whether a shell is Interactive. | |
4437 | * Is this Shell Interactive?:: How to tell if a shell is interactive. | |
4438 | * Interactive Shell Behavior:: What changes in a interactive shell? | |
4439 | ||
4440 | \1f | |
4441 | File: bashref.info, Node: What is an Interactive Shell?, Next: Is this Shell Interactive?, Up: Interactive Shells | |
4442 | ||
761783bf CR |
4443 | 6.3.1 What is an Interactive Shell? |
4444 | ----------------------------------- | |
bb70624e | 4445 | |
761783bf | 4446 | An interactive shell is one started without non-option arguments, |
bb70624e | 4447 | unless `-s' is specified, without specifiying the `-c' option, and |
56299fa5 CR |
4448 | whose input and error output are both connected to terminals (as |
4449 | determined by `isatty(3)'), or one started with the `-i' option. | |
bb70624e JA |
4450 | |
4451 | An interactive shell generally reads from and writes to a user's | |
4452 | terminal. | |
4453 | ||
4454 | The `-s' invocation option may be used to set the positional | |
4455 | parameters when an interactive shell is started. | |
4456 | ||
4457 | \1f | |
4458 | File: bashref.info, Node: Is this Shell Interactive?, Next: Interactive Shell Behavior, Prev: What is an Interactive Shell?, Up: Interactive Shells | |
4459 | ||
761783bf CR |
4460 | 6.3.2 Is this Shell Interactive? |
4461 | -------------------------------- | |
bb70624e | 4462 | |
761783bf | 4463 | To determine within a startup script whether or not Bash is running |
bb70624e JA |
4464 | interactively, test the value of the `-' special parameter. It |
4465 | contains `i' when the shell is interactive. For example: | |
4466 | ||
4467 | case "$-" in | |
4468 | *i*) echo This shell is interactive ;; | |
4469 | *) echo This shell is not interactive ;; | |
4470 | esac | |
4471 | ||
28ef6c31 JA |
4472 | Alternatively, startup scripts may examine the variable `PS1'; it is |
4473 | unset in non-interactive shells, and set in interactive shells. Thus: | |
bb70624e JA |
4474 | |
4475 | if [ -z "$PS1" ]; then | |
4476 | echo This shell is not interactive | |
4477 | else | |
4478 | echo This shell is interactive | |
4479 | fi | |
4480 | ||
4481 | \1f | |
4482 | File: bashref.info, Node: Interactive Shell Behavior, Prev: Is this Shell Interactive?, Up: Interactive Shells | |
4483 | ||
761783bf CR |
4484 | 6.3.3 Interactive Shell Behavior |
4485 | -------------------------------- | |
bb70624e | 4486 | |
761783bf | 4487 | When the shell is running interactively, it changes its behavior in |
bb70624e JA |
4488 | several ways. |
4489 | ||
4490 | 1. Startup files are read and executed as described in *Note Bash | |
4491 | Startup Files::. | |
4492 | ||
28ef6c31 | 4493 | 2. Job Control (*note Job Control::) is enabled by default. When job |
bb70624e JA |
4494 | control is in effect, Bash ignores the keyboard-generated job |
4495 | control signals `SIGTTIN', `SIGTTOU', and `SIGTSTP'. | |
4496 | ||
28ef6c31 JA |
4497 | 3. Bash expands and displays `PS1' before reading the first line of a |
4498 | command, and expands and displays `PS2' before reading the second | |
4499 | and subsequent lines of a multi-line command. | |
bb70624e JA |
4500 | |
4501 | 4. Bash executes the value of the `PROMPT_COMMAND' variable as a | |
4502 | command before printing the primary prompt, `$PS1' (*note Bash | |
28ef6c31 | 4503 | Variables::). |
bb70624e | 4504 | |
28ef6c31 | 4505 | 5. Readline (*note Command Line Editing::) is used to read commands |
bb70624e JA |
4506 | from the user's terminal. |
4507 | ||
4508 | 6. Bash inspects the value of the `ignoreeof' option to `set -o' | |
4509 | instead of exiting immediately when it receives an `EOF' on its | |
28ef6c31 | 4510 | standard input when reading a command (*note The Set Builtin::). |
bb70624e | 4511 | |
28ef6c31 JA |
4512 | 7. Command history (*note Bash History Facilities::) and history |
4513 | expansion (*note History Interaction::) are enabled by default. | |
bb70624e JA |
4514 | Bash will save the command history to the file named by `$HISTFILE' |
4515 | when an interactive shell exits. | |
4516 | ||
28ef6c31 | 4517 | 8. Alias expansion (*note Aliases::) is performed by default. |
bb70624e JA |
4518 | |
4519 | 9. In the absence of any traps, Bash ignores `SIGTERM' (*note | |
28ef6c31 | 4520 | Signals::). |
bb70624e JA |
4521 | |
4522 | 10. In the absence of any traps, `SIGINT' is caught and handled | |
28ef6c31 | 4523 | ((*note Signals::). `SIGINT' will interrupt some shell builtins. |
bb70624e JA |
4524 | |
4525 | 11. An interactive login shell sends a `SIGHUP' to all jobs on exit if | |
28ef6c31 | 4526 | the `hupoxexit' shell option has been enabled (*note Signals::). |
bb70624e JA |
4527 | |
4528 | 12. The `-n' invocation option is ignored, and `set -n' has no effect | |
28ef6c31 | 4529 | (*note The Set Builtin::). |
bb70624e JA |
4530 | |
4531 | 13. Bash will check for mail periodically, depending on the values of | |
4532 | the `MAIL', `MAILPATH', and `MAILCHECK' shell variables (*note | |
28ef6c31 | 4533 | Bash Variables::). |
bb70624e JA |
4534 | |
4535 | 14. Expansion errors due to references to unbound shell variables after | |
4536 | `set -u' has been enabled will not cause the shell to exit (*note | |
28ef6c31 | 4537 | The Set Builtin::). |
bb70624e JA |
4538 | |
4539 | 15. The shell will not exit on expansion errors caused by VAR being | |
4540 | unset or null in `${VAR:?WORD}' expansions (*note Shell Parameter | |
28ef6c31 | 4541 | Expansion::). |
bb70624e JA |
4542 | |
4543 | 16. Redirection errors encountered by shell builtins will not cause the | |
4544 | shell to exit. | |
4545 | ||
4546 | 17. When running in POSIX mode, a special builtin returning an error | |
28ef6c31 | 4547 | status will not cause the shell to exit (*note Bash POSIX Mode::). |
bb70624e JA |
4548 | |
4549 | 18. A failed `exec' will not cause the shell to exit (*note Bourne | |
28ef6c31 | 4550 | Shell Builtins::). |
bb70624e JA |
4551 | |
4552 | 19. Parser syntax errors will not cause the shell to exit. | |
4553 | ||
4554 | 20. Simple spelling correction for directory arguments to the `cd' | |
4555 | builtin is enabled by default (see the description of the `cdspell' | |
4556 | option to the `shopt' builtin in *Note Bash Builtins::). | |
4557 | ||
4558 | 21. The shell will check the value of the `TMOUT' variable and exit if | |
4559 | a command is not read within the specified number of seconds after | |
28ef6c31 | 4560 | printing `$PS1' (*note Bash Variables::). |
bb70624e JA |
4561 | |
4562 | ||
4563 | \1f | |
4564 | File: bashref.info, Node: Bash Conditional Expressions, Next: Shell Arithmetic, Prev: Interactive Shells, Up: Bash Features | |
4565 | ||
761783bf CR |
4566 | 6.4 Bash Conditional Expressions |
4567 | ================================ | |
bb70624e | 4568 | |
761783bf CR |
4569 | Conditional expressions are used by the `[[' compound command and the |
4570 | `test' and `[' builtin commands. | |
bb70624e JA |
4571 | |
4572 | Expressions may be unary or binary. Unary expressions are often | |
4573 | used to examine the status of a file. There are string operators and | |
4574 | numeric comparison operators as well. If the FILE argument to one of | |
4575 | the primaries is of the form `/dev/fd/N', then file descriptor N is | |
4576 | checked. If the FILE argument to one of the primaries is one of | |
4577 | `/dev/stdin', `/dev/stdout', or `/dev/stderr', file descriptor 0, 1, or | |
4578 | 2, respectively, is checked. | |
4579 | ||
4580 | `-a FILE' | |
4581 | True if FILE exists. | |
4582 | ||
4583 | `-b FILE' | |
4584 | True if FILE exists and is a block special file. | |
4585 | ||
4586 | `-c FILE' | |
4587 | True if FILE exists and is a character special file. | |
4588 | ||
4589 | `-d FILE' | |
4590 | True if FILE exists and is a directory. | |
4591 | ||
4592 | `-e FILE' | |
4593 | True if FILE exists. | |
4594 | ||
4595 | `-f FILE' | |
4596 | True if FILE exists and is a regular file. | |
4597 | ||
4598 | `-g FILE' | |
4599 | True if FILE exists and its set-group-id bit is set. | |
4600 | ||
4601 | `-h FILE' | |
4602 | True if FILE exists and is a symbolic link. | |
4603 | ||
4604 | `-k FILE' | |
4605 | True if FILE exists and its "sticky" bit is set. | |
4606 | ||
4607 | `-p FILE' | |
4608 | True if FILE exists and is a named pipe (FIFO). | |
4609 | ||
4610 | `-r FILE' | |
4611 | True if FILE exists and is readable. | |
4612 | ||
4613 | `-s FILE' | |
4614 | True if FILE exists and has a size greater than zero. | |
4615 | ||
4616 | `-t FD' | |
4617 | True if file descriptor FD is open and refers to a terminal. | |
ccc6cda3 JA |
4618 | |
4619 | `-u FILE' | |
4620 | True if FILE exists and its set-user-id bit is set. | |
4621 | ||
4622 | `-w FILE' | |
4623 | True if FILE exists and is writable. | |
4624 | ||
4625 | `-x FILE' | |
4626 | True if FILE exists and is executable. | |
4627 | ||
4628 | `-O FILE' | |
4629 | True if FILE exists and is owned by the effective user id. | |
4630 | ||
4631 | `-G FILE' | |
4632 | True if FILE exists and is owned by the effective group id. | |
4633 | ||
cce855bc JA |
4634 | `-L FILE' |
4635 | True if FILE exists and is a symbolic link. | |
4636 | ||
4637 | `-S FILE' | |
4638 | True if FILE exists and is a socket. | |
4639 | ||
4640 | `-N FILE' | |
4641 | True if FILE exists and has been modified since it was last read. | |
4642 | ||
ccc6cda3 | 4643 | `FILE1 -nt FILE2' |
7117c2d2 JA |
4644 | True if FILE1 is newer (according to modification date) than |
4645 | FILE2, or if FILE1 exists and FILE2 does not. | |
ccc6cda3 JA |
4646 | |
4647 | `FILE1 -ot FILE2' | |
7117c2d2 JA |
4648 | True if FILE1 is older than FILE2, or if FILE2 exists and FILE1 |
4649 | does not. | |
ccc6cda3 JA |
4650 | |
4651 | `FILE1 -ef FILE2' | |
7117c2d2 | 4652 | True if FILE1 and FILE2 refer to the same device and inode numbers. |
ccc6cda3 JA |
4653 | |
4654 | `-o OPTNAME' | |
4655 | True if shell option OPTNAME is enabled. The list of options | |
4656 | appears in the description of the `-o' option to the `set' builtin | |
28ef6c31 | 4657 | (*note The Set Builtin::). |
ccc6cda3 JA |
4658 | |
4659 | `-z STRING' | |
4660 | True if the length of STRING is zero. | |
4661 | ||
4662 | `-n STRING' | |
4663 | `STRING' | |
4664 | True if the length of STRING is non-zero. | |
4665 | ||
cce855bc | 4666 | `STRING1 == STRING2' |
7117c2d2 JA |
4667 | True if the strings are equal. `=' may be used in place of `==' |
4668 | for strict POSIX compliance. | |
ccc6cda3 JA |
4669 | |
4670 | `STRING1 != STRING2' | |
4671 | True if the strings are not equal. | |
4672 | ||
4673 | `STRING1 < STRING2' | |
cce855bc JA |
4674 | True if STRING1 sorts before STRING2 lexicographically in the |
4675 | current locale. | |
ccc6cda3 JA |
4676 | |
4677 | `STRING1 > STRING2' | |
cce855bc JA |
4678 | True if STRING1 sorts after STRING2 lexicographically in the |
4679 | current locale. | |
ccc6cda3 JA |
4680 | |
4681 | `ARG1 OP ARG2' | |
4682 | `OP' is one of `-eq', `-ne', `-lt', `-le', `-gt', or `-ge'. These | |
4683 | arithmetic binary operators return true if ARG1 is equal to, not | |
4684 | equal to, less than, less than or equal to, greater than, or | |
4685 | greater than or equal to ARG2, respectively. ARG1 and ARG2 may be | |
4686 | positive or negative integers. | |
4687 | ||
761783bf | 4688 | |
ccc6cda3 | 4689 | \1f |
bb70624e | 4690 | File: bashref.info, Node: Shell Arithmetic, Next: Aliases, Prev: Bash Conditional Expressions, Up: Bash Features |
ccc6cda3 | 4691 | |
761783bf CR |
4692 | 6.5 Shell Arithmetic |
4693 | ==================== | |
ccc6cda3 | 4694 | |
761783bf CR |
4695 | The shell allows arithmetic expressions to be evaluated, as one of the |
4696 | shell expansions or by the `let' and the `-i' option to the `declare' | |
4697 | builtins. | |
ccc6cda3 | 4698 | |
7117c2d2 JA |
4699 | Evaluation is done in fixed-width integers with no check for |
4700 | overflow, though division by 0 is trapped and flagged as an error. The | |
d3a24ed2 CR |
4701 | operators and their precedence, associativity, and values are the same |
4702 | as in the C language. The following list of operators is grouped into | |
4703 | levels of equal-precedence operators. The levels are listed in order | |
4704 | of decreasing precedence. | |
cce855bc | 4705 | |
bb70624e JA |
4706 | `ID++ ID--' |
4707 | variable post-increment and post-decrement | |
d166f048 | 4708 | |
bb70624e JA |
4709 | `++ID --ID' |
4710 | variable pre-increment and pre-decrement | |
ccc6cda3 | 4711 | |
bb70624e JA |
4712 | `- +' |
4713 | unary minus and plus | |
ccc6cda3 | 4714 | |
bb70624e JA |
4715 | `! ~' |
4716 | logical and bitwise negation | |
ccc6cda3 | 4717 | |
bb70624e JA |
4718 | `**' |
4719 | exponentiation | |
ccc6cda3 | 4720 | |
bb70624e JA |
4721 | `* / %' |
4722 | multiplication, division, remainder | |
ccc6cda3 | 4723 | |
bb70624e JA |
4724 | `+ -' |
4725 | addition, subtraction | |
ccc6cda3 | 4726 | |
bb70624e JA |
4727 | `<< >>' |
4728 | left and right bitwise shifts | |
cce855bc | 4729 | |
bb70624e JA |
4730 | `<= >= < >' |
4731 | comparison | |
cce855bc | 4732 | |
bb70624e JA |
4733 | `== !=' |
4734 | equality and inequality | |
cce855bc | 4735 | |
bb70624e JA |
4736 | `&' |
4737 | bitwise AND | |
cce855bc | 4738 | |
bb70624e JA |
4739 | `^' |
4740 | bitwise exclusive OR | |
cce855bc | 4741 | |
bb70624e JA |
4742 | `|' |
4743 | bitwise OR | |
cce855bc | 4744 | |
bb70624e JA |
4745 | `&&' |
4746 | logical AND | |
ccc6cda3 | 4747 | |
bb70624e JA |
4748 | `||' |
4749 | logical OR | |
ccc6cda3 | 4750 | |
bb70624e | 4751 | `expr ? expr : expr' |
d3a24ed2 | 4752 | conditional operator |
cce855bc | 4753 | |
bb70624e JA |
4754 | `= *= /= %= += -= <<= >>= &= ^= |=' |
4755 | assignment | |
ccc6cda3 | 4756 | |
bb70624e JA |
4757 | `expr1 , expr2' |
4758 | comma | |
ccc6cda3 | 4759 | |
bb70624e JA |
4760 | Shell variables are allowed as operands; parameter expansion is |
4761 | performed before the expression is evaluated. Within an expression, | |
4762 | shell variables may also be referenced by name without using the | |
d3a24ed2 CR |
4763 | parameter expansion syntax. A shell variable that is null or unset |
4764 | evaluates to 0 when referenced by name without using the parameter | |
4765 | expansion syntax. The value of a variable is evaluated as an | |
4766 | arithmetic expression when it is referenced, or when a variable which | |
4767 | has been given the INTEGER attribute using `declare -i' is assigned a | |
4768 | value. A null value evaluates to 0. A shell variable need not have | |
4769 | its integer attribute turned on to be used in an expression. | |
ccc6cda3 | 4770 | |
bb70624e JA |
4771 | Constants with a leading 0 are interpreted as octal numbers. A |
4772 | leading `0x' or `0X' denotes hexadecimal. Otherwise, numbers take the | |
4773 | form [BASE`#']N, where BASE is a decimal number between 2 and 64 | |
4774 | representing the arithmetic base, and N is a number in that base. If | |
4775 | BASE`#' is omitted, then base 10 is used. The digits greater than 9 | |
f73dda09 JA |
4776 | are represented by the lowercase letters, the uppercase letters, `@', |
4777 | and `_', in that order. If BASE is less than or equal to 36, lowercase | |
bb70624e JA |
4778 | and uppercase letters may be used interchangably to represent numbers |
4779 | between 10 and 35. | |
ccc6cda3 | 4780 | |
bb70624e JA |
4781 | Operators are evaluated in order of precedence. Sub-expressions in |
4782 | parentheses are evaluated first and may override the precedence rules | |
4783 | above. | |
ccc6cda3 | 4784 | |
bb70624e JA |
4785 | \1f |
4786 | File: bashref.info, Node: Aliases, Next: Arrays, Prev: Shell Arithmetic, Up: Bash Features | |
ccc6cda3 | 4787 | |
761783bf CR |
4788 | 6.6 Aliases |
4789 | =========== | |
ccc6cda3 | 4790 | |
761783bf CR |
4791 | ALIASES allow a string to be substituted for a word when it is used as |
4792 | the first word of a simple command. The shell maintains a list of | |
bb70624e | 4793 | aliases that may be set and unset with the `alias' and `unalias' |
cce855bc JA |
4794 | builtin commands. |
4795 | ||
4796 | The first word of each simple command, if unquoted, is checked to see | |
4797 | if it has an alias. If so, that word is replaced by the text of the | |
de8913bd CR |
4798 | alias. The characters `/', `$', ``', `=' and any of the shell |
4799 | metacharacters or quoting characters listed above may not appear in an | |
4800 | alias name. The replacement text may contain any valid shell input, | |
4801 | including shell metacharacters. The first word of the replacement text | |
4802 | is tested for aliases, but a word that is identical to an alias being | |
4803 | expanded is not expanded a second time. This means that one may alias | |
4804 | `ls' to `"ls -F"', for instance, and Bash does not try to recursively | |
4805 | expand the replacement text. If the last character of the alias value | |
4806 | is a space or tab character, then the next command word following the | |
4807 | alias is also checked for alias expansion. | |
cce855bc JA |
4808 | |
4809 | Aliases are created and listed with the `alias' command, and removed | |
4810 | with the `unalias' command. | |
4811 | ||
4812 | There is no mechanism for using arguments in the replacement text, | |
4813 | as in `csh'. If arguments are needed, a shell function should be used | |
28ef6c31 | 4814 | (*note Shell Functions::). |
cce855bc JA |
4815 | |
4816 | Aliases are not expanded when the shell is not interactive, unless | |
4817 | the `expand_aliases' shell option is set using `shopt' (*note Bash | |
28ef6c31 | 4818 | Builtins::). |
ccc6cda3 | 4819 | |
cce855bc JA |
4820 | The rules concerning the definition and use of aliases are somewhat |
4821 | confusing. Bash always reads at least one complete line of input | |
4822 | before executing any of the commands on that line. Aliases are | |
4823 | expanded when a command is read, not when it is executed. Therefore, an | |
4824 | alias definition appearing on the same line as another command does not | |
4825 | take effect until the next line of input is read. The commands | |
4826 | following the alias definition on that line are not affected by the new | |
4827 | alias. This behavior is also an issue when functions are executed. | |
4828 | Aliases are expanded when a function definition is read, not when the | |
4829 | function is executed, because a function definition is itself a | |
4830 | compound command. As a consequence, aliases defined in a function are | |
4831 | not available until after that function is executed. To be safe, | |
4832 | always put alias definitions on a separate line, and do not use `alias' | |
4833 | in compound commands. | |
ccc6cda3 | 4834 | |
bb70624e | 4835 | For almost every purpose, shell functions are preferred over aliases. |
ccc6cda3 JA |
4836 | |
4837 | \1f | |
cce855bc | 4838 | File: bashref.info, Node: Arrays, Next: The Directory Stack, Prev: Aliases, Up: Bash Features |
ccc6cda3 | 4839 | |
761783bf CR |
4840 | 6.7 Arrays |
4841 | ========== | |
ccc6cda3 | 4842 | |
761783bf | 4843 | Bash provides one-dimensional array variables. Any variable may be |
ccc6cda3 JA |
4844 | used as an array; the `declare' builtin will explicitly declare an |
4845 | array. There is no maximum limit on the size of an array, nor any | |
4846 | requirement that members be indexed or assigned contiguously. Arrays | |
4847 | are zero-based. | |
4848 | ||
4849 | An array is created automatically if any variable is assigned to | |
4850 | using the syntax | |
4851 | name[SUBSCRIPT]=VALUE | |
4852 | ||
4853 | The SUBSCRIPT is treated as an arithmetic expression that must evaluate | |
4854 | to a number greater than or equal to zero. To explicitly declare an | |
4855 | array, use | |
4856 | declare -a NAME | |
761783bf | 4857 | The syntax |
ccc6cda3 | 4858 | declare -a NAME[SUBSCRIPT] |
761783bf | 4859 | is also accepted; the SUBSCRIPT is ignored. Attributes may be |
ccc6cda3 JA |
4860 | specified for an array variable using the `declare' and `readonly' |
4861 | builtins. Each attribute applies to all members of an array. | |
4862 | ||
4863 | Arrays are assigned to using compound assignments of the form | |
4864 | name=(value1 ... valueN) | |
761783bf | 4865 | where each VALUE is of the form `[[SUBSCRIPT]=]'STRING. If the |
ccc6cda3 JA |
4866 | optional subscript is supplied, that index is assigned to; otherwise |
4867 | the index of the element assigned is the last index assigned to by the | |
4868 | statement plus one. Indexing starts at zero. This syntax is also | |
4869 | accepted by the `declare' builtin. Individual array elements may be | |
4870 | assigned to using the `name['SUBSCRIPT`]='VALUE syntax introduced above. | |
4871 | ||
4872 | Any element of an array may be referenced using | |
4873 | `${name['SUBSCRIPT`]}'. The braces are required to avoid conflicts | |
4874 | with the shell's filename expansion operators. If the SUBSCRIPT is `@' | |
4875 | or `*', the word expands to all members of the array NAME. These | |
4876 | subscripts differ only when the word appears within double quotes. If | |
4877 | the word is double-quoted, `${name[*]}' expands to a single word with | |
4878 | the value of each array member separated by the first character of the | |
4879 | `IFS' variable, and `${name[@]}' expands each element of NAME to a | |
4880 | separate word. When there are no array members, `${name[@]}' expands | |
4881 | to nothing. This is analogous to the expansion of the special | |
4882 | parameters `@' and `*'. `${#name['SUBSCRIPT`]}' expands to the length | |
4883 | of `${name['SUBSCRIPT`]}'. If SUBSCRIPT is `@' or `*', the expansion | |
4884 | is the number of elements in the array. Referencing an array variable | |
4885 | without a subscript is equivalent to referencing element zero. | |
4886 | ||
4887 | The `unset' builtin is used to destroy arrays. `unset' | |
bb70624e JA |
4888 | NAME[SUBSCRIPT] destroys the array element at index SUBSCRIPT. `unset' |
4889 | NAME, where NAME is an array, removes the entire array. A subscript of | |
4890 | `*' or `@' also removes the entire array. | |
ccc6cda3 JA |
4891 | |
4892 | The `declare', `local', and `readonly' builtins each accept a `-a' | |
4893 | option to specify an array. The `read' builtin accepts a `-a' option | |
4894 | to assign a list of words read from the standard input to an array, and | |
4895 | can read values from the standard input into individual array elements. | |
4896 | The `set' and `declare' builtins display array values in a way that | |
4897 | allows them to be reused as input. | |
4898 | ||
4899 | \1f | |
cce855bc JA |
4900 | File: bashref.info, Node: The Directory Stack, Next: Printing a Prompt, Prev: Arrays, Up: Bash Features |
4901 | ||
761783bf CR |
4902 | 6.8 The Directory Stack |
4903 | ======================= | |
cce855bc | 4904 | |
bb70624e JA |
4905 | * Menu: |
4906 | ||
4907 | * Directory Stack Builtins:: Bash builtin commands to manipulate | |
4908 | the directory stack. | |
4909 | ||
4910 | The directory stack is a list of recently-visited directories. The | |
cce855bc JA |
4911 | `pushd' builtin adds directories to the stack as it changes the current |
4912 | directory, and the `popd' builtin removes specified directories from | |
4913 | the stack and changes the current directory to the directory removed. | |
4914 | The `dirs' builtin displays the contents of the directory stack. | |
4915 | ||
4916 | The contents of the directory stack are also visible as the value of | |
4917 | the `DIRSTACK' shell variable. | |
4918 | ||
bb70624e JA |
4919 | \1f |
4920 | File: bashref.info, Node: Directory Stack Builtins, Up: The Directory Stack | |
4921 | ||
761783bf CR |
4922 | 6.8.1 Directory Stack Builtins |
4923 | ------------------------------ | |
bb70624e | 4924 | |
cce855bc | 4925 | `dirs' |
bb70624e | 4926 | dirs [+N | -N] [-clpv] |
cce855bc JA |
4927 | Display the list of currently remembered directories. Directories |
4928 | are added to the list with the `pushd' command; the `popd' command | |
4929 | removes directories from the list. | |
4930 | `+N' | |
4931 | Displays the Nth directory (counting from the left of the | |
4932 | list printed by `dirs' when invoked without options), starting | |
4933 | with zero. | |
4934 | ||
4935 | `-N' | |
4936 | Displays the Nth directory (counting from the right of the | |
4937 | list printed by `dirs' when invoked without options), starting | |
4938 | with zero. | |
4939 | ||
4940 | `-c' | |
4941 | Clears the directory stack by deleting all of the elements. | |
4942 | ||
4943 | `-l' | |
4944 | Produces a longer listing; the default listing format uses a | |
4945 | tilde to denote the home directory. | |
4946 | ||
4947 | `-p' | |
4948 | Causes `dirs' to print the directory stack with one entry per | |
4949 | line. | |
4950 | ||
4951 | `-v' | |
4952 | Causes `dirs' to print the directory stack with one entry per | |
4953 | line, prefixing each entry with its index in the stack. | |
4954 | ||
4955 | `popd' | |
4956 | popd [+N | -N] [-n] | |
4957 | ||
4958 | Remove the top entry from the directory stack, and `cd' to the new | |
4959 | top directory. When no arguments are given, `popd' removes the | |
4960 | top directory from the stack and performs a `cd' to the new top | |
4961 | directory. The elements are numbered from 0 starting at the first | |
4962 | directory listed with `dirs'; i.e., `popd' is equivalent to `popd | |
4963 | +0'. | |
4964 | `+N' | |
4965 | Removes the Nth directory (counting from the left of the list | |
4966 | printed by `dirs'), starting with zero. | |
4967 | ||
4968 | `-N' | |
4969 | Removes the Nth directory (counting from the right of the | |
4970 | list printed by `dirs'), starting with zero. | |
4971 | ||
4972 | `-n' | |
4973 | Suppresses the normal change of directory when removing | |
4974 | directories from the stack, so that only the stack is | |
4975 | manipulated. | |
4976 | ||
4977 | `pushd' | |
4978 | pushd [DIR | +N | -N] [-n] | |
4979 | ||
4980 | Save the current directory on the top of the directory stack and | |
4981 | then `cd' to DIR. With no arguments, `pushd' exchanges the top | |
4982 | two directories. | |
4983 | ||
4984 | `+N' | |
4985 | Brings the Nth directory (counting from the left of the list | |
4986 | printed by `dirs', starting with zero) to the top of the list | |
4987 | by rotating the stack. | |
4988 | ||
4989 | `-N' | |
4990 | Brings the Nth directory (counting from the right of the list | |
4991 | printed by `dirs', starting with zero) to the top of the list | |
4992 | by rotating the stack. | |
4993 | ||
4994 | `-n' | |
4995 | Suppresses the normal change of directory when adding | |
4996 | directories to the stack, so that only the stack is | |
4997 | manipulated. | |
4998 | ||
4999 | `DIR' | |
5000 | Makes the current working directory be the top of the stack, | |
5001 | and then executes the equivalent of ``cd' DIR'. `cd's to DIR. | |
5002 | ||
761783bf | 5003 | |
cce855bc JA |
5004 | \1f |
5005 | File: bashref.info, Node: Printing a Prompt, Next: The Restricted Shell, Prev: The Directory Stack, Up: Bash Features | |
ccc6cda3 | 5006 | |
761783bf CR |
5007 | 6.9 Controlling the Prompt |
5008 | ========================== | |
ccc6cda3 | 5009 | |
761783bf CR |
5010 | The value of the variable `PROMPT_COMMAND' is examined just before Bash |
5011 | prints each primary prompt. If `PROMPT_COMMAND' is set and has a | |
bb70624e JA |
5012 | non-null value, then the value is executed just as if it had been typed |
5013 | on the command line. | |
ccc6cda3 JA |
5014 | |
5015 | In addition, the following table describes the special characters | |
5016 | which can appear in the prompt variables: | |
5017 | ||
5018 | `\a' | |
cce855bc | 5019 | A bell character. |
ccc6cda3 JA |
5020 | |
5021 | `\d' | |
cce855bc | 5022 | The date, in "Weekday Month Date" format (e.g., "Tue May 26"). |
ccc6cda3 | 5023 | |
7117c2d2 JA |
5024 | `\D{FORMAT}' |
5025 | The FORMAT is passed to `strftime'(3) and the result is inserted | |
5026 | into the prompt string; an empty FORMAT results in a | |
5027 | locale-specific time representation. The braces are required. | |
5028 | ||
ccc6cda3 | 5029 | `\e' |
cce855bc | 5030 | An escape character. |
ccc6cda3 JA |
5031 | |
5032 | `\h' | |
cce855bc | 5033 | The hostname, up to the first `.'. |
ccc6cda3 JA |
5034 | |
5035 | `\H' | |
cce855bc | 5036 | The hostname. |
ccc6cda3 | 5037 | |
bb70624e JA |
5038 | `\j' |
5039 | The number of jobs currently managed by the shell. | |
5040 | ||
5041 | `\l' | |
5042 | The basename of the shell's terminal device name. | |
5043 | ||
ccc6cda3 | 5044 | `\n' |
cce855bc JA |
5045 | A newline. |
5046 | ||
5047 | `\r' | |
5048 | A carriage return. | |
ccc6cda3 JA |
5049 | |
5050 | `\s' | |
cce855bc | 5051 | The name of the shell, the basename of `$0' (the portion following |
ccc6cda3 JA |
5052 | the final slash). |
5053 | ||
5054 | `\t' | |
cce855bc | 5055 | The time, in 24-hour HH:MM:SS format. |
ccc6cda3 JA |
5056 | |
5057 | `\T' | |
cce855bc | 5058 | The time, in 12-hour HH:MM:SS format. |
ccc6cda3 JA |
5059 | |
5060 | `\@' | |
cce855bc JA |
5061 | The time, in 12-hour am/pm format. |
5062 | ||
f73dda09 JA |
5063 | `\A' |
5064 | The time, in 24-hour HH:MM format. | |
5065 | ||
cce855bc JA |
5066 | `\u' |
5067 | The username of the current user. | |
ccc6cda3 JA |
5068 | |
5069 | `\v' | |
cce855bc | 5070 | The version of Bash (e.g., 2.00) |
ccc6cda3 JA |
5071 | |
5072 | `\V' | |
cce855bc | 5073 | The release of Bash, version + patchlevel (e.g., 2.00.0) |
ccc6cda3 JA |
5074 | |
5075 | `\w' | |
12d937f9 CR |
5076 | The current working directory, with `$HOME' abbreviated with a |
5077 | tilde. | |
ccc6cda3 JA |
5078 | |
5079 | `\W' | |
12d937f9 | 5080 | The basename of `$PWD', with `$HOME' abbreviated with a tilde. |
ccc6cda3 JA |
5081 | |
5082 | `\!' | |
cce855bc | 5083 | The history number of this command. |
ccc6cda3 JA |
5084 | |
5085 | `\#' | |
cce855bc | 5086 | The command number of this command. |
ccc6cda3 JA |
5087 | |
5088 | `\$' | |
cce855bc | 5089 | If the effective uid is 0, `#', otherwise `$'. |
ccc6cda3 | 5090 | |
cce855bc JA |
5091 | `\NNN' |
5092 | The character whose ASCII code is the octal value NNN. | |
ccc6cda3 JA |
5093 | |
5094 | `\\' | |
cce855bc | 5095 | A backslash. |
ccc6cda3 JA |
5096 | |
5097 | `\[' | |
cce855bc | 5098 | Begin a sequence of non-printing characters. This could be used to |
ccc6cda3 JA |
5099 | embed a terminal control sequence into the prompt. |
5100 | ||
5101 | `\]' | |
cce855bc | 5102 | End a sequence of non-printing characters. |
ccc6cda3 | 5103 | |
bb70624e JA |
5104 | The command number and the history number are usually different: the |
5105 | history number of a command is its position in the history list, which | |
5106 | may include commands restored from the history file (*note Bash History | |
28ef6c31 JA |
5107 | Facilities::), while the command number is the position in the sequence |
5108 | of commands executed during the current shell session. | |
bb70624e JA |
5109 | |
5110 | After the string is decoded, it is expanded via parameter expansion, | |
5111 | command substitution, arithmetic expansion, and quote removal, subject | |
28ef6c31 | 5112 | to the value of the `promptvars' shell option (*note Bash Builtins::). |
bb70624e | 5113 | |
ccc6cda3 JA |
5114 | \1f |
5115 | File: bashref.info, Node: The Restricted Shell, Next: Bash POSIX Mode, Prev: Printing a Prompt, Up: Bash Features | |
5116 | ||
761783bf CR |
5117 | 6.10 The Restricted Shell |
5118 | ========================= | |
ccc6cda3 | 5119 | |
761783bf CR |
5120 | If Bash is started with the name `rbash', or the `--restricted' or `-r' |
5121 | option is supplied at invocation, the shell becomes restricted. A | |
ccc6cda3 JA |
5122 | restricted shell is used to set up an environment more controlled than |
5123 | the standard shell. A restricted shell behaves identically to `bash' | |
7117c2d2 JA |
5124 | with the exception that the following are disallowed or not performed: |
5125 | ||
ccc6cda3 JA |
5126 | * Changing directories with the `cd' builtin. |
5127 | ||
b72432fd JA |
5128 | * Setting or unsetting the values of the `SHELL', `PATH', `ENV', or |
5129 | `BASH_ENV' variables. | |
ccc6cda3 JA |
5130 | |
5131 | * Specifying command names containing slashes. | |
5132 | ||
5133 | * Specifying a filename containing a slash as an argument to the `.' | |
5134 | builtin command. | |
5135 | ||
bb70624e JA |
5136 | * Specifying a filename containing a slash as an argument to the `-p' |
5137 | option to the `hash' builtin command. | |
5138 | ||
ccc6cda3 JA |
5139 | * Importing function definitions from the shell environment at |
5140 | startup. | |
5141 | ||
cce855bc JA |
5142 | * Parsing the value of `SHELLOPTS' from the shell environment at |
5143 | startup. | |
5144 | ||
ccc6cda3 JA |
5145 | * Redirecting output using the `>', `>|', `<>', `>&', `&>', and `>>' |
5146 | redirection operators. | |
5147 | ||
5148 | * Using the `exec' builtin to replace the shell with another command. | |
5149 | ||
5150 | * Adding or deleting builtin commands with the `-f' and `-d' options | |
5151 | to the `enable' builtin. | |
5152 | ||
7117c2d2 JA |
5153 | * Using the `enable' builtin command to enable disabled shell |
5154 | builtins. | |
5155 | ||
ccc6cda3 JA |
5156 | * Specifying the `-p' option to the `command' builtin. |
5157 | ||
cce855bc | 5158 | * Turning off restricted mode with `set +r' or `set +o restricted'. |
ccc6cda3 | 5159 | |
7117c2d2 JA |
5160 | These restrictions are enforced after any startup files are read. |
5161 | ||
5162 | When a command that is found to be a shell script is executed (*note | |
5163 | Shell Scripts::), `rbash' turns off any restrictions in the shell | |
5164 | spawned to execute the script. | |
5165 | ||
ccc6cda3 JA |
5166 | \1f |
5167 | File: bashref.info, Node: Bash POSIX Mode, Prev: The Restricted Shell, Up: Bash Features | |
5168 | ||
761783bf CR |
5169 | 6.11 Bash POSIX Mode |
5170 | ==================== | |
ccc6cda3 | 5171 | |
761783bf CR |
5172 | Starting Bash with the `--posix' command-line option or executing `set |
5173 | -o posix' while Bash is running will cause Bash to conform more closely | |
5174 | to the POSIX 1003.2 standard by changing the behavior to match that | |
5175 | specified by POSIX in areas where the Bash default differs. | |
ccc6cda3 | 5176 | |
7117c2d2 JA |
5177 | When invoked as `sh', Bash enters POSIX mode after reading the |
5178 | startup files. | |
5179 | ||
ccc6cda3 JA |
5180 | The following list is what's changed when `POSIX mode' is in effect: |
5181 | ||
5182 | 1. When a command in the hash table no longer exists, Bash will | |
5183 | re-search `$PATH' to find the new location. This is also | |
5184 | available with `shopt -s checkhash'. | |
5185 | ||
28ef6c31 JA |
5186 | 2. The message printed by the job control code and builtins when a job |
5187 | exits with a non-zero status is `Done(status)'. | |
ccc6cda3 JA |
5188 | |
5189 | 3. The message printed by the job control code and builtins when a job | |
28ef6c31 JA |
5190 | is stopped is `Stopped(SIGNAME)', where SIGNAME is, for example, |
5191 | `SIGTSTP'. | |
ccc6cda3 JA |
5192 | |
5193 | 4. Reserved words may not be aliased. | |
5194 | ||
bb70624e | 5195 | 5. The POSIX 1003.2 `PS1' and `PS2' expansions of `!' to the history |
ccc6cda3 | 5196 | number and `!!' to `!' are enabled, and parameter expansion is |
cce855bc JA |
5197 | performed on the values of `PS1' and `PS2' regardless of the |
5198 | setting of the `promptvars' option. | |
ccc6cda3 | 5199 | |
d3a24ed2 | 5200 | 6. The POSIX 1003.2 startup files are executed (`$ENV') rather than |
bb70624e | 5201 | the normal Bash files. |
ccc6cda3 | 5202 | |
d3a24ed2 | 5203 | 7. Tilde expansion is only performed on assignments preceding a |
ccc6cda3 JA |
5204 | command name, rather than on all assignment statements on the line. |
5205 | ||
d3a24ed2 | 5206 | 8. The default history file is `~/.sh_history' (this is the default |
ccc6cda3 JA |
5207 | value of `$HISTFILE'). |
5208 | ||
d3a24ed2 CR |
5209 | 9. The output of `kill -l' prints all the signal names on a single |
5210 | line, separated by spaces, without the `SIG' prefix. | |
5211 | ||
5212 | 10. The `kill' builtin does not accept signal names with a `SIG' | |
5213 | prefix. | |
ccc6cda3 JA |
5214 | |
5215 | 11. Non-interactive shells exit if FILENAME in `.' FILENAME is not | |
5216 | found. | |
5217 | ||
cce855bc JA |
5218 | 12. Non-interactive shells exit if a syntax error in an arithmetic |
5219 | expansion results in an invalid expression. | |
5220 | ||
5221 | 13. Redirection operators do not perform filename expansion on the word | |
ccc6cda3 JA |
5222 | in the redirection unless the shell is interactive. |
5223 | ||
bb70624e JA |
5224 | 14. Redirection operators do not perform word splitting on the word in |
5225 | the redirection. | |
5226 | ||
5227 | 15. Function names must be valid shell `name's. That is, they may not | |
ccc6cda3 | 5228 | contain characters other than letters, digits, and underscores, and |
cce855bc | 5229 | may not start with a digit. Declaring a function with an invalid |
ccc6cda3 JA |
5230 | name causes a fatal syntax error in non-interactive shells. |
5231 | ||
bb70624e JA |
5232 | 16. POSIX 1003.2 `special' builtins are found before shell functions |
5233 | during command lookup. | |
ccc6cda3 | 5234 | |
bb70624e | 5235 | 17. If a POSIX 1003.2 special builtin returns an error status, a |
ccc6cda3 JA |
5236 | non-interactive shell exits. The fatal errors are those listed in |
5237 | the POSIX.2 standard, and include things like passing incorrect | |
5238 | options, redirection errors, variable assignment errors for | |
5239 | assignments preceding the command name, and so on. | |
5240 | ||
bb70624e | 5241 | 18. If the `cd' builtin finds a directory to change to using |
ccc6cda3 JA |
5242 | `$CDPATH', the value it assigns to the `PWD' variable does not |
5243 | contain any symbolic links, as if `cd -P' had been executed. | |
5244 | ||
28ef6c31 | 5245 | 19. If `CDPATH' is set, the `cd' builtin will not implicitly append |
cce855bc JA |
5246 | the current directory to it. This means that `cd' will fail if no |
5247 | valid directory name can be constructed from any of the entries in | |
5248 | `$CDPATH', even if the a directory with the same name as the name | |
5249 | given as an argument to `cd' exists in the current directory. | |
5250 | ||
bb70624e | 5251 | 20. A non-interactive shell exits with an error status if a variable |
ccc6cda3 JA |
5252 | assignment error occurs when no command name follows the assignment |
5253 | statements. A variable assignment error occurs, for example, when | |
cce855bc | 5254 | trying to assign a value to a readonly variable. |
ccc6cda3 | 5255 | |
bb70624e | 5256 | 21. A non-interactive shell exits with an error status if the iteration |
ccc6cda3 | 5257 | variable in a `for' statement or the selection variable in a |
cce855bc | 5258 | `select' statement is a readonly variable. |
ccc6cda3 | 5259 | |
bb70624e | 5260 | 22. Process substitution is not available. |
ccc6cda3 | 5261 | |
bb70624e JA |
5262 | 23. Assignment statements preceding POSIX 1003.2 special builtins |
5263 | persist in the shell environment after the builtin completes. | |
ccc6cda3 | 5264 | |
28ef6c31 JA |
5265 | 24. Assignment statements preceding shell function calls persist in the |
5266 | shell environment after the function returns, as if a POSIX | |
5267 | special builtin command had been executed. | |
5268 | ||
5269 | 25. The `export' and `readonly' builtin commands display their output | |
bb70624e | 5270 | in the format required by POSIX 1003.2. |
d166f048 | 5271 | |
28ef6c31 JA |
5272 | 26. The `trap' builtin displays signal names without the leading `SIG'. |
5273 | ||
d3a24ed2 CR |
5274 | 27. The `trap' builtin doesn't check the first argument for a possible |
5275 | signal specification and revert the signal handling to the original | |
5276 | disposition if it is. If users want to reset the handler for a | |
5277 | given signal to the original disposition, they should use `-' as | |
5278 | the first argument. | |
5279 | ||
5280 | 28. The `.' and `source' builtins do not search the current directory | |
28ef6c31 JA |
5281 | for the filename argument if it is not found by searching `PATH'. |
5282 | ||
d3a24ed2 | 5283 | 29. Subshells spawned to execute command substitutions inherit the |
28ef6c31 JA |
5284 | value of the `-e' option from the parent shell. When not in POSIX |
5285 | mode, Bash clears the `-e' option in such subshells. | |
5286 | ||
d3a24ed2 | 5287 | 30. Alias expansion is always enabled, even in non-interactive shells. |
28ef6c31 | 5288 | |
d3a24ed2 CR |
5289 | 31. When the `alias' builtin displays alias definitions, it does not |
5290 | display them with a leading `alias ' unless the `-p' option is | |
5291 | supplied. | |
5292 | ||
5293 | 32. When the `set' builtin is invoked without options, it does not | |
28ef6c31 JA |
5294 | display shell function names and definitions. |
5295 | ||
d3a24ed2 | 5296 | 33. When the `set' builtin is invoked without options, it displays |
f73dda09 JA |
5297 | variable values without quotes, unless they contain shell |
5298 | metacharacters, even if the result contains nonprinting characters. | |
ccc6cda3 | 5299 | |
d3a24ed2 | 5300 | 34. When the `cd' builtin is invoked in LOGICAL mode, and the pathname |
7117c2d2 JA |
5301 | constructed from `$PWD' and the directory name supplied as an |
5302 | argument does not refer to an existing directory, `cd' will fail | |
5303 | instead of falling back to PHYSICAL mode. | |
5304 | ||
bb70624e | 5305 | There is other POSIX 1003.2 behavior that Bash does not implement. |
ccc6cda3 JA |
5306 | Specifically: |
5307 | ||
5308 | 1. Assignment statements affect the execution environment of all | |
5309 | builtins, not just special ones. | |
5310 | ||
28ef6c31 JA |
5311 | 2. When a subshell is created to execute a shell script with execute |
5312 | permission, but without a leading `#!', Bash sets `$0' to the full | |
5313 | pathname of the script as found by searching `$PATH', rather than | |
5314 | the command as typed by the user. | |
5315 | ||
5316 | 3. When using `.' to source a shell script found in `$PATH', bash | |
5317 | checks execute permission bits rather than read permission bits, | |
5318 | just as if it were searching for a command. | |
5319 | ||
5320 | ||
ccc6cda3 JA |
5321 | \1f |
5322 | File: bashref.info, Node: Job Control, Next: Using History Interactively, Prev: Bash Features, Up: Top | |
5323 | ||
761783bf CR |
5324 | 7 Job Control |
5325 | ************* | |
ccc6cda3 | 5326 | |
761783bf CR |
5327 | This chapter discusses what job control is, how it works, and how Bash |
5328 | allows you to access its facilities. | |
ccc6cda3 JA |
5329 | |
5330 | * Menu: | |
5331 | ||
5332 | * Job Control Basics:: How job control works. | |
5333 | * Job Control Builtins:: Bash builtin commands used to interact | |
5334 | with job control. | |
5335 | * Job Control Variables:: Variables Bash uses to customize job | |
5336 | control. | |
5337 | ||
5338 | \1f | |
5339 | File: bashref.info, Node: Job Control Basics, Next: Job Control Builtins, Up: Job Control | |
5340 | ||
761783bf CR |
5341 | 7.1 Job Control Basics |
5342 | ====================== | |
ccc6cda3 | 5343 | |
761783bf | 5344 | Job control refers to the ability to selectively stop (suspend) the |
ccc6cda3 JA |
5345 | execution of processes and continue (resume) their execution at a later |
5346 | point. A user typically employs this facility via an interactive | |
5347 | interface supplied jointly by the system's terminal driver and Bash. | |
5348 | ||
5349 | The shell associates a JOB with each pipeline. It keeps a table of | |
5350 | currently executing jobs, which may be listed with the `jobs' command. | |
cce855bc | 5351 | When Bash starts a job asynchronously, it prints a line that looks like: |
ccc6cda3 | 5352 | [1] 25647 |
761783bf CR |
5353 | indicating that this job is job number 1 and that the process ID of |
5354 | the last process in the pipeline associated with this job is 25647. | |
5355 | All of the processes in a single pipeline are members of the same job. | |
5356 | Bash uses the JOB abstraction as the basis for job control. | |
ccc6cda3 JA |
5357 | |
5358 | To facilitate the implementation of the user interface to job | |
bb70624e JA |
5359 | control, the operating system maintains the notion of a current terminal |
5360 | process group ID. Members of this process group (processes whose | |
5361 | process group ID is equal to the current terminal process group ID) | |
5362 | receive keyboard-generated signals such as `SIGINT'. These processes | |
5363 | are said to be in the foreground. Background processes are those whose | |
5364 | process group ID differs from the terminal's; such processes are immune | |
5365 | to keyboard-generated signals. Only foreground processes are allowed | |
5366 | to read from or write to the terminal. Background processes which | |
5367 | attempt to read from (write to) the terminal are sent a `SIGTTIN' | |
5368 | (`SIGTTOU') signal by the terminal driver, which, unless caught, | |
5369 | suspends the process. | |
ccc6cda3 JA |
5370 | |
5371 | If the operating system on which Bash is running supports job | |
cce855bc JA |
5372 | control, Bash contains facilities to use it. Typing the SUSPEND |
5373 | character (typically `^Z', Control-Z) while a process is running causes | |
5374 | that process to be stopped and returns control to Bash. Typing the | |
5375 | DELAYED SUSPEND character (typically `^Y', Control-Y) causes the | |
5376 | process to be stopped when it attempts to read input from the terminal, | |
5377 | and control to be returned to Bash. The user then manipulates the | |
5378 | state of this job, using the `bg' command to continue it in the | |
5379 | background, the `fg' command to continue it in the foreground, or the | |
5380 | `kill' command to kill it. A `^Z' takes effect immediately, and has | |
5381 | the additional side effect of causing pending output and typeahead to | |
5382 | be discarded. | |
ccc6cda3 JA |
5383 | |
5384 | There are a number of ways to refer to a job in the shell. The | |
bb70624e JA |
5385 | character `%' introduces a job name. |
5386 | ||
5387 | Job number `n' may be referred to as `%n'. The symbols `%%' and | |
5388 | `%+' refer to the shell's notion of the current job, which is the last | |
5389 | job stopped while it was in the foreground or started in the | |
5390 | background. The previous job may be referenced using `%-'. In output | |
5391 | pertaining to jobs (e.g., the output of the `jobs' command), the | |
5392 | current job is always flagged with a `+', and the previous job with a | |
5393 | `-'. | |
5394 | ||
5395 | A job may also be referred to using a prefix of the name used to | |
5396 | start it, or using a substring that appears in its command line. For | |
5397 | example, `%ce' refers to a stopped `ce' job. Using `%?ce', on the other | |
5398 | hand, refers to any job containing the string `ce' in its command line. | |
5399 | If the prefix or substring matches more than one job, Bash reports an | |
5400 | error. | |
ccc6cda3 JA |
5401 | |
5402 | Simply naming a job can be used to bring it into the foreground: | |
5403 | `%1' is a synonym for `fg %1', bringing job 1 from the background into | |
5404 | the foreground. Similarly, `%1 &' resumes job 1 in the background, | |
5405 | equivalent to `bg %1' | |
5406 | ||
5407 | The shell learns immediately whenever a job changes state. | |
5408 | Normally, Bash waits until it is about to print a prompt before | |
5409 | reporting changes in a job's status so as to not interrupt any other | |
f73dda09 JA |
5410 | output. If the `-b' option to the `set' builtin is enabled, Bash |
5411 | reports such changes immediately (*note The Set Builtin::). Any trap | |
5412 | on `SIGCHLD' is executed for each child process that exits. | |
ccc6cda3 | 5413 | |
de8913bd | 5414 | If an attempt to exit Bash is made while jobs are stopped, the shell |
cce855bc JA |
5415 | prints a message warning that there are stopped jobs. The `jobs' |
5416 | command may then be used to inspect their status. If a second attempt | |
5417 | to exit is made without an intervening command, Bash does not print | |
5418 | another warning, and the stopped jobs are terminated. | |
ccc6cda3 JA |
5419 | |
5420 | \1f | |
5421 | File: bashref.info, Node: Job Control Builtins, Next: Job Control Variables, Prev: Job Control Basics, Up: Job Control | |
5422 | ||
761783bf CR |
5423 | 7.2 Job Control Builtins |
5424 | ======================== | |
ccc6cda3 JA |
5425 | |
5426 | `bg' | |
5427 | bg [JOBSPEC] | |
cce855bc JA |
5428 | Resume the suspended job JOBSPEC in the background, as if it had |
5429 | been started with `&'. If JOBSPEC is not supplied, the current | |
5430 | job is used. The return status is zero unless it is run when job | |
5431 | control is not enabled, or, when run with job control enabled, if | |
5432 | JOBSPEC was not found or JOBSPEC specifies a job that was started | |
5433 | without job control. | |
ccc6cda3 JA |
5434 | |
5435 | `fg' | |
5436 | fg [JOBSPEC] | |
cce855bc JA |
5437 | Resume the job JOBSPEC in the foreground and make it the current |
5438 | job. If JOBSPEC is not supplied, the current job is used. The | |
5439 | return status is that of the command placed into the foreground, | |
5440 | or non-zero if run when job control is disabled or, when run with | |
5441 | job control enabled, JOBSPEC does not specify a valid job or | |
5442 | JOBSPEC specifies a job that was started without job control. | |
ccc6cda3 JA |
5443 | |
5444 | `jobs' | |
bb70624e | 5445 | jobs [-lnprs] [JOBSPEC] |
cce855bc | 5446 | jobs -x COMMAND [ARGUMENTS] |
ccc6cda3 JA |
5447 | |
5448 | The first form lists the active jobs. The options have the | |
5449 | following meanings: | |
5450 | ||
5451 | `-l' | |
cce855bc | 5452 | List process IDs in addition to the normal information. |
ccc6cda3 JA |
5453 | |
5454 | `-n' | |
5455 | Display information only about jobs that have changed status | |
cce855bc | 5456 | since the user was last notified of their status. |
ccc6cda3 JA |
5457 | |
5458 | `-p' | |
5459 | List only the process ID of the job's process group leader. | |
5460 | ||
5461 | `-r' | |
5462 | Restrict output to running jobs. | |
5463 | ||
5464 | `-s' | |
5465 | Restrict output to stopped jobs. | |
5466 | ||
5467 | If JOBSPEC is given, output is restricted to information about | |
5468 | that job. If JOBSPEC is not supplied, the status of all jobs is | |
5469 | listed. | |
5470 | ||
5471 | If the `-x' option is supplied, `jobs' replaces any JOBSPEC found | |
5472 | in COMMAND or ARGUMENTS with the corresponding process group ID, | |
5473 | and executes COMMAND, passing it ARGUMENTs, returning its exit | |
5474 | status. | |
5475 | ||
5476 | `kill' | |
cce855bc JA |
5477 | kill [-s SIGSPEC] [-n SIGNUM] [-SIGSPEC] JOBSPEC or PID |
5478 | kill -l [EXIT_STATUS] | |
ccc6cda3 | 5479 | Send a signal specified by SIGSPEC or SIGNUM to the process named |
cce855bc | 5480 | by job specification JOBSPEC or process ID PID. SIGSPEC is either |
9f422431 CR |
5481 | a case-insensitive signal name such as `SIGINT' (with or without |
5482 | the `SIG' prefix) or a signal number; SIGNUM is a signal number. | |
5483 | If SIGSPEC and SIGNUM are not present, `SIGTERM' is used. The | |
5484 | `-l' option lists the signal names. If any arguments are supplied | |
5485 | when `-l' is given, the names of the signals corresponding to the | |
5486 | arguments are listed, and the return status is zero. EXIT_STATUS | |
5487 | is a number specifying a signal number or the exit status of a | |
5488 | process terminated by a signal. The return status is zero if at | |
5489 | least one signal was successfully sent, or non-zero if an error | |
5490 | occurs or an invalid option is encountered. | |
ccc6cda3 JA |
5491 | |
5492 | `wait' | |
bb70624e | 5493 | wait [JOBSPEC or PID] |
ccc6cda3 | 5494 | Wait until the child process specified by process ID PID or job |
cce855bc JA |
5495 | specification JOBSPEC exits and return the exit status of the last |
5496 | command waited for. If a job spec is given, all processes in the | |
5497 | job are waited for. If no arguments are given, all currently | |
5498 | active child processes are waited for, and the return status is | |
5499 | zero. If neither JOBSPEC nor PID specifies an active child process | |
5500 | of the shell, the return status is 127. | |
ccc6cda3 JA |
5501 | |
5502 | `disown' | |
cce855bc | 5503 | disown [-ar] [-h] [JOBSPEC ...] |
ccc6cda3 JA |
5504 | Without options, each JOBSPEC is removed from the table of active |
5505 | jobs. If the `-h' option is given, the job is not removed from | |
5506 | the table, but is marked so that `SIGHUP' is not sent to the job | |
cce855bc JA |
5507 | if the shell receives a `SIGHUP'. If JOBSPEC is not present, and |
5508 | neither the `-a' nor `-r' option is supplied, the current job is | |
5509 | used. If no JOBSPEC is supplied, the `-a' option means to remove | |
5510 | or mark all jobs; the `-r' option without a JOBSPEC argument | |
5511 | restricts operation to running jobs. | |
ccc6cda3 JA |
5512 | |
5513 | `suspend' | |
5514 | suspend [-f] | |
5515 | Suspend the execution of this shell until it receives a `SIGCONT' | |
5516 | signal. The `-f' option means to suspend even if the shell is a | |
5517 | login shell. | |
5518 | ||
761783bf | 5519 | |
ccc6cda3 JA |
5520 | When job control is not active, the `kill' and `wait' builtins do |
5521 | not accept JOBSPEC arguments. They must be supplied process IDs. | |
5522 | ||
5523 | \1f | |
5524 | File: bashref.info, Node: Job Control Variables, Prev: Job Control Builtins, Up: Job Control | |
5525 | ||
761783bf CR |
5526 | 7.3 Job Control Variables |
5527 | ========================= | |
ccc6cda3 JA |
5528 | |
5529 | `auto_resume' | |
5530 | This variable controls how the shell interacts with the user and | |
5531 | job control. If this variable exists then single word simple | |
cce855bc JA |
5532 | commands without redirections are treated as candidates for |
5533 | resumption of an existing job. There is no ambiguity allowed; if | |
5534 | there is more than one job beginning with the string typed, then | |
5535 | the most recently accessed job will be selected. The name of a | |
5536 | stopped job, in this context, is the command line used to start | |
5537 | it. If this variable is set to the value `exact', the string | |
5538 | supplied must match the name of a stopped job exactly; if set to | |
ccc6cda3 JA |
5539 | `substring', the string supplied needs to match a substring of the |
5540 | name of a stopped job. The `substring' value provides | |
5541 | functionality analogous to the `%?' job ID (*note Job Control | |
28ef6c31 JA |
5542 | Basics::). If set to any other value, the supplied string must be |
5543 | a prefix of a stopped job's name; this provides functionality | |
ccc6cda3 JA |
5544 | analogous to the `%' job ID. |
5545 | ||
761783bf | 5546 | |
ccc6cda3 | 5547 | \1f |
bb70624e | 5548 | File: bashref.info, Node: Command Line Editing, Next: Installing Bash, Prev: Using History Interactively, Up: Top |
ccc6cda3 | 5549 | |
761783bf CR |
5550 | 8 Command Line Editing |
5551 | ********************** | |
ccc6cda3 | 5552 | |
761783bf | 5553 | This chapter describes the basic features of the GNU command line |
bb70624e JA |
5554 | editing interface. Command line editing is provided by the Readline |
5555 | library, which is used by several different programs, including Bash. | |
ccc6cda3 JA |
5556 | |
5557 | * Menu: | |
5558 | ||
bb70624e JA |
5559 | * Introduction and Notation:: Notation used in this text. |
5560 | * Readline Interaction:: The minimum set of commands for editing a line. | |
5561 | * Readline Init File:: Customizing Readline from a user's view. | |
5562 | * Bindable Readline Commands:: A description of most of the Readline commands | |
5563 | available for binding | |
5564 | * Readline vi Mode:: A short description of how to make Readline | |
5565 | behave like the vi editor. | |
5566 | ||
5567 | * Programmable Completion:: How to specify the possible completions for | |
5568 | a specific command. | |
5569 | * Programmable Completion Builtins:: Builtin commands to specify how to | |
5570 | complete arguments for a particular command. | |
ccc6cda3 JA |
5571 | |
5572 | \1f | |
bb70624e | 5573 | File: bashref.info, Node: Introduction and Notation, Next: Readline Interaction, Up: Command Line Editing |
ccc6cda3 | 5574 | |
761783bf CR |
5575 | 8.1 Introduction to Line Editing |
5576 | ================================ | |
ccc6cda3 | 5577 | |
761783bf | 5578 | The following paragraphs describe the notation used to represent |
bb70624e | 5579 | keystrokes. |
ccc6cda3 | 5580 | |
28ef6c31 | 5581 | The text `C-k' is read as `Control-K' and describes the character |
bb70624e | 5582 | produced when the <k> key is pressed while the Control key is depressed. |
ccc6cda3 | 5583 | |
28ef6c31 | 5584 | The text `M-k' is read as `Meta-K' and describes the character |
bb70624e JA |
5585 | produced when the Meta key (if you have one) is depressed, and the <k> |
5586 | key is pressed. The Meta key is labeled <ALT> on many keyboards. On | |
5587 | keyboards with two keys labeled <ALT> (usually to either side of the | |
5588 | space bar), the <ALT> on the left side is generally set to work as a | |
5589 | Meta key. The <ALT> key on the right may also be configured to work as | |
5590 | a Meta key or may be configured as some other modifier, such as a | |
5591 | Compose key for typing accented characters. | |
5592 | ||
5593 | If you do not have a Meta or <ALT> key, or another key working as a | |
5594 | Meta key, the identical keystroke can be generated by typing <ESC> | |
28ef6c31 JA |
5595 | _first_, and then typing <k>. Either process is known as "metafying" |
5596 | the <k> key. | |
bb70624e | 5597 | |
28ef6c31 JA |
5598 | The text `M-C-k' is read as `Meta-Control-k' and describes the |
5599 | character produced by "metafying" `C-k'. | |
bb70624e JA |
5600 | |
5601 | In addition, several keys have their own names. Specifically, | |
5602 | <DEL>, <ESC>, <LFD>, <SPC>, <RET>, and <TAB> all stand for themselves | |
28ef6c31 JA |
5603 | when seen in this text, or in an init file (*note Readline Init File::). |
5604 | If your keyboard lacks a <LFD> key, typing <C-j> will produce the | |
5605 | desired character. The <RET> key may be labeled <Return> or <Enter> on | |
5606 | some keyboards. | |
ccc6cda3 JA |
5607 | |
5608 | \1f | |
bb70624e | 5609 | File: bashref.info, Node: Readline Interaction, Next: Readline Init File, Prev: Introduction and Notation, Up: Command Line Editing |
cce855bc | 5610 | |
761783bf CR |
5611 | 8.2 Readline Interaction |
5612 | ======================== | |
cce855bc | 5613 | |
761783bf | 5614 | Often during an interactive session you type in a long line of text, |
bb70624e JA |
5615 | only to notice that the first word on the line is misspelled. The |
5616 | Readline library gives you a set of commands for manipulating the text | |
5617 | as you type it in, allowing you to just fix your typo, and not forcing | |
5618 | you to retype the majority of the line. Using these editing commands, | |
5619 | you move the cursor to the place that needs correction, and delete or | |
5620 | insert the text of the corrections. Then, when you are satisfied with | |
28ef6c31 JA |
5621 | the line, you simply press <RET>. You do not have to be at the end of |
5622 | the line to press <RET>; the entire line is accepted regardless of the | |
5623 | location of the cursor within the line. | |
cce855bc | 5624 | |
bb70624e | 5625 | * Menu: |
cce855bc | 5626 | |
bb70624e JA |
5627 | * Readline Bare Essentials:: The least you need to know about Readline. |
5628 | * Readline Movement Commands:: Moving about the input line. | |
5629 | * Readline Killing Commands:: How to delete text, and how to get it back! | |
5630 | * Readline Arguments:: Giving numeric arguments to commands. | |
5631 | * Searching:: Searching through previous lines. | |
cce855bc | 5632 | |
bb70624e JA |
5633 | \1f |
5634 | File: bashref.info, Node: Readline Bare Essentials, Next: Readline Movement Commands, Up: Readline Interaction | |
cce855bc | 5635 | |
761783bf CR |
5636 | 8.2.1 Readline Bare Essentials |
5637 | ------------------------------ | |
cce855bc | 5638 | |
761783bf CR |
5639 | In order to enter characters into the line, simply type them. The typed |
5640 | character appears where the cursor was, and then the cursor moves one | |
5641 | space to the right. If you mistype a character, you can use your erase | |
5642 | character to back up and delete the mistyped character. | |
cce855bc | 5643 | |
bb70624e JA |
5644 | Sometimes you may mistype a character, and not notice the error |
5645 | until you have typed several other characters. In that case, you can | |
28ef6c31 JA |
5646 | type `C-b' to move the cursor to the left, and then correct your |
5647 | mistake. Afterwards, you can move the cursor to the right with `C-f'. | |
cce855bc | 5648 | |
bb70624e JA |
5649 | When you add text in the middle of a line, you will notice that |
5650 | characters to the right of the cursor are `pushed over' to make room | |
5651 | for the text that you have inserted. Likewise, when you delete text | |
5652 | behind the cursor, characters to the right of the cursor are `pulled | |
5653 | back' to fill in the blank space created by the removal of the text. A | |
5654 | list of the bare essentials for editing the text of an input line | |
5655 | follows. | |
cce855bc | 5656 | |
28ef6c31 | 5657 | `C-b' |
bb70624e | 5658 | Move back one character. |
cce855bc | 5659 | |
28ef6c31 | 5660 | `C-f' |
bb70624e | 5661 | Move forward one character. |
cce855bc | 5662 | |
bb70624e JA |
5663 | <DEL> or <Backspace> |
5664 | Delete the character to the left of the cursor. | |
cce855bc | 5665 | |
28ef6c31 | 5666 | `C-d' |
bb70624e | 5667 | Delete the character underneath the cursor. |
cce855bc | 5668 | |
bb70624e JA |
5669 | Printing characters |
5670 | Insert the character into the line at the cursor. | |
cce855bc | 5671 | |
28ef6c31 | 5672 | `C-_' or `C-x C-u' |
bb70624e JA |
5673 | Undo the last editing command. You can undo all the way back to an |
5674 | empty line. | |
cce855bc | 5675 | |
bb70624e JA |
5676 | (Depending on your configuration, the <Backspace> key be set to delete |
5677 | the character to the left of the cursor and the <DEL> key set to delete | |
28ef6c31 | 5678 | the character underneath the cursor, like `C-d', rather than the |
bb70624e | 5679 | character to the left of the cursor.) |
cce855bc JA |
5680 | |
5681 | \1f | |
bb70624e | 5682 | File: bashref.info, Node: Readline Movement Commands, Next: Readline Killing Commands, Prev: Readline Bare Essentials, Up: Readline Interaction |
ccc6cda3 | 5683 | |
761783bf CR |
5684 | 8.2.2 Readline Movement Commands |
5685 | -------------------------------- | |
ccc6cda3 | 5686 | |
761783bf | 5687 | The above table describes the most basic keystrokes that you need in |
bb70624e | 5688 | order to do editing of the input line. For your convenience, many |
28ef6c31 | 5689 | other commands have been added in addition to `C-b', `C-f', `C-d', and |
bb70624e | 5690 | <DEL>. Here are some commands for moving more rapidly about the line. |
ccc6cda3 | 5691 | |
28ef6c31 | 5692 | `C-a' |
bb70624e | 5693 | Move to the start of the line. |
ccc6cda3 | 5694 | |
28ef6c31 | 5695 | `C-e' |
bb70624e | 5696 | Move to the end of the line. |
ccc6cda3 | 5697 | |
28ef6c31 | 5698 | `M-f' |
bb70624e JA |
5699 | Move forward a word, where a word is composed of letters and |
5700 | digits. | |
ccc6cda3 | 5701 | |
28ef6c31 | 5702 | `M-b' |
bb70624e | 5703 | Move backward a word. |
ccc6cda3 | 5704 | |
28ef6c31 | 5705 | `C-l' |
bb70624e | 5706 | Clear the screen, reprinting the current line at the top. |
ccc6cda3 | 5707 | |
28ef6c31 | 5708 | Notice how `C-f' moves forward a character, while `M-f' moves |
bb70624e JA |
5709 | forward a word. It is a loose convention that control keystrokes |
5710 | operate on characters while meta keystrokes operate on words. | |
ccc6cda3 JA |
5711 | |
5712 | \1f | |
bb70624e | 5713 | File: bashref.info, Node: Readline Killing Commands, Next: Readline Arguments, Prev: Readline Movement Commands, Up: Readline Interaction |
ccc6cda3 | 5714 | |
761783bf CR |
5715 | 8.2.3 Readline Killing Commands |
5716 | ------------------------------- | |
ccc6cda3 | 5717 | |
761783bf CR |
5718 | "Killing" text means to delete the text from the line, but to save it |
5719 | away for later use, usually by "yanking" (re-inserting) it back into | |
bb70624e JA |
5720 | the line. (`Cut' and `paste' are more recent jargon for `kill' and |
5721 | `yank'.) | |
ccc6cda3 | 5722 | |
bb70624e JA |
5723 | If the description for a command says that it `kills' text, then you |
5724 | can be sure that you can get the text back in a different (or the same) | |
5725 | place later. | |
ccc6cda3 | 5726 | |
bb70624e JA |
5727 | When you use a kill command, the text is saved in a "kill-ring". |
5728 | Any number of consecutive kills save all of the killed text together, so | |
5729 | that when you yank it back, you get it all. The kill ring is not line | |
5730 | specific; the text that you killed on a previously typed line is | |
761783bf | 5731 | available to be yanked back later, when you are typing another line. |
ccc6cda3 | 5732 | |
bb70624e | 5733 | Here is the list of commands for killing text. |
ccc6cda3 | 5734 | |
28ef6c31 | 5735 | `C-k' |
bb70624e JA |
5736 | Kill the text from the current cursor position to the end of the |
5737 | line. | |
ccc6cda3 | 5738 | |
28ef6c31 | 5739 | `M-d' |
bb70624e JA |
5740 | Kill from the cursor to the end of the current word, or, if between |
5741 | words, to the end of the next word. Word boundaries are the same | |
28ef6c31 | 5742 | as those used by `M-f'. |
ccc6cda3 | 5743 | |
28ef6c31 | 5744 | `M-<DEL>' |
f73dda09 | 5745 | Kill from the cursor the start of the current word, or, if between |
bb70624e | 5746 | words, to the start of the previous word. Word boundaries are the |
28ef6c31 | 5747 | same as those used by `M-b'. |
ccc6cda3 | 5748 | |
28ef6c31 | 5749 | `C-w' |
ccc6cda3 | 5750 | Kill from the cursor to the previous whitespace. This is |
28ef6c31 | 5751 | different than `M-<DEL>' because the word boundaries differ. |
ccc6cda3 | 5752 | |
761783bf | 5753 | |
cce855bc JA |
5754 | Here is how to "yank" the text back into the line. Yanking means to |
5755 | copy the most-recently-killed text from the kill buffer. | |
ccc6cda3 | 5756 | |
28ef6c31 | 5757 | `C-y' |
ccc6cda3 JA |
5758 | Yank the most recently killed text back into the buffer at the |
5759 | cursor. | |
5760 | ||
28ef6c31 | 5761 | `M-y' |
ccc6cda3 | 5762 | Rotate the kill-ring, and yank the new top. You can only do this |
28ef6c31 | 5763 | if the prior command is `C-y' or `M-y'. |
ccc6cda3 JA |
5764 | |
5765 | \1f | |
5766 | File: bashref.info, Node: Readline Arguments, Next: Searching, Prev: Readline Killing Commands, Up: Readline Interaction | |
5767 | ||
761783bf CR |
5768 | 8.2.4 Readline Arguments |
5769 | ------------------------ | |
ccc6cda3 | 5770 | |
761783bf | 5771 | You can pass numeric arguments to Readline commands. Sometimes the |
ccc6cda3 JA |
5772 | argument acts as a repeat count, other times it is the sign of the |
5773 | argument that is significant. If you pass a negative argument to a | |
5774 | command which normally acts in a forward direction, that command will | |
5775 | act in a backward direction. For example, to kill text back to the | |
5776 | start of the line, you might type `M-- C-k'. | |
5777 | ||
5778 | The general way to pass numeric arguments to a command is to type | |
cce855bc | 5779 | meta digits before the command. If the first `digit' typed is a minus |
bb70624e | 5780 | sign (`-'), then the sign of the argument will be negative. Once you |
cce855bc JA |
5781 | have typed one meta digit to get the argument started, you can type the |
5782 | remainder of the digits, and then the command. For example, to give | |
28ef6c31 JA |
5783 | the `C-d' command an argument of 10, you could type `M-1 0 C-d', which |
5784 | will delete the next ten characters on the input line. | |
ccc6cda3 JA |
5785 | |
5786 | \1f | |
5787 | File: bashref.info, Node: Searching, Prev: Readline Arguments, Up: Readline Interaction | |
5788 | ||
761783bf CR |
5789 | 8.2.5 Searching for Commands in the History |
5790 | ------------------------------------------- | |
ccc6cda3 | 5791 | |
761783bf | 5792 | Readline provides commands for searching through the command history |
28ef6c31 JA |
5793 | (*note Bash History Facilities::) for lines containing a specified |
5794 | string. There are two search modes: "incremental" and | |
5795 | "non-incremental". | |
ccc6cda3 JA |
5796 | |
5797 | Incremental searches begin before the user has finished typing the | |
5798 | search string. As each character of the search string is typed, | |
cce855bc | 5799 | Readline displays the next entry from the history matching the string |
ccc6cda3 | 5800 | typed so far. An incremental search requires only as many characters |
bb70624e | 5801 | as needed to find the desired history entry. To search backward in the |
28ef6c31 | 5802 | history for a particular string, type `C-r'. Typing `C-s' searches |
bb70624e JA |
5803 | forward through the history. The characters present in the value of |
5804 | the `isearch-terminators' variable are used to terminate an incremental | |
5805 | search. If that variable has not been assigned a value, the <ESC> and | |
28ef6c31 | 5806 | `C-J' characters will terminate an incremental search. `C-g' will |
bb70624e JA |
5807 | abort an incremental search and restore the original line. When the |
5808 | search is terminated, the history entry containing the search string | |
5809 | becomes the current line. | |
5810 | ||
28ef6c31 JA |
5811 | To find other matching entries in the history list, type `C-r' or |
5812 | `C-s' as appropriate. This will search backward or forward in the | |
bb70624e JA |
5813 | history for the next entry matching the search string typed so far. |
5814 | Any other key sequence bound to a Readline command will terminate the | |
5815 | search and execute that command. For instance, a <RET> will terminate | |
5816 | the search and accept the line, thereby executing the command from the | |
28ef6c31 JA |
5817 | history list. A movement command will terminate the search, make the |
5818 | last line found the current line, and begin editing. | |
ccc6cda3 | 5819 | |
f73dda09 JA |
5820 | Readline remembers the last incremental search string. If two |
5821 | `C-r's are typed without any intervening characters defining a new | |
5822 | search string, any remembered search string is used. | |
5823 | ||
ccc6cda3 JA |
5824 | Non-incremental searches read the entire search string before |
5825 | starting to search for matching history lines. The search string may be | |
cce855bc | 5826 | typed by the user or be part of the contents of the current line. |
ccc6cda3 JA |
5827 | |
5828 | \1f | |
5829 | File: bashref.info, Node: Readline Init File, Next: Bindable Readline Commands, Prev: Readline Interaction, Up: Command Line Editing | |
5830 | ||
761783bf CR |
5831 | 8.3 Readline Init File |
5832 | ====================== | |
ccc6cda3 | 5833 | |
761783bf | 5834 | Although the Readline library comes with a set of Emacs-like |
cce855bc JA |
5835 | keybindings installed by default, it is possible to use a different set |
5836 | of keybindings. Any user can customize programs that use Readline by | |
bb70624e JA |
5837 | putting commands in an "inputrc" file, conventionally in his home |
5838 | directory. The name of this file is taken from the value of the shell | |
5839 | variable `INPUTRC'. If that variable is unset, the default is | |
5840 | `~/.inputrc'. | |
ccc6cda3 JA |
5841 | |
5842 | When a program which uses the Readline library starts up, the init | |
5843 | file is read, and the key bindings are set. | |
5844 | ||
5845 | In addition, the `C-x C-r' command re-reads this init file, thus | |
5846 | incorporating any changes that you might have made to it. | |
5847 | ||
5848 | * Menu: | |
5849 | ||
5850 | * Readline Init File Syntax:: Syntax for the commands in the inputrc file. | |
5851 | ||
5852 | * Conditional Init Constructs:: Conditional key bindings in the inputrc file. | |
5853 | ||
5854 | * Sample Init File:: An example inputrc file. | |
5855 | ||
5856 | \1f | |
5857 | File: bashref.info, Node: Readline Init File Syntax, Next: Conditional Init Constructs, Up: Readline Init File | |
5858 | ||
761783bf CR |
5859 | 8.3.1 Readline Init File Syntax |
5860 | ------------------------------- | |
ccc6cda3 | 5861 | |
761783bf | 5862 | There are only a few basic constructs allowed in the Readline init |
ccc6cda3 JA |
5863 | file. Blank lines are ignored. Lines beginning with a `#' are |
5864 | comments. Lines beginning with a `$' indicate conditional constructs | |
28ef6c31 | 5865 | (*note Conditional Init Constructs::). Other lines denote variable |
ccc6cda3 JA |
5866 | settings and key bindings. |
5867 | ||
5868 | Variable Settings | |
cce855bc JA |
5869 | You can modify the run-time behavior of Readline by altering the |
5870 | values of variables in Readline using the `set' command within the | |
28ef6c31 JA |
5871 | init file. The syntax is simple: |
5872 | ||
5873 | set VARIABLE VALUE | |
5874 | ||
5875 | Here, for example, is how to change from the default Emacs-like | |
5876 | key binding to use `vi' line editing commands: | |
ccc6cda3 JA |
5877 | |
5878 | set editing-mode vi | |
5879 | ||
28ef6c31 JA |
5880 | Variable names and values, where appropriate, are recognized |
5881 | without regard to case. | |
5882 | ||
bb70624e JA |
5883 | The `bind -V' command lists the current Readline variable names |
5884 | and values. *Note Bash Builtins::. | |
5885 | ||
cce855bc JA |
5886 | A great deal of run-time behavior is changeable with the following |
5887 | variables. | |
ccc6cda3 JA |
5888 | |
5889 | `bell-style' | |
5890 | Controls what happens when Readline wants to ring the | |
5891 | terminal bell. If set to `none', Readline never rings the | |
5892 | bell. If set to `visible', Readline uses a visible bell if | |
5893 | one is available. If set to `audible' (the default), | |
5894 | Readline attempts to ring the terminal's bell. | |
5895 | ||
5896 | `comment-begin' | |
5897 | The string to insert at the beginning of the line when the | |
5898 | `insert-comment' command is executed. The default value is | |
5899 | `"#"'. | |
5900 | ||
cce855bc JA |
5901 | `completion-ignore-case' |
5902 | If set to `on', Readline performs filename matching and | |
5903 | completion in a case-insensitive fashion. The default value | |
5904 | is `off'. | |
5905 | ||
ccc6cda3 JA |
5906 | `completion-query-items' |
5907 | The number of possible completions that determines when the | |
d3a24ed2 CR |
5908 | user is asked whether the list of possibilities should be |
5909 | displayed. If the number of possible completions is greater | |
5910 | than this value, Readline will ask the user whether or not he | |
5911 | wishes to view them; otherwise, they are simply listed. This | |
5912 | variable must be set to an integer value greater than or | |
5913 | equal to 0. The default limit is `100'. | |
ccc6cda3 JA |
5914 | |
5915 | `convert-meta' | |
5916 | If set to `on', Readline will convert characters with the | |
cce855bc | 5917 | eighth bit set to an ASCII key sequence by stripping the |
bb70624e | 5918 | eighth bit and prefixing an <ESC> character, converting them |
cce855bc | 5919 | to a meta-prefixed key sequence. The default value is `on'. |
ccc6cda3 JA |
5920 | |
5921 | `disable-completion' | |
cce855bc | 5922 | If set to `On', Readline will inhibit word completion. |
ccc6cda3 JA |
5923 | Completion characters will be inserted into the line as if |
5924 | they had been mapped to `self-insert'. The default is `off'. | |
5925 | ||
5926 | `editing-mode' | |
cce855bc JA |
5927 | The `editing-mode' variable controls which default set of key |
5928 | bindings is used. By default, Readline starts up in Emacs | |
5929 | editing mode, where the keystrokes are most similar to Emacs. | |
5930 | This variable can be set to either `emacs' or `vi'. | |
ccc6cda3 JA |
5931 | |
5932 | `enable-keypad' | |
cce855bc | 5933 | When set to `on', Readline will try to enable the application |
ccc6cda3 JA |
5934 | keypad when it is called. Some systems need this to enable |
5935 | the arrow keys. The default is `off'. | |
5936 | ||
5937 | `expand-tilde' | |
5938 | If set to `on', tilde expansion is performed when Readline | |
5939 | attempts word completion. The default is `off'. | |
5940 | ||
f73dda09 | 5941 | If set to `on', the history code attempts to place point at |
d3a24ed2 | 5942 | the same location on each history line retrieved with |
f73dda09 JA |
5943 | `previous-history' or `next-history'. |
5944 | ||
ccc6cda3 JA |
5945 | `horizontal-scroll-mode' |
5946 | This variable can be set to either `on' or `off'. Setting it | |
cce855bc | 5947 | to `on' means that the text of the lines being edited will |
ccc6cda3 JA |
5948 | scroll horizontally on a single screen line when they are |
5949 | longer than the width of the screen, instead of wrapping onto | |
5950 | a new screen line. By default, this variable is set to `off'. | |
5951 | ||
b72432fd JA |
5952 | `input-meta' |
5953 | If set to `on', Readline will enable eight-bit input (it will | |
28ef6c31 | 5954 | not clear the eighth bit in the characters it reads), |
b72432fd JA |
5955 | regardless of what the terminal claims it can support. The |
5956 | default value is `off'. The name `meta-flag' is a synonym | |
5957 | for this variable. | |
5958 | ||
5959 | `isearch-terminators' | |
5960 | The string of characters that should terminate an incremental | |
5961 | search without subsequently executing the character as a | |
28ef6c31 JA |
5962 | command (*note Searching::). If this variable has not been |
5963 | given a value, the characters <ESC> and `C-J' will terminate | |
b72432fd JA |
5964 | an incremental search. |
5965 | ||
ccc6cda3 JA |
5966 | `keymap' |
5967 | Sets Readline's idea of the current keymap for key binding | |
5968 | commands. Acceptable `keymap' names are `emacs', | |
28ef6c31 | 5969 | `emacs-standard', `emacs-meta', `emacs-ctlx', `vi', `vi-move', |
ccc6cda3 JA |
5970 | `vi-command', and `vi-insert'. `vi' is equivalent to |
5971 | `vi-command'; `emacs' is equivalent to `emacs-standard'. The | |
5972 | default value is `emacs'. The value of the `editing-mode' | |
5973 | variable also affects the default keymap. | |
5974 | ||
5975 | `mark-directories' | |
5976 | If set to `on', completed directory names have a slash | |
5977 | appended. The default is `on'. | |
5978 | ||
5979 | `mark-modified-lines' | |
cce855bc JA |
5980 | This variable, when set to `on', causes Readline to display an |
5981 | asterisk (`*') at the start of history lines which have been | |
5982 | modified. This variable is `off' by default. | |
ccc6cda3 | 5983 | |
7117c2d2 JA |
5984 | `mark-symlinked-directories' |
5985 | If set to `on', completed names which are symbolic links to | |
5986 | directories have a slash appended (subject to the value of | |
5987 | `mark-directories'). The default is `off'. | |
5988 | ||
f73dda09 JA |
5989 | `match-hidden-files' |
5990 | This variable, when set to `on', causes Readline to match | |
5991 | files whose names begin with a `.' (hidden files) when | |
5992 | performing filename completion, unless the leading `.' is | |
5993 | supplied by the user in the filename to be completed. This | |
5994 | variable is `on' by default. | |
5995 | ||
ccc6cda3 JA |
5996 | `output-meta' |
5997 | If set to `on', Readline will display characters with the | |
5998 | eighth bit set directly rather than as a meta-prefixed escape | |
5999 | sequence. The default is `off'. | |
6000 | ||
7117c2d2 JA |
6001 | `page-completions' |
6002 | If set to `on', Readline uses an internal `more'-like pager | |
6003 | to display a screenful of possible completions at a time. | |
6004 | This variable is `on' by default. | |
6005 | ||
cce855bc JA |
6006 | `print-completions-horizontally' |
6007 | If set to `on', Readline will display completions with matches | |
6008 | sorted horizontally in alphabetical order, rather than down | |
6009 | the screen. The default is `off'. | |
6010 | ||
ccc6cda3 JA |
6011 | `show-all-if-ambiguous' |
6012 | This alters the default behavior of the completion functions. | |
6013 | If set to `on', words which have more than one possible | |
6014 | completion cause the matches to be listed immediately instead | |
6015 | of ringing the bell. The default value is `off'. | |
6016 | ||
d3a24ed2 CR |
6017 | `show-all-if-unmodified' |
6018 | This alters the default behavior of the completion functions | |
6019 | in a fashion similar to SHOW-ALL-IF-AMBIGUOUS. If set to | |
6020 | `on', words which have more than one possible completion | |
6021 | without any possible partial completion (the possible | |
6022 | completions don't share a common prefix) cause the matches to | |
6023 | be listed immediately instead of ringing the bell. The | |
6024 | default value is `off'. | |
6025 | ||
ccc6cda3 JA |
6026 | `visible-stats' |
6027 | If set to `on', a character denoting a file's type is | |
6028 | appended to the filename when listing possible completions. | |
6029 | The default is `off'. | |
6030 | ||
761783bf | 6031 | |
ccc6cda3 JA |
6032 | Key Bindings |
6033 | The syntax for controlling key bindings in the init file is | |
bb70624e | 6034 | simple. First you need to find the name of the command that you |
cce855bc JA |
6035 | want to change. The following sections contain tables of the |
6036 | command name, the default keybinding, if any, and a short | |
6037 | description of what the command does. | |
ccc6cda3 | 6038 | |
28ef6c31 JA |
6039 | Once you know the name of the command, simply place on a line in |
6040 | the init file the name of the key you wish to bind the command to, | |
6041 | a colon, and then the name of the command. The name of the key | |
6042 | can be expressed in different ways, depending on what you find most | |
6043 | comfortable. | |
6044 | ||
6045 | In addition to command names, readline allows keys to be bound to | |
6046 | a string that is inserted when the key is pressed (a MACRO). | |
ccc6cda3 | 6047 | |
bb70624e JA |
6048 | The `bind -p' command displays Readline function names and |
6049 | bindings in a format that can put directly into an initialization | |
6050 | file. *Note Bash Builtins::. | |
6051 | ||
ccc6cda3 JA |
6052 | KEYNAME: FUNCTION-NAME or MACRO |
6053 | KEYNAME is the name of a key spelled out in English. For | |
6054 | example: | |
6055 | Control-u: universal-argument | |
6056 | Meta-Rubout: backward-kill-word | |
6057 | Control-o: "> output" | |
6058 | ||
28ef6c31 JA |
6059 | In the above example, `C-u' is bound to the function |
6060 | `universal-argument', `M-DEL' is bound to the function | |
6061 | `backward-kill-word', and `C-o' is bound to run the macro | |
ccc6cda3 JA |
6062 | expressed on the right hand side (that is, to insert the text |
6063 | `> output' into the line). | |
6064 | ||
28ef6c31 JA |
6065 | A number of symbolic character names are recognized while |
6066 | processing this key binding syntax: DEL, ESC, ESCAPE, LFD, | |
6067 | NEWLINE, RET, RETURN, RUBOUT, SPACE, SPC, and TAB. | |
6068 | ||
ccc6cda3 JA |
6069 | "KEYSEQ": FUNCTION-NAME or MACRO |
6070 | KEYSEQ differs from KEYNAME above in that strings denoting an | |
6071 | entire key sequence can be specified, by placing the key | |
6072 | sequence in double quotes. Some GNU Emacs style key escapes | |
6073 | can be used, as in the following example, but the special | |
6074 | character names are not recognized. | |
6075 | ||
6076 | "\C-u": universal-argument | |
6077 | "\C-x\C-r": re-read-init-file | |
6078 | "\e[11~": "Function Key 1" | |
6079 | ||
28ef6c31 | 6080 | In the above example, `C-u' is again bound to the function |
ccc6cda3 | 6081 | `universal-argument' (just as it was in the first example), |
28ef6c31 JA |
6082 | `C-x C-r' is bound to the function `re-read-init-file', and |
6083 | `<ESC> <[> <1> <1> <~>' is bound to insert the text `Function | |
6084 | Key 1'. | |
cce855bc | 6085 | |
761783bf | 6086 | |
cce855bc JA |
6087 | The following GNU Emacs style escape sequences are available when |
6088 | specifying key sequences: | |
6089 | ||
6090 | `\C-' | |
6091 | control prefix | |
6092 | ||
6093 | `\M-' | |
6094 | meta prefix | |
6095 | ||
6096 | `\e' | |
6097 | an escape character | |
6098 | ||
6099 | `\\' | |
6100 | backslash | |
6101 | ||
6102 | `\"' | |
bb70624e | 6103 | <">, a double quotation mark |
cce855bc JA |
6104 | |
6105 | `\'' | |
bb70624e | 6106 | <'>, a single quote or apostrophe |
cce855bc JA |
6107 | |
6108 | In addition to the GNU Emacs style escape sequences, a second set | |
6109 | of backslash escapes is available: | |
ccc6cda3 | 6110 | |
cce855bc JA |
6111 | `\a' |
6112 | alert (bell) | |
6113 | ||
6114 | `\b' | |
6115 | backspace | |
6116 | ||
6117 | `\d' | |
6118 | delete | |
6119 | ||
6120 | `\f' | |
6121 | form feed | |
6122 | ||
6123 | `\n' | |
6124 | newline | |
ccc6cda3 | 6125 | |
cce855bc JA |
6126 | `\r' |
6127 | carriage return | |
ccc6cda3 | 6128 | |
cce855bc JA |
6129 | `\t' |
6130 | horizontal tab | |
ccc6cda3 | 6131 | |
cce855bc JA |
6132 | `\v' |
6133 | vertical tab | |
ccc6cda3 | 6134 | |
cce855bc | 6135 | `\NNN' |
f73dda09 | 6136 | the eight-bit character whose value is the octal value NNN |
cce855bc | 6137 | (one to three digits) |
ccc6cda3 | 6138 | |
f73dda09 JA |
6139 | `\xHH' |
6140 | the eight-bit character whose value is the hexadecimal value | |
6141 | HH (one or two hex digits) | |
6142 | ||
cce855bc JA |
6143 | When entering the text of a macro, single or double quotes must be |
6144 | used to indicate a macro definition. Unquoted text is assumed to | |
6145 | be a function name. In the macro body, the backslash escapes | |
6146 | described above are expanded. Backslash will quote any other | |
6147 | character in the macro text, including `"' and `''. For example, | |
6148 | the following binding will make `C-x \' insert a single `\' into | |
6149 | the line: | |
6150 | "\C-x\\": "\\" | |
ccc6cda3 | 6151 | |
761783bf | 6152 | |
ccc6cda3 JA |
6153 | \1f |
6154 | File: bashref.info, Node: Conditional Init Constructs, Next: Sample Init File, Prev: Readline Init File Syntax, Up: Readline Init File | |
6155 | ||
761783bf CR |
6156 | 8.3.2 Conditional Init Constructs |
6157 | --------------------------------- | |
ccc6cda3 | 6158 | |
761783bf | 6159 | Readline implements a facility similar in spirit to the conditional |
ccc6cda3 JA |
6160 | compilation features of the C preprocessor which allows key bindings |
6161 | and variable settings to be performed as the result of tests. There | |
cce855bc | 6162 | are four parser directives used. |
ccc6cda3 JA |
6163 | |
6164 | `$if' | |
6165 | The `$if' construct allows bindings to be made based on the | |
6166 | editing mode, the terminal being used, or the application using | |
6167 | Readline. The text of the test extends to the end of the line; no | |
6168 | characters are required to isolate it. | |
6169 | ||
6170 | `mode' | |
6171 | The `mode=' form of the `$if' directive is used to test | |
6172 | whether Readline is in `emacs' or `vi' mode. This may be | |
6173 | used in conjunction with the `set keymap' command, for | |
6174 | instance, to set bindings in the `emacs-standard' and | |
6175 | `emacs-ctlx' keymaps only if Readline is starting out in | |
6176 | `emacs' mode. | |
6177 | ||
6178 | `term' | |
6179 | The `term=' form may be used to include terminal-specific key | |
6180 | bindings, perhaps to bind the key sequences output by the | |
6181 | terminal's function keys. The word on the right side of the | |
cce855bc JA |
6182 | `=' is tested against both the full name of the terminal and |
6183 | the portion of the terminal name before the first `-'. This | |
ccc6cda3 JA |
6184 | allows `sun' to match both `sun' and `sun-cmd', for instance. |
6185 | ||
6186 | `application' | |
6187 | The APPLICATION construct is used to include | |
6188 | application-specific settings. Each program using the | |
6189 | Readline library sets the APPLICATION NAME, and you can test | |
28ef6c31 JA |
6190 | for a particular value. This could be used to bind key |
6191 | sequences to functions useful for a specific program. For | |
6192 | instance, the following command adds a key sequence that | |
6193 | quotes the current or previous word in Bash: | |
ccc6cda3 JA |
6194 | $if Bash |
6195 | # Quote the current or previous word | |
6196 | "\C-xq": "\eb\"\ef\"" | |
6197 | $endif | |
6198 | ||
6199 | `$endif' | |
cce855bc JA |
6200 | This command, as seen in the previous example, terminates an `$if' |
6201 | command. | |
ccc6cda3 JA |
6202 | |
6203 | `$else' | |
6204 | Commands in this branch of the `$if' directive are executed if the | |
6205 | test fails. | |
6206 | ||
cce855bc JA |
6207 | `$include' |
6208 | This directive takes a single filename as an argument and reads | |
28ef6c31 JA |
6209 | commands and bindings from that file. For example, the following |
6210 | directive reads from `/etc/inputrc': | |
cce855bc JA |
6211 | $include /etc/inputrc |
6212 | ||
ccc6cda3 JA |
6213 | \1f |
6214 | File: bashref.info, Node: Sample Init File, Prev: Conditional Init Constructs, Up: Readline Init File | |
6215 | ||
761783bf CR |
6216 | 8.3.3 Sample Init File |
6217 | ---------------------- | |
ccc6cda3 | 6218 | |
761783bf CR |
6219 | Here is an example of an INPUTRC file. This illustrates key binding, |
6220 | variable assignment, and conditional syntax. | |
ccc6cda3 JA |
6221 | |
6222 | ||
6223 | # This file controls the behaviour of line input editing for | |
7117c2d2 JA |
6224 | # programs that use the GNU Readline library. Existing |
6225 | # programs include FTP, Bash, and GDB. | |
ccc6cda3 JA |
6226 | # |
6227 | # You can re-read the inputrc file with C-x C-r. | |
6228 | # Lines beginning with '#' are comments. | |
cce855bc | 6229 | # |
7117c2d2 JA |
6230 | # First, include any systemwide bindings and variable |
6231 | # assignments from /etc/Inputrc | |
cce855bc | 6232 | $include /etc/Inputrc |
761783bf | 6233 | |
ccc6cda3 JA |
6234 | # |
6235 | # Set various bindings for emacs mode. | |
761783bf | 6236 | |
ccc6cda3 | 6237 | set editing-mode emacs |
761783bf | 6238 | |
ccc6cda3 | 6239 | $if mode=emacs |
761783bf | 6240 | |
ccc6cda3 | 6241 | Meta-Control-h: backward-kill-word Text after the function name is ignored |
761783bf | 6242 | |
ccc6cda3 JA |
6243 | # |
6244 | # Arrow keys in keypad mode | |
6245 | # | |
d166f048 JA |
6246 | #"\M-OD": backward-char |
6247 | #"\M-OC": forward-char | |
6248 | #"\M-OA": previous-history | |
6249 | #"\M-OB": next-history | |
ccc6cda3 JA |
6250 | # |
6251 | # Arrow keys in ANSI mode | |
6252 | # | |
d166f048 JA |
6253 | "\M-[D": backward-char |
6254 | "\M-[C": forward-char | |
6255 | "\M-[A": previous-history | |
6256 | "\M-[B": next-history | |
ccc6cda3 JA |
6257 | # |
6258 | # Arrow keys in 8 bit keypad mode | |
6259 | # | |
d166f048 JA |
6260 | #"\M-\C-OD": backward-char |
6261 | #"\M-\C-OC": forward-char | |
6262 | #"\M-\C-OA": previous-history | |
6263 | #"\M-\C-OB": next-history | |
ccc6cda3 JA |
6264 | # |
6265 | # Arrow keys in 8 bit ANSI mode | |
6266 | # | |
d166f048 JA |
6267 | #"\M-\C-[D": backward-char |
6268 | #"\M-\C-[C": forward-char | |
6269 | #"\M-\C-[A": previous-history | |
6270 | #"\M-\C-[B": next-history | |
761783bf | 6271 | |
ccc6cda3 | 6272 | C-q: quoted-insert |
761783bf | 6273 | |
ccc6cda3 | 6274 | $endif |
761783bf | 6275 | |
ccc6cda3 JA |
6276 | # An old-style binding. This happens to be the default. |
6277 | TAB: complete | |
761783bf | 6278 | |
ccc6cda3 JA |
6279 | # Macros that are convenient for shell interaction |
6280 | $if Bash | |
6281 | # edit the path | |
6282 | "\C-xp": "PATH=${PATH}\e\C-e\C-a\ef\C-f" | |
7117c2d2 JA |
6283 | # prepare to type a quoted word -- |
6284 | # insert open and close double quotes | |
ccc6cda3 JA |
6285 | # and move to just after the open quote |
6286 | "\C-x\"": "\"\"\C-b" | |
7117c2d2 JA |
6287 | # insert a backslash (testing backslash escapes |
6288 | # in sequences and macros) | |
ccc6cda3 JA |
6289 | "\C-x\\": "\\" |
6290 | # Quote the current or previous word | |
6291 | "\C-xq": "\eb\"\ef\"" | |
6292 | # Add a binding to refresh the line, which is unbound | |
6293 | "\C-xr": redraw-current-line | |
6294 | # Edit variable on current line. | |
6295 | "\M-\C-v": "\C-a\C-k$\C-y\M-\C-e\C-a\C-y=" | |
6296 | $endif | |
761783bf | 6297 | |
ccc6cda3 JA |
6298 | # use a visible bell if one is available |
6299 | set bell-style visible | |
761783bf | 6300 | |
ccc6cda3 JA |
6301 | # don't strip characters to 7 bits when reading |
6302 | set input-meta on | |
761783bf | 6303 | |
7117c2d2 JA |
6304 | # allow iso-latin1 characters to be inserted rather |
6305 | # than converted to prefix-meta sequences | |
ccc6cda3 | 6306 | set convert-meta off |
761783bf | 6307 | |
7117c2d2 JA |
6308 | # display characters with the eighth bit set directly |
6309 | # rather than as meta-prefixed characters | |
ccc6cda3 | 6310 | set output-meta on |
761783bf | 6311 | |
7117c2d2 JA |
6312 | # if there are more than 150 possible completions for |
6313 | # a word, ask the user if he wants to see all of them | |
ccc6cda3 | 6314 | set completion-query-items 150 |
761783bf | 6315 | |
ccc6cda3 JA |
6316 | # For FTP |
6317 | $if Ftp | |
6318 | "\C-xg": "get \M-?" | |
6319 | "\C-xt": "put \M-?" | |
6320 | "\M-.": yank-last-arg | |
6321 | $endif | |
6322 | ||
6323 | \1f | |
bb70624e JA |
6324 | File: bashref.info, Node: Bindable Readline Commands, Next: Readline vi Mode, Prev: Readline Init File, Up: Command Line Editing |
6325 | ||
761783bf CR |
6326 | 8.4 Bindable Readline Commands |
6327 | ============================== | |
bb70624e JA |
6328 | |
6329 | * Menu: | |
6330 | ||
6331 | * Commands For Moving:: Moving about the line. | |
6332 | * Commands For History:: Getting at previous lines. | |
6333 | * Commands For Text:: Commands for changing text. | |
6334 | * Commands For Killing:: Commands for killing and yanking. | |
6335 | * Numeric Arguments:: Specifying numeric arguments, repeat counts. | |
6336 | * Commands For Completion:: Getting Readline to do the typing for you. | |
6337 | * Keyboard Macros:: Saving and re-executing typed characters | |
6338 | * Miscellaneous Commands:: Other miscellaneous commands. | |
6339 | ||
6340 | This section describes Readline commands that may be bound to key | |
6341 | sequences. You can list your key bindings by executing `bind -P' or, | |
6342 | for a more terse format, suitable for an INPUTRC file, `bind -p'. | |
28ef6c31 JA |
6343 | (*Note Bash Builtins::.) Command names without an accompanying key |
6344 | sequence are unbound by default. | |
bb70624e | 6345 | |
28ef6c31 JA |
6346 | In the following descriptions, "point" refers to the current cursor |
6347 | position, and "mark" refers to a cursor position saved by the | |
bb70624e | 6348 | `set-mark' command. The text between the point and mark is referred to |
28ef6c31 | 6349 | as the "region". |
bb70624e JA |
6350 | |
6351 | \1f | |
6352 | File: bashref.info, Node: Commands For Moving, Next: Commands For History, Up: Bindable Readline Commands | |
6353 | ||
761783bf CR |
6354 | 8.4.1 Commands For Moving |
6355 | ------------------------- | |
bb70624e JA |
6356 | |
6357 | `beginning-of-line (C-a)' | |
6358 | Move to the start of the current line. | |
6359 | ||
6360 | `end-of-line (C-e)' | |
6361 | Move to the end of the line. | |
6362 | ||
6363 | `forward-char (C-f)' | |
6364 | Move forward a character. | |
6365 | ||
6366 | `backward-char (C-b)' | |
6367 | Move back a character. | |
6368 | ||
6369 | `forward-word (M-f)' | |
6370 | Move forward to the end of the next word. Words are composed of | |
6371 | letters and digits. | |
6372 | ||
6373 | `backward-word (M-b)' | |
6374 | Move back to the start of the current or previous word. Words are | |
6375 | composed of letters and digits. | |
6376 | ||
6377 | `clear-screen (C-l)' | |
6378 | Clear the screen and redraw the current line, leaving the current | |
6379 | line at the top of the screen. | |
6380 | ||
6381 | `redraw-current-line ()' | |
6382 | Refresh the current line. By default, this is unbound. | |
6383 | ||
761783bf | 6384 | |
bb70624e JA |
6385 | \1f |
6386 | File: bashref.info, Node: Commands For History, Next: Commands For Text, Prev: Commands For Moving, Up: Bindable Readline Commands | |
6387 | ||
761783bf CR |
6388 | 8.4.2 Commands For Manipulating The History |
6389 | ------------------------------------------- | |
bb70624e | 6390 | |
28ef6c31 | 6391 | `accept-line (Newline or Return)' |
bb70624e JA |
6392 | Accept the line regardless of where the cursor is. If this line is |
6393 | non-empty, add it to the history list according to the setting of | |
28ef6c31 JA |
6394 | the `HISTCONTROL' and `HISTIGNORE' variables. If this line is a |
6395 | modified history line, then restore the history line to its | |
6396 | original state. | |
bb70624e JA |
6397 | |
6398 | `previous-history (C-p)' | |
28ef6c31 JA |
6399 | Move `back' through the history list, fetching the previous |
6400 | command. | |
bb70624e JA |
6401 | |
6402 | `next-history (C-n)' | |
28ef6c31 | 6403 | Move `forward' through the history list, fetching the next command. |
bb70624e JA |
6404 | |
6405 | `beginning-of-history (M-<)' | |
6406 | Move to the first line in the history. | |
6407 | ||
6408 | `end-of-history (M->)' | |
6409 | Move to the end of the input history, i.e., the line currently | |
6410 | being entered. | |
6411 | ||
6412 | `reverse-search-history (C-r)' | |
6413 | Search backward starting at the current line and moving `up' | |
6414 | through the history as necessary. This is an incremental search. | |
6415 | ||
6416 | `forward-search-history (C-s)' | |
6417 | Search forward starting at the current line and moving `down' | |
6418 | through the the history as necessary. This is an incremental | |
6419 | search. | |
6420 | ||
6421 | `non-incremental-reverse-search-history (M-p)' | |
6422 | Search backward starting at the current line and moving `up' | |
6423 | through the history as necessary using a non-incremental search | |
6424 | for a string supplied by the user. | |
6425 | ||
6426 | `non-incremental-forward-search-history (M-n)' | |
6427 | Search forward starting at the current line and moving `down' | |
6428 | through the the history as necessary using a non-incremental search | |
6429 | for a string supplied by the user. | |
6430 | ||
6431 | `history-search-forward ()' | |
6432 | Search forward through the history for the string of characters | |
6433 | between the start of the current line and the point. This is a | |
6434 | non-incremental search. By default, this command is unbound. | |
6435 | ||
6436 | `history-search-backward ()' | |
6437 | Search backward through the history for the string of characters | |
6438 | between the start of the current line and the point. This is a | |
6439 | non-incremental search. By default, this command is unbound. | |
6440 | ||
6441 | `yank-nth-arg (M-C-y)' | |
6442 | Insert the first argument to the previous command (usually the | |
28ef6c31 JA |
6443 | second word on the previous line) at point. With an argument N, |
6444 | insert the Nth word from the previous command (the words in the | |
6445 | previous command begin with word 0). A negative argument inserts | |
6446 | the Nth word from the end of the previous command. | |
bb70624e | 6447 | |
28ef6c31 | 6448 | `yank-last-arg (M-. or M-_)' |
bb70624e JA |
6449 | Insert last argument to the previous command (the last word of the |
6450 | previous history entry). With an argument, behave exactly like | |
6451 | `yank-nth-arg'. Successive calls to `yank-last-arg' move back | |
6452 | through the history list, inserting the last argument of each line | |
6453 | in turn. | |
6454 | ||
761783bf | 6455 | |
bb70624e JA |
6456 | \1f |
6457 | File: bashref.info, Node: Commands For Text, Next: Commands For Killing, Prev: Commands For History, Up: Bindable Readline Commands | |
6458 | ||
761783bf CR |
6459 | 8.4.3 Commands For Changing Text |
6460 | -------------------------------- | |
bb70624e JA |
6461 | |
6462 | `delete-char (C-d)' | |
28ef6c31 JA |
6463 | Delete the character at point. If point is at the beginning of |
6464 | the line, there are no characters in the line, and the last | |
6465 | character typed was not bound to `delete-char', then return EOF. | |
bb70624e JA |
6466 | |
6467 | `backward-delete-char (Rubout)' | |
6468 | Delete the character behind the cursor. A numeric argument means | |
6469 | to kill the characters instead of deleting them. | |
6470 | ||
6471 | `forward-backward-delete-char ()' | |
6472 | Delete the character under the cursor, unless the cursor is at the | |
6473 | end of the line, in which case the character behind the cursor is | |
6474 | deleted. By default, this is not bound to a key. | |
6475 | ||
28ef6c31 | 6476 | `quoted-insert (C-q or C-v)' |
bb70624e | 6477 | Add the next character typed to the line verbatim. This is how to |
28ef6c31 | 6478 | insert key sequences like `C-q', for example. |
bb70624e JA |
6479 | |
6480 | `self-insert (a, b, A, 1, !, ...)' | |
6481 | Insert yourself. | |
6482 | ||
6483 | `transpose-chars (C-t)' | |
6484 | Drag the character before the cursor forward over the character at | |
6485 | the cursor, moving the cursor forward as well. If the insertion | |
6486 | point is at the end of the line, then this transposes the last two | |
6487 | characters of the line. Negative arguments have no effect. | |
6488 | ||
6489 | `transpose-words (M-t)' | |
6490 | Drag the word before point past the word after point, moving point | |
f73dda09 JA |
6491 | past that word as well. If the insertion point is at the end of |
6492 | the line, this transposes the last two words on the line. | |
bb70624e JA |
6493 | |
6494 | `upcase-word (M-u)' | |
6495 | Uppercase the current (or following) word. With a negative | |
6496 | argument, uppercase the previous word, but do not move the cursor. | |
6497 | ||
6498 | `downcase-word (M-l)' | |
6499 | Lowercase the current (or following) word. With a negative | |
6500 | argument, lowercase the previous word, but do not move the cursor. | |
6501 | ||
6502 | `capitalize-word (M-c)' | |
6503 | Capitalize the current (or following) word. With a negative | |
6504 | argument, capitalize the previous word, but do not move the cursor. | |
6505 | ||
7117c2d2 JA |
6506 | `overwrite-mode ()' |
6507 | Toggle overwrite mode. With an explicit positive numeric argument, | |
6508 | switches to overwrite mode. With an explicit non-positive numeric | |
6509 | argument, switches to insert mode. This command affects only | |
6510 | `emacs' mode; `vi' mode does overwrite differently. Each call to | |
6511 | `readline()' starts in insert mode. | |
6512 | ||
6513 | In overwrite mode, characters bound to `self-insert' replace the | |
6514 | text at point rather than pushing the text to the right. | |
6515 | Characters bound to `backward-delete-char' replace the character | |
6516 | before point with a space. | |
6517 | ||
6518 | By default, this command is unbound. | |
6519 | ||
761783bf | 6520 | |
bb70624e JA |
6521 | \1f |
6522 | File: bashref.info, Node: Commands For Killing, Next: Numeric Arguments, Prev: Commands For Text, Up: Bindable Readline Commands | |
6523 | ||
761783bf CR |
6524 | 8.4.4 Killing And Yanking |
6525 | ------------------------- | |
bb70624e JA |
6526 | |
6527 | `kill-line (C-k)' | |
6528 | Kill the text from point to the end of the line. | |
6529 | ||
6530 | `backward-kill-line (C-x Rubout)' | |
6531 | Kill backward to the beginning of the line. | |
6532 | ||
6533 | `unix-line-discard (C-u)' | |
6534 | Kill backward from the cursor to the beginning of the current line. | |
6535 | ||
6536 | `kill-whole-line ()' | |
28ef6c31 JA |
6537 | Kill all characters on the current line, no matter where point is. |
6538 | By default, this is unbound. | |
bb70624e JA |
6539 | |
6540 | `kill-word (M-d)' | |
6541 | Kill from point to the end of the current word, or if between | |
6542 | words, to the end of the next word. Word boundaries are the same | |
6543 | as `forward-word'. | |
6544 | ||
28ef6c31 | 6545 | `backward-kill-word (M-<DEL>)' |
bb70624e JA |
6546 | Kill the word behind point. Word boundaries are the same as |
6547 | `backward-word'. | |
6548 | ||
6549 | `unix-word-rubout (C-w)' | |
6550 | Kill the word behind point, using white space as a word boundary. | |
6551 | The killed text is saved on the kill-ring. | |
6552 | ||
113d85a4 CR |
6553 | `unix-filename-rubout ()' |
6554 | Kill the word behind point, using white space and the slash | |
6555 | character as the word boundaries. The killed text is saved on the | |
6556 | kill-ring. | |
6557 | ||
bb70624e JA |
6558 | `delete-horizontal-space ()' |
6559 | Delete all spaces and tabs around point. By default, this is | |
6560 | unbound. | |
6561 | ||
6562 | `kill-region ()' | |
6563 | Kill the text in the current region. By default, this command is | |
6564 | unbound. | |
6565 | ||
6566 | `copy-region-as-kill ()' | |
6567 | Copy the text in the region to the kill buffer, so it can be yanked | |
6568 | right away. By default, this command is unbound. | |
6569 | ||
6570 | `copy-backward-word ()' | |
6571 | Copy the word before point to the kill buffer. The word | |
6572 | boundaries are the same as `backward-word'. By default, this | |
6573 | command is unbound. | |
6574 | ||
6575 | `copy-forward-word ()' | |
6576 | Copy the word following point to the kill buffer. The word | |
6577 | boundaries are the same as `forward-word'. By default, this | |
6578 | command is unbound. | |
6579 | ||
6580 | `yank (C-y)' | |
28ef6c31 | 6581 | Yank the top of the kill ring into the buffer at point. |
bb70624e JA |
6582 | |
6583 | `yank-pop (M-y)' | |
6584 | Rotate the kill-ring, and yank the new top. You can only do this | |
28ef6c31 | 6585 | if the prior command is `yank' or `yank-pop'. |
bb70624e JA |
6586 | |
6587 | \1f | |
6588 | File: bashref.info, Node: Numeric Arguments, Next: Commands For Completion, Prev: Commands For Killing, Up: Bindable Readline Commands | |
6589 | ||
761783bf CR |
6590 | 8.4.5 Specifying Numeric Arguments |
6591 | ---------------------------------- | |
bb70624e JA |
6592 | |
6593 | `digit-argument (M-0, M-1, ... M--)' | |
6594 | Add this digit to the argument already accumulating, or start a new | |
28ef6c31 | 6595 | argument. `M--' starts a negative argument. |
bb70624e JA |
6596 | |
6597 | `universal-argument ()' | |
6598 | This is another way to specify an argument. If this command is | |
6599 | followed by one or more digits, optionally with a leading minus | |
6600 | sign, those digits define the argument. If the command is | |
6601 | followed by digits, executing `universal-argument' again ends the | |
6602 | numeric argument, but is otherwise ignored. As a special case, if | |
6603 | this command is immediately followed by a character that is | |
6604 | neither a digit or minus sign, the argument count for the next | |
6605 | command is multiplied by four. The argument count is initially | |
6606 | one, so executing this function the first time makes the argument | |
6607 | count four, a second time makes the argument count sixteen, and so | |
6608 | on. By default, this is not bound to a key. | |
6609 | ||
6610 | \1f | |
6611 | File: bashref.info, Node: Commands For Completion, Next: Keyboard Macros, Prev: Numeric Arguments, Up: Bindable Readline Commands | |
6612 | ||
761783bf CR |
6613 | 8.4.6 Letting Readline Type For You |
6614 | ----------------------------------- | |
bb70624e | 6615 | |
28ef6c31 JA |
6616 | `complete (<TAB>)' |
6617 | Attempt to perform completion on the text before point. The | |
6618 | actual completion performed is application-specific. Bash | |
6619 | attempts completion treating the text as a variable (if the text | |
6620 | begins with `$'), username (if the text begins with `~'), hostname | |
6621 | (if the text begins with `@'), or command (including aliases and | |
6622 | functions) in turn. If none of these produces a match, filename | |
6623 | completion is attempted. | |
bb70624e JA |
6624 | |
6625 | `possible-completions (M-?)' | |
28ef6c31 | 6626 | List the possible completions of the text before point. |
bb70624e JA |
6627 | |
6628 | `insert-completions (M-*)' | |
6629 | Insert all completions of the text before point that would have | |
6630 | been generated by `possible-completions'. | |
6631 | ||
6632 | `menu-complete ()' | |
6633 | Similar to `complete', but replaces the word to be completed with | |
6634 | a single match from the list of possible completions. Repeated | |
6635 | execution of `menu-complete' steps through the list of possible | |
6636 | completions, inserting each match in turn. At the end of the list | |
28ef6c31 JA |
6637 | of completions, the bell is rung (subject to the setting of |
6638 | `bell-style') and the original text is restored. An argument of N | |
6639 | moves N positions forward in the list of matches; a negative | |
6640 | argument may be used to move backward through the list. This | |
6641 | command is intended to be bound to <TAB>, but is unbound by | |
bb70624e JA |
6642 | default. |
6643 | ||
6644 | `delete-char-or-list ()' | |
6645 | Deletes the character under the cursor if not at the beginning or | |
6646 | end of the line (like `delete-char'). If at the end of the line, | |
6647 | behaves identically to `possible-completions'. This command is | |
6648 | unbound by default. | |
6649 | ||
6650 | `complete-filename (M-/)' | |
6651 | Attempt filename completion on the text before point. | |
6652 | ||
6653 | `possible-filename-completions (C-x /)' | |
6654 | List the possible completions of the text before point, treating | |
6655 | it as a filename. | |
6656 | ||
6657 | `complete-username (M-~)' | |
6658 | Attempt completion on the text before point, treating it as a | |
6659 | username. | |
6660 | ||
6661 | `possible-username-completions (C-x ~)' | |
6662 | List the possible completions of the text before point, treating | |
6663 | it as a username. | |
6664 | ||
6665 | `complete-variable (M-$)' | |
6666 | Attempt completion on the text before point, treating it as a | |
6667 | shell variable. | |
6668 | ||
6669 | `possible-variable-completions (C-x $)' | |
6670 | List the possible completions of the text before point, treating | |
6671 | it as a shell variable. | |
6672 | ||
6673 | `complete-hostname (M-@)' | |
6674 | Attempt completion on the text before point, treating it as a | |
6675 | hostname. | |
6676 | ||
6677 | `possible-hostname-completions (C-x @)' | |
6678 | List the possible completions of the text before point, treating | |
6679 | it as a hostname. | |
6680 | ||
6681 | `complete-command (M-!)' | |
6682 | Attempt completion on the text before point, treating it as a | |
6683 | command name. Command completion attempts to match the text | |
6684 | against aliases, reserved words, shell functions, shell builtins, | |
6685 | and finally executable filenames, in that order. | |
6686 | ||
6687 | `possible-command-completions (C-x !)' | |
6688 | List the possible completions of the text before point, treating | |
6689 | it as a command name. | |
6690 | ||
28ef6c31 | 6691 | `dynamic-complete-history (M-<TAB>)' |
bb70624e JA |
6692 | Attempt completion on the text before point, comparing the text |
6693 | against lines from the history list for possible completion | |
6694 | matches. | |
6695 | ||
6696 | `complete-into-braces (M-{)' | |
6697 | Perform filename completion and insert the list of possible | |
6698 | completions enclosed within braces so the list is available to the | |
28ef6c31 | 6699 | shell (*note Brace Expansion::). |
bb70624e | 6700 | |
761783bf | 6701 | |
bb70624e JA |
6702 | \1f |
6703 | File: bashref.info, Node: Keyboard Macros, Next: Miscellaneous Commands, Prev: Commands For Completion, Up: Bindable Readline Commands | |
6704 | ||
761783bf CR |
6705 | 8.4.7 Keyboard Macros |
6706 | --------------------- | |
bb70624e JA |
6707 | |
6708 | `start-kbd-macro (C-x ()' | |
6709 | Begin saving the characters typed into the current keyboard macro. | |
6710 | ||
6711 | `end-kbd-macro (C-x ))' | |
6712 | Stop saving the characters typed into the current keyboard macro | |
6713 | and save the definition. | |
6714 | ||
6715 | `call-last-kbd-macro (C-x e)' | |
6716 | Re-execute the last keyboard macro defined, by making the | |
6717 | characters in the macro appear as if typed at the keyboard. | |
6718 | ||
761783bf | 6719 | |
bb70624e JA |
6720 | \1f |
6721 | File: bashref.info, Node: Miscellaneous Commands, Prev: Keyboard Macros, Up: Bindable Readline Commands | |
6722 | ||
761783bf CR |
6723 | 8.4.8 Some Miscellaneous Commands |
6724 | --------------------------------- | |
bb70624e JA |
6725 | |
6726 | `re-read-init-file (C-x C-r)' | |
6727 | Read in the contents of the INPUTRC file, and incorporate any | |
6728 | bindings or variable assignments found there. | |
6729 | ||
6730 | `abort (C-g)' | |
6731 | Abort the current editing command and ring the terminal's bell | |
6732 | (subject to the setting of `bell-style'). | |
6733 | ||
6734 | `do-uppercase-version (M-a, M-b, M-X, ...)' | |
6735 | If the metafied character X is lowercase, run the command that is | |
6736 | bound to the corresponding uppercase character. | |
6737 | ||
28ef6c31 JA |
6738 | `prefix-meta (<ESC>)' |
6739 | Metafy the next character typed. This is for keyboards without a | |
6740 | meta key. Typing `<ESC> f' is equivalent to typing `M-f'. | |
bb70624e | 6741 | |
28ef6c31 | 6742 | `undo (C-_ or C-x C-u)' |
bb70624e JA |
6743 | Incremental undo, separately remembered for each line. |
6744 | ||
6745 | `revert-line (M-r)' | |
6746 | Undo all changes made to this line. This is like executing the | |
6747 | `undo' command enough times to get back to the beginning. | |
6748 | ||
6749 | `tilde-expand (M-&)' | |
6750 | Perform tilde expansion on the current word. | |
6751 | ||
6752 | `set-mark (C-@)' | |
28ef6c31 JA |
6753 | Set the mark to the point. If a numeric argument is supplied, the |
6754 | mark is set to that position. | |
bb70624e JA |
6755 | |
6756 | `exchange-point-and-mark (C-x C-x)' | |
6757 | Swap the point with the mark. The current cursor position is set | |
6758 | to the saved position, and the old cursor position is saved as the | |
6759 | mark. | |
6760 | ||
6761 | `character-search (C-])' | |
6762 | A character is read and point is moved to the next occurrence of | |
6763 | that character. A negative count searches for previous | |
6764 | occurrences. | |
6765 | ||
6766 | `character-search-backward (M-C-])' | |
6767 | A character is read and point is moved to the previous occurrence | |
6768 | of that character. A negative count searches for subsequent | |
6769 | occurrences. | |
6770 | ||
6771 | `insert-comment (M-#)' | |
7117c2d2 JA |
6772 | Without a numeric argument, the value of the `comment-begin' |
6773 | variable is inserted at the beginning of the current line. If a | |
6774 | numeric argument is supplied, this command acts as a toggle: if | |
6775 | the characters at the beginning of the line do not match the value | |
6776 | of `comment-begin', the value is inserted, otherwise the | |
6777 | characters in `comment-begin' are deleted from the beginning of | |
6778 | the line. In either case, the line is accepted as if a newline | |
6779 | had been typed. The default value of `comment-begin' causes this | |
6780 | command to make the current line a shell comment. If a numeric | |
6781 | argument causes the comment character to be removed, the line will | |
6782 | be executed by the shell. | |
bb70624e JA |
6783 | |
6784 | `dump-functions ()' | |
6785 | Print all of the functions and their key bindings to the Readline | |
6786 | output stream. If a numeric argument is supplied, the output is | |
6787 | formatted in such a way that it can be made part of an INPUTRC | |
6788 | file. This command is unbound by default. | |
6789 | ||
6790 | `dump-variables ()' | |
6791 | Print all of the settable variables and their values to the | |
6792 | Readline output stream. If a numeric argument is supplied, the | |
6793 | output is formatted in such a way that it can be made part of an | |
6794 | INPUTRC file. This command is unbound by default. | |
6795 | ||
6796 | `dump-macros ()' | |
6797 | Print all of the Readline key sequences bound to macros and the | |
28ef6c31 JA |
6798 | strings they output. If a numeric argument is supplied, the |
6799 | output is formatted in such a way that it can be made part of an | |
6800 | INPUTRC file. This command is unbound by default. | |
bb70624e | 6801 | |
7117c2d2 JA |
6802 | `glob-complete-word (M-g)' |
6803 | The word before point is treated as a pattern for pathname | |
6804 | expansion, with an asterisk implicitly appended. This pattern is | |
6805 | used to generate a list of matching file names for possible | |
6806 | completions. | |
6807 | ||
bb70624e JA |
6808 | `glob-expand-word (C-x *)' |
6809 | The word before point is treated as a pattern for pathname | |
6810 | expansion, and the list of matching file names is inserted, | |
7117c2d2 JA |
6811 | replacing the word. If a numeric argument is supplied, a `*' is |
6812 | appended before pathname expansion. | |
bb70624e JA |
6813 | |
6814 | `glob-list-expansions (C-x g)' | |
6815 | The list of expansions that would have been generated by | |
7117c2d2 JA |
6816 | `glob-expand-word' is displayed, and the line is redrawn. If a |
6817 | numeric argument is supplied, a `*' is appended before pathname | |
6818 | expansion. | |
bb70624e JA |
6819 | |
6820 | `display-shell-version (C-x C-v)' | |
6821 | Display version information about the current instance of Bash. | |
6822 | ||
6823 | `shell-expand-line (M-C-e)' | |
6824 | Expand the line as the shell does. This performs alias and | |
6825 | history expansion as well as all of the shell word expansions | |
28ef6c31 | 6826 | (*note Shell Expansions::). |
bb70624e JA |
6827 | |
6828 | `history-expand-line (M-^)' | |
6829 | Perform history expansion on the current line. | |
6830 | ||
6831 | `magic-space ()' | |
6832 | Perform history expansion on the current line and insert a space | |
28ef6c31 | 6833 | (*note History Interaction::). |
bb70624e JA |
6834 | |
6835 | `alias-expand-line ()' | |
28ef6c31 | 6836 | Perform alias expansion on the current line (*note Aliases::). |
bb70624e JA |
6837 | |
6838 | `history-and-alias-expand-line ()' | |
6839 | Perform history and alias expansion on the current line. | |
6840 | ||
28ef6c31 | 6841 | `insert-last-argument (M-. or M-_)' |
bb70624e JA |
6842 | A synonym for `yank-last-arg'. |
6843 | ||
6844 | `operate-and-get-next (C-o)' | |
6845 | Accept the current line for execution and fetch the next line | |
6846 | relative to the current line from the history for editing. Any | |
6847 | argument is ignored. | |
6848 | ||
7117c2d2 JA |
6849 | `edit-and-execute-command (C-xC-e)' |
6850 | Invoke an editor on the current command line, and execute the | |
c2258e1c | 6851 | result as shell commands. Bash attempts to invoke `$VISUAL', |
7117c2d2 | 6852 | `$EDITOR', and `emacs' as the editor, in that order. |
bb70624e | 6853 | |
761783bf | 6854 | |
bb70624e JA |
6855 | \1f |
6856 | File: bashref.info, Node: Readline vi Mode, Next: Programmable Completion, Prev: Bindable Readline Commands, Up: Command Line Editing | |
6857 | ||
761783bf CR |
6858 | 8.5 Readline vi Mode |
6859 | ==================== | |
bb70624e | 6860 | |
761783bf | 6861 | While the Readline library does not have a full set of `vi' editing |
bb70624e JA |
6862 | functions, it does contain enough to allow simple editing of the line. |
6863 | The Readline `vi' mode behaves as specified in the POSIX 1003.2 | |
6864 | standard. | |
6865 | ||
6866 | In order to switch interactively between `emacs' and `vi' editing | |
6867 | modes, use the `set -o emacs' and `set -o vi' commands (*note The Set | |
28ef6c31 | 6868 | Builtin::). The Readline default is `emacs' mode. |
bb70624e JA |
6869 | |
6870 | When you enter a line in `vi' mode, you are already placed in | |
6871 | `insertion' mode, as if you had typed an `i'. Pressing <ESC> switches | |
6872 | you into `command' mode, where you can edit the text of the line with | |
6873 | the standard `vi' movement keys, move to previous history lines with | |
6874 | `k' and subsequent lines with `j', and so forth. | |
6875 | ||
6876 | \1f | |
6877 | File: bashref.info, Node: Programmable Completion, Next: Programmable Completion Builtins, Prev: Readline vi Mode, Up: Command Line Editing | |
6878 | ||
761783bf CR |
6879 | 8.6 Programmable Completion |
6880 | =========================== | |
bb70624e | 6881 | |
761783bf | 6882 | When word completion is attempted for an argument to a command for |
bb70624e | 6883 | which a completion specification (a COMPSPEC) has been defined using |
28ef6c31 | 6884 | the `complete' builtin (*note Programmable Completion Builtins::), the |
bb70624e JA |
6885 | programmable completion facilities are invoked. |
6886 | ||
6887 | First, the command name is identified. If a compspec has been | |
6888 | defined for that command, the compspec is used to generate the list of | |
6889 | possible completions for the word. If the command word is a full | |
6890 | pathname, a compspec for the full pathname is searched for first. If | |
6891 | no compspec is found for the full pathname, an attempt is made to find | |
6892 | a compspec for the portion following the final slash. | |
6893 | ||
6894 | Once a compspec has been found, it is used to generate the list of | |
6895 | matching words. If a compspec is not found, the default Bash completion | |
28ef6c31 | 6896 | described above (*note Commands For Completion::) is performed. |
bb70624e JA |
6897 | |
6898 | First, the actions specified by the compspec are used. Only matches | |
6899 | which are prefixed by the word being completed are returned. When the | |
6900 | `-f' or `-d' option is used for filename or directory name completion, | |
6901 | the shell variable `FIGNORE' is used to filter the matches. *Note Bash | |
6902 | Variables::, for a description of `FIGNORE'. | |
6903 | ||
6904 | Any completions specified by a filename expansion pattern to the | |
6905 | `-G' option are generated next. The words generated by the pattern | |
6906 | need not match the word being completed. The `GLOBIGNORE' shell | |
6907 | variable is not used to filter the matches, but the `FIGNORE' shell | |
6908 | variable is used. | |
6909 | ||
6910 | Next, the string specified as the argument to the `-W' option is | |
6911 | considered. The string is first split using the characters in the `IFS' | |
6912 | special variable as delimiters. Shell quoting is honored. Each word | |
6913 | is then expanded using brace expansion, tilde expansion, parameter and | |
6914 | variable expansion, command substitution, arithmetic expansion, and | |
28ef6c31 JA |
6915 | pathname expansion, as described above (*note Shell Expansions::). The |
6916 | results are split using the rules described above (*note Word | |
6917 | Splitting::). The results of the expansion are prefix-matched against | |
bb70624e JA |
6918 | the word being completed, and the matching words become the possible |
6919 | completions. | |
6920 | ||
6921 | After these matches have been generated, any shell function or | |
6922 | command specified with the `-F' and `-C' options is invoked. When the | |
6923 | command or function is invoked, the `COMP_LINE' and `COMP_POINT' | |
6924 | variables are assigned values as described above (*note Bash | |
28ef6c31 | 6925 | Variables::). If a shell function is being invoked, the `COMP_WORDS' |
bb70624e JA |
6926 | and `COMP_CWORD' variables are also set. When the function or command |
6927 | is invoked, the first argument is the name of the command whose | |
6928 | arguments are being completed, the second argument is the word being | |
6929 | completed, and the third argument is the word preceding the word being | |
6930 | completed on the current command line. No filtering of the generated | |
6931 | completions against the word being completed is performed; the function | |
6932 | or command has complete freedom in generating the matches. | |
6933 | ||
6934 | Any function specified with `-F' is invoked first. The function may | |
6935 | use any of the shell facilities, including the `compgen' builtin | |
28ef6c31 JA |
6936 | described below (*note Programmable Completion Builtins::), to generate |
6937 | the matches. It must put the possible completions in the `COMPREPLY' | |
6938 | array variable. | |
bb70624e JA |
6939 | |
6940 | Next, any command specified with the `-C' option is invoked in an | |
6941 | environment equivalent to command substitution. It should print a list | |
6942 | of completions, one per line, to the standard output. Backslash may be | |
6943 | used to escape a newline, if necessary. | |
6944 | ||
6945 | After all of the possible completions are generated, any filter | |
6946 | specified with the `-X' option is applied to the list. The filter is a | |
6947 | pattern as used for pathname expansion; a `&' in the pattern is | |
6948 | replaced with the text of the word being completed. A literal `&' may | |
6949 | be escaped with a backslash; the backslash is removed before attempting | |
6950 | a match. Any completion that matches the pattern will be removed from | |
6951 | the list. A leading `!' negates the pattern; in this case any | |
6952 | completion not matching the pattern will be removed. | |
6953 | ||
6954 | Finally, any prefix and suffix specified with the `-P' and `-S' | |
6955 | options are added to each member of the completion list, and the result | |
6956 | is returned to the Readline completion code as the list of possible | |
6957 | completions. | |
6958 | ||
28ef6c31 JA |
6959 | If the previously-applied actions do not generate any matches, and |
6960 | the `-o dirnames' option was supplied to `complete' when the compspec | |
6961 | was defined, directory name completion is attempted. | |
6962 | ||
d3a24ed2 CR |
6963 | If the `-o plusdirs' option was supplied to `complete' when the |
6964 | compspec was defined, directory name completion is attempted and any | |
6965 | matches are added to the results of the other actions. | |
6966 | ||
28ef6c31 JA |
6967 | By default, if a compspec is found, whatever it generates is |
6968 | returned to the completion code as the full set of possible completions. | |
6969 | The default Bash completions are not attempted, and the Readline default | |
d3a24ed2 CR |
6970 | of filename completion is disabled. If the `-o bashdefault' option was |
6971 | supplied to `complete' when the compspec was defined, the default Bash | |
6972 | completions are attempted if the compspec generates no matches. If the | |
6973 | `-o default' option was supplied to `complete' when the compspec was | |
6974 | defined, Readline's default completion will be performed if the | |
6975 | compspec (and, if attempted, the default Bash completions) generate no | |
28ef6c31 | 6976 | matches. |
bb70624e | 6977 | |
7117c2d2 JA |
6978 | When a compspec indicates that directory name completion is desired, |
6979 | the programmable completion functions force Readline to append a slash | |
6980 | to completed names which are symbolic links to directories, subject to | |
6981 | the value of the MARK-DIRECTORIES Readline variable, regardless of the | |
6982 | setting of the MARK-SYMLINKED-DIRECTORIES Readline variable. | |
6983 | ||
bb70624e JA |
6984 | \1f |
6985 | File: bashref.info, Node: Programmable Completion Builtins, Prev: Programmable Completion, Up: Command Line Editing | |
6986 | ||
761783bf CR |
6987 | 8.7 Programmable Completion Builtins |
6988 | ==================================== | |
bb70624e | 6989 | |
761783bf | 6990 | Two builtin commands are available to manipulate the programmable |
bb70624e JA |
6991 | completion facilities. |
6992 | ||
6993 | `compgen' | |
6994 | `compgen [OPTION] [WORD]' | |
6995 | ||
6996 | Generate possible completion matches for WORD according to the | |
6997 | OPTIONs, which may be any option accepted by the `complete' | |
6998 | builtin with the exception of `-p' and `-r', and write the matches | |
6999 | to the standard output. When using the `-F' or `-C' options, the | |
7000 | various shell variables set by the programmable completion | |
7001 | facilities, while available, will not have useful values. | |
7002 | ||
7003 | The matches will be generated in the same way as if the | |
7004 | programmable completion code had generated them directly from a | |
7005 | completion specification with the same flags. If WORD is | |
7006 | specified, only those completions matching WORD will be displayed. | |
7007 | ||
7008 | The return value is true unless an invalid option is supplied, or | |
7009 | no matches were generated. | |
7010 | ||
7011 | `complete' | |
7117c2d2 | 7012 | `complete [-abcdefgjksuv] [-o COMP-OPTION] [-A ACTION] [-G GLOBPAT] [-W WORDLIST] |
bb70624e JA |
7013 | [-P PREFIX] [-S SUFFIX] [-X FILTERPAT] [-F FUNCTION] |
7014 | [-C COMMAND] NAME [NAME ...]' | |
7015 | `complete -pr [NAME ...]' | |
7016 | ||
7017 | Specify how arguments to each NAME should be completed. If the | |
7018 | `-p' option is supplied, or if no options are supplied, existing | |
7019 | completion specifications are printed in a way that allows them to | |
7020 | be reused as input. The `-r' option removes a completion | |
7021 | specification for each NAME, or, if no NAMEs are supplied, all | |
7022 | completion specifications. | |
7023 | ||
7024 | The process of applying these completion specifications when word | |
7025 | completion is attempted is described above (*note Programmable | |
28ef6c31 | 7026 | Completion::). |
bb70624e JA |
7027 | |
7028 | Other options, if specified, have the following meanings. The | |
7029 | arguments to the `-G', `-W', and `-X' options (and, if necessary, | |
7030 | the `-P' and `-S' options) should be quoted to protect them from | |
7031 | expansion before the `complete' builtin is invoked. | |
7032 | ||
28ef6c31 JA |
7033 | `-o COMP-OPTION' |
7034 | The COMP-OPTION controls several aspects of the compspec's | |
7035 | behavior beyond the simple generation of completions. | |
7036 | COMP-OPTION may be one of: | |
7037 | ||
d3a24ed2 CR |
7038 | `bashdefault' |
7039 | Perform the rest of the default Bash completions if the | |
7040 | compspec generates no matches. | |
7041 | ||
28ef6c31 | 7042 | `default' |
7117c2d2 JA |
7043 | Use Readline's default filename completion if the |
7044 | compspec generates no matches. | |
28ef6c31 JA |
7045 | |
7046 | `dirnames' | |
7047 | Perform directory name completion if the compspec | |
7048 | generates no matches. | |
7049 | ||
7050 | `filenames' | |
7051 | Tell Readline that the compspec generates filenames, so | |
d3a24ed2 | 7052 | it can perform any filename-specific processing (like |
28ef6c31 JA |
7053 | adding a slash to directory names or suppressing |
7054 | trailing spaces). This option is intended to be used | |
7055 | with shell functions specified with `-F'. | |
7056 | ||
7117c2d2 JA |
7057 | `nospace' |
7058 | Tell Readline not to append a space (the default) to | |
7059 | words completed at the end of the line. | |
7060 | ||
bb70624e JA |
7061 | `-A ACTION' |
7062 | The ACTION may be one of the following to generate a list of | |
7063 | possible completions: | |
7064 | ||
7065 | `alias' | |
7066 | Alias names. May also be specified as `-a'. | |
7067 | ||
7068 | `arrayvar' | |
7069 | Array variable names. | |
7070 | ||
7071 | `binding' | |
7072 | Readline key binding names (*note Bindable Readline | |
28ef6c31 | 7073 | Commands::). |
bb70624e JA |
7074 | |
7075 | `builtin' | |
7076 | Names of shell builtin commands. May also be specified | |
7077 | as `-b'. | |
7078 | ||
7079 | `command' | |
7080 | Command names. May also be specified as `-c'. | |
7081 | ||
7082 | `directory' | |
7083 | Directory names. May also be specified as `-d'. | |
7084 | ||
7085 | `disabled' | |
7086 | Names of disabled shell builtins. | |
7087 | ||
7088 | `enabled' | |
7089 | Names of enabled shell builtins. | |
7090 | ||
7091 | `export' | |
7092 | Names of exported shell variables. May also be | |
7093 | specified as `-e'. | |
7094 | ||
7095 | `file' | |
7096 | File names. May also be specified as `-f'. | |
7097 | ||
7098 | `function' | |
7099 | Names of shell functions. | |
7100 | ||
f73dda09 JA |
7101 | `group' |
7102 | Group names. May also be specified as `-g'. | |
7103 | ||
bb70624e JA |
7104 | `helptopic' |
7105 | Help topics as accepted by the `help' builtin (*note | |
28ef6c31 | 7106 | Bash Builtins::). |
bb70624e JA |
7107 | |
7108 | `hostname' | |
7109 | Hostnames, as taken from the file specified by the | |
28ef6c31 | 7110 | `HOSTFILE' shell variable (*note Bash Variables::). |
bb70624e JA |
7111 | |
7112 | `job' | |
7113 | Job names, if job control is active. May also be | |
7114 | specified as `-j'. | |
7115 | ||
7116 | `keyword' | |
7117 | Shell reserved words. May also be specified as `-k'. | |
7118 | ||
7119 | `running' | |
7120 | Names of running jobs, if job control is active. | |
7121 | ||
7117c2d2 JA |
7122 | `service' |
7123 | Service names. May also be specified as `-s'. | |
7124 | ||
bb70624e JA |
7125 | `setopt' |
7126 | Valid arguments for the `-o' option to the `set' builtin | |
28ef6c31 | 7127 | (*note The Set Builtin::). |
bb70624e JA |
7128 | |
7129 | `shopt' | |
7130 | Shell option names as accepted by the `shopt' builtin | |
28ef6c31 | 7131 | (*note Bash Builtins::). |
bb70624e JA |
7132 | |
7133 | `signal' | |
7134 | Signal names. | |
7135 | ||
7136 | `stopped' | |
7137 | Names of stopped jobs, if job control is active. | |
7138 | ||
7139 | `user' | |
7140 | User names. May also be specified as `-u'. | |
7141 | ||
7142 | `variable' | |
7143 | Names of all shell variables. May also be specified as | |
7144 | `-v'. | |
7145 | ||
7146 | `-G GLOBPAT' | |
7147 | The filename expansion pattern GLOBPAT is expanded to generate | |
7148 | the possible completions. | |
7149 | ||
7150 | `-W WORDLIST' | |
7151 | The WORDLIST is split using the characters in the `IFS' | |
7152 | special variable as delimiters, and each resultant word is | |
7153 | expanded. The possible completions are the members of the | |
7154 | resultant list which match the word being completed. | |
7155 | ||
7156 | `-C COMMAND' | |
7157 | COMMAND is executed in a subshell environment, and its output | |
7158 | is used as the possible completions. | |
7159 | ||
7160 | `-F FUNCTION' | |
7161 | The shell function FUNCTION is executed in the current shell | |
7162 | environment. When it finishes, the possible completions are | |
7163 | retrieved from the value of the `COMPREPLY' array variable. | |
7164 | ||
7165 | `-X FILTERPAT' | |
7166 | FILTERPAT is a pattern as used for filename expansion. It is | |
7167 | applied to the list of possible completions generated by the | |
7168 | preceding options and arguments, and each completion matching | |
7169 | FILTERPAT is removed from the list. A leading `!' in | |
7170 | FILTERPAT negates the pattern; in this case, any completion | |
7171 | not matching FILTERPAT is removed. | |
7172 | ||
7173 | `-P PREFIX' | |
7174 | PREFIX is added at the beginning of each possible completion | |
7175 | after all other options have been applied. | |
7176 | ||
7177 | `-S SUFFIX' | |
7178 | SUFFIX is appended to each possible completion after all | |
7179 | other options have been applied. | |
7180 | ||
7181 | The return value is true unless an invalid option is supplied, an | |
7182 | option other than `-p' or `-r' is supplied without a NAME | |
7183 | argument, an attempt is made to remove a completion specification | |
7184 | for a NAME for which no specification exists, or an error occurs | |
7185 | adding a completion specification. | |
7186 | ||
761783bf | 7187 | |
bb70624e JA |
7188 | \1f |
7189 | File: bashref.info, Node: Using History Interactively, Next: Command Line Editing, Prev: Job Control, Up: Top | |
7190 | ||
761783bf CR |
7191 | 9 Using History Interactively |
7192 | ***************************** | |
bb70624e | 7193 | |
761783bf | 7194 | This chapter describes how to use the GNU History Library |
bb70624e JA |
7195 | interactively, from a user's standpoint. It should be considered a |
7196 | user's guide. For information on using the GNU History Library in | |
7197 | other programs, see the GNU Readline Library Manual. | |
7198 | ||
7199 | * Menu: | |
7200 | ||
7201 | * Bash History Facilities:: How Bash lets you manipulate your command | |
7202 | history. | |
7203 | * Bash History Builtins:: The Bash builtin commands that manipulate | |
7204 | the command history. | |
7205 | * History Interaction:: What it feels like using History as a user. | |
7206 | ||
7207 | \1f | |
7208 | File: bashref.info, Node: Bash History Facilities, Next: Bash History Builtins, Up: Using History Interactively | |
7209 | ||
761783bf CR |
7210 | 9.1 Bash History Facilities |
7211 | =========================== | |
bb70624e | 7212 | |
761783bf CR |
7213 | When the `-o history' option to the `set' builtin is enabled (*note The |
7214 | Set Builtin::), the shell provides access to the "command history", the | |
7215 | list of commands previously typed. The value of the `HISTSIZE' shell | |
7216 | variable is used as the number of commands to save in a history list. | |
7217 | The text of the last `$HISTSIZE' commands (default 500) is saved. The | |
7218 | shell stores each command in the history list prior to parameter and | |
7219 | variable expansion but after history expansion is performed, subject to | |
7220 | the values of the shell variables `HISTIGNORE' and `HISTCONTROL'. | |
bb70624e JA |
7221 | |
7222 | When the shell starts up, the history is initialized from the file | |
7223 | named by the `HISTFILE' variable (default `~/.bash_history'). The file | |
7224 | named by the value of `HISTFILE' is truncated, if necessary, to contain | |
7225 | no more than the number of lines specified by the value of the | |
7226 | `HISTFILESIZE' variable. When an interactive shell exits, the last | |
7227 | `$HISTSIZE' lines are copied from the history list to the file named by | |
7228 | `$HISTFILE'. If the `histappend' shell option is set (*note Bash | |
28ef6c31 | 7229 | Builtins::), the lines are appended to the history file, otherwise the |
bb70624e JA |
7230 | history file is overwritten. If `HISTFILE' is unset, or if the history |
7231 | file is unwritable, the history is not saved. After saving the | |
7232 | history, the history file is truncated to contain no more than | |
7233 | `$HISTFILESIZE' lines. If `HISTFILESIZE' is not set, no truncation is | |
7234 | performed. | |
7235 | ||
d3a24ed2 CR |
7236 | If the `HISTTIMEFORMAT' is set, the time stamp information |
7237 | associated with each history entry is written to the history file. | |
7238 | ||
bb70624e JA |
7239 | The builtin command `fc' may be used to list or edit and re-execute |
7240 | a portion of the history list. The `history' builtin may be used to | |
7241 | display or modify the history list and manipulate the history file. | |
7242 | When using command-line editing, search commands are available in each | |
7243 | editing mode that provide access to the history list (*note Commands | |
28ef6c31 | 7244 | For History::). |
bb70624e JA |
7245 | |
7246 | The shell allows control over which commands are saved on the history | |
7247 | list. The `HISTCONTROL' and `HISTIGNORE' variables may be set to cause | |
7248 | the shell to save only a subset of the commands entered. The `cmdhist' | |
7249 | shell option, if enabled, causes the shell to attempt to save each line | |
7250 | of a multi-line command in the same history entry, adding semicolons | |
7251 | where necessary to preserve syntactic correctness. The `lithist' shell | |
7252 | option causes the shell to save the command with embedded newlines | |
7253 | instead of semicolons. The `shopt' builtin is used to set these | |
7254 | options. *Note Bash Builtins::, for a description of `shopt'. | |
7255 | ||
7256 | \1f | |
7257 | File: bashref.info, Node: Bash History Builtins, Next: History Interaction, Prev: Bash History Facilities, Up: Using History Interactively | |
7258 | ||
761783bf CR |
7259 | 9.2 Bash History Builtins |
7260 | ========================= | |
bb70624e | 7261 | |
761783bf | 7262 | Bash provides two builtin commands which manipulate the history list |
bb70624e JA |
7263 | and history file. |
7264 | ||
7265 | `fc' | |
7266 | `fc [-e ENAME] [-nlr] [FIRST] [LAST]' | |
7267 | `fc -s [PAT=REP] [COMMAND]' | |
7268 | ||
7269 | Fix Command. In the first form, a range of commands from FIRST to | |
7270 | LAST is selected from the history list. Both FIRST and LAST may | |
7271 | be specified as a string (to locate the most recent command | |
7272 | beginning with that string) or as a number (an index into the | |
7273 | history list, where a negative number is used as an offset from the | |
7274 | current command number). If LAST is not specified it is set to | |
7275 | FIRST. If FIRST is not specified it is set to the previous | |
7276 | command for editing and -16 for listing. If the `-l' flag is | |
7277 | given, the commands are listed on standard output. The `-n' flag | |
7278 | suppresses the command numbers when listing. The `-r' flag | |
7279 | reverses the order of the listing. Otherwise, the editor given by | |
7280 | ENAME is invoked on a file containing those commands. If ENAME is | |
7281 | not given, the value of the following variable expansion is used: | |
7282 | `${FCEDIT:-${EDITOR:-vi}}'. This says to use the value of the | |
7283 | `FCEDIT' variable if set, or the value of the `EDITOR' variable if | |
7284 | that is set, or `vi' if neither is set. When editing is complete, | |
7285 | the edited commands are echoed and executed. | |
7286 | ||
7287 | In the second form, COMMAND is re-executed after each instance of | |
7288 | PAT in the selected command is replaced by REP. | |
7289 | ||
7290 | A useful alias to use with the `fc' command is `r='fc -s'', so | |
7291 | that typing `r cc' runs the last command beginning with `cc' and | |
28ef6c31 | 7292 | typing `r' re-executes the last command (*note Aliases::). |
bb70624e JA |
7293 | |
7294 | `history' | |
7295 | history [N] | |
7296 | history -c | |
7297 | history -d OFFSET | |
7298 | history [-anrw] [FILENAME] | |
7299 | history -ps ARG | |
7300 | ||
7301 | With no options, display the history list with line numbers. | |
28ef6c31 | 7302 | Lines prefixed with a `*' have been modified. An argument of N |
d3a24ed2 CR |
7303 | lists only the last N lines. If the shell variable |
7304 | `HISTTIMEFORMAT' is set and not null, it is used as a format | |
7305 | string for STRFTIME to display the time stamp associated with each | |
7306 | displayed history entry. No intervening blank is printed between | |
7307 | the formatted time stamp and the history line. | |
7308 | ||
7309 | Options, if supplied, have the following meanings: | |
bb70624e JA |
7310 | |
7311 | `-c' | |
7312 | Clear the history list. This may be combined with the other | |
7313 | options to replace the history list completely. | |
7314 | ||
7315 | `-d OFFSET' | |
7316 | Delete the history entry at position OFFSET. OFFSET should | |
7317 | be specified as it appears when the history is displayed. | |
7318 | ||
7319 | `-a' | |
7320 | Append the new history lines (history lines entered since the | |
7321 | beginning of the current Bash session) to the history file. | |
7322 | ||
7323 | `-n' | |
7324 | Append the history lines not already read from the history | |
7325 | file to the current history list. These are lines appended | |
7326 | to the history file since the beginning of the current Bash | |
7327 | session. | |
7328 | ||
7329 | `-r' | |
7330 | Read the current history file and append its contents to the | |
7331 | history list. | |
7332 | ||
7333 | `-w' | |
7334 | Write out the current history to the history file. | |
7335 | ||
7336 | `-p' | |
7337 | Perform history substitution on the ARGs and display the | |
7338 | result on the standard output, without storing the results in | |
7339 | the history list. | |
7340 | ||
7341 | `-s' | |
7342 | The ARGs are added to the end of the history list as a single | |
7343 | entry. | |
7344 | ||
761783bf | 7345 | |
bb70624e JA |
7346 | When any of the `-w', `-r', `-a', or `-n' options is used, if |
7347 | FILENAME is given, then it is used as the history file. If not, | |
7348 | then the value of the `HISTFILE' variable is used. | |
7349 | ||
761783bf | 7350 | |
bb70624e JA |
7351 | \1f |
7352 | File: bashref.info, Node: History Interaction, Prev: Bash History Builtins, Up: Using History Interactively | |
ccc6cda3 | 7353 | |
761783bf CR |
7354 | 9.3 History Expansion |
7355 | ===================== | |
ccc6cda3 | 7356 | |
761783bf CR |
7357 | The History library provides a history expansion feature that is similar |
7358 | to the history expansion provided by `csh'. This section describes the | |
7359 | syntax used to manipulate the history information. | |
ccc6cda3 | 7360 | |
bb70624e JA |
7361 | History expansions introduce words from the history list into the |
7362 | input stream, making it easy to repeat commands, insert the arguments | |
7363 | to a previous command into the current input line, or fix errors in | |
7364 | previous commands quickly. | |
ccc6cda3 | 7365 | |
bb70624e JA |
7366 | History expansion takes place in two parts. The first is to |
7367 | determine which line from the history list should be used during | |
7368 | substitution. The second is to select portions of that line for | |
7369 | inclusion into the current one. The line selected from the history is | |
7370 | called the "event", and the portions of that line that are acted upon | |
7371 | are called "words". Various "modifiers" are available to manipulate | |
7372 | the selected words. The line is broken into words in the same fashion | |
7373 | that Bash does, so that several words surrounded by quotes are | |
7374 | considered one word. History expansions are introduced by the | |
7375 | appearance of the history expansion character, which is `!' by default. | |
7376 | Only `\' and `'' may be used to escape the history expansion character. | |
7377 | ||
7378 | Several shell options settable with the `shopt' builtin (*note Bash | |
28ef6c31 | 7379 | Builtins::) may be used to tailor the behavior of history expansion. |
bb70624e JA |
7380 | If the `histverify' shell option is enabled, and Readline is being |
7381 | used, history substitutions are not immediately passed to the shell | |
7382 | parser. Instead, the expanded line is reloaded into the Readline | |
7383 | editing buffer for further modification. If Readline is being used, | |
7384 | and the `histreedit' shell option is enabled, a failed history | |
7385 | expansion will be reloaded into the Readline editing buffer for | |
7386 | correction. The `-p' option to the `history' builtin command may be | |
7387 | used to see what a history expansion will do before using it. The `-s' | |
7388 | option to the `history' builtin may be used to add commands to the end | |
7389 | of the history list without actually executing them, so that they are | |
7390 | available for subsequent recall. This is most useful in conjunction | |
7391 | with Readline. | |
7392 | ||
7393 | The shell allows control of the various characters used by the | |
7394 | history expansion mechanism with the `histchars' variable. | |
7395 | ||
7396 | * Menu: | |
7397 | ||
7398 | * Event Designators:: How to specify which history line to use. | |
7399 | * Word Designators:: Specifying which words are of interest. | |
7400 | * Modifiers:: Modifying the results of substitution. | |
ccc6cda3 JA |
7401 | |
7402 | \1f | |
bb70624e | 7403 | File: bashref.info, Node: Event Designators, Next: Word Designators, Up: History Interaction |
ccc6cda3 | 7404 | |
761783bf CR |
7405 | 9.3.1 Event Designators |
7406 | ----------------------- | |
ccc6cda3 | 7407 | |
761783bf CR |
7408 | An event designator is a reference to a command line entry in the |
7409 | history list. | |
ccc6cda3 | 7410 | |
bb70624e JA |
7411 | `!' |
7412 | Start a history substitution, except when followed by a space, tab, | |
d3a24ed2 CR |
7413 | the end of the line, `=' or `(' (when the `extglob' shell option |
7414 | is enabled using the `shopt' builtin). | |
ccc6cda3 | 7415 | |
bb70624e JA |
7416 | `!N' |
7417 | Refer to command line N. | |
ccc6cda3 | 7418 | |
bb70624e JA |
7419 | `!-N' |
7420 | Refer to the command N lines back. | |
ccc6cda3 | 7421 | |
bb70624e JA |
7422 | `!!' |
7423 | Refer to the previous command. This is a synonym for `!-1'. | |
ccc6cda3 | 7424 | |
bb70624e JA |
7425 | `!STRING' |
7426 | Refer to the most recent command starting with STRING. | |
ccc6cda3 | 7427 | |
bb70624e JA |
7428 | `!?STRING[?]' |
7429 | Refer to the most recent command containing STRING. The trailing | |
7430 | `?' may be omitted if the STRING is followed immediately by a | |
7431 | newline. | |
ccc6cda3 | 7432 | |
bb70624e JA |
7433 | `^STRING1^STRING2^' |
7434 | Quick Substitution. Repeat the last command, replacing STRING1 | |
7435 | with STRING2. Equivalent to `!!:s/STRING1/STRING2/'. | |
7436 | ||
7437 | `!#' | |
7438 | The entire command line typed so far. | |
ccc6cda3 | 7439 | |
761783bf | 7440 | |
ccc6cda3 | 7441 | \1f |
bb70624e | 7442 | File: bashref.info, Node: Word Designators, Next: Modifiers, Prev: Event Designators, Up: History Interaction |
ccc6cda3 | 7443 | |
761783bf CR |
7444 | 9.3.2 Word Designators |
7445 | ---------------------- | |
ccc6cda3 | 7446 | |
761783bf | 7447 | Word designators are used to select desired words from the event. A |
bb70624e JA |
7448 | `:' separates the event specification from the word designator. It may |
7449 | be omitted if the word designator begins with a `^', `$', `*', `-', or | |
7450 | `%'. Words are numbered from the beginning of the line, with the first | |
7451 | word being denoted by 0 (zero). Words are inserted into the current | |
7452 | line separated by single spaces. | |
ccc6cda3 | 7453 | |
bb70624e | 7454 | For example, |
ccc6cda3 | 7455 | |
bb70624e JA |
7456 | `!!' |
7457 | designates the preceding command. When you type this, the | |
7458 | preceding command is repeated in toto. | |
ccc6cda3 | 7459 | |
bb70624e JA |
7460 | `!!:$' |
7461 | designates the last argument of the preceding command. This may be | |
7462 | shortened to `!$'. | |
ccc6cda3 | 7463 | |
bb70624e JA |
7464 | `!fi:2' |
7465 | designates the second argument of the most recent command starting | |
7466 | with the letters `fi'. | |
ccc6cda3 | 7467 | |
bb70624e | 7468 | Here are the word designators: |
ccc6cda3 | 7469 | |
bb70624e JA |
7470 | `0 (zero)' |
7471 | The `0'th word. For many applications, this is the command word. | |
ccc6cda3 | 7472 | |
bb70624e JA |
7473 | `N' |
7474 | The Nth word. | |
ccc6cda3 | 7475 | |
bb70624e JA |
7476 | `^' |
7477 | The first argument; that is, word 1. | |
ccc6cda3 | 7478 | |
bb70624e JA |
7479 | `$' |
7480 | The last argument. | |
ccc6cda3 | 7481 | |
bb70624e JA |
7482 | `%' |
7483 | The word matched by the most recent `?STRING?' search. | |
ccc6cda3 | 7484 | |
bb70624e JA |
7485 | `X-Y' |
7486 | A range of words; `-Y' abbreviates `0-Y'. | |
ccc6cda3 | 7487 | |
bb70624e JA |
7488 | `*' |
7489 | All of the words, except the `0'th. This is a synonym for `1-$'. | |
7490 | It is not an error to use `*' if there is just one word in the | |
7491 | event; the empty string is returned in that case. | |
7492 | ||
7493 | `X*' | |
7494 | Abbreviates `X-$' | |
7495 | ||
7496 | `X-' | |
7497 | Abbreviates `X-$' like `X*', but omits the last word. | |
7498 | ||
761783bf | 7499 | |
bb70624e JA |
7500 | If a word designator is supplied without an event specification, the |
7501 | previous command is used as the event. | |
ccc6cda3 JA |
7502 | |
7503 | \1f | |
bb70624e | 7504 | File: bashref.info, Node: Modifiers, Prev: Word Designators, Up: History Interaction |
ccc6cda3 | 7505 | |
761783bf CR |
7506 | 9.3.3 Modifiers |
7507 | --------------- | |
ccc6cda3 | 7508 | |
761783bf | 7509 | After the optional word designator, you can add a sequence of one or |
bb70624e | 7510 | more of the following modifiers, each preceded by a `:'. |
ccc6cda3 | 7511 | |
bb70624e JA |
7512 | `h' |
7513 | Remove a trailing pathname component, leaving only the head. | |
ccc6cda3 | 7514 | |
bb70624e JA |
7515 | `t' |
7516 | Remove all leading pathname components, leaving the tail. | |
7517 | ||
7518 | `r' | |
7519 | Remove a trailing suffix of the form `.SUFFIX', leaving the | |
7520 | basename. | |
7521 | ||
7522 | `e' | |
7523 | Remove all but the trailing suffix. | |
7524 | ||
7525 | `p' | |
7526 | Print the new command but do not execute it. | |
7527 | ||
7528 | `q' | |
7529 | Quote the substituted words, escaping further substitutions. | |
7530 | ||
7531 | `x' | |
7532 | Quote the substituted words as with `q', but break into words at | |
7533 | spaces, tabs, and newlines. | |
7534 | ||
7535 | `s/OLD/NEW/' | |
7536 | Substitute NEW for the first occurrence of OLD in the event line. | |
7537 | Any delimiter may be used in place of `/'. The delimiter may be | |
7538 | quoted in OLD and NEW with a single backslash. If `&' appears in | |
7539 | NEW, it is replaced by OLD. A single backslash will quote the | |
7540 | `&'. The final delimiter is optional if it is the last character | |
7541 | on the input line. | |
7542 | ||
7543 | `&' | |
7544 | Repeat the previous substitution. | |
7545 | ||
7546 | `g' | |
d3a24ed2 | 7547 | `a' |
bb70624e JA |
7548 | Cause changes to be applied over the entire event line. Used in |
7549 | conjunction with `s', as in `gs/OLD/NEW/', or with `&'. | |
7550 | ||
d3a24ed2 CR |
7551 | `G' |
7552 | Apply the following `s' modifier once to each word in the event. | |
7553 | ||
761783bf | 7554 | |
bb70624e JA |
7555 | \1f |
7556 | File: bashref.info, Node: Installing Bash, Next: Reporting Bugs, Prev: Command Line Editing, Up: Top | |
7557 | ||
761783bf CR |
7558 | 10 Installing Bash |
7559 | ****************** | |
b72432fd | 7560 | |
761783bf | 7561 | This chapter provides basic instructions for installing Bash on the |
bb70624e JA |
7562 | various supported platforms. The distribution supports the GNU |
7563 | operating systems, nearly every version of Unix, and several non-Unix | |
7564 | systems such as BeOS and Interix. Other independent ports exist for | |
d3a24ed2 | 7565 | MS-DOS, OS/2, and Windows platforms. |
ccc6cda3 | 7566 | |
bb70624e | 7567 | * Menu: |
ccc6cda3 | 7568 | |
bb70624e | 7569 | * Basic Installation:: Installation instructions. |
ccc6cda3 | 7570 | |
bb70624e JA |
7571 | * Compilers and Options:: How to set special options for various |
7572 | systems. | |
ccc6cda3 | 7573 | |
bb70624e JA |
7574 | * Compiling For Multiple Architectures:: How to compile Bash for more |
7575 | than one kind of system from | |
7576 | the same source tree. | |
ccc6cda3 | 7577 | |
bb70624e | 7578 | * Installation Names:: How to set the various paths used by the installation. |
ccc6cda3 | 7579 | |
bb70624e | 7580 | * Specifying the System Type:: How to configure Bash for a particular system. |
ccc6cda3 | 7581 | |
bb70624e JA |
7582 | * Sharing Defaults:: How to share default configuration values among GNU |
7583 | programs. | |
ccc6cda3 | 7584 | |
bb70624e | 7585 | * Operation Controls:: Options recognized by the configuration program. |
ccc6cda3 | 7586 | |
bb70624e JA |
7587 | * Optional Features:: How to enable and disable optional features when |
7588 | building Bash. | |
ccc6cda3 | 7589 | |
bb70624e JA |
7590 | \1f |
7591 | File: bashref.info, Node: Basic Installation, Next: Compilers and Options, Up: Installing Bash | |
ccc6cda3 | 7592 | |
761783bf CR |
7593 | 10.1 Basic Installation |
7594 | ======================= | |
ccc6cda3 | 7595 | |
761783bf | 7596 | These are installation instructions for Bash. |
ccc6cda3 | 7597 | |
bb70624e | 7598 | The simplest way to compile Bash is: |
ccc6cda3 | 7599 | |
bb70624e JA |
7600 | 1. `cd' to the directory containing the source code and type |
7601 | `./configure' to configure Bash for your system. If you're using | |
7602 | `csh' on an old version of System V, you might need to type `sh | |
7603 | ./configure' instead to prevent `csh' from trying to execute | |
7604 | `configure' itself. | |
ccc6cda3 | 7605 | |
bb70624e JA |
7606 | Running `configure' takes some time. While running, it prints |
7607 | messages telling which features it is checking for. | |
ccc6cda3 | 7608 | |
bb70624e JA |
7609 | 2. Type `make' to compile Bash and build the `bashbug' bug reporting |
7610 | script. | |
ccc6cda3 | 7611 | |
bb70624e | 7612 | 3. Optionally, type `make tests' to run the Bash test suite. |
ccc6cda3 | 7613 | |
bb70624e JA |
7614 | 4. Type `make install' to install `bash' and `bashbug'. This will |
7615 | also install the manual pages and Info file. | |
ccc6cda3 | 7616 | |
ccc6cda3 | 7617 | |
bb70624e JA |
7618 | The `configure' shell script attempts to guess correct values for |
7619 | various system-dependent variables used during compilation. It uses | |
7620 | those values to create a `Makefile' in each directory of the package | |
7621 | (the top directory, the `builtins', `doc', and `support' directories, | |
7622 | each directory under `lib', and several others). It also creates a | |
7623 | `config.h' file containing system-dependent definitions. Finally, it | |
7624 | creates a shell script named `config.status' that you can run in the | |
7625 | future to recreate the current configuration, a file `config.cache' | |
7626 | that saves the results of its tests to speed up reconfiguring, and a | |
7627 | file `config.log' containing compiler output (useful mainly for | |
7628 | debugging `configure'). If at some point `config.cache' contains | |
7629 | results you don't want to keep, you may remove or edit it. | |
ccc6cda3 | 7630 | |
bb70624e JA |
7631 | To find out more about the options and arguments that the |
7632 | `configure' script understands, type | |
ccc6cda3 | 7633 | |
bb70624e | 7634 | bash-2.04$ ./configure --help |
ccc6cda3 | 7635 | |
bb70624e | 7636 | at the Bash prompt in your Bash source directory. |
ccc6cda3 | 7637 | |
bb70624e JA |
7638 | If you need to do unusual things to compile Bash, please try to |
7639 | figure out how `configure' could check whether or not to do them, and | |
7640 | mail diffs or instructions to <bash-maintainers@gnu.org> so they can be | |
7641 | considered for the next release. | |
ccc6cda3 | 7642 | |
bb70624e JA |
7643 | The file `configure.in' is used to create `configure' by a program |
7644 | called Autoconf. You only need `configure.in' if you want to change it | |
7645 | or regenerate `configure' using a newer version of Autoconf. If you do | |
f73dda09 | 7646 | this, make sure you are using Autoconf version 2.50 or newer. |
ccc6cda3 | 7647 | |
bb70624e JA |
7648 | You can remove the program binaries and object files from the source |
7649 | code directory by typing `make clean'. To also remove the files that | |
7650 | `configure' created (so you can compile Bash for a different kind of | |
7651 | computer), type `make distclean'. | |
ccc6cda3 | 7652 | |
bb70624e JA |
7653 | \1f |
7654 | File: bashref.info, Node: Compilers and Options, Next: Compiling For Multiple Architectures, Prev: Basic Installation, Up: Installing Bash | |
ccc6cda3 | 7655 | |
761783bf CR |
7656 | 10.2 Compilers and Options |
7657 | ========================== | |
ccc6cda3 | 7658 | |
761783bf | 7659 | Some systems require unusual options for compilation or linking that |
bb70624e JA |
7660 | the `configure' script does not know about. You can give `configure' |
7661 | initial values for variables by setting them in the environment. Using | |
7662 | a Bourne-compatible shell, you can do that on the command line like | |
7663 | this: | |
ccc6cda3 | 7664 | |
bb70624e | 7665 | CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure |
ccc6cda3 | 7666 | |
bb70624e | 7667 | On systems that have the `env' program, you can do it like this: |
cce855bc | 7668 | |
bb70624e | 7669 | env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure |
b72432fd | 7670 | |
bb70624e | 7671 | The configuration process uses GCC to build Bash if it is available. |
ccc6cda3 | 7672 | |
bb70624e JA |
7673 | \1f |
7674 | File: bashref.info, Node: Compiling For Multiple Architectures, Next: Installation Names, Prev: Compilers and Options, Up: Installing Bash | |
ccc6cda3 | 7675 | |
761783bf CR |
7676 | 10.3 Compiling For Multiple Architectures |
7677 | ========================================= | |
ccc6cda3 | 7678 | |
761783bf | 7679 | You can compile Bash for more than one kind of computer at the same |
bb70624e JA |
7680 | time, by placing the object files for each architecture in their own |
7681 | directory. To do this, you must use a version of `make' that supports | |
7682 | the `VPATH' variable, such as GNU `make'. `cd' to the directory where | |
7683 | you want the object files and executables to go and run the `configure' | |
7684 | script from the source directory. You may need to supply the | |
7685 | `--srcdir=PATH' argument to tell `configure' where the source files | |
7686 | are. `configure' automatically checks for the source code in the | |
7687 | directory that `configure' is in and in `..'. | |
ccc6cda3 | 7688 | |
bb70624e JA |
7689 | If you have to use a `make' that does not supports the `VPATH' |
7690 | variable, you can compile Bash for one architecture at a time in the | |
7691 | source code directory. After you have installed Bash for one | |
7692 | architecture, use `make distclean' before reconfiguring for another | |
7693 | architecture. | |
ccc6cda3 | 7694 | |
bb70624e JA |
7695 | Alternatively, if your system supports symbolic links, you can use |
7696 | the `support/mkclone' script to create a build tree which has symbolic | |
7697 | links back to each file in the source directory. Here's an example | |
7698 | that creates a build directory in the current directory from a source | |
7699 | directory `/usr/gnu/src/bash-2.0': | |
ccc6cda3 | 7700 | |
bb70624e | 7701 | bash /usr/gnu/src/bash-2.0/support/mkclone -s /usr/gnu/src/bash-2.0 . |
ccc6cda3 | 7702 | |
bb70624e JA |
7703 | The `mkclone' script requires Bash, so you must have already built Bash |
7704 | for at least one architecture before you can create build directories | |
7705 | for other architectures. | |
ccc6cda3 | 7706 | |
bb70624e JA |
7707 | \1f |
7708 | File: bashref.info, Node: Installation Names, Next: Specifying the System Type, Prev: Compiling For Multiple Architectures, Up: Installing Bash | |
ccc6cda3 | 7709 | |
761783bf CR |
7710 | 10.4 Installation Names |
7711 | ======================= | |
ccc6cda3 | 7712 | |
761783bf | 7713 | By default, `make install' will install into `/usr/local/bin', |
bb70624e | 7714 | `/usr/local/man', etc. You can specify an installation prefix other |
f73dda09 JA |
7715 | than `/usr/local' by giving `configure' the option `--prefix=PATH', or |
7716 | by specifying a value for the `DESTDIR' `make' variable when running | |
7717 | `make install'. | |
ccc6cda3 | 7718 | |
bb70624e JA |
7719 | You can specify separate installation prefixes for |
7720 | architecture-specific files and architecture-independent files. If you | |
7721 | give `configure' the option `--exec-prefix=PATH', `make install' will | |
7722 | use PATH as the prefix for installing programs and libraries. | |
7723 | Documentation and other data files will still use the regular prefix. | |
ccc6cda3 JA |
7724 | |
7725 | \1f | |
bb70624e | 7726 | File: bashref.info, Node: Specifying the System Type, Next: Sharing Defaults, Prev: Installation Names, Up: Installing Bash |
ccc6cda3 | 7727 | |
761783bf CR |
7728 | 10.5 Specifying the System Type |
7729 | =============================== | |
ccc6cda3 | 7730 | |
761783bf | 7731 | There may be some features `configure' can not figure out |
f73dda09 | 7732 | automatically, but need to determine by the type of host Bash will run |
bb70624e JA |
7733 | on. Usually `configure' can figure that out, but if it prints a |
7734 | message saying it can not guess the host type, give it the | |
7735 | `--host=TYPE' option. `TYPE' can either be a short name for the system | |
7736 | type, such as `sun4', or a canonical name with three fields: | |
f73dda09 | 7737 | `CPU-COMPANY-SYSTEM' (e.g., `i386-unknown-freebsd4.2'). |
ccc6cda3 | 7738 | |
bb70624e JA |
7739 | See the file `support/config.sub' for the possible values of each |
7740 | field. | |
ccc6cda3 | 7741 | |
bb70624e JA |
7742 | \1f |
7743 | File: bashref.info, Node: Sharing Defaults, Next: Operation Controls, Prev: Specifying the System Type, Up: Installing Bash | |
7744 | ||
761783bf CR |
7745 | 10.6 Sharing Defaults |
7746 | ===================== | |
bb70624e | 7747 | |
761783bf CR |
7748 | If you want to set default values for `configure' scripts to share, you |
7749 | can create a site shell script called `config.site' that gives default | |
7750 | values for variables like `CC', `cache_file', and `prefix'. `configure' | |
7751 | looks for `PREFIX/share/config.site' if it exists, then | |
bb70624e JA |
7752 | `PREFIX/etc/config.site' if it exists. Or, you can set the |
7753 | `CONFIG_SITE' environment variable to the location of the site script. | |
7754 | A warning: the Bash `configure' looks for a site script, but not all | |
7755 | `configure' scripts do. | |
ccc6cda3 JA |
7756 | |
7757 | \1f | |
bb70624e | 7758 | File: bashref.info, Node: Operation Controls, Next: Optional Features, Prev: Sharing Defaults, Up: Installing Bash |
ccc6cda3 | 7759 | |
761783bf CR |
7760 | 10.7 Operation Controls |
7761 | ======================= | |
ccc6cda3 | 7762 | |
761783bf | 7763 | `configure' recognizes the following options to control how it operates. |
ccc6cda3 | 7764 | |
bb70624e JA |
7765 | `--cache-file=FILE' |
7766 | Use and save the results of the tests in FILE instead of | |
7767 | `./config.cache'. Set FILE to `/dev/null' to disable caching, for | |
7768 | debugging `configure'. | |
ccc6cda3 | 7769 | |
bb70624e JA |
7770 | `--help' |
7771 | Print a summary of the options to `configure', and exit. | |
ccc6cda3 | 7772 | |
bb70624e JA |
7773 | `--quiet' |
7774 | `--silent' | |
7775 | `-q' | |
7776 | Do not print messages saying which checks are being made. | |
ccc6cda3 | 7777 | |
bb70624e JA |
7778 | `--srcdir=DIR' |
7779 | Look for the Bash source code in directory DIR. Usually | |
7780 | `configure' can determine that directory automatically. | |
ccc6cda3 | 7781 | |
bb70624e JA |
7782 | `--version' |
7783 | Print the version of Autoconf used to generate the `configure' | |
7784 | script, and exit. | |
ccc6cda3 | 7785 | |
bb70624e JA |
7786 | `configure' also accepts some other, not widely used, boilerplate |
7787 | options. `configure --help' prints the complete list. | |
ccc6cda3 | 7788 | |
bb70624e JA |
7789 | \1f |
7790 | File: bashref.info, Node: Optional Features, Prev: Operation Controls, Up: Installing Bash | |
ccc6cda3 | 7791 | |
761783bf CR |
7792 | 10.8 Optional Features |
7793 | ====================== | |
ccc6cda3 | 7794 | |
761783bf CR |
7795 | The Bash `configure' has a number of `--enable-FEATURE' options, where |
7796 | FEATURE indicates an optional part of Bash. There are also several | |
7797 | `--with-PACKAGE' options, where PACKAGE is something like `bash-malloc' | |
7798 | or `purify'. To turn off the default use of a package, use | |
7799 | `--without-PACKAGE'. To configure Bash without a feature that is | |
bb70624e | 7800 | enabled by default, use `--disable-FEATURE'. |
ccc6cda3 | 7801 | |
bb70624e JA |
7802 | Here is a complete list of the `--enable-' and `--with-' options |
7803 | that the Bash `configure' recognizes. | |
ccc6cda3 | 7804 | |
bb70624e JA |
7805 | `--with-afs' |
7806 | Define if you are using the Andrew File System from Transarc. | |
ccc6cda3 | 7807 | |
bb70624e JA |
7808 | `--with-bash-malloc' |
7809 | Use the Bash version of `malloc' in `lib/malloc/malloc.c'. This | |
7810 | is not the same `malloc' that appears in GNU libc, but an older | |
7811 | version derived from the 4.2 BSD `malloc'. This `malloc' is very | |
7812 | fast, but wastes some space on each allocation. This option is | |
7813 | enabled by default. The `NOTES' file contains a list of systems | |
7814 | for which this should be turned off, and `configure' disables this | |
7815 | option automatically for a number of systems. | |
ccc6cda3 | 7816 | |
bb70624e JA |
7817 | `--with-curses' |
7818 | Use the curses library instead of the termcap library. This should | |
7819 | be supplied if your system has an inadequate or incomplete termcap | |
7820 | database. | |
ccc6cda3 | 7821 | |
bb70624e JA |
7822 | `--with-gnu-malloc' |
7823 | A synonym for `--with-bash-malloc'. | |
ccc6cda3 | 7824 | |
f73dda09 | 7825 | `--with-installed-readline[=PREFIX]' |
bb70624e JA |
7826 | Define this to make Bash link with a locally-installed version of |
7827 | Readline rather than the version in `lib/readline'. This works | |
7117c2d2 | 7828 | only with Readline 4.3 and later versions. If PREFIX is `yes' or |
f73dda09 JA |
7829 | not supplied, `configure' uses the values of the make variables |
7830 | `includedir' and `libdir', which are subdirectories of `prefix' by | |
7831 | default, to find the installed version of Readline if it is not in | |
7832 | the standard system include and library directories. If PREFIX is | |
7833 | `no', Bash links with the version in `lib/readline'. If PREFIX is | |
7834 | set to any other value, `configure' treats it as a directory | |
7835 | pathname and looks for the installed version of Readline in | |
7836 | subdirectories of that directory (include files in | |
7837 | PREFIX/`include' and the library in PREFIX/`lib'). | |
ccc6cda3 | 7838 | |
bb70624e JA |
7839 | `--with-purify' |
7840 | Define this to use the Purify memory allocation checker from | |
7841 | Rational Software. | |
ccc6cda3 | 7842 | |
bb70624e JA |
7843 | `--enable-minimal-config' |
7844 | This produces a shell with minimal features, close to the | |
7845 | historical Bourne shell. | |
ccc6cda3 | 7846 | |
bb70624e JA |
7847 | There are several `--enable-' options that alter how Bash is |
7848 | compiled and linked, rather than changing run-time features. | |
ccc6cda3 | 7849 | |
f73dda09 JA |
7850 | `--enable-largefile' |
7851 | Enable support for large files | |
7852 | (http://www.sas.com/standards/large_file/x_open.20Mar96.html) if | |
7853 | the operating system requires special compiler options to build | |
7117c2d2 JA |
7854 | programs which can access large files. This is enabled by |
7855 | default, if the operating system provides large file support. | |
f73dda09 | 7856 | |
bb70624e JA |
7857 | `--enable-profiling' |
7858 | This builds a Bash binary that produces profiling information to be | |
7859 | processed by `gprof' each time it is executed. | |
cce855bc | 7860 | |
bb70624e JA |
7861 | `--enable-static-link' |
7862 | This causes Bash to be linked statically, if `gcc' is being used. | |
7863 | This could be used to build a version to use as root's shell. | |
d166f048 | 7864 | |
bb70624e JA |
7865 | The `minimal-config' option can be used to disable all of the |
7866 | following options, but it is processed first, so individual options may | |
7867 | be enabled using `enable-FEATURE'. | |
d166f048 | 7868 | |
bb70624e JA |
7869 | All of the following options except for `disabled-builtins' and |
7870 | `xpg-echo-default' are enabled by default, unless the operating system | |
7871 | does not provide the necessary support. | |
ccc6cda3 | 7872 | |
bb70624e JA |
7873 | `--enable-alias' |
7874 | Allow alias expansion and include the `alias' and `unalias' | |
28ef6c31 | 7875 | builtins (*note Aliases::). |
ccc6cda3 | 7876 | |
bb70624e JA |
7877 | `--enable-arith-for-command' |
7878 | Include support for the alternate form of the `for' command that | |
7879 | behaves like the C language `for' statement (*note Looping | |
28ef6c31 | 7880 | Constructs::). |
ccc6cda3 | 7881 | |
bb70624e JA |
7882 | `--enable-array-variables' |
7883 | Include support for one-dimensional array shell variables (*note | |
28ef6c31 | 7884 | Arrays::). |
ccc6cda3 | 7885 | |
bb70624e JA |
7886 | `--enable-bang-history' |
7887 | Include support for `csh'-like history substitution (*note History | |
28ef6c31 | 7888 | Interaction::). |
ccc6cda3 | 7889 | |
bb70624e JA |
7890 | `--enable-brace-expansion' |
7891 | Include `csh'-like brace expansion ( `b{a,b}c' ==> `bac bbc' ). | |
7892 | See *Note Brace Expansion::, for a complete description. | |
ccc6cda3 | 7893 | |
bb70624e JA |
7894 | `--enable-command-timing' |
7895 | Include support for recognizing `time' as a reserved word and for | |
7896 | displaying timing statistics for the pipeline following `time' | |
28ef6c31 | 7897 | (*note Pipelines::). This allows pipelines as well as shell |
bb70624e | 7898 | builtins and functions to be timed. |
ccc6cda3 | 7899 | |
bb70624e | 7900 | `--enable-cond-command' |
5e13499c CR |
7901 | Include support for the `[[' conditional command. (*note |
7902 | Conditional Constructs::). | |
7903 | ||
7904 | `--enable-cond-regexp' | |
7905 | Include support for matching POSIX regular expressions using the | |
7906 | `=~' binary operator in the `[[' conditional command. (*note | |
28ef6c31 | 7907 | Conditional Constructs::). |
ccc6cda3 | 7908 | |
bb70624e JA |
7909 | `--enable-directory-stack' |
7910 | Include support for a `csh'-like directory stack and the `pushd', | |
28ef6c31 | 7911 | `popd', and `dirs' builtins (*note The Directory Stack::). |
ccc6cda3 | 7912 | |
bb70624e JA |
7913 | `--enable-disabled-builtins' |
7914 | Allow builtin commands to be invoked via `builtin xxx' even after | |
7915 | `xxx' has been disabled using `enable -n xxx'. See *Note Bash | |
7916 | Builtins::, for details of the `builtin' and `enable' builtin | |
7917 | commands. | |
ccc6cda3 | 7918 | |
bb70624e JA |
7919 | `--enable-dparen-arithmetic' |
7920 | Include support for the `((...))' command (*note Conditional | |
28ef6c31 | 7921 | Constructs::). |
ccc6cda3 | 7922 | |
bb70624e JA |
7923 | `--enable-extended-glob' |
7924 | Include support for the extended pattern matching features | |
7925 | described above under *Note Pattern Matching::. | |
ccc6cda3 | 7926 | |
bb70624e JA |
7927 | `--enable-help-builtin' |
7928 | Include the `help' builtin, which displays help on shell builtins | |
28ef6c31 | 7929 | and variables (*note Bash Builtins::). |
ccc6cda3 | 7930 | |
bb70624e JA |
7931 | `--enable-history' |
7932 | Include command history and the `fc' and `history' builtin | |
28ef6c31 | 7933 | commands (*note Bash History Facilities::). |
ccc6cda3 | 7934 | |
bb70624e | 7935 | `--enable-job-control' |
28ef6c31 | 7936 | This enables the job control features (*note Job Control::), if |
bb70624e | 7937 | the operating system supports them. |
ccc6cda3 | 7938 | |
d3a24ed2 CR |
7939 | `--enable-multibyte' |
7940 | This enables support for multibyte characters if the operating | |
7941 | system provides the necessary support. | |
7942 | ||
bb70624e JA |
7943 | `--enable-net-redirections' |
7944 | This enables the special handling of filenames of the form | |
7945 | `/dev/tcp/HOST/PORT' and `/dev/udp/HOST/PORT' when used in | |
28ef6c31 | 7946 | redirections (*note Redirections::). |
ccc6cda3 | 7947 | |
bb70624e | 7948 | `--enable-process-substitution' |
28ef6c31 JA |
7949 | This enables process substitution (*note Process Substitution::) if |
7950 | the operating system provides the necessary support. | |
ccc6cda3 | 7951 | |
bb70624e JA |
7952 | `--enable-prompt-string-decoding' |
7953 | Turn on the interpretation of a number of backslash-escaped | |
7954 | characters in the `$PS1', `$PS2', `$PS3', and `$PS4' prompt | |
7955 | strings. See *Note Printing a Prompt::, for a complete list of | |
7956 | prompt string escape sequences. | |
ccc6cda3 | 7957 | |
bb70624e JA |
7958 | `--enable-progcomp' |
7959 | Enable the programmable completion facilities (*note Programmable | |
28ef6c31 | 7960 | Completion::). If Readline is not enabled, this option has no |
bb70624e | 7961 | effect. |
ccc6cda3 | 7962 | |
bb70624e JA |
7963 | `--enable-readline' |
7964 | Include support for command-line editing and history with the Bash | |
28ef6c31 | 7965 | version of the Readline library (*note Command Line Editing::). |
ccc6cda3 | 7966 | |
bb70624e JA |
7967 | `--enable-restricted' |
7968 | Include support for a "restricted shell". If this is enabled, | |
7969 | Bash, when called as `rbash', enters a restricted mode. See *Note | |
7970 | The Restricted Shell::, for a description of restricted mode. | |
ccc6cda3 | 7971 | |
bb70624e JA |
7972 | `--enable-select' |
7973 | Include the `select' builtin, which allows the generation of simple | |
28ef6c31 | 7974 | menus (*note Conditional Constructs::). |
ccc6cda3 | 7975 | |
bb70624e JA |
7976 | `--enable-usg-echo-default' |
7977 | A synonym for `--enable-xpg-echo-default'. | |
ccc6cda3 | 7978 | |
bb70624e JA |
7979 | `--enable-xpg-echo-default' |
7980 | Make the `echo' builtin expand backslash-escaped characters by | |
7981 | default, without requiring the `-e' option. This sets the default | |
7982 | value of the `xpg_echo' shell option to `on', which makes the Bash | |
7983 | `echo' behave more like the version specified in the Single Unix | |
7984 | Specification, version 2. *Note Bash Builtins::, for a | |
7985 | description of the escape sequences that `echo' recognizes. | |
ccc6cda3 | 7986 | |
761783bf | 7987 | |
bb70624e JA |
7988 | The file `config-top.h' contains C Preprocessor `#define' statements |
7989 | for options which are not settable from `configure'. Some of these are | |
7990 | not meant to be changed; beware of the consequences if you do. Read | |
7991 | the comments associated with each definition for more information about | |
7992 | its effect. | |
ccc6cda3 | 7993 | |
bb70624e JA |
7994 | \1f |
7995 | File: bashref.info, Node: Reporting Bugs, Next: Major Differences From The Bourne Shell, Prev: Installing Bash, Up: Top | |
d166f048 | 7996 | |
761783bf CR |
7997 | Appendix A Reporting Bugs |
7998 | ************************* | |
ccc6cda3 | 7999 | |
761783bf | 8000 | Please report all bugs you find in Bash. But first, you should make |
bb70624e | 8001 | sure that it really is a bug, and that it appears in the latest version |
d3a24ed2 CR |
8002 | of Bash. The latest version of Bash is always available for FTP from |
8003 | `ftp://ftp.gnu.org/pub/bash/'. | |
ccc6cda3 | 8004 | |
bb70624e JA |
8005 | Once you have determined that a bug actually exists, use the |
8006 | `bashbug' command to submit a bug report. If you have a fix, you are | |
8007 | encouraged to mail that as well! Suggestions and `philosophical' bug | |
8008 | reports may be mailed to <bug-bash@gnu.org> or posted to the Usenet | |
8009 | newsgroup `gnu.bash.bug'. | |
ccc6cda3 | 8010 | |
bb70624e JA |
8011 | All bug reports should include: |
8012 | * The version number of Bash. | |
ccc6cda3 | 8013 | |
bb70624e | 8014 | * The hardware and operating system. |
ccc6cda3 | 8015 | |
bb70624e | 8016 | * The compiler used to compile Bash. |
ccc6cda3 | 8017 | |
bb70624e | 8018 | * A description of the bug behaviour. |
ccc6cda3 | 8019 | |
bb70624e JA |
8020 | * A short script or `recipe' which exercises the bug and may be used |
8021 | to reproduce it. | |
ccc6cda3 | 8022 | |
bb70624e JA |
8023 | `bashbug' inserts the first three items automatically into the template |
8024 | it provides for filing a bug report. | |
8025 | ||
8026 | Please send all reports concerning this manual to <chet@po.CWRU.Edu>. | |
ccc6cda3 JA |
8027 | |
8028 | \1f | |
d3a24ed2 | 8029 | File: bashref.info, Node: Major Differences From The Bourne Shell, Next: Copying This Manual, Prev: Reporting Bugs, Up: Top |
ccc6cda3 | 8030 | |
761783bf CR |
8031 | Appendix B Major Differences From The Bourne Shell |
8032 | ************************************************** | |
ccc6cda3 | 8033 | |
761783bf | 8034 | Bash implements essentially the same grammar, parameter and variable |
bb70624e JA |
8035 | expansion, redirection, and quoting as the Bourne Shell. Bash uses the |
8036 | POSIX 1003.2 standard as the specification of how these features are to | |
8037 | be implemented. There are some differences between the traditional | |
8038 | Bourne shell and Bash; this section quickly details the differences of | |
8039 | significance. A number of these differences are explained in greater | |
8040 | depth in previous sections. This section uses the version of `sh' | |
28ef6c31 | 8041 | included in SVR4.2 as the baseline reference. |
ccc6cda3 | 8042 | |
bb70624e | 8043 | * Bash is POSIX-conformant, even where the POSIX specification |
28ef6c31 | 8044 | differs from traditional `sh' behavior (*note Bash POSIX Mode::). |
ccc6cda3 | 8045 | |
bb70624e | 8046 | * Bash has multi-character invocation options (*note Invoking |
28ef6c31 | 8047 | Bash::). |
ccc6cda3 | 8048 | |
28ef6c31 | 8049 | * Bash has command-line editing (*note Command Line Editing::) and |
bb70624e | 8050 | the `bind' builtin. |
ccc6cda3 | 8051 | |
bb70624e | 8052 | * Bash provides a programmable word completion mechanism (*note |
28ef6c31 | 8053 | Programmable Completion::), and two builtin commands, `complete' |
bb70624e | 8054 | and `compgen', to manipulate it. |
ccc6cda3 | 8055 | |
28ef6c31 | 8056 | * Bash has command history (*note Bash History Facilities::) and the |
5e13499c CR |
8057 | `history' and `fc' builtins to manipulate it. The Bash history |
8058 | list maintains timestamp information and uses the value of the | |
8059 | `HISTTIMEFORMAT' variable to display it. | |
ccc6cda3 | 8060 | |
bb70624e | 8061 | * Bash implements `csh'-like history expansion (*note History |
28ef6c31 | 8062 | Interaction::). |
ccc6cda3 | 8063 | |
28ef6c31 | 8064 | * Bash has one-dimensional array variables (*note Arrays::), and the |
bb70624e JA |
8065 | appropriate variable expansions and assignment syntax to use them. |
8066 | Several of the Bash builtins take options to act on arrays. Bash | |
8067 | provides a number of built-in array variables. | |
ccc6cda3 | 8068 | |
bb70624e JA |
8069 | * The `$'...'' quoting syntax, which expands ANSI-C |
8070 | backslash-escaped characters in the text between the single quotes, | |
28ef6c31 | 8071 | is supported (*note ANSI-C Quoting::). |
ccc6cda3 | 8072 | |
bb70624e JA |
8073 | * Bash supports the `$"..."' quoting syntax to do locale-specific |
8074 | translation of the characters between the double quotes. The | |
8075 | `-D', `--dump-strings', and `--dump-po-strings' invocation options | |
8076 | list the translatable strings found in a script (*note Locale | |
28ef6c31 | 8077 | Translation::). |
ccc6cda3 | 8078 | |
bb70624e | 8079 | * Bash implements the `!' keyword to negate the return value of a |
28ef6c31 | 8080 | pipeline (*note Pipelines::). Very useful when an `if' statement |
bb70624e | 8081 | needs to act only if a test fails. |
ccc6cda3 | 8082 | |
bb70624e | 8083 | * Bash has the `time' reserved word and command timing (*note |
28ef6c31 | 8084 | Pipelines::). The display of the timing statistics may be |
bb70624e | 8085 | controlled with the `TIMEFORMAT' variable. |
ccc6cda3 | 8086 | |
bb70624e JA |
8087 | * Bash implements the `for (( EXPR1 ; EXPR2 ; EXPR3 ))' arithmetic |
8088 | for command, similar to the C language (*note Looping | |
28ef6c31 | 8089 | Constructs::). |
ccc6cda3 | 8090 | |
bb70624e | 8091 | * Bash includes the `select' compound command, which allows the |
28ef6c31 | 8092 | generation of simple menus (*note Conditional Constructs::). |
ccc6cda3 | 8093 | |
bb70624e | 8094 | * Bash includes the `[[' compound command, which makes conditional |
28ef6c31 | 8095 | testing part of the shell grammar (*note Conditional Constructs::). |
ccc6cda3 | 8096 | |
28ef6c31 JA |
8097 | * Bash includes brace expansion (*note Brace Expansion::) and tilde |
8098 | expansion (*note Tilde Expansion::). | |
ccc6cda3 | 8099 | |
bb70624e | 8100 | * Bash implements command aliases and the `alias' and `unalias' |
28ef6c31 | 8101 | builtins (*note Aliases::). |
ccc6cda3 | 8102 | |
bb70624e | 8103 | * Bash provides shell arithmetic, the `((' compound command (*note |
28ef6c31 JA |
8104 | Conditional Constructs::), and arithmetic expansion (*note Shell |
8105 | Arithmetic::). | |
ccc6cda3 | 8106 | |
bb70624e JA |
8107 | * Variables present in the shell's initial environment are |
8108 | automatically exported to child processes. The Bourne shell does | |
8109 | not normally do this unless the variables are explicitly marked | |
8110 | using the `export' command. | |
ccc6cda3 | 8111 | |
bb70624e JA |
8112 | * Bash includes the POSIX pattern removal `%', `#', `%%' and `##' |
8113 | expansions to remove leading or trailing substrings from variable | |
28ef6c31 | 8114 | values (*note Shell Parameter Expansion::). |
ccc6cda3 | 8115 | |
bb70624e | 8116 | * The expansion `${#xx}', which returns the length of `${xx}', is |
28ef6c31 | 8117 | supported (*note Shell Parameter Expansion::). |
ccc6cda3 | 8118 | |
bb70624e JA |
8119 | * The expansion `${var:'OFFSET`[:'LENGTH`]}', which expands to the |
8120 | substring of `var''s value of length LENGTH, beginning at OFFSET, | |
28ef6c31 | 8121 | is present (*note Shell Parameter Expansion::). |
ccc6cda3 | 8122 | |
bb70624e JA |
8123 | * The expansion `${var/[/]'PATTERN`[/'REPLACEMENT`]}', which matches |
8124 | PATTERN and replaces it with REPLACEMENT in the value of `var', is | |
28ef6c31 | 8125 | available (*note Shell Parameter Expansion::). |
ccc6cda3 | 8126 | |
bb70624e JA |
8127 | * The expansion `${!PREFIX}*' expansion, which expands to the names |
8128 | of all shell variables whose names begin with PREFIX, is available | |
28ef6c31 | 8129 | (*note Shell Parameter Expansion::). |
ccc6cda3 | 8130 | |
bb70624e | 8131 | * Bash has INDIRECT variable expansion using `${!word}' (*note Shell |
28ef6c31 | 8132 | Parameter Expansion::). |
ccc6cda3 | 8133 | |
bb70624e | 8134 | * Bash can expand positional parameters beyond `$9' using `${NUM}'. |
ccc6cda3 | 8135 | |
bb70624e | 8136 | * The POSIX `$()' form of command substitution is implemented (*note |
28ef6c31 | 8137 | Command Substitution::), and preferred to the Bourne shell's ```' |
bb70624e | 8138 | (which is also implemented for backwards compatibility). |
ccc6cda3 | 8139 | |
28ef6c31 | 8140 | * Bash has process substitution (*note Process Substitution::). |
ccc6cda3 | 8141 | |
bb70624e JA |
8142 | * Bash automatically assigns variables that provide information |
8143 | about the current user (`UID', `EUID', and `GROUPS'), the current | |
8144 | host (`HOSTTYPE', `OSTYPE', `MACHTYPE', and `HOSTNAME'), and the | |
8145 | instance of Bash that is running (`BASH', `BASH_VERSION', and | |
8146 | `BASH_VERSINFO'). *Note Bash Variables::, for details. | |
ccc6cda3 | 8147 | |
bb70624e | 8148 | * The `IFS' variable is used to split only the results of expansion, |
28ef6c31 | 8149 | not all words (*note Word Splitting::). This closes a |
bb70624e | 8150 | longstanding shell security hole. |
ccc6cda3 | 8151 | |
bb70624e JA |
8152 | * Bash implements the full set of POSIX 1003.2 filename expansion |
8153 | operators, including CHARACTER CLASSES, EQUIVALENCE CLASSES, and | |
28ef6c31 | 8154 | COLLATING SYMBOLS (*note Filename Expansion::). |
ccc6cda3 | 8155 | |
bb70624e | 8156 | * Bash implements extended pattern matching features when the |
28ef6c31 | 8157 | `extglob' shell option is enabled (*note Pattern Matching::). |
ccc6cda3 | 8158 | |
bb70624e JA |
8159 | * It is possible to have a variable and a function with the same |
8160 | name; `sh' does not separate the two name spaces. | |
ccc6cda3 | 8161 | |
bb70624e JA |
8162 | * Bash functions are permitted to have local variables using the |
8163 | `local' builtin, and thus useful recursive functions may be written | |
28ef6c31 | 8164 | (*note Bash Builtins::). |
ccc6cda3 | 8165 | |
bb70624e | 8166 | * Variable assignments preceding commands affect only that command, |
28ef6c31 | 8167 | even builtins and functions (*note Environment::). In `sh', all |
bb70624e JA |
8168 | variable assignments preceding commands are global unless the |
8169 | command is executed from the file system. | |
ccc6cda3 | 8170 | |
bb70624e | 8171 | * Bash performs filename expansion on filenames specified as operands |
28ef6c31 | 8172 | to input and output redirection operators (*note Redirections::). |
ccc6cda3 | 8173 | |
bb70624e JA |
8174 | * Bash contains the `<>' redirection operator, allowing a file to be |
8175 | opened for both reading and writing, and the `&>' redirection | |
8176 | operator, for directing standard output and standard error to the | |
28ef6c31 | 8177 | same file (*note Redirections::). |
d166f048 | 8178 | |
bb70624e | 8179 | * Bash treats a number of filenames specially when they are used in |
28ef6c31 | 8180 | redirection operators (*note Redirections::). |
ccc6cda3 | 8181 | |
bb70624e | 8182 | * Bash can open network connections to arbitrary machines and |
28ef6c31 | 8183 | services with the redirection operators (*note Redirections::). |
ccc6cda3 | 8184 | |
bb70624e | 8185 | * The `noclobber' option is available to avoid overwriting existing |
28ef6c31 JA |
8186 | files with output redirection (*note The Set Builtin::). The `>|' |
8187 | redirection operator may be used to override `noclobber'. | |
ccc6cda3 | 8188 | |
28ef6c31 JA |
8189 | * The Bash `cd' and `pwd' builtins (*note Bourne Shell Builtins::) |
8190 | each take `-L' and `-P' options to switch between logical and | |
bb70624e | 8191 | physical modes. |
b72432fd | 8192 | |
bb70624e JA |
8193 | * Bash allows a function to override a builtin with the same name, |
8194 | and provides access to that builtin's functionality within the | |
8195 | function via the `builtin' and `command' builtins (*note Bash | |
28ef6c31 | 8196 | Builtins::). |
ccc6cda3 | 8197 | |
bb70624e | 8198 | * The `command' builtin allows selective disabling of functions when |
28ef6c31 | 8199 | command lookup is performed (*note Bash Builtins::). |
ccc6cda3 | 8200 | |
bb70624e | 8201 | * Individual builtins may be enabled or disabled using the `enable' |
28ef6c31 | 8202 | builtin (*note Bash Builtins::). |
cce855bc | 8203 | |
bb70624e JA |
8204 | * The Bash `exec' builtin takes additional options that allow users |
8205 | to control the contents of the environment passed to the executed | |
8206 | command, and what the zeroth argument to the command is to be | |
28ef6c31 | 8207 | (*note Bourne Shell Builtins::). |
cce855bc | 8208 | |
bb70624e | 8209 | * Shell functions may be exported to children via the environment |
28ef6c31 | 8210 | using `export -f' (*note Shell Functions::). |
cce855bc | 8211 | |
bb70624e JA |
8212 | * The Bash `export', `readonly', and `declare' builtins can take a |
8213 | `-f' option to act on shell functions, a `-p' option to display | |
8214 | variables with various attributes set in a format that can be used | |
8215 | as shell input, a `-n' option to remove various variable | |
8216 | attributes, and `name=value' arguments to set variable attributes | |
8217 | and values simultaneously. | |
ccc6cda3 | 8218 | |
bb70624e JA |
8219 | * The Bash `hash' builtin allows a name to be associated with an |
8220 | arbitrary filename, even when that filename cannot be found by | |
8221 | searching the `$PATH', using `hash -p' (*note Bourne Shell | |
28ef6c31 | 8222 | Builtins::). |
ccc6cda3 | 8223 | |
bb70624e | 8224 | * Bash includes a `help' builtin for quick reference to shell |
28ef6c31 | 8225 | facilities (*note Bash Builtins::). |
ccc6cda3 | 8226 | |
bb70624e | 8227 | * The `printf' builtin is available to display formatted output |
28ef6c31 | 8228 | (*note Bash Builtins::). |
ccc6cda3 | 8229 | |
28ef6c31 | 8230 | * The Bash `read' builtin (*note Bash Builtins::) will read a line |
bb70624e JA |
8231 | ending in `\' with the `-r' option, and will use the `REPLY' |
8232 | variable as a default if no non-option arguments are supplied. | |
8233 | The Bash `read' builtin also accepts a prompt string with the `-p' | |
8234 | option and will use Readline to obtain the line when given the | |
8235 | `-e' option. The `read' builtin also has additional options to | |
8236 | control input: the `-s' option will turn off echoing of input | |
8237 | characters as they are read, the `-t' option will allow `read' to | |
8238 | time out if input does not arrive within a specified number of | |
8239 | seconds, the `-n' option will allow reading only a specified | |
8240 | number of characters rather than a full line, and the `-d' option | |
8241 | will read until a particular character rather than newline. | |
ccc6cda3 | 8242 | |
bb70624e JA |
8243 | * The `return' builtin may be used to abort execution of scripts |
8244 | executed with the `.' or `source' builtins (*note Bourne Shell | |
28ef6c31 | 8245 | Builtins::). |
d166f048 | 8246 | |
bb70624e | 8247 | * Bash includes the `shopt' builtin, for finer control of shell |
f73dda09 JA |
8248 | optional capabilities (*note Bash Builtins::), and allows these |
8249 | options to be set and unset at shell invocation (*note Invoking | |
8250 | Bash::). | |
d166f048 | 8251 | |
bb70624e | 8252 | * Bash has much more optional behavior controllable with the `set' |
28ef6c31 | 8253 | builtin (*note The Set Builtin::). |
cce855bc | 8254 | |
5e13499c CR |
8255 | * The `-x' (`xtrace') option displays commands other than simple |
8256 | commands when performing an execution trace (*note The Set | |
8257 | Builtin::). | |
8258 | ||
28ef6c31 | 8259 | * The `test' builtin (*note Bourne Shell Builtins::) is slightly |
bb70624e JA |
8260 | different, as it implements the POSIX algorithm, which specifies |
8261 | the behavior based on the number of arguments. | |
ccc6cda3 | 8262 | |
5e13499c CR |
8263 | * Bash includes the `caller' builtin, which displays the context of |
8264 | any active subroutine call (a shell function or a script executed | |
8265 | with the `.' or `source' builtins). This supports the bash | |
8266 | debugger. | |
8267 | ||
28ef6c31 | 8268 | * The `trap' builtin (*note Bourne Shell Builtins::) allows a |
bb70624e | 8269 | `DEBUG' pseudo-signal specification, similar to `EXIT'. Commands |
d3a24ed2 CR |
8270 | specified with a `DEBUG' trap are executed before every simple |
8271 | command, `for' command, `case' command, `select' command, every | |
8272 | arithmetic `for' command, and before the first command executes in | |
8273 | a shell function. The `DEBUG' trap is not inherited by shell | |
8274 | functions unless the function has been given the `trace' attribute | |
8275 | or the `functrace' option has been enabled using the `shopt' | |
8276 | builtin. The `extdebug' shell option has additional effects on the | |
8277 | `DEBUG' trap. | |
d166f048 | 8278 | |
f73dda09 JA |
8279 | The `trap' builtin (*note Bourne Shell Builtins::) allows an `ERR' |
8280 | pseudo-signal specification, similar to `EXIT' and `DEBUG'. | |
8281 | Commands specified with an `ERR' trap are executed after a simple | |
8282 | command fails, with a few exceptions. The `ERR' trap is not | |
d3a24ed2 CR |
8283 | inherited by shell functions unless the `-o errtrace' option to |
8284 | the `set' builtin is enabled. | |
8285 | ||
8286 | The `trap' builtin (*note Bourne Shell Builtins::) allows a | |
8287 | `RETURN' pseudo-signal specification, similar to `EXIT' and | |
8288 | `DEBUG'. Commands specified with an `RETURN' trap are executed | |
8289 | before execution resumes after a shell function or a shell script | |
8290 | executed with `.' or `source' returns. The `RETURN' trap is not | |
f73dda09 JA |
8291 | inherited by shell functions. |
8292 | ||
bb70624e | 8293 | * The Bash `type' builtin is more extensive and gives more |
28ef6c31 | 8294 | information about the names it finds (*note Bash Builtins::). |
cce855bc | 8295 | |
bb70624e JA |
8296 | * The Bash `umask' builtin permits a `-p' option to cause the output |
8297 | to be displayed in the form of a `umask' command that may be | |
28ef6c31 | 8298 | reused as input (*note Bourne Shell Builtins::). |
d166f048 | 8299 | |
bb70624e JA |
8300 | * Bash implements a `csh'-like directory stack, and provides the |
8301 | `pushd', `popd', and `dirs' builtins to manipulate it (*note The | |
28ef6c31 | 8302 | Directory Stack::). Bash also makes the directory stack visible |
bb70624e | 8303 | as the value of the `DIRSTACK' shell variable. |
d166f048 | 8304 | |
bb70624e | 8305 | * Bash interprets special backslash-escaped characters in the prompt |
28ef6c31 | 8306 | strings when interactive (*note Printing a Prompt::). |
d166f048 | 8307 | |
bb70624e | 8308 | * The Bash restricted mode is more useful (*note The Restricted |
28ef6c31 | 8309 | Shell::); the SVR4.2 shell restricted mode is too limited. |
ccc6cda3 | 8310 | |
bb70624e | 8311 | * The `disown' builtin can remove a job from the internal shell job |
28ef6c31 | 8312 | table (*note Job Control Builtins::) or suppress the sending of |
bb70624e | 8313 | `SIGHUP' to a job when the shell exits as the result of a `SIGHUP'. |
ccc6cda3 | 8314 | |
bb70624e JA |
8315 | * The SVR4.2 shell has two privilege-related builtins (`mldmode' and |
8316 | `priv') not present in Bash. | |
ccc6cda3 | 8317 | |
bb70624e | 8318 | * Bash does not have the `stop' or `newgrp' builtins. |
d166f048 | 8319 | |
bb70624e JA |
8320 | * Bash does not use the `SHACCT' variable or perform shell |
8321 | accounting. | |
d166f048 | 8322 | |
bb70624e | 8323 | * The SVR4.2 `sh' uses a `TIMEOUT' variable like Bash uses `TMOUT'. |
ccc6cda3 | 8324 | |
28ef6c31 | 8325 | |
bb70624e | 8326 | More features unique to Bash may be found in *Note Bash Features::. |
ccc6cda3 | 8327 | |
761783bf CR |
8328 | B.1 Implementation Differences From The SVR4.2 Shell |
8329 | ==================================================== | |
ccc6cda3 | 8330 | |
761783bf CR |
8331 | Since Bash is a completely new implementation, it does not suffer from |
8332 | many of the limitations of the SVR4.2 shell. For instance: | |
ccc6cda3 | 8333 | |
bb70624e JA |
8334 | * Bash does not fork a subshell when redirecting into or out of a |
8335 | shell control structure such as an `if' or `while' statement. | |
ccc6cda3 | 8336 | |
bb70624e JA |
8337 | * Bash does not allow unbalanced quotes. The SVR4.2 shell will |
8338 | silently insert a needed closing quote at `EOF' under certain | |
8339 | circumstances. This can be the cause of some hard-to-find errors. | |
ccc6cda3 | 8340 | |
bb70624e JA |
8341 | * The SVR4.2 shell uses a baroque memory management scheme based on |
8342 | trapping `SIGSEGV'. If the shell is started from a process with | |
8343 | `SIGSEGV' blocked (e.g., by using the `system()' C library | |
8344 | function call), it misbehaves badly. | |
ccc6cda3 | 8345 | |
bb70624e JA |
8346 | * In a questionable attempt at security, the SVR4.2 shell, when |
8347 | invoked without the `-p' option, will alter its real and effective | |
8348 | UID and GID if they are less than some magic threshold value, | |
8349 | commonly 100. This can lead to unexpected results. | |
ccc6cda3 | 8350 | |
bb70624e JA |
8351 | * The SVR4.2 shell does not allow users to trap `SIGSEGV', |
8352 | `SIGALRM', or `SIGCHLD'. | |
ccc6cda3 | 8353 | |
bb70624e JA |
8354 | * The SVR4.2 shell does not allow the `IFS', `MAILCHECK', `PATH', |
8355 | `PS1', or `PS2' variables to be unset. | |
ccc6cda3 | 8356 | |
bb70624e | 8357 | * The SVR4.2 shell treats `^' as the undocumented equivalent of `|'. |
ccc6cda3 | 8358 | |
bb70624e JA |
8359 | * Bash allows multiple option arguments when it is invoked (`-x -v'); |
8360 | the SVR4.2 shell allows only one option argument (`-xv'). In | |
8361 | fact, some versions of the shell dump core if the second argument | |
8362 | begins with a `-'. | |
ccc6cda3 | 8363 | |
bb70624e JA |
8364 | * The SVR4.2 shell exits a script if any builtin fails; Bash exits a |
8365 | script only if one of the POSIX 1003.2 special builtins fails, and | |
8366 | only for certain failures, as enumerated in the POSIX 1003.2 | |
8367 | standard. | |
ccc6cda3 | 8368 | |
bb70624e JA |
8369 | * The SVR4.2 shell behaves differently when invoked as `jsh' (it |
8370 | turns on job control). | |
ccc6cda3 JA |
8371 | |
8372 | \1f | |
d3a24ed2 CR |
8373 | File: bashref.info, Node: Copying This Manual, Next: Builtin Index, Prev: Major Differences From The Bourne Shell, Up: Top |
8374 | ||
761783bf CR |
8375 | Appendix C Copying This Manual |
8376 | ****************************** | |
d3a24ed2 CR |
8377 | |
8378 | * Menu: | |
8379 | ||
8380 | * GNU Free Documentation License:: License for copying this manual. | |
8381 | ||
8382 | \1f | |
8383 | File: bashref.info, Node: GNU Free Documentation License, Up: Copying This Manual | |
8384 | ||
761783bf CR |
8385 | C.1 GNU Free Documentation License |
8386 | ================================== | |
d3a24ed2 CR |
8387 | |
8388 | Version 1.2, November 2002 | |
761783bf | 8389 | |
d3a24ed2 CR |
8390 | Copyright (C) 2000,2001,2002 Free Software Foundation, Inc. |
8391 | 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA | |
761783bf | 8392 | |
d3a24ed2 CR |
8393 | Everyone is permitted to copy and distribute verbatim copies |
8394 | of this license document, but changing it is not allowed. | |
8395 | ||
8396 | 0. PREAMBLE | |
8397 | ||
8398 | The purpose of this License is to make a manual, textbook, or other | |
8399 | functional and useful document "free" in the sense of freedom: to | |
8400 | assure everyone the effective freedom to copy and redistribute it, | |
8401 | with or without modifying it, either commercially or | |
8402 | noncommercially. Secondarily, this License preserves for the | |
8403 | author and publisher a way to get credit for their work, while not | |
8404 | being considered responsible for modifications made by others. | |
8405 | ||
8406 | This License is a kind of "copyleft", which means that derivative | |
8407 | works of the document must themselves be free in the same sense. | |
8408 | It complements the GNU General Public License, which is a copyleft | |
8409 | license designed for free software. | |
8410 | ||
8411 | We have designed this License in order to use it for manuals for | |
8412 | free software, because free software needs free documentation: a | |
8413 | free program should come with manuals providing the same freedoms | |
8414 | that the software does. But this License is not limited to | |
8415 | software manuals; it can be used for any textual work, regardless | |
8416 | of subject matter or whether it is published as a printed book. | |
8417 | We recommend this License principally for works whose purpose is | |
8418 | instruction or reference. | |
8419 | ||
8420 | 1. APPLICABILITY AND DEFINITIONS | |
8421 | ||
8422 | This License applies to any manual or other work, in any medium, | |
8423 | that contains a notice placed by the copyright holder saying it | |
8424 | can be distributed under the terms of this License. Such a notice | |
8425 | grants a world-wide, royalty-free license, unlimited in duration, | |
8426 | to use that work under the conditions stated herein. The | |
8427 | "Document", below, refers to any such manual or work. Any member | |
8428 | of the public is a licensee, and is addressed as "you". You | |
8429 | accept the license if you copy, modify or distribute the work in a | |
8430 | way requiring permission under copyright law. | |
8431 | ||
8432 | A "Modified Version" of the Document means any work containing the | |
8433 | Document or a portion of it, either copied verbatim, or with | |
8434 | modifications and/or translated into another language. | |
8435 | ||
8436 | A "Secondary Section" is a named appendix or a front-matter section | |
8437 | of the Document that deals exclusively with the relationship of the | |
8438 | publishers or authors of the Document to the Document's overall | |
8439 | subject (or to related matters) and contains nothing that could | |
8440 | fall directly within that overall subject. (Thus, if the Document | |
8441 | is in part a textbook of mathematics, a Secondary Section may not | |
8442 | explain any mathematics.) The relationship could be a matter of | |
8443 | historical connection with the subject or with related matters, or | |
8444 | of legal, commercial, philosophical, ethical or political position | |
8445 | regarding them. | |
8446 | ||
8447 | The "Invariant Sections" are certain Secondary Sections whose | |
8448 | titles are designated, as being those of Invariant Sections, in | |
8449 | the notice that says that the Document is released under this | |
8450 | License. If a section does not fit the above definition of | |
8451 | Secondary then it is not allowed to be designated as Invariant. | |
8452 | The Document may contain zero Invariant Sections. If the Document | |
8453 | does not identify any Invariant Sections then there are none. | |
8454 | ||
8455 | The "Cover Texts" are certain short passages of text that are | |
8456 | listed, as Front-Cover Texts or Back-Cover Texts, in the notice | |
8457 | that says that the Document is released under this License. A | |
8458 | Front-Cover Text may be at most 5 words, and a Back-Cover Text may | |
8459 | be at most 25 words. | |
8460 | ||
8461 | A "Transparent" copy of the Document means a machine-readable copy, | |
8462 | represented in a format whose specification is available to the | |
8463 | general public, that is suitable for revising the document | |
8464 | straightforwardly with generic text editors or (for images | |
8465 | composed of pixels) generic paint programs or (for drawings) some | |
8466 | widely available drawing editor, and that is suitable for input to | |
8467 | text formatters or for automatic translation to a variety of | |
8468 | formats suitable for input to text formatters. A copy made in an | |
8469 | otherwise Transparent file format whose markup, or absence of | |
8470 | markup, has been arranged to thwart or discourage subsequent | |
8471 | modification by readers is not Transparent. An image format is | |
8472 | not Transparent if used for any substantial amount of text. A | |
8473 | copy that is not "Transparent" is called "Opaque". | |
8474 | ||
8475 | Examples of suitable formats for Transparent copies include plain | |
8476 | ASCII without markup, Texinfo input format, LaTeX input format, | |
8477 | SGML or XML using a publicly available DTD, and | |
8478 | standard-conforming simple HTML, PostScript or PDF designed for | |
8479 | human modification. Examples of transparent image formats include | |
8480 | PNG, XCF and JPG. Opaque formats include proprietary formats that | |
8481 | can be read and edited only by proprietary word processors, SGML or | |
8482 | XML for which the DTD and/or processing tools are not generally | |
8483 | available, and the machine-generated HTML, PostScript or PDF | |
8484 | produced by some word processors for output purposes only. | |
8485 | ||
8486 | The "Title Page" means, for a printed book, the title page itself, | |
8487 | plus such following pages as are needed to hold, legibly, the | |
8488 | material this License requires to appear in the title page. For | |
8489 | works in formats which do not have any title page as such, "Title | |
8490 | Page" means the text near the most prominent appearance of the | |
8491 | work's title, preceding the beginning of the body of the text. | |
8492 | ||
8493 | A section "Entitled XYZ" means a named subunit of the Document | |
8494 | whose title either is precisely XYZ or contains XYZ in parentheses | |
8495 | following text that translates XYZ in another language. (Here XYZ | |
8496 | stands for a specific section name mentioned below, such as | |
8497 | "Acknowledgements", "Dedications", "Endorsements", or "History".) | |
8498 | To "Preserve the Title" of such a section when you modify the | |
8499 | Document means that it remains a section "Entitled XYZ" according | |
8500 | to this definition. | |
8501 | ||
8502 | The Document may include Warranty Disclaimers next to the notice | |
8503 | which states that this License applies to the Document. These | |
8504 | Warranty Disclaimers are considered to be included by reference in | |
8505 | this License, but only as regards disclaiming warranties: any other | |
8506 | implication that these Warranty Disclaimers may have is void and | |
8507 | has no effect on the meaning of this License. | |
8508 | ||
8509 | 2. VERBATIM COPYING | |
8510 | ||
8511 | You may copy and distribute the Document in any medium, either | |
8512 | commercially or noncommercially, provided that this License, the | |
8513 | copyright notices, and the license notice saying this License | |
8514 | applies to the Document are reproduced in all copies, and that you | |
8515 | add no other conditions whatsoever to those of this License. You | |
8516 | may not use technical measures to obstruct or control the reading | |
8517 | or further copying of the copies you make or distribute. However, | |
8518 | you may accept compensation in exchange for copies. If you | |
8519 | distribute a large enough number of copies you must also follow | |
8520 | the conditions in section 3. | |
8521 | ||
8522 | You may also lend copies, under the same conditions stated above, | |
8523 | and you may publicly display copies. | |
8524 | ||
8525 | 3. COPYING IN QUANTITY | |
8526 | ||
8527 | If you publish printed copies (or copies in media that commonly | |
8528 | have printed covers) of the Document, numbering more than 100, and | |
8529 | the Document's license notice requires Cover Texts, you must | |
8530 | enclose the copies in covers that carry, clearly and legibly, all | |
8531 | these Cover Texts: Front-Cover Texts on the front cover, and | |
8532 | Back-Cover Texts on the back cover. Both covers must also clearly | |
8533 | and legibly identify you as the publisher of these copies. The | |
8534 | front cover must present the full title with all words of the | |
8535 | title equally prominent and visible. You may add other material | |
8536 | on the covers in addition. Copying with changes limited to the | |
8537 | covers, as long as they preserve the title of the Document and | |
8538 | satisfy these conditions, can be treated as verbatim copying in | |
8539 | other respects. | |
8540 | ||
8541 | If the required texts for either cover are too voluminous to fit | |
8542 | legibly, you should put the first ones listed (as many as fit | |
8543 | reasonably) on the actual cover, and continue the rest onto | |
8544 | adjacent pages. | |
8545 | ||
8546 | If you publish or distribute Opaque copies of the Document | |
8547 | numbering more than 100, you must either include a | |
8548 | machine-readable Transparent copy along with each Opaque copy, or | |
8549 | state in or with each Opaque copy a computer-network location from | |
8550 | which the general network-using public has access to download | |
8551 | using public-standard network protocols a complete Transparent | |
8552 | copy of the Document, free of added material. If you use the | |
8553 | latter option, you must take reasonably prudent steps, when you | |
8554 | begin distribution of Opaque copies in quantity, to ensure that | |
8555 | this Transparent copy will remain thus accessible at the stated | |
8556 | location until at least one year after the last time you | |
8557 | distribute an Opaque copy (directly or through your agents or | |
8558 | retailers) of that edition to the public. | |
8559 | ||
8560 | It is requested, but not required, that you contact the authors of | |
8561 | the Document well before redistributing any large number of | |
8562 | copies, to give them a chance to provide you with an updated | |
8563 | version of the Document. | |
8564 | ||
8565 | 4. MODIFICATIONS | |
8566 | ||
8567 | You may copy and distribute a Modified Version of the Document | |
8568 | under the conditions of sections 2 and 3 above, provided that you | |
8569 | release the Modified Version under precisely this License, with | |
8570 | the Modified Version filling the role of the Document, thus | |
8571 | licensing distribution and modification of the Modified Version to | |
8572 | whoever possesses a copy of it. In addition, you must do these | |
8573 | things in the Modified Version: | |
8574 | ||
8575 | A. Use in the Title Page (and on the covers, if any) a title | |
8576 | distinct from that of the Document, and from those of | |
8577 | previous versions (which should, if there were any, be listed | |
8578 | in the History section of the Document). You may use the | |
8579 | same title as a previous version if the original publisher of | |
8580 | that version gives permission. | |
8581 | ||
8582 | B. List on the Title Page, as authors, one or more persons or | |
8583 | entities responsible for authorship of the modifications in | |
8584 | the Modified Version, together with at least five of the | |
8585 | principal authors of the Document (all of its principal | |
8586 | authors, if it has fewer than five), unless they release you | |
8587 | from this requirement. | |
8588 | ||
8589 | C. State on the Title page the name of the publisher of the | |
8590 | Modified Version, as the publisher. | |
8591 | ||
8592 | D. Preserve all the copyright notices of the Document. | |
8593 | ||
8594 | E. Add an appropriate copyright notice for your modifications | |
8595 | adjacent to the other copyright notices. | |
8596 | ||
8597 | F. Include, immediately after the copyright notices, a license | |
8598 | notice giving the public permission to use the Modified | |
8599 | Version under the terms of this License, in the form shown in | |
8600 | the Addendum below. | |
8601 | ||
8602 | G. Preserve in that license notice the full lists of Invariant | |
8603 | Sections and required Cover Texts given in the Document's | |
8604 | license notice. | |
8605 | ||
8606 | H. Include an unaltered copy of this License. | |
8607 | ||
8608 | I. Preserve the section Entitled "History", Preserve its Title, | |
8609 | and add to it an item stating at least the title, year, new | |
8610 | authors, and publisher of the Modified Version as given on | |
8611 | the Title Page. If there is no section Entitled "History" in | |
8612 | the Document, create one stating the title, year, authors, | |
8613 | and publisher of the Document as given on its Title Page, | |
8614 | then add an item describing the Modified Version as stated in | |
8615 | the previous sentence. | |
8616 | ||
8617 | J. Preserve the network location, if any, given in the Document | |
8618 | for public access to a Transparent copy of the Document, and | |
8619 | likewise the network locations given in the Document for | |
8620 | previous versions it was based on. These may be placed in | |
8621 | the "History" section. You may omit a network location for a | |
8622 | work that was published at least four years before the | |
8623 | Document itself, or if the original publisher of the version | |
8624 | it refers to gives permission. | |
8625 | ||
8626 | K. For any section Entitled "Acknowledgements" or "Dedications", | |
8627 | Preserve the Title of the section, and preserve in the | |
8628 | section all the substance and tone of each of the contributor | |
8629 | acknowledgements and/or dedications given therein. | |
8630 | ||
8631 | L. Preserve all the Invariant Sections of the Document, | |
8632 | unaltered in their text and in their titles. Section numbers | |
8633 | or the equivalent are not considered part of the section | |
8634 | titles. | |
8635 | ||
8636 | M. Delete any section Entitled "Endorsements". Such a section | |
8637 | may not be included in the Modified Version. | |
8638 | ||
8639 | N. Do not retitle any existing section to be Entitled | |
8640 | "Endorsements" or to conflict in title with any Invariant | |
8641 | Section. | |
8642 | ||
8643 | O. Preserve any Warranty Disclaimers. | |
8644 | ||
8645 | If the Modified Version includes new front-matter sections or | |
8646 | appendices that qualify as Secondary Sections and contain no | |
8647 | material copied from the Document, you may at your option | |
8648 | designate some or all of these sections as invariant. To do this, | |
8649 | add their titles to the list of Invariant Sections in the Modified | |
8650 | Version's license notice. These titles must be distinct from any | |
8651 | other section titles. | |
8652 | ||
8653 | You may add a section Entitled "Endorsements", provided it contains | |
8654 | nothing but endorsements of your Modified Version by various | |
8655 | parties--for example, statements of peer review or that the text | |
8656 | has been approved by an organization as the authoritative | |
8657 | definition of a standard. | |
8658 | ||
8659 | You may add a passage of up to five words as a Front-Cover Text, | |
8660 | and a passage of up to 25 words as a Back-Cover Text, to the end | |
8661 | of the list of Cover Texts in the Modified Version. Only one | |
8662 | passage of Front-Cover Text and one of Back-Cover Text may be | |
8663 | added by (or through arrangements made by) any one entity. If the | |
8664 | Document already includes a cover text for the same cover, | |
8665 | previously added by you or by arrangement made by the same entity | |
8666 | you are acting on behalf of, you may not add another; but you may | |
8667 | replace the old one, on explicit permission from the previous | |
8668 | publisher that added the old one. | |
8669 | ||
8670 | The author(s) and publisher(s) of the Document do not by this | |
8671 | License give permission to use their names for publicity for or to | |
8672 | assert or imply endorsement of any Modified Version. | |
8673 | ||
8674 | 5. COMBINING DOCUMENTS | |
8675 | ||
8676 | You may combine the Document with other documents released under | |
8677 | this License, under the terms defined in section 4 above for | |
8678 | modified versions, provided that you include in the combination | |
8679 | all of the Invariant Sections of all of the original documents, | |
8680 | unmodified, and list them all as Invariant Sections of your | |
8681 | combined work in its license notice, and that you preserve all | |
8682 | their Warranty Disclaimers. | |
8683 | ||
8684 | The combined work need only contain one copy of this License, and | |
8685 | multiple identical Invariant Sections may be replaced with a single | |
8686 | copy. If there are multiple Invariant Sections with the same name | |
8687 | but different contents, make the title of each such section unique | |
8688 | by adding at the end of it, in parentheses, the name of the | |
8689 | original author or publisher of that section if known, or else a | |
8690 | unique number. Make the same adjustment to the section titles in | |
8691 | the list of Invariant Sections in the license notice of the | |
8692 | combined work. | |
8693 | ||
8694 | In the combination, you must combine any sections Entitled | |
8695 | "History" in the various original documents, forming one section | |
8696 | Entitled "History"; likewise combine any sections Entitled | |
8697 | "Acknowledgements", and any sections Entitled "Dedications". You | |
8698 | must delete all sections Entitled "Endorsements." | |
8699 | ||
8700 | 6. COLLECTIONS OF DOCUMENTS | |
8701 | ||
8702 | You may make a collection consisting of the Document and other | |
8703 | documents released under this License, and replace the individual | |
8704 | copies of this License in the various documents with a single copy | |
8705 | that is included in the collection, provided that you follow the | |
8706 | rules of this License for verbatim copying of each of the | |
8707 | documents in all other respects. | |
8708 | ||
8709 | You may extract a single document from such a collection, and | |
8710 | distribute it individually under this License, provided you insert | |
8711 | a copy of this License into the extracted document, and follow | |
8712 | this License in all other respects regarding verbatim copying of | |
8713 | that document. | |
8714 | ||
8715 | 7. AGGREGATION WITH INDEPENDENT WORKS | |
8716 | ||
8717 | A compilation of the Document or its derivatives with other | |
8718 | separate and independent documents or works, in or on a volume of | |
8719 | a storage or distribution medium, is called an "aggregate" if the | |
8720 | copyright resulting from the compilation is not used to limit the | |
8721 | legal rights of the compilation's users beyond what the individual | |
8722 | works permit. When the Document is included an aggregate, this | |
8723 | License does not apply to the other works in the aggregate which | |
8724 | are not themselves derivative works of the Document. | |
8725 | ||
8726 | If the Cover Text requirement of section 3 is applicable to these | |
8727 | copies of the Document, then if the Document is less than one half | |
8728 | of the entire aggregate, the Document's Cover Texts may be placed | |
8729 | on covers that bracket the Document within the aggregate, or the | |
8730 | electronic equivalent of covers if the Document is in electronic | |
8731 | form. Otherwise they must appear on printed covers that bracket | |
8732 | the whole aggregate. | |
8733 | ||
8734 | 8. TRANSLATION | |
8735 | ||
8736 | Translation is considered a kind of modification, so you may | |
8737 | distribute translations of the Document under the terms of section | |
8738 | 4. Replacing Invariant Sections with translations requires special | |
8739 | permission from their copyright holders, but you may include | |
8740 | translations of some or all Invariant Sections in addition to the | |
8741 | original versions of these Invariant Sections. You may include a | |
8742 | translation of this License, and all the license notices in the | |
8743 | Document, and any Warranty Disclaimers, provided that you also | |
8744 | include the original English version of this License and the | |
8745 | original versions of those notices and disclaimers. In case of a | |
8746 | disagreement between the translation and the original version of | |
8747 | this License or a notice or disclaimer, the original version will | |
8748 | prevail. | |
8749 | ||
8750 | If a section in the Document is Entitled "Acknowledgements", | |
8751 | "Dedications", or "History", the requirement (section 4) to | |
8752 | Preserve its Title (section 1) will typically require changing the | |
8753 | actual title. | |
8754 | ||
8755 | 9. TERMINATION | |
8756 | ||
8757 | You may not copy, modify, sublicense, or distribute the Document | |
8758 | except as expressly provided for under this License. Any other | |
8759 | attempt to copy, modify, sublicense or distribute the Document is | |
8760 | void, and will automatically terminate your rights under this | |
8761 | License. However, parties who have received copies, or rights, | |
8762 | from you under this License will not have their licenses | |
8763 | terminated so long as such parties remain in full compliance. | |
8764 | ||
8765 | 10. FUTURE REVISIONS OF THIS LICENSE | |
8766 | ||
8767 | The Free Software Foundation may publish new, revised versions of | |
8768 | the GNU Free Documentation License from time to time. Such new | |
8769 | versions will be similar in spirit to the present version, but may | |
8770 | differ in detail to address new problems or concerns. See | |
8771 | `http://www.gnu.org/copyleft/'. | |
8772 | ||
8773 | Each version of the License is given a distinguishing version | |
8774 | number. If the Document specifies that a particular numbered | |
8775 | version of this License "or any later version" applies to it, you | |
8776 | have the option of following the terms and conditions either of | |
8777 | that specified version or of any later version that has been | |
8778 | published (not as a draft) by the Free Software Foundation. If | |
8779 | the Document does not specify a version number of this License, | |
8780 | you may choose any version ever published (not as a draft) by the | |
8781 | Free Software Foundation. | |
8782 | ||
761783bf CR |
8783 | C.1.1 ADDENDUM: How to use this License for your documents |
8784 | ---------------------------------------------------------- | |
d3a24ed2 | 8785 | |
761783bf | 8786 | To use this License in a document you have written, include a copy of |
d3a24ed2 CR |
8787 | the License in the document and put the following copyright and license |
8788 | notices just after the title page: | |
8789 | ||
8790 | Copyright (C) YEAR YOUR NAME. | |
8791 | Permission is granted to copy, distribute and/or modify this document | |
8792 | under the terms of the GNU Free Documentation License, Version 1.2 | |
8793 | or any later version published by the Free Software Foundation; | |
8794 | with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. | |
8795 | A copy of the license is included in the section entitled ``GNU | |
8796 | Free Documentation License''. | |
8797 | ||
8798 | If you have Invariant Sections, Front-Cover Texts and Back-Cover | |
8799 | Texts, replace the "with...Texts." line with this: | |
8800 | ||
8801 | with the Invariant Sections being LIST THEIR TITLES, with | |
8802 | the Front-Cover Texts being LIST, and with the Back-Cover Texts | |
8803 | being LIST. | |
8804 | ||
8805 | If you have Invariant Sections without Cover Texts, or some other | |
8806 | combination of the three, merge those two alternatives to suit the | |
8807 | situation. | |
8808 | ||
8809 | If your document contains nontrivial examples of program code, we | |
8810 | recommend releasing these examples in parallel under your choice of | |
8811 | free software license, such as the GNU General Public License, to | |
8812 | permit their use in free software. | |
8813 | ||
8814 | \1f | |
8815 | File: bashref.info, Node: Builtin Index, Next: Reserved Word Index, Prev: Copying This Manual, Up: Top | |
ccc6cda3 JA |
8816 | |
8817 | Index of Shell Builtin Commands | |
8818 | ******************************* | |
8819 | ||
761783bf | 8820 | \0\b[index\0\b] |
ccc6cda3 JA |
8821 | * Menu: |
8822 | ||
e8ce775d | 8823 | * .: Bourne Shell Builtins. |
761783bf | 8824 | (line 16) |
e8ce775d | 8825 | * :: Bourne Shell Builtins. |
761783bf | 8826 | (line 11) |
e8ce775d | 8827 | * [: Bourne Shell Builtins. |
761783bf CR |
8828 | (line 212) |
8829 | * alias: Bash Builtins. (line 11) | |
e8ce775d | 8830 | * bg: Job Control Builtins. |
761783bf CR |
8831 | (line 7) |
8832 | * bind: Bash Builtins. (line 21) | |
e8ce775d | 8833 | * break: Bourne Shell Builtins. |
761783bf CR |
8834 | (line 29) |
8835 | * builtin: Bash Builtins. (line 92) | |
8836 | * caller: Bash Builtins. (line 100) | |
e8ce775d | 8837 | * cd: Bourne Shell Builtins. |
761783bf CR |
8838 | (line 36) |
8839 | * command: Bash Builtins. (line 117) | |
bb70624e | 8840 | * compgen: Programmable Completion Builtins. |
761783bf | 8841 | (line 10) |
bb70624e | 8842 | * complete: Programmable Completion Builtins. |
761783bf | 8843 | (line 28) |
e8ce775d | 8844 | * continue: Bourne Shell Builtins. |
761783bf CR |
8845 | (line 55) |
8846 | * declare: Bash Builtins. (line 136) | |
bb70624e | 8847 | * dirs: Directory Stack Builtins. |
761783bf | 8848 | (line 7) |
e8ce775d | 8849 | * disown: Job Control Builtins. |
761783bf CR |
8850 | (line 83) |
8851 | * echo: Bash Builtins. (line 191) | |
8852 | * enable: Bash Builtins. (line 244) | |
e8ce775d | 8853 | * eval: Bourne Shell Builtins. |
761783bf | 8854 | (line 63) |
e8ce775d | 8855 | * exec: Bourne Shell Builtins. |
761783bf | 8856 | (line 70) |
e8ce775d | 8857 | * exit: Bourne Shell Builtins. |
761783bf | 8858 | (line 82) |
e8ce775d | 8859 | * export: Bourne Shell Builtins. |
761783bf | 8860 | (line 88) |
cce855bc | 8861 | * fc: Bash History Builtins. |
761783bf | 8862 | (line 10) |
e8ce775d | 8863 | * fg: Job Control Builtins. |
761783bf | 8864 | (line 16) |
e8ce775d | 8865 | * getopts: Bourne Shell Builtins. |
761783bf | 8866 | (line 103) |
e8ce775d | 8867 | * hash: Bourne Shell Builtins. |
761783bf CR |
8868 | (line 145) |
8869 | * help: Bash Builtins. (line 272) | |
cce855bc | 8870 | * history: Bash History Builtins. |
761783bf | 8871 | (line 39) |
e8ce775d | 8872 | * jobs: Job Control Builtins. |
761783bf | 8873 | (line 25) |
e8ce775d | 8874 | * kill: Job Control Builtins. |
761783bf CR |
8875 | (line 57) |
8876 | * let: Bash Builtins. (line 281) | |
8877 | * local: Bash Builtins. (line 288) | |
8878 | * logout: Bash Builtins. (line 298) | |
bb70624e | 8879 | * popd: Directory Stack Builtins. |
761783bf CR |
8880 | (line 37) |
8881 | * printf: Bash Builtins. (line 302) | |
bb70624e | 8882 | * pushd: Directory Stack Builtins. |
761783bf | 8883 | (line 58) |
e8ce775d | 8884 | * pwd: Bourne Shell Builtins. |
761783bf CR |
8885 | (line 163) |
8886 | * read: Bash Builtins. (line 324) | |
e8ce775d | 8887 | * readonly: Bourne Shell Builtins. |
761783bf | 8888 | (line 172) |
e8ce775d | 8889 | * return: Bourne Shell Builtins. |
761783bf CR |
8890 | (line 187) |
8891 | * set: The Set Builtin. (line 9) | |
e8ce775d | 8892 | * shift: Bourne Shell Builtins. |
761783bf CR |
8893 | (line 200) |
8894 | * shopt: Bash Builtins. (line 385) | |
8895 | * source: Bash Builtins. (line 600) | |
e8ce775d | 8896 | * suspend: Job Control Builtins. |
761783bf | 8897 | (line 94) |
e8ce775d | 8898 | * test: Bourne Shell Builtins. |
761783bf | 8899 | (line 212) |
e8ce775d | 8900 | * times: Bourne Shell Builtins. |
761783bf | 8901 | (line 276) |
e8ce775d | 8902 | * trap: Bourne Shell Builtins. |
761783bf CR |
8903 | (line 281) |
8904 | * type: Bash Builtins. (line 604) | |
8905 | * typeset: Bash Builtins. (line 635) | |
8906 | * ulimit: Bash Builtins. (line 641) | |
e8ce775d | 8907 | * umask: Bourne Shell Builtins. |
761783bf CR |
8908 | (line 322) |
8909 | * unalias: Bash Builtins. (line 703) | |
e8ce775d | 8910 | * unset: Bourne Shell Builtins. |
761783bf | 8911 | (line 339) |
e8ce775d | 8912 | * wait: Job Control Builtins. |
761783bf | 8913 | (line 73) |
ccc6cda3 JA |
8914 | |
8915 | \1f | |
8916 | File: bashref.info, Node: Reserved Word Index, Next: Variable Index, Prev: Builtin Index, Up: Top | |
8917 | ||
bb70624e JA |
8918 | Index of Shell Reserved Words |
8919 | ***************************** | |
ccc6cda3 | 8920 | |
761783bf | 8921 | \0\b[index\0\b] |
ccc6cda3 JA |
8922 | * Menu: |
8923 | ||
761783bf | 8924 | * !: Pipelines. (line 8) |
cce855bc | 8925 | * [[: Conditional Constructs. |
761783bf | 8926 | (line 105) |
cce855bc | 8927 | * ]]: Conditional Constructs. |
761783bf | 8928 | (line 105) |
e8ce775d | 8929 | * case: Conditional Constructs. |
761783bf CR |
8930 | (line 28) |
8931 | * do: Looping Constructs. (line 12) | |
8932 | * done: Looping Constructs. (line 12) | |
e8ce775d | 8933 | * elif: Conditional Constructs. |
761783bf | 8934 | (line 7) |
e8ce775d | 8935 | * else: Conditional Constructs. |
761783bf | 8936 | (line 7) |
e8ce775d | 8937 | * esac: Conditional Constructs. |
761783bf | 8938 | (line 28) |
e8ce775d | 8939 | * fi: Conditional Constructs. |
761783bf CR |
8940 | (line 7) |
8941 | * for: Looping Constructs. (line 29) | |
8942 | * function: Shell Functions. (line 13) | |
e8ce775d | 8943 | * if: Conditional Constructs. |
761783bf | 8944 | (line 7) |
e8ce775d | 8945 | * in: Conditional Constructs. |
761783bf | 8946 | (line 28) |
cce855bc | 8947 | * select: Conditional Constructs. |
761783bf | 8948 | (line 64) |
e8ce775d | 8949 | * then: Conditional Constructs. |
761783bf CR |
8950 | (line 7) |
8951 | * time: Pipelines. (line 8) | |
8952 | * until: Looping Constructs. (line 12) | |
8953 | * while: Looping Constructs. (line 20) | |
8954 | * {: Command Grouping. (line 21) | |
8955 | * }: Command Grouping. (line 21) | |
ccc6cda3 JA |
8956 | |
8957 | \1f | |
8958 | File: bashref.info, Node: Variable Index, Next: Function Index, Prev: Reserved Word Index, Up: Top | |
8959 | ||
8960 | Parameter and Variable Index | |
8961 | **************************** | |
8962 | ||
761783bf | 8963 | \0\b[index\0\b] |
ccc6cda3 JA |
8964 | * Menu: |
8965 | ||
761783bf CR |
8966 | * !: Special Parameters. (line 42) |
8967 | * #: Special Parameters. (line 26) | |
8968 | * $: Special Parameters. (line 38) | |
8969 | * *: Special Parameters. (line 9) | |
8970 | * -: Special Parameters. (line 33) | |
8971 | * 0: Special Parameters. (line 46) | |
8972 | * ?: Special Parameters. (line 29) | |
8973 | * @: Special Parameters. (line 19) | |
8974 | * _: Special Parameters. (line 55) | |
e8ce775d | 8975 | * auto_resume: Job Control Variables. |
761783bf CR |
8976 | (line 6) |
8977 | * BASH: Bash Variables. (line 13) | |
8978 | * BASH_ARGC: Bash Variables. (line 16) | |
8979 | * BASH_ARGV: Bash Variables. (line 24) | |
8980 | * BASH_COMMAND: Bash Variables. (line 31) | |
8981 | * BASH_ENV: Bash Variables. (line 36) | |
8982 | * BASH_EXECUTION_STRING: Bash Variables. (line 42) | |
8983 | * BASH_LINENO: Bash Variables. (line 45) | |
8984 | * BASH_REMATCH: Bash Variables. (line 53) | |
8985 | * BASH_SOURCE: Bash Variables. (line 61) | |
8986 | * BASH_SUBSHELL: Bash Variables. (line 65) | |
8987 | * BASH_VERSINFO: Bash Variables. (line 69) | |
8988 | * BASH_VERSION: Bash Variables. (line 93) | |
e8ce775d | 8989 | * bell-style: Readline Init File Syntax. |
761783bf | 8990 | (line 34) |
e8ce775d | 8991 | * CDPATH: Bourne Shell Variables. |
761783bf CR |
8992 | (line 9) |
8993 | * COLUMNS: Bash Variables. (line 96) | |
e8ce775d | 8994 | * comment-begin: Readline Init File Syntax. |
761783bf CR |
8995 | (line 41) |
8996 | * COMP_CWORD: Bash Variables. (line 101) | |
8997 | * COMP_LINE: Bash Variables. (line 107) | |
8998 | * COMP_POINT: Bash Variables. (line 112) | |
8999 | * COMP_WORDBREAKS: Bash Variables. (line 120) | |
9000 | * COMP_WORDS: Bash Variables. (line 126) | |
e8ce775d | 9001 | * completion-query-items: Readline Init File Syntax. |
761783bf CR |
9002 | (line 51) |
9003 | * COMPREPLY: Bash Variables. (line 132) | |
e8ce775d | 9004 | * convert-meta: Readline Init File Syntax. |
761783bf CR |
9005 | (line 60) |
9006 | * DIRSTACK: Bash Variables. (line 137) | |
e8ce775d | 9007 | * disable-completion: Readline Init File Syntax. |
761783bf | 9008 | (line 66) |
e8ce775d | 9009 | * editing-mode: Readline Init File Syntax. |
761783bf CR |
9010 | (line 71) |
9011 | * EMACS: Bash Variables. (line 147) | |
e8ce775d | 9012 | * enable-keypad: Readline Init File Syntax. |
761783bf CR |
9013 | (line 77) |
9014 | * EUID: Bash Variables. (line 152) | |
e8ce775d | 9015 | * expand-tilde: Readline Init File Syntax. |
761783bf CR |
9016 | (line 82) |
9017 | * FCEDIT: Bash Variables. (line 156) | |
9018 | * FIGNORE: Bash Variables. (line 160) | |
9019 | * FUNCNAME: Bash Variables. (line 166) | |
9020 | * GLOBIGNORE: Bash Variables. (line 175) | |
9021 | * GROUPS: Bash Variables. (line 181) | |
9022 | * histchars: Bash Variables. (line 187) | |
9023 | * HISTCMD: Bash Variables. (line 202) | |
9024 | * HISTCONTROL: Bash Variables. (line 207) | |
9025 | * HISTFILE: Bash Variables. (line 223) | |
9026 | * HISTFILESIZE: Bash Variables. (line 227) | |
9027 | * HISTIGNORE: Bash Variables. (line 234) | |
f73dda09 | 9028 | * history-preserve-point: Readline Init File Syntax. |
761783bf CR |
9029 | (line 85) |
9030 | * HISTSIZE: Bash Variables. (line 253) | |
9031 | * HISTTIMEFORMAT: Bash Variables. (line 257) | |
e8ce775d | 9032 | * HOME: Bourne Shell Variables. |
761783bf | 9033 | (line 13) |
e8ce775d | 9034 | * horizontal-scroll-mode: Readline Init File Syntax. |
761783bf CR |
9035 | (line 90) |
9036 | * HOSTFILE: Bash Variables. (line 264) | |
9037 | * HOSTNAME: Bash Variables. (line 275) | |
9038 | * HOSTTYPE: Bash Variables. (line 278) | |
e8ce775d | 9039 | * IFS: Bourne Shell Variables. |
761783bf CR |
9040 | (line 18) |
9041 | * IGNOREEOF: Bash Variables. (line 281) | |
e8ce775d | 9042 | * input-meta: Readline Init File Syntax. |
761783bf CR |
9043 | (line 97) |
9044 | * INPUTRC: Bash Variables. (line 291) | |
b72432fd | 9045 | * isearch-terminators: Readline Init File Syntax. |
761783bf | 9046 | (line 104) |
e8ce775d | 9047 | * keymap: Readline Init File Syntax. |
761783bf CR |
9048 | (line 111) |
9049 | * LANG: Bash Variables. (line 295) | |
9050 | * LC_ALL: Bash Variables. (line 299) | |
9051 | * LC_COLLATE: Bash Variables. (line 303) | |
9052 | * LC_CTYPE: Bash Variables. (line 310) | |
9053 | * LC_MESSAGES <1>: Locale Translation. (line 11) | |
9054 | * LC_MESSAGES: Bash Variables. (line 315) | |
9055 | * LC_NUMERIC: Bash Variables. (line 319) | |
9056 | * LINENO: Bash Variables. (line 323) | |
9057 | * LINES: Bash Variables. (line 327) | |
9058 | * MACHTYPE: Bash Variables. (line 332) | |
e8ce775d | 9059 | * MAIL: Bourne Shell Variables. |
761783bf CR |
9060 | (line 22) |
9061 | * MAILCHECK: Bash Variables. (line 336) | |
e8ce775d | 9062 | * MAILPATH: Bourne Shell Variables. |
761783bf | 9063 | (line 27) |
e8ce775d | 9064 | * mark-modified-lines: Readline Init File Syntax. |
761783bf | 9065 | (line 124) |
7117c2d2 | 9066 | * mark-symlinked-directories: Readline Init File Syntax. |
761783bf | 9067 | (line 129) |
f73dda09 | 9068 | * match-hidden-files: Readline Init File Syntax. |
761783bf | 9069 | (line 134) |
e8ce775d | 9070 | * meta-flag: Readline Init File Syntax. |
761783bf CR |
9071 | (line 97) |
9072 | * OLDPWD: Bash Variables. (line 344) | |
e8ce775d | 9073 | * OPTARG: Bourne Shell Variables. |
761783bf CR |
9074 | (line 34) |
9075 | * OPTERR: Bash Variables. (line 347) | |
e8ce775d | 9076 | * OPTIND: Bourne Shell Variables. |
761783bf CR |
9077 | (line 38) |
9078 | * OSTYPE: Bash Variables. (line 351) | |
e8ce775d | 9079 | * output-meta: Readline Init File Syntax. |
761783bf | 9080 | (line 141) |
7117c2d2 | 9081 | * page-completions: Readline Init File Syntax. |
761783bf | 9082 | (line 146) |
e8ce775d | 9083 | * PATH: Bourne Shell Variables. |
761783bf CR |
9084 | (line 42) |
9085 | * PIPESTATUS: Bash Variables. (line 354) | |
9086 | * POSIXLY_CORRECT: Bash Variables. (line 359) | |
9087 | * PPID: Bash Variables. (line 368) | |
9088 | * PROMPT_COMMAND: Bash Variables. (line 372) | |
e8ce775d | 9089 | * PS1: Bourne Shell Variables. |
761783bf | 9090 | (line 48) |
e8ce775d | 9091 | * PS2: Bourne Shell Variables. |
761783bf CR |
9092 | (line 53) |
9093 | * PS3: Bash Variables. (line 376) | |
9094 | * PS4: Bash Variables. (line 381) | |
9095 | * PWD: Bash Variables. (line 387) | |
9096 | * RANDOM: Bash Variables. (line 390) | |
9097 | * REPLY: Bash Variables. (line 395) | |
9098 | * SECONDS: Bash Variables. (line 398) | |
9099 | * SHELL: Bash Variables. (line 404) | |
9100 | * SHELLOPTS: Bash Variables. (line 409) | |
9101 | * SHLVL: Bash Variables. (line 418) | |
e8ce775d | 9102 | * show-all-if-ambiguous: Readline Init File Syntax. |
761783bf | 9103 | (line 156) |
d3a24ed2 | 9104 | * show-all-if-unmodified: Readline Init File Syntax. |
761783bf CR |
9105 | (line 162) |
9106 | * TEXTDOMAIN: Locale Translation. (line 11) | |
9107 | * TEXTDOMAINDIR: Locale Translation. (line 11) | |
9108 | * TIMEFORMAT: Bash Variables. (line 423) | |
9109 | * TMOUT: Bash Variables. (line 461) | |
9110 | * UID: Bash Variables. (line 473) | |
e8ce775d | 9111 | * visible-stats: Readline Init File Syntax. |
761783bf | 9112 | (line 171) |
ccc6cda3 JA |
9113 | |
9114 | \1f | |
9115 | File: bashref.info, Node: Function Index, Next: Concept Index, Prev: Variable Index, Up: Top | |
9116 | ||
9117 | Function Index | |
9118 | ************** | |
9119 | ||
761783bf | 9120 | \0\b[index\0\b] |
ccc6cda3 JA |
9121 | * Menu: |
9122 | ||
e8ce775d | 9123 | * abort (C-g): Miscellaneous Commands. |
761783bf CR |
9124 | (line 10) |
9125 | * accept-line (Newline or Return): Commands For History. (line 6) | |
9126 | * backward-char (C-b): Commands For Moving. (line 15) | |
9127 | * backward-delete-char (Rubout): Commands For Text. (line 11) | |
9128 | * backward-kill-line (C-x Rubout): Commands For Killing. (line 9) | |
9129 | * backward-kill-word (M-<DEL>): Commands For Killing. (line 24) | |
9130 | * backward-word (M-b): Commands For Moving. (line 22) | |
9131 | * beginning-of-history (M-<): Commands For History. (line 20) | |
9132 | * beginning-of-line (C-a): Commands For Moving. (line 6) | |
9133 | * call-last-kbd-macro (C-x e): Keyboard Macros. (line 13) | |
9134 | * capitalize-word (M-c): Commands For Text. (line 46) | |
e8ce775d | 9135 | * character-search (C-]): Miscellaneous Commands. |
761783bf | 9136 | (line 41) |
e8ce775d | 9137 | * character-search-backward (M-C-]): Miscellaneous Commands. |
761783bf CR |
9138 | (line 46) |
9139 | * clear-screen (C-l): Commands For Moving. (line 26) | |
28ef6c31 | 9140 | * complete (<TAB>): Commands For Completion. |
761783bf CR |
9141 | (line 6) |
9142 | * copy-backward-word (): Commands For Killing. (line 49) | |
9143 | * copy-forward-word (): Commands For Killing. (line 54) | |
9144 | * copy-region-as-kill (): Commands For Killing. (line 45) | |
9145 | * delete-char (C-d): Commands For Text. (line 6) | |
b72432fd | 9146 | * delete-char-or-list (): Commands For Completion. |
761783bf CR |
9147 | (line 34) |
9148 | * delete-horizontal-space (): Commands For Killing. (line 37) | |
9149 | * digit-argument (M-0, M-1, ... M--): Numeric Arguments. (line 6) | |
ccc6cda3 | 9150 | * do-uppercase-version (M-a, M-b, M-X, ...): Miscellaneous Commands. |
761783bf CR |
9151 | (line 14) |
9152 | * downcase-word (M-l): Commands For Text. (line 42) | |
e8ce775d | 9153 | * dump-functions (): Miscellaneous Commands. |
761783bf | 9154 | (line 64) |
e8ce775d | 9155 | * dump-macros (): Miscellaneous Commands. |
761783bf | 9156 | (line 76) |
e8ce775d | 9157 | * dump-variables (): Miscellaneous Commands. |
761783bf CR |
9158 | (line 70) |
9159 | * end-kbd-macro (C-x )): Keyboard Macros. (line 9) | |
9160 | * end-of-history (M->): Commands For History. (line 23) | |
9161 | * end-of-line (C-e): Commands For Moving. (line 9) | |
e8ce775d | 9162 | * exchange-point-and-mark (C-x C-x): Miscellaneous Commands. |
761783bf CR |
9163 | (line 36) |
9164 | * forward-backward-delete-char (): Commands For Text. (line 15) | |
9165 | * forward-char (C-f): Commands For Moving. (line 12) | |
9166 | * forward-search-history (C-s): Commands For History. (line 31) | |
9167 | * forward-word (M-f): Commands For Moving. (line 18) | |
9168 | * history-search-backward (): Commands For History. (line 51) | |
9169 | * history-search-forward (): Commands For History. (line 46) | |
e8ce775d | 9170 | * insert-comment (M-#): Miscellaneous Commands. |
761783bf | 9171 | (line 51) |
e8ce775d | 9172 | * insert-completions (M-*): Commands For Completion. |
761783bf CR |
9173 | (line 18) |
9174 | * kill-line (C-k): Commands For Killing. (line 6) | |
9175 | * kill-region (): Commands For Killing. (line 41) | |
9176 | * kill-whole-line (): Commands For Killing. (line 15) | |
9177 | * kill-word (M-d): Commands For Killing. (line 19) | |
cce855bc | 9178 | * menu-complete (): Commands For Completion. |
761783bf CR |
9179 | (line 22) |
9180 | * next-history (C-n): Commands For History. (line 17) | |
ccc6cda3 | 9181 | * non-incremental-forward-search-history (M-n): Commands For History. |
761783bf | 9182 | (line 41) |
ccc6cda3 | 9183 | * non-incremental-reverse-search-history (M-p): Commands For History. |
761783bf CR |
9184 | (line 36) |
9185 | * overwrite-mode (): Commands For Text. (line 50) | |
e8ce775d | 9186 | * possible-completions (M-?): Commands For Completion. |
761783bf | 9187 | (line 15) |
28ef6c31 | 9188 | * prefix-meta (<ESC>): Miscellaneous Commands. |
761783bf CR |
9189 | (line 18) |
9190 | * previous-history (C-p): Commands For History. (line 13) | |
9191 | * quoted-insert (C-q or C-v): Commands For Text. (line 20) | |
e8ce775d | 9192 | * re-read-init-file (C-x C-r): Miscellaneous Commands. |
761783bf CR |
9193 | (line 6) |
9194 | * redraw-current-line (): Commands For Moving. (line 30) | |
9195 | * reverse-search-history (C-r): Commands For History. (line 27) | |
e8ce775d | 9196 | * revert-line (M-r): Miscellaneous Commands. |
761783bf CR |
9197 | (line 25) |
9198 | * self-insert (a, b, A, 1, !, ...): Commands For Text. (line 24) | |
e8ce775d | 9199 | * set-mark (C-@): Miscellaneous Commands. |
761783bf CR |
9200 | (line 32) |
9201 | * start-kbd-macro (C-x (): Keyboard Macros. (line 6) | |
9202 | * transpose-chars (C-t): Commands For Text. (line 27) | |
9203 | * transpose-words (M-t): Commands For Text. (line 33) | |
28ef6c31 | 9204 | * undo (C-_ or C-x C-u): Miscellaneous Commands. |
761783bf CR |
9205 | (line 22) |
9206 | * universal-argument (): Numeric Arguments. (line 10) | |
9207 | * unix-filename-rubout (): Commands For Killing. (line 32) | |
9208 | * unix-line-discard (C-u): Commands For Killing. (line 12) | |
9209 | * unix-word-rubout (C-w): Commands For Killing. (line 28) | |
9210 | * upcase-word (M-u): Commands For Text. (line 38) | |
9211 | * yank (C-y): Commands For Killing. (line 59) | |
9212 | * yank-last-arg (M-. or M-_): Commands For History. (line 63) | |
9213 | * yank-nth-arg (M-C-y): Commands For History. (line 56) | |
9214 | * yank-pop (M-y): Commands For Killing. (line 62) | |
ccc6cda3 JA |
9215 | |
9216 | \1f | |
9217 | File: bashref.info, Node: Concept Index, Prev: Function Index, Up: Top | |
9218 | ||
9219 | Concept Index | |
9220 | ************* | |
9221 | ||
761783bf | 9222 | \0\b[index\0\b] |
ccc6cda3 JA |
9223 | * Menu: |
9224 | ||
761783bf CR |
9225 | * alias expansion: Aliases. (line 6) |
9226 | * arithmetic evaluation: Shell Arithmetic. (line 6) | |
e8ce775d | 9227 | * arithmetic expansion: Arithmetic Expansion. |
761783bf CR |
9228 | (line 6) |
9229 | * arithmetic, shell: Shell Arithmetic. (line 6) | |
9230 | * arrays: Arrays. (line 6) | |
9231 | * background: Job Control Basics. (line 6) | |
9232 | * Bash configuration: Basic Installation. (line 6) | |
9233 | * Bash installation: Basic Installation. (line 6) | |
e8ce775d | 9234 | * Bourne shell: Basic Shell Features. |
761783bf CR |
9235 | (line 6) |
9236 | * brace expansion: Brace Expansion. (line 6) | |
9237 | * builtin: Definitions. (line 16) | |
e8ce775d | 9238 | * command editing: Readline Bare Essentials. |
761783bf | 9239 | (line 6) |
e8ce775d | 9240 | * command execution: Command Search and Execution. |
761783bf | 9241 | (line 6) |
cce855bc | 9242 | * command expansion: Simple Command Expansion. |
761783bf | 9243 | (line 6) |
e8ce775d | 9244 | * command history: Bash History Facilities. |
761783bf | 9245 | (line 6) |
e8ce775d | 9246 | * command search: Command Search and Execution. |
761783bf | 9247 | (line 6) |
e8ce775d | 9248 | * command substitution: Command Substitution. |
761783bf CR |
9249 | (line 6) |
9250 | * command timing: Pipelines. (line 8) | |
9251 | * commands, compound: Compound Commands. (line 6) | |
e8ce775d | 9252 | * commands, conditional: Conditional Constructs. |
761783bf CR |
9253 | (line 6) |
9254 | * commands, grouping: Command Grouping. (line 6) | |
9255 | * commands, lists: Lists. (line 6) | |
9256 | * commands, looping: Looping Constructs. (line 6) | |
9257 | * commands, pipelines: Pipelines. (line 6) | |
9258 | * commands, shell: Shell Commands. (line 6) | |
9259 | * commands, simple: Simple Commands. (line 6) | |
9260 | * comments, shell: Comments. (line 6) | |
bb70624e | 9261 | * completion builtins: Programmable Completion Builtins. |
761783bf CR |
9262 | (line 6) |
9263 | * configuration: Basic Installation. (line 6) | |
9264 | * control operator: Definitions. (line 20) | |
9265 | * directory stack: The Directory Stack. (line 6) | |
e8ce775d | 9266 | * editing command lines: Readline Bare Essentials. |
761783bf CR |
9267 | (line 6) |
9268 | * environment: Environment. (line 6) | |
9269 | * evaluation, arithmetic: Shell Arithmetic. (line 6) | |
9270 | * event designators: Event Designators. (line 6) | |
cce855bc | 9271 | * execution environment: Command Execution Environment. |
761783bf CR |
9272 | (line 6) |
9273 | * exit status <1>: Exit Status. (line 6) | |
9274 | * exit status: Definitions. (line 24) | |
9275 | * expansion: Shell Expansions. (line 6) | |
e8ce775d | 9276 | * expansion, arithmetic: Arithmetic Expansion. |
761783bf CR |
9277 | (line 6) |
9278 | * expansion, brace: Brace Expansion. (line 6) | |
9279 | * expansion, filename: Filename Expansion. (line 9) | |
e8ce775d | 9280 | * expansion, parameter: Shell Parameter Expansion. |
761783bf CR |
9281 | (line 6) |
9282 | * expansion, pathname: Filename Expansion. (line 9) | |
9283 | * expansion, tilde: Tilde Expansion. (line 6) | |
9284 | * expressions, arithmetic: Shell Arithmetic. (line 6) | |
e8ce775d | 9285 | * expressions, conditional: Bash Conditional Expressions. |
761783bf | 9286 | (line 6) |
d3a24ed2 | 9287 | * FDL, GNU Free Documentation License: GNU Free Documentation License. |
761783bf CR |
9288 | (line 6) |
9289 | * field: Definitions. (line 28) | |
9290 | * filename: Definitions. (line 33) | |
9291 | * filename expansion: Filename Expansion. (line 9) | |
9292 | * foreground: Job Control Basics. (line 6) | |
9293 | * functions, shell: Shell Functions. (line 6) | |
cce855bc | 9294 | * history builtins: Bash History Builtins. |
761783bf CR |
9295 | (line 6) |
9296 | * history events: Event Designators. (line 7) | |
9297 | * history expansion: History Interaction. (line 6) | |
e8ce775d | 9298 | * history list: Bash History Facilities. |
761783bf | 9299 | (line 6) |
bb70624e | 9300 | * History, how to use: Programmable Completion Builtins. |
761783bf CR |
9301 | (line 203) |
9302 | * identifier: Definitions. (line 49) | |
9303 | * initialization file, readline: Readline Init File. (line 6) | |
9304 | * installation: Basic Installation. (line 6) | |
e8ce775d | 9305 | * interaction, readline: Readline Interaction. |
761783bf CR |
9306 | (line 6) |
9307 | * interactive shell <1>: Interactive Shells. (line 6) | |
9308 | * interactive shell: Invoking Bash. (line 128) | |
9309 | * internationalization: Locale Translation. (line 6) | |
9310 | * job: Definitions. (line 36) | |
9311 | * job control <1>: Definitions. (line 40) | |
9312 | * job control: Job Control Basics. (line 6) | |
e8ce775d | 9313 | * kill ring: Readline Killing Commands. |
761783bf | 9314 | (line 19) |
e8ce775d | 9315 | * killing text: Readline Killing Commands. |
761783bf CR |
9316 | (line 6) |
9317 | * localization: Locale Translation. (line 6) | |
9318 | * login shell: Invoking Bash. (line 125) | |
9319 | * matching, pattern: Pattern Matching. (line 6) | |
9320 | * metacharacter: Definitions. (line 44) | |
9321 | * name: Definitions. (line 49) | |
9322 | * native languages: Locale Translation. (line 6) | |
e8ce775d | 9323 | * notation, readline: Readline Bare Essentials. |
761783bf CR |
9324 | (line 6) |
9325 | * operator, shell: Definitions. (line 55) | |
e8ce775d | 9326 | * parameter expansion: Shell Parameter Expansion. |
761783bf CR |
9327 | (line 6) |
9328 | * parameters: Shell Parameters. (line 6) | |
e8ce775d | 9329 | * parameters, positional: Positional Parameters. |
761783bf CR |
9330 | (line 6) |
9331 | * parameters, special: Special Parameters. (line 6) | |
9332 | * pathname expansion: Filename Expansion. (line 9) | |
9333 | * pattern matching: Pattern Matching. (line 6) | |
9334 | * pipeline: Pipelines. (line 6) | |
9335 | * POSIX: Definitions. (line 9) | |
9336 | * POSIX Mode: Bash POSIX Mode. (line 6) | |
9337 | * process group: Definitions. (line 59) | |
9338 | * process group ID: Definitions. (line 63) | |
e8ce775d | 9339 | * process substitution: Process Substitution. |
761783bf | 9340 | (line 6) |
bb70624e | 9341 | * programmable completion: Programmable Completion. |
761783bf CR |
9342 | (line 6) |
9343 | * prompting: Printing a Prompt. (line 6) | |
9344 | * quoting: Quoting. (line 6) | |
9345 | * quoting, ANSI: ANSI-C Quoting. (line 6) | |
bb70624e | 9346 | * Readline, how to use: Job Control Variables. |
761783bf CR |
9347 | (line 24) |
9348 | * redirection: Redirections. (line 6) | |
9349 | * reserved word: Definitions. (line 67) | |
e8ce775d | 9350 | * restricted shell: The Restricted Shell. |
761783bf CR |
9351 | (line 6) |
9352 | * return status: Definitions. (line 72) | |
9353 | * shell arithmetic: Shell Arithmetic. (line 6) | |
9354 | * shell function: Shell Functions. (line 6) | |
9355 | * shell script: Shell Scripts. (line 6) | |
9356 | * shell variable: Shell Parameters. (line 6) | |
9357 | * shell, interactive: Interactive Shells. (line 6) | |
9358 | * signal: Definitions. (line 75) | |
9359 | * signal handling: Signals. (line 6) | |
9360 | * special builtin <1>: Definitions. (line 79) | |
9361 | * special builtin: Special Builtins. (line 6) | |
9362 | * startup files: Bash Startup Files. (line 6) | |
9363 | * suspending jobs: Job Control Basics. (line 6) | |
9364 | * tilde expansion: Tilde Expansion. (line 6) | |
9365 | * token: Definitions. (line 83) | |
9366 | * translation, native languages: Locale Translation. (line 6) | |
9367 | * variable, shell: Shell Parameters. (line 6) | |
28ef6c31 | 9368 | * variables, readline: Readline Init File Syntax. |
761783bf CR |
9369 | (line 33) |
9370 | * word: Definitions. (line 87) | |
9371 | * word splitting: Word Splitting. (line 6) | |
e8ce775d | 9372 | * yanking text: Readline Killing Commands. |
761783bf | 9373 | (line 6) |
ccc6cda3 JA |
9374 | |
9375 | ||
9376 | \1f | |
9377 | Tag Table: | |
761783bf CR |
9378 | Node: Top\7f1349 |
9379 | Node: Introduction\7f3485 | |
9380 | Node: What is Bash?\7f3714 | |
9381 | Node: What is a shell?\7f4807 | |
9382 | Node: Definitions\7f7348 | |
9383 | Node: Basic Shell Features\7f10089 | |
9384 | Node: Shell Syntax\7f11308 | |
9385 | Node: Shell Operation\7f12340 | |
9386 | Node: Quoting\7f13634 | |
9387 | Node: Escape Character\7f14908 | |
9388 | Node: Single Quotes\7f15393 | |
9389 | Node: Double Quotes\7f15741 | |
9390 | Node: ANSI-C Quoting\7f16767 | |
9391 | Node: Locale Translation\7f17723 | |
9392 | Node: Comments\7f18619 | |
9393 | Node: Shell Commands\7f19233 | |
9394 | Node: Simple Commands\7f19999 | |
9395 | Node: Pipelines\7f20630 | |
9396 | Node: Lists\7f22505 | |
9397 | Node: Compound Commands\7f24136 | |
9398 | Node: Looping Constructs\7f24920 | |
9399 | Node: Conditional Constructs\7f27367 | |
9400 | Node: Command Grouping\7f34434 | |
9401 | Node: Shell Functions\7f35883 | |
9402 | Node: Shell Parameters\7f40151 | |
9403 | Node: Positional Parameters\7f41732 | |
9404 | Node: Special Parameters\7f42632 | |
9405 | Node: Shell Expansions\7f45299 | |
9406 | Node: Brace Expansion\7f47224 | |
9407 | Node: Tilde Expansion\7f49549 | |
9408 | Node: Shell Parameter Expansion\7f51890 | |
9409 | Node: Command Substitution\7f59153 | |
9410 | Node: Arithmetic Expansion\7f60486 | |
9411 | Node: Process Substitution\7f61336 | |
9412 | Node: Word Splitting\7f62386 | |
9413 | Node: Filename Expansion\7f63847 | |
9414 | Node: Pattern Matching\7f65983 | |
9415 | Node: Quote Removal\7f69316 | |
9416 | Node: Redirections\7f69611 | |
9417 | Node: Executing Commands\7f77190 | |
9418 | Node: Simple Command Expansion\7f77865 | |
9419 | Node: Command Search and Execution\7f79795 | |
9420 | Node: Command Execution Environment\7f81801 | |
9421 | Node: Environment\7f84572 | |
9422 | Node: Exit Status\7f86232 | |
9423 | Node: Signals\7f87436 | |
9424 | Node: Shell Scripts\7f89400 | |
9425 | Node: Shell Builtin Commands\7f91918 | |
9426 | Node: Bourne Shell Builtins\7f93497 | |
9427 | Node: Bash Builtins\7f110450 | |
9428 | Node: The Set Builtin\7f138577 | |
9429 | Node: Special Builtins\7f146800 | |
9430 | Node: Shell Variables\7f147777 | |
9431 | Node: Bourne Shell Variables\7f148217 | |
9432 | Node: Bash Variables\7f150198 | |
9433 | Node: Bash Features\7f169913 | |
9434 | Node: Invoking Bash\7f170796 | |
9435 | Node: Bash Startup Files\7f176615 | |
9436 | Node: Interactive Shells\7f181473 | |
9437 | Node: What is an Interactive Shell?\7f181883 | |
9438 | Node: Is this Shell Interactive?\7f182533 | |
9439 | Node: Interactive Shell Behavior\7f183348 | |
9440 | Node: Bash Conditional Expressions\7f186624 | |
9441 | Node: Shell Arithmetic\7f190049 | |
9442 | Node: Aliases\7f192794 | |
9443 | Node: Arrays\7f195362 | |
9444 | Node: The Directory Stack\7f198393 | |
9445 | Node: Directory Stack Builtins\7f199107 | |
9446 | Node: Printing a Prompt\7f201998 | |
9447 | Node: The Restricted Shell\7f204712 | |
9448 | Node: Bash POSIX Mode\7f206544 | |
9449 | Node: Job Control\7f213197 | |
9450 | Node: Job Control Basics\7f213664 | |
9451 | Node: Job Control Builtins\7f217954 | |
9452 | Node: Job Control Variables\7f222274 | |
9453 | Node: Command Line Editing\7f223432 | |
9454 | Node: Introduction and Notation\7f224431 | |
9455 | Node: Readline Interaction\7f226053 | |
9456 | Node: Readline Bare Essentials\7f227244 | |
9457 | Node: Readline Movement Commands\7f229033 | |
9458 | Node: Readline Killing Commands\7f229998 | |
9459 | Node: Readline Arguments\7f231918 | |
9460 | Node: Searching\7f232962 | |
9461 | Node: Readline Init File\7f235148 | |
9462 | Node: Readline Init File Syntax\7f236207 | |
9463 | Node: Conditional Init Constructs\7f247860 | |
9464 | Node: Sample Init File\7f250393 | |
9465 | Node: Bindable Readline Commands\7f253510 | |
9466 | Node: Commands For Moving\7f254717 | |
9467 | Node: Commands For History\7f255578 | |
9468 | Node: Commands For Text\7f258479 | |
9469 | Node: Commands For Killing\7f261152 | |
9470 | Node: Numeric Arguments\7f263294 | |
9471 | Node: Commands For Completion\7f264433 | |
9472 | Node: Keyboard Macros\7f268026 | |
9473 | Node: Miscellaneous Commands\7f268597 | |
9474 | Node: Readline vi Mode\7f273908 | |
9475 | Node: Programmable Completion\7f274822 | |
9476 | Node: Programmable Completion Builtins\7f280634 | |
9477 | Node: Using History Interactively\7f288004 | |
9478 | Node: Bash History Facilities\7f288684 | |
9479 | Node: Bash History Builtins\7f291379 | |
9480 | Node: History Interaction\7f295236 | |
9481 | Node: Event Designators\7f297792 | |
9482 | Node: Word Designators\7f298807 | |
9483 | Node: Modifiers\7f300446 | |
9484 | Node: Installing Bash\7f301852 | |
9485 | Node: Basic Installation\7f302989 | |
9486 | Node: Compilers and Options\7f305681 | |
9487 | Node: Compiling For Multiple Architectures\7f306422 | |
9488 | Node: Installation Names\7f308086 | |
9489 | Node: Specifying the System Type\7f308904 | |
9490 | Node: Sharing Defaults\7f309620 | |
9491 | Node: Operation Controls\7f310293 | |
9492 | Node: Optional Features\7f311251 | |
9493 | Node: Reporting Bugs\7f319530 | |
9494 | Node: Major Differences From The Bourne Shell\7f320724 | |
9495 | Node: Copying This Manual\7f336496 | |
9496 | Node: GNU Free Documentation License\7f336772 | |
9497 | Node: Builtin Index\7f359178 | |
9498 | Node: Reserved Word Index\7f365727 | |
9499 | Node: Variable Index\7f368163 | |
9500 | Node: Function Index\7f378882 | |
9501 | Node: Concept Index\7f385602 | |
ccc6cda3 JA |
9502 | \1f |
9503 | End Tag Table |