]>
Commit | Line | Data |
---|---|---|
db31fb26 | 1 | This is bashref.info, produced by makeinfo version 4.13 from |
a9fac3b2 | 2 | /Users/chet/src/bash/src/doc/bashref.texi. |
e8ce775d | 3 | |
6a8fd0ed | 4 | This text is a brief description of the features that are present in |
2c471a92 | 5 | the Bash shell (version 4.0, 17 June 2009). |
d3a24ed2 | 6 | |
2c471a92 | 7 | This is Edition 4.0, last updated 17 June 2009, of `The GNU Bash |
ed35cb4a | 8 | Reference Manual', for `Bash', Version 4.0. |
d3a24ed2 | 9 | |
db31fb26 | 10 | Copyright (C) 1988-2009 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, | |
c302751c | 18 | Version 1.3 or any later version published by the Free Software |
d3a24ed2 | 19 | Foundation; with no Invariant Sections, with the Front-Cover texts |
c2a47ea9 | 20 | being "A GNU Manual", and with the Back-Cover Texts as in (a) |
d3a24ed2 | 21 | below. A copy of the license is included in the section entitled |
c2a47ea9 | 22 | "GNU Free Documentation License". |
d3a24ed2 | 23 | |
a9fac3b2 CR |
24 | (a) The FSF's Back-Cover Text is: You are free to copy and modify |
25 | this GNU manual. Buying copies from GNU Press supports the FSF in | |
26 | developing GNU and promoting software freedom." | |
29d25b54 | 27 | |
37c41ab1 | 28 | |
d3a24ed2 | 29 | INFO-DIR-SECTION Basics |
e8ce775d | 30 | START-INFO-DIR-ENTRY |
cce855bc | 31 | * Bash: (bash). The GNU Bourne-Again SHell. |
e8ce775d | 32 | END-INFO-DIR-ENTRY |
ccc6cda3 | 33 | |
ccc6cda3 JA |
34 | \1f |
35 | File: bashref.info, Node: Top, Next: Introduction, Prev: (dir), Up: (dir) | |
36 | ||
37 | Bash Features | |
38 | ************* | |
39 | ||
37c41ab1 | 40 | This text is a brief description of the features that are present in |
2c471a92 | 41 | the Bash shell (version 4.0, 17 June 2009). |
ccc6cda3 | 42 | |
2c471a92 | 43 | This is Edition 4.0, last updated 17 June 2009, of `The GNU Bash |
ed35cb4a | 44 | Reference Manual', for `Bash', Version 4.0. |
ccc6cda3 JA |
45 | |
46 | Bash contains features that appear in other popular shells, and some | |
47 | features that only appear in Bash. Some of the shells that Bash has | |
48 | borrowed concepts from are the Bourne Shell (`sh'), the Korn Shell | |
49 | (`ksh'), and the C-shell (`csh' and its successor, `tcsh'). The | |
50 | following menu breaks the features up into categories based upon which | |
51 | one of these other shells inspired the feature. | |
52 | ||
53 | This manual is meant as a brief introduction to features found in | |
54 | Bash. The Bash manual page should be used as the definitive reference | |
55 | on shell behavior. | |
56 | ||
57 | * Menu: | |
58 | ||
59 | * Introduction:: An introduction to the shell. | |
ccc6cda3 JA |
60 | * Definitions:: Some definitions used in the rest of this |
61 | manual. | |
ccc6cda3 | 62 | * Basic Shell Features:: The shell "building blocks". |
bb70624e | 63 | * Shell Builtin Commands:: Commands that are a part of the shell. |
bb70624e | 64 | * Shell Variables:: Variables used or set by Bash. |
ccc6cda3 | 65 | * Bash Features:: Features found only in Bash. |
1c72c0cd CR |
66 | * Job Control:: What job control is and how Bash allows you |
67 | to use it. | |
ccc6cda3 JA |
68 | * Command Line Editing:: Chapter describing the command line |
69 | editing features. | |
c2a47ea9 | 70 | * Using History Interactively:: Command History Expansion |
ccc6cda3 | 71 | * Installing Bash:: How to build and install Bash on your system. |
ccc6cda3 | 72 | * Reporting Bugs:: How to report bugs in Bash. |
bb70624e JA |
73 | * Major Differences From The Bourne Shell:: A terse list of the differences |
74 | between Bash and historical | |
75 | versions of /bin/sh. | |
c2a47ea9 | 76 | * GNU Free Documentation License:: Copying and sharing this documentation. |
d3ad40de | 77 | * Indexes:: Various indexes for this manual. |
ccc6cda3 JA |
78 | |
79 | \1f | |
80 | File: bashref.info, Node: Introduction, Next: Definitions, Prev: Top, Up: Top | |
81 | ||
37c41ab1 CR |
82 | 1 Introduction |
83 | ************** | |
ccc6cda3 JA |
84 | |
85 | * Menu: | |
86 | ||
87 | * What is Bash?:: A short description of Bash. | |
ccc6cda3 JA |
88 | * What is a shell?:: A brief introduction to shells. |
89 | ||
90 | \1f | |
91 | File: bashref.info, Node: What is Bash?, Next: What is a shell?, Up: Introduction | |
92 | ||
37c41ab1 CR |
93 | 1.1 What is Bash? |
94 | ================= | |
ccc6cda3 | 95 | |
37c41ab1 | 96 | Bash is the shell, or command language interpreter, for the GNU |
bb70624e JA |
97 | operating system. The name is an acronym for the `Bourne-Again SHell', |
98 | a pun on Stephen Bourne, the author of the direct ancestor of the | |
d3a24ed2 CR |
99 | current Unix shell `sh', which appeared in the Seventh Edition Bell |
100 | Labs Research version of Unix. | |
ccc6cda3 | 101 | |
bb70624e JA |
102 | Bash is largely compatible with `sh' and incorporates useful |
103 | features from the Korn shell `ksh' and the C shell `csh'. It is | |
104 | intended to be a conformant implementation of the IEEE POSIX Shell and | |
ac18b312 CR |
105 | Tools portion of the IEEE POSIX specification (IEEE Standard 1003.1). |
106 | It offers functional improvements over `sh' for both interactive and | |
107 | programming use. | |
ccc6cda3 | 108 | |
bb70624e JA |
109 | While the GNU operating system provides other shells, including a |
110 | version of `csh', Bash is the default shell. Like other GNU software, | |
111 | Bash is quite portable. It currently runs on nearly every version of | |
112 | Unix and a few other operating systems - independently-supported ports | |
d3a24ed2 | 113 | exist for MS-DOS, OS/2, and Windows platforms. |
ccc6cda3 JA |
114 | |
115 | \1f | |
116 | File: bashref.info, Node: What is a shell?, Prev: What is Bash?, Up: Introduction | |
117 | ||
37c41ab1 CR |
118 | 1.2 What is a shell? |
119 | ==================== | |
ccc6cda3 | 120 | |
37c41ab1 | 121 | At its base, a shell is simply a macro processor that executes |
d3a24ed2 CR |
122 | commands. The term macro processor means functionality where text and |
123 | symbols are expanded to create larger expressions. | |
124 | ||
125 | A Unix shell is both a command interpreter and a programming | |
126 | language. As a command interpreter, the shell provides the user | |
127 | interface to the rich set of GNU utilities. The programming language | |
d3ad40de | 128 | features allow these utilities to be combined. Files containing |
cce855bc | 129 | commands can be created, and become commands themselves. These new |
bb70624e | 130 | commands have the same status as system commands in directories such as |
d3a24ed2 CR |
131 | `/bin', allowing users or groups to establish custom environments to |
132 | automate their common tasks. | |
133 | ||
134 | Shells may be used interactively or non-interactively. In | |
135 | interactive mode, they accept input typed from the keyboard. When | |
136 | executing non-interactively, shells execute commands read from a file. | |
ccc6cda3 | 137 | |
bb70624e | 138 | A shell allows execution of GNU commands, both synchronously and |
cce855bc JA |
139 | asynchronously. The shell waits for synchronous commands to complete |
140 | before accepting more input; asynchronous commands continue to execute | |
141 | in parallel with the shell while it reads and executes additional | |
142 | commands. The "redirection" constructs permit fine-grained control of | |
bb70624e | 143 | the input and output of those commands. Moreover, the shell allows |
d3a24ed2 | 144 | control over the contents of commands' environments. |
bb70624e JA |
145 | |
146 | Shells also provide a small set of built-in commands ("builtins") | |
147 | implementing functionality impossible or inconvenient to obtain via | |
148 | separate utilities. For example, `cd', `break', `continue', and | |
149 | `exec') cannot be implemented outside of the shell because they | |
150 | directly manipulate the shell itself. The `history', `getopts', | |
151 | `kill', or `pwd' builtins, among others, could be implemented in | |
152 | separate utilities, but they are more convenient to use as builtin | |
153 | commands. All of the shell builtins are described in subsequent | |
154 | sections. | |
ccc6cda3 JA |
155 | |
156 | While executing commands is essential, most of the power (and | |
157 | complexity) of shells is due to their embedded programming languages. | |
158 | Like any high-level language, the shell provides variables, flow | |
159 | control constructs, quoting, and functions. | |
160 | ||
bb70624e JA |
161 | Shells offer features geared specifically for interactive use rather |
162 | than to augment the programming language. These interactive features | |
d3a24ed2 CR |
163 | include job control, command line editing, command history and aliases. |
164 | Each of these features is described in this manual. | |
ccc6cda3 JA |
165 | |
166 | \1f | |
167 | File: bashref.info, Node: Definitions, Next: Basic Shell Features, Prev: Introduction, Up: Top | |
168 | ||
37c41ab1 CR |
169 | 2 Definitions |
170 | ************* | |
ccc6cda3 | 171 | |
37c41ab1 | 172 | These definitions are used throughout the remainder of this manual. |
ccc6cda3 JA |
173 | |
174 | `POSIX' | |
175 | A family of open system standards based on Unix. Bash is | |
ac18b312 CR |
176 | primarily concerned with the Shell and Utilities portion of the |
177 | POSIX 1003.1 standard. | |
ccc6cda3 JA |
178 | |
179 | `blank' | |
180 | A space or tab character. | |
181 | ||
182 | `builtin' | |
183 | A command that is implemented internally by the shell itself, | |
184 | rather than by an executable program somewhere in the file system. | |
185 | ||
186 | `control operator' | |
3d4e09aa | 187 | A `token' that performs a control function. It is a `newline' or |
ed35cb4a CR |
188 | one of the following: `||', `&&', `&', `;', `;;', `|', `|&', `(', |
189 | or `)'. | |
ccc6cda3 JA |
190 | |
191 | `exit status' | |
f73dda09 JA |
192 | The value returned by a command to its caller. The value is |
193 | restricted to eight bits, so the maximum value is 255. | |
ccc6cda3 JA |
194 | |
195 | `field' | |
196 | A unit of text that is the result of one of the shell expansions. | |
197 | After expansion, when executing a command, the resulting fields | |
198 | are used as the command name and arguments. | |
199 | ||
200 | `filename' | |
201 | A string of characters used to identify a file. | |
202 | ||
203 | `job' | |
204 | A set of processes comprising a pipeline, and any processes | |
205 | descended from it, that are all in the same process group. | |
206 | ||
207 | `job control' | |
d166f048 JA |
208 | A mechanism by which users can selectively stop (suspend) and |
209 | restart (resume) execution of processes. | |
ccc6cda3 JA |
210 | |
211 | `metacharacter' | |
212 | A character that, when unquoted, separates words. A metacharacter | |
213 | is a `blank' or one of the following characters: `|', `&', `;', | |
214 | `(', `)', `<', or `>'. | |
215 | ||
216 | `name' | |
217 | A `word' consisting solely of letters, numbers, and underscores, | |
218 | and beginning with a letter or underscore. `Name's are used as | |
219 | shell variable and function names. Also referred to as an | |
220 | `identifier'. | |
221 | ||
222 | `operator' | |
223 | A `control operator' or a `redirection operator'. *Note | |
a9fac3b2 CR |
224 | Redirections::, for a list of redirection operators. Operators |
225 | contain at least one unquoted `metacharacter'. | |
ccc6cda3 JA |
226 | |
227 | `process group' | |
228 | A collection of related processes each having the same process | |
229 | group ID. | |
230 | ||
231 | `process group ID' | |
d3ad40de | 232 | A unique identifier that represents a `process group' during its |
ccc6cda3 JA |
233 | lifetime. |
234 | ||
235 | `reserved word' | |
236 | A `word' that has a special meaning to the shell. Most reserved | |
237 | words introduce shell flow control constructs, such as `for' and | |
238 | `while'. | |
239 | ||
240 | `return status' | |
241 | A synonym for `exit status'. | |
242 | ||
243 | `signal' | |
bb70624e | 244 | A mechanism by which a process may be notified by the kernel of an |
ccc6cda3 JA |
245 | event occurring in the system. |
246 | ||
247 | `special builtin' | |
248 | A shell builtin command that has been classified as special by the | |
ac18b312 | 249 | POSIX standard. |
ccc6cda3 JA |
250 | |
251 | `token' | |
252 | A sequence of characters considered a single unit by the shell. | |
253 | It is either a `word' or an `operator'. | |
254 | ||
255 | `word' | |
a9fac3b2 CR |
256 | A sequence of characters treated as a unit by the shell. Words |
257 | may not include unquoted `metacharacters'. | |
ccc6cda3 JA |
258 | |
259 | \1f | |
bb70624e | 260 | File: bashref.info, Node: Basic Shell Features, Next: Shell Builtin Commands, Prev: Definitions, Up: Top |
ccc6cda3 | 261 | |
37c41ab1 CR |
262 | 3 Basic Shell Features |
263 | ********************** | |
ccc6cda3 | 264 | |
37c41ab1 CR |
265 | Bash is an acronym for `Bourne-Again SHell'. The Bourne shell is the |
266 | traditional Unix shell originally written by Stephen Bourne. All of | |
267 | the Bourne shell builtin commands are available in Bash, The rules for | |
268 | evaluation and quoting are taken from the POSIX specification for the | |
269 | `standard' Unix shell. | |
ccc6cda3 | 270 | |
cce855bc | 271 | This chapter briefly summarizes the shell's `building blocks': |
ccc6cda3 JA |
272 | commands, control structures, shell functions, shell parameters, shell |
273 | expansions, redirections, which are a way to direct input and output | |
274 | from and to named files, and how the shell executes commands. | |
275 | ||
276 | * Menu: | |
277 | ||
278 | * Shell Syntax:: What your input means to the shell. | |
cce855bc | 279 | * Shell Commands:: The types of commands you can use. |
ccc6cda3 | 280 | * Shell Functions:: Grouping commands by name. |
d3a24ed2 CR |
281 | * Shell Parameters:: How the shell stores values. |
282 | * Shell Expansions:: How Bash expands parameters and the various | |
ccc6cda3 JA |
283 | expansions available. |
284 | * Redirections:: A way to control where input and output go. | |
285 | * Executing Commands:: What happens when you run a command. | |
286 | * Shell Scripts:: Executing files of shell commands. | |
287 | ||
288 | \1f | |
cce855bc | 289 | File: bashref.info, Node: Shell Syntax, Next: Shell Commands, Up: Basic Shell Features |
ccc6cda3 | 290 | |
37c41ab1 CR |
291 | 3.1 Shell Syntax |
292 | ================ | |
ccc6cda3 JA |
293 | |
294 | * Menu: | |
295 | ||
296 | * Shell Operation:: The basic operation of the shell. | |
ccc6cda3 | 297 | * Quoting:: How to remove the special meaning from characters. |
ccc6cda3 JA |
298 | * Comments:: How to specify comments. |
299 | ||
bb70624e JA |
300 | When the shell reads input, it proceeds through a sequence of |
301 | operations. If the input indicates the beginning of a comment, the | |
302 | shell ignores the comment symbol (`#'), and the rest of that line. | |
303 | ||
304 | Otherwise, roughly speaking, the shell reads its input and divides | |
305 | the input into words and operators, employing the quoting rules to | |
306 | select which meanings to assign various words and characters. | |
307 | ||
308 | The shell then parses these tokens into commands and other | |
309 | constructs, removes the special meaning of certain words or characters, | |
310 | expands others, redirects input and output as needed, executes the | |
311 | specified command, waits for the command's exit status, and makes that | |
312 | exit status available for further inspection or processing. | |
313 | ||
ccc6cda3 JA |
314 | \1f |
315 | File: bashref.info, Node: Shell Operation, Next: Quoting, Up: Shell Syntax | |
316 | ||
37c41ab1 CR |
317 | 3.1.1 Shell Operation |
318 | --------------------- | |
ccc6cda3 | 319 | |
37c41ab1 | 320 | The following is a brief description of the shell's operation when it |
ccc6cda3 JA |
321 | reads and executes a command. Basically, the shell does the following: |
322 | ||
28ef6c31 | 323 | 1. Reads its input from a file (*note Shell Scripts::), from a string |
ccc6cda3 | 324 | supplied as an argument to the `-c' invocation option (*note |
28ef6c31 | 325 | Invoking Bash::), or from the user's terminal. |
ccc6cda3 JA |
326 | |
327 | 2. Breaks the input into words and operators, obeying the quoting | |
6a8fd0ed | 328 | rules described in *note Quoting::. These tokens are separated by |
ccc6cda3 | 329 | `metacharacters'. Alias expansion is performed by this step |
28ef6c31 | 330 | (*note Aliases::). |
ccc6cda3 | 331 | |
cce855bc | 332 | 3. Parses the tokens into simple and compound commands (*note Shell |
28ef6c31 | 333 | Commands::). |
ccc6cda3 | 334 | |
28ef6c31 | 335 | 4. Performs the various shell expansions (*note Shell Expansions::), |
ccc6cda3 | 336 | breaking the expanded tokens into lists of filenames (*note |
28ef6c31 | 337 | Filename Expansion::) and commands and arguments. |
ccc6cda3 | 338 | |
28ef6c31 | 339 | 5. Performs any necessary redirections (*note Redirections::) and |
ccc6cda3 JA |
340 | removes the redirection operators and their operands from the |
341 | argument list. | |
342 | ||
28ef6c31 | 343 | 6. Executes the command (*note Executing Commands::). |
ccc6cda3 JA |
344 | |
345 | 7. Optionally waits for the command to complete and collects its exit | |
28ef6c31 | 346 | status (*note Exit Status::). |
ccc6cda3 JA |
347 | |
348 | ||
349 | \1f | |
350 | File: bashref.info, Node: Quoting, Next: Comments, Prev: Shell Operation, Up: Shell Syntax | |
351 | ||
37c41ab1 CR |
352 | 3.1.2 Quoting |
353 | ------------- | |
ccc6cda3 JA |
354 | |
355 | * Menu: | |
356 | ||
357 | * Escape Character:: How to remove the special meaning from a single | |
358 | character. | |
359 | * Single Quotes:: How to inhibit all interpretation of a sequence | |
360 | of characters. | |
361 | * Double Quotes:: How to suppress most of the interpretation of a | |
362 | sequence of characters. | |
363 | * ANSI-C Quoting:: How to expand ANSI-C sequences in quoted strings. | |
ccc6cda3 JA |
364 | * Locale Translation:: How to translate strings into different languages. |
365 | ||
366 | Quoting is used to remove the special meaning of certain characters | |
367 | or words to the shell. Quoting can be used to disable special | |
368 | treatment for special characters, to prevent reserved words from being | |
369 | recognized as such, and to prevent parameter expansion. | |
370 | ||
28ef6c31 | 371 | Each of the shell metacharacters (*note Definitions::) has special |
cce855bc | 372 | meaning to the shell and must be quoted if it is to represent itself. |
01ed5ba4 CR |
373 | When the command history expansion facilities are being used (*note |
374 | History Interaction::), the HISTORY EXPANSION character, usually `!', | |
375 | must be quoted to prevent history expansion. *Note Bash History | |
376 | Facilities::, for more details concerning history expansion. | |
d3a24ed2 CR |
377 | |
378 | There are three quoting mechanisms: the ESCAPE CHARACTER, single | |
379 | quotes, and double quotes. | |
ccc6cda3 JA |
380 | |
381 | \1f | |
382 | File: bashref.info, Node: Escape Character, Next: Single Quotes, Up: Quoting | |
383 | ||
37c41ab1 CR |
384 | 3.1.2.1 Escape Character |
385 | ........................ | |
ccc6cda3 | 386 | |
37c41ab1 CR |
387 | A non-quoted backslash `\' is the Bash escape character. It preserves |
388 | the literal value of the next character that follows, with the | |
389 | exception of `newline'. If a `\newline' pair appears, and the | |
cce855bc JA |
390 | backslash itself is not quoted, the `\newline' is treated as a line |
391 | continuation (that is, it is removed from the input stream and | |
392 | effectively ignored). | |
ccc6cda3 JA |
393 | |
394 | \1f | |
395 | File: bashref.info, Node: Single Quotes, Next: Double Quotes, Prev: Escape Character, Up: Quoting | |
396 | ||
37c41ab1 CR |
397 | 3.1.2.2 Single Quotes |
398 | ..................... | |
ccc6cda3 | 399 | |
37c41ab1 CR |
400 | Enclosing characters in single quotes (`'') preserves the literal value |
401 | of each character within the quotes. A single quote may not occur | |
bb70624e | 402 | between single quotes, even when preceded by a backslash. |
ccc6cda3 JA |
403 | |
404 | \1f | |
405 | File: bashref.info, Node: Double Quotes, Next: ANSI-C Quoting, Prev: Single Quotes, Up: Quoting | |
406 | ||
37c41ab1 CR |
407 | 3.1.2.3 Double Quotes |
408 | ..................... | |
ccc6cda3 | 409 | |
37c41ab1 CR |
410 | Enclosing characters in double quotes (`"') preserves the literal value |
411 | of all characters within the quotes, with the exception of `$', ``', | |
01ed5ba4 CR |
412 | `\', and, when history expansion is enabled, `!'. The characters `$' |
413 | and ``' retain their special meaning within double quotes (*note Shell | |
414 | Expansions::). The backslash retains its special meaning only when | |
415 | followed by one of the following characters: `$', ``', `"', `\', or | |
416 | `newline'. Within double quotes, backslashes that are followed by one | |
417 | of these characters are removed. Backslashes preceding characters | |
418 | without a special meaning are left unmodified. A double quote may be | |
419 | quoted within double quotes by preceding it with a backslash. If | |
420 | enabled, history expansion will be performed unless an `!' appearing in | |
421 | double quotes is escaped using a backslash. The backslash preceding | |
422 | the `!' is not removed. | |
ccc6cda3 JA |
423 | |
424 | The special parameters `*' and `@' have special meaning when in | |
28ef6c31 | 425 | double quotes (*note Shell Parameter Expansion::). |
ccc6cda3 JA |
426 | |
427 | \1f | |
428 | File: bashref.info, Node: ANSI-C Quoting, Next: Locale Translation, Prev: Double Quotes, Up: Quoting | |
429 | ||
37c41ab1 CR |
430 | 3.1.2.4 ANSI-C Quoting |
431 | ...................... | |
ccc6cda3 | 432 | |
37c41ab1 CR |
433 | Words of the form `$'STRING'' are treated specially. The word expands |
434 | to STRING, with backslash-escaped characters replaced as specified by | |
435 | the ANSI C standard. Backslash escape sequences, if present, are | |
436 | decoded as follows: | |
ccc6cda3 JA |
437 | |
438 | `\a' | |
439 | alert (bell) | |
440 | ||
441 | `\b' | |
442 | backspace | |
443 | ||
444 | `\e' | |
445 | an escape character (not ANSI C) | |
446 | ||
447 | `\f' | |
448 | form feed | |
449 | ||
450 | `\n' | |
451 | newline | |
452 | ||
453 | `\r' | |
454 | carriage return | |
455 | ||
456 | `\t' | |
457 | horizontal tab | |
458 | ||
459 | `\v' | |
460 | vertical tab | |
461 | ||
462 | `\\' | |
463 | backslash | |
464 | ||
bb70624e JA |
465 | `\'' |
466 | single quote | |
467 | ||
ccc6cda3 | 468 | `\NNN' |
f73dda09 | 469 | the eight-bit character whose value is the octal value NNN (one to |
cce855bc JA |
470 | three digits) |
471 | ||
f73dda09 JA |
472 | `\xHH' |
473 | the eight-bit character whose value is the hexadecimal value HH | |
474 | (one or two hex digits) | |
ccc6cda3 | 475 | |
7117c2d2 JA |
476 | `\cX' |
477 | a control-X character | |
478 | ||
bb70624e JA |
479 | The expanded result is single-quoted, as if the dollar sign had not |
480 | been present. | |
ccc6cda3 JA |
481 | |
482 | \1f | |
483 | File: bashref.info, Node: Locale Translation, Prev: ANSI-C Quoting, Up: Quoting | |
484 | ||
37c41ab1 CR |
485 | 3.1.2.5 Locale-Specific Translation |
486 | ................................... | |
ccc6cda3 | 487 | |
37c41ab1 CR |
488 | A double-quoted string preceded by a dollar sign (`$') will cause the |
489 | string to be translated according to the current locale. If the | |
ccc6cda3 JA |
490 | current locale is `C' or `POSIX', the dollar sign is ignored. If the |
491 | string is translated and replaced, the replacement is double-quoted. | |
492 | ||
28ef6c31 JA |
493 | Some systems use the message catalog selected by the `LC_MESSAGES' |
494 | shell variable. Others create the name of the message catalog from the | |
495 | value of the `TEXTDOMAIN' shell variable, possibly adding a suffix of | |
496 | `.mo'. If you use the `TEXTDOMAIN' variable, you may need to set the | |
497 | `TEXTDOMAINDIR' variable to the location of the message catalog files. | |
f73dda09 JA |
498 | Still others use both variables in this fashion: |
499 | `TEXTDOMAINDIR'/`LC_MESSAGES'/LC_MESSAGES/`TEXTDOMAIN'.mo. | |
28ef6c31 | 500 | |
ccc6cda3 JA |
501 | \1f |
502 | File: bashref.info, Node: Comments, Prev: Quoting, Up: Shell Syntax | |
503 | ||
37c41ab1 CR |
504 | 3.1.3 Comments |
505 | -------------- | |
ccc6cda3 | 506 | |
37c41ab1 | 507 | In a non-interactive shell, or an interactive shell in which the |
ccc6cda3 | 508 | `interactive_comments' option to the `shopt' builtin is enabled (*note |
d3ad40de CR |
509 | The Shopt Builtin::), a word beginning with `#' causes that word and |
510 | all remaining characters on that line to be ignored. An interactive | |
511 | shell without the `interactive_comments' option enabled does not allow | |
ccc6cda3 | 512 | comments. The `interactive_comments' option is on by default in |
bb70624e JA |
513 | interactive shells. *Note Interactive Shells::, for a description of |
514 | what makes a shell interactive. | |
cce855bc JA |
515 | |
516 | \1f | |
517 | File: bashref.info, Node: Shell Commands, Next: Shell Functions, Prev: Shell Syntax, Up: Basic Shell Features | |
518 | ||
37c41ab1 CR |
519 | 3.2 Shell Commands |
520 | ================== | |
cce855bc | 521 | |
37c41ab1 | 522 | A simple shell command such as `echo a b c' consists of the command |
bb70624e JA |
523 | itself followed by arguments, separated by spaces. |
524 | ||
525 | More complex shell commands are composed of simple commands arranged | |
526 | together in a variety of ways: in a pipeline in which the output of one | |
527 | command becomes the input of a second, in a loop or conditional | |
528 | construct, or in some other grouping. | |
529 | ||
cce855bc JA |
530 | * Menu: |
531 | ||
532 | * Simple Commands:: The most common type of command. | |
533 | * Pipelines:: Connecting the input and output of several | |
534 | commands. | |
535 | * Lists:: How to execute commands sequentially. | |
d3a24ed2 | 536 | * Compound Commands:: Shell commands for control flow. |
8e1a6eaa | 537 | * Coprocesses:: Two-way communication between commands. |
ccc6cda3 JA |
538 | |
539 | \1f | |
cce855bc | 540 | File: bashref.info, Node: Simple Commands, Next: Pipelines, Up: Shell Commands |
ccc6cda3 | 541 | |
37c41ab1 CR |
542 | 3.2.1 Simple Commands |
543 | --------------------- | |
ccc6cda3 | 544 | |
37c41ab1 CR |
545 | A simple command is the kind of command encountered most often. It's |
546 | just a sequence of words separated by `blank's, terminated by one of | |
547 | the shell's control operators (*note Definitions::). The first word | |
28ef6c31 | 548 | generally specifies a command to be executed, with the rest of the |
bb70624e | 549 | words being that command's arguments. |
ccc6cda3 | 550 | |
28ef6c31 | 551 | The return status (*note Exit Status::) of a simple command is its |
bb70624e JA |
552 | exit status as provided by the POSIX 1003.1 `waitpid' function, or |
553 | 128+N if the command was terminated by signal N. | |
ccc6cda3 JA |
554 | |
555 | \1f | |
cce855bc | 556 | File: bashref.info, Node: Pipelines, Next: Lists, Prev: Simple Commands, Up: Shell Commands |
ccc6cda3 | 557 | |
37c41ab1 CR |
558 | 3.2.2 Pipelines |
559 | --------------- | |
ccc6cda3 | 560 | |
ed35cb4a CR |
561 | A `pipeline' is a sequence of simple commands separated by one of the |
562 | control operators `|' or `|&'. | |
ccc6cda3 JA |
563 | |
564 | The format for a pipeline is | |
ed35cb4a | 565 | [`time' [`-p']] [`!'] COMMAND1 [ [`|' or `|&'] COMMAND2 ...] |
ccc6cda3 | 566 | |
f73dda09 JA |
567 | The output of each command in the pipeline is connected via a pipe to |
568 | the input of the next command. That is, each command reads the | |
ed35cb4a CR |
569 | previous command's output. This connection is performed before any |
570 | redirections specified by the command. | |
571 | ||
572 | If `|&' is used, the standard error of COMMAND1 is connected to | |
573 | COMMAND2's standard input through the pipe; it is shorthand for `2>&1 | |
574 | |'. This implicit redirection of the standard error is performed after | |
575 | any redirections specified by the command. | |
ccc6cda3 JA |
576 | |
577 | The reserved word `time' causes timing statistics to be printed for | |
cce855bc JA |
578 | the pipeline once it finishes. The statistics currently consist of |
579 | elapsed (wall-clock) time and user and system time consumed by the | |
580 | command's execution. The `-p' option changes the output format to that | |
581 | specified by POSIX. The `TIMEFORMAT' variable may be set to a format | |
582 | string that specifies how the timing information should be displayed. | |
583 | *Note Bash Variables::, for a description of the available formats. | |
584 | The use of `time' as a reserved word permits the timing of shell | |
585 | builtins, shell functions, and pipelines. An external `time' command | |
586 | cannot time these easily. | |
587 | ||
28ef6c31 | 588 | If the pipeline is not executed asynchronously (*note Lists::), the |
cce855bc | 589 | shell waits for all commands in the pipeline to complete. |
ccc6cda3 | 590 | |
cce855bc | 591 | Each command in a pipeline is executed in its own subshell (*note |
28ef6c31 | 592 | Command Execution Environment::). The exit status of a pipeline is the |
5e13499c CR |
593 | exit status of the last command in the pipeline, unless the `pipefail' |
594 | option is enabled (*note The Set Builtin::). If `pipefail' is enabled, | |
595 | the pipeline's return status is the value of the last (rightmost) | |
596 | command to exit with a non-zero status, or zero if all commands exit | |
597 | successfully. If the reserved word `!' precedes the pipeline, the exit | |
598 | status is the logical negation of the exit status as described above. | |
599 | The shell waits for all commands in the pipeline to terminate before | |
600 | returning a value. | |
ccc6cda3 JA |
601 | |
602 | \1f | |
d3a24ed2 | 603 | File: bashref.info, Node: Lists, Next: Compound Commands, Prev: Pipelines, Up: Shell Commands |
ccc6cda3 | 604 | |
37c41ab1 CR |
605 | 3.2.3 Lists of Commands |
606 | ----------------------- | |
ccc6cda3 | 607 | |
37c41ab1 CR |
608 | A `list' is a sequence of one or more pipelines separated by one of the |
609 | operators `;', `&', `&&', or `||', and optionally terminated by one of | |
610 | `;', `&', or a `newline'. | |
ccc6cda3 JA |
611 | |
612 | Of these list operators, `&&' and `||' have equal precedence, | |
613 | followed by `;' and `&', which have equal precedence. | |
614 | ||
7117c2d2 JA |
615 | A sequence of one or more newlines may appear in a `list' to delimit |
616 | commands, equivalent to a semicolon. | |
617 | ||
ccc6cda3 | 618 | If a command is terminated by the control operator `&', the shell |
cce855bc JA |
619 | executes the command asynchronously in a subshell. This is known as |
620 | executing the command in the BACKGROUND. The shell does not wait for | |
bb70624e | 621 | the command to finish, and the return status is 0 (true). When job |
28ef6c31 | 622 | control is not active (*note Job Control::), the standard input for |
bb70624e JA |
623 | asynchronous commands, in the absence of any explicit redirections, is |
624 | redirected from `/dev/null'. | |
cce855bc JA |
625 | |
626 | Commands separated by a `;' are executed sequentially; the shell | |
627 | waits for each command to terminate in turn. The return status is the | |
628 | exit status of the last command executed. | |
ccc6cda3 | 629 | |
6a8fd0ed CR |
630 | AND and OR lists are sequences of one or more pipelines separated by |
631 | the control operators `&&' and `||', respectively. AND and OR lists | |
632 | are executed with left associativity. | |
633 | ||
634 | An AND list has the form | |
bb70624e | 635 | COMMAND1 && COMMAND2 |
ccc6cda3 | 636 | |
bb70624e JA |
637 | COMMAND2 is executed if, and only if, COMMAND1 returns an exit status |
638 | of zero. | |
ccc6cda3 JA |
639 | |
640 | An OR list has the form | |
bb70624e | 641 | COMMAND1 || COMMAND2 |
ccc6cda3 | 642 | |
bb70624e | 643 | COMMAND2 is executed if, and only if, COMMAND1 returns a non-zero exit |
ccc6cda3 JA |
644 | status. |
645 | ||
646 | The return status of AND and OR lists is the exit status of the last | |
647 | command executed in the list. | |
648 | ||
649 | \1f | |
8e1a6eaa | 650 | File: bashref.info, Node: Compound Commands, Next: Coprocesses, Prev: Lists, Up: Shell Commands |
d3a24ed2 | 651 | |
37c41ab1 CR |
652 | 3.2.4 Compound Commands |
653 | ----------------------- | |
d3a24ed2 CR |
654 | |
655 | * Menu: | |
656 | ||
657 | * Looping Constructs:: Shell commands for iterative action. | |
658 | * Conditional Constructs:: Shell commands for conditional execution. | |
659 | * Command Grouping:: Ways to group commands. | |
660 | ||
661 | Compound commands are the shell programming constructs. Each | |
662 | construct begins with a reserved word or control operator and is | |
663 | terminated by a corresponding reserved word or operator. Any | |
664 | redirections (*note Redirections::) associated with a compound command | |
665 | apply to all commands within that compound command unless explicitly | |
666 | overridden. | |
667 | ||
668 | Bash provides looping constructs, conditional commands, and | |
669 | mechanisms to group commands and execute them as a unit. | |
670 | ||
671 | \1f | |
672 | File: bashref.info, Node: Looping Constructs, Next: Conditional Constructs, Up: Compound Commands | |
ccc6cda3 | 673 | |
37c41ab1 CR |
674 | 3.2.4.1 Looping Constructs |
675 | .......................... | |
ccc6cda3 | 676 | |
37c41ab1 | 677 | Bash supports the following looping constructs. |
ccc6cda3 | 678 | |
bb70624e | 679 | Note that wherever a `;' appears in the description of a command's |
cce855bc JA |
680 | syntax, it may be replaced with one or more newlines. |
681 | ||
ccc6cda3 JA |
682 | `until' |
683 | The syntax of the `until' command is: | |
684 | until TEST-COMMANDS; do CONSEQUENT-COMMANDS; done | |
cce855bc JA |
685 | Execute CONSEQUENT-COMMANDS as long as TEST-COMMANDS has an exit |
686 | status which is not zero. The return status is the exit status of | |
687 | the last command executed in CONSEQUENT-COMMANDS, or zero if none | |
688 | was executed. | |
ccc6cda3 JA |
689 | |
690 | `while' | |
691 | The syntax of the `while' command is: | |
692 | while TEST-COMMANDS; do CONSEQUENT-COMMANDS; done | |
693 | ||
cce855bc JA |
694 | Execute CONSEQUENT-COMMANDS as long as TEST-COMMANDS has an exit |
695 | status of zero. The return status is the exit status of the last | |
696 | command executed in CONSEQUENT-COMMANDS, or zero if none was | |
697 | executed. | |
ccc6cda3 JA |
698 | |
699 | `for' | |
700 | The syntax of the `for' command is: | |
701 | ||
4a8bb13f | 702 | for NAME [ [in [WORDS ...] ] ; ] do COMMANDS; done |
cce855bc JA |
703 | Expand WORDS, and execute COMMANDS once for each member in the |
704 | resultant list, with NAME bound to the current member. If `in | |
bb70624e JA |
705 | WORDS' is not present, the `for' command executes the COMMANDS |
706 | once for each positional parameter that is set, as if `in "$@"' | |
28ef6c31 | 707 | had been specified (*note Special Parameters::). The return |
bb70624e JA |
708 | status is the exit status of the last command that executes. If |
709 | there are no items in the expansion of WORDS, no commands are | |
710 | executed, and the return status is zero. | |
711 | ||
712 | An alternate form of the `for' command is also supported: | |
713 | ||
714 | for (( EXPR1 ; EXPR2 ; EXPR3 )) ; do COMMANDS ; done | |
715 | First, the arithmetic expression EXPR1 is evaluated according to | |
28ef6c31 | 716 | the rules described below (*note Shell Arithmetic::). The |
bb70624e JA |
717 | arithmetic expression EXPR2 is then evaluated repeatedly until it |
718 | evaluates to zero. Each time EXPR2 evaluates to a non-zero value, | |
719 | COMMANDS are executed and the arithmetic expression EXPR3 is | |
720 | evaluated. If any expression is omitted, it behaves as if it | |
721 | evaluates to 1. The return value is the exit status of the last | |
722 | command in LIST that is executed, or false if any of the | |
723 | expressions is invalid. | |
ccc6cda3 | 724 | |
761783bf | 725 | |
28ef6c31 | 726 | The `break' and `continue' builtins (*note Bourne Shell Builtins::) |
ccc6cda3 JA |
727 | may be used to control loop execution. |
728 | ||
729 | \1f | |
d3a24ed2 | 730 | File: bashref.info, Node: Conditional Constructs, Next: Command Grouping, Prev: Looping Constructs, Up: Compound Commands |
ccc6cda3 | 731 | |
37c41ab1 CR |
732 | 3.2.4.2 Conditional Constructs |
733 | .............................. | |
ccc6cda3 JA |
734 | |
735 | `if' | |
736 | The syntax of the `if' command is: | |
737 | ||
738 | if TEST-COMMANDS; then | |
739 | CONSEQUENT-COMMANDS; | |
740 | [elif MORE-TEST-COMMANDS; then | |
741 | MORE-CONSEQUENTS;] | |
742 | [else ALTERNATE-CONSEQUENTS;] | |
743 | fi | |
744 | ||
cce855bc JA |
745 | The TEST-COMMANDS list is executed, and if its return status is |
746 | zero, the CONSEQUENT-COMMANDS list is executed. If TEST-COMMANDS | |
747 | returns a non-zero status, each `elif' list is executed in turn, | |
748 | and if its exit status is zero, the corresponding MORE-CONSEQUENTS | |
749 | is executed and the command completes. If `else | |
750 | ALTERNATE-CONSEQUENTS' is present, and the final command in the | |
751 | final `if' or `elif' clause has a non-zero exit status, then | |
752 | ALTERNATE-CONSEQUENTS is executed. The return status is the exit | |
753 | status of the last command executed, or zero if no condition | |
754 | tested true. | |
ccc6cda3 JA |
755 | |
756 | `case' | |
757 | The syntax of the `case' command is: | |
758 | ||
cce855bc | 759 | `case WORD in [ [(] PATTERN [| PATTERN]...) COMMAND-LIST ;;]... esac' |
ccc6cda3 | 760 | |
cce855bc | 761 | `case' will selectively execute the COMMAND-LIST corresponding to |
9d2b70f0 | 762 | the first PATTERN that matches WORD. If the shell option |
6a8fd0ed | 763 | `nocasematch' (see the description of `shopt' in *note The Shopt |
d3ad40de | 764 | Builtin::) is enabled, the match is performed without regard to |
9d2b70f0 | 765 | the case of alphabetic characters. The `|' is used to separate |
cce855bc JA |
766 | multiple patterns, and the `)' operator terminates a pattern list. |
767 | A list of patterns and an associated command-list is known as a | |
ed35cb4a CR |
768 | CLAUSE. |
769 | ||
c302751c | 770 | Each clause must be terminated with `;;', `;&', or `;;&'. The |
ed35cb4a | 771 | WORD undergoes tilde expansion, parameter expansion, command |
cce855bc JA |
772 | substitution, arithmetic expansion, and quote removal before |
773 | matching is attempted. Each PATTERN undergoes tilde expansion, | |
774 | parameter expansion, command substitution, and arithmetic | |
775 | expansion. | |
776 | ||
777 | There may be an arbitrary number of `case' clauses, each terminated | |
ed35cb4a CR |
778 | by a `;;', `;&', or `;;&'. The first pattern that matches |
779 | determines the command-list that is executed. | |
ccc6cda3 JA |
780 | |
781 | Here is an example using `case' in a script that could be used to | |
782 | describe one interesting feature of an animal: | |
783 | ||
784 | echo -n "Enter the name of an animal: " | |
785 | read ANIMAL | |
786 | echo -n "The $ANIMAL has " | |
787 | case $ANIMAL in | |
788 | horse | dog | cat) echo -n "four";; | |
789 | man | kangaroo ) echo -n "two";; | |
790 | *) echo -n "an unknown number of";; | |
791 | esac | |
792 | echo " legs." | |
793 | ||
ed35cb4a CR |
794 | If the `;;' operator is used, no subsequent matches are attempted |
795 | after the first pattern match. Using `;&' in place of `;;' | |
796 | causes execution to continue with the COMMAND-LIST associated with | |
797 | the next clause, if any. Using `;;&' in place of `;;' causes the | |
798 | shell to test the patterns in the next clause, if any, and execute | |
799 | any associated COMMAND-LIST on a successful match. | |
800 | ||
cce855bc JA |
801 | The return status is zero if no PATTERN is matched. Otherwise, the |
802 | return status is the exit status of the COMMAND-LIST executed. | |
803 | ||
804 | `select' | |
805 | The `select' construct allows the easy generation of menus. It | |
806 | has almost the same syntax as the `for' command: | |
807 | ||
808 | select NAME [in WORDS ...]; do COMMANDS; done | |
809 | ||
810 | The list of words following `in' is expanded, generating a list of | |
811 | items. The set of expanded words is printed on the standard error | |
812 | output stream, each preceded by a number. If the `in WORDS' is | |
813 | omitted, the positional parameters are printed, as if `in "$@"' | |
d3ad40de | 814 | had been specified. The `PS3' prompt is then displayed and a line |
cce855bc JA |
815 | is read from the standard input. If the line consists of a number |
816 | corresponding to one of the displayed words, then the value of | |
817 | NAME is set to that word. If the line is empty, the words and | |
818 | prompt are displayed again. If `EOF' is read, the `select' | |
819 | command completes. Any other value read causes NAME to be set to | |
820 | null. The line read is saved in the variable `REPLY'. | |
821 | ||
f73dda09 JA |
822 | The COMMANDS are executed after each selection until a `break' |
823 | command is executed, at which point the `select' command completes. | |
cce855bc JA |
824 | |
825 | Here is an example that allows the user to pick a filename from the | |
826 | current directory, and displays the name and index of the file | |
827 | selected. | |
828 | ||
829 | select fname in *; | |
830 | do | |
831 | echo you picked $fname \($REPLY\) | |
832 | break; | |
833 | done | |
834 | ||
ccc6cda3 JA |
835 | `((...))' |
836 | (( EXPRESSION )) | |
837 | ||
cce855bc | 838 | The arithmetic EXPRESSION is evaluated according to the rules |
28ef6c31 | 839 | described below (*note Shell Arithmetic::). If the value of the |
cce855bc JA |
840 | expression is non-zero, the return status is 0; otherwise the |
841 | return status is 1. This is exactly equivalent to | |
ccc6cda3 | 842 | let "EXPRESSION" |
cce855bc JA |
843 | *Note Bash Builtins::, for a full description of the `let' builtin. |
844 | ||
845 | `[[...]]' | |
846 | [[ EXPRESSION ]] | |
847 | ||
848 | Return a status of 0 or 1 depending on the evaluation of the | |
849 | conditional expression EXPRESSION. Expressions are composed of | |
6a8fd0ed | 850 | the primaries described below in *note Bash Conditional |
cce855bc JA |
851 | Expressions::. Word splitting and filename expansion are not |
852 | performed on the words between the `[[' and `]]'; tilde expansion, | |
853 | parameter and variable expansion, arithmetic expansion, command | |
854 | substitution, process substitution, and quote removal are | |
d3a24ed2 CR |
855 | performed. Conditional operators such as `-f' must be unquoted to |
856 | be recognized as primaries. | |
cce855bc JA |
857 | |
858 | When the `==' and `!=' operators are used, the string to the right | |
859 | of the operator is considered a pattern and matched according to | |
6a8fd0ed | 860 | the rules described below in *note Pattern Matching::. If the |
9d2b70f0 | 861 | shell option `nocasematch' (see the description of `shopt' in |
6a8fd0ed | 862 | *note The Shopt Builtin::) is enabled, the match is performed |
d3ad40de CR |
863 | without regard to the case of alphabetic characters. The return |
864 | value is 0 if the string matches (`==') or does not match | |
865 | (`!=')the pattern, and 1 otherwise. Any part of the pattern may | |
866 | be quoted to force it to be matched as a string. | |
cce855bc | 867 | |
5e13499c CR |
868 | An additional binary operator, `=~', is available, with the same |
869 | precedence as `==' and `!='. When it is used, the string to the | |
870 | right of the operator is considered an extended regular expression | |
871 | and matched accordingly (as in regex3)). The return value is 0 if | |
872 | the string matches the pattern, and 1 otherwise. If the regular | |
873 | expression is syntactically incorrect, the conditional | |
9d2b70f0 | 874 | expression's return value is 2. If the shell option `nocasematch' |
6a8fd0ed | 875 | (see the description of `shopt' in *note The Shopt Builtin::) is |
5e13499c | 876 | enabled, the match is performed without regard to the case of |
3d4e09aa CR |
877 | alphabetic characters. Any part of the pattern may be quoted to |
878 | force it to be matched as a string. Substrings matched by | |
879 | parenthesized subexpressions within the regular expression are | |
880 | saved in the array variable `BASH_REMATCH'. The element of | |
881 | `BASH_REMATCH' with index 0 is the portion of the string matching | |
882 | the entire regular expression. The element of `BASH_REMATCH' with | |
883 | index N is the portion of the string matching the Nth | |
884 | parenthesized subexpression. | |
5e13499c | 885 | |
cce855bc JA |
886 | Expressions may be combined using the following operators, listed |
887 | in decreasing order of precedence: | |
888 | ||
889 | `( EXPRESSION )' | |
890 | Returns the value of EXPRESSION. This may be used to | |
891 | override the normal precedence of operators. | |
892 | ||
893 | `! EXPRESSION' | |
894 | True if EXPRESSION is false. | |
895 | ||
896 | `EXPRESSION1 && EXPRESSION2' | |
897 | True if both EXPRESSION1 and EXPRESSION2 are true. | |
898 | ||
899 | `EXPRESSION1 || EXPRESSION2' | |
900 | True if either EXPRESSION1 or EXPRESSION2 is true. | |
7117c2d2 JA |
901 | The `&&' and `||' operators do not evaluate EXPRESSION2 if the |
902 | value of EXPRESSION1 is sufficient to determine the return value | |
903 | of the entire conditional expression. | |
ccc6cda3 | 904 | |
761783bf | 905 | |
ccc6cda3 | 906 | \1f |
d3a24ed2 | 907 | File: bashref.info, Node: Command Grouping, Prev: Conditional Constructs, Up: Compound Commands |
ccc6cda3 | 908 | |
37c41ab1 CR |
909 | 3.2.4.3 Grouping Commands |
910 | ......................... | |
ccc6cda3 | 911 | |
37c41ab1 CR |
912 | Bash provides two ways to group a list of commands to be executed as a |
913 | unit. When commands are grouped, redirections may be applied to the | |
ccc6cda3 JA |
914 | entire command list. For example, the output of all the commands in |
915 | the list may be redirected to a single stream. | |
916 | ||
917 | `()' | |
918 | ( LIST ) | |
919 | ||
920 | Placing a list of commands between parentheses causes a subshell | |
d3a24ed2 CR |
921 | environment to be created (*note Command Execution Environment::), |
922 | and each of the commands in LIST to be executed in that subshell. | |
923 | Since the LIST is executed in a subshell, variable assignments do | |
924 | not remain in effect after the subshell completes. | |
ccc6cda3 JA |
925 | |
926 | `{}' | |
927 | { LIST; } | |
928 | ||
929 | Placing a list of commands between curly braces causes the list to | |
930 | be executed in the current shell context. No subshell is created. | |
cce855bc | 931 | The semicolon (or newline) following LIST is required. |
ccc6cda3 JA |
932 | |
933 | In addition to the creation of a subshell, there is a subtle | |
934 | difference between these two constructs due to historical reasons. The | |
935 | braces are `reserved words', so they must be separated from the LIST by | |
d7f49990 CR |
936 | `blank's or other shell metacharacters. The parentheses are |
937 | `operators', and are recognized as separate tokens by the shell even if | |
938 | they are not separated from the LIST by whitespace. | |
ccc6cda3 JA |
939 | |
940 | The exit status of both of these constructs is the exit status of | |
941 | LIST. | |
942 | ||
8e1a6eaa CR |
943 | \1f |
944 | File: bashref.info, Node: Coprocesses, Prev: Compound Commands, Up: Shell Commands | |
945 | ||
946 | 3.2.5 Coprocesses | |
947 | ----------------- | |
948 | ||
949 | A `coprocess' is a shell command preceded by the `coproc' reserved word. | |
950 | A coprocess is executed asynchronously in a subshell, as if the command | |
951 | had been terminated with the `&' control operator, with a two-way pipe | |
952 | established between the executing shell and the coprocess. | |
953 | ||
954 | The format for a coprocess is: | |
955 | `coproc' [NAME] COMMAND [REDIRECTIONS] | |
956 | ||
957 | This creates a coprocess named NAME. If NAME is not supplied, the | |
db31fb26 CR |
958 | default name is COPROC. NAME must not be supplied if COMMAND is a |
959 | simple command (*note Simple Commands::); otherwise, it is interpreted | |
960 | as the first word of the simple command. | |
8e1a6eaa CR |
961 | |
962 | When the coproc is executed, the shell creates an array variable | |
963 | (*note Arrays::) named NAME in the context of the executing shell. The | |
964 | standard output of COMMAND is connected via a pipe to a file descriptor | |
965 | in the executing shell, and that file descriptor is assigned to NAME[0]. | |
966 | The standard input of COMMAND is connected via a pipe to a file | |
967 | descriptor in the executing shell, and that file descriptor is assigned | |
968 | to NAME[1]. This pipe is established before any redirections specified | |
969 | by the command (*note Redirections::). The file descriptors can be | |
970 | utilized as arguments to shell commands and redirections using standard | |
971 | word expansions. | |
972 | ||
973 | The process id of the shell spawned to execute the coprocess is | |
974 | available as the value of the variable NAME_PID. The `wait' builtin | |
975 | command may be used to wait for the coprocess to terminate. | |
976 | ||
977 | The return status of a coprocess is the exit status of COMMAND. | |
978 | ||
ccc6cda3 | 979 | \1f |
cce855bc | 980 | File: bashref.info, Node: Shell Functions, Next: Shell Parameters, Prev: Shell Commands, Up: Basic Shell Features |
ccc6cda3 | 981 | |
37c41ab1 CR |
982 | 3.3 Shell Functions |
983 | =================== | |
ccc6cda3 | 984 | |
37c41ab1 CR |
985 | Shell functions are a way to group commands for later execution using a |
986 | single name for the group. They are executed just like a "regular" | |
987 | command. When the name of a shell function is used as a simple command | |
988 | name, the list of commands associated with that function name is | |
989 | executed. Shell functions are executed in the current shell context; | |
990 | no new process is created to interpret them. | |
ccc6cda3 | 991 | |
37c41ab1 | 992 | Functions are declared using this syntax: |
d3a24ed2 | 993 | [ `function' ] NAME () COMPOUND-COMMAND [ REDIRECTIONS ] |
ccc6cda3 JA |
994 | |
995 | This defines a shell function named NAME. The reserved word | |
cce855bc | 996 | `function' is optional. If the `function' reserved word is supplied, |
d3a24ed2 CR |
997 | the parentheses are optional. The BODY of the function is the compound |
998 | command COMPOUND-COMMAND (*note Compound Commands::). That command is | |
999 | usually a LIST enclosed between { and }, but may be any compound | |
1000 | command listed above. COMPOUND-COMMAND is executed whenever NAME is | |
1001 | specified as the name of a command. Any redirections (*note | |
1002 | Redirections::) associated with the shell function are performed when | |
1003 | the function is executed. | |
1004 | ||
ac18b312 CR |
1005 | A function definition may be deleted using the `-f' option to the |
1006 | `unset' builtin (*note Bourne Shell Builtins::). | |
1007 | ||
d3a24ed2 CR |
1008 | The exit status of a function definition is zero unless a syntax |
1009 | error occurs or a readonly function with the same name already exists. | |
1010 | When executed, the exit status of a function is the exit status of the | |
1011 | last command executed in the body. | |
1012 | ||
1013 | Note that for historical reasons, in the most common usage the curly | |
1014 | braces that surround the body of the function must be separated from | |
1015 | the body by `blank's or newlines. This is because the braces are | |
1016 | reserved words and are only recognized as such when they are separated | |
d7f49990 CR |
1017 | from the command list by whitespace or another shell metacharacter. |
1018 | Also, when using the braces, the LIST must be terminated by a semicolon, | |
1019 | a `&', or a newline. | |
bb70624e | 1020 | |
ccc6cda3 JA |
1021 | When a function is executed, the arguments to the function become |
1022 | the positional parameters during its execution (*note Positional | |
28ef6c31 | 1023 | Parameters::). The special parameter `#' that expands to the number of |
de8913bd | 1024 | positional parameters is updated to reflect the change. Special |
d3a24ed2 CR |
1025 | parameter `0' is unchanged. The first element of the `FUNCNAME' |
1026 | variable is set to the name of the function while the function is | |
4a8bb13f CR |
1027 | executing. |
1028 | ||
1029 | All other aspects of the shell execution environment are identical | |
1030 | between a function and its caller with these exceptions: the `DEBUG' | |
1031 | and `RETURN' traps are not inherited unless the function has been given | |
1032 | the `trace' attribute using the `declare' builtin or the `-o functrace' | |
1033 | option has been enabled with the `set' builtin, (in which case all | |
1034 | functions inherit the `DEBUG' and `RETURN' traps), and the `ERR' trap | |
1035 | is not inherited unless the `-o errtrace' shell option has been enabled. | |
1036 | *Note Bourne Shell Builtins::, for the description of the `trap' | |
1037 | builtin. | |
ccc6cda3 JA |
1038 | |
1039 | If the builtin command `return' is executed in a function, the | |
1040 | function completes and execution resumes with the next command after | |
d3a24ed2 CR |
1041 | the function call. Any command associated with the `RETURN' trap is |
1042 | executed before execution resumes. When a function completes, the | |
1043 | values of the positional parameters and the special parameter `#' are | |
1044 | restored to the values they had prior to the function's execution. If | |
1045 | a numeric argument is given to `return', that is the function's return | |
1046 | status; otherwise the function's return status is the exit status of | |
1047 | the last command executed before the `return'. | |
ccc6cda3 JA |
1048 | |
1049 | Variables local to the function may be declared with the `local' | |
1050 | builtin. These variables are visible only to the function and the | |
1051 | commands it invokes. | |
1052 | ||
d3a24ed2 CR |
1053 | Function names and definitions may be listed with the `-f' option to |
1054 | the `declare' or `typeset' builtin commands (*note Bash Builtins::). | |
1055 | The `-F' option to `declare' or `typeset' will list the function names | |
1056 | only (and optionally the source file and line number, if the `extdebug' | |
1057 | shell option is enabled). Functions may be exported so that subshells | |
1058 | automatically have them defined with the `-f' option to the `export' | |
1059 | builtin (*note Bourne Shell Builtins::). Note that shell functions and | |
1060 | variables with the same name may result in multiple identically-named | |
1061 | entries in the environment passed to the shell's children. Care should | |
1062 | be taken in cases where this may cause a problem. | |
1063 | ||
ccc6cda3 JA |
1064 | Functions may be recursive. No limit is placed on the number of |
1065 | recursive calls. | |
1066 | ||
1067 | \1f | |
1068 | File: bashref.info, Node: Shell Parameters, Next: Shell Expansions, Prev: Shell Functions, Up: Basic Shell Features | |
1069 | ||
37c41ab1 CR |
1070 | 3.4 Shell Parameters |
1071 | ==================== | |
ccc6cda3 JA |
1072 | |
1073 | * Menu: | |
1074 | ||
1075 | * Positional Parameters:: The shell's command-line arguments. | |
d3a24ed2 | 1076 | * Special Parameters:: Parameters denoted by special characters. |
ccc6cda3 JA |
1077 | |
1078 | A PARAMETER is an entity that stores values. It can be a `name', a | |
d3a24ed2 CR |
1079 | number, or one of the special characters listed below. A VARIABLE is a |
1080 | parameter denoted by a `name'. A variable has a VALUE and zero or more | |
1081 | ATTRIBUTES. Attributes are assigned using the `declare' builtin command | |
6a8fd0ed | 1082 | (see the description of the `declare' builtin in *note Bash Builtins::). |
ccc6cda3 JA |
1083 | |
1084 | A parameter is set if it has been assigned a value. The null string | |
1085 | is a valid value. Once a variable is set, it may be unset only by using | |
1086 | the `unset' builtin command. | |
1087 | ||
1088 | A variable may be assigned to by a statement of the form | |
1089 | NAME=[VALUE] | |
37c41ab1 | 1090 | If VALUE is not given, the variable is assigned the null string. All |
ccc6cda3 JA |
1091 | VALUEs undergo tilde expansion, parameter and variable expansion, |
1092 | command substitution, arithmetic expansion, and quote removal (detailed | |
f73dda09 | 1093 | below). If the variable has its `integer' attribute set, then VALUE is |
d3a24ed2 CR |
1094 | evaluated as an arithmetic expression even if the `$((...))' expansion |
1095 | is not used (*note Arithmetic Expansion::). Word splitting is not | |
1096 | performed, with the exception of `"$@"' as explained below. Filename | |
1097 | expansion is not performed. Assignment statements may also appear as | |
5e13499c CR |
1098 | arguments to the `alias', `declare', `typeset', `export', `readonly', |
1099 | and `local' builtin commands. | |
ccc6cda3 | 1100 | |
eb2bb562 CR |
1101 | In the context where an assignment statement is assigning a value to |
1102 | a shell variable or array index (*note Arrays::), the `+=' operator can | |
1103 | be used to append to or add to the variable's previous value. When | |
1104 | `+=' is applied to a variable for which the integer attribute has been | |
1105 | set, VALUE is evaluated as an arithmetic expression and added to the | |
1106 | variable's current value, which is also evaluated. When `+=' is | |
1107 | applied to an array variable using compound assignment (*note | |
1108 | Arrays::), the variable's value is not unset (as it is when using `='), | |
1109 | and new values are appended to the array beginning at one greater than | |
09767ff0 CR |
1110 | the array's maximum index (for indexed arrays), or added as additional |
1111 | key-value pairs in an associative array. When applied to a | |
1112 | string-valued variable, VALUE is expanded and appended to the | |
1113 | variable's value. | |
eb2bb562 | 1114 | |
ccc6cda3 JA |
1115 | \1f |
1116 | File: bashref.info, Node: Positional Parameters, Next: Special Parameters, Up: Shell Parameters | |
1117 | ||
37c41ab1 CR |
1118 | 3.4.1 Positional Parameters |
1119 | --------------------------- | |
ccc6cda3 | 1120 | |
37c41ab1 | 1121 | A POSITIONAL PARAMETER is a parameter denoted by one or more digits, |
ccc6cda3 JA |
1122 | other than the single digit `0'. Positional parameters are assigned |
1123 | from the shell's arguments when it is invoked, and may be reassigned | |
cce855bc | 1124 | using the `set' builtin command. Positional parameter `N' may be |
bb70624e JA |
1125 | referenced as `${N}', or as `$N' when `N' consists of a single digit. |
1126 | Positional parameters may not be assigned to with assignment statements. | |
1127 | The `set' and `shift' builtins are used to set and unset them (*note | |
28ef6c31 JA |
1128 | Shell Builtin Commands::). The positional parameters are temporarily |
1129 | replaced when a shell function is executed (*note Shell Functions::). | |
ccc6cda3 JA |
1130 | |
1131 | When a positional parameter consisting of more than a single digit | |
1132 | is expanded, it must be enclosed in braces. | |
1133 | ||
1134 | \1f | |
1135 | File: bashref.info, Node: Special Parameters, Prev: Positional Parameters, Up: Shell Parameters | |
1136 | ||
37c41ab1 CR |
1137 | 3.4.2 Special Parameters |
1138 | ------------------------ | |
ccc6cda3 | 1139 | |
37c41ab1 | 1140 | The shell treats several parameters specially. These parameters may |
ccc6cda3 JA |
1141 | only be referenced; assignment to them is not allowed. |
1142 | ||
1143 | `*' | |
1144 | Expands to the positional parameters, starting from one. When the | |
1145 | expansion occurs within double quotes, it expands to a single word | |
1146 | with the value of each parameter separated by the first character | |
1147 | of the `IFS' special variable. That is, `"$*"' is equivalent to | |
1148 | `"$1C$2C..."', where C is the first character of the value of the | |
d166f048 JA |
1149 | `IFS' variable. If `IFS' is unset, the parameters are separated |
1150 | by spaces. If `IFS' is null, the parameters are joined without | |
1151 | intervening separators. | |
ccc6cda3 JA |
1152 | |
1153 | `@' | |
1154 | Expands to the positional parameters, starting from one. When the | |
cce855bc | 1155 | expansion occurs within double quotes, each parameter expands to a |
ccc6cda3 | 1156 | separate word. That is, `"$@"' is equivalent to `"$1" "$2" ...'. |
37c41ab1 CR |
1157 | If the double-quoted expansion occurs within a word, the expansion |
1158 | of the first parameter is joined with the beginning part of the | |
1159 | original word, and the expansion of the last parameter is joined | |
1160 | with the last part of the original word. When there are no | |
1161 | positional parameters, `"$@"' and `$@' expand to nothing (i.e., | |
1162 | they are removed). | |
ccc6cda3 JA |
1163 | |
1164 | `#' | |
1165 | Expands to the number of positional parameters in decimal. | |
1166 | ||
1167 | `?' | |
1168 | Expands to the exit status of the most recently executed foreground | |
1169 | pipeline. | |
1170 | ||
1171 | `-' | |
bb70624e JA |
1172 | (A hyphen.) Expands to the current option flags as specified upon |
1173 | invocation, by the `set' builtin command, or those set by the | |
1174 | shell itself (such as the `-i' option). | |
ccc6cda3 JA |
1175 | |
1176 | `$' | |
1177 | Expands to the process ID of the shell. In a `()' subshell, it | |
cce855bc | 1178 | expands to the process ID of the invoking shell, not the subshell. |
ccc6cda3 JA |
1179 | |
1180 | `!' | |
1181 | Expands to the process ID of the most recently executed background | |
1182 | (asynchronous) command. | |
1183 | ||
1184 | `0' | |
1185 | Expands to the name of the shell or shell script. This is set at | |
cce855bc | 1186 | shell initialization. If Bash is invoked with a file of commands |
28ef6c31 JA |
1187 | (*note Shell Scripts::), `$0' is set to the name of that file. If |
1188 | Bash is started with the `-c' option (*note Invoking Bash::), then | |
1189 | `$0' is set to the first argument after the string to be executed, | |
1190 | if one is present. Otherwise, it is set to the filename used to | |
1191 | invoke Bash, as given by argument zero. | |
ccc6cda3 JA |
1192 | |
1193 | `_' | |
2206f89a CR |
1194 | (An underscore.) At shell startup, set to the absolute pathname |
1195 | used to invoke the shell or shell script being executed as passed | |
1196 | in the environment or argument list. Subsequently, expands to the | |
1197 | last argument to the previous command, after expansion. Also set | |
1198 | to the full pathname used to invoke each command executed and | |
1199 | placed in the environment exported to that command. When checking | |
1200 | mail, this parameter holds the name of the mail file. | |
ccc6cda3 JA |
1201 | |
1202 | \1f | |
1203 | File: bashref.info, Node: Shell Expansions, Next: Redirections, Prev: Shell Parameters, Up: Basic Shell Features | |
1204 | ||
37c41ab1 CR |
1205 | 3.5 Shell Expansions |
1206 | ==================== | |
ccc6cda3 | 1207 | |
37c41ab1 CR |
1208 | Expansion is performed on the command line after it has been split into |
1209 | `token's. There are seven kinds of expansion performed: | |
ccc6cda3 JA |
1210 | * brace expansion |
1211 | ||
1212 | * tilde expansion | |
1213 | ||
1214 | * parameter and variable expansion | |
1215 | ||
1216 | * command substitution | |
1217 | ||
1218 | * arithmetic expansion | |
1219 | ||
1220 | * word splitting | |
1221 | ||
1222 | * filename expansion | |
1223 | ||
1224 | * Menu: | |
1225 | ||
cce855bc JA |
1226 | * Brace Expansion:: Expansion of expressions within braces. |
1227 | * Tilde Expansion:: Expansion of the ~ character. | |
ccc6cda3 JA |
1228 | * Shell Parameter Expansion:: How Bash expands variables to their values. |
1229 | * Command Substitution:: Using the output of a command as an argument. | |
cce855bc | 1230 | * Arithmetic Expansion:: How to use arithmetic in shell expansions. |
ccc6cda3 JA |
1231 | * Process Substitution:: A way to write and read to and from a |
1232 | command. | |
1233 | * Word Splitting:: How the results of expansion are split into separate | |
1234 | arguments. | |
1235 | * Filename Expansion:: A shorthand for specifying filenames matching patterns. | |
1236 | * Quote Removal:: How and when quote characters are removed from | |
1237 | words. | |
1238 | ||
ccc6cda3 JA |
1239 | The order of expansions is: brace expansion, tilde expansion, |
1240 | parameter, variable, and arithmetic expansion and command substitution | |
1241 | (done in a left-to-right fashion), word splitting, and filename | |
1242 | expansion. | |
1243 | ||
1244 | On systems that can support it, there is an additional expansion | |
1245 | available: PROCESS SUBSTITUTION. This is performed at the same time as | |
cce855bc | 1246 | parameter, variable, and arithmetic expansion and command substitution. |
ccc6cda3 JA |
1247 | |
1248 | Only brace expansion, word splitting, and filename expansion can | |
1249 | change the number of words of the expansion; other expansions expand a | |
1250 | single word to a single word. The only exceptions to this are the | |
28ef6c31 JA |
1251 | expansions of `"$@"' (*note Special Parameters::) and `"${NAME[@]}"' |
1252 | (*note Arrays::). | |
ccc6cda3 | 1253 | |
28ef6c31 | 1254 | After all expansions, `quote removal' (*note Quote Removal::) is |
ccc6cda3 JA |
1255 | performed. |
1256 | ||
1257 | \1f | |
cce855bc JA |
1258 | File: bashref.info, Node: Brace Expansion, Next: Tilde Expansion, Up: Shell Expansions |
1259 | ||
37c41ab1 CR |
1260 | 3.5.1 Brace Expansion |
1261 | --------------------- | |
cce855bc | 1262 | |
37c41ab1 | 1263 | Brace expansion is a mechanism by which arbitrary strings may be |
cce855bc | 1264 | generated. This mechanism is similar to FILENAME EXPANSION (*note |
28ef6c31 | 1265 | Filename Expansion::), but the file names generated need not exist. |
cce855bc | 1266 | Patterns to be brace expanded take the form of an optional PREAMBLE, |
d3ad40de | 1267 | followed by either a series of comma-separated strings or a seqeunce |
d3a24ed2 CR |
1268 | expression between a pair of braces, followed by an optional POSTSCRIPT. |
1269 | The preamble is prefixed to each string contained within the braces, and | |
1270 | the postscript is then appended to each resulting string, expanding left | |
1271 | to right. | |
cce855bc JA |
1272 | |
1273 | Brace expansions may be nested. The results of each expanded string | |
1274 | are not sorted; left to right order is preserved. For example, | |
1275 | bash$ echo a{d,c,b}e | |
1276 | ade ace abe | |
1277 | ||
4a8bb13f | 1278 | A sequence expression takes the form `{X..Y[..INCR]}', where X and Y |
ed35cb4a CR |
1279 | are either integers or single characters, and INCR, an optional |
1280 | increment, is an integer. When integers are supplied, the expression | |
1281 | expands to each number between X and Y, inclusive. Supplied integers | |
1282 | may be prefixed with `0' to force each term to have the same width. | |
1283 | When either X or Y begins with a zero, the shell attempts to force all | |
1284 | generated terms to contain the same number of digits, zero-padding | |
1285 | where necessary. When characters are supplied, the expression expands | |
1286 | to each character lexicographically between X and Y, inclusive. Note | |
1287 | that both X and Y must be of the same type. When the increment is | |
1288 | supplied, it is used as the difference between each term. The default | |
1289 | increment is 1 or -1 as appropriate. | |
d3a24ed2 | 1290 | |
cce855bc JA |
1291 | Brace expansion is performed before any other expansions, and any |
1292 | characters special to other expansions are preserved in the result. It | |
1293 | is strictly textual. Bash does not apply any syntactic interpretation | |
bb70624e JA |
1294 | to the context of the expansion or the text between the braces. To |
1295 | avoid conflicts with parameter expansion, the string `${' is not | |
1296 | considered eligible for brace expansion. | |
cce855bc JA |
1297 | |
1298 | A correctly-formed brace expansion must contain unquoted opening and | |
d3a24ed2 CR |
1299 | closing braces, and at least one unquoted comma or a valid sequence |
1300 | expression. Any incorrectly formed brace expansion is left unchanged. | |
1301 | ||
1302 | A { or `,' may be quoted with a backslash to prevent its being | |
1303 | considered part of a brace expression. To avoid conflicts with | |
1304 | parameter expansion, the string `${' is not considered eligible for | |
1305 | brace expansion. | |
cce855bc JA |
1306 | |
1307 | This construct is typically used as shorthand when the common prefix | |
1308 | of the strings to be generated is longer than in the above example: | |
1309 | mkdir /usr/local/src/bash/{old,new,dist,bugs} | |
1310 | or | |
1311 | chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}} | |
1312 | ||
1313 | \1f | |
1314 | File: bashref.info, Node: Tilde Expansion, Next: Shell Parameter Expansion, Prev: Brace Expansion, Up: Shell Expansions | |
1315 | ||
37c41ab1 CR |
1316 | 3.5.2 Tilde Expansion |
1317 | --------------------- | |
cce855bc | 1318 | |
37c41ab1 | 1319 | If a word begins with an unquoted tilde character (`~'), all of the |
cce855bc JA |
1320 | characters up to the first unquoted slash (or all characters, if there |
1321 | is no unquoted slash) are considered a TILDE-PREFIX. If none of the | |
1322 | characters in the tilde-prefix are quoted, the characters in the | |
1323 | tilde-prefix following the tilde are treated as a possible LOGIN NAME. | |
1324 | If this login name is the null string, the tilde is replaced with the | |
1325 | value of the `HOME' shell variable. If `HOME' is unset, the home | |
1326 | directory of the user executing the shell is substituted instead. | |
1327 | Otherwise, the tilde-prefix is replaced with the home directory | |
1328 | associated with the specified login name. | |
1329 | ||
1330 | If the tilde-prefix is `~+', the value of the shell variable `PWD' | |
1331 | replaces the tilde-prefix. If the tilde-prefix is `~-', the value of | |
1332 | the shell variable `OLDPWD', if it is set, is substituted. | |
1333 | ||
1334 | If the characters following the tilde in the tilde-prefix consist of | |
1335 | a number N, optionally prefixed by a `+' or a `-', the tilde-prefix is | |
1336 | replaced with the corresponding element from the directory stack, as it | |
1337 | would be displayed by the `dirs' builtin invoked with the characters | |
1338 | following tilde in the tilde-prefix as an argument (*note The Directory | |
28ef6c31 | 1339 | Stack::). If the tilde-prefix, sans the tilde, consists of a number |
cce855bc JA |
1340 | without a leading `+' or `-', `+' is assumed. |
1341 | ||
1342 | If the login name is invalid, or the tilde expansion fails, the word | |
1343 | is left unchanged. | |
1344 | ||
1345 | Each variable assignment is checked for unquoted tilde-prefixes | |
eb2bb562 CR |
1346 | immediately following a `:' or the first `='. In these cases, tilde |
1347 | expansion is also performed. Consequently, one may use file names with | |
1348 | tildes in assignments to `PATH', `MAILPATH', and `CDPATH', and the | |
1349 | shell assigns the expanded value. | |
cce855bc JA |
1350 | |
1351 | The following table shows how Bash treats unquoted tilde-prefixes: | |
1352 | ||
1353 | `~' | |
1354 | The value of `$HOME' | |
1355 | ||
1356 | `~/foo' | |
1357 | `$HOME/foo' | |
1358 | ||
1359 | `~fred/foo' | |
1360 | The subdirectory `foo' of the home directory of the user `fred' | |
1361 | ||
1362 | `~+/foo' | |
1363 | `$PWD/foo' | |
1364 | ||
1365 | `~-/foo' | |
1366 | `${OLDPWD-'~-'}/foo' | |
1367 | ||
1368 | `~N' | |
1369 | The string that would be displayed by `dirs +N' | |
1370 | ||
1371 | `~+N' | |
1372 | The string that would be displayed by `dirs +N' | |
1373 | ||
1374 | `~-N' | |
1375 | The string that would be displayed by `dirs -N' | |
1376 | ||
761783bf | 1377 | |
cce855bc JA |
1378 | \1f |
1379 | File: bashref.info, Node: Shell Parameter Expansion, Next: Command Substitution, Prev: Tilde Expansion, Up: Shell Expansions | |
ccc6cda3 | 1380 | |
37c41ab1 CR |
1381 | 3.5.3 Shell Parameter Expansion |
1382 | ------------------------------- | |
ccc6cda3 | 1383 | |
37c41ab1 CR |
1384 | The `$' character introduces parameter expansion, command substitution, |
1385 | or arithmetic expansion. The parameter name or symbol to be expanded | |
1386 | may be enclosed in braces, which are optional but serve to protect the | |
1387 | variable to be expanded from characters immediately following it which | |
1388 | could be interpreted as part of the name. | |
ccc6cda3 | 1389 | |
cce855bc JA |
1390 | When braces are used, the matching ending brace is the first `}' not |
1391 | escaped by a backslash or within a quoted string, and not within an | |
1392 | embedded arithmetic expansion, command substitution, or parameter | |
1393 | expansion. | |
1394 | ||
ccc6cda3 JA |
1395 | The basic form of parameter expansion is ${PARAMETER}. The value of |
1396 | PARAMETER is substituted. The braces are required when PARAMETER is a | |
1397 | positional parameter with more than one digit, or when PARAMETER is | |
1398 | followed by a character that is not to be interpreted as part of its | |
1399 | name. | |
1400 | ||
1401 | If the first character of PARAMETER is an exclamation point, a level | |
1402 | of variable indirection is introduced. Bash uses the value of the | |
1403 | variable formed from the rest of PARAMETER as the name of the variable; | |
d166f048 JA |
1404 | this variable is then expanded and that value is used in the rest of |
1405 | the substitution, rather than the value of PARAMETER itself. This is | |
d3a24ed2 CR |
1406 | known as `indirect expansion'. The exceptions to this are the |
1407 | expansions of ${!PREFIX*} and ${!NAME[@]} described below. The | |
1408 | exclamation point must immediately follow the left brace in order to | |
1409 | introduce indirection. | |
ccc6cda3 JA |
1410 | |
1411 | In each of the cases below, WORD is subject to tilde expansion, | |
1412 | parameter expansion, command substitution, and arithmetic expansion. | |
bb70624e | 1413 | |
db31fb26 CR |
1414 | When not performing substring expansion, using the form described |
1415 | below, Bash tests for a parameter that is unset or null. Omitting the | |
1416 | colon results in a test only for a parameter that is unset. Put | |
1417 | another way, if the colon is included, the operator tests for both | |
1418 | PARAMETER's existence and that its value is not null; if the colon is | |
1419 | omitted, the operator tests only for existence. | |
ccc6cda3 JA |
1420 | |
1421 | `${PARAMETER:-WORD}' | |
1422 | If PARAMETER is unset or null, the expansion of WORD is | |
1423 | substituted. Otherwise, the value of PARAMETER is substituted. | |
1424 | ||
1425 | `${PARAMETER:=WORD}' | |
1426 | If PARAMETER is unset or null, the expansion of WORD is assigned | |
1427 | to PARAMETER. The value of PARAMETER is then substituted. | |
de8913bd CR |
1428 | Positional parameters and special parameters may not be assigned to |
1429 | in this way. | |
ccc6cda3 JA |
1430 | |
1431 | `${PARAMETER:?WORD}' | |
1432 | If PARAMETER is null or unset, the expansion of WORD (or a message | |
1433 | to that effect if WORD is not present) is written to the standard | |
1434 | error and the shell, if it is not interactive, exits. Otherwise, | |
1435 | the value of PARAMETER is substituted. | |
1436 | ||
1437 | `${PARAMETER:+WORD}' | |
1438 | If PARAMETER is null or unset, nothing is substituted, otherwise | |
1439 | the expansion of WORD is substituted. | |
1440 | ||
1441 | `${PARAMETER:OFFSET}' | |
1442 | `${PARAMETER:OFFSET:LENGTH}' | |
bb70624e | 1443 | Expands to up to LENGTH characters of PARAMETER starting at the |
cce855bc | 1444 | character specified by OFFSET. If LENGTH is omitted, expands to |
bb70624e | 1445 | the substring of PARAMETER starting at the character specified by |
cce855bc | 1446 | OFFSET. LENGTH and OFFSET are arithmetic expressions (*note Shell |
28ef6c31 | 1447 | Arithmetic::). This is referred to as Substring Expansion. |
ccc6cda3 JA |
1448 | |
1449 | LENGTH must evaluate to a number greater than or equal to zero. | |
1450 | If OFFSET evaluates to a number less than zero, the value is used | |
1451 | as an offset from the end of the value of PARAMETER. If PARAMETER | |
1452 | is `@', the result is LENGTH positional parameters beginning at | |
09767ff0 CR |
1453 | OFFSET. If PARAMETER is an indexed array name subscripted by `@' |
1454 | or `*', the result is the LENGTH members of the array beginning | |
1455 | with `${PARAMETER[OFFSET]}'. A negative OFFSET is taken relative | |
1456 | to one greater than the maximum index of the specified array. | |
1457 | Substring expansion applied to an associative array produces | |
1458 | undefined results. | |
1459 | ||
1460 | Note that a negative offset must be separated from the colon by at | |
1461 | least one space to avoid being confused with the `:-' expansion. | |
eb2bb562 | 1462 | Substring indexing is zero-based unless the positional parameters |
d3ad40de CR |
1463 | are used, in which case the indexing starts at 1 by default. If |
1464 | OFFSET is 0, and the positional parameters are used, `$@' is | |
1465 | prefixed to the list. | |
ccc6cda3 | 1466 | |
bb70624e | 1467 | `${!PREFIX*}' |
d3a24ed2 | 1468 | `${!PREFIX@}' |
bb70624e JA |
1469 | Expands to the names of variables whose names begin with PREFIX, |
1470 | separated by the first character of the `IFS' special variable. | |
d3ad40de CR |
1471 | When `@' is used and the expansion appears within double quotes, |
1472 | each variable name expands to a separate word. | |
bb70624e | 1473 | |
d3a24ed2 CR |
1474 | `${!NAME[@]}' |
1475 | `${!NAME[*]}' | |
1476 | If NAME is an array variable, expands to the list of array indices | |
1477 | (keys) assigned in NAME. If NAME is not an array, expands to 0 if | |
1478 | NAME is set and null otherwise. When `@' is used and the | |
1479 | expansion appears within double quotes, each key expands to a | |
1480 | separate word. | |
1481 | ||
ccc6cda3 | 1482 | `${#PARAMETER}' |
cce855bc JA |
1483 | The length in characters of the expanded value of PARAMETER is |
1484 | substituted. If PARAMETER is `*' or `@', the value substituted is | |
1485 | the number of positional parameters. If PARAMETER is an array | |
1486 | name subscripted by `*' or `@', the value substituted is the | |
1487 | number of elements in the array. | |
ccc6cda3 JA |
1488 | |
1489 | `${PARAMETER#WORD}' | |
1490 | `${PARAMETER##WORD}' | |
1491 | The WORD is expanded to produce a pattern just as in filename | |
28ef6c31 | 1492 | expansion (*note Filename Expansion::). If the pattern matches |
cce855bc JA |
1493 | the beginning of the expanded value of PARAMETER, then the result |
1494 | of the expansion is the expanded value of PARAMETER with the | |
1495 | shortest matching pattern (the `#' case) or the longest matching | |
1496 | pattern (the `##' case) deleted. If PARAMETER is `@' or `*', the | |
1497 | pattern removal operation is applied to each positional parameter | |
1498 | in turn, and the expansion is the resultant list. If PARAMETER is | |
1499 | an array variable subscripted with `@' or `*', the pattern removal | |
1500 | operation is applied to each member of the array in turn, and the | |
1501 | expansion is the resultant list. | |
ccc6cda3 JA |
1502 | |
1503 | `${PARAMETER%WORD}' | |
1504 | `${PARAMETER%%WORD}' | |
1505 | The WORD is expanded to produce a pattern just as in filename | |
cce855bc JA |
1506 | expansion. If the pattern matches a trailing portion of the |
1507 | expanded value of PARAMETER, then the result of the expansion is | |
1508 | the value of PARAMETER with the shortest matching pattern (the `%' | |
1509 | case) or the longest matching pattern (the `%%' case) deleted. If | |
1510 | PARAMETER is `@' or `*', the pattern removal operation is applied | |
1511 | to each positional parameter in turn, and the expansion is the | |
1512 | resultant list. If PARAMETER is an array variable subscripted | |
1513 | with `@' or `*', the pattern removal operation is applied to each | |
1514 | member of the array in turn, and the expansion is the resultant | |
1515 | list. | |
ccc6cda3 JA |
1516 | |
1517 | `${PARAMETER/PATTERN/STRING}' | |
ccc6cda3 JA |
1518 | The PATTERN is expanded to produce a pattern just as in filename |
1519 | expansion. PARAMETER is expanded and the longest match of PATTERN | |
ac18b312 CR |
1520 | against its value is replaced with STRING. If PATTERN begins with |
1521 | `/', all matches of PATTERN are replaced with STRING. Normally | |
1522 | only the first match is replaced. If PATTERN begins with `#', it | |
1523 | must match at the beginning of the expanded value of PARAMETER. | |
1524 | If PATTERN begins with `%', it must match at the end of the | |
1525 | expanded value of PARAMETER. If STRING is null, matches of | |
b72432fd JA |
1526 | PATTERN are deleted and the `/' following PATTERN may be omitted. |
1527 | If PARAMETER is `@' or `*', the substitution operation is applied | |
1528 | to each positional parameter in turn, and the expansion is the | |
1529 | resultant list. If PARAMETER is an array variable subscripted | |
1530 | with `@' or `*', the substitution operation is applied to each | |
1531 | member of the array in turn, and the expansion is the resultant | |
1532 | list. | |
ccc6cda3 | 1533 | |
09767ff0 CR |
1534 | `${PARAMETER^PATTERN}' |
1535 | `${PARAMETER^^PATTERN}' | |
1536 | `${PARAMETER,PATTERN}' | |
1537 | `${PARAMETER,,PATTERN}' | |
1538 | This expansion modifies the case of alphabetic characters in | |
1539 | PARAMETER. The PATTERN is expanded to produce a pattern just as in | |
4a8bb13f | 1540 | filename expansion. The `^' operator converts lowercase letters |
09767ff0 CR |
1541 | matching PATTERN to uppercase; the `,' operator converts matching |
1542 | uppercase letters to lowercase. The `^^' and `,,' expansions | |
1543 | convert each matched character in the expanded value; the `^' and | |
db31fb26 CR |
1544 | `,' expansions match and convert only the first character in the |
1545 | expanded value. If PATTERN is omitted, it is treated like a `?', | |
1546 | which matches every character. If PARAMETER is `@' or `*', the | |
1547 | case modification operation is applied to each positional | |
1548 | parameter in turn, and the expansion is the resultant list. If | |
1549 | PARAMETER is an array variable subscripted with `@' or `*', the | |
1550 | case modification operation is applied to each member of the array | |
1551 | in turn, and the expansion is the resultant list. | |
09767ff0 | 1552 | |
761783bf | 1553 | |
ccc6cda3 | 1554 | \1f |
cce855bc | 1555 | File: bashref.info, Node: Command Substitution, Next: Arithmetic Expansion, Prev: Shell Parameter Expansion, Up: Shell Expansions |
ccc6cda3 | 1556 | |
37c41ab1 CR |
1557 | 3.5.4 Command Substitution |
1558 | -------------------------- | |
ccc6cda3 | 1559 | |
37c41ab1 | 1560 | Command substitution allows the output of a command to replace the |
bb70624e JA |
1561 | command itself. Command substitution occurs when a command is enclosed |
1562 | as follows: | |
ccc6cda3 | 1563 | $(COMMAND) |
37c41ab1 | 1564 | or |
ccc6cda3 JA |
1565 | `COMMAND` |
1566 | ||
1567 | Bash performs the expansion by executing COMMAND and replacing the | |
1568 | command substitution with the standard output of the command, with any | |
cce855bc JA |
1569 | trailing newlines deleted. Embedded newlines are not deleted, but they |
1570 | may be removed during word splitting. The command substitution `$(cat | |
1571 | FILE)' can be replaced by the equivalent but faster `$(< FILE)'. | |
ccc6cda3 JA |
1572 | |
1573 | When the old-style backquote form of substitution is used, backslash | |
1574 | retains its literal meaning except when followed by `$', ``', or `\'. | |
cce855bc JA |
1575 | The first backquote not preceded by a backslash terminates the command |
1576 | substitution. When using the `$(COMMAND)' form, all characters between | |
1577 | the parentheses make up the command; none are treated specially. | |
ccc6cda3 | 1578 | |
cce855bc JA |
1579 | Command substitutions may be nested. To nest when using the |
1580 | backquoted form, escape the inner backquotes with backslashes. | |
ccc6cda3 JA |
1581 | |
1582 | If the substitution appears within double quotes, word splitting and | |
1583 | filename expansion are not performed on the results. | |
1584 | ||
1585 | \1f | |
cce855bc JA |
1586 | File: bashref.info, Node: Arithmetic Expansion, Next: Process Substitution, Prev: Command Substitution, Up: Shell Expansions |
1587 | ||
37c41ab1 CR |
1588 | 3.5.5 Arithmetic Expansion |
1589 | -------------------------- | |
cce855bc | 1590 | |
37c41ab1 CR |
1591 | Arithmetic expansion allows the evaluation of an arithmetic expression |
1592 | and the substitution of the result. The format for arithmetic | |
1593 | expansion is: | |
cce855bc JA |
1594 | |
1595 | $(( EXPRESSION )) | |
1596 | ||
1597 | The expression is treated as if it were within double quotes, but a | |
1598 | double quote inside the parentheses is not treated specially. All | |
1599 | tokens in the expression undergo parameter expansion, command | |
d3a24ed2 | 1600 | substitution, and quote removal. Arithmetic expansions may be nested. |
cce855bc JA |
1601 | |
1602 | The evaluation is performed according to the rules listed below | |
28ef6c31 | 1603 | (*note Shell Arithmetic::). If the expression is invalid, Bash prints |
cce855bc JA |
1604 | a message indicating failure to the standard error and no substitution |
1605 | occurs. | |
1606 | ||
1607 | \1f | |
1608 | File: bashref.info, Node: Process Substitution, Next: Word Splitting, Prev: Arithmetic Expansion, Up: Shell Expansions | |
ccc6cda3 | 1609 | |
37c41ab1 CR |
1610 | 3.5.6 Process Substitution |
1611 | -------------------------- | |
ccc6cda3 | 1612 | |
37c41ab1 CR |
1613 | Process substitution is supported on systems that support named pipes |
1614 | (FIFOs) or the `/dev/fd' method of naming open files. It takes the | |
1615 | form of | |
ccc6cda3 | 1616 | <(LIST) |
37c41ab1 | 1617 | or |
ccc6cda3 | 1618 | >(LIST) |
37c41ab1 CR |
1619 | The process LIST is run with its input or output connected to a FIFO |
1620 | or some file in `/dev/fd'. The name of this file is passed as an | |
1621 | argument to the current command as the result of the expansion. If the | |
ccc6cda3 JA |
1622 | `>(LIST)' form is used, writing to the file will provide input for |
1623 | LIST. If the `<(LIST)' form is used, the file passed as an argument | |
bb70624e JA |
1624 | should be read to obtain the output of LIST. Note that no space may |
1625 | appear between the `<' or `>' and the left parenthesis, otherwise the | |
1626 | construct would be interpreted as a redirection. | |
ccc6cda3 | 1627 | |
cce855bc JA |
1628 | When available, process substitution is performed simultaneously with |
1629 | parameter and variable expansion, command substitution, and arithmetic | |
1630 | expansion. | |
ccc6cda3 JA |
1631 | |
1632 | \1f | |
1633 | File: bashref.info, Node: Word Splitting, Next: Filename Expansion, Prev: Process Substitution, Up: Shell Expansions | |
1634 | ||
37c41ab1 CR |
1635 | 3.5.7 Word Splitting |
1636 | -------------------- | |
ccc6cda3 | 1637 | |
37c41ab1 | 1638 | The shell scans the results of parameter expansion, command |
ccc6cda3 JA |
1639 | substitution, and arithmetic expansion that did not occur within double |
1640 | quotes for word splitting. | |
1641 | ||
1642 | The shell treats each character of `$IFS' as a delimiter, and splits | |
1643 | the results of the other expansions into words on these characters. If | |
1644 | `IFS' is unset, or its value is exactly `<space><tab><newline>', the | |
d3ad40de CR |
1645 | default, then sequences of ` <space>', `<tab>', and `<newline>' at the |
1646 | beginning and end of the results of the previous expansions are | |
1647 | ignored, and any sequence of `IFS' characters not at the beginning or | |
1648 | end serves to delimit words. If `IFS' has a value other than the | |
1649 | default, then sequences of the whitespace characters `space' and `tab' | |
1650 | are ignored at the beginning and end of the word, as long as the | |
1651 | whitespace character is in the value of `IFS' (an `IFS' whitespace | |
1652 | character). Any character in `IFS' that is not `IFS' whitespace, along | |
1653 | with any adjacent `IFS' whitespace characters, delimits a field. A | |
1654 | sequence of `IFS' whitespace characters is also treated as a delimiter. | |
1655 | If the value of `IFS' is null, no word splitting occurs. | |
ccc6cda3 JA |
1656 | |
1657 | Explicit null arguments (`""' or `''') are retained. Unquoted | |
bb70624e | 1658 | implicit null arguments, resulting from the expansion of parameters |
ccc6cda3 JA |
1659 | that have no values, are removed. If a parameter with no value is |
1660 | expanded within double quotes, a null argument results and is retained. | |
1661 | ||
1662 | Note that if no expansion occurs, no splitting is performed. | |
1663 | ||
1664 | \1f | |
1665 | File: bashref.info, Node: Filename Expansion, Next: Quote Removal, Prev: Word Splitting, Up: Shell Expansions | |
1666 | ||
37c41ab1 CR |
1667 | 3.5.8 Filename Expansion |
1668 | ------------------------ | |
ccc6cda3 | 1669 | |
cce855bc JA |
1670 | * Menu: |
1671 | ||
1672 | * Pattern Matching:: How the shell matches patterns. | |
1673 | ||
ccc6cda3 | 1674 | After word splitting, unless the `-f' option has been set (*note The |
28ef6c31 | 1675 | Set Builtin::), Bash scans each word for the characters `*', `?', and |
bb70624e JA |
1676 | `['. If one of these characters appears, then the word is regarded as |
1677 | a PATTERN, and replaced with an alphabetically sorted list of file | |
ccc6cda3 | 1678 | names matching the pattern. If no matching file names are found, and |
cce855bc JA |
1679 | the shell option `nullglob' is disabled, the word is left unchanged. |
1680 | If the `nullglob' option is set, and no matches are found, the word is | |
5e13499c CR |
1681 | removed. If the `failglob' shell option is set, and no matches are |
1682 | found, an error message is printed and the command is not executed. If | |
1683 | the shell option `nocaseglob' is enabled, the match is performed | |
1684 | without regard to the case of alphabetic characters. | |
cce855bc | 1685 | |
4a8bb13f | 1686 | When a pattern is used for filename expansion, the character `.' at |
28ef6c31 | 1687 | the start of a filename or immediately following a slash must be |
cce855bc JA |
1688 | matched explicitly, unless the shell option `dotglob' is set. When |
1689 | matching a file name, the slash character must always be matched | |
1690 | explicitly. In other cases, the `.' character is not treated specially. | |
1691 | ||
6a8fd0ed | 1692 | See the description of `shopt' in *note The Shopt Builtin::, for a |
5e13499c CR |
1693 | description of the `nocaseglob', `nullglob', `failglob', and `dotglob' |
1694 | options. | |
ccc6cda3 JA |
1695 | |
1696 | The `GLOBIGNORE' shell variable may be used to restrict the set of | |
cce855bc | 1697 | filenames matching a pattern. If `GLOBIGNORE' is set, each matching |
ccc6cda3 | 1698 | filename that also matches one of the patterns in `GLOBIGNORE' is |
28ef6c31 | 1699 | removed from the list of matches. The filenames `.' and `..' are |
d3a24ed2 CR |
1700 | always ignored when `GLOBIGNORE' is set and not null. However, setting |
1701 | `GLOBIGNORE' to a non-null value has the effect of enabling the | |
1702 | `dotglob' shell option, so all other filenames beginning with a `.' | |
1703 | will match. To get the old behavior of ignoring filenames beginning | |
1704 | with a `.', make `.*' one of the patterns in `GLOBIGNORE'. The | |
1705 | `dotglob' option is disabled when `GLOBIGNORE' is unset. | |
ccc6cda3 | 1706 | |
cce855bc JA |
1707 | \1f |
1708 | File: bashref.info, Node: Pattern Matching, Up: Filename Expansion | |
1709 | ||
37c41ab1 CR |
1710 | 3.5.8.1 Pattern Matching |
1711 | ........................ | |
cce855bc | 1712 | |
37c41ab1 CR |
1713 | Any character that appears in a pattern, other than the special pattern |
1714 | characters described below, matches itself. The NUL character may not | |
1715 | occur in a pattern. A backslash escapes the following character; the | |
1716 | escaping backslash is discarded when matching. The special pattern | |
1717 | characters must be quoted if they are to be matched literally. | |
cce855bc | 1718 | |
ccc6cda3 JA |
1719 | The special pattern characters have the following meanings: |
1720 | `*' | |
ed35cb4a CR |
1721 | Matches any string, including the null string. When the |
1722 | `globstar' shell option is enabled, and `*' is used in a filename | |
1723 | expansion context, two adjacent `*'s used as a single pattern will | |
1724 | match all files and zero or more directories and subdirectories. | |
1725 | If followed by a `/', two adjacent `*'s will match only | |
1726 | directories and subdirectories. | |
ccc6cda3 JA |
1727 | |
1728 | `?' | |
1729 | Matches any single character. | |
1730 | ||
1731 | `[...]' | |
1732 | Matches any one of the enclosed characters. A pair of characters | |
28ef6c31 JA |
1733 | separated by a hyphen denotes a RANGE EXPRESSION; any character |
1734 | that sorts between those two characters, inclusive, using the | |
1735 | current locale's collating sequence and character set, is matched. | |
1736 | If the first character following the `[' is a `!' or a `^' then | |
1737 | any character not enclosed is matched. A `-' may be matched by | |
1738 | including it as the first or last character in the set. A `]' may | |
1739 | be matched by including it as the first character in the set. The | |
1740 | sorting order of characters in range expressions is determined by | |
1741 | the current locale and the value of the `LC_COLLATE' shell | |
1742 | variable, if set. | |
1743 | ||
1744 | For example, in the default C locale, `[a-dx-z]' is equivalent to | |
1745 | `[abcdxyz]'. Many locales sort characters in dictionary order, | |
1746 | and in these locales `[a-dx-z]' is typically not equivalent to | |
1747 | `[abcdxyz]'; it might be equivalent to `[aBbCcDdxXyYz]', for | |
1748 | example. To obtain the traditional interpretation of ranges in | |
1749 | bracket expressions, you can force the use of the C locale by | |
1750 | setting the `LC_COLLATE' or `LC_ALL' environment variable to the | |
1751 | value `C'. | |
ccc6cda3 | 1752 | |
cce855bc JA |
1753 | Within `[' and `]', CHARACTER CLASSES can be specified using the |
1754 | syntax `[:'CLASS`:]', where CLASS is one of the following classes | |
ac18b312 | 1755 | defined in the POSIX standard: |
cce855bc | 1756 | alnum alpha ascii blank cntrl digit graph lower |
7117c2d2 | 1757 | print punct space upper word xdigit |
cce855bc | 1758 | A character class matches any character belonging to that class. |
7117c2d2 JA |
1759 | The `word' character class matches letters, digits, and the |
1760 | character `_'. | |
cce855bc JA |
1761 | |
1762 | Within `[' and `]', an EQUIVALENCE CLASS can be specified using | |
1763 | the syntax `[='C`=]', which matches all characters with the same | |
1764 | collation weight (as defined by the current locale) as the | |
1765 | character C. | |
1766 | ||
28ef6c31 | 1767 | Within `[' and `]', the syntax `[.'SYMBOL`.]' matches the |
cce855bc JA |
1768 | collating symbol SYMBOL. |
1769 | ||
1770 | If the `extglob' shell option is enabled using the `shopt' builtin, | |
1771 | several extended pattern matching operators are recognized. In the | |
1772 | following description, a PATTERN-LIST is a list of one or more patterns | |
1773 | separated by a `|'. Composite patterns may be formed using one or more | |
1774 | of the following sub-patterns: | |
1775 | ||
1776 | `?(PATTERN-LIST)' | |
1777 | Matches zero or one occurrence of the given patterns. | |
1778 | ||
1779 | `*(PATTERN-LIST)' | |
1780 | Matches zero or more occurrences of the given patterns. | |
1781 | ||
1782 | `+(PATTERN-LIST)' | |
1783 | Matches one or more occurrences of the given patterns. | |
1784 | ||
1785 | `@(PATTERN-LIST)' | |
eb2bb562 | 1786 | Matches one of the given patterns. |
cce855bc JA |
1787 | |
1788 | `!(PATTERN-LIST)' | |
1789 | Matches anything except one of the given patterns. | |
1790 | ||
ccc6cda3 JA |
1791 | \1f |
1792 | File: bashref.info, Node: Quote Removal, Prev: Filename Expansion, Up: Shell Expansions | |
1793 | ||
37c41ab1 CR |
1794 | 3.5.9 Quote Removal |
1795 | ------------------- | |
ccc6cda3 | 1796 | |
37c41ab1 | 1797 | After the preceding expansions, all unquoted occurrences of the |
ccc6cda3 JA |
1798 | characters `\', `'', and `"' that did not result from one of the above |
1799 | expansions are removed. | |
1800 | ||
1801 | \1f | |
1802 | File: bashref.info, Node: Redirections, Next: Executing Commands, Prev: Shell Expansions, Up: Basic Shell Features | |
1803 | ||
37c41ab1 CR |
1804 | 3.6 Redirections |
1805 | ================ | |
ccc6cda3 | 1806 | |
37c41ab1 | 1807 | Before a command is executed, its input and output may be REDIRECTED |
ccc6cda3 JA |
1808 | using a special notation interpreted by the shell. Redirection may |
1809 | also be used to open and close files for the current shell execution | |
1810 | environment. The following redirection operators may precede or appear | |
1811 | anywhere within a simple command or may follow a command. Redirections | |
1812 | are processed in the order they appear, from left to right. | |
1813 | ||
1814 | In the following descriptions, if the file descriptor number is | |
1815 | omitted, and the first character of the redirection operator is `<', | |
1816 | the redirection refers to the standard input (file descriptor 0). If | |
1817 | the first character of the redirection operator is `>', the redirection | |
1818 | refers to the standard output (file descriptor 1). | |
1819 | ||
cce855bc JA |
1820 | The word following the redirection operator in the following |
1821 | descriptions, unless otherwise noted, is subjected to brace expansion, | |
1822 | tilde expansion, parameter expansion, command substitution, arithmetic | |
bb70624e JA |
1823 | expansion, quote removal, filename expansion, and word splitting. If |
1824 | it expands to more than one word, Bash reports an error. | |
ccc6cda3 JA |
1825 | |
1826 | Note that the order of redirections is significant. For example, | |
1827 | the command | |
1828 | ls > DIRLIST 2>&1 | |
37c41ab1 | 1829 | directs both standard output (file descriptor 1) and standard error |
bb70624e | 1830 | (file descriptor 2) to the file DIRLIST, while the command |
ccc6cda3 | 1831 | ls 2>&1 > DIRLIST |
37c41ab1 | 1832 | directs only the standard output to file DIRLIST, because the |
6932f7f5 CR |
1833 | standard error was made a copy of the standard output before the |
1834 | standard output was redirected to DIRLIST. | |
ccc6cda3 | 1835 | |
bb70624e JA |
1836 | Bash handles several filenames specially when they are used in |
1837 | redirections, as described in the following table: | |
1838 | ||
1839 | `/dev/fd/FD' | |
1840 | If FD is a valid integer, file descriptor FD is duplicated. | |
1841 | ||
1842 | `/dev/stdin' | |
1843 | File descriptor 0 is duplicated. | |
1844 | ||
1845 | `/dev/stdout' | |
1846 | File descriptor 1 is duplicated. | |
1847 | ||
1848 | `/dev/stderr' | |
1849 | File descriptor 2 is duplicated. | |
1850 | ||
1851 | `/dev/tcp/HOST/PORT' | |
1852 | If HOST is a valid hostname or Internet address, and PORT is an | |
f73dda09 JA |
1853 | integer port number or service name, Bash attempts to open a TCP |
1854 | connection to the corresponding socket. | |
bb70624e JA |
1855 | |
1856 | `/dev/udp/HOST/PORT' | |
1857 | If HOST is a valid hostname or Internet address, and PORT is an | |
f73dda09 JA |
1858 | integer port number or service name, Bash attempts to open a UDP |
1859 | connection to the corresponding socket. | |
bb70624e | 1860 | |
761783bf | 1861 | |
cce855bc JA |
1862 | A failure to open or create a file causes the redirection to fail. |
1863 | ||
eb2bb562 CR |
1864 | Redirections using file descriptors greater than 9 should be used |
1865 | with care, as they may conflict with file descriptors the shell uses | |
1866 | internally. | |
1867 | ||
37c41ab1 CR |
1868 | 3.6.1 Redirecting Input |
1869 | ----------------------- | |
ccc6cda3 | 1870 | |
37c41ab1 | 1871 | Redirection of input causes the file whose name results from the |
ccc6cda3 JA |
1872 | expansion of WORD to be opened for reading on file descriptor `n', or |
1873 | the standard input (file descriptor 0) if `n' is not specified. | |
1874 | ||
1875 | The general format for redirecting input is: | |
7117c2d2 | 1876 | [N]<WORD |
ccc6cda3 | 1877 | |
37c41ab1 CR |
1878 | 3.6.2 Redirecting Output |
1879 | ------------------------ | |
ccc6cda3 | 1880 | |
37c41ab1 | 1881 | Redirection of output causes the file whose name results from the |
7117c2d2 JA |
1882 | expansion of WORD to be opened for writing on file descriptor N, or the |
1883 | standard output (file descriptor 1) if N is not specified. If the file | |
1884 | does not exist it is created; if it does exist it is truncated to zero | |
1885 | size. | |
ccc6cda3 JA |
1886 | |
1887 | The general format for redirecting output is: | |
7117c2d2 | 1888 | [N]>[|]WORD |
ccc6cda3 | 1889 | |
cce855bc JA |
1890 | If the redirection operator is `>', and the `noclobber' option to |
1891 | the `set' builtin has been enabled, the redirection will fail if the | |
bb70624e | 1892 | file whose name results from the expansion of WORD exists and is a |
cce855bc JA |
1893 | regular file. If the redirection operator is `>|', or the redirection |
1894 | operator is `>' and the `noclobber' option is not enabled, the | |
1895 | redirection is attempted even if the file named by WORD exists. | |
ccc6cda3 | 1896 | |
37c41ab1 CR |
1897 | 3.6.3 Appending Redirected Output |
1898 | --------------------------------- | |
ccc6cda3 | 1899 | |
37c41ab1 | 1900 | Redirection of output in this fashion causes the file whose name |
ccc6cda3 | 1901 | results from the expansion of WORD to be opened for appending on file |
7117c2d2 JA |
1902 | descriptor N, or the standard output (file descriptor 1) if N is not |
1903 | specified. If the file does not exist it is created. | |
ccc6cda3 JA |
1904 | |
1905 | The general format for appending output is: | |
7117c2d2 | 1906 | [N]>>WORD |
ccc6cda3 | 1907 | |
37c41ab1 CR |
1908 | 3.6.4 Redirecting Standard Output and Standard Error |
1909 | ---------------------------------------------------- | |
ccc6cda3 | 1910 | |
ed35cb4a CR |
1911 | This construct allows both the standard output (file descriptor 1) and |
1912 | the standard error output (file descriptor 2) to be redirected to the | |
1913 | file whose name is the expansion of WORD. | |
ccc6cda3 JA |
1914 | |
1915 | There are two formats for redirecting standard output and standard | |
1916 | error: | |
1917 | &>WORD | |
37c41ab1 | 1918 | and |
ccc6cda3 | 1919 | >&WORD |
37c41ab1 | 1920 | Of the two forms, the first is preferred. This is semantically |
ccc6cda3 JA |
1921 | equivalent to |
1922 | >WORD 2>&1 | |
1923 | ||
ed35cb4a CR |
1924 | 3.6.5 Appending Standard Output and Standard Error |
1925 | -------------------------------------------------- | |
1926 | ||
1927 | This construct allows both the standard output (file descriptor 1) and | |
1928 | the standard error output (file descriptor 2) to be appended to the | |
1929 | file whose name is the expansion of WORD. | |
1930 | ||
1931 | The format for appending standard output and standard error is: | |
1932 | &>>WORD | |
1933 | This is semantically equivalent to | |
1934 | >>WORD 2>&1 | |
1935 | ||
1936 | 3.6.6 Here Documents | |
37c41ab1 | 1937 | -------------------- |
ccc6cda3 | 1938 | |
37c41ab1 | 1939 | This type of redirection instructs the shell to read input from the |
ccc6cda3 JA |
1940 | current source until a line containing only WORD (with no trailing |
1941 | blanks) is seen. All of the lines read up to that point are then used | |
1942 | as the standard input for a command. | |
1943 | ||
7117c2d2 | 1944 | The format of here-documents is: |
ccc6cda3 JA |
1945 | <<[-]WORD |
1946 | HERE-DOCUMENT | |
1947 | DELIMITER | |
1948 | ||
bb70624e JA |
1949 | No parameter expansion, command substitution, arithmetic expansion, |
1950 | or filename expansion is performed on WORD. If any characters in WORD | |
ccc6cda3 | 1951 | are quoted, the DELIMITER is the result of quote removal on WORD, and |
cce855bc JA |
1952 | the lines in the here-document are not expanded. If WORD is unquoted, |
1953 | all lines of the here-document are subjected to parameter expansion, | |
1954 | command substitution, and arithmetic expansion. In the latter case, | |
bb70624e JA |
1955 | the character sequence `\newline' is ignored, and `\' must be used to |
1956 | quote the characters `\', `$', and ``'. | |
ccc6cda3 JA |
1957 | |
1958 | If the redirection operator is `<<-', then all leading tab | |
1959 | characters are stripped from input lines and the line containing | |
1960 | DELIMITER. This allows here-documents within shell scripts to be | |
1961 | indented in a natural fashion. | |
1962 | ||
ed35cb4a | 1963 | 3.6.7 Here Strings |
37c41ab1 | 1964 | ------------------ |
7117c2d2 | 1965 | |
37c41ab1 | 1966 | A variant of here documents, the format is: |
7117c2d2 JA |
1967 | <<< WORD |
1968 | ||
1969 | The WORD is expanded and supplied to the command on its standard | |
1970 | input. | |
1971 | ||
ed35cb4a | 1972 | 3.6.8 Duplicating File Descriptors |
37c41ab1 | 1973 | ---------------------------------- |
ccc6cda3 | 1974 | |
37c41ab1 | 1975 | The redirection operator |
7117c2d2 | 1976 | [N]<&WORD |
37c41ab1 CR |
1977 | is used to duplicate input file descriptors. If WORD expands to one |
1978 | or more digits, the file descriptor denoted by N is made to be a copy | |
1979 | of that file descriptor. If the digits in WORD do not specify a file | |
cce855bc | 1980 | descriptor open for input, a redirection error occurs. If WORD |
7117c2d2 JA |
1981 | evaluates to `-', file descriptor N is closed. If N is not specified, |
1982 | the standard input (file descriptor 0) is used. | |
ccc6cda3 JA |
1983 | |
1984 | The operator | |
7117c2d2 | 1985 | [N]>&WORD |
37c41ab1 | 1986 | is used similarly to duplicate output file descriptors. If N is not |
cce855bc JA |
1987 | specified, the standard output (file descriptor 1) is used. If the |
1988 | digits in WORD do not specify a file descriptor open for output, a | |
7117c2d2 JA |
1989 | redirection error occurs. As a special case, if N is omitted, and WORD |
1990 | does not expand to one or more digits, the standard output and standard | |
1991 | error are redirected as described previously. | |
1992 | ||
ed35cb4a | 1993 | 3.6.9 Moving File Descriptors |
37c41ab1 | 1994 | ----------------------------- |
7117c2d2 | 1995 | |
37c41ab1 | 1996 | The redirection operator |
7117c2d2 | 1997 | [N]<&DIGIT- |
37c41ab1 CR |
1998 | moves the file descriptor DIGIT to file descriptor N, or the |
1999 | standard input (file descriptor 0) if N is not specified. DIGIT is | |
2000 | closed after being duplicated to N. | |
7117c2d2 JA |
2001 | |
2002 | Similarly, the redirection operator | |
2003 | [N]>&DIGIT- | |
37c41ab1 CR |
2004 | moves the file descriptor DIGIT to file descriptor N, or the |
2005 | standard output (file descriptor 1) if N is not specified. | |
7117c2d2 | 2006 | |
ed35cb4a CR |
2007 | 3.6.10 Opening File Descriptors for Reading and Writing |
2008 | ------------------------------------------------------- | |
ccc6cda3 | 2009 | |
37c41ab1 | 2010 | The redirection operator |
7117c2d2 | 2011 | [N]<>WORD |
37c41ab1 | 2012 | causes the file whose name is the expansion of WORD to be opened for |
7117c2d2 JA |
2013 | both reading and writing on file descriptor N, or on file descriptor 0 |
2014 | if N is not specified. If the file does not exist, it is created. | |
ccc6cda3 JA |
2015 | |
2016 | \1f | |
2017 | File: bashref.info, Node: Executing Commands, Next: Shell Scripts, Prev: Redirections, Up: Basic Shell Features | |
2018 | ||
37c41ab1 CR |
2019 | 3.7 Executing Commands |
2020 | ====================== | |
ccc6cda3 JA |
2021 | |
2022 | * Menu: | |
2023 | ||
cce855bc JA |
2024 | * Simple Command Expansion:: How Bash expands simple commands before |
2025 | executing them. | |
ccc6cda3 | 2026 | * Command Search and Execution:: How Bash finds commands and runs them. |
cce855bc JA |
2027 | * Command Execution Environment:: The environment in which Bash |
2028 | executes commands that are not | |
2029 | shell builtins. | |
ccc6cda3 | 2030 | * Environment:: The environment given to a command. |
ccc6cda3 JA |
2031 | * Exit Status:: The status returned by commands and how Bash |
2032 | interprets it. | |
ccc6cda3 JA |
2033 | * Signals:: What happens when Bash or a command it runs |
2034 | receives a signal. | |
2035 | ||
2036 | \1f | |
cce855bc JA |
2037 | File: bashref.info, Node: Simple Command Expansion, Next: Command Search and Execution, Up: Executing Commands |
2038 | ||
37c41ab1 CR |
2039 | 3.7.1 Simple Command Expansion |
2040 | ------------------------------ | |
cce855bc | 2041 | |
37c41ab1 | 2042 | When a simple command is executed, the shell performs the following |
cce855bc JA |
2043 | expansions, assignments, and redirections, from left to right. |
2044 | ||
2045 | 1. The words that the parser has marked as variable assignments (those | |
2046 | preceding the command name) and redirections are saved for later | |
2047 | processing. | |
2048 | ||
2049 | 2. The words that are not variable assignments or redirections are | |
28ef6c31 | 2050 | expanded (*note Shell Expansions::). If any words remain after |
cce855bc JA |
2051 | expansion, the first word is taken to be the name of the command |
2052 | and the remaining words are the arguments. | |
2053 | ||
2054 | 3. Redirections are performed as described above (*note | |
28ef6c31 | 2055 | Redirections::). |
cce855bc JA |
2056 | |
2057 | 4. The text after the `=' in each variable assignment undergoes tilde | |
2058 | expansion, parameter expansion, command substitution, arithmetic | |
2059 | expansion, and quote removal before being assigned to the variable. | |
2060 | ||
2061 | If no command name results, the variable assignments affect the | |
2062 | current shell environment. Otherwise, the variables are added to the | |
2063 | environment of the executed command and do not affect the current shell | |
2064 | environment. If any of the assignments attempts to assign a value to a | |
2065 | readonly variable, an error occurs, and the command exits with a | |
2066 | non-zero status. | |
2067 | ||
2068 | If no command name results, redirections are performed, but do not | |
2069 | affect the current shell environment. A redirection error causes the | |
2070 | command to exit with a non-zero status. | |
2071 | ||
2072 | If there is a command name left after expansion, execution proceeds | |
2073 | as described below. Otherwise, the command exits. If one of the | |
2074 | expansions contained a command substitution, the exit status of the | |
2075 | command is the exit status of the last command substitution performed. | |
2076 | If there were no command substitutions, the command exits with a status | |
2077 | of zero. | |
2078 | ||
2079 | \1f | |
2080 | File: bashref.info, Node: Command Search and Execution, Next: Command Execution Environment, Prev: Simple Command Expansion, Up: Executing Commands | |
ccc6cda3 | 2081 | |
37c41ab1 CR |
2082 | 3.7.2 Command Search and Execution |
2083 | ---------------------------------- | |
ccc6cda3 | 2084 | |
37c41ab1 | 2085 | After a command has been split into words, if it results in a simple |
ccc6cda3 JA |
2086 | command and an optional list of arguments, the following actions are |
2087 | taken. | |
2088 | ||
2089 | 1. If the command name contains no slashes, the shell attempts to | |
2090 | locate it. If there exists a shell function by that name, that | |
6a8fd0ed | 2091 | function is invoked as described in *note Shell Functions::. |
ccc6cda3 JA |
2092 | |
2093 | 2. If the name does not match a function, the shell searches for it | |
2094 | in the list of shell builtins. If a match is found, that builtin | |
2095 | is invoked. | |
2096 | ||
2097 | 3. If the name is neither a shell function nor a builtin, and | |
2098 | contains no slashes, Bash searches each element of `$PATH' for a | |
2099 | directory containing an executable file by that name. Bash uses a | |
cce855bc JA |
2100 | hash table to remember the full pathnames of executable files to |
2101 | avoid multiple `PATH' searches (see the description of `hash' in | |
6a8fd0ed | 2102 | *note Bourne Shell Builtins::). A full search of the directories |
ccc6cda3 | 2103 | in `$PATH' is performed only if the command is not found in the |
ed35cb4a CR |
2104 | hash table. If the search is unsuccessful, the shell searches for |
2105 | a defined shell function named `command_not_found_handle'. If | |
2106 | that function exists, it is invoked with the original command and | |
2107 | the original command's arguments as its arguments, and the | |
2108 | function's exit status becomes the exit status of the shell. If | |
2109 | that function is not defined, the shell prints an error message | |
2110 | and returns an exit status of 127. | |
ccc6cda3 JA |
2111 | |
2112 | 4. If the search is successful, or if the command name contains one | |
cce855bc JA |
2113 | or more slashes, the shell executes the named program in a |
2114 | separate execution environment. Argument 0 is set to the name | |
2115 | given, and the remaining arguments to the command are set to the | |
2116 | arguments supplied, if any. | |
ccc6cda3 JA |
2117 | |
2118 | 5. If this execution fails because the file is not in executable | |
cce855bc | 2119 | format, and the file is not a directory, it is assumed to be a |
6a8fd0ed | 2120 | SHELL SCRIPT and the shell executes it as described in *note Shell |
cce855bc JA |
2121 | Scripts::. |
2122 | ||
2123 | 6. If the command was not begun asynchronously, the shell waits for | |
2124 | the command to complete and collects its exit status. | |
2125 | ||
2126 | ||
2127 | \1f | |
2128 | File: bashref.info, Node: Command Execution Environment, Next: Environment, Prev: Command Search and Execution, Up: Executing Commands | |
2129 | ||
37c41ab1 CR |
2130 | 3.7.3 Command Execution Environment |
2131 | ----------------------------------- | |
cce855bc | 2132 | |
37c41ab1 | 2133 | The shell has an EXECUTION ENVIRONMENT, which consists of the following: |
cce855bc JA |
2134 | |
2135 | * open files inherited by the shell at invocation, as modified by | |
2136 | redirections supplied to the `exec' builtin | |
2137 | ||
2138 | * the current working directory as set by `cd', `pushd', or `popd', | |
2139 | or inherited by the shell at invocation | |
2140 | ||
2141 | * the file creation mode mask as set by `umask' or inherited from | |
2142 | the shell's parent | |
2143 | ||
2144 | * current traps set by `trap' | |
2145 | ||
2146 | * shell parameters that are set by variable assignment or with `set' | |
2147 | or inherited from the shell's parent in the environment | |
2148 | ||
2149 | * shell functions defined during execution or inherited from the | |
2150 | shell's parent in the environment | |
2151 | ||
2152 | * options enabled at invocation (either by default or with | |
2153 | command-line arguments) or by `set' | |
2154 | ||
d3ad40de | 2155 | * options enabled by `shopt' (*note The Shopt Builtin::) |
cce855bc | 2156 | |
28ef6c31 | 2157 | * shell aliases defined with `alias' (*note Aliases::) |
cce855bc JA |
2158 | |
2159 | * various process IDs, including those of background jobs (*note | |
28ef6c31 JA |
2160 | Lists::), the value of `$$', and the value of `$PPID' |
2161 | ||
cce855bc JA |
2162 | |
2163 | When a simple command other than a builtin or shell function is to | |
2164 | be executed, it is invoked in a separate execution environment that | |
2165 | consists of the following. Unless otherwise noted, the values are | |
2166 | inherited from the shell. | |
2167 | ||
2168 | * the shell's open files, plus any modifications and additions | |
2169 | specified by redirections to the command | |
2170 | ||
2171 | * the current working directory | |
2172 | ||
2173 | * the file creation mode mask | |
2174 | ||
d3a24ed2 CR |
2175 | * shell variables and functions marked for export, along with |
2176 | variables exported for the command, passed in the environment | |
2177 | (*note Environment::) | |
cce855bc JA |
2178 | |
2179 | * traps caught by the shell are reset to the values inherited from | |
2180 | the shell's parent, and traps ignored by the shell are ignored | |
2181 | ||
28ef6c31 | 2182 | |
cce855bc JA |
2183 | A command invoked in this separate environment cannot affect the |
2184 | shell's execution environment. | |
2185 | ||
d3a24ed2 CR |
2186 | Command substitution, commands grouped with parentheses, and |
2187 | asynchronous commands are invoked in a subshell environment that is a | |
2188 | duplicate of the shell environment, except that traps caught by the | |
2189 | shell are reset to the values that the shell inherited from its parent | |
2190 | at invocation. Builtin commands that are invoked as part of a pipeline | |
2191 | are also executed in a subshell environment. Changes made to the | |
2192 | subshell environment cannot affect the shell's execution environment. | |
ccc6cda3 | 2193 | |
db31fb26 CR |
2194 | Subshells spawned to execute command substitutions inherit the value |
2195 | of the `-e' option from the parent shell. When not in POSIX mode, Bash | |
2196 | clears the `-e' option in such subshells. | |
2197 | ||
f73dda09 JA |
2198 | If a command is followed by a `&' and job control is not active, the |
2199 | default standard input for the command is the empty file `/dev/null'. | |
2200 | Otherwise, the invoked command inherits the file descriptors of the | |
2201 | calling shell as modified by redirections. | |
2202 | ||
ccc6cda3 | 2203 | \1f |
cce855bc | 2204 | File: bashref.info, Node: Environment, Next: Exit Status, Prev: Command Execution Environment, Up: Executing Commands |
ccc6cda3 | 2205 | |
37c41ab1 CR |
2206 | 3.7.4 Environment |
2207 | ----------------- | |
ccc6cda3 | 2208 | |
37c41ab1 | 2209 | When a program is invoked it is given an array of strings called the |
ccc6cda3 JA |
2210 | ENVIRONMENT. This is a list of name-value pairs, of the form |
2211 | `name=value'. | |
2212 | ||
bb70624e | 2213 | Bash provides several ways to manipulate the environment. On |
ccc6cda3 JA |
2214 | invocation, the shell scans its own environment and creates a parameter |
2215 | for each name found, automatically marking it for EXPORT to child | |
2216 | processes. Executed commands inherit the environment. The `export' | |
2217 | and `declare -x' commands allow parameters and functions to be added to | |
2218 | and deleted from the environment. If the value of a parameter in the | |
2219 | environment is modified, the new value becomes part of the environment, | |
2220 | replacing the old. The environment inherited by any executed command | |
2221 | consists of the shell's initial environment, whose values may be | |
cce855bc JA |
2222 | modified in the shell, less any pairs removed by the `unset' and |
2223 | `export -n' commands, plus any additions via the `export' and `declare | |
2224 | -x' commands. | |
ccc6cda3 JA |
2225 | |
2226 | The environment for any simple command or function may be augmented | |
2227 | temporarily by prefixing it with parameter assignments, as described in | |
6a8fd0ed | 2228 | *note Shell Parameters::. These assignment statements affect only the |
ccc6cda3 JA |
2229 | environment seen by that command. |
2230 | ||
28ef6c31 | 2231 | If the `-k' option is set (*note The Set Builtin::), then all |
ccc6cda3 JA |
2232 | parameter assignments are placed in the environment for a command, not |
2233 | just those that precede the command name. | |
2234 | ||
2235 | When Bash invokes an external command, the variable `$_' is set to | |
2236 | the full path name of the command and passed to that command in its | |
2237 | environment. | |
2238 | ||
2239 | \1f | |
2240 | File: bashref.info, Node: Exit Status, Next: Signals, Prev: Environment, Up: Executing Commands | |
2241 | ||
37c41ab1 CR |
2242 | 3.7.5 Exit Status |
2243 | ----------------- | |
ccc6cda3 | 2244 | |
29d25b54 CR |
2245 | The exit status of an executed command is the value returned by the |
2246 | WAITPID system call or equivalent function. Exit statuses fall between | |
2247 | 0 and 255, though, as explained below, the shell may use values above | |
2248 | 125 specially. Exit statuses from shell builtins and compound commands | |
2249 | are also limited to this range. Under certain circumstances, the shell | |
2250 | will use special values to indicate specific failure modes. | |
2251 | ||
2252 | For the shell's purposes, a command which exits with a zero exit | |
2253 | status has succeeded. A non-zero exit status indicates failure. This | |
cce855bc JA |
2254 | seemingly counter-intuitive scheme is used so there is one well-defined |
2255 | way to indicate success and a variety of ways to indicate various | |
2256 | failure modes. When a command terminates on a fatal signal whose | |
2257 | number is N, Bash uses the value 128+N as the exit status. | |
ccc6cda3 JA |
2258 | |
2259 | If a command is not found, the child process created to execute it | |
2260 | returns a status of 127. If a command is found but is not executable, | |
2261 | the return status is 126. | |
2262 | ||
cce855bc JA |
2263 | If a command fails because of an error during expansion or |
2264 | redirection, the exit status is greater than zero. | |
2265 | ||
ccc6cda3 | 2266 | The exit status is used by the Bash conditional commands (*note |
28ef6c31 JA |
2267 | Conditional Constructs::) and some of the list constructs (*note |
2268 | Lists::). | |
ccc6cda3 JA |
2269 | |
2270 | All of the Bash builtins return an exit status of zero if they | |
2271 | succeed and a non-zero status on failure, so they may be used by the | |
cce855bc JA |
2272 | conditional and list constructs. All builtins return an exit status of |
2273 | 2 to indicate incorrect usage. | |
ccc6cda3 JA |
2274 | |
2275 | \1f | |
2276 | File: bashref.info, Node: Signals, Prev: Exit Status, Up: Executing Commands | |
2277 | ||
37c41ab1 CR |
2278 | 3.7.6 Signals |
2279 | ------------- | |
ccc6cda3 | 2280 | |
37c41ab1 | 2281 | When Bash is interactive, in the absence of any traps, it ignores |
cce855bc JA |
2282 | `SIGTERM' (so that `kill 0' does not kill an interactive shell), and |
2283 | `SIGINT' is caught and handled (so that the `wait' builtin is | |
2284 | interruptible). When Bash receives a `SIGINT', it breaks out of any | |
2285 | executing loops. In all cases, Bash ignores `SIGQUIT'. If job control | |
28ef6c31 | 2286 | is in effect (*note Job Control::), Bash ignores `SIGTTIN', `SIGTTOU', |
cce855bc | 2287 | and `SIGTSTP'. |
ccc6cda3 | 2288 | |
5e13499c CR |
2289 | Non-builtin commands started by Bash have signal handlers set to the |
2290 | values inherited by the shell from its parent. When job control is not | |
2291 | in effect, asynchronous commands ignore `SIGINT' and `SIGQUIT' in | |
2292 | addition to these inherited handlers. Commands run as a result of | |
2293 | command substitution ignore the keyboard-generated job control signals | |
2294 | `SIGTTIN', `SIGTTOU', and `SIGTSTP'. | |
ccc6cda3 JA |
2295 | |
2296 | The shell exits by default upon receipt of a `SIGHUP'. Before | |
f73dda09 JA |
2297 | exiting, an interactive shell resends the `SIGHUP' to all jobs, running |
2298 | or stopped. Stopped jobs are sent `SIGCONT' to ensure that they receive | |
2299 | the `SIGHUP'. To prevent the shell from sending the `SIGHUP' signal to | |
2300 | a particular job, it should be removed from the jobs table with the | |
28ef6c31 | 2301 | `disown' builtin (*note Job Control Builtins::) or marked to not |
cce855bc JA |
2302 | receive `SIGHUP' using `disown -h'. |
2303 | ||
2304 | If the `huponexit' shell option has been set with `shopt' (*note | |
d3ad40de CR |
2305 | The Shopt Builtin::), Bash sends a `SIGHUP' to all jobs when an |
2306 | interactive login shell exits. | |
cce855bc | 2307 | |
5e13499c CR |
2308 | If Bash is waiting for a command to complete and receives a signal |
2309 | for which a trap has been set, the trap will not be executed until the | |
2310 | command completes. When Bash is waiting for an asynchronous command | |
2311 | via the `wait' builtin, the reception of a signal for which a trap has | |
2312 | been set will cause the `wait' builtin to return immediately with an | |
2313 | exit status greater than 128, immediately after which the trap is | |
2314 | executed. | |
ccc6cda3 JA |
2315 | |
2316 | \1f | |
2317 | File: bashref.info, Node: Shell Scripts, Prev: Executing Commands, Up: Basic Shell Features | |
2318 | ||
37c41ab1 CR |
2319 | 3.8 Shell Scripts |
2320 | ================= | |
ccc6cda3 | 2321 | |
37c41ab1 CR |
2322 | A shell script is a text file containing shell commands. When such a |
2323 | file is used as the first non-option argument when invoking Bash, and | |
28ef6c31 | 2324 | neither the `-c' nor `-s' option is supplied (*note Invoking Bash::), |
ccc6cda3 | 2325 | Bash reads and executes commands from the file, then exits. This mode |
f73dda09 JA |
2326 | of operation creates a non-interactive shell. The shell first searches |
2327 | for the file in the current directory, and looks in the directories in | |
2328 | `$PATH' if not found there. | |
2329 | ||
2330 | When Bash runs a shell script, it sets the special parameter `0' to | |
2331 | the name of the file, rather than the name of the shell, and the | |
2332 | positional parameters are set to the remaining arguments, if any are | |
2333 | given. If no additional arguments are supplied, the positional | |
2334 | parameters are unset. | |
ccc6cda3 JA |
2335 | |
2336 | A shell script may be made executable by using the `chmod' command | |
2337 | to turn on the execute bit. When Bash finds such a file while | |
2338 | searching the `$PATH' for a command, it spawns a subshell to execute | |
2339 | it. In other words, executing | |
2340 | filename ARGUMENTS | |
37c41ab1 | 2341 | is equivalent to executing |
ccc6cda3 JA |
2342 | bash filename ARGUMENTS |
2343 | ||
2344 | if `filename' is an executable shell script. This subshell | |
2345 | reinitializes itself, so that the effect is as if a new shell had been | |
cce855bc JA |
2346 | invoked to interpret the script, with the exception that the locations |
2347 | of commands remembered by the parent (see the description of `hash' in | |
6a8fd0ed | 2348 | *note Bourne Shell Builtins::) are retained by the child. |
ccc6cda3 | 2349 | |
bb70624e JA |
2350 | Most versions of Unix make this a part of the operating system's |
2351 | command execution mechanism. If the first line of a script begins with | |
2352 | the two characters `#!', the remainder of the line specifies an | |
2353 | interpreter for the program. Thus, you can specify Bash, `awk', Perl, | |
2354 | or some other interpreter and write the rest of the script file in that | |
2355 | language. | |
2356 | ||
2357 | The arguments to the interpreter consist of a single optional | |
2358 | argument following the interpreter name on the first line of the script | |
2359 | file, followed by the name of the script file, followed by the rest of | |
2360 | the arguments. Bash will perform this action on operating systems that | |
2361 | do not handle it themselves. Note that some older versions of Unix | |
2362 | limit the interpreter name and argument to a maximum of 32 characters. | |
2363 | ||
2364 | Bash scripts often begin with `#! /bin/bash' (assuming that Bash has | |
2365 | been installed in `/bin'), since this ensures that Bash will be used to | |
2366 | interpret the script, even if it is executed under another shell. | |
ccc6cda3 JA |
2367 | |
2368 | \1f | |
bb70624e | 2369 | File: bashref.info, Node: Shell Builtin Commands, Next: Shell Variables, Prev: Basic Shell Features, Up: Top |
ccc6cda3 | 2370 | |
37c41ab1 CR |
2371 | 4 Shell Builtin Commands |
2372 | ************************ | |
ccc6cda3 JA |
2373 | |
2374 | * Menu: | |
2375 | ||
2376 | * Bourne Shell Builtins:: Builtin commands inherited from the Bourne | |
2377 | Shell. | |
bb70624e | 2378 | * Bash Builtins:: Table of builtins specific to Bash. |
d3ad40de CR |
2379 | * Modifying Shell Behavior:: Builtins to modify shell attributes and |
2380 | optional behavior. | |
bb70624e | 2381 | * Special Builtins:: Builtin commands classified specially by |
ac18b312 | 2382 | POSIX. |
bb70624e JA |
2383 | |
2384 | Builtin commands are contained within the shell itself. When the | |
2385 | name of a builtin command is used as the first word of a simple command | |
28ef6c31 | 2386 | (*note Simple Commands::), the shell executes the command directly, |
bb70624e JA |
2387 | without invoking another program. Builtin commands are necessary to |
2388 | implement functionality impossible or inconvenient to obtain with | |
2389 | separate utilities. | |
ccc6cda3 | 2390 | |
ac18b312 CR |
2391 | This section briefly describes the builtins which Bash inherits from |
2392 | the Bourne Shell, as well as the builtin commands which are unique to | |
2393 | or have been extended in Bash. | |
bb70624e JA |
2394 | |
2395 | Several builtin commands are described in other chapters: builtin | |
2396 | commands which provide the Bash interface to the job control facilities | |
28ef6c31 JA |
2397 | (*note Job Control Builtins::), the directory stack (*note Directory |
2398 | Stack Builtins::), the command history (*note Bash History Builtins::), | |
2399 | and the programmable completion facilities (*note Programmable | |
2400 | Completion Builtins::). | |
bb70624e JA |
2401 | |
2402 | Many of the builtins have been extended by POSIX or Bash. | |
ccc6cda3 | 2403 | |
c2258e1c CR |
2404 | Unless otherwise noted, each builtin command documented as accepting |
2405 | options preceded by `-' accepts `--' to signify the end of the options. | |
6932f7f5 CR |
2406 | The `:', `true', `false', and `test' builtins do not accept options and |
2407 | do not treat `--' specially. The `exit', `logout', `break', | |
2408 | `continue', `let', and `shift' builtins accept and process arguments | |
2409 | beginning with `-' without requiring `--'. Other builtins that accept | |
2410 | arguments but are not specified as accepting options interpret | |
2411 | arguments beginning with `-' as invalid options and require `--' to | |
2412 | prevent this interpretation. | |
c2258e1c | 2413 | |
ccc6cda3 | 2414 | \1f |
bb70624e | 2415 | File: bashref.info, Node: Bourne Shell Builtins, Next: Bash Builtins, Up: Shell Builtin Commands |
ccc6cda3 | 2416 | |
37c41ab1 CR |
2417 | 4.1 Bourne Shell Builtins |
2418 | ========================= | |
ccc6cda3 | 2419 | |
37c41ab1 | 2420 | The following shell builtin commands are inherited from the Bourne |
ac18b312 | 2421 | Shell. These commands are implemented as specified by the POSIX |
ccc6cda3 JA |
2422 | standard. |
2423 | ||
bb70624e | 2424 | `: (a colon)' |
ccc6cda3 JA |
2425 | : [ARGUMENTS] |
2426 | Do nothing beyond expanding ARGUMENTS and performing redirections. | |
cce855bc | 2427 | The return status is zero. |
ccc6cda3 | 2428 | |
bb70624e | 2429 | `. (a period)' |
b72432fd | 2430 | . FILENAME [ARGUMENTS] |
ccc6cda3 | 2431 | Read and execute commands from the FILENAME argument in the |
cce855bc | 2432 | current shell context. If FILENAME does not contain a slash, the |
28ef6c31 JA |
2433 | `PATH' variable is used to find FILENAME. When Bash is not in |
2434 | POSIX mode, the current directory is searched if FILENAME is not | |
2435 | found in `$PATH'. If any ARGUMENTS are supplied, they become the | |
2436 | positional parameters when FILENAME is executed. Otherwise the | |
2437 | positional parameters are unchanged. The return status is the | |
2438 | exit status of the last command executed, or zero if no commands | |
2439 | are executed. If FILENAME is not found, or cannot be read, the | |
2440 | return status is non-zero. This builtin is equivalent to `source'. | |
ccc6cda3 JA |
2441 | |
2442 | `break' | |
2443 | break [N] | |
2444 | Exit from a `for', `while', `until', or `select' loop. If N is | |
cce855bc JA |
2445 | supplied, the Nth enclosing loop is exited. N must be greater |
2446 | than or equal to 1. The return status is zero unless N is not | |
2447 | greater than or equal to 1. | |
ccc6cda3 JA |
2448 | |
2449 | `cd' | |
7117c2d2 | 2450 | cd [-L|-P] [DIRECTORY] |
ccc6cda3 JA |
2451 | Change the current working directory to DIRECTORY. If DIRECTORY |
2452 | is not given, the value of the `HOME' shell variable is used. If | |
2453 | the shell variable `CDPATH' exists, it is used as a search path. | |
d3a24ed2 CR |
2454 | If DIRECTORY begins with a slash, `CDPATH' is not used. |
2455 | ||
2456 | The `-P' option means to not follow symbolic links; symbolic links | |
2457 | are followed by default or with the `-L' option. If DIRECTORY is | |
2458 | `-', it is equivalent to `$OLDPWD'. | |
2459 | ||
2460 | If a non-empty directory name from `CDPATH' is used, or if `-' is | |
2461 | the first argument, and the directory change is successful, the | |
2462 | absolute pathname of the new working directory is written to the | |
2463 | standard output. | |
2464 | ||
2465 | The return status is zero if the directory is successfully changed, | |
2466 | non-zero otherwise. | |
ccc6cda3 JA |
2467 | |
2468 | `continue' | |
2469 | continue [N] | |
2470 | Resume the next iteration of an enclosing `for', `while', `until', | |
2471 | or `select' loop. If N is supplied, the execution of the Nth | |
cce855bc JA |
2472 | enclosing loop is resumed. N must be greater than or equal to 1. |
2473 | The return status is zero unless N is not greater than or equal to | |
2474 | 1. | |
ccc6cda3 JA |
2475 | |
2476 | `eval' | |
2477 | eval [ARGUMENTS] | |
2478 | The arguments are concatenated together into a single command, | |
cce855bc JA |
2479 | which is then read and executed, and its exit status returned as |
2480 | the exit status of `eval'. If there are no arguments or only | |
2481 | empty arguments, the return status is zero. | |
ccc6cda3 JA |
2482 | |
2483 | `exec' | |
cce855bc JA |
2484 | exec [-cl] [-a NAME] [COMMAND [ARGUMENTS]] |
2485 | If COMMAND is supplied, it replaces the shell without creating a | |
2486 | new process. If the `-l' option is supplied, the shell places a | |
d3ad40de CR |
2487 | dash at the beginning of the zeroth argument passed to COMMAND. |
2488 | This is what the `login' program does. The `-c' option causes | |
2489 | COMMAND to be executed with an empty environment. If `-a' is | |
2490 | supplied, the shell passes NAME as the zeroth argument to COMMAND. | |
2491 | If no COMMAND is specified, redirections may be used to affect the | |
cce855bc JA |
2492 | current shell environment. If there are no redirection errors, the |
2493 | return status is zero; otherwise the return status is non-zero. | |
ccc6cda3 JA |
2494 | |
2495 | `exit' | |
2496 | exit [N] | |
bb70624e JA |
2497 | Exit the shell, returning a status of N to the shell's parent. If |
2498 | N is omitted, the exit status is that of the last command executed. | |
cce855bc | 2499 | Any trap on `EXIT' is executed before the shell terminates. |
ccc6cda3 JA |
2500 | |
2501 | `export' | |
2502 | export [-fn] [-p] [NAME[=VALUE]] | |
2503 | Mark each NAME to be passed to child processes in the environment. | |
2504 | If the `-f' option is supplied, the NAMEs refer to shell | |
cce855bc JA |
2505 | functions; otherwise the names refer to shell variables. The `-n' |
2506 | option means to no longer mark each NAME for export. If no NAMES | |
2507 | are supplied, or if the `-p' option is given, a list of exported | |
2508 | names is displayed. The `-p' option displays output in a form | |
d3a24ed2 CR |
2509 | that may be reused as input. If a variable name is followed by |
2510 | =VALUE, the value of the variable is set to VALUE. | |
2511 | ||
2512 | The return status is zero unless an invalid option is supplied, | |
2513 | one of the names is not a valid shell variable name, or `-f' is | |
2514 | supplied with a name that is not a shell function. | |
ccc6cda3 JA |
2515 | |
2516 | `getopts' | |
2517 | getopts OPTSTRING NAME [ARGS] | |
2518 | `getopts' is used by shell scripts to parse positional parameters. | |
bb70624e JA |
2519 | OPTSTRING contains the option characters to be recognized; if a |
2520 | character is followed by a colon, the option is expected to have an | |
2521 | argument, which should be separated from it by white space. The | |
2522 | colon (`:') and question mark (`?') may not be used as option | |
2523 | characters. Each time it is invoked, `getopts' places the next | |
2524 | option in the shell variable NAME, initializing NAME if it does | |
2525 | not exist, and the index of the next argument to be processed into | |
2526 | the variable `OPTIND'. `OPTIND' is initialized to 1 each time the | |
2527 | shell or a shell script is invoked. When an option requires an | |
2528 | argument, `getopts' places that argument into the variable | |
2529 | `OPTARG'. The shell does not reset `OPTIND' automatically; it | |
2530 | must be manually reset between multiple calls to `getopts' within | |
2531 | the same shell invocation if a new set of parameters is to be used. | |
ccc6cda3 | 2532 | |
cce855bc JA |
2533 | When the end of options is encountered, `getopts' exits with a |
2534 | return value greater than zero. `OPTIND' is set to the index of | |
2535 | the first non-option argument, and `name' is set to `?'. | |
2536 | ||
2537 | `getopts' normally parses the positional parameters, but if more | |
2538 | arguments are given in ARGS, `getopts' parses those instead. | |
2539 | ||
ccc6cda3 JA |
2540 | `getopts' can report errors in two ways. If the first character of |
2541 | OPTSTRING is a colon, SILENT error reporting is used. In normal | |
cce855bc | 2542 | operation diagnostic messages are printed when invalid options or |
ccc6cda3 | 2543 | missing option arguments are encountered. If the variable `OPTERR' |
cce855bc | 2544 | is set to 0, no error messages will be displayed, even if the first |
ccc6cda3 JA |
2545 | character of `optstring' is not a colon. |
2546 | ||
cce855bc | 2547 | If an invalid option is seen, `getopts' places `?' into NAME and, |
ccc6cda3 JA |
2548 | if not silent, prints an error message and unsets `OPTARG'. If |
2549 | `getopts' is silent, the option character found is placed in | |
2550 | `OPTARG' and no diagnostic message is printed. | |
2551 | ||
2552 | If a required argument is not found, and `getopts' is not silent, | |
2553 | a question mark (`?') is placed in NAME, `OPTARG' is unset, and a | |
2554 | diagnostic message is printed. If `getopts' is silent, then a | |
2555 | colon (`:') is placed in NAME and `OPTARG' is set to the option | |
2556 | character found. | |
2557 | ||
ccc6cda3 | 2558 | `hash' |
ac18b312 | 2559 | hash [-r] [-p FILENAME] [-dt] [NAME] |
cce855bc JA |
2560 | Remember the full pathnames of commands specified as NAME |
2561 | arguments, so they need not be searched for on subsequent | |
2562 | invocations. The commands are found by searching through the | |
2563 | directories listed in `$PATH'. The `-p' option inhibits the path | |
2564 | search, and FILENAME is used as the location of NAME. The `-r' | |
7117c2d2 JA |
2565 | option causes the shell to forget all remembered locations. The |
2566 | `-d' option causes the shell to forget the remembered location of | |
2567 | each NAME. If the `-t' option is supplied, the full pathname to | |
2568 | which each NAME corresponds is printed. If multiple NAME | |
2569 | arguments are supplied with `-t' the NAME is printed before the | |
2570 | hashed full pathname. The `-l' option causes output to be | |
2571 | displayed in a format that may be reused as input. If no | |
2572 | arguments are given, or if only `-l' is supplied, information | |
2573 | about remembered commands is printed. The return status is zero | |
2574 | unless a NAME is not found or an invalid option is supplied. | |
ccc6cda3 JA |
2575 | |
2576 | `pwd' | |
2577 | pwd [-LP] | |
bb70624e JA |
2578 | Print the absolute pathname of the current working directory. If |
2579 | the `-P' option is supplied, the pathname printed will not contain | |
2580 | symbolic links. If the `-L' option is supplied, the pathname | |
2581 | printed may contain symbolic links. The return status is zero | |
2582 | unless an error is encountered while determining the name of the | |
2583 | current directory or an invalid option is supplied. | |
ccc6cda3 JA |
2584 | |
2585 | `readonly' | |
09767ff0 | 2586 | readonly [-aApf] [NAME[=VALUE]] ... |
cce855bc JA |
2587 | Mark each NAME as readonly. The values of these names may not be |
2588 | changed by subsequent assignment. If the `-f' option is supplied, | |
2589 | each NAME refers to a shell function. The `-a' option means each | |
09767ff0 CR |
2590 | NAME refers to an indexed array variable; the `-A' option means |
2591 | each NAME refers to an associative array variable. If no NAME | |
2592 | arguments are given, or if the `-p' option is supplied, a list of | |
2593 | all readonly names is printed. The `-p' option causes output to | |
2594 | be displayed in a format that may be reused as input. If a | |
2595 | variable name is followed by =VALUE, the value of the variable is | |
2596 | set to VALUE. The return status is zero unless an invalid option | |
2597 | is supplied, one of the NAME arguments is not a valid shell | |
2598 | variable or function name, or the `-f' option is supplied with a | |
2599 | name that is not a shell function. | |
ccc6cda3 JA |
2600 | |
2601 | `return' | |
2602 | return [N] | |
bb70624e JA |
2603 | Cause a shell function to exit with the return value N. If N is |
2604 | not supplied, the return value is the exit status of the last | |
2605 | command executed in the function. This may also be used to | |
2606 | terminate execution of a script being executed with the `.' (or | |
2607 | `source') builtin, returning either N or the exit status of the | |
cce855bc | 2608 | last command executed within the script as the exit status of the |
d3a24ed2 CR |
2609 | script. Any command associated with the `RETURN' trap is executed |
2610 | before execution resumes after the function or script. The return | |
2611 | status is non-zero if `return' is used outside a function and not | |
2612 | during the execution of a script by `.' or `source'. | |
ccc6cda3 JA |
2613 | |
2614 | `shift' | |
2615 | shift [N] | |
cce855bc | 2616 | Shift the positional parameters to the left by N. The positional |
d3ad40de CR |
2617 | parameters from N+1 ... `$#' are renamed to `$1' ... `$#'-N. |
2618 | Parameters represented by the numbers `$#' to `$#'-N+1 are unset. | |
2619 | N must be a non-negative number less than or equal to `$#'. If N | |
2620 | is zero or greater than `$#', the positional parameters are not | |
bb70624e JA |
2621 | changed. If N is not supplied, it is assumed to be 1. The return |
2622 | status is zero unless N is greater than `$#' or less than zero, | |
2623 | non-zero otherwise. | |
ccc6cda3 JA |
2624 | |
2625 | `test' | |
2626 | `[' | |
cce855bc JA |
2627 | Evaluate a conditional expression EXPR. Each operator and operand |
2628 | must be a separate argument. Expressions are composed of the | |
6a8fd0ed | 2629 | primaries described below in *note Bash Conditional Expressions::. |
1c72c0cd CR |
2630 | `test' does not accept any options, nor does it accept and ignore |
2631 | an argument of `--' as signifying the end of options. | |
cce855bc | 2632 | |
bb70624e JA |
2633 | When the `[' form is used, the last argument to the command must |
2634 | be a `]'. | |
2635 | ||
cce855bc | 2636 | Expressions may be combined using the following operators, listed |
d7f49990 CR |
2637 | in decreasing order of precedence. The evaluation depends on the |
2638 | number of arguments; see below. | |
cce855bc JA |
2639 | |
2640 | `! EXPR' | |
2641 | True if EXPR is false. | |
2642 | ||
2643 | `( EXPR )' | |
2644 | Returns the value of EXPR. This may be used to override the | |
2645 | normal precedence of operators. | |
2646 | ||
2647 | `EXPR1 -a EXPR2' | |
2648 | True if both EXPR1 and EXPR2 are true. | |
2649 | ||
2650 | `EXPR1 -o EXPR2' | |
2651 | True if either EXPR1 or EXPR2 is true. | |
2652 | ||
2653 | The `test' and `[' builtins evaluate conditional expressions using | |
2654 | a set of rules based on the number of arguments. | |
2655 | ||
2656 | 0 arguments | |
2657 | The expression is false. | |
2658 | ||
2659 | 1 argument | |
2660 | The expression is true if and only if the argument is not | |
2661 | null. | |
2662 | ||
2663 | 2 arguments | |
2664 | If the first argument is `!', the expression is true if and | |
2665 | only if the second argument is null. If the first argument | |
2666 | is one of the unary conditional operators (*note Bash | |
28ef6c31 | 2667 | Conditional Expressions::), the expression is true if the |
cce855bc JA |
2668 | unary test is true. If the first argument is not a valid |
2669 | unary operator, the expression is false. | |
2670 | ||
2671 | 3 arguments | |
2672 | If the second argument is one of the binary conditional | |
28ef6c31 | 2673 | operators (*note Bash Conditional Expressions::), the result |
cce855bc | 2674 | of the expression is the result of the binary test using the |
d7f49990 CR |
2675 | first and third arguments as operands. The `-a' and `-o' |
2676 | operators are considered binary operators when there are | |
2677 | three arguments. If the first argument is `!', the value is | |
2678 | the negation of the two-argument test using the second and | |
2679 | third arguments. If the first argument is exactly `(' and | |
2680 | the third argument is exactly `)', the result is the | |
2681 | one-argument test of the second argument. Otherwise, the | |
2682 | expression is false. | |
cce855bc JA |
2683 | |
2684 | 4 arguments | |
2685 | If the first argument is `!', the result is the negation of | |
2686 | the three-argument expression composed of the remaining | |
2687 | arguments. Otherwise, the expression is parsed and evaluated | |
2688 | according to precedence using the rules listed above. | |
2689 | ||
2690 | 5 or more arguments | |
2691 | The expression is parsed and evaluated according to precedence | |
2692 | using the rules listed above. | |
ccc6cda3 JA |
2693 | |
2694 | `times' | |
2695 | times | |
2696 | Print out the user and system times used by the shell and its | |
cce855bc | 2697 | children. The return status is zero. |
ccc6cda3 JA |
2698 | |
2699 | `trap' | |
d166f048 | 2700 | trap [-lp] [ARG] [SIGSPEC ...] |
ccc6cda3 | 2701 | The commands in ARG are to be read and executed when the shell |
9f422431 CR |
2702 | receives signal SIGSPEC. If ARG is absent (and there is a single |
2703 | SIGSPEC) or equal to `-', each specified signal's disposition is | |
2704 | reset to the value it had when the shell was started. If ARG is | |
2705 | the null string, then the signal specified by each SIGSPEC is | |
2706 | ignored by the shell and commands it invokes. If ARG is not | |
2707 | present and `-p' has been supplied, the shell displays the trap | |
2708 | commands associated with each SIGSPEC. If no arguments are | |
2709 | supplied, or only `-p' is given, `trap' prints the list of commands | |
2710 | associated with each signal number in a form that may be reused as | |
2711 | shell input. The `-l' option causes the shell to print a list of | |
2712 | signal names and their corresponding numbers. Each SIGSPEC is | |
2713 | either a signal name or a signal number. Signal names are case | |
4a8bb13f CR |
2714 | insensitive and the `SIG' prefix is optional. |
2715 | ||
2716 | If a SIGSPEC is `0' or `EXIT', ARG is executed when the shell | |
2717 | exits. If a SIGSPEC is `DEBUG', the command ARG is executed | |
2718 | before every simple command, `for' command, `case' command, | |
2719 | `select' command, every arithmetic `for' command, and before the | |
2720 | first command executes in a shell function. Refer to the | |
2721 | description of the `extdebug' option to the `shopt' builtin (*note | |
2722 | The Shopt Builtin::) for details of its effect on the `DEBUG' trap. | |
2723 | If a SIGSPEC is `RETURN', the command ARG is executed each time a | |
2724 | shell function or a script executed with the `.' or `source' | |
2725 | builtins finishes executing. | |
2726 | ||
2727 | If a SIGSPEC is `ERR', the command ARG is executed whenever a | |
2728 | simple command has a non-zero exit status, subject to the | |
2729 | following conditions. The `ERR' trap is not executed if the | |
2730 | failed command is part of the command list immediately following | |
2731 | an `until' or `while' keyword, part of the test following the `if' | |
2732 | or `elif' reserved words, part of a command executed in a `&&' or | |
2733 | `||' list, or if the command's return status is being inverted | |
2734 | using `!'. These are the same conditions obeyed by the `errexit' | |
2735 | option. | |
d3a24ed2 | 2736 | |
ccc6cda3 | 2737 | Signals ignored upon entry to the shell cannot be trapped or reset. |
d3ad40de | 2738 | Trapped signals that are not being ignored are reset to their |
4a8bb13f CR |
2739 | original values in a subshell or subshell environment when one is |
2740 | created. | |
ccc6cda3 | 2741 | |
cce855bc JA |
2742 | The return status is zero unless a SIGSPEC does not specify a |
2743 | valid signal. | |
2744 | ||
ccc6cda3 | 2745 | `umask' |
cce855bc | 2746 | umask [-p] [-S] [MODE] |
ccc6cda3 JA |
2747 | Set the shell process's file creation mask to MODE. If MODE |
2748 | begins with a digit, it is interpreted as an octal number; if not, | |
2749 | it is interpreted as a symbolic mode mask similar to that accepted | |
2750 | by the `chmod' command. If MODE is omitted, the current value of | |
2751 | the mask is printed. If the `-S' option is supplied without a | |
cce855bc JA |
2752 | MODE argument, the mask is printed in a symbolic format. If the |
2753 | `-p' option is supplied, and MODE is omitted, the output is in a | |
2754 | form that may be reused as input. The return status is zero if | |
2755 | the mode is successfully changed or if no MODE argument is | |
2756 | supplied, and non-zero otherwise. | |
ccc6cda3 | 2757 | |
bb70624e JA |
2758 | Note that when the mode is interpreted as an octal number, each |
2759 | number of the umask is subtracted from `7'. Thus, a umask of `022' | |
2760 | results in permissions of `755'. | |
2761 | ||
ccc6cda3 JA |
2762 | `unset' |
2763 | unset [-fv] [NAME] | |
2764 | Each variable or function NAME is removed. If no options are | |
2765 | supplied, or the `-v' option is given, each NAME refers to a shell | |
2766 | variable. If the `-f' option is given, the NAMEs refer to shell | |
cce855bc JA |
2767 | functions, and the function definition is removed. Readonly |
2768 | variables and functions may not be unset. The return status is | |
d3a24ed2 | 2769 | zero unless a NAME is readonly. |
ccc6cda3 JA |
2770 | |
2771 | \1f | |
d3ad40de | 2772 | File: bashref.info, Node: Bash Builtins, Next: Modifying Shell Behavior, Prev: Bourne Shell Builtins, Up: Shell Builtin Commands |
ccc6cda3 | 2773 | |
37c41ab1 CR |
2774 | 4.2 Bash Builtin Commands |
2775 | ========================= | |
ccc6cda3 | 2776 | |
37c41ab1 | 2777 | This section describes builtin commands which are unique to or have |
bb70624e | 2778 | been extended in Bash. Some of these commands are specified in the |
ac18b312 | 2779 | POSIX standard. |
ccc6cda3 | 2780 | |
bb70624e JA |
2781 | `alias' |
2782 | alias [`-p'] [NAME[=VALUE] ...] | |
ccc6cda3 | 2783 | |
bb70624e JA |
2784 | Without arguments or with the `-p' option, `alias' prints the list |
2785 | of aliases on the standard output in a form that allows them to be | |
2786 | reused as input. If arguments are supplied, an alias is defined | |
2787 | for each NAME whose VALUE is given. If no VALUE is given, the name | |
6a8fd0ed | 2788 | and value of the alias is printed. Aliases are described in *note |
bb70624e | 2789 | Aliases::. |
ccc6cda3 | 2790 | |
bb70624e JA |
2791 | `bind' |
2792 | bind [-m KEYMAP] [-lpsvPSV] | |
2793 | bind [-m KEYMAP] [-q FUNCTION] [-u FUNCTION] [-r KEYSEQ] | |
2794 | bind [-m KEYMAP] -f FILENAME | |
2795 | bind [-m KEYMAP] -x KEYSEQ:SHELL-COMMAND | |
2796 | bind [-m KEYMAP] KEYSEQ:FUNCTION-NAME | |
7117c2d2 | 2797 | bind READLINE-COMMAND |
ccc6cda3 | 2798 | |
28ef6c31 | 2799 | Display current Readline (*note Command Line Editing::) key and |
7117c2d2 JA |
2800 | function bindings, bind a key sequence to a Readline function or |
2801 | macro, or set a Readline variable. Each non-option argument is a | |
d3ad40de | 2802 | command as it would appear in a Readline initialization file |
7117c2d2 JA |
2803 | (*note Readline Init File::), but each binding or command must be |
2804 | passed as a separate argument; e.g., | |
ed35cb4a CR |
2805 | `"\C-x\C-r":re-read-init-file'. |
2806 | ||
2807 | Options, if supplied, have the following meanings: | |
ccc6cda3 | 2808 | |
bb70624e JA |
2809 | `-m KEYMAP' |
2810 | Use KEYMAP as the keymap to be affected by the subsequent | |
2811 | bindings. Acceptable KEYMAP names are `emacs', | |
28ef6c31 | 2812 | `emacs-standard', `emacs-meta', `emacs-ctlx', `vi', `vi-move', |
bb70624e JA |
2813 | `vi-command', and `vi-insert'. `vi' is equivalent to |
2814 | `vi-command'; `emacs' is equivalent to `emacs-standard'. | |
cce855bc | 2815 | |
bb70624e JA |
2816 | `-l' |
2817 | List the names of all Readline functions. | |
cce855bc | 2818 | |
bb70624e JA |
2819 | `-p' |
2820 | Display Readline function names and bindings in such a way | |
2821 | that they can be used as input or in a Readline | |
2822 | initialization file. | |
cce855bc | 2823 | |
bb70624e JA |
2824 | `-P' |
2825 | List current Readline function names and bindings. | |
cce855bc | 2826 | |
bb70624e JA |
2827 | `-v' |
2828 | Display Readline variable names and values in such a way that | |
2829 | they can be used as input or in a Readline initialization | |
2830 | file. | |
ccc6cda3 | 2831 | |
bb70624e JA |
2832 | `-V' |
2833 | List current Readline variable names and values. | |
ccc6cda3 | 2834 | |
bb70624e JA |
2835 | `-s' |
2836 | Display Readline key sequences bound to macros and the | |
2837 | strings they output in such a way that they can be used as | |
2838 | input or in a Readline initialization file. | |
ccc6cda3 | 2839 | |
bb70624e JA |
2840 | `-S' |
2841 | Display Readline key sequences bound to macros and the | |
2842 | strings they output. | |
ccc6cda3 | 2843 | |
bb70624e JA |
2844 | `-f FILENAME' |
2845 | Read key bindings from FILENAME. | |
ccc6cda3 | 2846 | |
bb70624e JA |
2847 | `-q FUNCTION' |
2848 | Query about which keys invoke the named FUNCTION. | |
ccc6cda3 | 2849 | |
bb70624e JA |
2850 | `-u FUNCTION' |
2851 | Unbind all keys bound to the named FUNCTION. | |
ccc6cda3 | 2852 | |
bb70624e JA |
2853 | `-r KEYSEQ' |
2854 | Remove any current binding for KEYSEQ. | |
ccc6cda3 | 2855 | |
bb70624e JA |
2856 | `-x KEYSEQ:SHELL-COMMAND' |
2857 | Cause SHELL-COMMAND to be executed whenever KEYSEQ is entered. | |
ed35cb4a CR |
2858 | When SHELL-COMMAND is executed, the shell sets the |
2859 | `READLINE_LINE' variable to the contents of the Readline line | |
2860 | buffer and the `READLINE_POINT' variable to the current | |
2861 | location of the insertion point. If the executed command | |
2862 | changes the value of `READLINE_LINE' or `READLINE_POINT', | |
2863 | those new values will be reflected in the editing state. | |
761783bf | 2864 | |
bb70624e JA |
2865 | The return status is zero unless an invalid option is supplied or |
2866 | an error occurs. | |
ccc6cda3 | 2867 | |
bb70624e JA |
2868 | `builtin' |
2869 | builtin [SHELL-BUILTIN [ARGS]] | |
2870 | Run a shell builtin, passing it ARGS, and return its exit status. | |
2871 | This is useful when defining a shell function with the same name | |
2872 | as a shell builtin, retaining the functionality of the builtin | |
2873 | within the function. The return status is non-zero if | |
2874 | SHELL-BUILTIN is not a shell builtin command. | |
ccc6cda3 | 2875 | |
d3a24ed2 CR |
2876 | `caller' |
2877 | caller [EXPR] | |
2878 | Returns the context of any active subroutine call (a shell | |
5e13499c | 2879 | function or a script executed with the `.' or `source' builtins). |
d3a24ed2 CR |
2880 | |
2881 | Without EXPR, `caller' displays the line number and source | |
2882 | filename of the current subroutine call. If a non-negative | |
2883 | integer is supplied as EXPR, `caller' displays the line number, | |
2884 | subroutine name, and source file corresponding to that position in | |
2885 | the current execution call stack. This extra information may be | |
2886 | used, for example, to print a stack trace. The current frame is | |
2887 | frame 0. | |
2888 | ||
2889 | The return value is 0 unless the shell is not executing a | |
2890 | subroutine call or EXPR does not correspond to a valid position in | |
2891 | the call stack. | |
2892 | ||
bb70624e JA |
2893 | `command' |
2894 | command [-pVv] COMMAND [ARGUMENTS ...] | |
2895 | Runs COMMAND with ARGUMENTS ignoring any shell function named | |
2896 | COMMAND. Only shell builtin commands or commands found by | |
2897 | searching the `PATH' are executed. If there is a shell function | |
2898 | named `ls', running `command ls' within the function will execute | |
2899 | the external command `ls' instead of calling the function | |
2900 | recursively. The `-p' option means to use a default value for | |
28ef6c31 | 2901 | `PATH' that is guaranteed to find all of the standard utilities. |
bb70624e JA |
2902 | The return status in this case is 127 if COMMAND cannot be found |
2903 | or an error occurred, and the exit status of COMMAND otherwise. | |
ccc6cda3 | 2904 | |
bb70624e JA |
2905 | If either the `-V' or `-v' option is supplied, a description of |
2906 | COMMAND is printed. The `-v' option causes a single word | |
2907 | indicating the command or file name used to invoke COMMAND to be | |
2908 | displayed; the `-V' option produces a more verbose description. | |
2909 | In this case, the return status is zero if COMMAND is found, and | |
2910 | non-zero if not. | |
ccc6cda3 | 2911 | |
bb70624e | 2912 | `declare' |
8e1a6eaa | 2913 | declare [-aAfFilrtux] [-p] [NAME[=VALUE] ...] |
ccc6cda3 | 2914 | |
bb70624e JA |
2915 | Declare variables and give them attributes. If no NAMEs are |
2916 | given, then display the values of variables instead. | |
ccc6cda3 | 2917 | |
bb70624e | 2918 | The `-p' option will display the attributes and values of each |
6a8fd0ed CR |
2919 | NAME. When `-p' is used with NAME arguments, additional options |
2920 | are ignored. | |
2921 | ||
2922 | When `-p' is supplied without NAME arguments, `declare' will | |
2923 | display the attributes and values of all variables having the | |
2924 | attributes specified by the additional options. If no other | |
2925 | options are supplied with `-p', `declare' will display the | |
2926 | attributes and values of all shell variables. The `-f' option | |
2927 | will restrict the display to shell functions. | |
2928 | ||
2929 | The `-F' option inhibits the display of function definitions; only | |
2930 | the function name and attributes are printed. If the `extdebug' | |
2931 | shell option is enabled using `shopt' (*note The Shopt Builtin::), | |
2932 | the source file name and line number where the function is defined | |
2933 | are displayed as well. `-F' implies `-f'. The following options | |
2934 | can be used to restrict output to variables with the specified | |
d3a24ed2 | 2935 | attributes or to give variables attributes: |
ccc6cda3 | 2936 | |
bb70624e | 2937 | `-a' |
09767ff0 CR |
2938 | Each NAME is an indexed array variable (*note Arrays::). |
2939 | ||
2940 | `-A' | |
2941 | Each NAME is an associative array variable (*note Arrays::). | |
ccc6cda3 | 2942 | |
bb70624e JA |
2943 | `-f' |
2944 | Use function names only. | |
ccc6cda3 | 2945 | |
bb70624e JA |
2946 | `-i' |
2947 | The variable is to be treated as an integer; arithmetic | |
28ef6c31 | 2948 | evaluation (*note Shell Arithmetic::) is performed when the |
bb70624e | 2949 | variable is assigned a value. |
ccc6cda3 | 2950 | |
8e1a6eaa CR |
2951 | `-l' |
2952 | When the variable is assigned a value, all upper-case | |
2953 | characters are converted to lower-case. The upper-case | |
2954 | attribute is disabled. | |
2955 | ||
bb70624e JA |
2956 | `-r' |
2957 | Make NAMEs readonly. These names cannot then be assigned | |
2958 | values by subsequent assignment statements or unset. | |
ccc6cda3 | 2959 | |
7117c2d2 JA |
2960 | `-t' |
2961 | Give each NAME the `trace' attribute. Traced functions | |
8fed3589 CR |
2962 | inherit the `DEBUG' and `RETURN' traps from the calling shell. |
2963 | The trace attribute has no special meaning for variables. | |
7117c2d2 | 2964 | |
8e1a6eaa CR |
2965 | `-u' |
2966 | When the variable is assigned a value, all lower-case | |
2967 | characters are converted to upper-case. The lower-case | |
2968 | attribute is disabled. | |
2969 | ||
bb70624e JA |
2970 | `-x' |
2971 | Mark each NAME for export to subsequent commands via the | |
2972 | environment. | |
ccc6cda3 | 2973 | |
d3ad40de CR |
2974 | Using `+' instead of `-' turns off the attribute instead, with the |
2975 | exceptions that `+a' may not be used to destroy an array variable | |
2976 | and `+r' will not remove the readonly attribute. When used in a | |
2977 | function, `declare' makes each NAME local, as with the `local' | |
2978 | command. If a variable name is followed by =VALUE, the value of | |
2979 | the variable is set to VALUE. | |
ccc6cda3 | 2980 | |
bb70624e JA |
2981 | The return status is zero unless an invalid option is encountered, |
2982 | an attempt is made to define a function using `-f foo=bar', an | |
2983 | attempt is made to assign a value to a readonly variable, an | |
2984 | attempt is made to assign a value to an array variable without | |
28ef6c31 | 2985 | using the compound assignment syntax (*note Arrays::), one of the |
bb70624e JA |
2986 | NAMES is not a valid shell variable name, an attempt is made to |
2987 | turn off readonly status for a readonly variable, an attempt is | |
2988 | made to turn off array status for an array variable, or an attempt | |
2989 | is made to display a non-existent function with `-f'. | |
ccc6cda3 | 2990 | |
bb70624e JA |
2991 | `echo' |
2992 | echo [-neE] [ARG ...] | |
2993 | Output the ARGs, separated by spaces, terminated with a newline. | |
2994 | The return status is always 0. If `-n' is specified, the trailing | |
2995 | newline is suppressed. If the `-e' option is given, | |
2996 | interpretation of the following backslash-escaped characters is | |
2997 | enabled. The `-E' option disables the interpretation of these | |
2998 | escape characters, even on systems where they are interpreted by | |
2999 | default. The `xpg_echo' shell option may be used to dynamically | |
3000 | determine whether or not `echo' expands these escape characters by | |
1c72c0cd CR |
3001 | default. `echo' does not interpret `--' to mean the end of |
3002 | options. | |
3003 | ||
3004 | `echo' interprets the following escape sequences: | |
bb70624e JA |
3005 | `\a' |
3006 | alert (bell) | |
ccc6cda3 | 3007 | |
bb70624e JA |
3008 | `\b' |
3009 | backspace | |
ccc6cda3 | 3010 | |
bb70624e | 3011 | `\c' |
a9fac3b2 | 3012 | suppress further output |
ccc6cda3 | 3013 | |
bb70624e JA |
3014 | `\e' |
3015 | escape | |
ccc6cda3 | 3016 | |
bb70624e JA |
3017 | `\f' |
3018 | form feed | |
ccc6cda3 | 3019 | |
bb70624e JA |
3020 | `\n' |
3021 | new line | |
ccc6cda3 | 3022 | |
bb70624e JA |
3023 | `\r' |
3024 | carriage return | |
ccc6cda3 | 3025 | |
bb70624e JA |
3026 | `\t' |
3027 | horizontal tab | |
ccc6cda3 | 3028 | |
bb70624e JA |
3029 | `\v' |
3030 | vertical tab | |
ccc6cda3 | 3031 | |
bb70624e JA |
3032 | `\\' |
3033 | backslash | |
ccc6cda3 | 3034 | |
7117c2d2 JA |
3035 | `\0NNN' |
3036 | the eight-bit character whose value is the octal value NNN | |
3037 | (zero to three octal digits) | |
3038 | ||
f73dda09 JA |
3039 | `\xHH' |
3040 | the eight-bit character whose value is the hexadecimal value | |
3041 | HH (one or two hex digits) | |
3042 | ||
bb70624e | 3043 | `enable' |
d3ad40de | 3044 | enable [-a] [-dnps] [-f FILENAME] [NAME ...] |
bb70624e JA |
3045 | Enable and disable builtin shell commands. Disabling a builtin |
3046 | allows a disk command which has the same name as a shell builtin | |
3047 | to be executed without specifying a full pathname, even though the | |
3048 | shell normally searches for builtins before disk commands. If | |
3049 | `-n' is used, the NAMEs become disabled. Otherwise NAMEs are | |
3050 | enabled. For example, to use the `test' binary found via `$PATH' | |
3051 | instead of the shell builtin version, type `enable -n test'. | |
ccc6cda3 | 3052 | |
bb70624e JA |
3053 | If the `-p' option is supplied, or no NAME arguments appear, a |
3054 | list of shell builtins is printed. With no other arguments, the | |
3055 | list consists of all enabled shell builtins. The `-a' option | |
3056 | means to list each builtin with an indication of whether or not it | |
3057 | is enabled. | |
ccc6cda3 | 3058 | |
bb70624e JA |
3059 | The `-f' option means to load the new builtin command NAME from |
3060 | shared object FILENAME, on systems that support dynamic loading. | |
3061 | The `-d' option will delete a builtin loaded with `-f'. | |
ccc6cda3 | 3062 | |
bb70624e JA |
3063 | If there are no options, a list of the shell builtins is displayed. |
3064 | The `-s' option restricts `enable' to the POSIX special builtins. | |
3065 | If `-s' is used with `-f', the new builtin becomes a special | |
28ef6c31 | 3066 | builtin (*note Special Builtins::). |
ccc6cda3 | 3067 | |
bb70624e JA |
3068 | The return status is zero unless a NAME is not a shell builtin or |
3069 | there is an error loading a new builtin from a shared object. | |
ccc6cda3 | 3070 | |
bb70624e | 3071 | `help' |
ed35cb4a | 3072 | help [-dms] [PATTERN] |
bb70624e JA |
3073 | Display helpful information about builtin commands. If PATTERN is |
3074 | specified, `help' gives detailed help on all commands matching | |
ed35cb4a CR |
3075 | PATTERN, otherwise a list of the builtins is printed. |
3076 | ||
3077 | Options, if supplied, have the following meanings: | |
3078 | ||
3079 | `-d' | |
3080 | Display a short description of each PATTERN | |
3081 | ||
3082 | `-m' | |
3083 | Display the description of each PATTERN in a manpage-like | |
3084 | format | |
3085 | ||
3086 | `-s' | |
3087 | Display only a short usage synopsis for each PATTERN | |
3088 | ||
3089 | The return status is zero unless no command matches PATTERN. | |
ccc6cda3 | 3090 | |
bb70624e JA |
3091 | `let' |
3092 | let EXPRESSION [EXPRESSION] | |
3093 | The `let' builtin allows arithmetic to be performed on shell | |
3094 | variables. Each EXPRESSION is evaluated according to the rules | |
6a8fd0ed | 3095 | given below in *note Shell Arithmetic::. If the last EXPRESSION |
bb70624e | 3096 | evaluates to 0, `let' returns 1; otherwise 0 is returned. |
ccc6cda3 | 3097 | |
bb70624e | 3098 | `local' |
d3a24ed2 | 3099 | local [OPTION] NAME[=VALUE] ... |
bb70624e JA |
3100 | For each argument, a local variable named NAME is created, and |
3101 | assigned VALUE. The OPTION can be any of the options accepted by | |
3102 | `declare'. `local' can only be used within a function; it makes | |
3103 | the variable NAME have a visible scope restricted to that function | |
3104 | and its children. The return status is zero unless `local' is | |
3105 | used outside a function, an invalid NAME is supplied, or NAME is a | |
3106 | readonly variable. | |
ccc6cda3 | 3107 | |
bb70624e JA |
3108 | `logout' |
3109 | logout [N] | |
3110 | Exit a login shell, returning a status of N to the shell's parent. | |
ccc6cda3 | 3111 | |
ed35cb4a CR |
3112 | `mapfile' |
3113 | mapfile [-n COUNT] [-O ORIGIN] [-s COUNT] [-t] [-u FD] [ | |
3114 | -C CALLBACK] [-c QUANTUM] [ARRAY] | |
3115 | Read lines from the standard input into array variable ARRAY, or | |
3116 | from file descriptor FD if the `-u' option is supplied. The | |
3117 | variable `MAPFILE' is the default ARRAY. Options, if supplied, | |
3118 | have the following meanings: | |
3119 | `-n' | |
3120 | Copy at most COUNT lines. If COUNT is 0, all lines are | |
3121 | copied. | |
3122 | ||
3123 | `-O' | |
3124 | Begin assigning to ARRAY at index ORIGIN. The default index | |
3125 | is 0. | |
3126 | ||
3127 | `-s' | |
3128 | Discard the first COUNT lines read. | |
3129 | ||
3130 | `-t' | |
3131 | Remove a trailing line from each line read. | |
3132 | ||
3133 | `-u' | |
3134 | Read lines from file descriptor FD instead of the standard | |
3135 | input. | |
3136 | ||
3137 | `-C' | |
3138 | Evaluate CALLBACK each time QUANTUMP lines are read. The | |
3139 | `-c' option specifies QUANTUM. | |
3140 | ||
3141 | `-c' | |
3142 | Specify the number of lines read between each call to | |
3143 | CALLBACK. | |
3144 | ||
3145 | If `-C' is specified without `-c', the default quantum is 5000. | |
db31fb26 CR |
3146 | When CALLBACK is evaluated, it is supplied the index of the next |
3147 | array element to be assigned as an additional argument. CALLBACK | |
3148 | is evaluated after the line is read but before the array element | |
3149 | is assigned. | |
ed35cb4a CR |
3150 | |
3151 | If not supplied with an explicit origin, `mapfile' will clear ARRAY | |
3152 | before assigning to it. | |
3153 | ||
3154 | `mapfile' returns successfully unless an invalid option or option | |
3155 | argument is supplied, or ARRAY is invalid or unassignable. | |
3156 | ||
bb70624e | 3157 | `printf' |
29d25b54 | 3158 | printf [-v VAR] FORMAT [ARGUMENTS] |
bb70624e JA |
3159 | Write the formatted ARGUMENTS to the standard output under the |
3160 | control of the FORMAT. The FORMAT is a character string which | |
3161 | contains three types of objects: plain characters, which are | |
3162 | simply copied to standard output, character escape sequences, | |
3163 | which are converted and copied to the standard output, and format | |
3164 | specifications, each of which causes printing of the next | |
3165 | successive ARGUMENT. In addition to the standard `printf(1)' | |
3166 | formats, `%b' causes `printf' to expand backslash escape sequences | |
5e13499c CR |
3167 | in the corresponding ARGUMENT, (except that `\c' terminates |
3168 | output, backslashes in `\'', `\"', and `\?' are not removed, and | |
3169 | octal escapes beginning with `\0' may contain up to four digits), | |
3170 | and `%q' causes `printf' to output the corresponding ARGUMENT in a | |
3171 | format that can be reused as shell input. | |
ccc6cda3 | 3172 | |
3ee6b87d CR |
3173 | The `-v' option causes the output to be assigned to the variable |
3174 | VAR rather than being printed to the standard output. | |
3175 | ||
bb70624e JA |
3176 | The FORMAT is reused as necessary to consume all of the ARGUMENTS. |
3177 | If the FORMAT requires more ARGUMENTS than are supplied, the extra | |
3178 | format specifications behave as if a zero value or null string, as | |
3179 | appropriate, had been supplied. The return value is zero on | |
3180 | success, non-zero on failure. | |
ccc6cda3 | 3181 | |
bb70624e | 3182 | `read' |
6a8fd0ed | 3183 | read [-ers] [-a ANAME] [-d DELIM] [-i TEXT] [-n NCHARS] [-p PROMPT] [-t TIMEOUT] [-u FD] [NAME ...] |
7117c2d2 JA |
3184 | One line is read from the standard input, or from the file |
3185 | descriptor FD supplied as an argument to the `-u' option, and the | |
3186 | first word is assigned to the first NAME, the second word to the | |
3187 | second NAME, and so on, with leftover words and their intervening | |
3188 | separators assigned to the last NAME. If there are fewer words | |
3189 | read from the input stream than names, the remaining names are | |
3190 | assigned empty values. The characters in the value of the `IFS' | |
3191 | variable are used to split the line into words. The backslash | |
3192 | character `\' may be used to remove any special meaning for the | |
3193 | next character read and for line continuation. If no names are | |
3194 | supplied, the line read is assigned to the variable `REPLY'. The | |
3195 | return code is zero, unless end-of-file is encountered, `read' | |
8e1a6eaa CR |
3196 | times out (in which case the return code is greater than 128), or |
3197 | an invalid file descriptor is supplied as the argument to `-u'. | |
3198 | ||
3199 | Options, if supplied, have the following meanings: | |
ccc6cda3 | 3200 | |
bb70624e JA |
3201 | `-a ANAME' |
3202 | The words are assigned to sequential indices of the array | |
3203 | variable ANAME, starting at 0. All elements are removed from | |
3204 | ANAME before the assignment. Other NAME arguments are | |
3205 | ignored. | |
ccc6cda3 | 3206 | |
bb70624e JA |
3207 | `-d DELIM' |
3208 | The first character of DELIM is used to terminate the input | |
3209 | line, rather than newline. | |
ccc6cda3 | 3210 | |
bb70624e | 3211 | `-e' |
28ef6c31 | 3212 | Readline (*note Command Line Editing::) is used to obtain the |
a9fac3b2 CR |
3213 | line. Readline uses the current (or default, if line editing |
3214 | was not previously active) editing settings. | |
ccc6cda3 | 3215 | |
6a8fd0ed CR |
3216 | `-i TEXT' |
3217 | If Readline is being used to read the line, TEXT is placed | |
3218 | into the editing buffer before editing begins. | |
3219 | ||
bb70624e JA |
3220 | `-n NCHARS' |
3221 | `read' returns after reading NCHARS characters rather than | |
3222 | waiting for a complete line of input. | |
cce855bc | 3223 | |
bb70624e JA |
3224 | `-p PROMPT' |
3225 | Display PROMPT, without a trailing newline, before attempting | |
3226 | to read any input. The prompt is displayed only if input is | |
3227 | coming from a terminal. | |
ccc6cda3 | 3228 | |
bb70624e JA |
3229 | `-r' |
3230 | If this option is given, backslash does not act as an escape | |
3231 | character. The backslash is considered to be part of the | |
3232 | line. In particular, a backslash-newline pair may not be | |
3233 | used as a line continuation. | |
ccc6cda3 | 3234 | |
bb70624e JA |
3235 | `-s' |
3236 | Silent mode. If input is coming from a terminal, characters | |
3237 | are not echoed. | |
cce855bc | 3238 | |
bb70624e JA |
3239 | `-t TIMEOUT' |
3240 | Cause `read' to time out and return failure if a complete | |
ed35cb4a CR |
3241 | line of input is not read within TIMEOUT seconds. TIMEOUT |
3242 | may be a decimal number with a fractional portion following | |
09767ff0 CR |
3243 | the decimal point. This option is only effective if `read' |
3244 | is reading input from a terminal, pipe, or other special | |
a9fac3b2 CR |
3245 | file; it has no effect when reading from regular files. If |
3246 | TIMEOUT is 0, `read' returns success if input is available on | |
3247 | the specified file descriptor, failure otherwise. The exit | |
3248 | status is greater than 128 if the timeout is exceeded. | |
cce855bc | 3249 | |
7117c2d2 JA |
3250 | `-u FD' |
3251 | Read input from file descriptor FD. | |
3252 | ||
761783bf | 3253 | |
db31fb26 CR |
3254 | `readarray' |
3255 | readarray [-n COUNT] [-O ORIGIN] [-s COUNT] [-t] [-u FD] [ | |
3256 | -C CALLBACK] [-c QUANTUM] [ARRAY] | |
3257 | Read lines from the standard input into array variable ARRAY, or | |
3258 | from file descriptor FD if the `-u' option is supplied. | |
3259 | ||
3260 | A synonym for `mapfile'. | |
3261 | ||
bb70624e JA |
3262 | `source' |
3263 | source FILENAME | |
28ef6c31 | 3264 | A synonym for `.' (*note Bourne Shell Builtins::). |
ccc6cda3 | 3265 | |
bb70624e | 3266 | `type' |
7117c2d2 | 3267 | type [-afptP] [NAME ...] |
bb70624e JA |
3268 | For each NAME, indicate how it would be interpreted if used as a |
3269 | command name. | |
cce855bc | 3270 | |
bb70624e JA |
3271 | If the `-t' option is used, `type' prints a single word which is |
3272 | one of `alias', `function', `builtin', `file' or `keyword', if | |
3273 | NAME is an alias, shell function, shell builtin, disk file, or | |
3274 | shell reserved word, respectively. If the NAME is not found, then | |
3275 | nothing is printed, and `type' returns a failure status. | |
ccc6cda3 | 3276 | |
bb70624e JA |
3277 | If the `-p' option is used, `type' either returns the name of the |
3278 | disk file that would be executed, or nothing if `-t' would not | |
3279 | return `file'. | |
ccc6cda3 | 3280 | |
7117c2d2 JA |
3281 | The `-P' option forces a path search for each NAME, even if `-t' |
3282 | would not return `file'. | |
3283 | ||
3284 | If a command is hashed, `-p' and `-P' print the hashed value, not | |
3285 | necessarily the file that appears first in `$PATH'. | |
3286 | ||
bb70624e JA |
3287 | If the `-a' option is used, `type' returns all of the places that |
3288 | contain an executable named FILE. This includes aliases and | |
3289 | functions, if and only if the `-p' option is not also used. | |
ccc6cda3 | 3290 | |
7117c2d2 JA |
3291 | If the `-f' option is used, `type' does not attempt to find shell |
3292 | functions, as with the `command' builtin. | |
3293 | ||
ed35cb4a CR |
3294 | The return status is zero if all of the NAMES are found, non-zero |
3295 | if any are not found. | |
ccc6cda3 | 3296 | |
bb70624e | 3297 | `typeset' |
d3a24ed2 | 3298 | typeset [-afFrxi] [-p] [NAME[=VALUE] ...] |
bb70624e JA |
3299 | The `typeset' command is supplied for compatibility with the Korn |
3300 | shell; however, it has been deprecated in favor of the `declare' | |
3301 | builtin command. | |
ccc6cda3 | 3302 | |
bb70624e | 3303 | `ulimit' |
6a8fd0ed | 3304 | ulimit [-abcdefilmnpqrstuvxHST] [LIMIT] |
bb70624e JA |
3305 | `ulimit' provides control over the resources available to processes |
3306 | started by the shell, on systems that allow such control. If an | |
3307 | option is given, it is interpreted as follows: | |
3308 | `-S' | |
3309 | Change and report the soft limit associated with a resource. | |
ccc6cda3 | 3310 | |
bb70624e JA |
3311 | `-H' |
3312 | Change and report the hard limit associated with a resource. | |
ccc6cda3 | 3313 | |
bb70624e JA |
3314 | `-a' |
3315 | All current limits are reported. | |
ccc6cda3 | 3316 | |
6a8fd0ed CR |
3317 | `-b' |
3318 | The maximum socket buffer size. | |
3319 | ||
bb70624e JA |
3320 | `-c' |
3321 | The maximum size of core files created. | |
ccc6cda3 | 3322 | |
bb70624e JA |
3323 | `-d' |
3324 | The maximum size of a process's data segment. | |
ccc6cda3 | 3325 | |
ac18b312 CR |
3326 | `-e' |
3327 | The maximum scheduling priority ("nice"). | |
3328 | ||
bb70624e | 3329 | `-f' |
d3ad40de CR |
3330 | The maximum size of files written by the shell and its |
3331 | children. | |
ccc6cda3 | 3332 | |
ac18b312 CR |
3333 | `-i' |
3334 | The maximum number of pending signals. | |
3335 | ||
bb70624e JA |
3336 | `-l' |
3337 | The maximum size that may be locked into memory. | |
ccc6cda3 | 3338 | |
bb70624e | 3339 | `-m' |
6932f7f5 CR |
3340 | The maximum resident set size (many systems do not honor this |
3341 | limit). | |
ccc6cda3 | 3342 | |
bb70624e | 3343 | `-n' |
6932f7f5 CR |
3344 | The maximum number of open file descriptors (most systems do |
3345 | not allow this value to be set). | |
ccc6cda3 | 3346 | |
bb70624e JA |
3347 | `-p' |
3348 | The pipe buffer size. | |
ccc6cda3 | 3349 | |
ac18b312 CR |
3350 | `-q' |
3351 | The maximum number of bytes in POSIX message queues. | |
3352 | ||
3353 | `-r' | |
3354 | The maximum real-time scheduling priority. | |
3355 | ||
bb70624e JA |
3356 | `-s' |
3357 | The maximum stack size. | |
ccc6cda3 | 3358 | |
bb70624e JA |
3359 | `-t' |
3360 | The maximum amount of cpu time in seconds. | |
ccc6cda3 | 3361 | |
bb70624e JA |
3362 | `-u' |
3363 | The maximum number of processes available to a single user. | |
cce855bc | 3364 | |
bb70624e JA |
3365 | `-v' |
3366 | The maximum amount of virtual memory available to the process. | |
ccc6cda3 | 3367 | |
ac18b312 CR |
3368 | `-x' |
3369 | The maximum number of file locks. | |
3370 | ||
6a8fd0ed CR |
3371 | `-T' |
3372 | The maximum number of threads. | |
3373 | ||
761783bf | 3374 | |
f73dda09 JA |
3375 | If LIMIT is given, it is the new value of the specified resource; |
3376 | the special LIMIT values `hard', `soft', and `unlimited' stand for | |
3377 | the current hard limit, the current soft limit, and no limit, | |
3d4e09aa CR |
3378 | respectively. A hard limit cannot be increased by a non-root user |
3379 | once it is set; a soft limit may be increased up to the value of | |
3380 | the hard limit. Otherwise, the current value of the soft limit | |
3381 | for the specified resource is printed, unless the `-H' option is | |
f73dda09 JA |
3382 | supplied. When setting new limits, if neither `-H' nor `-S' is |
3383 | supplied, both the hard and soft limits are set. If no option is | |
3384 | given, then `-f' is assumed. Values are in 1024-byte increments, | |
3385 | except for `-t', which is in seconds, `-p', which is in units of | |
3386 | 512-byte blocks, and `-n' and `-u', which are unscaled values. | |
ccc6cda3 | 3387 | |
f73dda09 JA |
3388 | The return status is zero unless an invalid option or argument is |
3389 | supplied, or an error occurs while setting a new limit. | |
ccc6cda3 | 3390 | |
bb70624e JA |
3391 | `unalias' |
3392 | unalias [-a] [NAME ... ] | |
ccc6cda3 | 3393 | |
bb70624e | 3394 | Remove each NAME from the list of aliases. If `-a' is supplied, |
6a8fd0ed | 3395 | all aliases are removed. Aliases are described in *note Aliases::. |
ccc6cda3 | 3396 | |
761783bf | 3397 | |
bb70624e | 3398 | \1f |
d3ad40de | 3399 | File: bashref.info, Node: Modifying Shell Behavior, Next: Special Builtins, Prev: Bash Builtins, Up: Shell Builtin Commands |
ccc6cda3 | 3400 | |
d3ad40de CR |
3401 | 4.3 Modifying Shell Behavior |
3402 | ============================ | |
3403 | ||
3404 | * Menu: | |
3405 | ||
3406 | * The Set Builtin:: Change the values of shell attributes and | |
3407 | positional parameters. | |
3408 | * The Shopt Builtin:: Modify shell optional behavior. | |
3409 | ||
3410 | \1f | |
3411 | File: bashref.info, Node: The Set Builtin, Next: The Shopt Builtin, Up: Modifying Shell Behavior | |
3412 | ||
3413 | 4.3.1 The Set Builtin | |
3414 | --------------------- | |
9d6e5e30 | 3415 | |
d3ad40de CR |
3416 | This builtin is so complicated that it deserves its own section. `set' |
3417 | allows you to change the values of shell options and set the positional | |
3418 | parameters, or to display the names and values of shell variables. | |
ccc6cda3 | 3419 | |
bb70624e | 3420 | `set' |
d3ad40de CR |
3421 | set [--abefhkmnptuvxBCEHPT] [-o OPTION] [ARGUMENT ...] |
3422 | set [+abefhkmnptuvxBCEHPT] [+o OPTION] [ARGUMENT ...] | |
ccc6cda3 | 3423 | |
bb70624e JA |
3424 | If no options or arguments are supplied, `set' displays the names |
3425 | and values of all shell variables and functions, sorted according | |
54cdd75a CR |
3426 | to the current locale, in a format that may be reused as input for |
3427 | setting or resetting the currently-set variables. Read-only | |
3428 | variables cannot be reset. In POSIX mode, only shell variables | |
3429 | are listed. | |
ccc6cda3 | 3430 | |
bb70624e JA |
3431 | When options are supplied, they set or unset shell attributes. |
3432 | Options, if specified, have the following meanings: | |
ccc6cda3 | 3433 | |
bb70624e | 3434 | `-a' |
28ef6c31 JA |
3435 | Mark variables and function which are modified or created for |
3436 | export to the environment of subsequent commands. | |
ccc6cda3 | 3437 | |
bb70624e JA |
3438 | `-b' |
3439 | Cause the status of terminated background jobs to be reported | |
3440 | immediately, rather than before printing the next primary | |
3441 | prompt. | |
ccc6cda3 | 3442 | |
bb70624e | 3443 | `-e' |
6932f7f5 CR |
3444 | Exit immediately if a pipeline (*note Pipelines::), which may |
3445 | consist of a single simple command (*note Simple Commands::), | |
3446 | a subshell command enclosed in parentheses (*note Command | |
3447 | Grouping::), or one of the commands executed as part of a | |
3448 | command list enclosed by braces (*note Command Grouping::) | |
3449 | returns a non-zero status. The shell does not exit if the | |
3450 | command that fails is part of the command list immediately | |
3451 | following a `while' or `until' keyword, part of the test in | |
3452 | an `if' statement, part of any command executed in a `&&' or | |
3453 | `||' list except the command following the final `&&' or `||', | |
c2a47ea9 | 3454 | any command in a pipeline but the last, or if the command's |
6932f7f5 | 3455 | return status is being inverted with `!'. A trap on `ERR', |
c2a47ea9 | 3456 | if set, is executed before the shell exits. |
ccc6cda3 | 3457 | |
6932f7f5 CR |
3458 | This option applies to the shell environment and each |
3459 | subshell environment separately (*note Command Execution | |
3460 | Environment::), and may cause subshells to exit before | |
3461 | executing all the commands in the subshell. | |
3462 | ||
bb70624e | 3463 | `-f' |
4a8bb13f | 3464 | Disable filename expansion (globbing). |
ccc6cda3 | 3465 | |
bb70624e JA |
3466 | `-h' |
3467 | Locate and remember (hash) commands as they are looked up for | |
3468 | execution. This option is enabled by default. | |
ccc6cda3 | 3469 | |
bb70624e JA |
3470 | `-k' |
3471 | All arguments in the form of assignment statements are placed | |
3472 | in the environment for a command, not just those that precede | |
3473 | the command name. | |
ccc6cda3 | 3474 | |
bb70624e | 3475 | `-m' |
28ef6c31 | 3476 | Job control is enabled (*note Job Control::). |
b72432fd | 3477 | |
bb70624e JA |
3478 | `-n' |
3479 | Read commands but do not execute them; this may be used to | |
3480 | check a script for syntax errors. This option is ignored by | |
3481 | interactive shells. | |
ccc6cda3 | 3482 | |
bb70624e JA |
3483 | `-o OPTION-NAME' |
3484 | Set the option corresponding to OPTION-NAME: | |
ccc6cda3 | 3485 | |
bb70624e JA |
3486 | `allexport' |
3487 | Same as `-a'. | |
ccc6cda3 | 3488 | |
bb70624e JA |
3489 | `braceexpand' |
3490 | Same as `-B'. | |
ccc6cda3 | 3491 | |
bb70624e JA |
3492 | `emacs' |
3493 | Use an `emacs'-style line editing interface (*note | |
a9fac3b2 CR |
3494 | Command Line Editing::). This also affects the editing |
3495 | interface used for `read -e'. | |
ccc6cda3 | 3496 | |
bb70624e JA |
3497 | `errexit' |
3498 | Same as `-e'. | |
d166f048 | 3499 | |
d3a24ed2 CR |
3500 | `errtrace' |
3501 | Same as `-E'. | |
3502 | ||
3503 | `functrace' | |
3504 | Same as `-T'. | |
3505 | ||
bb70624e JA |
3506 | `hashall' |
3507 | Same as `-h'. | |
d166f048 | 3508 | |
bb70624e JA |
3509 | `histexpand' |
3510 | Same as `-H'. | |
ccc6cda3 | 3511 | |
bb70624e | 3512 | `history' |
6a8fd0ed | 3513 | Enable command history, as described in *note Bash |
bb70624e JA |
3514 | History Facilities::. This option is on by default in |
3515 | interactive shells. | |
ccc6cda3 | 3516 | |
bb70624e JA |
3517 | `ignoreeof' |
3518 | An interactive shell will not exit upon reading EOF. | |
ccc6cda3 | 3519 | |
bb70624e JA |
3520 | `keyword' |
3521 | Same as `-k'. | |
ccc6cda3 | 3522 | |
bb70624e JA |
3523 | `monitor' |
3524 | Same as `-m'. | |
ccc6cda3 | 3525 | |
bb70624e JA |
3526 | `noclobber' |
3527 | Same as `-C'. | |
ccc6cda3 | 3528 | |
bb70624e JA |
3529 | `noexec' |
3530 | Same as `-n'. | |
ccc6cda3 | 3531 | |
28157acd CR |
3532 | `noglob' |
3533 | Same as `-f'. | |
9d6e5e30 | 3534 | |
d3ad40de CR |
3535 | `nolog' |
3536 | Currently ignored. | |
3537 | ||
3538 | `notify' | |
3539 | Same as `-b'. | |
3540 | ||
3541 | `nounset' | |
3542 | Same as `-u'. | |
3543 | ||
3544 | `onecmd' | |
3545 | Same as `-t'. | |
3546 | ||
3547 | `physical' | |
3548 | Same as `-P'. | |
3549 | ||
3550 | `pipefail' | |
3551 | If set, the return value of a pipeline is the value of | |
3552 | the last (rightmost) command to exit with a non-zero | |
3553 | status, or zero if all commands in the pipeline exit | |
3554 | successfully. This option is disabled by default. | |
3555 | ||
3556 | `posix' | |
3557 | Change the behavior of Bash where the default operation | |
3558 | differs from the POSIX standard to match the standard | |
3559 | (*note Bash POSIX Mode::). This is intended to make | |
3560 | Bash behave as a strict superset of that standard. | |
3561 | ||
3562 | `privileged' | |
3563 | Same as `-p'. | |
3564 | ||
3565 | `verbose' | |
3566 | Same as `-v'. | |
3567 | ||
3568 | `vi' | |
a9fac3b2 CR |
3569 | Use a `vi'-style line editing interface. This also |
3570 | affects the editing interface used for `read -e'. | |
d3ad40de CR |
3571 | |
3572 | `xtrace' | |
3573 | Same as `-x'. | |
3574 | ||
3575 | `-p' | |
3576 | Turn on privileged mode. In this mode, the `$BASH_ENV' and | |
3577 | `$ENV' files are not processed, shell functions are not | |
a9fac3b2 CR |
3578 | inherited from the environment, and the `SHELLOPTS', `CDPATH' |
3579 | and `GLOBIGNORE' variables, if they appear in the | |
3580 | environment, are ignored. If the shell is started with the | |
3581 | effective user (group) id not equal to the real user (group) | |
3582 | id, and the `-p' option is not supplied, these actions are | |
3583 | taken and the effective user id is set to the real user id. | |
3584 | If the `-p' option is supplied at startup, the effective user | |
3585 | id is not reset. Turning this option off causes the | |
3586 | effective user and group ids to be set to the real user and | |
3587 | group ids. | |
d3ad40de CR |
3588 | |
3589 | `-t' | |
3590 | Exit after reading and executing one command. | |
3591 | ||
3592 | `-u' | |
2c471a92 CR |
3593 | Treat unset variables and parameters other than the special |
3594 | parameters `@' or `*' as an error when performing parameter | |
d3ad40de CR |
3595 | expansion. An error message will be written to the standard |
3596 | error, and a non-interactive shell will exit. | |
3597 | ||
3598 | `-v' | |
3599 | Print shell input lines as they are read. | |
3600 | ||
3601 | `-x' | |
3602 | Print a trace of simple commands, `for' commands, `case' | |
3603 | commands, `select' commands, and arithmetic `for' commands | |
3604 | and their arguments or associated word lists after they are | |
3605 | expanded and before they are executed. The value of the `PS4' | |
3606 | variable is expanded and the resultant value is printed before | |
3607 | the command and its expanded arguments. | |
3608 | ||
3609 | `-B' | |
3610 | The shell will perform brace expansion (*note Brace | |
3611 | Expansion::). This option is on by default. | |
3612 | ||
3613 | `-C' | |
3614 | Prevent output redirection using `>', `>&', and `<>' from | |
3615 | overwriting existing files. | |
3616 | ||
3617 | `-E' | |
3618 | If set, any trap on `ERR' is inherited by shell functions, | |
3619 | command substitutions, and commands executed in a subshell | |
3620 | environment. The `ERR' trap is normally not inherited in | |
3621 | such cases. | |
3622 | ||
3623 | `-H' | |
3624 | Enable `!' style history substitution (*note History | |
3625 | Interaction::). This option is on by default for interactive | |
3626 | shells. | |
3627 | ||
3628 | `-P' | |
3629 | If set, do not follow symbolic links when performing commands | |
3630 | such as `cd' which change the current directory. The | |
3631 | physical directory is used instead. By default, Bash follows | |
3632 | the logical chain of directories when performing commands | |
3633 | which change the current directory. | |
3634 | ||
3635 | For example, if `/usr/sys' is a symbolic link to | |
3636 | `/usr/local/sys' then: | |
3637 | $ cd /usr/sys; echo $PWD | |
3638 | /usr/sys | |
3639 | $ cd ..; pwd | |
3640 | /usr | |
3641 | ||
3642 | If `set -P' is on, then: | |
3643 | $ cd /usr/sys; echo $PWD | |
3644 | /usr/local/sys | |
3645 | $ cd ..; pwd | |
3646 | /usr/local | |
3647 | ||
3648 | `-T' | |
3649 | If set, any trap on `DEBUG' and `RETURN' are inherited by | |
3650 | shell functions, command substitutions, and commands executed | |
3651 | in a subshell environment. The `DEBUG' and `RETURN' traps | |
3652 | are normally not inherited in such cases. | |
3653 | ||
3654 | `--' | |
3655 | If no arguments follow this option, then the positional | |
3656 | parameters are unset. Otherwise, the positional parameters | |
3657 | are set to the ARGUMENTS, even if some of them begin with a | |
3658 | `-'. | |
3659 | ||
3660 | `-' | |
3661 | Signal the end of options, cause all remaining ARGUMENTS to | |
3662 | be assigned to the positional parameters. The `-x' and `-v' | |
3663 | options are turned off. If there are no arguments, the | |
3664 | positional parameters remain unchanged. | |
3665 | ||
3666 | Using `+' rather than `-' causes these options to be turned off. | |
3667 | The options can also be used upon invocation of the shell. The | |
3668 | current set of options may be found in `$-'. | |
3669 | ||
3670 | The remaining N ARGUMENTS are positional parameters and are | |
3671 | assigned, in order, to `$1', `$2', ... `$N'. The special | |
3672 | parameter `#' is set to N. | |
3673 | ||
3674 | The return status is always zero unless an invalid option is | |
3675 | supplied. | |
3676 | ||
3677 | \1f | |
3678 | File: bashref.info, Node: The Shopt Builtin, Prev: The Set Builtin, Up: Modifying Shell Behavior | |
3679 | ||
3680 | 4.3.2 The Shopt Builtin | |
3681 | ----------------------- | |
3682 | ||
3683 | This builtin allows you to change additional shell optional behavior. | |
3684 | ||
3685 | `shopt' | |
3686 | shopt [-pqsu] [-o] [OPTNAME ...] | |
3687 | Toggle the values of variables controlling optional shell behavior. | |
3688 | With no options, or with the `-p' option, a list of all settable | |
3689 | options is displayed, with an indication of whether or not each is | |
3690 | set. The `-p' option causes output to be displayed in a form that | |
3691 | may be reused as input. Other options have the following meanings: | |
3692 | ||
3693 | `-s' | |
3694 | Enable (set) each OPTNAME. | |
3695 | ||
3696 | `-u' | |
3697 | Disable (unset) each OPTNAME. | |
3698 | ||
3699 | `-q' | |
3700 | Suppresses normal output; the return status indicates whether | |
3701 | the OPTNAME is set or unset. If multiple OPTNAME arguments | |
3702 | are given with `-q', the return status is zero if all | |
3703 | OPTNAMES are enabled; non-zero otherwise. | |
3704 | ||
3705 | `-o' | |
3706 | Restricts the values of OPTNAME to be those defined for the | |
3707 | `-o' option to the `set' builtin (*note The Set Builtin::). | |
3708 | ||
3709 | If either `-s' or `-u' is used with no OPTNAME arguments, the | |
3710 | display is limited to those options which are set or unset, | |
3711 | respectively. | |
3712 | ||
3713 | Unless otherwise noted, the `shopt' options are disabled (off) by | |
3714 | default. | |
3715 | ||
3716 | The return status when listing options is zero if all OPTNAMES are | |
3717 | enabled, non-zero otherwise. When setting or unsetting options, | |
3718 | the return status is zero unless an OPTNAME is not a valid shell | |
3719 | option. | |
3720 | ||
3721 | The list of `shopt' options is: | |
3722 | `autocd' | |
3723 | If set, a command name that is the name of a directory is | |
3724 | executed as if it were the argument to the `cd' command. | |
3725 | This option is only used by interactive shells. | |
3726 | ||
3727 | `cdable_vars' | |
3728 | If this is set, an argument to the `cd' builtin command that | |
3729 | is not a directory is assumed to be the name of a variable | |
3730 | whose value is the directory to change to. | |
3731 | ||
3732 | `cdspell' | |
3733 | If set, minor errors in the spelling of a directory component | |
3734 | in a `cd' command will be corrected. The errors checked for | |
3735 | are transposed characters, a missing character, and a | |
3736 | character too many. If a correction is found, the corrected | |
3737 | path is printed, and the command proceeds. This option is | |
3738 | only used by interactive shells. | |
3739 | ||
3740 | `checkhash' | |
3741 | If this is set, Bash checks that a command found in the hash | |
3742 | table exists before trying to execute it. If a hashed | |
3743 | command no longer exists, a normal path search is performed. | |
3744 | ||
3745 | `checkjobs' | |
3746 | If set, Bash lists the status of any stopped and running jobs | |
3747 | before exiting an interactive shell. If any jobs are | |
3748 | running, this causes the exit to be deferred until a second | |
3749 | exit is attempted without an intervening command (*note Job | |
3750 | Control::). The shell always postpones exiting if any jobs | |
3751 | are stopped. | |
3752 | ||
3753 | `checkwinsize' | |
3754 | If set, Bash checks the window size after each command and, | |
3755 | if necessary, updates the values of `LINES' and `COLUMNS'. | |
3756 | ||
3757 | `cmdhist' | |
3758 | If set, Bash attempts to save all lines of a multiple-line | |
3759 | command in the same history entry. This allows easy | |
3760 | re-editing of multi-line commands. | |
3761 | ||
29d25b54 CR |
3762 | `compat31' |
3763 | If set, Bash changes its behavior to that of version 3.1 with | |
3764 | respect to quoted arguments to the conditional command's =~ | |
3765 | operator. | |
3766 | ||
ed35cb4a CR |
3767 | `dirspell' |
3768 | If set, Bash attempts spelling correction on directory names | |
3769 | during word completion if the directory name initially | |
3770 | supplied does not exist. | |
3771 | ||
d3ad40de CR |
3772 | `dotglob' |
3773 | If set, Bash includes filenames beginning with a `.' in the | |
3774 | results of filename expansion. | |
3775 | ||
3776 | `execfail' | |
3777 | If this is set, a non-interactive shell will not exit if it | |
3778 | cannot execute the file specified as an argument to the `exec' | |
3779 | builtin command. An interactive shell does not exit if `exec' | |
3780 | fails. | |
3781 | ||
3782 | `expand_aliases' | |
3783 | If set, aliases are expanded as described below under Aliases, | |
6a8fd0ed | 3784 | *note Aliases::. This option is enabled by default for |
d3ad40de CR |
3785 | interactive shells. |
3786 | ||
3787 | `extdebug' | |
3788 | If set, behavior intended for use by debuggers is enabled: | |
3789 | ||
3790 | 1. The `-F' option to the `declare' builtin (*note Bash | |
3791 | Builtins::) displays the source file name and line | |
3792 | number corresponding to each function name supplied as | |
3793 | an argument. | |
3794 | ||
3795 | 2. If the command run by the `DEBUG' trap returns a | |
3796 | non-zero value, the next command is skipped and not | |
3797 | executed. | |
3798 | ||
3799 | 3. If the command run by the `DEBUG' trap returns a value | |
3800 | of 2, and the shell is executing in a subroutine (a | |
3801 | shell function or a shell script executed by the `.' or | |
3802 | `source' builtins), a call to `return' is simulated. | |
3803 | ||
3804 | 4. `BASH_ARGC' and `BASH_ARGV' are updated as described in | |
3805 | their descriptions (*note Bash Variables::). | |
3806 | ||
3807 | 5. Function tracing is enabled: command substitution, | |
3808 | shell functions, and subshells invoked with `( COMMAND | |
3809 | )' inherit the `DEBUG' and `RETURN' traps. | |
9d6e5e30 | 3810 | |
d3ad40de CR |
3811 | 6. Error tracing is enabled: command substitution, shell |
3812 | functions, and subshells invoked with `( COMMAND )' | |
3813 | inherit the `ERROR' trap. | |
9d6e5e30 | 3814 | |
d3ad40de CR |
3815 | `extglob' |
3816 | If set, the extended pattern matching features described above | |
3817 | (*note Pattern Matching::) are enabled. | |
9d6e5e30 | 3818 | |
d3ad40de CR |
3819 | `extquote' |
3820 | If set, `$'STRING'' and `$"STRING"' quoting is performed | |
3821 | within `${PARAMETER}' expansions enclosed in double quotes. | |
3822 | This option is enabled by default. | |
9d6e5e30 | 3823 | |
d3ad40de CR |
3824 | `failglob' |
3825 | If set, patterns which fail to match filenames during | |
4a8bb13f | 3826 | filename expansion result in an expansion error. |
9d6e5e30 | 3827 | |
d3ad40de CR |
3828 | `force_fignore' |
3829 | If set, the suffixes specified by the `FIGNORE' shell variable | |
3830 | cause words to be ignored when performing word completion | |
3831 | even if the ignored words are the only possible completions. | |
3832 | *Note Bash Variables::, for a description of `FIGNORE'. This | |
3833 | option is enabled by default. | |
9d6e5e30 | 3834 | |
ed35cb4a CR |
3835 | `globstar' |
3836 | If set, the pattern `**' used in a filename expansion context | |
3837 | will match a files and zero or more directories and | |
3838 | subdirectories. If the pattern is followed by a `/', only | |
3839 | directories and subdirectories match. | |
3840 | ||
d3ad40de CR |
3841 | `gnu_errfmt' |
3842 | If set, shell error messages are written in the standard GNU | |
3843 | error message format. | |
9d6e5e30 | 3844 | |
d3ad40de CR |
3845 | `histappend' |
3846 | If set, the history list is appended to the file named by the | |
3847 | value of the `HISTFILE' variable when the shell exits, rather | |
3848 | than overwriting the file. | |
9d6e5e30 | 3849 | |
d3ad40de CR |
3850 | `histreedit' |
3851 | If set, and Readline is being used, a user is given the | |
3852 | opportunity to re-edit a failed history substitution. | |
9d6e5e30 | 3853 | |
d3ad40de CR |
3854 | `histverify' |
3855 | If set, and Readline is being used, the results of history | |
3856 | substitution are not immediately passed to the shell parser. | |
3857 | Instead, the resulting line is loaded into the Readline | |
3858 | editing buffer, allowing further modification. | |
9d6e5e30 | 3859 | |
d3ad40de CR |
3860 | `hostcomplete' |
3861 | If set, and Readline is being used, Bash will attempt to | |
3862 | perform hostname completion when a word containing a `@' is | |
3863 | being completed (*note Commands For Completion::). This | |
3864 | option is enabled by default. | |
9d6e5e30 | 3865 | |
d3ad40de CR |
3866 | `huponexit' |
3867 | If set, Bash will send `SIGHUP' to all jobs when an | |
3868 | interactive login shell exits (*note Signals::). | |
9d6e5e30 | 3869 | |
d3ad40de CR |
3870 | `interactive_comments' |
3871 | Allow a word beginning with `#' to cause that word and all | |
3872 | remaining characters on that line to be ignored in an | |
3873 | interactive shell. This option is enabled by default. | |
9d6e5e30 | 3874 | |
d3ad40de CR |
3875 | `lithist' |
3876 | If enabled, and the `cmdhist' option is enabled, multi-line | |
3877 | commands are saved to the history with embedded newlines | |
3878 | rather than using semicolon separators where possible. | |
9d6e5e30 | 3879 | |
d3ad40de CR |
3880 | `login_shell' |
3881 | The shell sets this option if it is started as a login shell | |
3882 | (*note Invoking Bash::). The value may not be changed. | |
9d6e5e30 | 3883 | |
d3ad40de CR |
3884 | `mailwarn' |
3885 | If set, and a file that Bash is checking for mail has been | |
3886 | accessed since the last time it was checked, the message | |
3887 | `"The mail in MAILFILE has been read"' is displayed. | |
9d6e5e30 | 3888 | |
d3ad40de CR |
3889 | `no_empty_cmd_completion' |
3890 | If set, and Readline is being used, Bash will not attempt to | |
3891 | search the `PATH' for possible completions when completion is | |
3892 | attempted on an empty line. | |
9d6e5e30 | 3893 | |
d3ad40de CR |
3894 | `nocaseglob' |
3895 | If set, Bash matches filenames in a case-insensitive fashion | |
3896 | when performing filename expansion. | |
9d6e5e30 | 3897 | |
d3ad40de CR |
3898 | `nocasematch' |
3899 | If set, Bash matches patterns in a case-insensitive fashion | |
3900 | when performing matching while executing `case' or `[[' | |
3901 | conditional commands. | |
9d6e5e30 | 3902 | |
d3ad40de CR |
3903 | `nullglob' |
3904 | If set, Bash allows filename patterns which match no files to | |
3905 | expand to a null string, rather than themselves. | |
9d6e5e30 | 3906 | |
d3ad40de CR |
3907 | `progcomp' |
3908 | If set, the programmable completion facilities (*note | |
3909 | Programmable Completion::) are enabled. This option is | |
3910 | enabled by default. | |
9d6e5e30 | 3911 | |
d3ad40de CR |
3912 | `promptvars' |
3913 | If set, prompt strings undergo parameter expansion, command | |
3914 | substitution, arithmetic expansion, and quote removal after | |
3915 | being expanded as described below (*note Printing a Prompt::). | |
3916 | This option is enabled by default. | |
9d6e5e30 | 3917 | |
d3ad40de CR |
3918 | `restricted_shell' |
3919 | The shell sets this option if it is started in restricted mode | |
3920 | (*note The Restricted Shell::). The value may not be changed. | |
3921 | This is not reset when the startup files are executed, | |
3922 | allowing the startup files to discover whether or not a shell | |
3923 | is restricted. | |
9d6e5e30 | 3924 | |
d3ad40de CR |
3925 | `shift_verbose' |
3926 | If this is set, the `shift' builtin prints an error message | |
3927 | when the shift count exceeds the number of positional | |
3928 | parameters. | |
9d6e5e30 | 3929 | |
d3ad40de CR |
3930 | `sourcepath' |
3931 | If set, the `source' builtin uses the value of `PATH' to find | |
3932 | the directory containing the file supplied as an argument. | |
3933 | This option is enabled by default. | |
9d6e5e30 | 3934 | |
d3ad40de CR |
3935 | `xpg_echo' |
3936 | If set, the `echo' builtin expands backslash-escape sequences | |
3937 | by default. | |
9d6e5e30 CR |
3938 | |
3939 | ||
d3ad40de CR |
3940 | The return status when listing options is zero if all OPTNAMES are |
3941 | enabled, non-zero otherwise. When setting or unsetting options, | |
3942 | the return status is zero unless an OPTNAME is not a valid shell | |
3943 | option. | |
9d6e5e30 CR |
3944 | |
3945 | ||
3946 | \1f | |
d3ad40de | 3947 | File: bashref.info, Node: Special Builtins, Prev: Modifying Shell Behavior, Up: Shell Builtin Commands |
ccc6cda3 | 3948 | |
37c41ab1 CR |
3949 | 4.4 Special Builtins |
3950 | ==================== | |
ccc6cda3 | 3951 | |
ac18b312 CR |
3952 | For historical reasons, the POSIX standard has classified several |
3953 | builtin commands as _special_. When Bash is executing in POSIX mode, | |
3954 | the special builtins differ from other builtin commands in three | |
bb70624e | 3955 | respects: |
ccc6cda3 | 3956 | |
bb70624e JA |
3957 | 1. Special builtins are found before shell functions during command |
3958 | lookup. | |
ccc6cda3 | 3959 | |
bb70624e JA |
3960 | 2. If a special builtin returns an error status, a non-interactive |
3961 | shell exits. | |
ccc6cda3 | 3962 | |
bb70624e JA |
3963 | 3. Assignment statements preceding the command stay in effect in the |
3964 | shell environment after the command completes. | |
ccc6cda3 | 3965 | |
bb70624e JA |
3966 | When Bash is not executing in POSIX mode, these builtins behave no |
3967 | differently than the rest of the Bash builtin commands. The Bash POSIX | |
6a8fd0ed | 3968 | mode is described in *note Bash POSIX Mode::. |
ccc6cda3 | 3969 | |
bb70624e JA |
3970 | These are the POSIX special builtins: |
3971 | break : . continue eval exec exit export readonly return set | |
3972 | shift trap unset | |
ccc6cda3 | 3973 | |
bb70624e JA |
3974 | \1f |
3975 | File: bashref.info, Node: Shell Variables, Next: Bash Features, Prev: Shell Builtin Commands, Up: Top | |
cce855bc | 3976 | |
37c41ab1 CR |
3977 | 5 Shell Variables |
3978 | ***************** | |
ccc6cda3 | 3979 | |
bb70624e | 3980 | * Menu: |
ccc6cda3 | 3981 | |
bb70624e JA |
3982 | * Bourne Shell Variables:: Variables which Bash uses in the same way |
3983 | as the Bourne Shell. | |
3984 | * Bash Variables:: List of variables that exist in Bash. | |
ccc6cda3 | 3985 | |
bb70624e JA |
3986 | This chapter describes the shell variables that Bash uses. Bash |
3987 | automatically assigns default values to a number of variables. | |
cce855bc | 3988 | |
bb70624e JA |
3989 | \1f |
3990 | File: bashref.info, Node: Bourne Shell Variables, Next: Bash Variables, Up: Shell Variables | |
ccc6cda3 | 3991 | |
37c41ab1 CR |
3992 | 5.1 Bourne Shell Variables |
3993 | ========================== | |
cce855bc | 3994 | |
37c41ab1 CR |
3995 | Bash uses certain shell variables in the same way as the Bourne shell. |
3996 | In some cases, Bash assigns a default value to the variable. | |
cce855bc | 3997 | |
bb70624e JA |
3998 | `CDPATH' |
3999 | A colon-separated list of directories used as a search path for | |
4000 | the `cd' builtin command. | |
ccc6cda3 | 4001 | |
bb70624e JA |
4002 | `HOME' |
4003 | The current user's home directory; the default for the `cd' builtin | |
4004 | command. The value of this variable is also used by tilde | |
28ef6c31 | 4005 | expansion (*note Tilde Expansion::). |
ccc6cda3 | 4006 | |
bb70624e JA |
4007 | `IFS' |
4008 | A list of characters that separate fields; used when the shell | |
4009 | splits words as part of expansion. | |
ccc6cda3 | 4010 | |
bb70624e JA |
4011 | `MAIL' |
4012 | If this parameter is set to a filename and the `MAILPATH' variable | |
4013 | is not set, Bash informs the user of the arrival of mail in the | |
4014 | specified file. | |
cce855bc | 4015 | |
bb70624e JA |
4016 | `MAILPATH' |
4017 | A colon-separated list of filenames which the shell periodically | |
4018 | checks for new mail. Each list entry can specify the message that | |
4019 | is printed when new mail arrives in the mail file by separating | |
4020 | the file name from the message with a `?'. When used in the text | |
4021 | of the message, `$_' expands to the name of the current mail file. | |
cce855bc | 4022 | |
bb70624e JA |
4023 | `OPTARG' |
4024 | The value of the last option argument processed by the `getopts' | |
4025 | builtin. | |
ccc6cda3 | 4026 | |
bb70624e JA |
4027 | `OPTIND' |
4028 | The index of the last option argument processed by the `getopts' | |
4029 | builtin. | |
ccc6cda3 | 4030 | |
bb70624e JA |
4031 | `PATH' |
4032 | A colon-separated list of directories in which the shell looks for | |
d3a24ed2 CR |
4033 | commands. A zero-length (null) directory name in the value of |
4034 | `PATH' indicates the current directory. A null directory name may | |
4035 | appear as two adjacent colons, or as an initial or trailing colon. | |
ccc6cda3 | 4036 | |
bb70624e JA |
4037 | `PS1' |
4038 | The primary prompt string. The default value is `\s-\v\$ '. | |
4039 | *Note Printing a Prompt::, for the complete list of escape | |
4040 | sequences that are expanded before `PS1' is displayed. | |
ccc6cda3 | 4041 | |
bb70624e JA |
4042 | `PS2' |
4043 | The secondary prompt string. The default value is `> '. | |
ccc6cda3 | 4044 | |
761783bf | 4045 | |
bb70624e JA |
4046 | \1f |
4047 | File: bashref.info, Node: Bash Variables, Prev: Bourne Shell Variables, Up: Shell Variables | |
ccc6cda3 | 4048 | |
37c41ab1 CR |
4049 | 5.2 Bash Variables |
4050 | ================== | |
ccc6cda3 | 4051 | |
37c41ab1 | 4052 | These variables are set or used by Bash, but other shells do not |
bb70624e | 4053 | normally treat them specially. |
ccc6cda3 | 4054 | |
bb70624e JA |
4055 | A few variables used by Bash are described in different chapters: |
4056 | variables for controlling the job control facilities (*note Job Control | |
28ef6c31 | 4057 | Variables::). |
ccc6cda3 | 4058 | |
bb70624e JA |
4059 | `BASH' |
4060 | The full pathname used to execute the current instance of Bash. | |
ccc6cda3 | 4061 | |
d3ad40de CR |
4062 | `BASHPID' |
4063 | Expands to the process id of the current Bash process. This | |
4064 | differs from `$$' under certain circumstances, such as subshells | |
4065 | that do not require Bash to be re-initialized. | |
4066 | ||
09767ff0 CR |
4067 | `BASH_ALIASES' |
4068 | An associative array variable whose members correspond to the | |
4069 | internal list of aliases as maintained by the `alias' builtin | |
4070 | (*note Bourne Shell Builtins::). Elements added to this array | |
4071 | appear in the alias list; unsetting array elements cause aliases | |
4072 | to be removed from the alias list. | |
4073 | ||
d3a24ed2 CR |
4074 | `BASH_ARGC' |
4075 | An array variable whose values are the number of parameters in each | |
4076 | frame of the current bash execution call stack. The number of | |
4077 | parameters to the current subroutine (shell function or script | |
4078 | executed with `.' or `source') is at the top of the stack. When a | |
4079 | subroutine is executed, the number of parameters passed is pushed | |
9d2b70f0 | 4080 | onto `BASH_ARGC'. The shell sets `BASH_ARGC' only when in |
6a8fd0ed | 4081 | extended debugging mode (see *note The Shopt Builtin:: for a |
9d2b70f0 | 4082 | description of the `extdebug' option to the `shopt' builtin). |
d3a24ed2 CR |
4083 | |
4084 | `BASH_ARGV' | |
4085 | An array variable containing all of the parameters in the current | |
4086 | bash execution call stack. The final parameter of the last | |
4087 | subroutine call is at the top of the stack; the first parameter of | |
4088 | the initial call is at the bottom. When a subroutine is executed, | |
9d2b70f0 | 4089 | the parameters supplied are pushed onto `BASH_ARGV'. The shell |
6a8fd0ed | 4090 | sets `BASH_ARGV' only when in extended debugging mode (see *note |
d3ad40de CR |
4091 | The Shopt Builtin:: for a description of the `extdebug' option to |
4092 | the `shopt' builtin). | |
d3a24ed2 | 4093 | |
09767ff0 CR |
4094 | `BASH_CMDS' |
4095 | An associative array variable whose members correspond to the | |
4096 | internal hash table of commands as maintained by the `hash' builtin | |
4097 | (*note Bourne Shell Builtins::). Elements added to this array | |
4098 | appear in the hash table; unsetting array elements cause commands | |
4099 | to be removed from the hash table. | |
4100 | ||
d3a24ed2 CR |
4101 | `BASH_COMMAND' |
4102 | The command currently being executed or about to be executed, | |
4103 | unless the shell is executing a command as the result of a trap, | |
4104 | in which case it is the command executing at the time of the trap. | |
4105 | ||
bb70624e JA |
4106 | `BASH_ENV' |
4107 | If this variable is set when Bash is invoked to execute a shell | |
4108 | script, its value is expanded and used as the name of a startup | |
4109 | file to read before executing the script. *Note Bash Startup | |
4110 | Files::. | |
ccc6cda3 | 4111 | |
d3a24ed2 CR |
4112 | `BASH_EXECUTION_STRING' |
4113 | The command argument to the `-c' invocation option. | |
4114 | ||
4115 | `BASH_LINENO' | |
4116 | An array variable whose members are the line numbers in source | |
4117 | files corresponding to each member of FUNCNAME. | |
4118 | `${BASH_LINENO[$i]}' is the line number in the source file where | |
c2a47ea9 CR |
4119 | `${FUNCNAME[$i]}' was called (or `${BASH_LINENO[$i-1]}' if |
4120 | referenced within another shell function). The corresponding | |
4121 | source file name is `${BASH_SOURCE[$i]}'. Use `LINENO' to obtain | |
4122 | the current line number. | |
d3a24ed2 | 4123 | |
5e13499c CR |
4124 | `BASH_REMATCH' |
4125 | An array variable whose members are assigned by the `=~' binary | |
4126 | operator to the `[[' conditional command (*note Conditional | |
4127 | Constructs::). The element with index 0 is the portion of the | |
4128 | string matching the entire regular expression. The element with | |
4129 | index N is the portion of the string matching the Nth | |
4130 | parenthesized subexpression. This variable is read-only. | |
4131 | ||
d3a24ed2 CR |
4132 | `BASH_SOURCE' |
4133 | An array variable whose members are the source filenames | |
4134 | corresponding to the elements in the `FUNCNAME' array variable. | |
4135 | ||
4136 | `BASH_SUBSHELL' | |
4137 | Incremented by one each time a subshell or subshell environment is | |
4138 | spawned. The initial value is 0. | |
ccc6cda3 | 4139 | |
bb70624e | 4140 | `BASH_VERSINFO' |
28ef6c31 | 4141 | A readonly array variable (*note Arrays::) whose members hold |
bb70624e JA |
4142 | version information for this instance of Bash. The values |
4143 | assigned to the array members are as follows: | |
ccc6cda3 | 4144 | |
bb70624e JA |
4145 | `BASH_VERSINFO[0]' |
4146 | The major version number (the RELEASE). | |
ccc6cda3 | 4147 | |
bb70624e JA |
4148 | `BASH_VERSINFO[1]' |
4149 | The minor version number (the VERSION). | |
ccc6cda3 | 4150 | |
bb70624e JA |
4151 | `BASH_VERSINFO[2]' |
4152 | The patch level. | |
ccc6cda3 | 4153 | |
bb70624e JA |
4154 | `BASH_VERSINFO[3]' |
4155 | The build version. | |
ccc6cda3 | 4156 | |
bb70624e JA |
4157 | `BASH_VERSINFO[4]' |
4158 | The release status (e.g., BETA1). | |
ccc6cda3 | 4159 | |
bb70624e JA |
4160 | `BASH_VERSINFO[5]' |
4161 | The value of `MACHTYPE'. | |
ccc6cda3 | 4162 | |
761783bf | 4163 | |
d3a24ed2 CR |
4164 | `BASH_VERSION' |
4165 | The version number of the current instance of Bash. | |
4166 | ||
f73dda09 JA |
4167 | `COLUMNS' |
4168 | Used by the `select' builtin command to determine the terminal | |
4169 | width when printing selection lists. Automatically set upon | |
4170 | receipt of a `SIGWINCH'. | |
bb70624e JA |
4171 | |
4172 | `COMP_CWORD' | |
4173 | An index into `${COMP_WORDS}' of the word containing the current | |
4174 | cursor position. This variable is available only in shell | |
4175 | functions invoked by the programmable completion facilities (*note | |
28ef6c31 | 4176 | Programmable Completion::). |
bb70624e JA |
4177 | |
4178 | `COMP_LINE' | |
4179 | The current command line. This variable is available only in | |
4180 | shell functions and external commands invoked by the programmable | |
28ef6c31 | 4181 | completion facilities (*note Programmable Completion::). |
bb70624e JA |
4182 | |
4183 | `COMP_POINT' | |
4184 | The index of the current cursor position relative to the beginning | |
4185 | of the current command. If the current cursor position is at the | |
4186 | end of the current command, the value of this variable is equal to | |
4187 | `${#COMP_LINE}'. This variable is available only in shell | |
4188 | functions and external commands invoked by the programmable | |
28ef6c31 | 4189 | completion facilities (*note Programmable Completion::). |
bb70624e | 4190 | |
d3ad40de CR |
4191 | `COMP_TYPE' |
4192 | Set to an integer value corresponding to the type of completion | |
4193 | attempted that caused a completion function to be called: TAB, for | |
4194 | normal completion, `?', for listing completions after successive | |
4195 | tabs, `!', for listing alternatives on partial word completion, | |
4196 | `@', to list completions if the word is not unmodified, or `%', | |
4197 | for menu completion. This variable is available only in shell | |
4198 | functions and external commands invoked by the programmable | |
4199 | completion facilities (*note Programmable Completion::). | |
4200 | ||
4201 | `COMP_KEY' | |
4202 | The key (or final key of a key sequence) used to invoke the current | |
4203 | completion function. | |
4204 | ||
d3a24ed2 CR |
4205 | `COMP_WORDBREAKS' |
4206 | The set of characters that the Readline library treats as word | |
4207 | separators when performing word completion. If `COMP_WORDBREAKS' | |
4208 | is unset, it loses its special properties, even if it is | |
4209 | subsequently reset. | |
4210 | ||
f73dda09 JA |
4211 | `COMP_WORDS' |
4212 | An array variable consisting of the individual words in the | |
6932f7f5 CR |
4213 | current command line. The line is split into words as Readline |
4214 | would split it, using `COMP_WORDBREAKS' as described above. This | |
4215 | variable is available only in shell functions invoked by the | |
4216 | programmable completion facilities (*note Programmable | |
4217 | Completion::). | |
f73dda09 | 4218 | |
bb70624e JA |
4219 | `COMPREPLY' |
4220 | An array variable from which Bash reads the possible completions | |
4221 | generated by a shell function invoked by the programmable | |
28ef6c31 | 4222 | completion facility (*note Programmable Completion::). |
ccc6cda3 | 4223 | |
bb70624e JA |
4224 | `DIRSTACK' |
4225 | An array variable containing the current contents of the directory | |
4226 | stack. Directories appear in the stack in the order they are | |
4227 | displayed by the `dirs' builtin. Assigning to members of this | |
4228 | array variable may be used to modify directories already in the | |
4229 | stack, but the `pushd' and `popd' builtins must be used to add and | |
4230 | remove directories. Assignment to this variable will not change | |
4231 | the current directory. If `DIRSTACK' is unset, it loses its | |
4232 | special properties, even if it is subsequently reset. | |
cce855bc | 4233 | |
d3a24ed2 CR |
4234 | `EMACS' |
4235 | If Bash finds this variable in the environment when the shell | |
4236 | starts with value `t', it assumes that the shell is running in an | |
4237 | emacs shell buffer and disables line editing. | |
4238 | ||
bb70624e JA |
4239 | `EUID' |
4240 | The numeric effective user id of the current user. This variable | |
4241 | is readonly. | |
cce855bc | 4242 | |
bb70624e JA |
4243 | `FCEDIT' |
4244 | The editor used as a default by the `-e' option to the `fc' | |
4245 | builtin command. | |
ccc6cda3 | 4246 | |
bb70624e JA |
4247 | `FIGNORE' |
4248 | A colon-separated list of suffixes to ignore when performing | |
4249 | filename completion. A file name whose suffix matches one of the | |
4250 | entries in `FIGNORE' is excluded from the list of matched file | |
4251 | names. A sample value is `.o:~' | |
ccc6cda3 | 4252 | |
f73dda09 | 4253 | `FUNCNAME' |
d3a24ed2 CR |
4254 | An array variable containing the names of all shell functions |
4255 | currently in the execution call stack. The element with index 0 | |
4256 | is the name of any currently-executing shell function. The | |
d3ad40de | 4257 | bottom-most element is `"main"'. This variable exists only when a |
d3a24ed2 CR |
4258 | shell function is executing. Assignments to `FUNCNAME' have no |
4259 | effect and return an error status. If `FUNCNAME' is unset, it | |
4260 | loses its special properties, even if it is subsequently reset. | |
f73dda09 | 4261 | |
bb70624e JA |
4262 | `GLOBIGNORE' |
4263 | A colon-separated list of patterns defining the set of filenames to | |
4264 | be ignored by filename expansion. If a filename matched by a | |
4265 | filename expansion pattern also matches one of the patterns in | |
4266 | `GLOBIGNORE', it is removed from the list of matches. | |
ccc6cda3 | 4267 | |
bb70624e JA |
4268 | `GROUPS' |
4269 | An array variable containing the list of groups of which the | |
4270 | current user is a member. Assignments to `GROUPS' have no effect | |
28ef6c31 | 4271 | and return an error status. If `GROUPS' is unset, it loses its |
bb70624e | 4272 | special properties, even if it is subsequently reset. |
ccc6cda3 | 4273 | |
bb70624e JA |
4274 | `histchars' |
4275 | Up to three characters which control history expansion, quick | |
28ef6c31 JA |
4276 | substitution, and tokenization (*note History Interaction::). The |
4277 | first character is the HISTORY EXPANSION character, that is, the | |
4278 | character which signifies the start of a history expansion, | |
bb70624e JA |
4279 | normally `!'. The second character is the character which |
4280 | signifies `quick substitution' when seen as the first character on | |
4281 | a line, normally `^'. The optional third character is the | |
4282 | character which indicates that the remainder of the line is a | |
4283 | comment when found as the first character of a word, usually `#'. | |
4284 | The history comment character causes history substitution to be | |
4285 | skipped for the remaining words on the line. It does not | |
4286 | necessarily cause the shell parser to treat the rest of the line | |
4287 | as a comment. | |
cce855bc | 4288 | |
bb70624e JA |
4289 | `HISTCMD' |
4290 | The history number, or index in the history list, of the current | |
4291 | command. If `HISTCMD' is unset, it loses its special properties, | |
4292 | even if it is subsequently reset. | |
ccc6cda3 | 4293 | |
bb70624e | 4294 | `HISTCONTROL' |
d3a24ed2 CR |
4295 | A colon-separated list of values controlling how commands are |
4296 | saved on the history list. If the list of values includes | |
4297 | `ignorespace', lines which begin with a space character are not | |
4298 | saved in the history list. A value of `ignoredups' causes lines | |
4299 | which match the previous history entry to not be saved. A value | |
4300 | of `ignoreboth' is shorthand for `ignorespace' and `ignoredups'. | |
4301 | A value of `erasedups' causes all previous lines matching the | |
4302 | current line to be removed from the history list before that line | |
4303 | is saved. Any value not in the above list is ignored. If | |
4304 | `HISTCONTROL' is unset, or does not include a valid value, all | |
4305 | lines read by the shell parser are saved on the history list, | |
4306 | subject to the value of `HISTIGNORE'. The second and subsequent | |
4307 | lines of a multi-line compound command are not tested, and are | |
4308 | added to the history regardless of the value of `HISTCONTROL'. | |
ccc6cda3 | 4309 | |
f73dda09 JA |
4310 | `HISTFILE' |
4311 | The name of the file to which the command history is saved. The | |
4312 | default value is `~/.bash_history'. | |
4313 | ||
4314 | `HISTFILESIZE' | |
4315 | The maximum number of lines contained in the history file. When | |
4316 | this variable is assigned a value, the history file is truncated, | |
d3ad40de CR |
4317 | if necessary, by removing the oldest entries, to contain no more |
4318 | than that number of lines. The history file is also truncated to | |
4319 | this size after writing it when an interactive shell exits. The | |
4320 | default value is 500. | |
f73dda09 | 4321 | |
bb70624e JA |
4322 | `HISTIGNORE' |
4323 | A colon-separated list of patterns used to decide which command | |
4324 | lines should be saved on the history list. Each pattern is | |
4325 | anchored at the beginning of the line and must match the complete | |
4326 | line (no implicit `*' is appended). Each pattern is tested | |
4327 | against the line after the checks specified by `HISTCONTROL' are | |
4328 | applied. In addition to the normal shell pattern matching | |
4329 | characters, `&' matches the previous history line. `&' may be | |
4330 | escaped using a backslash; the backslash is removed before | |
4331 | attempting a match. The second and subsequent lines of a | |
4332 | multi-line compound command are not tested, and are added to the | |
4333 | history regardless of the value of `HISTIGNORE'. | |
cce855bc | 4334 | |
bb70624e JA |
4335 | `HISTIGNORE' subsumes the function of `HISTCONTROL'. A pattern of |
4336 | `&' is identical to `ignoredups', and a pattern of `[ ]*' is | |
4337 | identical to `ignorespace'. Combining these two patterns, | |
4338 | separating them with a colon, provides the functionality of | |
4339 | `ignoreboth'. | |
ccc6cda3 | 4340 | |
bb70624e JA |
4341 | `HISTSIZE' |
4342 | The maximum number of commands to remember on the history list. | |
4343 | The default value is 500. | |
b72432fd | 4344 | |
d3a24ed2 CR |
4345 | `HISTTIMEFORMAT' |
4346 | If this variable is set and not null, its value is used as a | |
4347 | format string for STRFTIME to print the time stamp associated with | |
4348 | each history entry displayed by the `history' builtin. If this | |
4349 | variable is set, time stamps are written to the history file so | |
d3ad40de CR |
4350 | they may be preserved across shell sessions. This uses the |
4351 | history comment character to distinguish timestamps from other | |
4352 | history lines. | |
d3a24ed2 | 4353 | |
bb70624e JA |
4354 | `HOSTFILE' |
4355 | Contains the name of a file in the same format as `/etc/hosts' that | |
4356 | should be read when the shell needs to complete a hostname. The | |
4357 | list of possible hostname completions may be changed while the | |
4358 | shell is running; the next time hostname completion is attempted | |
4359 | after the value is changed, Bash adds the contents of the new file | |
4360 | to the existing list. If `HOSTFILE' is set, but has no value, | |
4361 | Bash attempts to read `/etc/hosts' to obtain the list of possible | |
4362 | hostname completions. When `HOSTFILE' is unset, the hostname list | |
4363 | is cleared. | |
cce855bc | 4364 | |
bb70624e JA |
4365 | `HOSTNAME' |
4366 | The name of the current host. | |
cce855bc | 4367 | |
bb70624e JA |
4368 | `HOSTTYPE' |
4369 | A string describing the machine Bash is running on. | |
ccc6cda3 | 4370 | |
bb70624e JA |
4371 | `IGNOREEOF' |
4372 | Controls the action of the shell on receipt of an `EOF' character | |
4373 | as the sole input. If set, the value denotes the number of | |
4374 | consecutive `EOF' characters that can be read as the first | |
4375 | character on an input line before the shell will exit. If the | |
4376 | variable exists but does not have a numeric value (or has no | |
4377 | value) then the default is 10. If the variable does not exist, | |
4378 | then `EOF' signifies the end of input to the shell. This is only | |
4379 | in effect for interactive shells. | |
ccc6cda3 | 4380 | |
bb70624e JA |
4381 | `INPUTRC' |
4382 | The name of the Readline initialization file, overriding the | |
4383 | default of `~/.inputrc'. | |
ccc6cda3 | 4384 | |
bb70624e JA |
4385 | `LANG' |
4386 | Used to determine the locale category for any category not | |
4387 | specifically selected with a variable starting with `LC_'. | |
ccc6cda3 | 4388 | |
bb70624e JA |
4389 | `LC_ALL' |
4390 | This variable overrides the value of `LANG' and any other `LC_' | |
4391 | variable specifying a locale category. | |
cce855bc | 4392 | |
bb70624e JA |
4393 | `LC_COLLATE' |
4394 | This variable determines the collation order used when sorting the | |
4395 | results of filename expansion, and determines the behavior of | |
4396 | range expressions, equivalence classes, and collating sequences | |
4397 | within filename expansion and pattern matching (*note Filename | |
28ef6c31 | 4398 | Expansion::). |
ccc6cda3 | 4399 | |
bb70624e JA |
4400 | `LC_CTYPE' |
4401 | This variable determines the interpretation of characters and the | |
4402 | behavior of character classes within filename expansion and pattern | |
28ef6c31 | 4403 | matching (*note Filename Expansion::). |
ccc6cda3 | 4404 | |
bb70624e JA |
4405 | `LC_MESSAGES' |
4406 | This variable determines the locale used to translate double-quoted | |
28ef6c31 | 4407 | strings preceded by a `$' (*note Locale Translation::). |
ccc6cda3 | 4408 | |
bb70624e JA |
4409 | `LC_NUMERIC' |
4410 | This variable determines the locale category used for number | |
4411 | formatting. | |
ccc6cda3 | 4412 | |
f73dda09 JA |
4413 | `LINENO' |
4414 | The line number in the script or shell function currently | |
4415 | executing. | |
4416 | ||
28ef6c31 JA |
4417 | `LINES' |
4418 | Used by the `select' builtin command to determine the column length | |
4419 | for printing selection lists. Automatically set upon receipt of a | |
4420 | `SIGWINCH'. | |
4421 | ||
bb70624e JA |
4422 | `MACHTYPE' |
4423 | A string that fully describes the system type on which Bash is | |
4424 | executing, in the standard GNU CPU-COMPANY-SYSTEM format. | |
ccc6cda3 | 4425 | |
bb70624e JA |
4426 | `MAILCHECK' |
4427 | How often (in seconds) that the shell should check for mail in the | |
28ef6c31 JA |
4428 | files specified in the `MAILPATH' or `MAIL' variables. The |
4429 | default is 60 seconds. When it is time to check for mail, the | |
4430 | shell does so before displaying the primary prompt. If this | |
4431 | variable is unset, or set to a value that is not a number greater | |
4432 | than or equal to zero, the shell disables mail checking. | |
ccc6cda3 | 4433 | |
bb70624e JA |
4434 | `OLDPWD' |
4435 | The previous working directory as set by the `cd' builtin. | |
ccc6cda3 | 4436 | |
bb70624e JA |
4437 | `OPTERR' |
4438 | If set to the value 1, Bash displays error messages generated by | |
4439 | the `getopts' builtin command. | |
ccc6cda3 | 4440 | |
bb70624e JA |
4441 | `OSTYPE' |
4442 | A string describing the operating system Bash is running on. | |
ccc6cda3 | 4443 | |
bb70624e | 4444 | `PIPESTATUS' |
28ef6c31 | 4445 | An array variable (*note Arrays::) containing a list of exit |
bb70624e JA |
4446 | status values from the processes in the most-recently-executed |
4447 | foreground pipeline (which may contain only a single command). | |
ccc6cda3 | 4448 | |
f73dda09 JA |
4449 | `POSIXLY_CORRECT' |
4450 | If this variable is in the environment when `bash' starts, the | |
4451 | shell enters POSIX mode (*note Bash POSIX Mode::) before reading | |
4452 | the startup files, as if the `--posix' invocation option had been | |
4453 | supplied. If it is set while the shell is running, `bash' enables | |
4454 | POSIX mode, as if the command | |
4455 | `set -o posix' | |
f73dda09 JA |
4456 | had been executed. |
4457 | ||
bb70624e JA |
4458 | `PPID' |
4459 | The process ID of the shell's parent process. This variable is | |
4460 | readonly. | |
ccc6cda3 | 4461 | |
bb70624e JA |
4462 | `PROMPT_COMMAND' |
4463 | If set, the value is interpreted as a command to execute before | |
4464 | the printing of each primary prompt (`$PS1'). | |
ccc6cda3 | 4465 | |
09767ff0 CR |
4466 | `PROMPT_DIRTRIM' |
4467 | If set to a number greater than zero, the value is used as the | |
4468 | number of trailing directory components to retain when expanding | |
4469 | the `\w' and `\W' prompt string escapes (*note Printing a | |
4470 | Prompt::). Characters removed are replaced with an ellipsis. | |
4471 | ||
bb70624e JA |
4472 | `PS3' |
4473 | The value of this variable is used as the prompt for the `select' | |
4474 | command. If this variable is not set, the `select' command | |
4475 | prompts with `#? ' | |
ccc6cda3 | 4476 | |
bb70624e JA |
4477 | `PS4' |
4478 | The value is the prompt printed before the command line is echoed | |
28ef6c31 | 4479 | when the `-x' option is set (*note The Set Builtin::). The first |
bb70624e JA |
4480 | character of `PS4' is replicated multiple times, as necessary, to |
4481 | indicate multiple levels of indirection. The default is `+ '. | |
ccc6cda3 | 4482 | |
bb70624e JA |
4483 | `PWD' |
4484 | The current working directory as set by the `cd' builtin. | |
ccc6cda3 | 4485 | |
bb70624e JA |
4486 | `RANDOM' |
4487 | Each time this parameter is referenced, a random integer between 0 | |
4488 | and 32767 is generated. Assigning a value to this variable seeds | |
4489 | the random number generator. | |
cce855bc | 4490 | |
bb70624e JA |
4491 | `REPLY' |
4492 | The default variable for the `read' builtin. | |
ccc6cda3 | 4493 | |
bb70624e JA |
4494 | `SECONDS' |
4495 | This variable expands to the number of seconds since the shell was | |
4496 | started. Assignment to this variable resets the count to the | |
4497 | value assigned, and the expanded value becomes the value assigned | |
4498 | plus the number of seconds since the assignment. | |
ccc6cda3 | 4499 | |
9f422431 CR |
4500 | `SHELL' |
4501 | The full pathname to the shell is kept in this environment | |
4502 | variable. If it is not set when the shell starts, Bash assigns to | |
4503 | it the full pathname of the current user's login shell. | |
4504 | ||
bb70624e JA |
4505 | `SHELLOPTS' |
4506 | A colon-separated list of enabled shell options. Each word in the | |
4507 | list is a valid argument for the `-o' option to the `set' builtin | |
28ef6c31 | 4508 | command (*note The Set Builtin::). The options appearing in |
bb70624e JA |
4509 | `SHELLOPTS' are those reported as `on' by `set -o'. If this |
4510 | variable is in the environment when Bash starts up, each shell | |
4511 | option in the list will be enabled before reading any startup | |
4512 | files. This variable is readonly. | |
ccc6cda3 | 4513 | |
bb70624e JA |
4514 | `SHLVL' |
4515 | Incremented by one each time a new instance of Bash is started. | |
4516 | This is intended to be a count of how deeply your Bash shells are | |
4517 | nested. | |
cce855bc | 4518 | |
bb70624e JA |
4519 | `TIMEFORMAT' |
4520 | The value of this parameter is used as a format string specifying | |
4521 | how the timing information for pipelines prefixed with the `time' | |
4522 | reserved word should be displayed. The `%' character introduces an | |
4523 | escape sequence that is expanded to a time value or other | |
4524 | information. The escape sequences and their meanings are as | |
4525 | follows; the braces denote optional portions. | |
cce855bc | 4526 | |
bb70624e JA |
4527 | `%%' |
4528 | A literal `%'. | |
ccc6cda3 | 4529 | |
bb70624e JA |
4530 | `%[P][l]R' |
4531 | The elapsed time in seconds. | |
ccc6cda3 | 4532 | |
bb70624e JA |
4533 | `%[P][l]U' |
4534 | The number of CPU seconds spent in user mode. | |
ccc6cda3 | 4535 | |
bb70624e JA |
4536 | `%[P][l]S' |
4537 | The number of CPU seconds spent in system mode. | |
ccc6cda3 | 4538 | |
bb70624e JA |
4539 | `%P' |
4540 | The CPU percentage, computed as (%U + %S) / %R. | |
ccc6cda3 | 4541 | |
bb70624e JA |
4542 | The optional P is a digit specifying the precision, the number of |
4543 | fractional digits after a decimal point. A value of 0 causes no | |
4544 | decimal point or fraction to be output. At most three places | |
4545 | after the decimal point may be specified; values of P greater than | |
4546 | 3 are changed to 3. If P is not specified, the value 3 is used. | |
ccc6cda3 | 4547 | |
bb70624e JA |
4548 | The optional `l' specifies a longer format, including minutes, of |
4549 | the form MMmSS.FFs. The value of P determines whether or not the | |
4550 | fraction is included. | |
ccc6cda3 | 4551 | |
bb70624e JA |
4552 | If this variable is not set, Bash acts as if it had the value |
4553 | `$'\nreal\t%3lR\nuser\t%3lU\nsys\t%3lS'' | |
4554 | If the value is null, no timing information is displayed. A | |
4555 | trailing newline is added when the format string is displayed. | |
ccc6cda3 | 4556 | |
bb70624e | 4557 | `TMOUT' |
7117c2d2 JA |
4558 | If set to a value greater than zero, `TMOUT' is treated as the |
4559 | default timeout for the `read' builtin (*note Bash Builtins::). | |
4560 | The `select' command (*note Conditional Constructs::) terminates | |
4561 | if input does not arrive after `TMOUT' seconds when input is coming | |
4562 | from a terminal. | |
4563 | ||
d3ad40de | 4564 | In an interactive shell, the value is interpreted as the number of |
7117c2d2 JA |
4565 | seconds to wait for input after issuing the primary prompt when |
4566 | the shell is interactive. Bash terminates after that number of | |
4567 | seconds if input does not arrive. | |
ccc6cda3 | 4568 | |
1c72c0cd CR |
4569 | `TMPDIR' |
4570 | If set, Bash uses its value as the name of a directory in which | |
4571 | Bash creates temporary files for the shell's use. | |
4572 | ||
bb70624e JA |
4573 | `UID' |
4574 | The numeric real user id of the current user. This variable is | |
4575 | readonly. | |
ccc6cda3 | 4576 | |
761783bf | 4577 | |
bb70624e JA |
4578 | \1f |
4579 | File: bashref.info, Node: Bash Features, Next: Job Control, Prev: Shell Variables, Up: Top | |
ccc6cda3 | 4580 | |
37c41ab1 CR |
4581 | 6 Bash Features |
4582 | *************** | |
ccc6cda3 | 4583 | |
37c41ab1 | 4584 | This section describes features unique to Bash. |
ccc6cda3 | 4585 | |
bb70624e | 4586 | * Menu: |
ccc6cda3 | 4587 | |
bb70624e JA |
4588 | * Invoking Bash:: Command line options that you can give |
4589 | to Bash. | |
4590 | * Bash Startup Files:: When and how Bash executes scripts. | |
4591 | * Interactive Shells:: What an interactive shell is. | |
4592 | * Bash Conditional Expressions:: Primitives used in composing expressions for | |
4593 | the `test' builtin. | |
4594 | * Shell Arithmetic:: Arithmetic on shell variables. | |
4595 | * Aliases:: Substituting one command for another. | |
4596 | * Arrays:: Array Variables. | |
4597 | * The Directory Stack:: History of visited directories. | |
4598 | * Printing a Prompt:: Controlling the PS1 string. | |
4599 | * The Restricted Shell:: A more controlled mode of shell execution. | |
4600 | * Bash POSIX Mode:: Making Bash behave more closely to what | |
4601 | the POSIX standard specifies. | |
ccc6cda3 | 4602 | |
bb70624e JA |
4603 | \1f |
4604 | File: bashref.info, Node: Invoking Bash, Next: Bash Startup Files, Up: Bash Features | |
ccc6cda3 | 4605 | |
37c41ab1 CR |
4606 | 6.1 Invoking Bash |
4607 | ================= | |
ccc6cda3 | 4608 | |
f73dda09 JA |
4609 | bash [long-opt] [-ir] [-abefhkmnptuvxdBCDHP] [-o OPTION] [-O SHOPT_OPTION] [ARGUMENT ...] |
4610 | bash [long-opt] [-abefhkmnptuvxdBCDHP] [-o OPTION] [-O SHOPT_OPTION] -c STRING [ARGUMENT ...] | |
4611 | bash [long-opt] -s [-abefhkmnptuvxdBCDHP] [-o OPTION] [-O SHOPT_OPTION] [ARGUMENT ...] | |
ccc6cda3 | 4612 | |
bb70624e | 4613 | In addition to the single-character shell command-line options |
28ef6c31 | 4614 | (*note The Set Builtin::), there are several multi-character options |
bb70624e | 4615 | that you can use. These options must appear on the command line before |
7117c2d2 | 4616 | the single-character options to be recognized. |
ccc6cda3 | 4617 | |
d3a24ed2 CR |
4618 | `--debugger' |
4619 | Arrange for the debugger profile to be executed before the shell | |
6a8fd0ed | 4620 | starts. Turns on extended debugging mode (see *note The Shopt |
d3ad40de | 4621 | Builtin:: for a description of the `extdebug' option to the `shopt' |
6a8fd0ed | 4622 | builtin) and shell function tracing (see *note The Set Builtin:: |
d3ad40de | 4623 | for a description of the `-o functrace' option). |
d3a24ed2 | 4624 | |
bb70624e JA |
4625 | `--dump-po-strings' |
4626 | A list of all double-quoted strings preceded by `$' is printed on | |
eb2bb562 | 4627 | the standard output in the GNU `gettext' PO (portable object) file |
bb70624e | 4628 | format. Equivalent to `-D' except for the output format. |
ccc6cda3 | 4629 | |
bb70624e JA |
4630 | `--dump-strings' |
4631 | Equivalent to `-D'. | |
ccc6cda3 | 4632 | |
bb70624e | 4633 | `--help' |
d3ad40de | 4634 | Display a usage message on standard output and exit successfully. |
ccc6cda3 | 4635 | |
28ef6c31 JA |
4636 | `--init-file FILENAME' |
4637 | `--rcfile FILENAME' | |
4638 | Execute commands from FILENAME (instead of `~/.bashrc') in an | |
4639 | interactive shell. | |
4640 | ||
bb70624e | 4641 | `--login' |
7117c2d2 | 4642 | Equivalent to `-l'. |
ccc6cda3 | 4643 | |
bb70624e | 4644 | `--noediting' |
28ef6c31 | 4645 | Do not use the GNU Readline library (*note Command Line Editing::) |
bb70624e | 4646 | to read command lines when the shell is interactive. |
ccc6cda3 | 4647 | |
bb70624e JA |
4648 | `--noprofile' |
4649 | Don't load the system-wide startup file `/etc/profile' or any of | |
4650 | the personal initialization files `~/.bash_profile', | |
4651 | `~/.bash_login', or `~/.profile' when Bash is invoked as a login | |
4652 | shell. | |
ccc6cda3 | 4653 | |
bb70624e JA |
4654 | `--norc' |
4655 | Don't read the `~/.bashrc' initialization file in an interactive | |
4656 | shell. This is on by default if the shell is invoked as `sh'. | |
ccc6cda3 | 4657 | |
bb70624e JA |
4658 | `--posix' |
4659 | Change the behavior of Bash where the default operation differs | |
ac18b312 CR |
4660 | from the POSIX standard to match the standard. This is intended |
4661 | to make Bash behave as a strict superset of that standard. *Note | |
4662 | Bash POSIX Mode::, for a description of the Bash POSIX mode. | |
ccc6cda3 | 4663 | |
bb70624e | 4664 | `--restricted' |
28ef6c31 | 4665 | Make the shell a restricted shell (*note The Restricted Shell::). |
ccc6cda3 | 4666 | |
bb70624e JA |
4667 | `--verbose' |
4668 | Equivalent to `-v'. Print shell input lines as they're read. | |
ccc6cda3 | 4669 | |
bb70624e JA |
4670 | `--version' |
4671 | Show version information for this instance of Bash on the standard | |
4672 | output and exit successfully. | |
ccc6cda3 | 4673 | |
761783bf | 4674 | |
bb70624e JA |
4675 | There are several single-character options that may be supplied at |
4676 | invocation which are not available with the `set' builtin. | |
ccc6cda3 | 4677 | |
bb70624e JA |
4678 | `-c STRING' |
4679 | Read and execute commands from STRING after processing the | |
4680 | options, then exit. Any remaining arguments are assigned to the | |
4681 | positional parameters, starting with `$0'. | |
ccc6cda3 | 4682 | |
bb70624e JA |
4683 | `-i' |
4684 | Force the shell to run interactively. Interactive shells are | |
6a8fd0ed | 4685 | described in *note Interactive Shells::. |
ccc6cda3 | 4686 | |
7117c2d2 JA |
4687 | `-l' |
4688 | Make this shell act as if it had been directly invoked by login. | |
4689 | When the shell is interactive, this is equivalent to starting a | |
4690 | login shell with `exec -l bash'. When the shell is not | |
4691 | interactive, the login shell startup files will be executed. | |
4692 | `exec bash -l' or `exec bash --login' will replace the current | |
4693 | shell with a Bash login shell. *Note Bash Startup Files::, for a | |
4694 | description of the special behavior of a login shell. | |
4695 | ||
bb70624e | 4696 | `-r' |
28ef6c31 | 4697 | Make the shell a restricted shell (*note The Restricted Shell::). |
ccc6cda3 | 4698 | |
bb70624e JA |
4699 | `-s' |
4700 | If this option is present, or if no arguments remain after option | |
4701 | processing, then commands are read from the standard input. This | |
4702 | option allows the positional parameters to be set when invoking an | |
4703 | interactive shell. | |
ccc6cda3 | 4704 | |
bb70624e JA |
4705 | `-D' |
4706 | A list of all double-quoted strings preceded by `$' is printed on | |
eb2bb562 | 4707 | the standard output. These are the strings that are subject to |
bb70624e | 4708 | language translation when the current locale is not `C' or `POSIX' |
28ef6c31 | 4709 | (*note Locale Translation::). This implies the `-n' option; no |
bb70624e | 4710 | commands will be executed. |
ccc6cda3 | 4711 | |
f73dda09 JA |
4712 | `[-+]O [SHOPT_OPTION]' |
4713 | SHOPT_OPTION is one of the shell options accepted by the `shopt' | |
d3ad40de CR |
4714 | builtin (*note The Shopt Builtin::). If SHOPT_OPTION is present, |
4715 | `-O' sets the value of that option; `+O' unsets it. If | |
f73dda09 JA |
4716 | SHOPT_OPTION is not supplied, the names and values of the shell |
4717 | options accepted by `shopt' are printed on the standard output. | |
4718 | If the invocation option is `+O', the output is displayed in a | |
4719 | format that may be reused as input. | |
4720 | ||
bb70624e JA |
4721 | `--' |
4722 | A `--' signals the end of options and disables further option | |
4723 | processing. Any arguments after the `--' are treated as filenames | |
4724 | and arguments. | |
ccc6cda3 | 4725 | |
761783bf | 4726 | |
f73dda09 JA |
4727 | A _login_ shell is one whose first character of argument zero is |
4728 | `-', or one invoked with the `--login' option. | |
4729 | ||
28ef6c31 | 4730 | An _interactive_ shell is one started without non-option arguments, |
bb70624e JA |
4731 | unless `-s' is specified, without specifying the `-c' option, and whose |
4732 | input and output are both connected to terminals (as determined by | |
4733 | `isatty(3)'), or one started with the `-i' option. *Note Interactive | |
28ef6c31 | 4734 | Shells::, for more information. |
ccc6cda3 | 4735 | |
bb70624e JA |
4736 | If arguments remain after option processing, and neither the `-c' |
4737 | nor the `-s' option has been supplied, the first argument is assumed to | |
28ef6c31 JA |
4738 | be the name of a file containing shell commands (*note Shell Scripts::). |
4739 | When Bash is invoked in this fashion, `$0' is set to the name of the | |
4740 | file, and the positional parameters are set to the remaining arguments. | |
4741 | Bash reads and executes commands from this file, then exits. Bash's | |
4742 | exit status is the exit status of the last command executed in the | |
4743 | script. If no commands are executed, the exit status is 0. | |
ccc6cda3 | 4744 | |
bb70624e JA |
4745 | \1f |
4746 | File: bashref.info, Node: Bash Startup Files, Next: Interactive Shells, Prev: Invoking Bash, Up: Bash Features | |
ccc6cda3 | 4747 | |
37c41ab1 CR |
4748 | 6.2 Bash Startup Files |
4749 | ====================== | |
ccc6cda3 | 4750 | |
d3ad40de | 4751 | This section describes how Bash executes its startup files. If any of |
37c41ab1 CR |
4752 | the files exist but cannot be read, Bash reports an error. Tildes are |
4753 | expanded in file names as described above under Tilde Expansion (*note | |
4754 | Tilde Expansion::). | |
ccc6cda3 | 4755 | |
6a8fd0ed | 4756 | Interactive shells are described in *note Interactive Shells::. |
ccc6cda3 | 4757 | |
bb70624e JA |
4758 | Invoked as an interactive login shell, or with `--login' |
4759 | ........................................................ | |
cce855bc | 4760 | |
37c41ab1 | 4761 | When Bash is invoked as an interactive login shell, or as a |
bb70624e JA |
4762 | non-interactive shell with the `--login' option, it first reads and |
4763 | executes commands from the file `/etc/profile', if that file exists. | |
4764 | After reading that file, it looks for `~/.bash_profile', | |
4765 | `~/.bash_login', and `~/.profile', in that order, and reads and | |
4766 | executes commands from the first one that exists and is readable. The | |
4767 | `--noprofile' option may be used when the shell is started to inhibit | |
4768 | this behavior. | |
ccc6cda3 | 4769 | |
bb70624e JA |
4770 | When a login shell exits, Bash reads and executes commands from the |
4771 | file `~/.bash_logout', if it exists. | |
ccc6cda3 | 4772 | |
bb70624e JA |
4773 | Invoked as an interactive non-login shell |
4774 | ......................................... | |
ccc6cda3 | 4775 | |
37c41ab1 | 4776 | When an interactive shell that is not a login shell is started, Bash |
bb70624e JA |
4777 | reads and executes commands from `~/.bashrc', if that file exists. |
4778 | This may be inhibited by using the `--norc' option. The `--rcfile | |
4779 | FILE' option will force Bash to read and execute commands from FILE | |
4780 | instead of `~/.bashrc'. | |
ccc6cda3 | 4781 | |
bb70624e JA |
4782 | So, typically, your `~/.bash_profile' contains the line |
4783 | `if [ -f ~/.bashrc ]; then . ~/.bashrc; fi' | |
37c41ab1 | 4784 | after (or before) any login-specific initializations. |
ccc6cda3 | 4785 | |
bb70624e JA |
4786 | Invoked non-interactively |
4787 | ......................... | |
ccc6cda3 | 4788 | |
37c41ab1 | 4789 | When Bash is started non-interactively, to run a shell script, for |
bb70624e JA |
4790 | example, it looks for the variable `BASH_ENV' in the environment, |
4791 | expands its value if it appears there, and uses the expanded value as | |
4792 | the name of a file to read and execute. Bash behaves as if the | |
4793 | following command were executed: | |
4794 | `if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi' | |
37c41ab1 CR |
4795 | but the value of the `PATH' variable is not used to search for the |
4796 | file name. | |
ccc6cda3 | 4797 | |
28ef6c31 JA |
4798 | As noted above, if a non-interactive shell is invoked with the |
4799 | `--login' option, Bash attempts to read and execute commands from the | |
4800 | login shell startup files. | |
4801 | ||
bb70624e JA |
4802 | Invoked with name `sh' |
4803 | ...................... | |
ccc6cda3 | 4804 | |
37c41ab1 | 4805 | If Bash is invoked with the name `sh', it tries to mimic the startup |
bb70624e JA |
4806 | behavior of historical versions of `sh' as closely as possible, while |
4807 | conforming to the POSIX standard as well. | |
ccc6cda3 | 4808 | |
bb70624e JA |
4809 | When invoked as an interactive login shell, or as a non-interactive |
4810 | shell with the `--login' option, it first attempts to read and execute | |
4811 | commands from `/etc/profile' and `~/.profile', in that order. The | |
4812 | `--noprofile' option may be used to inhibit this behavior. When | |
4813 | invoked as an interactive shell with the name `sh', Bash looks for the | |
4814 | variable `ENV', expands its value if it is defined, and uses the | |
4815 | expanded value as the name of a file to read and execute. Since a | |
4816 | shell invoked as `sh' does not attempt to read and execute commands | |
4817 | from any other startup files, the `--rcfile' option has no effect. A | |
4818 | non-interactive shell invoked with the name `sh' does not attempt to | |
4819 | read any other startup files. | |
ccc6cda3 | 4820 | |
bb70624e JA |
4821 | When invoked as `sh', Bash enters POSIX mode after the startup files |
4822 | are read. | |
b72432fd | 4823 | |
bb70624e JA |
4824 | Invoked in POSIX mode |
4825 | ..................... | |
ccc6cda3 | 4826 | |
37c41ab1 CR |
4827 | When Bash is started in POSIX mode, as with the `--posix' command line |
4828 | option, it follows the POSIX standard for startup files. In this mode, | |
4829 | interactive shells expand the `ENV' variable and commands are read and | |
4830 | executed from the file whose name is the expanded value. No other | |
4831 | startup files are read. | |
ccc6cda3 | 4832 | |
bb70624e JA |
4833 | Invoked by remote shell daemon |
4834 | .............................. | |
ccc6cda3 | 4835 | |
c2a47ea9 CR |
4836 | Bash attempts to determine when it is being run with its standard input |
4837 | connected to a a network connection, as if by the remote shell daemon, | |
4838 | usually `rshd', or the secure shell daemon `sshd'. If Bash determines | |
4839 | it is being run in this fashion, it reads and executes commands from | |
4840 | `~/.bashrc', if that file exists and is readable. It will not do this | |
4841 | if invoked as `sh'. The `--norc' option may be used to inhibit this | |
4842 | behavior, and the `--rcfile' option may be used to force another file | |
4843 | to be read, but `rshd' does not generally invoke the shell with those | |
4844 | options or allow them to be specified. | |
ccc6cda3 | 4845 | |
bb70624e JA |
4846 | Invoked with unequal effective and real UID/GIDs |
4847 | ................................................ | |
4848 | ||
37c41ab1 CR |
4849 | If Bash is started with the effective user (group) id not equal to the |
4850 | real user (group) id, and the `-p' option is not supplied, no startup | |
4851 | files are read, shell functions are not inherited from the environment, | |
4852 | the `SHELLOPTS' variable, if it appears in the environment, is ignored, | |
4853 | and the effective user id is set to the real user id. If the `-p' | |
4854 | option is supplied at invocation, the startup behavior is the same, but | |
4855 | the effective user id is not reset. | |
bb70624e JA |
4856 | |
4857 | \1f | |
4858 | File: bashref.info, Node: Interactive Shells, Next: Bash Conditional Expressions, Prev: Bash Startup Files, Up: Bash Features | |
4859 | ||
37c41ab1 CR |
4860 | 6.3 Interactive Shells |
4861 | ====================== | |
bb70624e JA |
4862 | |
4863 | * Menu: | |
4864 | ||
4865 | * What is an Interactive Shell?:: What determines whether a shell is Interactive. | |
4866 | * Is this Shell Interactive?:: How to tell if a shell is interactive. | |
4867 | * Interactive Shell Behavior:: What changes in a interactive shell? | |
4868 | ||
4869 | \1f | |
4870 | File: bashref.info, Node: What is an Interactive Shell?, Next: Is this Shell Interactive?, Up: Interactive Shells | |
4871 | ||
37c41ab1 CR |
4872 | 6.3.1 What is an Interactive Shell? |
4873 | ----------------------------------- | |
bb70624e | 4874 | |
37c41ab1 | 4875 | An interactive shell is one started without non-option arguments, |
d3ad40de CR |
4876 | unless `-s' is specified, without specifying the `-c' option, and whose |
4877 | input and error output are both connected to terminals (as determined | |
4878 | by `isatty(3)'), or one started with the `-i' option. | |
bb70624e JA |
4879 | |
4880 | An interactive shell generally reads from and writes to a user's | |
4881 | terminal. | |
4882 | ||
4883 | The `-s' invocation option may be used to set the positional | |
4884 | parameters when an interactive shell is started. | |
4885 | ||
4886 | \1f | |
4887 | File: bashref.info, Node: Is this Shell Interactive?, Next: Interactive Shell Behavior, Prev: What is an Interactive Shell?, Up: Interactive Shells | |
4888 | ||
37c41ab1 CR |
4889 | 6.3.2 Is this Shell Interactive? |
4890 | -------------------------------- | |
bb70624e | 4891 | |
37c41ab1 | 4892 | To determine within a startup script whether or not Bash is running |
bb70624e JA |
4893 | interactively, test the value of the `-' special parameter. It |
4894 | contains `i' when the shell is interactive. For example: | |
4895 | ||
4896 | case "$-" in | |
4897 | *i*) echo This shell is interactive ;; | |
4898 | *) echo This shell is not interactive ;; | |
4899 | esac | |
4900 | ||
28ef6c31 JA |
4901 | Alternatively, startup scripts may examine the variable `PS1'; it is |
4902 | unset in non-interactive shells, and set in interactive shells. Thus: | |
bb70624e JA |
4903 | |
4904 | if [ -z "$PS1" ]; then | |
4905 | echo This shell is not interactive | |
4906 | else | |
4907 | echo This shell is interactive | |
4908 | fi | |
4909 | ||
4910 | \1f | |
4911 | File: bashref.info, Node: Interactive Shell Behavior, Prev: Is this Shell Interactive?, Up: Interactive Shells | |
4912 | ||
37c41ab1 CR |
4913 | 6.3.3 Interactive Shell Behavior |
4914 | -------------------------------- | |
bb70624e | 4915 | |
37c41ab1 | 4916 | When the shell is running interactively, it changes its behavior in |
bb70624e JA |
4917 | several ways. |
4918 | ||
6a8fd0ed | 4919 | 1. Startup files are read and executed as described in *note Bash |
bb70624e JA |
4920 | Startup Files::. |
4921 | ||
28ef6c31 | 4922 | 2. Job Control (*note Job Control::) is enabled by default. When job |
bb70624e JA |
4923 | control is in effect, Bash ignores the keyboard-generated job |
4924 | control signals `SIGTTIN', `SIGTTOU', and `SIGTSTP'. | |
4925 | ||
28ef6c31 JA |
4926 | 3. Bash expands and displays `PS1' before reading the first line of a |
4927 | command, and expands and displays `PS2' before reading the second | |
4928 | and subsequent lines of a multi-line command. | |
bb70624e JA |
4929 | |
4930 | 4. Bash executes the value of the `PROMPT_COMMAND' variable as a | |
4931 | command before printing the primary prompt, `$PS1' (*note Bash | |
28ef6c31 | 4932 | Variables::). |
bb70624e | 4933 | |
28ef6c31 | 4934 | 5. Readline (*note Command Line Editing::) is used to read commands |
bb70624e JA |
4935 | from the user's terminal. |
4936 | ||
4937 | 6. Bash inspects the value of the `ignoreeof' option to `set -o' | |
4938 | instead of exiting immediately when it receives an `EOF' on its | |
28ef6c31 | 4939 | standard input when reading a command (*note The Set Builtin::). |
bb70624e | 4940 | |
28ef6c31 JA |
4941 | 7. Command history (*note Bash History Facilities::) and history |
4942 | expansion (*note History Interaction::) are enabled by default. | |
bb70624e JA |
4943 | Bash will save the command history to the file named by `$HISTFILE' |
4944 | when an interactive shell exits. | |
4945 | ||
28ef6c31 | 4946 | 8. Alias expansion (*note Aliases::) is performed by default. |
bb70624e JA |
4947 | |
4948 | 9. In the absence of any traps, Bash ignores `SIGTERM' (*note | |
28ef6c31 | 4949 | Signals::). |
bb70624e JA |
4950 | |
4951 | 10. In the absence of any traps, `SIGINT' is caught and handled | |
28ef6c31 | 4952 | ((*note Signals::). `SIGINT' will interrupt some shell builtins. |
bb70624e JA |
4953 | |
4954 | 11. An interactive login shell sends a `SIGHUP' to all jobs on exit if | |
d3ad40de | 4955 | the `huponexit' shell option has been enabled (*note Signals::). |
bb70624e JA |
4956 | |
4957 | 12. The `-n' invocation option is ignored, and `set -n' has no effect | |
28ef6c31 | 4958 | (*note The Set Builtin::). |
bb70624e JA |
4959 | |
4960 | 13. Bash will check for mail periodically, depending on the values of | |
4961 | the `MAIL', `MAILPATH', and `MAILCHECK' shell variables (*note | |
28ef6c31 | 4962 | Bash Variables::). |
bb70624e JA |
4963 | |
4964 | 14. Expansion errors due to references to unbound shell variables after | |
4965 | `set -u' has been enabled will not cause the shell to exit (*note | |
28ef6c31 | 4966 | The Set Builtin::). |
bb70624e JA |
4967 | |
4968 | 15. The shell will not exit on expansion errors caused by VAR being | |
4969 | unset or null in `${VAR:?WORD}' expansions (*note Shell Parameter | |
28ef6c31 | 4970 | Expansion::). |
bb70624e JA |
4971 | |
4972 | 16. Redirection errors encountered by shell builtins will not cause the | |
4973 | shell to exit. | |
4974 | ||
4975 | 17. When running in POSIX mode, a special builtin returning an error | |
28ef6c31 | 4976 | status will not cause the shell to exit (*note Bash POSIX Mode::). |
bb70624e JA |
4977 | |
4978 | 18. A failed `exec' will not cause the shell to exit (*note Bourne | |
28ef6c31 | 4979 | Shell Builtins::). |
bb70624e JA |
4980 | |
4981 | 19. Parser syntax errors will not cause the shell to exit. | |
4982 | ||
4983 | 20. Simple spelling correction for directory arguments to the `cd' | |
4984 | builtin is enabled by default (see the description of the `cdspell' | |
6a8fd0ed | 4985 | option to the `shopt' builtin in *note The Shopt Builtin::). |
bb70624e JA |
4986 | |
4987 | 21. The shell will check the value of the `TMOUT' variable and exit if | |
4988 | a command is not read within the specified number of seconds after | |
28ef6c31 | 4989 | printing `$PS1' (*note Bash Variables::). |
bb70624e JA |
4990 | |
4991 | ||
4992 | \1f | |
4993 | File: bashref.info, Node: Bash Conditional Expressions, Next: Shell Arithmetic, Prev: Interactive Shells, Up: Bash Features | |
4994 | ||
37c41ab1 CR |
4995 | 6.4 Bash Conditional Expressions |
4996 | ================================ | |
bb70624e | 4997 | |
37c41ab1 CR |
4998 | Conditional expressions are used by the `[[' compound command and the |
4999 | `test' and `[' builtin commands. | |
bb70624e JA |
5000 | |
5001 | Expressions may be unary or binary. Unary expressions are often | |
5002 | used to examine the status of a file. There are string operators and | |
5003 | numeric comparison operators as well. If the FILE argument to one of | |
5004 | the primaries is of the form `/dev/fd/N', then file descriptor N is | |
5005 | checked. If the FILE argument to one of the primaries is one of | |
5006 | `/dev/stdin', `/dev/stdout', or `/dev/stderr', file descriptor 0, 1, or | |
5007 | 2, respectively, is checked. | |
5008 | ||
37c41ab1 CR |
5009 | Unless otherwise specified, primaries that operate on files follow |
5010 | symbolic links and operate on the target of the link, rather than the | |
5011 | link itself. | |
5012 | ||
bb70624e JA |
5013 | `-a FILE' |
5014 | True if FILE exists. | |
5015 | ||
5016 | `-b FILE' | |
5017 | True if FILE exists and is a block special file. | |
5018 | ||
5019 | `-c FILE' | |
5020 | True if FILE exists and is a character special file. | |
5021 | ||
5022 | `-d FILE' | |
5023 | True if FILE exists and is a directory. | |
5024 | ||
5025 | `-e FILE' | |
5026 | True if FILE exists. | |
5027 | ||
5028 | `-f FILE' | |
5029 | True if FILE exists and is a regular file. | |
5030 | ||
5031 | `-g FILE' | |
5032 | True if FILE exists and its set-group-id bit is set. | |
5033 | ||
5034 | `-h FILE' | |
5035 | True if FILE exists and is a symbolic link. | |
5036 | ||
5037 | `-k FILE' | |
5038 | True if FILE exists and its "sticky" bit is set. | |
5039 | ||
5040 | `-p FILE' | |
5041 | True if FILE exists and is a named pipe (FIFO). | |
5042 | ||
5043 | `-r FILE' | |
5044 | True if FILE exists and is readable. | |
5045 | ||
5046 | `-s FILE' | |
5047 | True if FILE exists and has a size greater than zero. | |
5048 | ||
5049 | `-t FD' | |
5050 | True if file descriptor FD is open and refers to a terminal. | |
ccc6cda3 JA |
5051 | |
5052 | `-u FILE' | |
5053 | True if FILE exists and its set-user-id bit is set. | |
5054 | ||
5055 | `-w FILE' | |
5056 | True if FILE exists and is writable. | |
5057 | ||
5058 | `-x FILE' | |
5059 | True if FILE exists and is executable. | |
5060 | ||
5061 | `-O FILE' | |
5062 | True if FILE exists and is owned by the effective user id. | |
5063 | ||
5064 | `-G FILE' | |
5065 | True if FILE exists and is owned by the effective group id. | |
5066 | ||
cce855bc JA |
5067 | `-L FILE' |
5068 | True if FILE exists and is a symbolic link. | |
5069 | ||
5070 | `-S FILE' | |
5071 | True if FILE exists and is a socket. | |
5072 | ||
5073 | `-N FILE' | |
5074 | True if FILE exists and has been modified since it was last read. | |
5075 | ||
ccc6cda3 | 5076 | `FILE1 -nt FILE2' |
7117c2d2 JA |
5077 | True if FILE1 is newer (according to modification date) than |
5078 | FILE2, or if FILE1 exists and FILE2 does not. | |
ccc6cda3 JA |
5079 | |
5080 | `FILE1 -ot FILE2' | |
7117c2d2 JA |
5081 | True if FILE1 is older than FILE2, or if FILE2 exists and FILE1 |
5082 | does not. | |
ccc6cda3 JA |
5083 | |
5084 | `FILE1 -ef FILE2' | |
7117c2d2 | 5085 | True if FILE1 and FILE2 refer to the same device and inode numbers. |
ccc6cda3 JA |
5086 | |
5087 | `-o OPTNAME' | |
5088 | True if shell option OPTNAME is enabled. The list of options | |
5089 | appears in the description of the `-o' option to the `set' builtin | |
28ef6c31 | 5090 | (*note The Set Builtin::). |
ccc6cda3 JA |
5091 | |
5092 | `-z STRING' | |
5093 | True if the length of STRING is zero. | |
5094 | ||
5095 | `-n STRING' | |
5096 | `STRING' | |
5097 | True if the length of STRING is non-zero. | |
5098 | ||
cce855bc | 5099 | `STRING1 == STRING2' |
7117c2d2 JA |
5100 | True if the strings are equal. `=' may be used in place of `==' |
5101 | for strict POSIX compliance. | |
ccc6cda3 JA |
5102 | |
5103 | `STRING1 != STRING2' | |
5104 | True if the strings are not equal. | |
5105 | ||
5106 | `STRING1 < STRING2' | |
4a8bb13f | 5107 | True if STRING1 sorts before STRING2 lexicographically. |
ccc6cda3 JA |
5108 | |
5109 | `STRING1 > STRING2' | |
4a8bb13f | 5110 | True if STRING1 sorts after STRING2 lexicographically. |
ccc6cda3 JA |
5111 | |
5112 | `ARG1 OP ARG2' | |
5113 | `OP' is one of `-eq', `-ne', `-lt', `-le', `-gt', or `-ge'. These | |
5114 | arithmetic binary operators return true if ARG1 is equal to, not | |
5115 | equal to, less than, less than or equal to, greater than, or | |
5116 | greater than or equal to ARG2, respectively. ARG1 and ARG2 may be | |
5117 | positive or negative integers. | |
5118 | ||
761783bf | 5119 | |
ccc6cda3 | 5120 | \1f |
bb70624e | 5121 | File: bashref.info, Node: Shell Arithmetic, Next: Aliases, Prev: Bash Conditional Expressions, Up: Bash Features |
ccc6cda3 | 5122 | |
37c41ab1 CR |
5123 | 6.5 Shell Arithmetic |
5124 | ==================== | |
ccc6cda3 | 5125 | |
37c41ab1 CR |
5126 | The shell allows arithmetic expressions to be evaluated, as one of the |
5127 | shell expansions or by the `let' and the `-i' option to the `declare' | |
5128 | builtins. | |
ccc6cda3 | 5129 | |
7117c2d2 JA |
5130 | Evaluation is done in fixed-width integers with no check for |
5131 | overflow, though division by 0 is trapped and flagged as an error. The | |
d3a24ed2 CR |
5132 | operators and their precedence, associativity, and values are the same |
5133 | as in the C language. The following list of operators is grouped into | |
5134 | levels of equal-precedence operators. The levels are listed in order | |
5135 | of decreasing precedence. | |
cce855bc | 5136 | |
bb70624e JA |
5137 | `ID++ ID--' |
5138 | variable post-increment and post-decrement | |
d166f048 | 5139 | |
bb70624e JA |
5140 | `++ID --ID' |
5141 | variable pre-increment and pre-decrement | |
ccc6cda3 | 5142 | |
bb70624e JA |
5143 | `- +' |
5144 | unary minus and plus | |
ccc6cda3 | 5145 | |
bb70624e JA |
5146 | `! ~' |
5147 | logical and bitwise negation | |
ccc6cda3 | 5148 | |
bb70624e JA |
5149 | `**' |
5150 | exponentiation | |
ccc6cda3 | 5151 | |
bb70624e JA |
5152 | `* / %' |
5153 | multiplication, division, remainder | |
ccc6cda3 | 5154 | |
bb70624e JA |
5155 | `+ -' |
5156 | addition, subtraction | |
ccc6cda3 | 5157 | |
bb70624e JA |
5158 | `<< >>' |
5159 | left and right bitwise shifts | |
cce855bc | 5160 | |
bb70624e JA |
5161 | `<= >= < >' |
5162 | comparison | |
cce855bc | 5163 | |
bb70624e JA |
5164 | `== !=' |
5165 | equality and inequality | |
cce855bc | 5166 | |
bb70624e JA |
5167 | `&' |
5168 | bitwise AND | |
cce855bc | 5169 | |
bb70624e JA |
5170 | `^' |
5171 | bitwise exclusive OR | |
cce855bc | 5172 | |
bb70624e JA |
5173 | `|' |
5174 | bitwise OR | |
cce855bc | 5175 | |
bb70624e JA |
5176 | `&&' |
5177 | logical AND | |
ccc6cda3 | 5178 | |
bb70624e JA |
5179 | `||' |
5180 | logical OR | |
ccc6cda3 | 5181 | |
bb70624e | 5182 | `expr ? expr : expr' |
d3a24ed2 | 5183 | conditional operator |
cce855bc | 5184 | |
bb70624e JA |
5185 | `= *= /= %= += -= <<= >>= &= ^= |=' |
5186 | assignment | |
ccc6cda3 | 5187 | |
bb70624e JA |
5188 | `expr1 , expr2' |
5189 | comma | |
ccc6cda3 | 5190 | |
bb70624e JA |
5191 | Shell variables are allowed as operands; parameter expansion is |
5192 | performed before the expression is evaluated. Within an expression, | |
5193 | shell variables may also be referenced by name without using the | |
d3a24ed2 CR |
5194 | parameter expansion syntax. A shell variable that is null or unset |
5195 | evaluates to 0 when referenced by name without using the parameter | |
5196 | expansion syntax. The value of a variable is evaluated as an | |
5197 | arithmetic expression when it is referenced, or when a variable which | |
5198 | has been given the INTEGER attribute using `declare -i' is assigned a | |
5199 | value. A null value evaluates to 0. A shell variable need not have | |
5200 | its integer attribute turned on to be used in an expression. | |
ccc6cda3 | 5201 | |
bb70624e JA |
5202 | Constants with a leading 0 are interpreted as octal numbers. A |
5203 | leading `0x' or `0X' denotes hexadecimal. Otherwise, numbers take the | |
5204 | form [BASE`#']N, where BASE is a decimal number between 2 and 64 | |
5205 | representing the arithmetic base, and N is a number in that base. If | |
5206 | BASE`#' is omitted, then base 10 is used. The digits greater than 9 | |
f73dda09 JA |
5207 | are represented by the lowercase letters, the uppercase letters, `@', |
5208 | and `_', in that order. If BASE is less than or equal to 36, lowercase | |
eb2bb562 | 5209 | and uppercase letters may be used interchangeably to represent numbers |
bb70624e | 5210 | between 10 and 35. |
ccc6cda3 | 5211 | |
bb70624e JA |
5212 | Operators are evaluated in order of precedence. Sub-expressions in |
5213 | parentheses are evaluated first and may override the precedence rules | |
5214 | above. | |
ccc6cda3 | 5215 | |
bb70624e JA |
5216 | \1f |
5217 | File: bashref.info, Node: Aliases, Next: Arrays, Prev: Shell Arithmetic, Up: Bash Features | |
ccc6cda3 | 5218 | |
37c41ab1 CR |
5219 | 6.6 Aliases |
5220 | =========== | |
ccc6cda3 | 5221 | |
37c41ab1 CR |
5222 | ALIASES allow a string to be substituted for a word when it is used as |
5223 | the first word of a simple command. The shell maintains a list of | |
bb70624e | 5224 | aliases that may be set and unset with the `alias' and `unalias' |
cce855bc JA |
5225 | builtin commands. |
5226 | ||
5227 | The first word of each simple command, if unquoted, is checked to see | |
5228 | if it has an alias. If so, that word is replaced by the text of the | |
de8913bd CR |
5229 | alias. The characters `/', `$', ``', `=' and any of the shell |
5230 | metacharacters or quoting characters listed above may not appear in an | |
5231 | alias name. The replacement text may contain any valid shell input, | |
5232 | including shell metacharacters. The first word of the replacement text | |
5233 | is tested for aliases, but a word that is identical to an alias being | |
5234 | expanded is not expanded a second time. This means that one may alias | |
5235 | `ls' to `"ls -F"', for instance, and Bash does not try to recursively | |
5236 | expand the replacement text. If the last character of the alias value | |
5237 | is a space or tab character, then the next command word following the | |
5238 | alias is also checked for alias expansion. | |
cce855bc JA |
5239 | |
5240 | Aliases are created and listed with the `alias' command, and removed | |
5241 | with the `unalias' command. | |
5242 | ||
5243 | There is no mechanism for using arguments in the replacement text, | |
5244 | as in `csh'. If arguments are needed, a shell function should be used | |
28ef6c31 | 5245 | (*note Shell Functions::). |
cce855bc JA |
5246 | |
5247 | Aliases are not expanded when the shell is not interactive, unless | |
d3ad40de CR |
5248 | the `expand_aliases' shell option is set using `shopt' (*note The Shopt |
5249 | Builtin::). | |
ccc6cda3 | 5250 | |
cce855bc JA |
5251 | The rules concerning the definition and use of aliases are somewhat |
5252 | confusing. Bash always reads at least one complete line of input | |
5253 | before executing any of the commands on that line. Aliases are | |
5254 | expanded when a command is read, not when it is executed. Therefore, an | |
5255 | alias definition appearing on the same line as another command does not | |
5256 | take effect until the next line of input is read. The commands | |
5257 | following the alias definition on that line are not affected by the new | |
5258 | alias. This behavior is also an issue when functions are executed. | |
5259 | Aliases are expanded when a function definition is read, not when the | |
5260 | function is executed, because a function definition is itself a | |
5261 | compound command. As a consequence, aliases defined in a function are | |
5262 | not available until after that function is executed. To be safe, | |
5263 | always put alias definitions on a separate line, and do not use `alias' | |
5264 | in compound commands. | |
ccc6cda3 | 5265 | |
bb70624e | 5266 | For almost every purpose, shell functions are preferred over aliases. |
ccc6cda3 JA |
5267 | |
5268 | \1f | |
cce855bc | 5269 | File: bashref.info, Node: Arrays, Next: The Directory Stack, Prev: Aliases, Up: Bash Features |
ccc6cda3 | 5270 | |
37c41ab1 CR |
5271 | 6.7 Arrays |
5272 | ========== | |
ccc6cda3 | 5273 | |
09767ff0 CR |
5274 | Bash provides one-dimensional indexed and associative array variables. |
5275 | Any variable may be used as an indexed array; the `declare' builtin | |
5276 | will explicitly declare an array. There is no maximum limit on the | |
5277 | size of an array, nor any requirement that members be indexed or | |
5278 | assigned contiguously. Indexed arrays are referenced using integers | |
5279 | (including arithmetic expressions (*note Shell Arithmetic::) and are | |
5280 | zero-based; associative arrays use arbitrary strings. | |
ccc6cda3 | 5281 | |
09767ff0 CR |
5282 | An indexed array is created automatically if any variable is |
5283 | assigned to using the syntax | |
ccc6cda3 JA |
5284 | name[SUBSCRIPT]=VALUE |
5285 | ||
5286 | The SUBSCRIPT is treated as an arithmetic expression that must evaluate | |
5287 | to a number greater than or equal to zero. To explicitly declare an | |
5288 | array, use | |
5289 | declare -a NAME | |
37c41ab1 | 5290 | The syntax |
ccc6cda3 | 5291 | declare -a NAME[SUBSCRIPT] |
09767ff0 CR |
5292 | is also accepted; the SUBSCRIPT is ignored. |
5293 | ||
5294 | Associative arrays are created using | |
5295 | declare -A NAME. | |
5296 | ||
5297 | Attributes may be specified for an array variable using the | |
5298 | `declare' and `readonly' builtins. Each attribute applies to all | |
5299 | members of an array. | |
ccc6cda3 JA |
5300 | |
5301 | Arrays are assigned to using compound assignments of the form | |
5302 | name=(value1 ... valueN) | |
09767ff0 CR |
5303 | where each VALUE is of the form `[SUBSCRIPT]='STRING. Indexed array |
5304 | assignments do not require the bracket and subscript. When assigning | |
5305 | to indexed arrays, if the optional subscript is supplied, that index is | |
5306 | assigned to; otherwise the index of the element assigned is the last | |
5307 | index assigned to by the statement plus one. Indexing starts at zero. | |
5308 | ||
5309 | When assigning to an associative array, the subscript is required. | |
5310 | ||
5311 | This syntax is also accepted by the `declare' builtin. Individual | |
5312 | array elements may be assigned to using the `name['SUBSCRIPT`]='VALUE | |
5313 | syntax introduced above. | |
ccc6cda3 JA |
5314 | |
5315 | Any element of an array may be referenced using | |
5316 | `${name['SUBSCRIPT`]}'. The braces are required to avoid conflicts | |
5317 | with the shell's filename expansion operators. If the SUBSCRIPT is `@' | |
5318 | or `*', the word expands to all members of the array NAME. These | |
5319 | subscripts differ only when the word appears within double quotes. If | |
5320 | the word is double-quoted, `${name[*]}' expands to a single word with | |
5321 | the value of each array member separated by the first character of the | |
5322 | `IFS' variable, and `${name[@]}' expands each element of NAME to a | |
5323 | separate word. When there are no array members, `${name[@]}' expands | |
37c41ab1 CR |
5324 | to nothing. If the double-quoted expansion occurs within a word, the |
5325 | expansion of the first parameter is joined with the beginning part of | |
5326 | the original word, and the expansion of the last parameter is joined | |
5327 | with the last part of the original word. This is analogous to the | |
5328 | expansion of the special parameters `@' and `*'. | |
5329 | `${#name['SUBSCRIPT`]}' expands to the length of `${name['SUBSCRIPT`]}'. | |
5330 | If SUBSCRIPT is `@' or `*', the expansion is the number of elements in | |
5331 | the array. Referencing an array variable without a subscript is | |
09767ff0 | 5332 | equivalent to referencing with a subscript of 0. |
ccc6cda3 | 5333 | |
4a8bb13f CR |
5334 | An array variable is considered set if a subscript has been assigned |
5335 | a value. The null string is a valid value. | |
5336 | ||
ccc6cda3 | 5337 | The `unset' builtin is used to destroy arrays. `unset' |
1c72c0cd CR |
5338 | NAME[SUBSCRIPT] destroys the array element at index SUBSCRIPT. Care |
5339 | must be taken to avoid unwanted side effects caused by filename | |
4a8bb13f | 5340 | expansion. `unset' NAME, where NAME is an array, removes the entire |
1c72c0cd | 5341 | array. A subscript of `*' or `@' also removes the entire array. |
ccc6cda3 JA |
5342 | |
5343 | The `declare', `local', and `readonly' builtins each accept a `-a' | |
09767ff0 CR |
5344 | option to specify an indexed array and a `-A' option to specify an |
5345 | associative array. The `read' builtin accepts a `-a' option to assign | |
5346 | a list of words read from the standard input to an array, and can read | |
5347 | values from the standard input into individual array elements. The | |
5348 | `set' and `declare' builtins display array values in a way that allows | |
5349 | them to be reused as input. | |
ccc6cda3 JA |
5350 | |
5351 | \1f | |
cce855bc JA |
5352 | File: bashref.info, Node: The Directory Stack, Next: Printing a Prompt, Prev: Arrays, Up: Bash Features |
5353 | ||
37c41ab1 CR |
5354 | 6.8 The Directory Stack |
5355 | ======================= | |
cce855bc | 5356 | |
bb70624e JA |
5357 | * Menu: |
5358 | ||
5359 | * Directory Stack Builtins:: Bash builtin commands to manipulate | |
5360 | the directory stack. | |
5361 | ||
5362 | The directory stack is a list of recently-visited directories. The | |
cce855bc JA |
5363 | `pushd' builtin adds directories to the stack as it changes the current |
5364 | directory, and the `popd' builtin removes specified directories from | |
5365 | the stack and changes the current directory to the directory removed. | |
5366 | The `dirs' builtin displays the contents of the directory stack. | |
5367 | ||
5368 | The contents of the directory stack are also visible as the value of | |
5369 | the `DIRSTACK' shell variable. | |
5370 | ||
bb70624e JA |
5371 | \1f |
5372 | File: bashref.info, Node: Directory Stack Builtins, Up: The Directory Stack | |
5373 | ||
37c41ab1 CR |
5374 | 6.8.1 Directory Stack Builtins |
5375 | ------------------------------ | |
bb70624e | 5376 | |
cce855bc | 5377 | `dirs' |
bb70624e | 5378 | dirs [+N | -N] [-clpv] |
cce855bc JA |
5379 | Display the list of currently remembered directories. Directories |
5380 | are added to the list with the `pushd' command; the `popd' command | |
5381 | removes directories from the list. | |
5382 | `+N' | |
5383 | Displays the Nth directory (counting from the left of the | |
5384 | list printed by `dirs' when invoked without options), starting | |
5385 | with zero. | |
5386 | ||
5387 | `-N' | |
5388 | Displays the Nth directory (counting from the right of the | |
5389 | list printed by `dirs' when invoked without options), starting | |
5390 | with zero. | |
5391 | ||
5392 | `-c' | |
5393 | Clears the directory stack by deleting all of the elements. | |
5394 | ||
5395 | `-l' | |
5396 | Produces a longer listing; the default listing format uses a | |
5397 | tilde to denote the home directory. | |
5398 | ||
5399 | `-p' | |
5400 | Causes `dirs' to print the directory stack with one entry per | |
5401 | line. | |
5402 | ||
5403 | `-v' | |
5404 | Causes `dirs' to print the directory stack with one entry per | |
5405 | line, prefixing each entry with its index in the stack. | |
5406 | ||
5407 | `popd' | |
5408 | popd [+N | -N] [-n] | |
5409 | ||
5410 | Remove the top entry from the directory stack, and `cd' to the new | |
5411 | top directory. When no arguments are given, `popd' removes the | |
5412 | top directory from the stack and performs a `cd' to the new top | |
5413 | directory. The elements are numbered from 0 starting at the first | |
5414 | directory listed with `dirs'; i.e., `popd' is equivalent to `popd | |
5415 | +0'. | |
5416 | `+N' | |
5417 | Removes the Nth directory (counting from the left of the list | |
5418 | printed by `dirs'), starting with zero. | |
5419 | ||
5420 | `-N' | |
5421 | Removes the Nth directory (counting from the right of the | |
5422 | list printed by `dirs'), starting with zero. | |
5423 | ||
5424 | `-n' | |
5425 | Suppresses the normal change of directory when removing | |
5426 | directories from the stack, so that only the stack is | |
5427 | manipulated. | |
5428 | ||
5429 | `pushd' | |
d3ad40de | 5430 | pushd [-n] [+N | -N | DIR ] |
cce855bc JA |
5431 | |
5432 | Save the current directory on the top of the directory stack and | |
5433 | then `cd' to DIR. With no arguments, `pushd' exchanges the top | |
5434 | two directories. | |
5435 | ||
d3ad40de CR |
5436 | `-n' |
5437 | Suppresses the normal change of directory when adding | |
5438 | directories to the stack, so that only the stack is | |
5439 | manipulated. | |
5440 | ||
cce855bc JA |
5441 | `+N' |
5442 | Brings the Nth directory (counting from the left of the list | |
5443 | printed by `dirs', starting with zero) to the top of the list | |
5444 | by rotating the stack. | |
5445 | ||
5446 | `-N' | |
5447 | Brings the Nth directory (counting from the right of the list | |
5448 | printed by `dirs', starting with zero) to the top of the list | |
5449 | by rotating the stack. | |
5450 | ||
cce855bc JA |
5451 | `DIR' |
5452 | Makes the current working directory be the top of the stack, | |
5453 | and then executes the equivalent of ``cd' DIR'. `cd's to DIR. | |
5454 | ||
761783bf | 5455 | |
cce855bc JA |
5456 | \1f |
5457 | File: bashref.info, Node: Printing a Prompt, Next: The Restricted Shell, Prev: The Directory Stack, Up: Bash Features | |
ccc6cda3 | 5458 | |
37c41ab1 CR |
5459 | 6.9 Controlling the Prompt |
5460 | ========================== | |
ccc6cda3 | 5461 | |
37c41ab1 CR |
5462 | The value of the variable `PROMPT_COMMAND' is examined just before Bash |
5463 | prints each primary prompt. If `PROMPT_COMMAND' is set and has a | |
bb70624e JA |
5464 | non-null value, then the value is executed just as if it had been typed |
5465 | on the command line. | |
ccc6cda3 JA |
5466 | |
5467 | In addition, the following table describes the special characters | |
5468 | which can appear in the prompt variables: | |
5469 | ||
5470 | `\a' | |
cce855bc | 5471 | A bell character. |
ccc6cda3 JA |
5472 | |
5473 | `\d' | |
cce855bc | 5474 | The date, in "Weekday Month Date" format (e.g., "Tue May 26"). |
ccc6cda3 | 5475 | |
7117c2d2 JA |
5476 | `\D{FORMAT}' |
5477 | The FORMAT is passed to `strftime'(3) and the result is inserted | |
5478 | into the prompt string; an empty FORMAT results in a | |
5479 | locale-specific time representation. The braces are required. | |
5480 | ||
ccc6cda3 | 5481 | `\e' |
cce855bc | 5482 | An escape character. |
ccc6cda3 JA |
5483 | |
5484 | `\h' | |
cce855bc | 5485 | The hostname, up to the first `.'. |
ccc6cda3 JA |
5486 | |
5487 | `\H' | |
cce855bc | 5488 | The hostname. |
ccc6cda3 | 5489 | |
bb70624e JA |
5490 | `\j' |
5491 | The number of jobs currently managed by the shell. | |
5492 | ||
5493 | `\l' | |
5494 | The basename of the shell's terminal device name. | |
5495 | ||
ccc6cda3 | 5496 | `\n' |
cce855bc JA |
5497 | A newline. |
5498 | ||
5499 | `\r' | |
5500 | A carriage return. | |
ccc6cda3 JA |
5501 | |
5502 | `\s' | |
cce855bc | 5503 | The name of the shell, the basename of `$0' (the portion following |
ccc6cda3 JA |
5504 | the final slash). |
5505 | ||
5506 | `\t' | |
cce855bc | 5507 | The time, in 24-hour HH:MM:SS format. |
ccc6cda3 JA |
5508 | |
5509 | `\T' | |
cce855bc | 5510 | The time, in 12-hour HH:MM:SS format. |
ccc6cda3 JA |
5511 | |
5512 | `\@' | |
cce855bc JA |
5513 | The time, in 12-hour am/pm format. |
5514 | ||
f73dda09 JA |
5515 | `\A' |
5516 | The time, in 24-hour HH:MM format. | |
5517 | ||
cce855bc JA |
5518 | `\u' |
5519 | The username of the current user. | |
ccc6cda3 JA |
5520 | |
5521 | `\v' | |
cce855bc | 5522 | The version of Bash (e.g., 2.00) |
ccc6cda3 JA |
5523 | |
5524 | `\V' | |
cce855bc | 5525 | The release of Bash, version + patchlevel (e.g., 2.00.0) |
ccc6cda3 JA |
5526 | |
5527 | `\w' | |
12d937f9 | 5528 | The current working directory, with `$HOME' abbreviated with a |
09767ff0 | 5529 | tilde (uses the `$PROMPT_DIRTRIM' variable). |
ccc6cda3 JA |
5530 | |
5531 | `\W' | |
12d937f9 | 5532 | The basename of `$PWD', with `$HOME' abbreviated with a tilde. |
ccc6cda3 JA |
5533 | |
5534 | `\!' | |
cce855bc | 5535 | The history number of this command. |
ccc6cda3 JA |
5536 | |
5537 | `\#' | |
cce855bc | 5538 | The command number of this command. |
ccc6cda3 JA |
5539 | |
5540 | `\$' | |
cce855bc | 5541 | If the effective uid is 0, `#', otherwise `$'. |
ccc6cda3 | 5542 | |
cce855bc JA |
5543 | `\NNN' |
5544 | The character whose ASCII code is the octal value NNN. | |
ccc6cda3 JA |
5545 | |
5546 | `\\' | |
cce855bc | 5547 | A backslash. |
ccc6cda3 JA |
5548 | |
5549 | `\[' | |
cce855bc | 5550 | Begin a sequence of non-printing characters. This could be used to |
ccc6cda3 JA |
5551 | embed a terminal control sequence into the prompt. |
5552 | ||
5553 | `\]' | |
cce855bc | 5554 | End a sequence of non-printing characters. |
ccc6cda3 | 5555 | |
bb70624e JA |
5556 | The command number and the history number are usually different: the |
5557 | history number of a command is its position in the history list, which | |
5558 | may include commands restored from the history file (*note Bash History | |
28ef6c31 JA |
5559 | Facilities::), while the command number is the position in the sequence |
5560 | of commands executed during the current shell session. | |
bb70624e JA |
5561 | |
5562 | After the string is decoded, it is expanded via parameter expansion, | |
5563 | command substitution, arithmetic expansion, and quote removal, subject | |
28ef6c31 | 5564 | to the value of the `promptvars' shell option (*note Bash Builtins::). |
bb70624e | 5565 | |
ccc6cda3 JA |
5566 | \1f |
5567 | File: bashref.info, Node: The Restricted Shell, Next: Bash POSIX Mode, Prev: Printing a Prompt, Up: Bash Features | |
5568 | ||
37c41ab1 CR |
5569 | 6.10 The Restricted Shell |
5570 | ========================= | |
ccc6cda3 | 5571 | |
37c41ab1 CR |
5572 | If Bash is started with the name `rbash', or the `--restricted' or `-r' |
5573 | option is supplied at invocation, the shell becomes restricted. A | |
ccc6cda3 JA |
5574 | restricted shell is used to set up an environment more controlled than |
5575 | the standard shell. A restricted shell behaves identically to `bash' | |
7117c2d2 JA |
5576 | with the exception that the following are disallowed or not performed: |
5577 | ||
ccc6cda3 JA |
5578 | * Changing directories with the `cd' builtin. |
5579 | ||
b72432fd JA |
5580 | * Setting or unsetting the values of the `SHELL', `PATH', `ENV', or |
5581 | `BASH_ENV' variables. | |
ccc6cda3 JA |
5582 | |
5583 | * Specifying command names containing slashes. | |
5584 | ||
5585 | * Specifying a filename containing a slash as an argument to the `.' | |
5586 | builtin command. | |
5587 | ||
bb70624e JA |
5588 | * Specifying a filename containing a slash as an argument to the `-p' |
5589 | option to the `hash' builtin command. | |
5590 | ||
ccc6cda3 JA |
5591 | * Importing function definitions from the shell environment at |
5592 | startup. | |
5593 | ||
cce855bc JA |
5594 | * Parsing the value of `SHELLOPTS' from the shell environment at |
5595 | startup. | |
5596 | ||
ccc6cda3 JA |
5597 | * Redirecting output using the `>', `>|', `<>', `>&', `&>', and `>>' |
5598 | redirection operators. | |
5599 | ||
5600 | * Using the `exec' builtin to replace the shell with another command. | |
5601 | ||
5602 | * Adding or deleting builtin commands with the `-f' and `-d' options | |
5603 | to the `enable' builtin. | |
5604 | ||
7117c2d2 JA |
5605 | * Using the `enable' builtin command to enable disabled shell |
5606 | builtins. | |
5607 | ||
ccc6cda3 JA |
5608 | * Specifying the `-p' option to the `command' builtin. |
5609 | ||
cce855bc | 5610 | * Turning off restricted mode with `set +r' or `set +o restricted'. |
ccc6cda3 | 5611 | |
7117c2d2 JA |
5612 | These restrictions are enforced after any startup files are read. |
5613 | ||
5614 | When a command that is found to be a shell script is executed (*note | |
5615 | Shell Scripts::), `rbash' turns off any restrictions in the shell | |
5616 | spawned to execute the script. | |
5617 | ||
ccc6cda3 JA |
5618 | \1f |
5619 | File: bashref.info, Node: Bash POSIX Mode, Prev: The Restricted Shell, Up: Bash Features | |
5620 | ||
37c41ab1 CR |
5621 | 6.11 Bash POSIX Mode |
5622 | ==================== | |
ccc6cda3 | 5623 | |
37c41ab1 CR |
5624 | Starting Bash with the `--posix' command-line option or executing `set |
5625 | -o posix' while Bash is running will cause Bash to conform more closely | |
ac18b312 CR |
5626 | to the POSIX standard by changing the behavior to match that specified |
5627 | by POSIX in areas where the Bash default differs. | |
ccc6cda3 | 5628 | |
7117c2d2 JA |
5629 | When invoked as `sh', Bash enters POSIX mode after reading the |
5630 | startup files. | |
5631 | ||
ccc6cda3 JA |
5632 | The following list is what's changed when `POSIX mode' is in effect: |
5633 | ||
5634 | 1. When a command in the hash table no longer exists, Bash will | |
5635 | re-search `$PATH' to find the new location. This is also | |
5636 | available with `shopt -s checkhash'. | |
5637 | ||
28ef6c31 JA |
5638 | 2. The message printed by the job control code and builtins when a job |
5639 | exits with a non-zero status is `Done(status)'. | |
ccc6cda3 JA |
5640 | |
5641 | 3. The message printed by the job control code and builtins when a job | |
28ef6c31 JA |
5642 | is stopped is `Stopped(SIGNAME)', where SIGNAME is, for example, |
5643 | `SIGTSTP'. | |
ccc6cda3 | 5644 | |
1c72c0cd CR |
5645 | 4. The `bg' builtin uses the required format to describe each job |
5646 | placed in the background, which does not include an indication of | |
5647 | whether the job is the current or previous job. | |
5648 | ||
5649 | 5. Reserved words appearing in a context where reserved words are | |
3ee6b87d | 5650 | recognized do not undergo alias expansion. |
ccc6cda3 | 5651 | |
ac18b312 CR |
5652 | 6. The POSIX `PS1' and `PS2' expansions of `!' to the history number |
5653 | and `!!' to `!' are enabled, and parameter expansion is performed | |
5654 | on the values of `PS1' and `PS2' regardless of the setting of the | |
5655 | `promptvars' option. | |
ccc6cda3 | 5656 | |
ac18b312 CR |
5657 | 7. The POSIX startup files are executed (`$ENV') rather than the |
5658 | normal Bash files. | |
ccc6cda3 | 5659 | |
1c72c0cd | 5660 | 8. Tilde expansion is only performed on assignments preceding a |
ccc6cda3 JA |
5661 | command name, rather than on all assignment statements on the line. |
5662 | ||
1c72c0cd | 5663 | 9. The default history file is `~/.sh_history' (this is the default |
ccc6cda3 JA |
5664 | value of `$HISTFILE'). |
5665 | ||
1c72c0cd | 5666 | 10. The output of `kill -l' prints all the signal names on a single |
d3a24ed2 CR |
5667 | line, separated by spaces, without the `SIG' prefix. |
5668 | ||
1c72c0cd | 5669 | 11. The `kill' builtin does not accept signal names with a `SIG' |
d3a24ed2 | 5670 | prefix. |
ccc6cda3 | 5671 | |
1c72c0cd | 5672 | 12. Non-interactive shells exit if FILENAME in `.' FILENAME is not |
ccc6cda3 JA |
5673 | found. |
5674 | ||
1c72c0cd | 5675 | 13. Non-interactive shells exit if a syntax error in an arithmetic |
cce855bc JA |
5676 | expansion results in an invalid expression. |
5677 | ||
1c72c0cd | 5678 | 14. Redirection operators do not perform filename expansion on the word |
ccc6cda3 JA |
5679 | in the redirection unless the shell is interactive. |
5680 | ||
1c72c0cd | 5681 | 15. Redirection operators do not perform word splitting on the word in |
bb70624e JA |
5682 | the redirection. |
5683 | ||
1c72c0cd | 5684 | 16. Function names must be valid shell `name's. That is, they may not |
ccc6cda3 | 5685 | contain characters other than letters, digits, and underscores, and |
cce855bc | 5686 | may not start with a digit. Declaring a function with an invalid |
ccc6cda3 JA |
5687 | name causes a fatal syntax error in non-interactive shells. |
5688 | ||
ac18b312 CR |
5689 | 17. POSIX special builtins are found before shell functions during |
5690 | command lookup. | |
ccc6cda3 | 5691 | |
ac18b312 | 5692 | 18. If a POSIX special builtin returns an error status, a |
ccc6cda3 | 5693 | non-interactive shell exits. The fatal errors are those listed in |
ac18b312 | 5694 | the POSIX standard, and include things like passing incorrect |
ccc6cda3 JA |
5695 | options, redirection errors, variable assignment errors for |
5696 | assignments preceding the command name, and so on. | |
5697 | ||
1c72c0cd | 5698 | 19. If `CDPATH' is set, the `cd' builtin will not implicitly append |
cce855bc JA |
5699 | the current directory to it. This means that `cd' will fail if no |
5700 | valid directory name can be constructed from any of the entries in | |
5701 | `$CDPATH', even if the a directory with the same name as the name | |
5702 | given as an argument to `cd' exists in the current directory. | |
5703 | ||
1c72c0cd | 5704 | 20. A non-interactive shell exits with an error status if a variable |
ccc6cda3 JA |
5705 | assignment error occurs when no command name follows the assignment |
5706 | statements. A variable assignment error occurs, for example, when | |
cce855bc | 5707 | trying to assign a value to a readonly variable. |
ccc6cda3 | 5708 | |
1c72c0cd | 5709 | 21. A non-interactive shell exits with an error status if the iteration |
ccc6cda3 | 5710 | variable in a `for' statement or the selection variable in a |
cce855bc | 5711 | `select' statement is a readonly variable. |
ccc6cda3 | 5712 | |
1c72c0cd | 5713 | 22. Process substitution is not available. |
ccc6cda3 | 5714 | |
ac18b312 CR |
5715 | 23. Assignment statements preceding POSIX special builtins persist in |
5716 | the shell environment after the builtin completes. | |
ccc6cda3 | 5717 | |
1c72c0cd | 5718 | 24. Assignment statements preceding shell function calls persist in the |
28ef6c31 JA |
5719 | shell environment after the function returns, as if a POSIX |
5720 | special builtin command had been executed. | |
5721 | ||
1c72c0cd | 5722 | 25. The `export' and `readonly' builtin commands display their output |
ac18b312 | 5723 | in the format required by POSIX. |
d166f048 | 5724 | |
1c72c0cd | 5725 | 26. The `trap' builtin displays signal names without the leading `SIG'. |
28ef6c31 | 5726 | |
1c72c0cd | 5727 | 27. The `trap' builtin doesn't check the first argument for a possible |
d3a24ed2 | 5728 | signal specification and revert the signal handling to the original |
8a9c66f6 CR |
5729 | disposition if it is, unless that argument consists solely of |
5730 | digits and is a valid signal number. If users want to reset the | |
5731 | handler for a given signal to the original disposition, they | |
5732 | should use `-' as the first argument. | |
d3a24ed2 | 5733 | |
1c72c0cd | 5734 | 28. The `.' and `source' builtins do not search the current directory |
28ef6c31 JA |
5735 | for the filename argument if it is not found by searching `PATH'. |
5736 | ||
1c72c0cd | 5737 | 29. Subshells spawned to execute command substitutions inherit the |
28ef6c31 JA |
5738 | value of the `-e' option from the parent shell. When not in POSIX |
5739 | mode, Bash clears the `-e' option in such subshells. | |
5740 | ||
1c72c0cd | 5741 | 30. Alias expansion is always enabled, even in non-interactive shells. |
28ef6c31 | 5742 | |
1c72c0cd | 5743 | 31. When the `alias' builtin displays alias definitions, it does not |
d3a24ed2 CR |
5744 | display them with a leading `alias ' unless the `-p' option is |
5745 | supplied. | |
5746 | ||
1c72c0cd | 5747 | 32. When the `set' builtin is invoked without options, it does not |
28ef6c31 JA |
5748 | display shell function names and definitions. |
5749 | ||
1c72c0cd | 5750 | 33. When the `set' builtin is invoked without options, it displays |
f73dda09 JA |
5751 | variable values without quotes, unless they contain shell |
5752 | metacharacters, even if the result contains nonprinting characters. | |
ccc6cda3 | 5753 | |
1c72c0cd | 5754 | 34. When the `cd' builtin is invoked in LOGICAL mode, and the pathname |
7117c2d2 JA |
5755 | constructed from `$PWD' and the directory name supplied as an |
5756 | argument does not refer to an existing directory, `cd' will fail | |
5757 | instead of falling back to PHYSICAL mode. | |
5758 | ||
1c72c0cd | 5759 | 35. When the `pwd' builtin is supplied the `-P' option, it resets |
9d2b70f0 CR |
5760 | `$PWD' to a pathname containing no symlinks. |
5761 | ||
1c72c0cd CR |
5762 | 36. The `pwd' builtin verifies that the value it prints is the same as |
5763 | the current directory, even if it is not asked to check the file | |
5764 | system with the `-P' option. | |
5765 | ||
5766 | 37. When listing the history, the `fc' builtin does not include an | |
8a9c66f6 CR |
5767 | indication of whether or not a history entry has been modified. |
5768 | ||
1c72c0cd | 5769 | 38. The default editor used by `fc' is `ed'. |
8a9c66f6 | 5770 | |
1c72c0cd | 5771 | 39. The `type' and `command' builtins will not report a non-executable |
37c41ab1 CR |
5772 | file as having been found, though the shell will attempt to |
5773 | execute such a file if it is the only so-named file found in | |
5774 | `$PATH'. | |
5775 | ||
1c72c0cd | 5776 | 40. The `vi' editing mode will invoke the `vi' editor directly when |
a9fac3b2 | 5777 | the `v' command is run, instead of checking `$VISUAL' and |
1c72c0cd CR |
5778 | `$EDITOR'. |
5779 | ||
5780 | 41. When the `xpg_echo' option is enabled, Bash does not attempt to | |
37c41ab1 CR |
5781 | interpret any arguments to `echo' as options. Each argument is |
5782 | displayed, after escape characters are converted. | |
5783 | ||
09767ff0 CR |
5784 | 42. The `ulimit' builtin uses a block size of 512 bytes for the `-c' |
5785 | and `-f' options. | |
5786 | ||
8a9c66f6 | 5787 | |
ac18b312 | 5788 | There is other POSIX behavior that Bash does not implement by |
1c72c0cd | 5789 | default even when in POSIX mode. Specifically: |
ccc6cda3 | 5790 | |
1c72c0cd CR |
5791 | 1. The `fc' builtin checks `$EDITOR' as a program to edit history |
5792 | entries if `FCEDIT' is unset, rather than defaulting directly to | |
5793 | `ed'. `fc' uses `ed' if `EDITOR' is unset. | |
ccc6cda3 | 5794 | |
1c72c0cd CR |
5795 | 2. As noted above, Bash requires the `xpg_echo' option to be enabled |
5796 | for the `echo' builtin to be fully conformant. | |
28ef6c31 | 5797 | |
28ef6c31 | 5798 | |
1c72c0cd CR |
5799 | Bash can be configured to be POSIX-conformant by default, by |
5800 | specifying the `--enable-strict-posix-default' to `configure' when | |
5801 | building (*note Optional Features::). | |
28ef6c31 | 5802 | |
ccc6cda3 | 5803 | \1f |
c2a47ea9 | 5804 | File: bashref.info, Node: Job Control, Next: Command Line Editing, Prev: Bash Features, Up: Top |
ccc6cda3 | 5805 | |
37c41ab1 CR |
5806 | 7 Job Control |
5807 | ************* | |
ccc6cda3 | 5808 | |
37c41ab1 CR |
5809 | This chapter discusses what job control is, how it works, and how Bash |
5810 | allows you to access its facilities. | |
ccc6cda3 JA |
5811 | |
5812 | * Menu: | |
5813 | ||
5814 | * Job Control Basics:: How job control works. | |
5815 | * Job Control Builtins:: Bash builtin commands used to interact | |
5816 | with job control. | |
5817 | * Job Control Variables:: Variables Bash uses to customize job | |
5818 | control. | |
5819 | ||
5820 | \1f | |
5821 | File: bashref.info, Node: Job Control Basics, Next: Job Control Builtins, Up: Job Control | |
5822 | ||
37c41ab1 CR |
5823 | 7.1 Job Control Basics |
5824 | ====================== | |
ccc6cda3 | 5825 | |
37c41ab1 | 5826 | Job control refers to the ability to selectively stop (suspend) the |
ccc6cda3 JA |
5827 | execution of processes and continue (resume) their execution at a later |
5828 | point. A user typically employs this facility via an interactive | |
602bb739 CR |
5829 | interface supplied jointly by the operating system kernel's terminal |
5830 | driver and Bash. | |
ccc6cda3 JA |
5831 | |
5832 | The shell associates a JOB with each pipeline. It keeps a table of | |
5833 | currently executing jobs, which may be listed with the `jobs' command. | |
cce855bc | 5834 | When Bash starts a job asynchronously, it prints a line that looks like: |
ccc6cda3 | 5835 | [1] 25647 |
37c41ab1 CR |
5836 | indicating that this job is job number 1 and that the process ID of |
5837 | the last process in the pipeline associated with this job is 25647. | |
5838 | All of the processes in a single pipeline are members of the same job. | |
5839 | Bash uses the JOB abstraction as the basis for job control. | |
ccc6cda3 JA |
5840 | |
5841 | To facilitate the implementation of the user interface to job | |
bb70624e JA |
5842 | control, the operating system maintains the notion of a current terminal |
5843 | process group ID. Members of this process group (processes whose | |
5844 | process group ID is equal to the current terminal process group ID) | |
5845 | receive keyboard-generated signals such as `SIGINT'. These processes | |
5846 | are said to be in the foreground. Background processes are those whose | |
5847 | process group ID differs from the terminal's; such processes are immune | |
5848 | to keyboard-generated signals. Only foreground processes are allowed | |
602bb739 CR |
5849 | to read from or, if the user so specifies with `stty tostop', write to |
5850 | the terminal. Background processes which attempt to read from (write | |
5851 | to when `stty tostop' is in effect) the terminal are sent a `SIGTTIN' | |
5852 | (`SIGTTOU') signal by the kernel's terminal driver, which, unless | |
5853 | caught, suspends the process. | |
ccc6cda3 JA |
5854 | |
5855 | If the operating system on which Bash is running supports job | |
cce855bc JA |
5856 | control, Bash contains facilities to use it. Typing the SUSPEND |
5857 | character (typically `^Z', Control-Z) while a process is running causes | |
5858 | that process to be stopped and returns control to Bash. Typing the | |
5859 | DELAYED SUSPEND character (typically `^Y', Control-Y) causes the | |
5860 | process to be stopped when it attempts to read input from the terminal, | |
5861 | and control to be returned to Bash. The user then manipulates the | |
5862 | state of this job, using the `bg' command to continue it in the | |
5863 | background, the `fg' command to continue it in the foreground, or the | |
5864 | `kill' command to kill it. A `^Z' takes effect immediately, and has | |
5865 | the additional side effect of causing pending output and typeahead to | |
5866 | be discarded. | |
ccc6cda3 JA |
5867 | |
5868 | There are a number of ways to refer to a job in the shell. The | |
a9fac3b2 | 5869 | character `%' introduces a job specification (JOBSPEC). |
bb70624e JA |
5870 | |
5871 | Job number `n' may be referred to as `%n'. The symbols `%%' and | |
5872 | `%+' refer to the shell's notion of the current job, which is the last | |
eb2bb562 CR |
5873 | job stopped while it was in the foreground or started in the background. |
5874 | A single `%' (with no accompanying job specification) also refers to | |
09767ff0 CR |
5875 | the current job. The previous job may be referenced using `%-'. If |
5876 | there is only a single job, `%+' and `%-' can both be used to refer to | |
5877 | that job. In output pertaining to jobs (e.g., the output of the `jobs' | |
5878 | command), the current job is always flagged with a `+', and the | |
5879 | previous job with a `-'. | |
bb70624e JA |
5880 | |
5881 | A job may also be referred to using a prefix of the name used to | |
5882 | start it, or using a substring that appears in its command line. For | |
5883 | example, `%ce' refers to a stopped `ce' job. Using `%?ce', on the other | |
5884 | hand, refers to any job containing the string `ce' in its command line. | |
5885 | If the prefix or substring matches more than one job, Bash reports an | |
5886 | error. | |
ccc6cda3 JA |
5887 | |
5888 | Simply naming a job can be used to bring it into the foreground: | |
5889 | `%1' is a synonym for `fg %1', bringing job 1 from the background into | |
5890 | the foreground. Similarly, `%1 &' resumes job 1 in the background, | |
5891 | equivalent to `bg %1' | |
5892 | ||
5893 | The shell learns immediately whenever a job changes state. | |
5894 | Normally, Bash waits until it is about to print a prompt before | |
5895 | reporting changes in a job's status so as to not interrupt any other | |
f73dda09 JA |
5896 | output. If the `-b' option to the `set' builtin is enabled, Bash |
5897 | reports such changes immediately (*note The Set Builtin::). Any trap | |
5898 | on `SIGCHLD' is executed for each child process that exits. | |
ccc6cda3 | 5899 | |
d3ad40de | 5900 | If an attempt to exit Bash is made while jobs are stopped, (or |
6a8fd0ed | 5901 | running, if the `checkjobs' option is enabled - see *note The Shopt |
d3ad40de CR |
5902 | Builtin::), the shell prints a warning message, and if the `checkjobs' |
5903 | option is enabled, lists the jobs and their statuses. The `jobs' | |
cce855bc JA |
5904 | command may then be used to inspect their status. If a second attempt |
5905 | to exit is made without an intervening command, Bash does not print | |
d3ad40de | 5906 | another warning, and any stopped jobs are terminated. |
ccc6cda3 JA |
5907 | |
5908 | \1f | |
5909 | File: bashref.info, Node: Job Control Builtins, Next: Job Control Variables, Prev: Job Control Basics, Up: Job Control | |
5910 | ||
37c41ab1 CR |
5911 | 7.2 Job Control Builtins |
5912 | ======================== | |
ccc6cda3 JA |
5913 | |
5914 | `bg' | |
37c41ab1 CR |
5915 | bg [JOBSPEC ...] |
5916 | Resume each suspended job JOBSPEC in the background, as if it had | |
cce855bc JA |
5917 | been started with `&'. If JOBSPEC is not supplied, the current |
5918 | job is used. The return status is zero unless it is run when job | |
1c72c0cd CR |
5919 | control is not enabled, or, when run with job control enabled, any |
5920 | JOBSPEC was not found or specifies a job that was started without | |
5921 | job control. | |
ccc6cda3 JA |
5922 | |
5923 | `fg' | |
5924 | fg [JOBSPEC] | |
cce855bc JA |
5925 | Resume the job JOBSPEC in the foreground and make it the current |
5926 | job. If JOBSPEC is not supplied, the current job is used. The | |
5927 | return status is that of the command placed into the foreground, | |
5928 | or non-zero if run when job control is disabled or, when run with | |
5929 | job control enabled, JOBSPEC does not specify a valid job or | |
5930 | JOBSPEC specifies a job that was started without job control. | |
ccc6cda3 JA |
5931 | |
5932 | `jobs' | |
bb70624e | 5933 | jobs [-lnprs] [JOBSPEC] |
cce855bc | 5934 | jobs -x COMMAND [ARGUMENTS] |
ccc6cda3 JA |
5935 | |
5936 | The first form lists the active jobs. The options have the | |
5937 | following meanings: | |
5938 | ||
5939 | `-l' | |
cce855bc | 5940 | List process IDs in addition to the normal information. |
ccc6cda3 JA |
5941 | |
5942 | `-n' | |
5943 | Display information only about jobs that have changed status | |
cce855bc | 5944 | since the user was last notified of their status. |
ccc6cda3 JA |
5945 | |
5946 | `-p' | |
5947 | List only the process ID of the job's process group leader. | |
5948 | ||
5949 | `-r' | |
5950 | Restrict output to running jobs. | |
5951 | ||
5952 | `-s' | |
5953 | Restrict output to stopped jobs. | |
5954 | ||
5955 | If JOBSPEC is given, output is restricted to information about | |
5956 | that job. If JOBSPEC is not supplied, the status of all jobs is | |
5957 | listed. | |
5958 | ||
5959 | If the `-x' option is supplied, `jobs' replaces any JOBSPEC found | |
5960 | in COMMAND or ARGUMENTS with the corresponding process group ID, | |
5961 | and executes COMMAND, passing it ARGUMENTs, returning its exit | |
5962 | status. | |
5963 | ||
5964 | `kill' | |
cce855bc JA |
5965 | kill [-s SIGSPEC] [-n SIGNUM] [-SIGSPEC] JOBSPEC or PID |
5966 | kill -l [EXIT_STATUS] | |
ccc6cda3 | 5967 | Send a signal specified by SIGSPEC or SIGNUM to the process named |
cce855bc | 5968 | by job specification JOBSPEC or process ID PID. SIGSPEC is either |
9f422431 CR |
5969 | a case-insensitive signal name such as `SIGINT' (with or without |
5970 | the `SIG' prefix) or a signal number; SIGNUM is a signal number. | |
5971 | If SIGSPEC and SIGNUM are not present, `SIGTERM' is used. The | |
5972 | `-l' option lists the signal names. If any arguments are supplied | |
5973 | when `-l' is given, the names of the signals corresponding to the | |
5974 | arguments are listed, and the return status is zero. EXIT_STATUS | |
5975 | is a number specifying a signal number or the exit status of a | |
5976 | process terminated by a signal. The return status is zero if at | |
5977 | least one signal was successfully sent, or non-zero if an error | |
5978 | occurs or an invalid option is encountered. | |
ccc6cda3 JA |
5979 | |
5980 | `wait' | |
eb2bb562 CR |
5981 | wait [JOBSPEC or PID ...] |
5982 | Wait until the child process specified by each process ID PID or | |
5983 | job specification JOBSPEC exits and return the exit status of the | |
5984 | last command waited for. If a job spec is given, all processes in | |
5985 | the job are waited for. If no arguments are given, all currently | |
cce855bc JA |
5986 | active child processes are waited for, and the return status is |
5987 | zero. If neither JOBSPEC nor PID specifies an active child process | |
5988 | of the shell, the return status is 127. | |
ccc6cda3 JA |
5989 | |
5990 | `disown' | |
cce855bc | 5991 | disown [-ar] [-h] [JOBSPEC ...] |
ccc6cda3 JA |
5992 | Without options, each JOBSPEC is removed from the table of active |
5993 | jobs. If the `-h' option is given, the job is not removed from | |
5994 | the table, but is marked so that `SIGHUP' is not sent to the job | |
cce855bc JA |
5995 | if the shell receives a `SIGHUP'. If JOBSPEC is not present, and |
5996 | neither the `-a' nor `-r' option is supplied, the current job is | |
5997 | used. If no JOBSPEC is supplied, the `-a' option means to remove | |
5998 | or mark all jobs; the `-r' option without a JOBSPEC argument | |
5999 | restricts operation to running jobs. | |
ccc6cda3 JA |
6000 | |
6001 | `suspend' | |
6002 | suspend [-f] | |
6003 | Suspend the execution of this shell until it receives a `SIGCONT' | |
09767ff0 CR |
6004 | signal. A login shell cannot be suspended; the `-f' option can be |
6005 | used to override this and force the suspension. | |
ccc6cda3 | 6006 | |
761783bf | 6007 | |
ccc6cda3 JA |
6008 | When job control is not active, the `kill' and `wait' builtins do |
6009 | not accept JOBSPEC arguments. They must be supplied process IDs. | |
6010 | ||
6011 | \1f | |
6012 | File: bashref.info, Node: Job Control Variables, Prev: Job Control Builtins, Up: Job Control | |
6013 | ||
37c41ab1 CR |
6014 | 7.3 Job Control Variables |
6015 | ========================= | |
ccc6cda3 JA |
6016 | |
6017 | `auto_resume' | |
6018 | This variable controls how the shell interacts with the user and | |
6019 | job control. If this variable exists then single word simple | |
cce855bc JA |
6020 | commands without redirections are treated as candidates for |
6021 | resumption of an existing job. There is no ambiguity allowed; if | |
6022 | there is more than one job beginning with the string typed, then | |
6023 | the most recently accessed job will be selected. The name of a | |
6024 | stopped job, in this context, is the command line used to start | |
6025 | it. If this variable is set to the value `exact', the string | |
6026 | supplied must match the name of a stopped job exactly; if set to | |
ccc6cda3 JA |
6027 | `substring', the string supplied needs to match a substring of the |
6028 | name of a stopped job. The `substring' value provides | |
6029 | functionality analogous to the `%?' job ID (*note Job Control | |
28ef6c31 JA |
6030 | Basics::). If set to any other value, the supplied string must be |
6031 | a prefix of a stopped job's name; this provides functionality | |
ccc6cda3 JA |
6032 | analogous to the `%' job ID. |
6033 | ||
761783bf | 6034 | |
ccc6cda3 | 6035 | \1f |
c2a47ea9 | 6036 | File: bashref.info, Node: Command Line Editing, Next: Using History Interactively, Prev: Job Control, Up: Top |
ccc6cda3 | 6037 | |
37c41ab1 CR |
6038 | 8 Command Line Editing |
6039 | ********************** | |
ccc6cda3 | 6040 | |
37c41ab1 | 6041 | This chapter describes the basic features of the GNU command line |
bb70624e JA |
6042 | editing interface. Command line editing is provided by the Readline |
6043 | library, which is used by several different programs, including Bash. | |
a9fac3b2 CR |
6044 | Command line editing is enabled by default when using an interactive |
6045 | shell, unless the `--noediting' option is supplied at shell invocation. | |
6046 | Line editing is also used when using the `-e' option to the `read' | |
6047 | builtin command (*note Bash Builtins::). By default, the line editing | |
6048 | commands are similar to those of emacs. A vi-style line editing | |
6049 | interface is also available. Line editing can be enabled at any time | |
6050 | using the `-o emacs' or `-o vi' options to the `set' builtin command | |
6051 | (*note The Set Builtin::), or disabled using the `+o emacs' or `+o vi' | |
6052 | options to `set'. | |
ccc6cda3 JA |
6053 | |
6054 | * Menu: | |
6055 | ||
bb70624e JA |
6056 | * Introduction and Notation:: Notation used in this text. |
6057 | * Readline Interaction:: The minimum set of commands for editing a line. | |
6058 | * Readline Init File:: Customizing Readline from a user's view. | |
6059 | * Bindable Readline Commands:: A description of most of the Readline commands | |
6060 | available for binding | |
6061 | * Readline vi Mode:: A short description of how to make Readline | |
6062 | behave like the vi editor. | |
6063 | ||
6064 | * Programmable Completion:: How to specify the possible completions for | |
6065 | a specific command. | |
6066 | * Programmable Completion Builtins:: Builtin commands to specify how to | |
6067 | complete arguments for a particular command. | |
ccc6cda3 JA |
6068 | |
6069 | \1f | |
bb70624e | 6070 | File: bashref.info, Node: Introduction and Notation, Next: Readline Interaction, Up: Command Line Editing |
ccc6cda3 | 6071 | |
37c41ab1 CR |
6072 | 8.1 Introduction to Line Editing |
6073 | ================================ | |
ccc6cda3 | 6074 | |
37c41ab1 | 6075 | The following paragraphs describe the notation used to represent |
bb70624e | 6076 | keystrokes. |
ccc6cda3 | 6077 | |
28ef6c31 | 6078 | The text `C-k' is read as `Control-K' and describes the character |
bb70624e | 6079 | produced when the <k> key is pressed while the Control key is depressed. |
ccc6cda3 | 6080 | |
28ef6c31 | 6081 | The text `M-k' is read as `Meta-K' and describes the character |
bb70624e JA |
6082 | produced when the Meta key (if you have one) is depressed, and the <k> |
6083 | key is pressed. The Meta key is labeled <ALT> on many keyboards. On | |
6084 | keyboards with two keys labeled <ALT> (usually to either side of the | |
6085 | space bar), the <ALT> on the left side is generally set to work as a | |
6086 | Meta key. The <ALT> key on the right may also be configured to work as | |
6087 | a Meta key or may be configured as some other modifier, such as a | |
6088 | Compose key for typing accented characters. | |
6089 | ||
6090 | If you do not have a Meta or <ALT> key, or another key working as a | |
6091 | Meta key, the identical keystroke can be generated by typing <ESC> | |
28ef6c31 JA |
6092 | _first_, and then typing <k>. Either process is known as "metafying" |
6093 | the <k> key. | |
bb70624e | 6094 | |
28ef6c31 JA |
6095 | The text `M-C-k' is read as `Meta-Control-k' and describes the |
6096 | character produced by "metafying" `C-k'. | |
bb70624e JA |
6097 | |
6098 | In addition, several keys have their own names. Specifically, | |
6099 | <DEL>, <ESC>, <LFD>, <SPC>, <RET>, and <TAB> all stand for themselves | |
28ef6c31 JA |
6100 | when seen in this text, or in an init file (*note Readline Init File::). |
6101 | If your keyboard lacks a <LFD> key, typing <C-j> will produce the | |
6102 | desired character. The <RET> key may be labeled <Return> or <Enter> on | |
6103 | some keyboards. | |
ccc6cda3 JA |
6104 | |
6105 | \1f | |
bb70624e | 6106 | File: bashref.info, Node: Readline Interaction, Next: Readline Init File, Prev: Introduction and Notation, Up: Command Line Editing |
cce855bc | 6107 | |
37c41ab1 CR |
6108 | 8.2 Readline Interaction |
6109 | ======================== | |
cce855bc | 6110 | |
37c41ab1 | 6111 | Often during an interactive session you type in a long line of text, |
bb70624e JA |
6112 | only to notice that the first word on the line is misspelled. The |
6113 | Readline library gives you a set of commands for manipulating the text | |
6114 | as you type it in, allowing you to just fix your typo, and not forcing | |
6115 | you to retype the majority of the line. Using these editing commands, | |
6116 | you move the cursor to the place that needs correction, and delete or | |
6117 | insert the text of the corrections. Then, when you are satisfied with | |
28ef6c31 JA |
6118 | the line, you simply press <RET>. You do not have to be at the end of |
6119 | the line to press <RET>; the entire line is accepted regardless of the | |
6120 | location of the cursor within the line. | |
cce855bc | 6121 | |
bb70624e | 6122 | * Menu: |
cce855bc | 6123 | |
bb70624e JA |
6124 | * Readline Bare Essentials:: The least you need to know about Readline. |
6125 | * Readline Movement Commands:: Moving about the input line. | |
6126 | * Readline Killing Commands:: How to delete text, and how to get it back! | |
6127 | * Readline Arguments:: Giving numeric arguments to commands. | |
6128 | * Searching:: Searching through previous lines. | |
cce855bc | 6129 | |
bb70624e JA |
6130 | \1f |
6131 | File: bashref.info, Node: Readline Bare Essentials, Next: Readline Movement Commands, Up: Readline Interaction | |
cce855bc | 6132 | |
37c41ab1 CR |
6133 | 8.2.1 Readline Bare Essentials |
6134 | ------------------------------ | |
cce855bc | 6135 | |
37c41ab1 CR |
6136 | In order to enter characters into the line, simply type them. The typed |
6137 | character appears where the cursor was, and then the cursor moves one | |
6138 | space to the right. If you mistype a character, you can use your erase | |
6139 | character to back up and delete the mistyped character. | |
cce855bc | 6140 | |
bb70624e JA |
6141 | Sometimes you may mistype a character, and not notice the error |
6142 | until you have typed several other characters. In that case, you can | |
28ef6c31 JA |
6143 | type `C-b' to move the cursor to the left, and then correct your |
6144 | mistake. Afterwards, you can move the cursor to the right with `C-f'. | |
cce855bc | 6145 | |
bb70624e JA |
6146 | When you add text in the middle of a line, you will notice that |
6147 | characters to the right of the cursor are `pushed over' to make room | |
6148 | for the text that you have inserted. Likewise, when you delete text | |
6149 | behind the cursor, characters to the right of the cursor are `pulled | |
6150 | back' to fill in the blank space created by the removal of the text. A | |
6151 | list of the bare essentials for editing the text of an input line | |
6152 | follows. | |
cce855bc | 6153 | |
28ef6c31 | 6154 | `C-b' |
bb70624e | 6155 | Move back one character. |
cce855bc | 6156 | |
28ef6c31 | 6157 | `C-f' |
bb70624e | 6158 | Move forward one character. |
cce855bc | 6159 | |
bb70624e JA |
6160 | <DEL> or <Backspace> |
6161 | Delete the character to the left of the cursor. | |
cce855bc | 6162 | |
28ef6c31 | 6163 | `C-d' |
bb70624e | 6164 | Delete the character underneath the cursor. |
cce855bc | 6165 | |
bb70624e JA |
6166 | Printing characters |
6167 | Insert the character into the line at the cursor. | |
cce855bc | 6168 | |
28ef6c31 | 6169 | `C-_' or `C-x C-u' |
bb70624e JA |
6170 | Undo the last editing command. You can undo all the way back to an |
6171 | empty line. | |
cce855bc | 6172 | |
bb70624e JA |
6173 | (Depending on your configuration, the <Backspace> key be set to delete |
6174 | the character to the left of the cursor and the <DEL> key set to delete | |
28ef6c31 | 6175 | the character underneath the cursor, like `C-d', rather than the |
bb70624e | 6176 | character to the left of the cursor.) |
cce855bc JA |
6177 | |
6178 | \1f | |
bb70624e | 6179 | File: bashref.info, Node: Readline Movement Commands, Next: Readline Killing Commands, Prev: Readline Bare Essentials, Up: Readline Interaction |
ccc6cda3 | 6180 | |
37c41ab1 CR |
6181 | 8.2.2 Readline Movement Commands |
6182 | -------------------------------- | |
ccc6cda3 | 6183 | |
37c41ab1 | 6184 | The above table describes the most basic keystrokes that you need in |
bb70624e | 6185 | order to do editing of the input line. For your convenience, many |
28ef6c31 | 6186 | other commands have been added in addition to `C-b', `C-f', `C-d', and |
bb70624e | 6187 | <DEL>. Here are some commands for moving more rapidly about the line. |
ccc6cda3 | 6188 | |
28ef6c31 | 6189 | `C-a' |
bb70624e | 6190 | Move to the start of the line. |
ccc6cda3 | 6191 | |
28ef6c31 | 6192 | `C-e' |
bb70624e | 6193 | Move to the end of the line. |
ccc6cda3 | 6194 | |
28ef6c31 | 6195 | `M-f' |
bb70624e JA |
6196 | Move forward a word, where a word is composed of letters and |
6197 | digits. | |
ccc6cda3 | 6198 | |
28ef6c31 | 6199 | `M-b' |
bb70624e | 6200 | Move backward a word. |
ccc6cda3 | 6201 | |
28ef6c31 | 6202 | `C-l' |
bb70624e | 6203 | Clear the screen, reprinting the current line at the top. |
ccc6cda3 | 6204 | |
28ef6c31 | 6205 | Notice how `C-f' moves forward a character, while `M-f' moves |
bb70624e JA |
6206 | forward a word. It is a loose convention that control keystrokes |
6207 | operate on characters while meta keystrokes operate on words. | |
ccc6cda3 JA |
6208 | |
6209 | \1f | |
bb70624e | 6210 | File: bashref.info, Node: Readline Killing Commands, Next: Readline Arguments, Prev: Readline Movement Commands, Up: Readline Interaction |
ccc6cda3 | 6211 | |
37c41ab1 CR |
6212 | 8.2.3 Readline Killing Commands |
6213 | ------------------------------- | |
ccc6cda3 | 6214 | |
37c41ab1 CR |
6215 | "Killing" text means to delete the text from the line, but to save it |
6216 | away for later use, usually by "yanking" (re-inserting) it back into | |
bb70624e JA |
6217 | the line. (`Cut' and `paste' are more recent jargon for `kill' and |
6218 | `yank'.) | |
ccc6cda3 | 6219 | |
bb70624e JA |
6220 | If the description for a command says that it `kills' text, then you |
6221 | can be sure that you can get the text back in a different (or the same) | |
6222 | place later. | |
ccc6cda3 | 6223 | |
bb70624e JA |
6224 | When you use a kill command, the text is saved in a "kill-ring". |
6225 | Any number of consecutive kills save all of the killed text together, so | |
6226 | that when you yank it back, you get it all. The kill ring is not line | |
6227 | specific; the text that you killed on a previously typed line is | |
37c41ab1 | 6228 | available to be yanked back later, when you are typing another line. |
ccc6cda3 | 6229 | |
bb70624e | 6230 | Here is the list of commands for killing text. |
ccc6cda3 | 6231 | |
28ef6c31 | 6232 | `C-k' |
bb70624e JA |
6233 | Kill the text from the current cursor position to the end of the |
6234 | line. | |
ccc6cda3 | 6235 | |
28ef6c31 | 6236 | `M-d' |
bb70624e JA |
6237 | Kill from the cursor to the end of the current word, or, if between |
6238 | words, to the end of the next word. Word boundaries are the same | |
28ef6c31 | 6239 | as those used by `M-f'. |
ccc6cda3 | 6240 | |
28ef6c31 | 6241 | `M-<DEL>' |
f73dda09 | 6242 | Kill from the cursor the start of the current word, or, if between |
bb70624e | 6243 | words, to the start of the previous word. Word boundaries are the |
28ef6c31 | 6244 | same as those used by `M-b'. |
ccc6cda3 | 6245 | |
28ef6c31 | 6246 | `C-w' |
ccc6cda3 | 6247 | Kill from the cursor to the previous whitespace. This is |
28ef6c31 | 6248 | different than `M-<DEL>' because the word boundaries differ. |
ccc6cda3 | 6249 | |
761783bf | 6250 | |
cce855bc JA |
6251 | Here is how to "yank" the text back into the line. Yanking means to |
6252 | copy the most-recently-killed text from the kill buffer. | |
ccc6cda3 | 6253 | |
28ef6c31 | 6254 | `C-y' |
ccc6cda3 JA |
6255 | Yank the most recently killed text back into the buffer at the |
6256 | cursor. | |
6257 | ||
28ef6c31 | 6258 | `M-y' |
ccc6cda3 | 6259 | Rotate the kill-ring, and yank the new top. You can only do this |
28ef6c31 | 6260 | if the prior command is `C-y' or `M-y'. |
ccc6cda3 JA |
6261 | |
6262 | \1f | |
6263 | File: bashref.info, Node: Readline Arguments, Next: Searching, Prev: Readline Killing Commands, Up: Readline Interaction | |
6264 | ||
37c41ab1 CR |
6265 | 8.2.4 Readline Arguments |
6266 | ------------------------ | |
ccc6cda3 | 6267 | |
37c41ab1 | 6268 | You can pass numeric arguments to Readline commands. Sometimes the |
ccc6cda3 JA |
6269 | argument acts as a repeat count, other times it is the sign of the |
6270 | argument that is significant. If you pass a negative argument to a | |
6271 | command which normally acts in a forward direction, that command will | |
6272 | act in a backward direction. For example, to kill text back to the | |
6273 | start of the line, you might type `M-- C-k'. | |
6274 | ||
6275 | The general way to pass numeric arguments to a command is to type | |
cce855bc | 6276 | meta digits before the command. If the first `digit' typed is a minus |
bb70624e | 6277 | sign (`-'), then the sign of the argument will be negative. Once you |
cce855bc JA |
6278 | have typed one meta digit to get the argument started, you can type the |
6279 | remainder of the digits, and then the command. For example, to give | |
28ef6c31 JA |
6280 | the `C-d' command an argument of 10, you could type `M-1 0 C-d', which |
6281 | will delete the next ten characters on the input line. | |
ccc6cda3 JA |
6282 | |
6283 | \1f | |
6284 | File: bashref.info, Node: Searching, Prev: Readline Arguments, Up: Readline Interaction | |
6285 | ||
37c41ab1 CR |
6286 | 8.2.5 Searching for Commands in the History |
6287 | ------------------------------------------- | |
ccc6cda3 | 6288 | |
37c41ab1 | 6289 | Readline provides commands for searching through the command history |
28ef6c31 JA |
6290 | (*note Bash History Facilities::) for lines containing a specified |
6291 | string. There are two search modes: "incremental" and | |
6292 | "non-incremental". | |
ccc6cda3 JA |
6293 | |
6294 | Incremental searches begin before the user has finished typing the | |
6295 | search string. As each character of the search string is typed, | |
cce855bc | 6296 | Readline displays the next entry from the history matching the string |
ccc6cda3 | 6297 | typed so far. An incremental search requires only as many characters |
bb70624e | 6298 | as needed to find the desired history entry. To search backward in the |
28ef6c31 | 6299 | history for a particular string, type `C-r'. Typing `C-s' searches |
bb70624e JA |
6300 | forward through the history. The characters present in the value of |
6301 | the `isearch-terminators' variable are used to terminate an incremental | |
6302 | search. If that variable has not been assigned a value, the <ESC> and | |
28ef6c31 | 6303 | `C-J' characters will terminate an incremental search. `C-g' will |
bb70624e JA |
6304 | abort an incremental search and restore the original line. When the |
6305 | search is terminated, the history entry containing the search string | |
6306 | becomes the current line. | |
6307 | ||
28ef6c31 JA |
6308 | To find other matching entries in the history list, type `C-r' or |
6309 | `C-s' as appropriate. This will search backward or forward in the | |
bb70624e JA |
6310 | history for the next entry matching the search string typed so far. |
6311 | Any other key sequence bound to a Readline command will terminate the | |
6312 | search and execute that command. For instance, a <RET> will terminate | |
6313 | the search and accept the line, thereby executing the command from the | |
28ef6c31 JA |
6314 | history list. A movement command will terminate the search, make the |
6315 | last line found the current line, and begin editing. | |
ccc6cda3 | 6316 | |
f73dda09 JA |
6317 | Readline remembers the last incremental search string. If two |
6318 | `C-r's are typed without any intervening characters defining a new | |
6319 | search string, any remembered search string is used. | |
6320 | ||
ccc6cda3 JA |
6321 | Non-incremental searches read the entire search string before |
6322 | starting to search for matching history lines. The search string may be | |
cce855bc | 6323 | typed by the user or be part of the contents of the current line. |
ccc6cda3 JA |
6324 | |
6325 | \1f | |
6326 | File: bashref.info, Node: Readline Init File, Next: Bindable Readline Commands, Prev: Readline Interaction, Up: Command Line Editing | |
6327 | ||
37c41ab1 CR |
6328 | 8.3 Readline Init File |
6329 | ====================== | |
ccc6cda3 | 6330 | |
37c41ab1 | 6331 | Although the Readline library comes with a set of Emacs-like |
cce855bc JA |
6332 | keybindings installed by default, it is possible to use a different set |
6333 | of keybindings. Any user can customize programs that use Readline by | |
bb70624e JA |
6334 | putting commands in an "inputrc" file, conventionally in his home |
6335 | directory. The name of this file is taken from the value of the shell | |
6336 | variable `INPUTRC'. If that variable is unset, the default is | |
d3ad40de CR |
6337 | `~/.inputrc'. If that file does not exist or cannot be read, the |
6338 | ultimate default is `/etc/inputrc'. | |
ccc6cda3 JA |
6339 | |
6340 | When a program which uses the Readline library starts up, the init | |
6341 | file is read, and the key bindings are set. | |
6342 | ||
6343 | In addition, the `C-x C-r' command re-reads this init file, thus | |
6344 | incorporating any changes that you might have made to it. | |
6345 | ||
6346 | * Menu: | |
6347 | ||
6348 | * Readline Init File Syntax:: Syntax for the commands in the inputrc file. | |
6349 | ||
6350 | * Conditional Init Constructs:: Conditional key bindings in the inputrc file. | |
6351 | ||
6352 | * Sample Init File:: An example inputrc file. | |
6353 | ||
6354 | \1f | |
6355 | File: bashref.info, Node: Readline Init File Syntax, Next: Conditional Init Constructs, Up: Readline Init File | |
6356 | ||
37c41ab1 CR |
6357 | 8.3.1 Readline Init File Syntax |
6358 | ------------------------------- | |
ccc6cda3 | 6359 | |
37c41ab1 | 6360 | There are only a few basic constructs allowed in the Readline init |
ccc6cda3 JA |
6361 | file. Blank lines are ignored. Lines beginning with a `#' are |
6362 | comments. Lines beginning with a `$' indicate conditional constructs | |
28ef6c31 | 6363 | (*note Conditional Init Constructs::). Other lines denote variable |
ccc6cda3 JA |
6364 | settings and key bindings. |
6365 | ||
6366 | Variable Settings | |
cce855bc JA |
6367 | You can modify the run-time behavior of Readline by altering the |
6368 | values of variables in Readline using the `set' command within the | |
28ef6c31 JA |
6369 | init file. The syntax is simple: |
6370 | ||
6371 | set VARIABLE VALUE | |
6372 | ||
6373 | Here, for example, is how to change from the default Emacs-like | |
6374 | key binding to use `vi' line editing commands: | |
ccc6cda3 JA |
6375 | |
6376 | set editing-mode vi | |
6377 | ||
28ef6c31 | 6378 | Variable names and values, where appropriate, are recognized |
1c72c0cd CR |
6379 | without regard to case. Unrecognized variable names are ignored. |
6380 | ||
6381 | Boolean variables (those that can be set to on or off) are set to | |
6382 | on if the value is null or empty, ON (case-insensitive), or 1. | |
6383 | Any other value results in the variable being set to off. | |
28ef6c31 | 6384 | |
bb70624e JA |
6385 | The `bind -V' command lists the current Readline variable names |
6386 | and values. *Note Bash Builtins::. | |
6387 | ||
cce855bc JA |
6388 | A great deal of run-time behavior is changeable with the following |
6389 | variables. | |
ccc6cda3 JA |
6390 | |
6391 | `bell-style' | |
6392 | Controls what happens when Readline wants to ring the | |
6393 | terminal bell. If set to `none', Readline never rings the | |
6394 | bell. If set to `visible', Readline uses a visible bell if | |
6395 | one is available. If set to `audible' (the default), | |
6396 | Readline attempts to ring the terminal's bell. | |
6397 | ||
eb2bb562 CR |
6398 | `bind-tty-special-chars' |
6399 | If set to `on', Readline attempts to bind the control | |
6400 | characters treated specially by the kernel's terminal driver | |
6401 | to their Readline equivalents. | |
6402 | ||
ccc6cda3 JA |
6403 | `comment-begin' |
6404 | The string to insert at the beginning of the line when the | |
6405 | `insert-comment' command is executed. The default value is | |
6406 | `"#"'. | |
6407 | ||
cce855bc JA |
6408 | `completion-ignore-case' |
6409 | If set to `on', Readline performs filename matching and | |
6410 | completion in a case-insensitive fashion. The default value | |
6411 | is `off'. | |
6412 | ||
ed35cb4a CR |
6413 | `completion-prefix-display-length' |
6414 | The length in characters of the common prefix of a list of | |
6415 | possible completions that is displayed without modification. | |
6416 | When set to a value greater than zero, common prefixes longer | |
6417 | than this value are replaced with an ellipsis when displaying | |
6418 | possible completions. | |
6419 | ||
ccc6cda3 JA |
6420 | `completion-query-items' |
6421 | The number of possible completions that determines when the | |
d3a24ed2 CR |
6422 | user is asked whether the list of possibilities should be |
6423 | displayed. If the number of possible completions is greater | |
6424 | than this value, Readline will ask the user whether or not he | |
6425 | wishes to view them; otherwise, they are simply listed. This | |
6426 | variable must be set to an integer value greater than or | |
1c72c0cd CR |
6427 | equal to 0. A negative value means Readline should never ask. |
6428 | The default limit is `100'. | |
ccc6cda3 JA |
6429 | |
6430 | `convert-meta' | |
6431 | If set to `on', Readline will convert characters with the | |
cce855bc | 6432 | eighth bit set to an ASCII key sequence by stripping the |
bb70624e | 6433 | eighth bit and prefixing an <ESC> character, converting them |
cce855bc | 6434 | to a meta-prefixed key sequence. The default value is `on'. |
ccc6cda3 JA |
6435 | |
6436 | `disable-completion' | |
cce855bc | 6437 | If set to `On', Readline will inhibit word completion. |
ccc6cda3 JA |
6438 | Completion characters will be inserted into the line as if |
6439 | they had been mapped to `self-insert'. The default is `off'. | |
6440 | ||
6441 | `editing-mode' | |
cce855bc JA |
6442 | The `editing-mode' variable controls which default set of key |
6443 | bindings is used. By default, Readline starts up in Emacs | |
6444 | editing mode, where the keystrokes are most similar to Emacs. | |
6445 | This variable can be set to either `emacs' or `vi'. | |
ccc6cda3 JA |
6446 | |
6447 | `enable-keypad' | |
cce855bc | 6448 | When set to `on', Readline will try to enable the application |
ccc6cda3 JA |
6449 | keypad when it is called. Some systems need this to enable |
6450 | the arrow keys. The default is `off'. | |
6451 | ||
6452 | `expand-tilde' | |
6453 | If set to `on', tilde expansion is performed when Readline | |
6454 | attempts word completion. The default is `off'. | |
6455 | ||
1c72c0cd | 6456 | `history-preserve-point' |
d7f49990 CR |
6457 | If set to `on', the history code attempts to place the point |
6458 | (the current cursor position) at the same location on each | |
6459 | history line retrieved with `previous-history' or | |
6460 | `next-history'. The default is `off'. | |
f73dda09 | 6461 | |
6a8fd0ed CR |
6462 | `history-size' |
6463 | Set the maximum number of history entries saved in the | |
6464 | history list. If set to zero, the number of entries in the | |
6465 | history list is not limited. | |
6466 | ||
ccc6cda3 JA |
6467 | `horizontal-scroll-mode' |
6468 | This variable can be set to either `on' or `off'. Setting it | |
cce855bc | 6469 | to `on' means that the text of the lines being edited will |
ccc6cda3 JA |
6470 | scroll horizontally on a single screen line when they are |
6471 | longer than the width of the screen, instead of wrapping onto | |
6472 | a new screen line. By default, this variable is set to `off'. | |
6473 | ||
b72432fd JA |
6474 | `input-meta' |
6475 | If set to `on', Readline will enable eight-bit input (it will | |
28ef6c31 | 6476 | not clear the eighth bit in the characters it reads), |
b72432fd JA |
6477 | regardless of what the terminal claims it can support. The |
6478 | default value is `off'. The name `meta-flag' is a synonym | |
6479 | for this variable. | |
6480 | ||
6481 | `isearch-terminators' | |
6482 | The string of characters that should terminate an incremental | |
6483 | search without subsequently executing the character as a | |
28ef6c31 JA |
6484 | command (*note Searching::). If this variable has not been |
6485 | given a value, the characters <ESC> and `C-J' will terminate | |
b72432fd JA |
6486 | an incremental search. |
6487 | ||
ccc6cda3 JA |
6488 | `keymap' |
6489 | Sets Readline's idea of the current keymap for key binding | |
6490 | commands. Acceptable `keymap' names are `emacs', | |
28ef6c31 | 6491 | `emacs-standard', `emacs-meta', `emacs-ctlx', `vi', `vi-move', |
ccc6cda3 JA |
6492 | `vi-command', and `vi-insert'. `vi' is equivalent to |
6493 | `vi-command'; `emacs' is equivalent to `emacs-standard'. The | |
6494 | default value is `emacs'. The value of the `editing-mode' | |
6495 | variable also affects the default keymap. | |
6496 | ||
6497 | `mark-directories' | |
6498 | If set to `on', completed directory names have a slash | |
6499 | appended. The default is `on'. | |
6500 | ||
6501 | `mark-modified-lines' | |
cce855bc JA |
6502 | This variable, when set to `on', causes Readline to display an |
6503 | asterisk (`*') at the start of history lines which have been | |
6504 | modified. This variable is `off' by default. | |
ccc6cda3 | 6505 | |
7117c2d2 JA |
6506 | `mark-symlinked-directories' |
6507 | If set to `on', completed names which are symbolic links to | |
6508 | directories have a slash appended (subject to the value of | |
6509 | `mark-directories'). The default is `off'. | |
6510 | ||
f73dda09 JA |
6511 | `match-hidden-files' |
6512 | This variable, when set to `on', causes Readline to match | |
6513 | files whose names begin with a `.' (hidden files) when | |
6514 | performing filename completion, unless the leading `.' is | |
6515 | supplied by the user in the filename to be completed. This | |
6516 | variable is `on' by default. | |
6517 | ||
ccc6cda3 JA |
6518 | `output-meta' |
6519 | If set to `on', Readline will display characters with the | |
6520 | eighth bit set directly rather than as a meta-prefixed escape | |
6521 | sequence. The default is `off'. | |
6522 | ||
7117c2d2 JA |
6523 | `page-completions' |
6524 | If set to `on', Readline uses an internal `more'-like pager | |
6525 | to display a screenful of possible completions at a time. | |
6526 | This variable is `on' by default. | |
6527 | ||
cce855bc JA |
6528 | `print-completions-horizontally' |
6529 | If set to `on', Readline will display completions with matches | |
6530 | sorted horizontally in alphabetical order, rather than down | |
6531 | the screen. The default is `off'. | |
6532 | ||
ed35cb4a CR |
6533 | `revert-all-at-newline' |
6534 | If set to `on', Readline will undo all changes to history | |
6535 | lines before returning when `accept-line' is executed. By | |
6536 | default, history lines may be modified and retain individual | |
6537 | undo lists across calls to `readline'. The default is `off'. | |
6538 | ||
ccc6cda3 JA |
6539 | `show-all-if-ambiguous' |
6540 | This alters the default behavior of the completion functions. | |
6541 | If set to `on', words which have more than one possible | |
6542 | completion cause the matches to be listed immediately instead | |
6543 | of ringing the bell. The default value is `off'. | |
6544 | ||
d3a24ed2 CR |
6545 | `show-all-if-unmodified' |
6546 | This alters the default behavior of the completion functions | |
6547 | in a fashion similar to SHOW-ALL-IF-AMBIGUOUS. If set to | |
6548 | `on', words which have more than one possible completion | |
6549 | without any possible partial completion (the possible | |
6550 | completions don't share a common prefix) cause the matches to | |
6551 | be listed immediately instead of ringing the bell. The | |
6552 | default value is `off'. | |
6553 | ||
ccc6cda3 JA |
6554 | `visible-stats' |
6555 | If set to `on', a character denoting a file's type is | |
6556 | appended to the filename when listing possible completions. | |
6557 | The default is `off'. | |
6558 | ||
761783bf | 6559 | |
ccc6cda3 JA |
6560 | Key Bindings |
6561 | The syntax for controlling key bindings in the init file is | |
bb70624e | 6562 | simple. First you need to find the name of the command that you |
cce855bc JA |
6563 | want to change. The following sections contain tables of the |
6564 | command name, the default keybinding, if any, and a short | |
6565 | description of what the command does. | |
ccc6cda3 | 6566 | |
28ef6c31 JA |
6567 | Once you know the name of the command, simply place on a line in |
6568 | the init file the name of the key you wish to bind the command to, | |
d3ad40de CR |
6569 | a colon, and then the name of the command. There can be no space |
6570 | between the key name and the colon - that will be interpreted as | |
6571 | part of the key name. The name of the key can be expressed in | |
6572 | different ways, depending on what you find most comfortable. | |
28ef6c31 JA |
6573 | |
6574 | In addition to command names, readline allows keys to be bound to | |
6575 | a string that is inserted when the key is pressed (a MACRO). | |
ccc6cda3 | 6576 | |
bb70624e JA |
6577 | The `bind -p' command displays Readline function names and |
6578 | bindings in a format that can put directly into an initialization | |
6579 | file. *Note Bash Builtins::. | |
6580 | ||
ccc6cda3 JA |
6581 | KEYNAME: FUNCTION-NAME or MACRO |
6582 | KEYNAME is the name of a key spelled out in English. For | |
6583 | example: | |
6584 | Control-u: universal-argument | |
6585 | Meta-Rubout: backward-kill-word | |
6586 | Control-o: "> output" | |
6587 | ||
28ef6c31 JA |
6588 | In the above example, `C-u' is bound to the function |
6589 | `universal-argument', `M-DEL' is bound to the function | |
6590 | `backward-kill-word', and `C-o' is bound to run the macro | |
ccc6cda3 JA |
6591 | expressed on the right hand side (that is, to insert the text |
6592 | `> output' into the line). | |
6593 | ||
28ef6c31 JA |
6594 | A number of symbolic character names are recognized while |
6595 | processing this key binding syntax: DEL, ESC, ESCAPE, LFD, | |
6596 | NEWLINE, RET, RETURN, RUBOUT, SPACE, SPC, and TAB. | |
6597 | ||
ccc6cda3 JA |
6598 | "KEYSEQ": FUNCTION-NAME or MACRO |
6599 | KEYSEQ differs from KEYNAME above in that strings denoting an | |
6600 | entire key sequence can be specified, by placing the key | |
6601 | sequence in double quotes. Some GNU Emacs style key escapes | |
6602 | can be used, as in the following example, but the special | |
6603 | character names are not recognized. | |
6604 | ||
6605 | "\C-u": universal-argument | |
6606 | "\C-x\C-r": re-read-init-file | |
6607 | "\e[11~": "Function Key 1" | |
6608 | ||
28ef6c31 | 6609 | In the above example, `C-u' is again bound to the function |
ccc6cda3 | 6610 | `universal-argument' (just as it was in the first example), |
28ef6c31 JA |
6611 | `C-x C-r' is bound to the function `re-read-init-file', and |
6612 | `<ESC> <[> <1> <1> <~>' is bound to insert the text `Function | |
6613 | Key 1'. | |
cce855bc | 6614 | |
761783bf | 6615 | |
cce855bc JA |
6616 | The following GNU Emacs style escape sequences are available when |
6617 | specifying key sequences: | |
6618 | ||
6619 | `\C-' | |
6620 | control prefix | |
6621 | ||
6622 | `\M-' | |
6623 | meta prefix | |
6624 | ||
6625 | `\e' | |
6626 | an escape character | |
6627 | ||
6628 | `\\' | |
6629 | backslash | |
6630 | ||
6631 | `\"' | |
bb70624e | 6632 | <">, a double quotation mark |
cce855bc JA |
6633 | |
6634 | `\'' | |
bb70624e | 6635 | <'>, a single quote or apostrophe |
cce855bc JA |
6636 | |
6637 | In addition to the GNU Emacs style escape sequences, a second set | |
6638 | of backslash escapes is available: | |
ccc6cda3 | 6639 | |
cce855bc JA |
6640 | `\a' |
6641 | alert (bell) | |
6642 | ||
6643 | `\b' | |
6644 | backspace | |
6645 | ||
6646 | `\d' | |
6647 | delete | |
6648 | ||
6649 | `\f' | |
6650 | form feed | |
6651 | ||
6652 | `\n' | |
6653 | newline | |
ccc6cda3 | 6654 | |
cce855bc JA |
6655 | `\r' |
6656 | carriage return | |
ccc6cda3 | 6657 | |
cce855bc JA |
6658 | `\t' |
6659 | horizontal tab | |
ccc6cda3 | 6660 | |
cce855bc JA |
6661 | `\v' |
6662 | vertical tab | |
ccc6cda3 | 6663 | |
cce855bc | 6664 | `\NNN' |
f73dda09 | 6665 | the eight-bit character whose value is the octal value NNN |
cce855bc | 6666 | (one to three digits) |
ccc6cda3 | 6667 | |
f73dda09 JA |
6668 | `\xHH' |
6669 | the eight-bit character whose value is the hexadecimal value | |
6670 | HH (one or two hex digits) | |
6671 | ||
cce855bc JA |
6672 | When entering the text of a macro, single or double quotes must be |
6673 | used to indicate a macro definition. Unquoted text is assumed to | |
6674 | be a function name. In the macro body, the backslash escapes | |
6675 | described above are expanded. Backslash will quote any other | |
6676 | character in the macro text, including `"' and `''. For example, | |
6677 | the following binding will make `C-x \' insert a single `\' into | |
6678 | the line: | |
6679 | "\C-x\\": "\\" | |
ccc6cda3 | 6680 | |
761783bf | 6681 | |
ccc6cda3 JA |
6682 | \1f |
6683 | File: bashref.info, Node: Conditional Init Constructs, Next: Sample Init File, Prev: Readline Init File Syntax, Up: Readline Init File | |
6684 | ||
37c41ab1 CR |
6685 | 8.3.2 Conditional Init Constructs |
6686 | --------------------------------- | |
ccc6cda3 | 6687 | |
37c41ab1 | 6688 | Readline implements a facility similar in spirit to the conditional |
ccc6cda3 JA |
6689 | compilation features of the C preprocessor which allows key bindings |
6690 | and variable settings to be performed as the result of tests. There | |
cce855bc | 6691 | are four parser directives used. |
ccc6cda3 JA |
6692 | |
6693 | `$if' | |
6694 | The `$if' construct allows bindings to be made based on the | |
6695 | editing mode, the terminal being used, or the application using | |
6696 | Readline. The text of the test extends to the end of the line; no | |
6697 | characters are required to isolate it. | |
6698 | ||
6699 | `mode' | |
6700 | The `mode=' form of the `$if' directive is used to test | |
6701 | whether Readline is in `emacs' or `vi' mode. This may be | |
6702 | used in conjunction with the `set keymap' command, for | |
6703 | instance, to set bindings in the `emacs-standard' and | |
6704 | `emacs-ctlx' keymaps only if Readline is starting out in | |
6705 | `emacs' mode. | |
6706 | ||
6707 | `term' | |
6708 | The `term=' form may be used to include terminal-specific key | |
6709 | bindings, perhaps to bind the key sequences output by the | |
6710 | terminal's function keys. The word on the right side of the | |
cce855bc JA |
6711 | `=' is tested against both the full name of the terminal and |
6712 | the portion of the terminal name before the first `-'. This | |
ccc6cda3 JA |
6713 | allows `sun' to match both `sun' and `sun-cmd', for instance. |
6714 | ||
6715 | `application' | |
6716 | The APPLICATION construct is used to include | |
6717 | application-specific settings. Each program using the | |
6718 | Readline library sets the APPLICATION NAME, and you can test | |
28ef6c31 JA |
6719 | for a particular value. This could be used to bind key |
6720 | sequences to functions useful for a specific program. For | |
6721 | instance, the following command adds a key sequence that | |
6722 | quotes the current or previous word in Bash: | |
ccc6cda3 JA |
6723 | $if Bash |
6724 | # Quote the current or previous word | |
6725 | "\C-xq": "\eb\"\ef\"" | |
6726 | $endif | |
6727 | ||
6728 | `$endif' | |
cce855bc JA |
6729 | This command, as seen in the previous example, terminates an `$if' |
6730 | command. | |
ccc6cda3 JA |
6731 | |
6732 | `$else' | |
6733 | Commands in this branch of the `$if' directive are executed if the | |
6734 | test fails. | |
6735 | ||
cce855bc JA |
6736 | `$include' |
6737 | This directive takes a single filename as an argument and reads | |
28ef6c31 JA |
6738 | commands and bindings from that file. For example, the following |
6739 | directive reads from `/etc/inputrc': | |
cce855bc JA |
6740 | $include /etc/inputrc |
6741 | ||
ccc6cda3 JA |
6742 | \1f |
6743 | File: bashref.info, Node: Sample Init File, Prev: Conditional Init Constructs, Up: Readline Init File | |
6744 | ||
37c41ab1 CR |
6745 | 8.3.3 Sample Init File |
6746 | ---------------------- | |
ccc6cda3 | 6747 | |
37c41ab1 CR |
6748 | Here is an example of an INPUTRC file. This illustrates key binding, |
6749 | variable assignment, and conditional syntax. | |
ccc6cda3 JA |
6750 | |
6751 | ||
6752 | # This file controls the behaviour of line input editing for | |
7117c2d2 JA |
6753 | # programs that use the GNU Readline library. Existing |
6754 | # programs include FTP, Bash, and GDB. | |
ccc6cda3 JA |
6755 | # |
6756 | # You can re-read the inputrc file with C-x C-r. | |
6757 | # Lines beginning with '#' are comments. | |
cce855bc | 6758 | # |
7117c2d2 JA |
6759 | # First, include any systemwide bindings and variable |
6760 | # assignments from /etc/Inputrc | |
cce855bc | 6761 | $include /etc/Inputrc |
37c41ab1 | 6762 | |
ccc6cda3 JA |
6763 | # |
6764 | # Set various bindings for emacs mode. | |
37c41ab1 | 6765 | |
ccc6cda3 | 6766 | set editing-mode emacs |
37c41ab1 | 6767 | |
ccc6cda3 | 6768 | $if mode=emacs |
37c41ab1 | 6769 | |
ccc6cda3 | 6770 | Meta-Control-h: backward-kill-word Text after the function name is ignored |
37c41ab1 | 6771 | |
ccc6cda3 JA |
6772 | # |
6773 | # Arrow keys in keypad mode | |
6774 | # | |
d166f048 JA |
6775 | #"\M-OD": backward-char |
6776 | #"\M-OC": forward-char | |
6777 | #"\M-OA": previous-history | |
6778 | #"\M-OB": next-history | |
ccc6cda3 JA |
6779 | # |
6780 | # Arrow keys in ANSI mode | |
6781 | # | |
d166f048 JA |
6782 | "\M-[D": backward-char |
6783 | "\M-[C": forward-char | |
6784 | "\M-[A": previous-history | |
6785 | "\M-[B": next-history | |
ccc6cda3 JA |
6786 | # |
6787 | # Arrow keys in 8 bit keypad mode | |
6788 | # | |
d166f048 JA |
6789 | #"\M-\C-OD": backward-char |
6790 | #"\M-\C-OC": forward-char | |
6791 | #"\M-\C-OA": previous-history | |
6792 | #"\M-\C-OB": next-history | |
ccc6cda3 JA |
6793 | # |
6794 | # Arrow keys in 8 bit ANSI mode | |
6795 | # | |
d166f048 JA |
6796 | #"\M-\C-[D": backward-char |
6797 | #"\M-\C-[C": forward-char | |
6798 | #"\M-\C-[A": previous-history | |
6799 | #"\M-\C-[B": next-history | |
37c41ab1 | 6800 | |
ccc6cda3 | 6801 | C-q: quoted-insert |
37c41ab1 | 6802 | |
ccc6cda3 | 6803 | $endif |
37c41ab1 | 6804 | |
ccc6cda3 JA |
6805 | # An old-style binding. This happens to be the default. |
6806 | TAB: complete | |
37c41ab1 | 6807 | |
ccc6cda3 JA |
6808 | # Macros that are convenient for shell interaction |
6809 | $if Bash | |
6810 | # edit the path | |
6811 | "\C-xp": "PATH=${PATH}\e\C-e\C-a\ef\C-f" | |
7117c2d2 JA |
6812 | # prepare to type a quoted word -- |
6813 | # insert open and close double quotes | |
ccc6cda3 JA |
6814 | # and move to just after the open quote |
6815 | "\C-x\"": "\"\"\C-b" | |
7117c2d2 JA |
6816 | # insert a backslash (testing backslash escapes |
6817 | # in sequences and macros) | |
ccc6cda3 JA |
6818 | "\C-x\\": "\\" |
6819 | # Quote the current or previous word | |
6820 | "\C-xq": "\eb\"\ef\"" | |
6821 | # Add a binding to refresh the line, which is unbound | |
6822 | "\C-xr": redraw-current-line | |
6823 | # Edit variable on current line. | |
6824 | "\M-\C-v": "\C-a\C-k$\C-y\M-\C-e\C-a\C-y=" | |
6825 | $endif | |
37c41ab1 | 6826 | |
ccc6cda3 JA |
6827 | # use a visible bell if one is available |
6828 | set bell-style visible | |
37c41ab1 | 6829 | |
ccc6cda3 JA |
6830 | # don't strip characters to 7 bits when reading |
6831 | set input-meta on | |
37c41ab1 | 6832 | |
7117c2d2 JA |
6833 | # allow iso-latin1 characters to be inserted rather |
6834 | # than converted to prefix-meta sequences | |
ccc6cda3 | 6835 | set convert-meta off |
37c41ab1 | 6836 | |
7117c2d2 JA |
6837 | # display characters with the eighth bit set directly |
6838 | # rather than as meta-prefixed characters | |
ccc6cda3 | 6839 | set output-meta on |
37c41ab1 | 6840 | |
7117c2d2 JA |
6841 | # if there are more than 150 possible completions for |
6842 | # a word, ask the user if he wants to see all of them | |
ccc6cda3 | 6843 | set completion-query-items 150 |
37c41ab1 | 6844 | |
ccc6cda3 JA |
6845 | # For FTP |
6846 | $if Ftp | |
6847 | "\C-xg": "get \M-?" | |
6848 | "\C-xt": "put \M-?" | |
6849 | "\M-.": yank-last-arg | |
6850 | $endif | |
6851 | ||
6852 | \1f | |
bb70624e JA |
6853 | File: bashref.info, Node: Bindable Readline Commands, Next: Readline vi Mode, Prev: Readline Init File, Up: Command Line Editing |
6854 | ||
37c41ab1 CR |
6855 | 8.4 Bindable Readline Commands |
6856 | ============================== | |
bb70624e JA |
6857 | |
6858 | * Menu: | |
6859 | ||
6860 | * Commands For Moving:: Moving about the line. | |
6861 | * Commands For History:: Getting at previous lines. | |
6862 | * Commands For Text:: Commands for changing text. | |
6863 | * Commands For Killing:: Commands for killing and yanking. | |
6864 | * Numeric Arguments:: Specifying numeric arguments, repeat counts. | |
6865 | * Commands For Completion:: Getting Readline to do the typing for you. | |
6866 | * Keyboard Macros:: Saving and re-executing typed characters | |
6867 | * Miscellaneous Commands:: Other miscellaneous commands. | |
6868 | ||
6869 | This section describes Readline commands that may be bound to key | |
6870 | sequences. You can list your key bindings by executing `bind -P' or, | |
6871 | for a more terse format, suitable for an INPUTRC file, `bind -p'. | |
28ef6c31 JA |
6872 | (*Note Bash Builtins::.) Command names without an accompanying key |
6873 | sequence are unbound by default. | |
bb70624e | 6874 | |
28ef6c31 JA |
6875 | In the following descriptions, "point" refers to the current cursor |
6876 | position, and "mark" refers to a cursor position saved by the | |
bb70624e | 6877 | `set-mark' command. The text between the point and mark is referred to |
28ef6c31 | 6878 | as the "region". |
bb70624e JA |
6879 | |
6880 | \1f | |
6881 | File: bashref.info, Node: Commands For Moving, Next: Commands For History, Up: Bindable Readline Commands | |
6882 | ||
37c41ab1 CR |
6883 | 8.4.1 Commands For Moving |
6884 | ------------------------- | |
bb70624e JA |
6885 | |
6886 | `beginning-of-line (C-a)' | |
6887 | Move to the start of the current line. | |
6888 | ||
6889 | `end-of-line (C-e)' | |
6890 | Move to the end of the line. | |
6891 | ||
6892 | `forward-char (C-f)' | |
6893 | Move forward a character. | |
6894 | ||
6895 | `backward-char (C-b)' | |
6896 | Move back a character. | |
6897 | ||
6898 | `forward-word (M-f)' | |
6899 | Move forward to the end of the next word. Words are composed of | |
6900 | letters and digits. | |
6901 | ||
6902 | `backward-word (M-b)' | |
6903 | Move back to the start of the current or previous word. Words are | |
6904 | composed of letters and digits. | |
6905 | ||
a9fac3b2 CR |
6906 | `shell-forward-word ()' |
6907 | Move forward to the end of the next word. Words are delimited by | |
6908 | non-quoted shell metacharacters. | |
6909 | ||
6910 | `shell-backward-word ()' | |
6911 | Move back to the start of the current or previous word. Words are | |
6912 | delimited by non-quoted shell metacharacters. | |
6913 | ||
bb70624e JA |
6914 | `clear-screen (C-l)' |
6915 | Clear the screen and redraw the current line, leaving the current | |
6916 | line at the top of the screen. | |
6917 | ||
6918 | `redraw-current-line ()' | |
6919 | Refresh the current line. By default, this is unbound. | |
6920 | ||
761783bf | 6921 | |
bb70624e JA |
6922 | \1f |
6923 | File: bashref.info, Node: Commands For History, Next: Commands For Text, Prev: Commands For Moving, Up: Bindable Readline Commands | |
6924 | ||
37c41ab1 CR |
6925 | 8.4.2 Commands For Manipulating The History |
6926 | ------------------------------------------- | |
bb70624e | 6927 | |
28ef6c31 | 6928 | `accept-line (Newline or Return)' |
bb70624e JA |
6929 | Accept the line regardless of where the cursor is. If this line is |
6930 | non-empty, add it to the history list according to the setting of | |
28ef6c31 JA |
6931 | the `HISTCONTROL' and `HISTIGNORE' variables. If this line is a |
6932 | modified history line, then restore the history line to its | |
6933 | original state. | |
bb70624e JA |
6934 | |
6935 | `previous-history (C-p)' | |
28ef6c31 JA |
6936 | Move `back' through the history list, fetching the previous |
6937 | command. | |
bb70624e JA |
6938 | |
6939 | `next-history (C-n)' | |
28ef6c31 | 6940 | Move `forward' through the history list, fetching the next command. |
bb70624e JA |
6941 | |
6942 | `beginning-of-history (M-<)' | |
6943 | Move to the first line in the history. | |
6944 | ||
6945 | `end-of-history (M->)' | |
6946 | Move to the end of the input history, i.e., the line currently | |
6947 | being entered. | |
6948 | ||
6949 | `reverse-search-history (C-r)' | |
6950 | Search backward starting at the current line and moving `up' | |
6951 | through the history as necessary. This is an incremental search. | |
6952 | ||
6953 | `forward-search-history (C-s)' | |
6954 | Search forward starting at the current line and moving `down' | |
6955 | through the the history as necessary. This is an incremental | |
6956 | search. | |
6957 | ||
6958 | `non-incremental-reverse-search-history (M-p)' | |
6959 | Search backward starting at the current line and moving `up' | |
6960 | through the history as necessary using a non-incremental search | |
6961 | for a string supplied by the user. | |
6962 | ||
6963 | `non-incremental-forward-search-history (M-n)' | |
6964 | Search forward starting at the current line and moving `down' | |
6965 | through the the history as necessary using a non-incremental search | |
6966 | for a string supplied by the user. | |
6967 | ||
6968 | `history-search-forward ()' | |
6969 | Search forward through the history for the string of characters | |
6970 | between the start of the current line and the point. This is a | |
6971 | non-incremental search. By default, this command is unbound. | |
6972 | ||
6973 | `history-search-backward ()' | |
6974 | Search backward through the history for the string of characters | |
6975 | between the start of the current line and the point. This is a | |
6976 | non-incremental search. By default, this command is unbound. | |
6977 | ||
6978 | `yank-nth-arg (M-C-y)' | |
6979 | Insert the first argument to the previous command (usually the | |
28ef6c31 JA |
6980 | second word on the previous line) at point. With an argument N, |
6981 | insert the Nth word from the previous command (the words in the | |
6982 | previous command begin with word 0). A negative argument inserts | |
eb2bb562 CR |
6983 | the Nth word from the end of the previous command. Once the |
6984 | argument N is computed, the argument is extracted as if the `!N' | |
6985 | history expansion had been specified. | |
bb70624e | 6986 | |
28ef6c31 | 6987 | `yank-last-arg (M-. or M-_)' |
bb70624e JA |
6988 | Insert last argument to the previous command (the last word of the |
6989 | previous history entry). With an argument, behave exactly like | |
6990 | `yank-nth-arg'. Successive calls to `yank-last-arg' move back | |
6991 | through the history list, inserting the last argument of each line | |
eb2bb562 CR |
6992 | in turn. The history expansion facilities are used to extract the |
6993 | last argument, as if the `!$' history expansion had been specified. | |
bb70624e | 6994 | |
761783bf | 6995 | |
bb70624e JA |
6996 | \1f |
6997 | File: bashref.info, Node: Commands For Text, Next: Commands For Killing, Prev: Commands For History, Up: Bindable Readline Commands | |
6998 | ||
37c41ab1 CR |
6999 | 8.4.3 Commands For Changing Text |
7000 | -------------------------------- | |
bb70624e JA |
7001 | |
7002 | `delete-char (C-d)' | |
28ef6c31 JA |
7003 | Delete the character at point. If point is at the beginning of |
7004 | the line, there are no characters in the line, and the last | |
7005 | character typed was not bound to `delete-char', then return EOF. | |
bb70624e JA |
7006 | |
7007 | `backward-delete-char (Rubout)' | |
7008 | Delete the character behind the cursor. A numeric argument means | |
7009 | to kill the characters instead of deleting them. | |
7010 | ||
7011 | `forward-backward-delete-char ()' | |
7012 | Delete the character under the cursor, unless the cursor is at the | |
7013 | end of the line, in which case the character behind the cursor is | |
7014 | deleted. By default, this is not bound to a key. | |
7015 | ||
28ef6c31 | 7016 | `quoted-insert (C-q or C-v)' |
bb70624e | 7017 | Add the next character typed to the line verbatim. This is how to |
28ef6c31 | 7018 | insert key sequences like `C-q', for example. |
bb70624e JA |
7019 | |
7020 | `self-insert (a, b, A, 1, !, ...)' | |
7021 | Insert yourself. | |
7022 | ||
7023 | `transpose-chars (C-t)' | |
7024 | Drag the character before the cursor forward over the character at | |
7025 | the cursor, moving the cursor forward as well. If the insertion | |
7026 | point is at the end of the line, then this transposes the last two | |
7027 | characters of the line. Negative arguments have no effect. | |
7028 | ||
7029 | `transpose-words (M-t)' | |
7030 | Drag the word before point past the word after point, moving point | |
f73dda09 JA |
7031 | past that word as well. If the insertion point is at the end of |
7032 | the line, this transposes the last two words on the line. | |
bb70624e JA |
7033 | |
7034 | `upcase-word (M-u)' | |
7035 | Uppercase the current (or following) word. With a negative | |
7036 | argument, uppercase the previous word, but do not move the cursor. | |
7037 | ||
7038 | `downcase-word (M-l)' | |
7039 | Lowercase the current (or following) word. With a negative | |
7040 | argument, lowercase the previous word, but do not move the cursor. | |
7041 | ||
7042 | `capitalize-word (M-c)' | |
7043 | Capitalize the current (or following) word. With a negative | |
7044 | argument, capitalize the previous word, but do not move the cursor. | |
7045 | ||
7117c2d2 JA |
7046 | `overwrite-mode ()' |
7047 | Toggle overwrite mode. With an explicit positive numeric argument, | |
7048 | switches to overwrite mode. With an explicit non-positive numeric | |
7049 | argument, switches to insert mode. This command affects only | |
7050 | `emacs' mode; `vi' mode does overwrite differently. Each call to | |
7051 | `readline()' starts in insert mode. | |
7052 | ||
7053 | In overwrite mode, characters bound to `self-insert' replace the | |
7054 | text at point rather than pushing the text to the right. | |
7055 | Characters bound to `backward-delete-char' replace the character | |
7056 | before point with a space. | |
7057 | ||
7058 | By default, this command is unbound. | |
7059 | ||
761783bf | 7060 | |
bb70624e JA |
7061 | \1f |
7062 | File: bashref.info, Node: Commands For Killing, Next: Numeric Arguments, Prev: Commands For Text, Up: Bindable Readline Commands | |
7063 | ||
37c41ab1 CR |
7064 | 8.4.4 Killing And Yanking |
7065 | ------------------------- | |
bb70624e JA |
7066 | |
7067 | `kill-line (C-k)' | |
7068 | Kill the text from point to the end of the line. | |
7069 | ||
7070 | `backward-kill-line (C-x Rubout)' | |
7071 | Kill backward to the beginning of the line. | |
7072 | ||
7073 | `unix-line-discard (C-u)' | |
7074 | Kill backward from the cursor to the beginning of the current line. | |
7075 | ||
7076 | `kill-whole-line ()' | |
28ef6c31 JA |
7077 | Kill all characters on the current line, no matter where point is. |
7078 | By default, this is unbound. | |
bb70624e JA |
7079 | |
7080 | `kill-word (M-d)' | |
7081 | Kill from point to the end of the current word, or if between | |
7082 | words, to the end of the next word. Word boundaries are the same | |
7083 | as `forward-word'. | |
7084 | ||
28ef6c31 | 7085 | `backward-kill-word (M-<DEL>)' |
bb70624e JA |
7086 | Kill the word behind point. Word boundaries are the same as |
7087 | `backward-word'. | |
7088 | ||
a9fac3b2 CR |
7089 | `shell-kill-word ()' |
7090 | Kill from point to the end of the current word, or if between | |
7091 | words, to the end of the next word. Word boundaries are the same | |
7092 | as `shell-forward-word'. | |
7093 | ||
7094 | `backward-kill-word ()' | |
7095 | Kill the word behind point. Word boundaries are the same as | |
7096 | `shell-backward-word'. | |
7097 | ||
bb70624e JA |
7098 | `unix-word-rubout (C-w)' |
7099 | Kill the word behind point, using white space as a word boundary. | |
7100 | The killed text is saved on the kill-ring. | |
7101 | ||
113d85a4 CR |
7102 | `unix-filename-rubout ()' |
7103 | Kill the word behind point, using white space and the slash | |
7104 | character as the word boundaries. The killed text is saved on the | |
7105 | kill-ring. | |
7106 | ||
bb70624e JA |
7107 | `delete-horizontal-space ()' |
7108 | Delete all spaces and tabs around point. By default, this is | |
7109 | unbound. | |
7110 | ||
7111 | `kill-region ()' | |
7112 | Kill the text in the current region. By default, this command is | |
7113 | unbound. | |
7114 | ||
7115 | `copy-region-as-kill ()' | |
7116 | Copy the text in the region to the kill buffer, so it can be yanked | |
7117 | right away. By default, this command is unbound. | |
7118 | ||
7119 | `copy-backward-word ()' | |
7120 | Copy the word before point to the kill buffer. The word | |
7121 | boundaries are the same as `backward-word'. By default, this | |
7122 | command is unbound. | |
7123 | ||
7124 | `copy-forward-word ()' | |
7125 | Copy the word following point to the kill buffer. The word | |
7126 | boundaries are the same as `forward-word'. By default, this | |
7127 | command is unbound. | |
7128 | ||
7129 | `yank (C-y)' | |
28ef6c31 | 7130 | Yank the top of the kill ring into the buffer at point. |
bb70624e JA |
7131 | |
7132 | `yank-pop (M-y)' | |
7133 | Rotate the kill-ring, and yank the new top. You can only do this | |
28ef6c31 | 7134 | if the prior command is `yank' or `yank-pop'. |
bb70624e JA |
7135 | |
7136 | \1f | |
7137 | File: bashref.info, Node: Numeric Arguments, Next: Commands For Completion, Prev: Commands For Killing, Up: Bindable Readline Commands | |
7138 | ||
37c41ab1 CR |
7139 | 8.4.5 Specifying Numeric Arguments |
7140 | ---------------------------------- | |
bb70624e JA |
7141 | |
7142 | `digit-argument (M-0, M-1, ... M--)' | |
7143 | Add this digit to the argument already accumulating, or start a new | |
28ef6c31 | 7144 | argument. `M--' starts a negative argument. |
bb70624e JA |
7145 | |
7146 | `universal-argument ()' | |
7147 | This is another way to specify an argument. If this command is | |
7148 | followed by one or more digits, optionally with a leading minus | |
7149 | sign, those digits define the argument. If the command is | |
7150 | followed by digits, executing `universal-argument' again ends the | |
7151 | numeric argument, but is otherwise ignored. As a special case, if | |
7152 | this command is immediately followed by a character that is | |
7153 | neither a digit or minus sign, the argument count for the next | |
7154 | command is multiplied by four. The argument count is initially | |
7155 | one, so executing this function the first time makes the argument | |
7156 | count four, a second time makes the argument count sixteen, and so | |
7157 | on. By default, this is not bound to a key. | |
7158 | ||
7159 | \1f | |
7160 | File: bashref.info, Node: Commands For Completion, Next: Keyboard Macros, Prev: Numeric Arguments, Up: Bindable Readline Commands | |
7161 | ||
37c41ab1 CR |
7162 | 8.4.6 Letting Readline Type For You |
7163 | ----------------------------------- | |
bb70624e | 7164 | |
28ef6c31 JA |
7165 | `complete (<TAB>)' |
7166 | Attempt to perform completion on the text before point. The | |
7167 | actual completion performed is application-specific. Bash | |
7168 | attempts completion treating the text as a variable (if the text | |
7169 | begins with `$'), username (if the text begins with `~'), hostname | |
7170 | (if the text begins with `@'), or command (including aliases and | |
7171 | functions) in turn. If none of these produces a match, filename | |
7172 | completion is attempted. | |
bb70624e JA |
7173 | |
7174 | `possible-completions (M-?)' | |
28ef6c31 | 7175 | List the possible completions of the text before point. |
bb70624e JA |
7176 | |
7177 | `insert-completions (M-*)' | |
7178 | Insert all completions of the text before point that would have | |
7179 | been generated by `possible-completions'. | |
7180 | ||
7181 | `menu-complete ()' | |
7182 | Similar to `complete', but replaces the word to be completed with | |
7183 | a single match from the list of possible completions. Repeated | |
7184 | execution of `menu-complete' steps through the list of possible | |
7185 | completions, inserting each match in turn. At the end of the list | |
28ef6c31 JA |
7186 | of completions, the bell is rung (subject to the setting of |
7187 | `bell-style') and the original text is restored. An argument of N | |
7188 | moves N positions forward in the list of matches; a negative | |
7189 | argument may be used to move backward through the list. This | |
7190 | command is intended to be bound to <TAB>, but is unbound by | |
bb70624e JA |
7191 | default. |
7192 | ||
7193 | `delete-char-or-list ()' | |
7194 | Deletes the character under the cursor if not at the beginning or | |
7195 | end of the line (like `delete-char'). If at the end of the line, | |
7196 | behaves identically to `possible-completions'. This command is | |
7197 | unbound by default. | |
7198 | ||
7199 | `complete-filename (M-/)' | |
7200 | Attempt filename completion on the text before point. | |
7201 | ||
7202 | `possible-filename-completions (C-x /)' | |
7203 | List the possible completions of the text before point, treating | |
7204 | it as a filename. | |
7205 | ||
7206 | `complete-username (M-~)' | |
7207 | Attempt completion on the text before point, treating it as a | |
7208 | username. | |
7209 | ||
7210 | `possible-username-completions (C-x ~)' | |
7211 | List the possible completions of the text before point, treating | |
7212 | it as a username. | |
7213 | ||
7214 | `complete-variable (M-$)' | |
7215 | Attempt completion on the text before point, treating it as a | |
7216 | shell variable. | |
7217 | ||
7218 | `possible-variable-completions (C-x $)' | |
7219 | List the possible completions of the text before point, treating | |
7220 | it as a shell variable. | |
7221 | ||
7222 | `complete-hostname (M-@)' | |
7223 | Attempt completion on the text before point, treating it as a | |
7224 | hostname. | |
7225 | ||
7226 | `possible-hostname-completions (C-x @)' | |
7227 | List the possible completions of the text before point, treating | |
7228 | it as a hostname. | |
7229 | ||
7230 | `complete-command (M-!)' | |
7231 | Attempt completion on the text before point, treating it as a | |
7232 | command name. Command completion attempts to match the text | |
7233 | against aliases, reserved words, shell functions, shell builtins, | |
7234 | and finally executable filenames, in that order. | |
7235 | ||
7236 | `possible-command-completions (C-x !)' | |
7237 | List the possible completions of the text before point, treating | |
7238 | it as a command name. | |
7239 | ||
28ef6c31 | 7240 | `dynamic-complete-history (M-<TAB>)' |
bb70624e JA |
7241 | Attempt completion on the text before point, comparing the text |
7242 | against lines from the history list for possible completion | |
7243 | matches. | |
7244 | ||
ed35cb4a CR |
7245 | `dabbrev-expand ()' |
7246 | Attempt menu completion on the text before point, comparing the | |
7247 | text against lines from the history list for possible completion | |
7248 | matches. | |
7249 | ||
bb70624e JA |
7250 | `complete-into-braces (M-{)' |
7251 | Perform filename completion and insert the list of possible | |
7252 | completions enclosed within braces so the list is available to the | |
28ef6c31 | 7253 | shell (*note Brace Expansion::). |
bb70624e | 7254 | |
761783bf | 7255 | |
bb70624e JA |
7256 | \1f |
7257 | File: bashref.info, Node: Keyboard Macros, Next: Miscellaneous Commands, Prev: Commands For Completion, Up: Bindable Readline Commands | |
7258 | ||
37c41ab1 CR |
7259 | 8.4.7 Keyboard Macros |
7260 | --------------------- | |
bb70624e JA |
7261 | |
7262 | `start-kbd-macro (C-x ()' | |
7263 | Begin saving the characters typed into the current keyboard macro. | |
7264 | ||
7265 | `end-kbd-macro (C-x ))' | |
7266 | Stop saving the characters typed into the current keyboard macro | |
7267 | and save the definition. | |
7268 | ||
7269 | `call-last-kbd-macro (C-x e)' | |
7270 | Re-execute the last keyboard macro defined, by making the | |
7271 | characters in the macro appear as if typed at the keyboard. | |
7272 | ||
761783bf | 7273 | |
bb70624e JA |
7274 | \1f |
7275 | File: bashref.info, Node: Miscellaneous Commands, Prev: Keyboard Macros, Up: Bindable Readline Commands | |
7276 | ||
37c41ab1 CR |
7277 | 8.4.8 Some Miscellaneous Commands |
7278 | --------------------------------- | |
bb70624e JA |
7279 | |
7280 | `re-read-init-file (C-x C-r)' | |
7281 | Read in the contents of the INPUTRC file, and incorporate any | |
7282 | bindings or variable assignments found there. | |
7283 | ||
7284 | `abort (C-g)' | |
7285 | Abort the current editing command and ring the terminal's bell | |
7286 | (subject to the setting of `bell-style'). | |
7287 | ||
7288 | `do-uppercase-version (M-a, M-b, M-X, ...)' | |
7289 | If the metafied character X is lowercase, run the command that is | |
7290 | bound to the corresponding uppercase character. | |
7291 | ||
28ef6c31 JA |
7292 | `prefix-meta (<ESC>)' |
7293 | Metafy the next character typed. This is for keyboards without a | |
7294 | meta key. Typing `<ESC> f' is equivalent to typing `M-f'. | |
bb70624e | 7295 | |
28ef6c31 | 7296 | `undo (C-_ or C-x C-u)' |
bb70624e JA |
7297 | Incremental undo, separately remembered for each line. |
7298 | ||
7299 | `revert-line (M-r)' | |
7300 | Undo all changes made to this line. This is like executing the | |
7301 | `undo' command enough times to get back to the beginning. | |
7302 | ||
7303 | `tilde-expand (M-&)' | |
7304 | Perform tilde expansion on the current word. | |
7305 | ||
7306 | `set-mark (C-@)' | |
28ef6c31 JA |
7307 | Set the mark to the point. If a numeric argument is supplied, the |
7308 | mark is set to that position. | |
bb70624e JA |
7309 | |
7310 | `exchange-point-and-mark (C-x C-x)' | |
7311 | Swap the point with the mark. The current cursor position is set | |
7312 | to the saved position, and the old cursor position is saved as the | |
7313 | mark. | |
7314 | ||
7315 | `character-search (C-])' | |
7316 | A character is read and point is moved to the next occurrence of | |
7317 | that character. A negative count searches for previous | |
7318 | occurrences. | |
7319 | ||
7320 | `character-search-backward (M-C-])' | |
7321 | A character is read and point is moved to the previous occurrence | |
7322 | of that character. A negative count searches for subsequent | |
7323 | occurrences. | |
7324 | ||
7325 | `insert-comment (M-#)' | |
7117c2d2 JA |
7326 | Without a numeric argument, the value of the `comment-begin' |
7327 | variable is inserted at the beginning of the current line. If a | |
7328 | numeric argument is supplied, this command acts as a toggle: if | |
7329 | the characters at the beginning of the line do not match the value | |
7330 | of `comment-begin', the value is inserted, otherwise the | |
7331 | characters in `comment-begin' are deleted from the beginning of | |
7332 | the line. In either case, the line is accepted as if a newline | |
7333 | had been typed. The default value of `comment-begin' causes this | |
7334 | command to make the current line a shell comment. If a numeric | |
7335 | argument causes the comment character to be removed, the line will | |
7336 | be executed by the shell. | |
bb70624e JA |
7337 | |
7338 | `dump-functions ()' | |
7339 | Print all of the functions and their key bindings to the Readline | |
7340 | output stream. If a numeric argument is supplied, the output is | |
7341 | formatted in such a way that it can be made part of an INPUTRC | |
7342 | file. This command is unbound by default. | |
7343 | ||
7344 | `dump-variables ()' | |
7345 | Print all of the settable variables and their values to the | |
7346 | Readline output stream. If a numeric argument is supplied, the | |
7347 | output is formatted in such a way that it can be made part of an | |
7348 | INPUTRC file. This command is unbound by default. | |
7349 | ||
7350 | `dump-macros ()' | |
7351 | Print all of the Readline key sequences bound to macros and the | |
28ef6c31 JA |
7352 | strings they output. If a numeric argument is supplied, the |
7353 | output is formatted in such a way that it can be made part of an | |
7354 | INPUTRC file. This command is unbound by default. | |
bb70624e | 7355 | |
7117c2d2 JA |
7356 | `glob-complete-word (M-g)' |
7357 | The word before point is treated as a pattern for pathname | |
7358 | expansion, with an asterisk implicitly appended. This pattern is | |
7359 | used to generate a list of matching file names for possible | |
7360 | completions. | |
7361 | ||
bb70624e JA |
7362 | `glob-expand-word (C-x *)' |
7363 | The word before point is treated as a pattern for pathname | |
7364 | expansion, and the list of matching file names is inserted, | |
7117c2d2 JA |
7365 | replacing the word. If a numeric argument is supplied, a `*' is |
7366 | appended before pathname expansion. | |
bb70624e JA |
7367 | |
7368 | `glob-list-expansions (C-x g)' | |
7369 | The list of expansions that would have been generated by | |
7117c2d2 JA |
7370 | `glob-expand-word' is displayed, and the line is redrawn. If a |
7371 | numeric argument is supplied, a `*' is appended before pathname | |
7372 | expansion. | |
bb70624e JA |
7373 | |
7374 | `display-shell-version (C-x C-v)' | |
7375 | Display version information about the current instance of Bash. | |
7376 | ||
7377 | `shell-expand-line (M-C-e)' | |
7378 | Expand the line as the shell does. This performs alias and | |
7379 | history expansion as well as all of the shell word expansions | |
28ef6c31 | 7380 | (*note Shell Expansions::). |
bb70624e JA |
7381 | |
7382 | `history-expand-line (M-^)' | |
7383 | Perform history expansion on the current line. | |
7384 | ||
7385 | `magic-space ()' | |
7386 | Perform history expansion on the current line and insert a space | |
28ef6c31 | 7387 | (*note History Interaction::). |
bb70624e JA |
7388 | |
7389 | `alias-expand-line ()' | |
28ef6c31 | 7390 | Perform alias expansion on the current line (*note Aliases::). |
bb70624e JA |
7391 | |
7392 | `history-and-alias-expand-line ()' | |
7393 | Perform history and alias expansion on the current line. | |
7394 | ||
28ef6c31 | 7395 | `insert-last-argument (M-. or M-_)' |
bb70624e JA |
7396 | A synonym for `yank-last-arg'. |
7397 | ||
7398 | `operate-and-get-next (C-o)' | |
7399 | Accept the current line for execution and fetch the next line | |
7400 | relative to the current line from the history for editing. Any | |
7401 | argument is ignored. | |
7402 | ||
7117c2d2 JA |
7403 | `edit-and-execute-command (C-xC-e)' |
7404 | Invoke an editor on the current command line, and execute the | |
c2258e1c | 7405 | result as shell commands. Bash attempts to invoke `$VISUAL', |
7117c2d2 | 7406 | `$EDITOR', and `emacs' as the editor, in that order. |
bb70624e | 7407 | |
761783bf | 7408 | |
bb70624e JA |
7409 | \1f |
7410 | File: bashref.info, Node: Readline vi Mode, Next: Programmable Completion, Prev: Bindable Readline Commands, Up: Command Line Editing | |
7411 | ||
37c41ab1 CR |
7412 | 8.5 Readline vi Mode |
7413 | ==================== | |
bb70624e | 7414 | |
37c41ab1 | 7415 | While the Readline library does not have a full set of `vi' editing |
bb70624e JA |
7416 | functions, it does contain enough to allow simple editing of the line. |
7417 | The Readline `vi' mode behaves as specified in the POSIX 1003.2 | |
7418 | standard. | |
7419 | ||
7420 | In order to switch interactively between `emacs' and `vi' editing | |
7421 | modes, use the `set -o emacs' and `set -o vi' commands (*note The Set | |
28ef6c31 | 7422 | Builtin::). The Readline default is `emacs' mode. |
bb70624e JA |
7423 | |
7424 | When you enter a line in `vi' mode, you are already placed in | |
7425 | `insertion' mode, as if you had typed an `i'. Pressing <ESC> switches | |
7426 | you into `command' mode, where you can edit the text of the line with | |
7427 | the standard `vi' movement keys, move to previous history lines with | |
7428 | `k' and subsequent lines with `j', and so forth. | |
7429 | ||
7430 | \1f | |
7431 | File: bashref.info, Node: Programmable Completion, Next: Programmable Completion Builtins, Prev: Readline vi Mode, Up: Command Line Editing | |
7432 | ||
37c41ab1 CR |
7433 | 8.6 Programmable Completion |
7434 | =========================== | |
bb70624e | 7435 | |
37c41ab1 | 7436 | When word completion is attempted for an argument to a command for |
bb70624e | 7437 | which a completion specification (a COMPSPEC) has been defined using |
28ef6c31 | 7438 | the `complete' builtin (*note Programmable Completion Builtins::), the |
bb70624e JA |
7439 | programmable completion facilities are invoked. |
7440 | ||
7441 | First, the command name is identified. If a compspec has been | |
7442 | defined for that command, the compspec is used to generate the list of | |
7443 | possible completions for the word. If the command word is a full | |
7444 | pathname, a compspec for the full pathname is searched for first. If | |
7445 | no compspec is found for the full pathname, an attempt is made to find | |
7446 | a compspec for the portion following the final slash. | |
7447 | ||
7448 | Once a compspec has been found, it is used to generate the list of | |
7449 | matching words. If a compspec is not found, the default Bash completion | |
28ef6c31 | 7450 | described above (*note Commands For Completion::) is performed. |
bb70624e JA |
7451 | |
7452 | First, the actions specified by the compspec are used. Only matches | |
7453 | which are prefixed by the word being completed are returned. When the | |
7454 | `-f' or `-d' option is used for filename or directory name completion, | |
7455 | the shell variable `FIGNORE' is used to filter the matches. *Note Bash | |
7456 | Variables::, for a description of `FIGNORE'. | |
7457 | ||
7458 | Any completions specified by a filename expansion pattern to the | |
7459 | `-G' option are generated next. The words generated by the pattern | |
7460 | need not match the word being completed. The `GLOBIGNORE' shell | |
7461 | variable is not used to filter the matches, but the `FIGNORE' shell | |
7462 | variable is used. | |
7463 | ||
7464 | Next, the string specified as the argument to the `-W' option is | |
7465 | considered. The string is first split using the characters in the `IFS' | |
7466 | special variable as delimiters. Shell quoting is honored. Each word | |
7467 | is then expanded using brace expansion, tilde expansion, parameter and | |
2206f89a CR |
7468 | variable expansion, command substitution, and arithmetic expansion, as |
7469 | described above (*note Shell Expansions::). The results are split | |
7470 | using the rules described above (*note Word Splitting::). The results | |
7471 | of the expansion are prefix-matched against the word being completed, | |
7472 | and the matching words become the possible completions. | |
bb70624e JA |
7473 | |
7474 | After these matches have been generated, any shell function or | |
7475 | command specified with the `-F' and `-C' options is invoked. When the | |
d3ad40de CR |
7476 | command or function is invoked, the `COMP_LINE', `COMP_POINT', |
7477 | `COMP_KEY', and `COMP_TYPE' variables are assigned values as described | |
7478 | above (*note Bash Variables::). If a shell function is being invoked, | |
7479 | the `COMP_WORDS' and `COMP_CWORD' variables are also set. When the | |
7480 | function or command is invoked, the first argument is the name of the | |
7481 | command whose arguments are being completed, the second argument is the | |
7482 | word being completed, and the third argument is the word preceding the | |
7483 | word being completed on the current command line. No filtering of the | |
7484 | generated completions against the word being completed is performed; | |
7485 | the function or command has complete freedom in generating the matches. | |
bb70624e JA |
7486 | |
7487 | Any function specified with `-F' is invoked first. The function may | |
6a8fd0ed CR |
7488 | use any of the shell facilities, including the `compgen' and `compopt' |
7489 | builtins described below (*note Programmable Completion Builtins::), to | |
7490 | generate the matches. It must put the possible completions in the | |
7491 | `COMPREPLY' array variable. | |
bb70624e JA |
7492 | |
7493 | Next, any command specified with the `-C' option is invoked in an | |
7494 | environment equivalent to command substitution. It should print a list | |
7495 | of completions, one per line, to the standard output. Backslash may be | |
7496 | used to escape a newline, if necessary. | |
7497 | ||
7498 | After all of the possible completions are generated, any filter | |
7499 | specified with the `-X' option is applied to the list. The filter is a | |
7500 | pattern as used for pathname expansion; a `&' in the pattern is | |
7501 | replaced with the text of the word being completed. A literal `&' may | |
7502 | be escaped with a backslash; the backslash is removed before attempting | |
7503 | a match. Any completion that matches the pattern will be removed from | |
7504 | the list. A leading `!' negates the pattern; in this case any | |
7505 | completion not matching the pattern will be removed. | |
7506 | ||
7507 | Finally, any prefix and suffix specified with the `-P' and `-S' | |
7508 | options are added to each member of the completion list, and the result | |
7509 | is returned to the Readline completion code as the list of possible | |
7510 | completions. | |
7511 | ||
28ef6c31 JA |
7512 | If the previously-applied actions do not generate any matches, and |
7513 | the `-o dirnames' option was supplied to `complete' when the compspec | |
7514 | was defined, directory name completion is attempted. | |
7515 | ||
d3a24ed2 CR |
7516 | If the `-o plusdirs' option was supplied to `complete' when the |
7517 | compspec was defined, directory name completion is attempted and any | |
7518 | matches are added to the results of the other actions. | |
7519 | ||
28ef6c31 JA |
7520 | By default, if a compspec is found, whatever it generates is |
7521 | returned to the completion code as the full set of possible completions. | |
7522 | The default Bash completions are not attempted, and the Readline default | |
d3a24ed2 CR |
7523 | of filename completion is disabled. If the `-o bashdefault' option was |
7524 | supplied to `complete' when the compspec was defined, the default Bash | |
7525 | completions are attempted if the compspec generates no matches. If the | |
7526 | `-o default' option was supplied to `complete' when the compspec was | |
7527 | defined, Readline's default completion will be performed if the | |
7528 | compspec (and, if attempted, the default Bash completions) generate no | |
28ef6c31 | 7529 | matches. |
bb70624e | 7530 | |
7117c2d2 JA |
7531 | When a compspec indicates that directory name completion is desired, |
7532 | the programmable completion functions force Readline to append a slash | |
7533 | to completed names which are symbolic links to directories, subject to | |
7534 | the value of the MARK-DIRECTORIES Readline variable, regardless of the | |
7535 | setting of the MARK-SYMLINKED-DIRECTORIES Readline variable. | |
7536 | ||
bb70624e JA |
7537 | \1f |
7538 | File: bashref.info, Node: Programmable Completion Builtins, Prev: Programmable Completion, Up: Command Line Editing | |
7539 | ||
37c41ab1 CR |
7540 | 8.7 Programmable Completion Builtins |
7541 | ==================================== | |
bb70624e | 7542 | |
37c41ab1 | 7543 | Two builtin commands are available to manipulate the programmable |
bb70624e JA |
7544 | completion facilities. |
7545 | ||
7546 | `compgen' | |
7547 | `compgen [OPTION] [WORD]' | |
7548 | ||
7549 | Generate possible completion matches for WORD according to the | |
7550 | OPTIONs, which may be any option accepted by the `complete' | |
7551 | builtin with the exception of `-p' and `-r', and write the matches | |
7552 | to the standard output. When using the `-F' or `-C' options, the | |
7553 | various shell variables set by the programmable completion | |
7554 | facilities, while available, will not have useful values. | |
7555 | ||
7556 | The matches will be generated in the same way as if the | |
7557 | programmable completion code had generated them directly from a | |
7558 | completion specification with the same flags. If WORD is | |
7559 | specified, only those completions matching WORD will be displayed. | |
7560 | ||
7561 | The return value is true unless an invalid option is supplied, or | |
7562 | no matches were generated. | |
7563 | ||
7564 | `complete' | |
ed35cb4a | 7565 | `complete [-abcdefgjksuv] [-o COMP-OPTION] [-E] [-A ACTION] [-G GLOBPAT] [-W WORDLIST] |
d3ad40de CR |
7566 | [-F FUNCTION] [-C COMMAND] [-X FILTERPAT] |
7567 | [-P PREFIX] [-S SUFFIX] NAME [NAME ...]' | |
ed35cb4a | 7568 | `complete -pr [-E] [NAME ...]' |
bb70624e JA |
7569 | |
7570 | Specify how arguments to each NAME should be completed. If the | |
7571 | `-p' option is supplied, or if no options are supplied, existing | |
7572 | completion specifications are printed in a way that allows them to | |
7573 | be reused as input. The `-r' option removes a completion | |
7574 | specification for each NAME, or, if no NAMEs are supplied, all | |
ed35cb4a CR |
7575 | completion specifications. The `-E' option indicates that the |
7576 | remaining options and actions should apply to "empty" command | |
7577 | completion; that is, completion attempted on a blank line. | |
bb70624e JA |
7578 | |
7579 | The process of applying these completion specifications when word | |
7580 | completion is attempted is described above (*note Programmable | |
28ef6c31 | 7581 | Completion::). |
bb70624e JA |
7582 | |
7583 | Other options, if specified, have the following meanings. The | |
7584 | arguments to the `-G', `-W', and `-X' options (and, if necessary, | |
7585 | the `-P' and `-S' options) should be quoted to protect them from | |
7586 | expansion before the `complete' builtin is invoked. | |
7587 | ||
28ef6c31 JA |
7588 | `-o COMP-OPTION' |
7589 | The COMP-OPTION controls several aspects of the compspec's | |
7590 | behavior beyond the simple generation of completions. | |
7591 | COMP-OPTION may be one of: | |
7592 | ||
d3a24ed2 CR |
7593 | `bashdefault' |
7594 | Perform the rest of the default Bash completions if the | |
7595 | compspec generates no matches. | |
7596 | ||
28ef6c31 | 7597 | `default' |
7117c2d2 JA |
7598 | Use Readline's default filename completion if the |
7599 | compspec generates no matches. | |
28ef6c31 JA |
7600 | |
7601 | `dirnames' | |
7602 | Perform directory name completion if the compspec | |
7603 | generates no matches. | |
7604 | ||
7605 | `filenames' | |
7606 | Tell Readline that the compspec generates filenames, so | |
d3a24ed2 | 7607 | it can perform any filename-specific processing (like |
a9fac3b2 CR |
7608 | adding a slash to directory names quoting special |
7609 | characters, or suppressing trailing spaces). This | |
7610 | option is intended to be used with shell functions | |
7611 | specified with `-F'. | |
28ef6c31 | 7612 | |
7117c2d2 JA |
7613 | `nospace' |
7614 | Tell Readline not to append a space (the default) to | |
7615 | words completed at the end of the line. | |
7616 | ||
22e63b05 CR |
7617 | `plusdirs' |
7618 | After any matches defined by the compspec are generated, | |
7619 | directory name completion is attempted and any matches | |
7620 | are added to the results of the other actions. | |
7621 | ||
7622 | ||
bb70624e JA |
7623 | `-A ACTION' |
7624 | The ACTION may be one of the following to generate a list of | |
7625 | possible completions: | |
7626 | ||
7627 | `alias' | |
7628 | Alias names. May also be specified as `-a'. | |
7629 | ||
7630 | `arrayvar' | |
7631 | Array variable names. | |
7632 | ||
7633 | `binding' | |
7634 | Readline key binding names (*note Bindable Readline | |
28ef6c31 | 7635 | Commands::). |
bb70624e JA |
7636 | |
7637 | `builtin' | |
7638 | Names of shell builtin commands. May also be specified | |
7639 | as `-b'. | |
7640 | ||
7641 | `command' | |
7642 | Command names. May also be specified as `-c'. | |
7643 | ||
7644 | `directory' | |
7645 | Directory names. May also be specified as `-d'. | |
7646 | ||
7647 | `disabled' | |
7648 | Names of disabled shell builtins. | |
7649 | ||
7650 | `enabled' | |
7651 | Names of enabled shell builtins. | |
7652 | ||
7653 | `export' | |
7654 | Names of exported shell variables. May also be | |
7655 | specified as `-e'. | |
7656 | ||
7657 | `file' | |
7658 | File names. May also be specified as `-f'. | |
7659 | ||
7660 | `function' | |
7661 | Names of shell functions. | |
7662 | ||
f73dda09 JA |
7663 | `group' |
7664 | Group names. May also be specified as `-g'. | |
7665 | ||
bb70624e JA |
7666 | `helptopic' |
7667 | Help topics as accepted by the `help' builtin (*note | |
28ef6c31 | 7668 | Bash Builtins::). |
bb70624e JA |
7669 | |
7670 | `hostname' | |
7671 | Hostnames, as taken from the file specified by the | |
28ef6c31 | 7672 | `HOSTFILE' shell variable (*note Bash Variables::). |
bb70624e JA |
7673 | |
7674 | `job' | |
7675 | Job names, if job control is active. May also be | |
7676 | specified as `-j'. | |
7677 | ||
7678 | `keyword' | |
7679 | Shell reserved words. May also be specified as `-k'. | |
7680 | ||
7681 | `running' | |
7682 | Names of running jobs, if job control is active. | |
7683 | ||
7117c2d2 JA |
7684 | `service' |
7685 | Service names. May also be specified as `-s'. | |
7686 | ||
bb70624e JA |
7687 | `setopt' |
7688 | Valid arguments for the `-o' option to the `set' builtin | |
28ef6c31 | 7689 | (*note The Set Builtin::). |
bb70624e JA |
7690 | |
7691 | `shopt' | |
7692 | Shell option names as accepted by the `shopt' builtin | |
28ef6c31 | 7693 | (*note Bash Builtins::). |
bb70624e JA |
7694 | |
7695 | `signal' | |
7696 | Signal names. | |
7697 | ||
7698 | `stopped' | |
7699 | Names of stopped jobs, if job control is active. | |
7700 | ||
7701 | `user' | |
7702 | User names. May also be specified as `-u'. | |
7703 | ||
7704 | `variable' | |
7705 | Names of all shell variables. May also be specified as | |
7706 | `-v'. | |
7707 | ||
7708 | `-G GLOBPAT' | |
7709 | The filename expansion pattern GLOBPAT is expanded to generate | |
7710 | the possible completions. | |
7711 | ||
7712 | `-W WORDLIST' | |
7713 | The WORDLIST is split using the characters in the `IFS' | |
7714 | special variable as delimiters, and each resultant word is | |
7715 | expanded. The possible completions are the members of the | |
7716 | resultant list which match the word being completed. | |
7717 | ||
7718 | `-C COMMAND' | |
7719 | COMMAND is executed in a subshell environment, and its output | |
7720 | is used as the possible completions. | |
7721 | ||
7722 | `-F FUNCTION' | |
7723 | The shell function FUNCTION is executed in the current shell | |
7724 | environment. When it finishes, the possible completions are | |
7725 | retrieved from the value of the `COMPREPLY' array variable. | |
7726 | ||
7727 | `-X FILTERPAT' | |
7728 | FILTERPAT is a pattern as used for filename expansion. It is | |
7729 | applied to the list of possible completions generated by the | |
7730 | preceding options and arguments, and each completion matching | |
7731 | FILTERPAT is removed from the list. A leading `!' in | |
7732 | FILTERPAT negates the pattern; in this case, any completion | |
7733 | not matching FILTERPAT is removed. | |
7734 | ||
7735 | `-P PREFIX' | |
7736 | PREFIX is added at the beginning of each possible completion | |
7737 | after all other options have been applied. | |
7738 | ||
7739 | `-S SUFFIX' | |
7740 | SUFFIX is appended to each possible completion after all | |
7741 | other options have been applied. | |
7742 | ||
7743 | The return value is true unless an invalid option is supplied, an | |
7744 | option other than `-p' or `-r' is supplied without a NAME | |
7745 | argument, an attempt is made to remove a completion specification | |
7746 | for a NAME for which no specification exists, or an error occurs | |
7747 | adding a completion specification. | |
7748 | ||
6a8fd0ed CR |
7749 | `compopt' |
7750 | `compopt' [-o OPTION] [+o OPTION] [NAME] | |
7751 | Modify completion options for each NAME according to the OPTIONs, | |
7752 | or for the currently-execution completion if no NAMEs are supplied. | |
7753 | If no OPTIONs are given, display the completion options for each | |
7754 | NAME or the current completion. The possible values of OPTION are | |
7755 | those valid for the `complete' builtin described above. | |
7756 | ||
7757 | The return value is true unless an invalid option is supplied, an | |
7758 | attempt is made to modify the options for a NAME for which no | |
7759 | completion specification exists, or an output error occurs. | |
7760 | ||
7761 | ||
bb70624e | 7762 | \1f |
c2a47ea9 | 7763 | File: bashref.info, Node: Using History Interactively, Next: Installing Bash, Prev: Command Line Editing, Up: Top |
bb70624e | 7764 | |
37c41ab1 CR |
7765 | 9 Using History Interactively |
7766 | ***************************** | |
bb70624e | 7767 | |
37c41ab1 | 7768 | This chapter describes how to use the GNU History Library |
bb70624e JA |
7769 | interactively, from a user's standpoint. It should be considered a |
7770 | user's guide. For information on using the GNU History Library in | |
7771 | other programs, see the GNU Readline Library Manual. | |
7772 | ||
7773 | * Menu: | |
7774 | ||
7775 | * Bash History Facilities:: How Bash lets you manipulate your command | |
7776 | history. | |
7777 | * Bash History Builtins:: The Bash builtin commands that manipulate | |
7778 | the command history. | |
7779 | * History Interaction:: What it feels like using History as a user. | |
7780 | ||
7781 | \1f | |
7782 | File: bashref.info, Node: Bash History Facilities, Next: Bash History Builtins, Up: Using History Interactively | |
7783 | ||
37c41ab1 CR |
7784 | 9.1 Bash History Facilities |
7785 | =========================== | |
bb70624e | 7786 | |
37c41ab1 CR |
7787 | When the `-o history' option to the `set' builtin is enabled (*note The |
7788 | Set Builtin::), the shell provides access to the "command history", the | |
7789 | list of commands previously typed. The value of the `HISTSIZE' shell | |
7790 | variable is used as the number of commands to save in a history list. | |
7791 | The text of the last `$HISTSIZE' commands (default 500) is saved. The | |
7792 | shell stores each command in the history list prior to parameter and | |
7793 | variable expansion but after history expansion is performed, subject to | |
7794 | the values of the shell variables `HISTIGNORE' and `HISTCONTROL'. | |
bb70624e JA |
7795 | |
7796 | When the shell starts up, the history is initialized from the file | |
7797 | named by the `HISTFILE' variable (default `~/.bash_history'). The file | |
7798 | named by the value of `HISTFILE' is truncated, if necessary, to contain | |
7799 | no more than the number of lines specified by the value of the | |
7800 | `HISTFILESIZE' variable. When an interactive shell exits, the last | |
7801 | `$HISTSIZE' lines are copied from the history list to the file named by | |
7802 | `$HISTFILE'. If the `histappend' shell option is set (*note Bash | |
28ef6c31 | 7803 | Builtins::), the lines are appended to the history file, otherwise the |
bb70624e JA |
7804 | history file is overwritten. If `HISTFILE' is unset, or if the history |
7805 | file is unwritable, the history is not saved. After saving the | |
7806 | history, the history file is truncated to contain no more than | |
7807 | `$HISTFILESIZE' lines. If `HISTFILESIZE' is not set, no truncation is | |
7808 | performed. | |
7809 | ||
d3a24ed2 | 7810 | If the `HISTTIMEFORMAT' is set, the time stamp information |
d3ad40de CR |
7811 | associated with each history entry is written to the history file, |
7812 | marked with the history comment character. When the history file is | |
7813 | read, lines beginning with the history comment character followed | |
7814 | immediately by a digit are interpreted as timestamps for the previous | |
7815 | history line. | |
d3a24ed2 | 7816 | |
bb70624e JA |
7817 | The builtin command `fc' may be used to list or edit and re-execute |
7818 | a portion of the history list. The `history' builtin may be used to | |
7819 | display or modify the history list and manipulate the history file. | |
7820 | When using command-line editing, search commands are available in each | |
7821 | editing mode that provide access to the history list (*note Commands | |
28ef6c31 | 7822 | For History::). |
bb70624e JA |
7823 | |
7824 | The shell allows control over which commands are saved on the history | |
7825 | list. The `HISTCONTROL' and `HISTIGNORE' variables may be set to cause | |
7826 | the shell to save only a subset of the commands entered. The `cmdhist' | |
7827 | shell option, if enabled, causes the shell to attempt to save each line | |
7828 | of a multi-line command in the same history entry, adding semicolons | |
7829 | where necessary to preserve syntactic correctness. The `lithist' shell | |
7830 | option causes the shell to save the command with embedded newlines | |
7831 | instead of semicolons. The `shopt' builtin is used to set these | |
7832 | options. *Note Bash Builtins::, for a description of `shopt'. | |
7833 | ||
7834 | \1f | |
7835 | File: bashref.info, Node: Bash History Builtins, Next: History Interaction, Prev: Bash History Facilities, Up: Using History Interactively | |
7836 | ||
37c41ab1 CR |
7837 | 9.2 Bash History Builtins |
7838 | ========================= | |
bb70624e | 7839 | |
37c41ab1 | 7840 | Bash provides two builtin commands which manipulate the history list |
bb70624e JA |
7841 | and history file. |
7842 | ||
7843 | `fc' | |
d3ad40de | 7844 | `fc [-e ENAME] [-lnr] [FIRST] [LAST]' |
bb70624e JA |
7845 | `fc -s [PAT=REP] [COMMAND]' |
7846 | ||
7847 | Fix Command. In the first form, a range of commands from FIRST to | |
7848 | LAST is selected from the history list. Both FIRST and LAST may | |
7849 | be specified as a string (to locate the most recent command | |
7850 | beginning with that string) or as a number (an index into the | |
7851 | history list, where a negative number is used as an offset from the | |
7852 | current command number). If LAST is not specified it is set to | |
7853 | FIRST. If FIRST is not specified it is set to the previous | |
7854 | command for editing and -16 for listing. If the `-l' flag is | |
7855 | given, the commands are listed on standard output. The `-n' flag | |
7856 | suppresses the command numbers when listing. The `-r' flag | |
7857 | reverses the order of the listing. Otherwise, the editor given by | |
7858 | ENAME is invoked on a file containing those commands. If ENAME is | |
7859 | not given, the value of the following variable expansion is used: | |
7860 | `${FCEDIT:-${EDITOR:-vi}}'. This says to use the value of the | |
7861 | `FCEDIT' variable if set, or the value of the `EDITOR' variable if | |
7862 | that is set, or `vi' if neither is set. When editing is complete, | |
7863 | the edited commands are echoed and executed. | |
7864 | ||
7865 | In the second form, COMMAND is re-executed after each instance of | |
7866 | PAT in the selected command is replaced by REP. | |
7867 | ||
7868 | A useful alias to use with the `fc' command is `r='fc -s'', so | |
7869 | that typing `r cc' runs the last command beginning with `cc' and | |
28ef6c31 | 7870 | typing `r' re-executes the last command (*note Aliases::). |
bb70624e JA |
7871 | |
7872 | `history' | |
7873 | history [N] | |
7874 | history -c | |
7875 | history -d OFFSET | |
7876 | history [-anrw] [FILENAME] | |
7877 | history -ps ARG | |
7878 | ||
7879 | With no options, display the history list with line numbers. | |
28ef6c31 | 7880 | Lines prefixed with a `*' have been modified. An argument of N |
d3a24ed2 CR |
7881 | lists only the last N lines. If the shell variable |
7882 | `HISTTIMEFORMAT' is set and not null, it is used as a format | |
7883 | string for STRFTIME to display the time stamp associated with each | |
7884 | displayed history entry. No intervening blank is printed between | |
7885 | the formatted time stamp and the history line. | |
7886 | ||
7887 | Options, if supplied, have the following meanings: | |
bb70624e JA |
7888 | |
7889 | `-c' | |
7890 | Clear the history list. This may be combined with the other | |
7891 | options to replace the history list completely. | |
7892 | ||
7893 | `-d OFFSET' | |
7894 | Delete the history entry at position OFFSET. OFFSET should | |
7895 | be specified as it appears when the history is displayed. | |
7896 | ||
7897 | `-a' | |
7898 | Append the new history lines (history lines entered since the | |
7899 | beginning of the current Bash session) to the history file. | |
7900 | ||
7901 | `-n' | |
7902 | Append the history lines not already read from the history | |
7903 | file to the current history list. These are lines appended | |
7904 | to the history file since the beginning of the current Bash | |
7905 | session. | |
7906 | ||
7907 | `-r' | |
7908 | Read the current history file and append its contents to the | |
7909 | history list. | |
7910 | ||
7911 | `-w' | |
7912 | Write out the current history to the history file. | |
7913 | ||
7914 | `-p' | |
7915 | Perform history substitution on the ARGs and display the | |
7916 | result on the standard output, without storing the results in | |
7917 | the history list. | |
7918 | ||
7919 | `-s' | |
7920 | The ARGs are added to the end of the history list as a single | |
7921 | entry. | |
7922 | ||
761783bf | 7923 | |
bb70624e JA |
7924 | When any of the `-w', `-r', `-a', or `-n' options is used, if |
7925 | FILENAME is given, then it is used as the history file. If not, | |
7926 | then the value of the `HISTFILE' variable is used. | |
7927 | ||
761783bf | 7928 | |
bb70624e JA |
7929 | \1f |
7930 | File: bashref.info, Node: History Interaction, Prev: Bash History Builtins, Up: Using History Interactively | |
ccc6cda3 | 7931 | |
37c41ab1 CR |
7932 | 9.3 History Expansion |
7933 | ===================== | |
ccc6cda3 | 7934 | |
37c41ab1 CR |
7935 | The History library provides a history expansion feature that is similar |
7936 | to the history expansion provided by `csh'. This section describes the | |
7937 | syntax used to manipulate the history information. | |
ccc6cda3 | 7938 | |
bb70624e JA |
7939 | History expansions introduce words from the history list into the |
7940 | input stream, making it easy to repeat commands, insert the arguments | |
7941 | to a previous command into the current input line, or fix errors in | |
7942 | previous commands quickly. | |
ccc6cda3 | 7943 | |
bb70624e JA |
7944 | History expansion takes place in two parts. The first is to |
7945 | determine which line from the history list should be used during | |
7946 | substitution. The second is to select portions of that line for | |
7947 | inclusion into the current one. The line selected from the history is | |
7948 | called the "event", and the portions of that line that are acted upon | |
7949 | are called "words". Various "modifiers" are available to manipulate | |
7950 | the selected words. The line is broken into words in the same fashion | |
7951 | that Bash does, so that several words surrounded by quotes are | |
7952 | considered one word. History expansions are introduced by the | |
7953 | appearance of the history expansion character, which is `!' by default. | |
7954 | Only `\' and `'' may be used to escape the history expansion character. | |
7955 | ||
7956 | Several shell options settable with the `shopt' builtin (*note Bash | |
28ef6c31 | 7957 | Builtins::) may be used to tailor the behavior of history expansion. |
bb70624e JA |
7958 | If the `histverify' shell option is enabled, and Readline is being |
7959 | used, history substitutions are not immediately passed to the shell | |
7960 | parser. Instead, the expanded line is reloaded into the Readline | |
7961 | editing buffer for further modification. If Readline is being used, | |
7962 | and the `histreedit' shell option is enabled, a failed history | |
7963 | expansion will be reloaded into the Readline editing buffer for | |
7964 | correction. The `-p' option to the `history' builtin command may be | |
7965 | used to see what a history expansion will do before using it. The `-s' | |
7966 | option to the `history' builtin may be used to add commands to the end | |
7967 | of the history list without actually executing them, so that they are | |
7968 | available for subsequent recall. This is most useful in conjunction | |
7969 | with Readline. | |
7970 | ||
7971 | The shell allows control of the various characters used by the | |
d3ad40de CR |
7972 | history expansion mechanism with the `histchars' variable, as explained |
7973 | above (*note Bash Variables::). The shell uses the history comment | |
7974 | character to mark history timestamps when writing the history file. | |
bb70624e JA |
7975 | |
7976 | * Menu: | |
7977 | ||
7978 | * Event Designators:: How to specify which history line to use. | |
7979 | * Word Designators:: Specifying which words are of interest. | |
7980 | * Modifiers:: Modifying the results of substitution. | |
ccc6cda3 JA |
7981 | |
7982 | \1f | |
bb70624e | 7983 | File: bashref.info, Node: Event Designators, Next: Word Designators, Up: History Interaction |
ccc6cda3 | 7984 | |
37c41ab1 CR |
7985 | 9.3.1 Event Designators |
7986 | ----------------------- | |
ccc6cda3 | 7987 | |
37c41ab1 CR |
7988 | An event designator is a reference to a command line entry in the |
7989 | history list. | |
ccc6cda3 | 7990 | |
bb70624e JA |
7991 | `!' |
7992 | Start a history substitution, except when followed by a space, tab, | |
d3a24ed2 CR |
7993 | the end of the line, `=' or `(' (when the `extglob' shell option |
7994 | is enabled using the `shopt' builtin). | |
ccc6cda3 | 7995 | |
bb70624e JA |
7996 | `!N' |
7997 | Refer to command line N. | |
ccc6cda3 | 7998 | |
bb70624e JA |
7999 | `!-N' |
8000 | Refer to the command N lines back. | |
ccc6cda3 | 8001 | |
bb70624e JA |
8002 | `!!' |
8003 | Refer to the previous command. This is a synonym for `!-1'. | |
ccc6cda3 | 8004 | |
bb70624e JA |
8005 | `!STRING' |
8006 | Refer to the most recent command starting with STRING. | |
ccc6cda3 | 8007 | |
bb70624e JA |
8008 | `!?STRING[?]' |
8009 | Refer to the most recent command containing STRING. The trailing | |
8010 | `?' may be omitted if the STRING is followed immediately by a | |
8011 | newline. | |
ccc6cda3 | 8012 | |
bb70624e JA |
8013 | `^STRING1^STRING2^' |
8014 | Quick Substitution. Repeat the last command, replacing STRING1 | |
8015 | with STRING2. Equivalent to `!!:s/STRING1/STRING2/'. | |
8016 | ||
8017 | `!#' | |
8018 | The entire command line typed so far. | |
ccc6cda3 | 8019 | |
761783bf | 8020 | |
ccc6cda3 | 8021 | \1f |
bb70624e | 8022 | File: bashref.info, Node: Word Designators, Next: Modifiers, Prev: Event Designators, Up: History Interaction |
ccc6cda3 | 8023 | |
37c41ab1 CR |
8024 | 9.3.2 Word Designators |
8025 | ---------------------- | |
ccc6cda3 | 8026 | |
37c41ab1 | 8027 | Word designators are used to select desired words from the event. A |
bb70624e JA |
8028 | `:' separates the event specification from the word designator. It may |
8029 | be omitted if the word designator begins with a `^', `$', `*', `-', or | |
8030 | `%'. Words are numbered from the beginning of the line, with the first | |
8031 | word being denoted by 0 (zero). Words are inserted into the current | |
8032 | line separated by single spaces. | |
ccc6cda3 | 8033 | |
bb70624e | 8034 | For example, |
ccc6cda3 | 8035 | |
bb70624e JA |
8036 | `!!' |
8037 | designates the preceding command. When you type this, the | |
8038 | preceding command is repeated in toto. | |
ccc6cda3 | 8039 | |
bb70624e JA |
8040 | `!!:$' |
8041 | designates the last argument of the preceding command. This may be | |
8042 | shortened to `!$'. | |
ccc6cda3 | 8043 | |
bb70624e JA |
8044 | `!fi:2' |
8045 | designates the second argument of the most recent command starting | |
8046 | with the letters `fi'. | |
ccc6cda3 | 8047 | |
bb70624e | 8048 | Here are the word designators: |
ccc6cda3 | 8049 | |
bb70624e JA |
8050 | `0 (zero)' |
8051 | The `0'th word. For many applications, this is the command word. | |
ccc6cda3 | 8052 | |
bb70624e JA |
8053 | `N' |
8054 | The Nth word. | |
ccc6cda3 | 8055 | |
bb70624e JA |
8056 | `^' |
8057 | The first argument; that is, word 1. | |
ccc6cda3 | 8058 | |
bb70624e JA |
8059 | `$' |
8060 | The last argument. | |
ccc6cda3 | 8061 | |
bb70624e JA |
8062 | `%' |
8063 | The word matched by the most recent `?STRING?' search. | |
ccc6cda3 | 8064 | |
bb70624e JA |
8065 | `X-Y' |
8066 | A range of words; `-Y' abbreviates `0-Y'. | |
ccc6cda3 | 8067 | |
bb70624e JA |
8068 | `*' |
8069 | All of the words, except the `0'th. This is a synonym for `1-$'. | |
8070 | It is not an error to use `*' if there is just one word in the | |
8071 | event; the empty string is returned in that case. | |
8072 | ||
8073 | `X*' | |
8074 | Abbreviates `X-$' | |
8075 | ||
8076 | `X-' | |
8077 | Abbreviates `X-$' like `X*', but omits the last word. | |
8078 | ||
761783bf | 8079 | |
bb70624e JA |
8080 | If a word designator is supplied without an event specification, the |
8081 | previous command is used as the event. | |
ccc6cda3 JA |
8082 | |
8083 | \1f | |
bb70624e | 8084 | File: bashref.info, Node: Modifiers, Prev: Word Designators, Up: History Interaction |
ccc6cda3 | 8085 | |
37c41ab1 CR |
8086 | 9.3.3 Modifiers |
8087 | --------------- | |
ccc6cda3 | 8088 | |
37c41ab1 | 8089 | After the optional word designator, you can add a sequence of one or |
bb70624e | 8090 | more of the following modifiers, each preceded by a `:'. |
ccc6cda3 | 8091 | |
bb70624e JA |
8092 | `h' |
8093 | Remove a trailing pathname component, leaving only the head. | |
ccc6cda3 | 8094 | |
bb70624e | 8095 | `t' |
d3ad40de | 8096 | Remove all leading pathname components, leaving the tail. |
bb70624e JA |
8097 | |
8098 | `r' | |
8099 | Remove a trailing suffix of the form `.SUFFIX', leaving the | |
8100 | basename. | |
8101 | ||
8102 | `e' | |
8103 | Remove all but the trailing suffix. | |
8104 | ||
8105 | `p' | |
8106 | Print the new command but do not execute it. | |
8107 | ||
8108 | `q' | |
8109 | Quote the substituted words, escaping further substitutions. | |
8110 | ||
8111 | `x' | |
8112 | Quote the substituted words as with `q', but break into words at | |
8113 | spaces, tabs, and newlines. | |
8114 | ||
8115 | `s/OLD/NEW/' | |
8116 | Substitute NEW for the first occurrence of OLD in the event line. | |
8117 | Any delimiter may be used in place of `/'. The delimiter may be | |
8118 | quoted in OLD and NEW with a single backslash. If `&' appears in | |
8119 | NEW, it is replaced by OLD. A single backslash will quote the | |
8120 | `&'. The final delimiter is optional if it is the last character | |
8121 | on the input line. | |
8122 | ||
8123 | `&' | |
8124 | Repeat the previous substitution. | |
8125 | ||
8126 | `g' | |
d3a24ed2 | 8127 | `a' |
bb70624e JA |
8128 | Cause changes to be applied over the entire event line. Used in |
8129 | conjunction with `s', as in `gs/OLD/NEW/', or with `&'. | |
8130 | ||
d3a24ed2 CR |
8131 | `G' |
8132 | Apply the following `s' modifier once to each word in the event. | |
8133 | ||
761783bf | 8134 | |
bb70624e | 8135 | \1f |
c2a47ea9 | 8136 | File: bashref.info, Node: Installing Bash, Next: Reporting Bugs, Prev: Using History Interactively, Up: Top |
bb70624e | 8137 | |
37c41ab1 CR |
8138 | 10 Installing Bash |
8139 | ****************** | |
b72432fd | 8140 | |
37c41ab1 | 8141 | This chapter provides basic instructions for installing Bash on the |
bb70624e JA |
8142 | various supported platforms. The distribution supports the GNU |
8143 | operating systems, nearly every version of Unix, and several non-Unix | |
8144 | systems such as BeOS and Interix. Other independent ports exist for | |
d3a24ed2 | 8145 | MS-DOS, OS/2, and Windows platforms. |
ccc6cda3 | 8146 | |
bb70624e | 8147 | * Menu: |
ccc6cda3 | 8148 | |
bb70624e | 8149 | * Basic Installation:: Installation instructions. |
bb70624e JA |
8150 | * Compilers and Options:: How to set special options for various |
8151 | systems. | |
bb70624e JA |
8152 | * Compiling For Multiple Architectures:: How to compile Bash for more |
8153 | than one kind of system from | |
8154 | the same source tree. | |
bb70624e | 8155 | * Installation Names:: How to set the various paths used by the installation. |
bb70624e | 8156 | * Specifying the System Type:: How to configure Bash for a particular system. |
bb70624e JA |
8157 | * Sharing Defaults:: How to share default configuration values among GNU |
8158 | programs. | |
bb70624e | 8159 | * Operation Controls:: Options recognized by the configuration program. |
bb70624e JA |
8160 | * Optional Features:: How to enable and disable optional features when |
8161 | building Bash. | |
ccc6cda3 | 8162 | |
bb70624e JA |
8163 | \1f |
8164 | File: bashref.info, Node: Basic Installation, Next: Compilers and Options, Up: Installing Bash | |
ccc6cda3 | 8165 | |
37c41ab1 CR |
8166 | 10.1 Basic Installation |
8167 | ======================= | |
ccc6cda3 | 8168 | |
37c41ab1 | 8169 | These are installation instructions for Bash. |
ccc6cda3 | 8170 | |
bb70624e | 8171 | The simplest way to compile Bash is: |
ccc6cda3 | 8172 | |
bb70624e JA |
8173 | 1. `cd' to the directory containing the source code and type |
8174 | `./configure' to configure Bash for your system. If you're using | |
8175 | `csh' on an old version of System V, you might need to type `sh | |
8176 | ./configure' instead to prevent `csh' from trying to execute | |
8177 | `configure' itself. | |
ccc6cda3 | 8178 | |
bb70624e JA |
8179 | Running `configure' takes some time. While running, it prints |
8180 | messages telling which features it is checking for. | |
ccc6cda3 | 8181 | |
bb70624e JA |
8182 | 2. Type `make' to compile Bash and build the `bashbug' bug reporting |
8183 | script. | |
ccc6cda3 | 8184 | |
bb70624e | 8185 | 3. Optionally, type `make tests' to run the Bash test suite. |
ccc6cda3 | 8186 | |
bb70624e JA |
8187 | 4. Type `make install' to install `bash' and `bashbug'. This will |
8188 | also install the manual pages and Info file. | |
ccc6cda3 | 8189 | |
ccc6cda3 | 8190 | |
bb70624e JA |
8191 | The `configure' shell script attempts to guess correct values for |
8192 | various system-dependent variables used during compilation. It uses | |
8193 | those values to create a `Makefile' in each directory of the package | |
8194 | (the top directory, the `builtins', `doc', and `support' directories, | |
8195 | each directory under `lib', and several others). It also creates a | |
8196 | `config.h' file containing system-dependent definitions. Finally, it | |
8197 | creates a shell script named `config.status' that you can run in the | |
8198 | future to recreate the current configuration, a file `config.cache' | |
8199 | that saves the results of its tests to speed up reconfiguring, and a | |
8200 | file `config.log' containing compiler output (useful mainly for | |
8201 | debugging `configure'). If at some point `config.cache' contains | |
8202 | results you don't want to keep, you may remove or edit it. | |
ccc6cda3 | 8203 | |
bb70624e JA |
8204 | To find out more about the options and arguments that the |
8205 | `configure' script understands, type | |
ccc6cda3 | 8206 | |
bb70624e | 8207 | bash-2.04$ ./configure --help |
ccc6cda3 | 8208 | |
bb70624e | 8209 | at the Bash prompt in your Bash source directory. |
ccc6cda3 | 8210 | |
bb70624e JA |
8211 | If you need to do unusual things to compile Bash, please try to |
8212 | figure out how `configure' could check whether or not to do them, and | |
8213 | mail diffs or instructions to <bash-maintainers@gnu.org> so they can be | |
8214 | considered for the next release. | |
ccc6cda3 | 8215 | |
bb70624e JA |
8216 | The file `configure.in' is used to create `configure' by a program |
8217 | called Autoconf. You only need `configure.in' if you want to change it | |
8218 | or regenerate `configure' using a newer version of Autoconf. If you do | |
f73dda09 | 8219 | this, make sure you are using Autoconf version 2.50 or newer. |
ccc6cda3 | 8220 | |
bb70624e JA |
8221 | You can remove the program binaries and object files from the source |
8222 | code directory by typing `make clean'. To also remove the files that | |
8223 | `configure' created (so you can compile Bash for a different kind of | |
8224 | computer), type `make distclean'. | |
ccc6cda3 | 8225 | |
bb70624e JA |
8226 | \1f |
8227 | File: bashref.info, Node: Compilers and Options, Next: Compiling For Multiple Architectures, Prev: Basic Installation, Up: Installing Bash | |
ccc6cda3 | 8228 | |
37c41ab1 CR |
8229 | 10.2 Compilers and Options |
8230 | ========================== | |
ccc6cda3 | 8231 | |
37c41ab1 | 8232 | Some systems require unusual options for compilation or linking that |
bb70624e JA |
8233 | the `configure' script does not know about. You can give `configure' |
8234 | initial values for variables by setting them in the environment. Using | |
8235 | a Bourne-compatible shell, you can do that on the command line like | |
8236 | this: | |
ccc6cda3 | 8237 | |
bb70624e | 8238 | CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure |
ccc6cda3 | 8239 | |
bb70624e | 8240 | On systems that have the `env' program, you can do it like this: |
cce855bc | 8241 | |
bb70624e | 8242 | env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure |
b72432fd | 8243 | |
bb70624e | 8244 | The configuration process uses GCC to build Bash if it is available. |
ccc6cda3 | 8245 | |
bb70624e JA |
8246 | \1f |
8247 | File: bashref.info, Node: Compiling For Multiple Architectures, Next: Installation Names, Prev: Compilers and Options, Up: Installing Bash | |
ccc6cda3 | 8248 | |
37c41ab1 CR |
8249 | 10.3 Compiling For Multiple Architectures |
8250 | ========================================= | |
ccc6cda3 | 8251 | |
37c41ab1 | 8252 | You can compile Bash for more than one kind of computer at the same |
bb70624e JA |
8253 | time, by placing the object files for each architecture in their own |
8254 | directory. To do this, you must use a version of `make' that supports | |
8255 | the `VPATH' variable, such as GNU `make'. `cd' to the directory where | |
8256 | you want the object files and executables to go and run the `configure' | |
8257 | script from the source directory. You may need to supply the | |
8258 | `--srcdir=PATH' argument to tell `configure' where the source files | |
8259 | are. `configure' automatically checks for the source code in the | |
8260 | directory that `configure' is in and in `..'. | |
ccc6cda3 | 8261 | |
bb70624e JA |
8262 | If you have to use a `make' that does not supports the `VPATH' |
8263 | variable, you can compile Bash for one architecture at a time in the | |
8264 | source code directory. After you have installed Bash for one | |
8265 | architecture, use `make distclean' before reconfiguring for another | |
8266 | architecture. | |
ccc6cda3 | 8267 | |
bb70624e JA |
8268 | Alternatively, if your system supports symbolic links, you can use |
8269 | the `support/mkclone' script to create a build tree which has symbolic | |
8270 | links back to each file in the source directory. Here's an example | |
8271 | that creates a build directory in the current directory from a source | |
8272 | directory `/usr/gnu/src/bash-2.0': | |
ccc6cda3 | 8273 | |
bb70624e | 8274 | bash /usr/gnu/src/bash-2.0/support/mkclone -s /usr/gnu/src/bash-2.0 . |
ccc6cda3 | 8275 | |
bb70624e JA |
8276 | The `mkclone' script requires Bash, so you must have already built Bash |
8277 | for at least one architecture before you can create build directories | |
8278 | for other architectures. | |
ccc6cda3 | 8279 | |
bb70624e JA |
8280 | \1f |
8281 | File: bashref.info, Node: Installation Names, Next: Specifying the System Type, Prev: Compiling For Multiple Architectures, Up: Installing Bash | |
ccc6cda3 | 8282 | |
37c41ab1 CR |
8283 | 10.4 Installation Names |
8284 | ======================= | |
ccc6cda3 | 8285 | |
37c41ab1 | 8286 | By default, `make install' will install into `/usr/local/bin', |
bb70624e | 8287 | `/usr/local/man', etc. You can specify an installation prefix other |
f73dda09 JA |
8288 | than `/usr/local' by giving `configure' the option `--prefix=PATH', or |
8289 | by specifying a value for the `DESTDIR' `make' variable when running | |
8290 | `make install'. | |
ccc6cda3 | 8291 | |
bb70624e JA |
8292 | You can specify separate installation prefixes for |
8293 | architecture-specific files and architecture-independent files. If you | |
8294 | give `configure' the option `--exec-prefix=PATH', `make install' will | |
8295 | use PATH as the prefix for installing programs and libraries. | |
8296 | Documentation and other data files will still use the regular prefix. | |
ccc6cda3 JA |
8297 | |
8298 | \1f | |
bb70624e | 8299 | File: bashref.info, Node: Specifying the System Type, Next: Sharing Defaults, Prev: Installation Names, Up: Installing Bash |
ccc6cda3 | 8300 | |
37c41ab1 CR |
8301 | 10.5 Specifying the System Type |
8302 | =============================== | |
ccc6cda3 | 8303 | |
37c41ab1 | 8304 | There may be some features `configure' can not figure out |
f73dda09 | 8305 | automatically, but need to determine by the type of host Bash will run |
bb70624e JA |
8306 | on. Usually `configure' can figure that out, but if it prints a |
8307 | message saying it can not guess the host type, give it the | |
8308 | `--host=TYPE' option. `TYPE' can either be a short name for the system | |
8309 | type, such as `sun4', or a canonical name with three fields: | |
f73dda09 | 8310 | `CPU-COMPANY-SYSTEM' (e.g., `i386-unknown-freebsd4.2'). |
ccc6cda3 | 8311 | |
bb70624e JA |
8312 | See the file `support/config.sub' for the possible values of each |
8313 | field. | |
ccc6cda3 | 8314 | |
bb70624e JA |
8315 | \1f |
8316 | File: bashref.info, Node: Sharing Defaults, Next: Operation Controls, Prev: Specifying the System Type, Up: Installing Bash | |
8317 | ||
37c41ab1 CR |
8318 | 10.6 Sharing Defaults |
8319 | ===================== | |
bb70624e | 8320 | |
37c41ab1 CR |
8321 | If you want to set default values for `configure' scripts to share, you |
8322 | can create a site shell script called `config.site' that gives default | |
8323 | values for variables like `CC', `cache_file', and `prefix'. `configure' | |
8324 | looks for `PREFIX/share/config.site' if it exists, then | |
bb70624e JA |
8325 | `PREFIX/etc/config.site' if it exists. Or, you can set the |
8326 | `CONFIG_SITE' environment variable to the location of the site script. | |
8327 | A warning: the Bash `configure' looks for a site script, but not all | |
8328 | `configure' scripts do. | |
ccc6cda3 JA |
8329 | |
8330 | \1f | |
bb70624e | 8331 | File: bashref.info, Node: Operation Controls, Next: Optional Features, Prev: Sharing Defaults, Up: Installing Bash |
ccc6cda3 | 8332 | |
37c41ab1 CR |
8333 | 10.7 Operation Controls |
8334 | ======================= | |
ccc6cda3 | 8335 | |
37c41ab1 | 8336 | `configure' recognizes the following options to control how it operates. |
ccc6cda3 | 8337 | |
bb70624e JA |
8338 | `--cache-file=FILE' |
8339 | Use and save the results of the tests in FILE instead of | |
8340 | `./config.cache'. Set FILE to `/dev/null' to disable caching, for | |
8341 | debugging `configure'. | |
ccc6cda3 | 8342 | |
bb70624e JA |
8343 | `--help' |
8344 | Print a summary of the options to `configure', and exit. | |
ccc6cda3 | 8345 | |
bb70624e JA |
8346 | `--quiet' |
8347 | `--silent' | |
8348 | `-q' | |
8349 | Do not print messages saying which checks are being made. | |
ccc6cda3 | 8350 | |
bb70624e JA |
8351 | `--srcdir=DIR' |
8352 | Look for the Bash source code in directory DIR. Usually | |
8353 | `configure' can determine that directory automatically. | |
ccc6cda3 | 8354 | |
bb70624e JA |
8355 | `--version' |
8356 | Print the version of Autoconf used to generate the `configure' | |
8357 | script, and exit. | |
ccc6cda3 | 8358 | |
bb70624e JA |
8359 | `configure' also accepts some other, not widely used, boilerplate |
8360 | options. `configure --help' prints the complete list. | |
ccc6cda3 | 8361 | |
bb70624e JA |
8362 | \1f |
8363 | File: bashref.info, Node: Optional Features, Prev: Operation Controls, Up: Installing Bash | |
ccc6cda3 | 8364 | |
37c41ab1 CR |
8365 | 10.8 Optional Features |
8366 | ====================== | |
ccc6cda3 | 8367 | |
37c41ab1 CR |
8368 | The Bash `configure' has a number of `--enable-FEATURE' options, where |
8369 | FEATURE indicates an optional part of Bash. There are also several | |
8370 | `--with-PACKAGE' options, where PACKAGE is something like `bash-malloc' | |
8371 | or `purify'. To turn off the default use of a package, use | |
8372 | `--without-PACKAGE'. To configure Bash without a feature that is | |
bb70624e | 8373 | enabled by default, use `--disable-FEATURE'. |
ccc6cda3 | 8374 | |
bb70624e JA |
8375 | Here is a complete list of the `--enable-' and `--with-' options |
8376 | that the Bash `configure' recognizes. | |
ccc6cda3 | 8377 | |
bb70624e JA |
8378 | `--with-afs' |
8379 | Define if you are using the Andrew File System from Transarc. | |
ccc6cda3 | 8380 | |
bb70624e | 8381 | `--with-bash-malloc' |
1c72c0cd CR |
8382 | Use the Bash version of `malloc' in the directory `lib/malloc'. |
8383 | This is not the same `malloc' that appears in GNU libc, but an | |
8384 | older version originally derived from the 4.2 BSD `malloc'. This | |
8385 | `malloc' is very fast, but wastes some space on each allocation. | |
8386 | This option is enabled by default. The `NOTES' file contains a | |
8387 | list of systems for which this should be turned off, and | |
8388 | `configure' disables this option automatically for a number of | |
8389 | systems. | |
ccc6cda3 | 8390 | |
bb70624e JA |
8391 | `--with-curses' |
8392 | Use the curses library instead of the termcap library. This should | |
8393 | be supplied if your system has an inadequate or incomplete termcap | |
8394 | database. | |
ccc6cda3 | 8395 | |
bb70624e JA |
8396 | `--with-gnu-malloc' |
8397 | A synonym for `--with-bash-malloc'. | |
ccc6cda3 | 8398 | |
f73dda09 | 8399 | `--with-installed-readline[=PREFIX]' |
bb70624e JA |
8400 | Define this to make Bash link with a locally-installed version of |
8401 | Readline rather than the version in `lib/readline'. This works | |
01ed5ba4 | 8402 | only with Readline 5.0 and later versions. If PREFIX is `yes' or |
f73dda09 JA |
8403 | not supplied, `configure' uses the values of the make variables |
8404 | `includedir' and `libdir', which are subdirectories of `prefix' by | |
8405 | default, to find the installed version of Readline if it is not in | |
8406 | the standard system include and library directories. If PREFIX is | |
8407 | `no', Bash links with the version in `lib/readline'. If PREFIX is | |
8408 | set to any other value, `configure' treats it as a directory | |
8409 | pathname and looks for the installed version of Readline in | |
8410 | subdirectories of that directory (include files in | |
8411 | PREFIX/`include' and the library in PREFIX/`lib'). | |
ccc6cda3 | 8412 | |
bb70624e JA |
8413 | `--with-purify' |
8414 | Define this to use the Purify memory allocation checker from | |
8415 | Rational Software. | |
ccc6cda3 | 8416 | |
bb70624e JA |
8417 | `--enable-minimal-config' |
8418 | This produces a shell with minimal features, close to the | |
8419 | historical Bourne shell. | |
ccc6cda3 | 8420 | |
bb70624e JA |
8421 | There are several `--enable-' options that alter how Bash is |
8422 | compiled and linked, rather than changing run-time features. | |
ccc6cda3 | 8423 | |
f73dda09 JA |
8424 | `--enable-largefile' |
8425 | Enable support for large files | |
8426 | (http://www.sas.com/standards/large_file/x_open.20Mar96.html) if | |
8427 | the operating system requires special compiler options to build | |
7117c2d2 JA |
8428 | programs which can access large files. This is enabled by |
8429 | default, if the operating system provides large file support. | |
f73dda09 | 8430 | |
bb70624e JA |
8431 | `--enable-profiling' |
8432 | This builds a Bash binary that produces profiling information to be | |
8433 | processed by `gprof' each time it is executed. | |
cce855bc | 8434 | |
bb70624e JA |
8435 | `--enable-static-link' |
8436 | This causes Bash to be linked statically, if `gcc' is being used. | |
8437 | This could be used to build a version to use as root's shell. | |
d166f048 | 8438 | |
bb70624e JA |
8439 | The `minimal-config' option can be used to disable all of the |
8440 | following options, but it is processed first, so individual options may | |
8441 | be enabled using `enable-FEATURE'. | |
d166f048 | 8442 | |
bb70624e JA |
8443 | All of the following options except for `disabled-builtins' and |
8444 | `xpg-echo-default' are enabled by default, unless the operating system | |
8445 | does not provide the necessary support. | |
ccc6cda3 | 8446 | |
bb70624e JA |
8447 | `--enable-alias' |
8448 | Allow alias expansion and include the `alias' and `unalias' | |
28ef6c31 | 8449 | builtins (*note Aliases::). |
ccc6cda3 | 8450 | |
bb70624e JA |
8451 | `--enable-arith-for-command' |
8452 | Include support for the alternate form of the `for' command that | |
8453 | behaves like the C language `for' statement (*note Looping | |
28ef6c31 | 8454 | Constructs::). |
ccc6cda3 | 8455 | |
bb70624e JA |
8456 | `--enable-array-variables' |
8457 | Include support for one-dimensional array shell variables (*note | |
28ef6c31 | 8458 | Arrays::). |
ccc6cda3 | 8459 | |
bb70624e JA |
8460 | `--enable-bang-history' |
8461 | Include support for `csh'-like history substitution (*note History | |
28ef6c31 | 8462 | Interaction::). |
ccc6cda3 | 8463 | |
bb70624e JA |
8464 | `--enable-brace-expansion' |
8465 | Include `csh'-like brace expansion ( `b{a,b}c' ==> `bac bbc' ). | |
6a8fd0ed | 8466 | See *note Brace Expansion::, for a complete description. |
ccc6cda3 | 8467 | |
09767ff0 CR |
8468 | `--enable-casemod-attributes' |
8469 | Include support for case-modifying attributes in the `declare' | |
8470 | builtin and assignment statements. Variables with the UPPERCASE | |
8471 | attribute, for example, will have their values converted to | |
8472 | uppercase upon assignment. | |
8473 | ||
8474 | `--enable-casemod-expansion' | |
8475 | Include support for case-modifying word expansions. | |
8476 | ||
bb70624e JA |
8477 | `--enable-command-timing' |
8478 | Include support for recognizing `time' as a reserved word and for | |
8479 | displaying timing statistics for the pipeline following `time' | |
28ef6c31 | 8480 | (*note Pipelines::). This allows pipelines as well as shell |
bb70624e | 8481 | builtins and functions to be timed. |
ccc6cda3 | 8482 | |
bb70624e | 8483 | `--enable-cond-command' |
5e13499c CR |
8484 | Include support for the `[[' conditional command. (*note |
8485 | Conditional Constructs::). | |
8486 | ||
8487 | `--enable-cond-regexp' | |
8488 | Include support for matching POSIX regular expressions using the | |
8489 | `=~' binary operator in the `[[' conditional command. (*note | |
28ef6c31 | 8490 | Conditional Constructs::). |
ccc6cda3 | 8491 | |
8e1a6eaa CR |
8492 | `--enable-coprocesses' |
8493 | Include support for coprocesses and the `coproc' reserved word | |
8494 | (*note Pipelines::). | |
8495 | ||
01ed5ba4 CR |
8496 | `--enable-debugger' |
8497 | Include support for the bash debugger (distributed separately). | |
8498 | ||
bb70624e JA |
8499 | `--enable-directory-stack' |
8500 | Include support for a `csh'-like directory stack and the `pushd', | |
28ef6c31 | 8501 | `popd', and `dirs' builtins (*note The Directory Stack::). |
ccc6cda3 | 8502 | |
bb70624e JA |
8503 | `--enable-disabled-builtins' |
8504 | Allow builtin commands to be invoked via `builtin xxx' even after | |
6a8fd0ed | 8505 | `xxx' has been disabled using `enable -n xxx'. See *note Bash |
bb70624e JA |
8506 | Builtins::, for details of the `builtin' and `enable' builtin |
8507 | commands. | |
ccc6cda3 | 8508 | |
bb70624e JA |
8509 | `--enable-dparen-arithmetic' |
8510 | Include support for the `((...))' command (*note Conditional | |
28ef6c31 | 8511 | Constructs::). |
ccc6cda3 | 8512 | |
bb70624e JA |
8513 | `--enable-extended-glob' |
8514 | Include support for the extended pattern matching features | |
6a8fd0ed | 8515 | described above under *note Pattern Matching::. |
ccc6cda3 | 8516 | |
bb70624e JA |
8517 | `--enable-help-builtin' |
8518 | Include the `help' builtin, which displays help on shell builtins | |
28ef6c31 | 8519 | and variables (*note Bash Builtins::). |
ccc6cda3 | 8520 | |
bb70624e JA |
8521 | `--enable-history' |
8522 | Include command history and the `fc' and `history' builtin | |
28ef6c31 | 8523 | commands (*note Bash History Facilities::). |
ccc6cda3 | 8524 | |
bb70624e | 8525 | `--enable-job-control' |
28ef6c31 | 8526 | This enables the job control features (*note Job Control::), if |
bb70624e | 8527 | the operating system supports them. |
ccc6cda3 | 8528 | |
d3a24ed2 CR |
8529 | `--enable-multibyte' |
8530 | This enables support for multibyte characters if the operating | |
8531 | system provides the necessary support. | |
8532 | ||
bb70624e JA |
8533 | `--enable-net-redirections' |
8534 | This enables the special handling of filenames of the form | |
8535 | `/dev/tcp/HOST/PORT' and `/dev/udp/HOST/PORT' when used in | |
28ef6c31 | 8536 | redirections (*note Redirections::). |
ccc6cda3 | 8537 | |
bb70624e | 8538 | `--enable-process-substitution' |
28ef6c31 JA |
8539 | This enables process substitution (*note Process Substitution::) if |
8540 | the operating system provides the necessary support. | |
ccc6cda3 | 8541 | |
01ed5ba4 CR |
8542 | `--enable-progcomp' |
8543 | Enable the programmable completion facilities (*note Programmable | |
8544 | Completion::). If Readline is not enabled, this option has no | |
8545 | effect. | |
8546 | ||
bb70624e JA |
8547 | `--enable-prompt-string-decoding' |
8548 | Turn on the interpretation of a number of backslash-escaped | |
8549 | characters in the `$PS1', `$PS2', `$PS3', and `$PS4' prompt | |
6a8fd0ed | 8550 | strings. See *note Printing a Prompt::, for a complete list of |
bb70624e | 8551 | prompt string escape sequences. |
ccc6cda3 | 8552 | |
bb70624e JA |
8553 | `--enable-readline' |
8554 | Include support for command-line editing and history with the Bash | |
28ef6c31 | 8555 | version of the Readline library (*note Command Line Editing::). |
ccc6cda3 | 8556 | |
bb70624e JA |
8557 | `--enable-restricted' |
8558 | Include support for a "restricted shell". If this is enabled, | |
6a8fd0ed | 8559 | Bash, when called as `rbash', enters a restricted mode. See *note |
bb70624e | 8560 | The Restricted Shell::, for a description of restricted mode. |
ccc6cda3 | 8561 | |
bb70624e JA |
8562 | `--enable-select' |
8563 | Include the `select' builtin, which allows the generation of simple | |
28ef6c31 | 8564 | menus (*note Conditional Constructs::). |
ccc6cda3 | 8565 | |
01ed5ba4 CR |
8566 | `--enable-separate-helpfiles' |
8567 | Use external files for the documentation displayed by the `help' | |
8568 | builtin instead of storing the text internally. | |
8569 | ||
8570 | `--enable-single-help-strings' | |
8571 | Store the text displayed by the `help' builtin as a single string | |
8572 | for each help topic. This aids in translating the text to | |
8573 | different languages. You may need to disable this if your | |
8574 | compiler cannot handle very long string literals. | |
8575 | ||
1c72c0cd CR |
8576 | `--enable-strict-posix-default' |
8577 | Make Bash POSIX-conformant by default (*note Bash POSIX Mode::). | |
8578 | ||
bb70624e JA |
8579 | `--enable-usg-echo-default' |
8580 | A synonym for `--enable-xpg-echo-default'. | |
ccc6cda3 | 8581 | |
bb70624e JA |
8582 | `--enable-xpg-echo-default' |
8583 | Make the `echo' builtin expand backslash-escaped characters by | |
8584 | default, without requiring the `-e' option. This sets the default | |
8585 | value of the `xpg_echo' shell option to `on', which makes the Bash | |
8586 | `echo' behave more like the version specified in the Single Unix | |
01ed5ba4 | 8587 | Specification, version 3. *Note Bash Builtins::, for a |
bb70624e | 8588 | description of the escape sequences that `echo' recognizes. |
ccc6cda3 | 8589 | |
761783bf | 8590 | |
bb70624e JA |
8591 | The file `config-top.h' contains C Preprocessor `#define' statements |
8592 | for options which are not settable from `configure'. Some of these are | |
8593 | not meant to be changed; beware of the consequences if you do. Read | |
8594 | the comments associated with each definition for more information about | |
8595 | its effect. | |
ccc6cda3 | 8596 | |
bb70624e JA |
8597 | \1f |
8598 | File: bashref.info, Node: Reporting Bugs, Next: Major Differences From The Bourne Shell, Prev: Installing Bash, Up: Top | |
d166f048 | 8599 | |
37c41ab1 CR |
8600 | Appendix A Reporting Bugs |
8601 | ************************* | |
ccc6cda3 | 8602 | |
37c41ab1 | 8603 | Please report all bugs you find in Bash. But first, you should make |
bb70624e | 8604 | sure that it really is a bug, and that it appears in the latest version |
d3a24ed2 | 8605 | of Bash. The latest version of Bash is always available for FTP from |
4a8bb13f | 8606 | `ftp://ftp.gnu.org/pub/gnu/bash/'. |
ccc6cda3 | 8607 | |
bb70624e JA |
8608 | Once you have determined that a bug actually exists, use the |
8609 | `bashbug' command to submit a bug report. If you have a fix, you are | |
8610 | encouraged to mail that as well! Suggestions and `philosophical' bug | |
8611 | reports may be mailed to <bug-bash@gnu.org> or posted to the Usenet | |
8612 | newsgroup `gnu.bash.bug'. | |
ccc6cda3 | 8613 | |
bb70624e JA |
8614 | All bug reports should include: |
8615 | * The version number of Bash. | |
ccc6cda3 | 8616 | |
bb70624e | 8617 | * The hardware and operating system. |
ccc6cda3 | 8618 | |
bb70624e | 8619 | * The compiler used to compile Bash. |
ccc6cda3 | 8620 | |
bb70624e | 8621 | * A description of the bug behaviour. |
ccc6cda3 | 8622 | |
bb70624e JA |
8623 | * A short script or `recipe' which exercises the bug and may be used |
8624 | to reproduce it. | |
ccc6cda3 | 8625 | |
bb70624e JA |
8626 | `bashbug' inserts the first three items automatically into the template |
8627 | it provides for filing a bug report. | |
8628 | ||
6932f7f5 CR |
8629 | Please send all reports concerning this manual to |
8630 | <chet.ramey@case.edu>. | |
ccc6cda3 JA |
8631 | |
8632 | \1f | |
c2a47ea9 | 8633 | File: bashref.info, Node: Major Differences From The Bourne Shell, Next: GNU Free Documentation License, Prev: Reporting Bugs, Up: Top |
ccc6cda3 | 8634 | |
37c41ab1 CR |
8635 | Appendix B Major Differences From The Bourne Shell |
8636 | ************************************************** | |
ccc6cda3 | 8637 | |
37c41ab1 | 8638 | Bash implements essentially the same grammar, parameter and variable |
bb70624e | 8639 | expansion, redirection, and quoting as the Bourne Shell. Bash uses the |
ac18b312 CR |
8640 | POSIX standard as the specification of how these features are to be |
8641 | implemented. There are some differences between the traditional Bourne | |
8642 | shell and Bash; this section quickly details the differences of | |
bb70624e JA |
8643 | significance. A number of these differences are explained in greater |
8644 | depth in previous sections. This section uses the version of `sh' | |
1c72c0cd CR |
8645 | included in SVR4.2 (the last version of the historical Bourne shell) as |
8646 | the baseline reference. | |
ccc6cda3 | 8647 | |
bb70624e | 8648 | * Bash is POSIX-conformant, even where the POSIX specification |
28ef6c31 | 8649 | differs from traditional `sh' behavior (*note Bash POSIX Mode::). |
ccc6cda3 | 8650 | |
bb70624e | 8651 | * Bash has multi-character invocation options (*note Invoking |
28ef6c31 | 8652 | Bash::). |
ccc6cda3 | 8653 | |
28ef6c31 | 8654 | * Bash has command-line editing (*note Command Line Editing::) and |
bb70624e | 8655 | the `bind' builtin. |
ccc6cda3 | 8656 | |
bb70624e | 8657 | * Bash provides a programmable word completion mechanism (*note |
6a8fd0ed CR |
8658 | Programmable Completion::), and builtin commands `complete', |
8659 | `compgen', and `compopt', to manipulate it. | |
ccc6cda3 | 8660 | |
28ef6c31 | 8661 | * Bash has command history (*note Bash History Facilities::) and the |
5e13499c CR |
8662 | `history' and `fc' builtins to manipulate it. The Bash history |
8663 | list maintains timestamp information and uses the value of the | |
8664 | `HISTTIMEFORMAT' variable to display it. | |
ccc6cda3 | 8665 | |
bb70624e | 8666 | * Bash implements `csh'-like history expansion (*note History |
28ef6c31 | 8667 | Interaction::). |
ccc6cda3 | 8668 | |
28ef6c31 | 8669 | * Bash has one-dimensional array variables (*note Arrays::), and the |
bb70624e JA |
8670 | appropriate variable expansions and assignment syntax to use them. |
8671 | Several of the Bash builtins take options to act on arrays. Bash | |
8672 | provides a number of built-in array variables. | |
ccc6cda3 | 8673 | |
bb70624e JA |
8674 | * The `$'...'' quoting syntax, which expands ANSI-C |
8675 | backslash-escaped characters in the text between the single quotes, | |
28ef6c31 | 8676 | is supported (*note ANSI-C Quoting::). |
ccc6cda3 | 8677 | |
bb70624e JA |
8678 | * Bash supports the `$"..."' quoting syntax to do locale-specific |
8679 | translation of the characters between the double quotes. The | |
8680 | `-D', `--dump-strings', and `--dump-po-strings' invocation options | |
8681 | list the translatable strings found in a script (*note Locale | |
28ef6c31 | 8682 | Translation::). |
ccc6cda3 | 8683 | |
bb70624e | 8684 | * Bash implements the `!' keyword to negate the return value of a |
28ef6c31 | 8685 | pipeline (*note Pipelines::). Very useful when an `if' statement |
1c72c0cd CR |
8686 | needs to act only if a test fails. The Bash `-o pipefail' option |
8687 | to `set' will cause a pipeline to return a failure status if any | |
8688 | command fails. | |
ccc6cda3 | 8689 | |
bb70624e | 8690 | * Bash has the `time' reserved word and command timing (*note |
28ef6c31 | 8691 | Pipelines::). The display of the timing statistics may be |
bb70624e | 8692 | controlled with the `TIMEFORMAT' variable. |
ccc6cda3 | 8693 | |
bb70624e JA |
8694 | * Bash implements the `for (( EXPR1 ; EXPR2 ; EXPR3 ))' arithmetic |
8695 | for command, similar to the C language (*note Looping | |
28ef6c31 | 8696 | Constructs::). |
ccc6cda3 | 8697 | |
bb70624e | 8698 | * Bash includes the `select' compound command, which allows the |
28ef6c31 | 8699 | generation of simple menus (*note Conditional Constructs::). |
ccc6cda3 | 8700 | |
bb70624e | 8701 | * Bash includes the `[[' compound command, which makes conditional |
1c72c0cd CR |
8702 | testing part of the shell grammar (*note Conditional |
8703 | Constructs::), including optional regular expression matching. | |
8704 | ||
8705 | * Bash provides optional case-insensitive matching for the `case' and | |
8706 | `[[' constructs. | |
ccc6cda3 | 8707 | |
28ef6c31 JA |
8708 | * Bash includes brace expansion (*note Brace Expansion::) and tilde |
8709 | expansion (*note Tilde Expansion::). | |
ccc6cda3 | 8710 | |
bb70624e | 8711 | * Bash implements command aliases and the `alias' and `unalias' |
28ef6c31 | 8712 | builtins (*note Aliases::). |
ccc6cda3 | 8713 | |
bb70624e | 8714 | * Bash provides shell arithmetic, the `((' compound command (*note |
28ef6c31 JA |
8715 | Conditional Constructs::), and arithmetic expansion (*note Shell |
8716 | Arithmetic::). | |
ccc6cda3 | 8717 | |
bb70624e JA |
8718 | * Variables present in the shell's initial environment are |
8719 | automatically exported to child processes. The Bourne shell does | |
8720 | not normally do this unless the variables are explicitly marked | |
8721 | using the `export' command. | |
ccc6cda3 | 8722 | |
1c72c0cd CR |
8723 | * Bash supports the `+=' assignment operator, which appends to the |
8724 | value of the variable named on the left hand side. | |
8725 | ||
bb70624e JA |
8726 | * Bash includes the POSIX pattern removal `%', `#', `%%' and `##' |
8727 | expansions to remove leading or trailing substrings from variable | |
28ef6c31 | 8728 | values (*note Shell Parameter Expansion::). |
ccc6cda3 | 8729 | |
bb70624e | 8730 | * The expansion `${#xx}', which returns the length of `${xx}', is |
28ef6c31 | 8731 | supported (*note Shell Parameter Expansion::). |
ccc6cda3 | 8732 | |
bb70624e JA |
8733 | * The expansion `${var:'OFFSET`[:'LENGTH`]}', which expands to the |
8734 | substring of `var''s value of length LENGTH, beginning at OFFSET, | |
28ef6c31 | 8735 | is present (*note Shell Parameter Expansion::). |
ccc6cda3 | 8736 | |
bb70624e JA |
8737 | * The expansion `${var/[/]'PATTERN`[/'REPLACEMENT`]}', which matches |
8738 | PATTERN and replaces it with REPLACEMENT in the value of `var', is | |
28ef6c31 | 8739 | available (*note Shell Parameter Expansion::). |
ccc6cda3 | 8740 | |
bb70624e JA |
8741 | * The expansion `${!PREFIX}*' expansion, which expands to the names |
8742 | of all shell variables whose names begin with PREFIX, is available | |
28ef6c31 | 8743 | (*note Shell Parameter Expansion::). |
ccc6cda3 | 8744 | |
bb70624e | 8745 | * Bash has INDIRECT variable expansion using `${!word}' (*note Shell |
28ef6c31 | 8746 | Parameter Expansion::). |
ccc6cda3 | 8747 | |
bb70624e | 8748 | * Bash can expand positional parameters beyond `$9' using `${NUM}'. |
ccc6cda3 | 8749 | |
bb70624e | 8750 | * The POSIX `$()' form of command substitution is implemented (*note |
28ef6c31 | 8751 | Command Substitution::), and preferred to the Bourne shell's ```' |
bb70624e | 8752 | (which is also implemented for backwards compatibility). |
ccc6cda3 | 8753 | |
28ef6c31 | 8754 | * Bash has process substitution (*note Process Substitution::). |
ccc6cda3 | 8755 | |
bb70624e JA |
8756 | * Bash automatically assigns variables that provide information |
8757 | about the current user (`UID', `EUID', and `GROUPS'), the current | |
8758 | host (`HOSTTYPE', `OSTYPE', `MACHTYPE', and `HOSTNAME'), and the | |
8759 | instance of Bash that is running (`BASH', `BASH_VERSION', and | |
8760 | `BASH_VERSINFO'). *Note Bash Variables::, for details. | |
ccc6cda3 | 8761 | |
bb70624e | 8762 | * The `IFS' variable is used to split only the results of expansion, |
28ef6c31 | 8763 | not all words (*note Word Splitting::). This closes a |
bb70624e | 8764 | longstanding shell security hole. |
ccc6cda3 | 8765 | |
ac18b312 CR |
8766 | * Bash implements the full set of POSIX filename expansion operators, |
8767 | including CHARACTER CLASSES, EQUIVALENCE CLASSES, and COLLATING | |
8768 | SYMBOLS (*note Filename Expansion::). | |
ccc6cda3 | 8769 | |
bb70624e | 8770 | * Bash implements extended pattern matching features when the |
28ef6c31 | 8771 | `extglob' shell option is enabled (*note Pattern Matching::). |
ccc6cda3 | 8772 | |
bb70624e JA |
8773 | * It is possible to have a variable and a function with the same |
8774 | name; `sh' does not separate the two name spaces. | |
ccc6cda3 | 8775 | |
bb70624e JA |
8776 | * Bash functions are permitted to have local variables using the |
8777 | `local' builtin, and thus useful recursive functions may be written | |
28ef6c31 | 8778 | (*note Bash Builtins::). |
ccc6cda3 | 8779 | |
bb70624e | 8780 | * Variable assignments preceding commands affect only that command, |
28ef6c31 | 8781 | even builtins and functions (*note Environment::). In `sh', all |
bb70624e JA |
8782 | variable assignments preceding commands are global unless the |
8783 | command is executed from the file system. | |
ccc6cda3 | 8784 | |
bb70624e | 8785 | * Bash performs filename expansion on filenames specified as operands |
28ef6c31 | 8786 | to input and output redirection operators (*note Redirections::). |
ccc6cda3 | 8787 | |
bb70624e JA |
8788 | * Bash contains the `<>' redirection operator, allowing a file to be |
8789 | opened for both reading and writing, and the `&>' redirection | |
8790 | operator, for directing standard output and standard error to the | |
28ef6c31 | 8791 | same file (*note Redirections::). |
d166f048 | 8792 | |
1c72c0cd CR |
8793 | * Bash includes the `<<<' redirection operator, allowing a string to |
8794 | be used as the standard input to a command. | |
8795 | ||
8796 | * Bash implements the `[n]<&WORD' and `[n]>&WORD' redirection | |
8797 | operators, which move one file descriptor to another. | |
8798 | ||
bb70624e | 8799 | * Bash treats a number of filenames specially when they are used in |
28ef6c31 | 8800 | redirection operators (*note Redirections::). |
ccc6cda3 | 8801 | |
bb70624e | 8802 | * Bash can open network connections to arbitrary machines and |
28ef6c31 | 8803 | services with the redirection operators (*note Redirections::). |
ccc6cda3 | 8804 | |
bb70624e | 8805 | * The `noclobber' option is available to avoid overwriting existing |
28ef6c31 JA |
8806 | files with output redirection (*note The Set Builtin::). The `>|' |
8807 | redirection operator may be used to override `noclobber'. | |
ccc6cda3 | 8808 | |
28ef6c31 JA |
8809 | * The Bash `cd' and `pwd' builtins (*note Bourne Shell Builtins::) |
8810 | each take `-L' and `-P' options to switch between logical and | |
bb70624e | 8811 | physical modes. |
b72432fd | 8812 | |
bb70624e JA |
8813 | * Bash allows a function to override a builtin with the same name, |
8814 | and provides access to that builtin's functionality within the | |
8815 | function via the `builtin' and `command' builtins (*note Bash | |
28ef6c31 | 8816 | Builtins::). |
ccc6cda3 | 8817 | |
bb70624e | 8818 | * The `command' builtin allows selective disabling of functions when |
28ef6c31 | 8819 | command lookup is performed (*note Bash Builtins::). |
ccc6cda3 | 8820 | |
bb70624e | 8821 | * Individual builtins may be enabled or disabled using the `enable' |
28ef6c31 | 8822 | builtin (*note Bash Builtins::). |
cce855bc | 8823 | |
bb70624e JA |
8824 | * The Bash `exec' builtin takes additional options that allow users |
8825 | to control the contents of the environment passed to the executed | |
8826 | command, and what the zeroth argument to the command is to be | |
28ef6c31 | 8827 | (*note Bourne Shell Builtins::). |
cce855bc | 8828 | |
bb70624e | 8829 | * Shell functions may be exported to children via the environment |
28ef6c31 | 8830 | using `export -f' (*note Shell Functions::). |
cce855bc | 8831 | |
bb70624e JA |
8832 | * The Bash `export', `readonly', and `declare' builtins can take a |
8833 | `-f' option to act on shell functions, a `-p' option to display | |
8834 | variables with various attributes set in a format that can be used | |
8835 | as shell input, a `-n' option to remove various variable | |
8836 | attributes, and `name=value' arguments to set variable attributes | |
8837 | and values simultaneously. | |
ccc6cda3 | 8838 | |
bb70624e JA |
8839 | * The Bash `hash' builtin allows a name to be associated with an |
8840 | arbitrary filename, even when that filename cannot be found by | |
8841 | searching the `$PATH', using `hash -p' (*note Bourne Shell | |
28ef6c31 | 8842 | Builtins::). |
ccc6cda3 | 8843 | |
bb70624e | 8844 | * Bash includes a `help' builtin for quick reference to shell |
28ef6c31 | 8845 | facilities (*note Bash Builtins::). |
ccc6cda3 | 8846 | |
bb70624e | 8847 | * The `printf' builtin is available to display formatted output |
28ef6c31 | 8848 | (*note Bash Builtins::). |
ccc6cda3 | 8849 | |
28ef6c31 | 8850 | * The Bash `read' builtin (*note Bash Builtins::) will read a line |
bb70624e JA |
8851 | ending in `\' with the `-r' option, and will use the `REPLY' |
8852 | variable as a default if no non-option arguments are supplied. | |
8853 | The Bash `read' builtin also accepts a prompt string with the `-p' | |
8854 | option and will use Readline to obtain the line when given the | |
8855 | `-e' option. The `read' builtin also has additional options to | |
8856 | control input: the `-s' option will turn off echoing of input | |
8857 | characters as they are read, the `-t' option will allow `read' to | |
8858 | time out if input does not arrive within a specified number of | |
8859 | seconds, the `-n' option will allow reading only a specified | |
8860 | number of characters rather than a full line, and the `-d' option | |
8861 | will read until a particular character rather than newline. | |
ccc6cda3 | 8862 | |
bb70624e JA |
8863 | * The `return' builtin may be used to abort execution of scripts |
8864 | executed with the `.' or `source' builtins (*note Bourne Shell | |
28ef6c31 | 8865 | Builtins::). |
d166f048 | 8866 | |
bb70624e | 8867 | * Bash includes the `shopt' builtin, for finer control of shell |
d3ad40de CR |
8868 | optional capabilities (*note The Shopt Builtin::), and allows |
8869 | these options to be set and unset at shell invocation (*note | |
8870 | Invoking Bash::). | |
d166f048 | 8871 | |
bb70624e | 8872 | * Bash has much more optional behavior controllable with the `set' |
28ef6c31 | 8873 | builtin (*note The Set Builtin::). |
cce855bc | 8874 | |
5e13499c CR |
8875 | * The `-x' (`xtrace') option displays commands other than simple |
8876 | commands when performing an execution trace (*note The Set | |
8877 | Builtin::). | |
8878 | ||
28ef6c31 | 8879 | * The `test' builtin (*note Bourne Shell Builtins::) is slightly |
bb70624e JA |
8880 | different, as it implements the POSIX algorithm, which specifies |
8881 | the behavior based on the number of arguments. | |
ccc6cda3 | 8882 | |
5e13499c CR |
8883 | * Bash includes the `caller' builtin, which displays the context of |
8884 | any active subroutine call (a shell function or a script executed | |
8885 | with the `.' or `source' builtins). This supports the bash | |
8886 | debugger. | |
8887 | ||
28ef6c31 | 8888 | * The `trap' builtin (*note Bourne Shell Builtins::) allows a |
bb70624e | 8889 | `DEBUG' pseudo-signal specification, similar to `EXIT'. Commands |
d3a24ed2 CR |
8890 | specified with a `DEBUG' trap are executed before every simple |
8891 | command, `for' command, `case' command, `select' command, every | |
8892 | arithmetic `for' command, and before the first command executes in | |
8893 | a shell function. The `DEBUG' trap is not inherited by shell | |
8894 | functions unless the function has been given the `trace' attribute | |
8895 | or the `functrace' option has been enabled using the `shopt' | |
8896 | builtin. The `extdebug' shell option has additional effects on the | |
8897 | `DEBUG' trap. | |
d166f048 | 8898 | |
f73dda09 JA |
8899 | The `trap' builtin (*note Bourne Shell Builtins::) allows an `ERR' |
8900 | pseudo-signal specification, similar to `EXIT' and `DEBUG'. | |
8901 | Commands specified with an `ERR' trap are executed after a simple | |
8902 | command fails, with a few exceptions. The `ERR' trap is not | |
d3a24ed2 CR |
8903 | inherited by shell functions unless the `-o errtrace' option to |
8904 | the `set' builtin is enabled. | |
8905 | ||
8906 | The `trap' builtin (*note Bourne Shell Builtins::) allows a | |
8907 | `RETURN' pseudo-signal specification, similar to `EXIT' and | |
8908 | `DEBUG'. Commands specified with an `RETURN' trap are executed | |
8909 | before execution resumes after a shell function or a shell script | |
8910 | executed with `.' or `source' returns. The `RETURN' trap is not | |
8fed3589 CR |
8911 | inherited by shell functions unless the function has been given |
8912 | the `trace' attribute or the `functrace' option has been enabled | |
8913 | using the `shopt' builtin. | |
f73dda09 | 8914 | |
bb70624e | 8915 | * The Bash `type' builtin is more extensive and gives more |
28ef6c31 | 8916 | information about the names it finds (*note Bash Builtins::). |
cce855bc | 8917 | |
bb70624e JA |
8918 | * The Bash `umask' builtin permits a `-p' option to cause the output |
8919 | to be displayed in the form of a `umask' command that may be | |
28ef6c31 | 8920 | reused as input (*note Bourne Shell Builtins::). |
d166f048 | 8921 | |
bb70624e JA |
8922 | * Bash implements a `csh'-like directory stack, and provides the |
8923 | `pushd', `popd', and `dirs' builtins to manipulate it (*note The | |
28ef6c31 | 8924 | Directory Stack::). Bash also makes the directory stack visible |
bb70624e | 8925 | as the value of the `DIRSTACK' shell variable. |
d166f048 | 8926 | |
bb70624e | 8927 | * Bash interprets special backslash-escaped characters in the prompt |
28ef6c31 | 8928 | strings when interactive (*note Printing a Prompt::). |
d166f048 | 8929 | |
bb70624e | 8930 | * The Bash restricted mode is more useful (*note The Restricted |
28ef6c31 | 8931 | Shell::); the SVR4.2 shell restricted mode is too limited. |
ccc6cda3 | 8932 | |
bb70624e | 8933 | * The `disown' builtin can remove a job from the internal shell job |
28ef6c31 | 8934 | table (*note Job Control Builtins::) or suppress the sending of |
bb70624e | 8935 | `SIGHUP' to a job when the shell exits as the result of a `SIGHUP'. |
ccc6cda3 | 8936 | |
1c72c0cd CR |
8937 | * Bash includes a number of features to support a separate debugger |
8938 | for shell scripts. | |
8939 | ||
bb70624e JA |
8940 | * The SVR4.2 shell has two privilege-related builtins (`mldmode' and |
8941 | `priv') not present in Bash. | |
ccc6cda3 | 8942 | |
bb70624e | 8943 | * Bash does not have the `stop' or `newgrp' builtins. |
d166f048 | 8944 | |
bb70624e JA |
8945 | * Bash does not use the `SHACCT' variable or perform shell |
8946 | accounting. | |
d166f048 | 8947 | |
bb70624e | 8948 | * The SVR4.2 `sh' uses a `TIMEOUT' variable like Bash uses `TMOUT'. |
ccc6cda3 | 8949 | |
28ef6c31 | 8950 | |
6a8fd0ed | 8951 | More features unique to Bash may be found in *note Bash Features::. |
ccc6cda3 | 8952 | |
37c41ab1 CR |
8953 | B.1 Implementation Differences From The SVR4.2 Shell |
8954 | ==================================================== | |
ccc6cda3 | 8955 | |
37c41ab1 CR |
8956 | Since Bash is a completely new implementation, it does not suffer from |
8957 | many of the limitations of the SVR4.2 shell. For instance: | |
ccc6cda3 | 8958 | |
bb70624e JA |
8959 | * Bash does not fork a subshell when redirecting into or out of a |
8960 | shell control structure such as an `if' or `while' statement. | |
ccc6cda3 | 8961 | |
bb70624e JA |
8962 | * Bash does not allow unbalanced quotes. The SVR4.2 shell will |
8963 | silently insert a needed closing quote at `EOF' under certain | |
8964 | circumstances. This can be the cause of some hard-to-find errors. | |
ccc6cda3 | 8965 | |
bb70624e JA |
8966 | * The SVR4.2 shell uses a baroque memory management scheme based on |
8967 | trapping `SIGSEGV'. If the shell is started from a process with | |
8968 | `SIGSEGV' blocked (e.g., by using the `system()' C library | |
8969 | function call), it misbehaves badly. | |
ccc6cda3 | 8970 | |
bb70624e JA |
8971 | * In a questionable attempt at security, the SVR4.2 shell, when |
8972 | invoked without the `-p' option, will alter its real and effective | |
8973 | UID and GID if they are less than some magic threshold value, | |
8974 | commonly 100. This can lead to unexpected results. | |
ccc6cda3 | 8975 | |
bb70624e JA |
8976 | * The SVR4.2 shell does not allow users to trap `SIGSEGV', |
8977 | `SIGALRM', or `SIGCHLD'. | |
ccc6cda3 | 8978 | |
bb70624e JA |
8979 | * The SVR4.2 shell does not allow the `IFS', `MAILCHECK', `PATH', |
8980 | `PS1', or `PS2' variables to be unset. | |
ccc6cda3 | 8981 | |
bb70624e | 8982 | * The SVR4.2 shell treats `^' as the undocumented equivalent of `|'. |
ccc6cda3 | 8983 | |
bb70624e JA |
8984 | * Bash allows multiple option arguments when it is invoked (`-x -v'); |
8985 | the SVR4.2 shell allows only one option argument (`-xv'). In | |
8986 | fact, some versions of the shell dump core if the second argument | |
8987 | begins with a `-'. | |
ccc6cda3 | 8988 | |
bb70624e | 8989 | * The SVR4.2 shell exits a script if any builtin fails; Bash exits a |
ac18b312 CR |
8990 | script only if one of the POSIX special builtins fails, and only |
8991 | for certain failures, as enumerated in the POSIX standard. | |
ccc6cda3 | 8992 | |
bb70624e JA |
8993 | * The SVR4.2 shell behaves differently when invoked as `jsh' (it |
8994 | turns on job control). | |
ccc6cda3 JA |
8995 | |
8996 | \1f | |
c2a47ea9 | 8997 | File: bashref.info, Node: GNU Free Documentation License, Next: Indexes, Prev: Major Differences From The Bourne Shell, Up: Top |
d3a24ed2 | 8998 | |
c2a47ea9 CR |
8999 | Appendix C GNU Free Documentation License |
9000 | ***************************************** | |
d3a24ed2 | 9001 | |
1231ac47 | 9002 | Version 1.3, 3 November 2008 |
37c41ab1 | 9003 | |
1231ac47 CR |
9004 | Copyright (C) 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc. |
9005 | `http://fsf.org/' | |
37c41ab1 | 9006 | |
d3a24ed2 CR |
9007 | Everyone is permitted to copy and distribute verbatim copies |
9008 | of this license document, but changing it is not allowed. | |
9009 | ||
9010 | 0. PREAMBLE | |
9011 | ||
9012 | The purpose of this License is to make a manual, textbook, or other | |
9013 | functional and useful document "free" in the sense of freedom: to | |
9014 | assure everyone the effective freedom to copy and redistribute it, | |
9015 | with or without modifying it, either commercially or | |
9016 | noncommercially. Secondarily, this License preserves for the | |
9017 | author and publisher a way to get credit for their work, while not | |
9018 | being considered responsible for modifications made by others. | |
9019 | ||
9020 | This License is a kind of "copyleft", which means that derivative | |
9021 | works of the document must themselves be free in the same sense. | |
9022 | It complements the GNU General Public License, which is a copyleft | |
9023 | license designed for free software. | |
9024 | ||
9025 | We have designed this License in order to use it for manuals for | |
9026 | free software, because free software needs free documentation: a | |
9027 | free program should come with manuals providing the same freedoms | |
9028 | that the software does. But this License is not limited to | |
9029 | software manuals; it can be used for any textual work, regardless | |
9030 | of subject matter or whether it is published as a printed book. | |
9031 | We recommend this License principally for works whose purpose is | |
9032 | instruction or reference. | |
9033 | ||
9034 | 1. APPLICABILITY AND DEFINITIONS | |
9035 | ||
9036 | This License applies to any manual or other work, in any medium, | |
9037 | that contains a notice placed by the copyright holder saying it | |
9038 | can be distributed under the terms of this License. Such a notice | |
9039 | grants a world-wide, royalty-free license, unlimited in duration, | |
9040 | to use that work under the conditions stated herein. The | |
9041 | "Document", below, refers to any such manual or work. Any member | |
9042 | of the public is a licensee, and is addressed as "you". You | |
9043 | accept the license if you copy, modify or distribute the work in a | |
9044 | way requiring permission under copyright law. | |
9045 | ||
9046 | A "Modified Version" of the Document means any work containing the | |
9047 | Document or a portion of it, either copied verbatim, or with | |
9048 | modifications and/or translated into another language. | |
9049 | ||
9050 | A "Secondary Section" is a named appendix or a front-matter section | |
9051 | of the Document that deals exclusively with the relationship of the | |
9052 | publishers or authors of the Document to the Document's overall | |
9053 | subject (or to related matters) and contains nothing that could | |
9054 | fall directly within that overall subject. (Thus, if the Document | |
9055 | is in part a textbook of mathematics, a Secondary Section may not | |
9056 | explain any mathematics.) The relationship could be a matter of | |
9057 | historical connection with the subject or with related matters, or | |
9058 | of legal, commercial, philosophical, ethical or political position | |
9059 | regarding them. | |
9060 | ||
9061 | The "Invariant Sections" are certain Secondary Sections whose | |
9062 | titles are designated, as being those of Invariant Sections, in | |
9063 | the notice that says that the Document is released under this | |
9064 | License. If a section does not fit the above definition of | |
9065 | Secondary then it is not allowed to be designated as Invariant. | |
9066 | The Document may contain zero Invariant Sections. If the Document | |
9067 | does not identify any Invariant Sections then there are none. | |
9068 | ||
9069 | The "Cover Texts" are certain short passages of text that are | |
9070 | listed, as Front-Cover Texts or Back-Cover Texts, in the notice | |
9071 | that says that the Document is released under this License. A | |
9072 | Front-Cover Text may be at most 5 words, and a Back-Cover Text may | |
9073 | be at most 25 words. | |
9074 | ||
9075 | A "Transparent" copy of the Document means a machine-readable copy, | |
9076 | represented in a format whose specification is available to the | |
9077 | general public, that is suitable for revising the document | |
9078 | straightforwardly with generic text editors or (for images | |
9079 | composed of pixels) generic paint programs or (for drawings) some | |
9080 | widely available drawing editor, and that is suitable for input to | |
9081 | text formatters or for automatic translation to a variety of | |
9082 | formats suitable for input to text formatters. A copy made in an | |
9083 | otherwise Transparent file format whose markup, or absence of | |
9084 | markup, has been arranged to thwart or discourage subsequent | |
9085 | modification by readers is not Transparent. An image format is | |
9086 | not Transparent if used for any substantial amount of text. A | |
9087 | copy that is not "Transparent" is called "Opaque". | |
9088 | ||
9089 | Examples of suitable formats for Transparent copies include plain | |
9090 | ASCII without markup, Texinfo input format, LaTeX input format, | |
9091 | SGML or XML using a publicly available DTD, and | |
9092 | standard-conforming simple HTML, PostScript or PDF designed for | |
9093 | human modification. Examples of transparent image formats include | |
9094 | PNG, XCF and JPG. Opaque formats include proprietary formats that | |
9095 | can be read and edited only by proprietary word processors, SGML or | |
9096 | XML for which the DTD and/or processing tools are not generally | |
9097 | available, and the machine-generated HTML, PostScript or PDF | |
9098 | produced by some word processors for output purposes only. | |
9099 | ||
9100 | The "Title Page" means, for a printed book, the title page itself, | |
9101 | plus such following pages as are needed to hold, legibly, the | |
9102 | material this License requires to appear in the title page. For | |
9103 | works in formats which do not have any title page as such, "Title | |
9104 | Page" means the text near the most prominent appearance of the | |
9105 | work's title, preceding the beginning of the body of the text. | |
9106 | ||
1231ac47 CR |
9107 | The "publisher" means any person or entity that distributes copies |
9108 | of the Document to the public. | |
9109 | ||
d3a24ed2 CR |
9110 | A section "Entitled XYZ" means a named subunit of the Document |
9111 | whose title either is precisely XYZ or contains XYZ in parentheses | |
9112 | following text that translates XYZ in another language. (Here XYZ | |
9113 | stands for a specific section name mentioned below, such as | |
9114 | "Acknowledgements", "Dedications", "Endorsements", or "History".) | |
9115 | To "Preserve the Title" of such a section when you modify the | |
9116 | Document means that it remains a section "Entitled XYZ" according | |
9117 | to this definition. | |
9118 | ||
9119 | The Document may include Warranty Disclaimers next to the notice | |
9120 | which states that this License applies to the Document. These | |
9121 | Warranty Disclaimers are considered to be included by reference in | |
9122 | this License, but only as regards disclaiming warranties: any other | |
9123 | implication that these Warranty Disclaimers may have is void and | |
9124 | has no effect on the meaning of this License. | |
9125 | ||
9126 | 2. VERBATIM COPYING | |
9127 | ||
9128 | You may copy and distribute the Document in any medium, either | |
9129 | commercially or noncommercially, provided that this License, the | |
9130 | copyright notices, and the license notice saying this License | |
9131 | applies to the Document are reproduced in all copies, and that you | |
9132 | add no other conditions whatsoever to those of this License. You | |
9133 | may not use technical measures to obstruct or control the reading | |
9134 | or further copying of the copies you make or distribute. However, | |
9135 | you may accept compensation in exchange for copies. If you | |
9136 | distribute a large enough number of copies you must also follow | |
9137 | the conditions in section 3. | |
9138 | ||
9139 | You may also lend copies, under the same conditions stated above, | |
9140 | and you may publicly display copies. | |
9141 | ||
9142 | 3. COPYING IN QUANTITY | |
9143 | ||
9144 | If you publish printed copies (or copies in media that commonly | |
9145 | have printed covers) of the Document, numbering more than 100, and | |
9146 | the Document's license notice requires Cover Texts, you must | |
9147 | enclose the copies in covers that carry, clearly and legibly, all | |
9148 | these Cover Texts: Front-Cover Texts on the front cover, and | |
9149 | Back-Cover Texts on the back cover. Both covers must also clearly | |
9150 | and legibly identify you as the publisher of these copies. The | |
9151 | front cover must present the full title with all words of the | |
9152 | title equally prominent and visible. You may add other material | |
9153 | on the covers in addition. Copying with changes limited to the | |
9154 | covers, as long as they preserve the title of the Document and | |
9155 | satisfy these conditions, can be treated as verbatim copying in | |
9156 | other respects. | |
9157 | ||
9158 | If the required texts for either cover are too voluminous to fit | |
9159 | legibly, you should put the first ones listed (as many as fit | |
9160 | reasonably) on the actual cover, and continue the rest onto | |
9161 | adjacent pages. | |
9162 | ||
9163 | If you publish or distribute Opaque copies of the Document | |
9164 | numbering more than 100, you must either include a | |
9165 | machine-readable Transparent copy along with each Opaque copy, or | |
9166 | state in or with each Opaque copy a computer-network location from | |
9167 | which the general network-using public has access to download | |
9168 | using public-standard network protocols a complete Transparent | |
9169 | copy of the Document, free of added material. If you use the | |
9170 | latter option, you must take reasonably prudent steps, when you | |
9171 | begin distribution of Opaque copies in quantity, to ensure that | |
9172 | this Transparent copy will remain thus accessible at the stated | |
9173 | location until at least one year after the last time you | |
9174 | distribute an Opaque copy (directly or through your agents or | |
9175 | retailers) of that edition to the public. | |
9176 | ||
9177 | It is requested, but not required, that you contact the authors of | |
9178 | the Document well before redistributing any large number of | |
9179 | copies, to give them a chance to provide you with an updated | |
9180 | version of the Document. | |
9181 | ||
9182 | 4. MODIFICATIONS | |
9183 | ||
9184 | You may copy and distribute a Modified Version of the Document | |
9185 | under the conditions of sections 2 and 3 above, provided that you | |
9186 | release the Modified Version under precisely this License, with | |
9187 | the Modified Version filling the role of the Document, thus | |
9188 | licensing distribution and modification of the Modified Version to | |
9189 | whoever possesses a copy of it. In addition, you must do these | |
9190 | things in the Modified Version: | |
9191 | ||
9192 | A. Use in the Title Page (and on the covers, if any) a title | |
9193 | distinct from that of the Document, and from those of | |
9194 | previous versions (which should, if there were any, be listed | |
9195 | in the History section of the Document). You may use the | |
9196 | same title as a previous version if the original publisher of | |
9197 | that version gives permission. | |
9198 | ||
9199 | B. List on the Title Page, as authors, one or more persons or | |
9200 | entities responsible for authorship of the modifications in | |
9201 | the Modified Version, together with at least five of the | |
9202 | principal authors of the Document (all of its principal | |
9203 | authors, if it has fewer than five), unless they release you | |
9204 | from this requirement. | |
9205 | ||
9206 | C. State on the Title page the name of the publisher of the | |
9207 | Modified Version, as the publisher. | |
9208 | ||
9209 | D. Preserve all the copyright notices of the Document. | |
9210 | ||
9211 | E. Add an appropriate copyright notice for your modifications | |
9212 | adjacent to the other copyright notices. | |
9213 | ||
9214 | F. Include, immediately after the copyright notices, a license | |
9215 | notice giving the public permission to use the Modified | |
9216 | Version under the terms of this License, in the form shown in | |
9217 | the Addendum below. | |
9218 | ||
9219 | G. Preserve in that license notice the full lists of Invariant | |
9220 | Sections and required Cover Texts given in the Document's | |
9221 | license notice. | |
9222 | ||
9223 | H. Include an unaltered copy of this License. | |
9224 | ||
9225 | I. Preserve the section Entitled "History", Preserve its Title, | |
9226 | and add to it an item stating at least the title, year, new | |
9227 | authors, and publisher of the Modified Version as given on | |
9228 | the Title Page. If there is no section Entitled "History" in | |
9229 | the Document, create one stating the title, year, authors, | |
9230 | and publisher of the Document as given on its Title Page, | |
9231 | then add an item describing the Modified Version as stated in | |
9232 | the previous sentence. | |
9233 | ||
9234 | J. Preserve the network location, if any, given in the Document | |
9235 | for public access to a Transparent copy of the Document, and | |
9236 | likewise the network locations given in the Document for | |
9237 | previous versions it was based on. These may be placed in | |
9238 | the "History" section. You may omit a network location for a | |
9239 | work that was published at least four years before the | |
9240 | Document itself, or if the original publisher of the version | |
9241 | it refers to gives permission. | |
9242 | ||
9243 | K. For any section Entitled "Acknowledgements" or "Dedications", | |
9244 | Preserve the Title of the section, and preserve in the | |
9245 | section all the substance and tone of each of the contributor | |
9246 | acknowledgements and/or dedications given therein. | |
9247 | ||
9248 | L. Preserve all the Invariant Sections of the Document, | |
9249 | unaltered in their text and in their titles. Section numbers | |
9250 | or the equivalent are not considered part of the section | |
9251 | titles. | |
9252 | ||
9253 | M. Delete any section Entitled "Endorsements". Such a section | |
9254 | may not be included in the Modified Version. | |
9255 | ||
9256 | N. Do not retitle any existing section to be Entitled | |
9257 | "Endorsements" or to conflict in title with any Invariant | |
9258 | Section. | |
9259 | ||
9260 | O. Preserve any Warranty Disclaimers. | |
9261 | ||
9262 | If the Modified Version includes new front-matter sections or | |
9263 | appendices that qualify as Secondary Sections and contain no | |
9264 | material copied from the Document, you may at your option | |
9265 | designate some or all of these sections as invariant. To do this, | |
9266 | add their titles to the list of Invariant Sections in the Modified | |
9267 | Version's license notice. These titles must be distinct from any | |
9268 | other section titles. | |
9269 | ||
9270 | You may add a section Entitled "Endorsements", provided it contains | |
9271 | nothing but endorsements of your Modified Version by various | |
9272 | parties--for example, statements of peer review or that the text | |
9273 | has been approved by an organization as the authoritative | |
9274 | definition of a standard. | |
9275 | ||
9276 | You may add a passage of up to five words as a Front-Cover Text, | |
9277 | and a passage of up to 25 words as a Back-Cover Text, to the end | |
9278 | of the list of Cover Texts in the Modified Version. Only one | |
9279 | passage of Front-Cover Text and one of Back-Cover Text may be | |
9280 | added by (or through arrangements made by) any one entity. If the | |
9281 | Document already includes a cover text for the same cover, | |
9282 | previously added by you or by arrangement made by the same entity | |
9283 | you are acting on behalf of, you may not add another; but you may | |
9284 | replace the old one, on explicit permission from the previous | |
9285 | publisher that added the old one. | |
9286 | ||
9287 | The author(s) and publisher(s) of the Document do not by this | |
9288 | License give permission to use their names for publicity for or to | |
9289 | assert or imply endorsement of any Modified Version. | |
9290 | ||
9291 | 5. COMBINING DOCUMENTS | |
9292 | ||
9293 | You may combine the Document with other documents released under | |
9294 | this License, under the terms defined in section 4 above for | |
9295 | modified versions, provided that you include in the combination | |
9296 | all of the Invariant Sections of all of the original documents, | |
9297 | unmodified, and list them all as Invariant Sections of your | |
9298 | combined work in its license notice, and that you preserve all | |
9299 | their Warranty Disclaimers. | |
9300 | ||
9301 | The combined work need only contain one copy of this License, and | |
9302 | multiple identical Invariant Sections may be replaced with a single | |
9303 | copy. If there are multiple Invariant Sections with the same name | |
9304 | but different contents, make the title of each such section unique | |
9305 | by adding at the end of it, in parentheses, the name of the | |
9306 | original author or publisher of that section if known, or else a | |
9307 | unique number. Make the same adjustment to the section titles in | |
9308 | the list of Invariant Sections in the license notice of the | |
9309 | combined work. | |
9310 | ||
9311 | In the combination, you must combine any sections Entitled | |
9312 | "History" in the various original documents, forming one section | |
9313 | Entitled "History"; likewise combine any sections Entitled | |
9314 | "Acknowledgements", and any sections Entitled "Dedications". You | |
9315 | must delete all sections Entitled "Endorsements." | |
9316 | ||
9317 | 6. COLLECTIONS OF DOCUMENTS | |
9318 | ||
9319 | You may make a collection consisting of the Document and other | |
9320 | documents released under this License, and replace the individual | |
9321 | copies of this License in the various documents with a single copy | |
9322 | that is included in the collection, provided that you follow the | |
9323 | rules of this License for verbatim copying of each of the | |
9324 | documents in all other respects. | |
9325 | ||
9326 | You may extract a single document from such a collection, and | |
9327 | distribute it individually under this License, provided you insert | |
9328 | a copy of this License into the extracted document, and follow | |
9329 | this License in all other respects regarding verbatim copying of | |
9330 | that document. | |
9331 | ||
9332 | 7. AGGREGATION WITH INDEPENDENT WORKS | |
9333 | ||
9334 | A compilation of the Document or its derivatives with other | |
9335 | separate and independent documents or works, in or on a volume of | |
9336 | a storage or distribution medium, is called an "aggregate" if the | |
9337 | copyright resulting from the compilation is not used to limit the | |
9338 | legal rights of the compilation's users beyond what the individual | |
c2a47ea9 | 9339 | works permit. When the Document is included in an aggregate, this |
d3a24ed2 CR |
9340 | License does not apply to the other works in the aggregate which |
9341 | are not themselves derivative works of the Document. | |
9342 | ||
9343 | If the Cover Text requirement of section 3 is applicable to these | |
9344 | copies of the Document, then if the Document is less than one half | |
9345 | of the entire aggregate, the Document's Cover Texts may be placed | |
9346 | on covers that bracket the Document within the aggregate, or the | |
9347 | electronic equivalent of covers if the Document is in electronic | |
9348 | form. Otherwise they must appear on printed covers that bracket | |
9349 | the whole aggregate. | |
9350 | ||
9351 | 8. TRANSLATION | |
9352 | ||
9353 | Translation is considered a kind of modification, so you may | |
9354 | distribute translations of the Document under the terms of section | |
9355 | 4. Replacing Invariant Sections with translations requires special | |
9356 | permission from their copyright holders, but you may include | |
9357 | translations of some or all Invariant Sections in addition to the | |
9358 | original versions of these Invariant Sections. You may include a | |
9359 | translation of this License, and all the license notices in the | |
9360 | Document, and any Warranty Disclaimers, provided that you also | |
9361 | include the original English version of this License and the | |
9362 | original versions of those notices and disclaimers. In case of a | |
9363 | disagreement between the translation and the original version of | |
9364 | this License or a notice or disclaimer, the original version will | |
9365 | prevail. | |
9366 | ||
9367 | If a section in the Document is Entitled "Acknowledgements", | |
9368 | "Dedications", or "History", the requirement (section 4) to | |
9369 | Preserve its Title (section 1) will typically require changing the | |
9370 | actual title. | |
9371 | ||
9372 | 9. TERMINATION | |
9373 | ||
9374 | You may not copy, modify, sublicense, or distribute the Document | |
1231ac47 CR |
9375 | except as expressly provided under this License. Any attempt |
9376 | otherwise to copy, modify, sublicense, or distribute it is void, | |
9377 | and will automatically terminate your rights under this License. | |
9378 | ||
9379 | However, if you cease all violation of this License, then your | |
9380 | license from a particular copyright holder is reinstated (a) | |
9381 | provisionally, unless and until the copyright holder explicitly | |
9382 | and finally terminates your license, and (b) permanently, if the | |
9383 | copyright holder fails to notify you of the violation by some | |
9384 | reasonable means prior to 60 days after the cessation. | |
9385 | ||
9386 | Moreover, your license from a particular copyright holder is | |
9387 | reinstated permanently if the copyright holder notifies you of the | |
9388 | violation by some reasonable means, this is the first time you have | |
9389 | received notice of violation of this License (for any work) from | |
9390 | that copyright holder, and you cure the violation prior to 30 days | |
9391 | after your receipt of the notice. | |
9392 | ||
9393 | Termination of your rights under this section does not terminate | |
9394 | the licenses of parties who have received copies or rights from | |
9395 | you under this License. If your rights have been terminated and | |
9396 | not permanently reinstated, receipt of a copy of some or all of | |
9397 | the same material does not give you any rights to use it. | |
d3a24ed2 CR |
9398 | |
9399 | 10. FUTURE REVISIONS OF THIS LICENSE | |
9400 | ||
9401 | The Free Software Foundation may publish new, revised versions of | |
9402 | the GNU Free Documentation License from time to time. Such new | |
9403 | versions will be similar in spirit to the present version, but may | |
9404 | differ in detail to address new problems or concerns. See | |
9405 | `http://www.gnu.org/copyleft/'. | |
9406 | ||
9407 | Each version of the License is given a distinguishing version | |
9408 | number. If the Document specifies that a particular numbered | |
9409 | version of this License "or any later version" applies to it, you | |
9410 | have the option of following the terms and conditions either of | |
9411 | that specified version or of any later version that has been | |
9412 | published (not as a draft) by the Free Software Foundation. If | |
9413 | the Document does not specify a version number of this License, | |
9414 | you may choose any version ever published (not as a draft) by the | |
1231ac47 CR |
9415 | Free Software Foundation. If the Document specifies that a proxy |
9416 | can decide which future versions of this License can be used, that | |
9417 | proxy's public statement of acceptance of a version permanently | |
9418 | authorizes you to choose that version for the Document. | |
9419 | ||
9420 | 11. RELICENSING | |
9421 | ||
9422 | "Massive Multiauthor Collaboration Site" (or "MMC Site") means any | |
9423 | World Wide Web server that publishes copyrightable works and also | |
9424 | provides prominent facilities for anybody to edit those works. A | |
9425 | public wiki that anybody can edit is an example of such a server. | |
9426 | A "Massive Multiauthor Collaboration" (or "MMC") contained in the | |
9427 | site means any set of copyrightable works thus published on the MMC | |
9428 | site. | |
9429 | ||
9430 | "CC-BY-SA" means the Creative Commons Attribution-Share Alike 3.0 | |
9431 | license published by Creative Commons Corporation, a not-for-profit | |
9432 | corporation with a principal place of business in San Francisco, | |
9433 | California, as well as future copyleft versions of that license | |
9434 | published by that same organization. | |
9435 | ||
9436 | "Incorporate" means to publish or republish a Document, in whole or | |
9437 | in part, as part of another Document. | |
9438 | ||
9439 | An MMC is "eligible for relicensing" if it is licensed under this | |
9440 | License, and if all works that were first published under this | |
9441 | License somewhere other than this MMC, and subsequently | |
9442 | incorporated in whole or in part into the MMC, (1) had no cover | |
9443 | texts or invariant sections, and (2) were thus incorporated prior | |
9444 | to November 1, 2008. | |
9445 | ||
9446 | The operator of an MMC Site may republish an MMC contained in the | |
9447 | site under CC-BY-SA on the same site at any time before August 1, | |
9448 | 2009, provided the MMC is eligible for relicensing. | |
9449 | ||
d3a24ed2 | 9450 | |
c2a47ea9 CR |
9451 | ADDENDUM: How to use this License for your documents |
9452 | ==================================================== | |
d3a24ed2 | 9453 | |
37c41ab1 | 9454 | To use this License in a document you have written, include a copy of |
d3a24ed2 CR |
9455 | the License in the document and put the following copyright and license |
9456 | notices just after the title page: | |
9457 | ||
9458 | Copyright (C) YEAR YOUR NAME. | |
9459 | Permission is granted to copy, distribute and/or modify this document | |
1231ac47 | 9460 | under the terms of the GNU Free Documentation License, Version 1.3 |
d3a24ed2 | 9461 | or any later version published by the Free Software Foundation; |
c2a47ea9 CR |
9462 | with no Invariant Sections, no Front-Cover Texts, and no Back-Cover |
9463 | Texts. A copy of the license is included in the section entitled ``GNU | |
d3a24ed2 CR |
9464 | Free Documentation License''. |
9465 | ||
9466 | If you have Invariant Sections, Front-Cover Texts and Back-Cover | |
9467 | Texts, replace the "with...Texts." line with this: | |
9468 | ||
9469 | with the Invariant Sections being LIST THEIR TITLES, with | |
9470 | the Front-Cover Texts being LIST, and with the Back-Cover Texts | |
9471 | being LIST. | |
9472 | ||
9473 | If you have Invariant Sections without Cover Texts, or some other | |
9474 | combination of the three, merge those two alternatives to suit the | |
9475 | situation. | |
9476 | ||
9477 | If your document contains nontrivial examples of program code, we | |
9478 | recommend releasing these examples in parallel under your choice of | |
9479 | free software license, such as the GNU General Public License, to | |
9480 | permit their use in free software. | |
9481 | ||
9482 | \1f | |
c2a47ea9 | 9483 | File: bashref.info, Node: Indexes, Prev: GNU Free Documentation License, Up: Top |
d3ad40de CR |
9484 | |
9485 | Appendix D Indexes | |
9486 | ****************** | |
9487 | ||
9488 | * Menu: | |
9489 | ||
9490 | * Builtin Index:: Index of Bash builtin commands. | |
9491 | * Reserved Word Index:: Index of Bash reserved words. | |
9492 | * Variable Index:: Quick reference helps you find the | |
9493 | variable you want. | |
9494 | * Function Index:: Index of bindable Readline functions. | |
9495 | * Concept Index:: General index for concepts described in | |
9496 | this manual. | |
9497 | ||
9498 | \1f | |
9499 | File: bashref.info, Node: Builtin Index, Next: Reserved Word Index, Up: Indexes | |
5cfe250d | 9500 | |
d3ad40de CR |
9501 | D.1 Index of Shell Builtin Commands |
9502 | =================================== | |
ccc6cda3 | 9503 | |
37c41ab1 | 9504 | \0\b[index\0\b] |
ccc6cda3 JA |
9505 | * Menu: |
9506 | ||
e8ce775d | 9507 | * .: Bourne Shell Builtins. |
37c41ab1 | 9508 | (line 16) |
e8ce775d | 9509 | * :: Bourne Shell Builtins. |
37c41ab1 | 9510 | (line 11) |
e8ce775d | 9511 | * [: Bourne Shell Builtins. |
09767ff0 | 9512 | (line 213) |
37c41ab1 | 9513 | * alias: Bash Builtins. (line 11) |
e8ce775d | 9514 | * bg: Job Control Builtins. |
37c41ab1 CR |
9515 | (line 7) |
9516 | * bind: Bash Builtins. (line 21) | |
e8ce775d | 9517 | * break: Bourne Shell Builtins. |
37c41ab1 | 9518 | (line 29) |
ed35cb4a CR |
9519 | * builtin: Bash Builtins. (line 98) |
9520 | * caller: Bash Builtins. (line 106) | |
e8ce775d | 9521 | * cd: Bourne Shell Builtins. |
37c41ab1 | 9522 | (line 36) |
ed35cb4a | 9523 | * command: Bash Builtins. (line 123) |
bb70624e | 9524 | * compgen: Programmable Completion Builtins. |
37c41ab1 | 9525 | (line 10) |
bb70624e | 9526 | * complete: Programmable Completion Builtins. |
37c41ab1 | 9527 | (line 28) |
6a8fd0ed | 9528 | * compopt: Programmable Completion Builtins. |
a9fac3b2 | 9529 | (line 213) |
e8ce775d | 9530 | * continue: Bourne Shell Builtins. |
37c41ab1 | 9531 | (line 55) |
ed35cb4a | 9532 | * declare: Bash Builtins. (line 142) |
bb70624e | 9533 | * dirs: Directory Stack Builtins. |
37c41ab1 | 9534 | (line 7) |
e8ce775d | 9535 | * disown: Job Control Builtins. |
37c41ab1 | 9536 | (line 83) |
8e1a6eaa CR |
9537 | * echo: Bash Builtins. (line 221) |
9538 | * enable: Bash Builtins. (line 273) | |
e8ce775d | 9539 | * eval: Bourne Shell Builtins. |
37c41ab1 | 9540 | (line 63) |
e8ce775d | 9541 | * exec: Bourne Shell Builtins. |
37c41ab1 | 9542 | (line 70) |
e8ce775d | 9543 | * exit: Bourne Shell Builtins. |
37c41ab1 | 9544 | (line 82) |
e8ce775d | 9545 | * export: Bourne Shell Builtins. |
37c41ab1 | 9546 | (line 88) |
cce855bc | 9547 | * fc: Bash History Builtins. |
37c41ab1 | 9548 | (line 10) |
e8ce775d | 9549 | * fg: Job Control Builtins. |
37c41ab1 | 9550 | (line 16) |
e8ce775d | 9551 | * getopts: Bourne Shell Builtins. |
37c41ab1 | 9552 | (line 103) |
e8ce775d | 9553 | * hash: Bourne Shell Builtins. |
37c41ab1 | 9554 | (line 145) |
8e1a6eaa | 9555 | * help: Bash Builtins. (line 301) |
cce855bc | 9556 | * history: Bash History Builtins. |
37c41ab1 | 9557 | (line 39) |
e8ce775d | 9558 | * jobs: Job Control Builtins. |
37c41ab1 | 9559 | (line 25) |
e8ce775d | 9560 | * kill: Job Control Builtins. |
37c41ab1 | 9561 | (line 57) |
8e1a6eaa CR |
9562 | * let: Bash Builtins. (line 321) |
9563 | * local: Bash Builtins. (line 328) | |
9564 | * logout: Bash Builtins. (line 338) | |
9565 | * mapfile: Bash Builtins. (line 342) | |
bb70624e | 9566 | * popd: Directory Stack Builtins. |
37c41ab1 | 9567 | (line 37) |
db31fb26 | 9568 | * printf: Bash Builtins. (line 387) |
bb70624e | 9569 | * pushd: Directory Stack Builtins. |
37c41ab1 | 9570 | (line 58) |
e8ce775d | 9571 | * pwd: Bourne Shell Builtins. |
37c41ab1 | 9572 | (line 163) |
db31fb26 CR |
9573 | * read: Bash Builtins. (line 412) |
9574 | * readarray: Bash Builtins. (line 484) | |
e8ce775d | 9575 | * readonly: Bourne Shell Builtins. |
37c41ab1 | 9576 | (line 172) |
e8ce775d | 9577 | * return: Bourne Shell Builtins. |
09767ff0 | 9578 | (line 188) |
d3ad40de | 9579 | * set: The Set Builtin. (line 11) |
e8ce775d | 9580 | * shift: Bourne Shell Builtins. |
09767ff0 | 9581 | (line 201) |
d3ad40de | 9582 | * shopt: The Shopt Builtin. (line 9) |
db31fb26 | 9583 | * source: Bash Builtins. (line 492) |
e8ce775d | 9584 | * suspend: Job Control Builtins. |
37c41ab1 | 9585 | (line 94) |
e8ce775d | 9586 | * test: Bourne Shell Builtins. |
09767ff0 | 9587 | (line 213) |
e8ce775d | 9588 | * times: Bourne Shell Builtins. |
09767ff0 | 9589 | (line 281) |
e8ce775d | 9590 | * trap: Bourne Shell Builtins. |
09767ff0 | 9591 | (line 286) |
db31fb26 CR |
9592 | * type: Bash Builtins. (line 496) |
9593 | * typeset: Bash Builtins. (line 527) | |
9594 | * ulimit: Bash Builtins. (line 533) | |
e8ce775d | 9595 | * umask: Bourne Shell Builtins. |
4a8bb13f | 9596 | (line 332) |
6932f7f5 | 9597 | * unalias: Bash Builtins. (line 621) |
e8ce775d | 9598 | * unset: Bourne Shell Builtins. |
4a8bb13f | 9599 | (line 349) |
e8ce775d | 9600 | * wait: Job Control Builtins. |
37c41ab1 | 9601 | (line 73) |
ccc6cda3 JA |
9602 | |
9603 | \1f | |
d3ad40de | 9604 | File: bashref.info, Node: Reserved Word Index, Next: Variable Index, Prev: Builtin Index, Up: Indexes |
ccc6cda3 | 9605 | |
d3ad40de CR |
9606 | D.2 Index of Shell Reserved Words |
9607 | ================================= | |
ccc6cda3 | 9608 | |
37c41ab1 | 9609 | \0\b[index\0\b] |
ccc6cda3 JA |
9610 | * Menu: |
9611 | ||
ed35cb4a | 9612 | * !: Pipelines. (line 9) |
cce855bc | 9613 | * [[: Conditional Constructs. |
ed35cb4a | 9614 | (line 117) |
cce855bc | 9615 | * ]]: Conditional Constructs. |
ed35cb4a | 9616 | (line 117) |
e8ce775d | 9617 | * case: Conditional Constructs. |
37c41ab1 CR |
9618 | (line 28) |
9619 | * do: Looping Constructs. (line 12) | |
9620 | * done: Looping Constructs. (line 12) | |
e8ce775d | 9621 | * elif: Conditional Constructs. |
37c41ab1 | 9622 | (line 7) |
e8ce775d | 9623 | * else: Conditional Constructs. |
37c41ab1 | 9624 | (line 7) |
e8ce775d | 9625 | * esac: Conditional Constructs. |
37c41ab1 | 9626 | (line 28) |
e8ce775d | 9627 | * fi: Conditional Constructs. |
37c41ab1 CR |
9628 | (line 7) |
9629 | * for: Looping Constructs. (line 29) | |
9630 | * function: Shell Functions. (line 13) | |
e8ce775d | 9631 | * if: Conditional Constructs. |
37c41ab1 | 9632 | (line 7) |
e8ce775d | 9633 | * in: Conditional Constructs. |
37c41ab1 | 9634 | (line 28) |
cce855bc | 9635 | * select: Conditional Constructs. |
ed35cb4a | 9636 | (line 76) |
e8ce775d | 9637 | * then: Conditional Constructs. |
37c41ab1 | 9638 | (line 7) |
ed35cb4a | 9639 | * time: Pipelines. (line 9) |
37c41ab1 CR |
9640 | * until: Looping Constructs. (line 12) |
9641 | * while: Looping Constructs. (line 20) | |
9642 | * {: Command Grouping. (line 21) | |
9643 | * }: Command Grouping. (line 21) | |
ccc6cda3 JA |
9644 | |
9645 | \1f | |
d3ad40de | 9646 | File: bashref.info, Node: Variable Index, Next: Function Index, Prev: Reserved Word Index, Up: Indexes |
ccc6cda3 | 9647 | |
d3ad40de CR |
9648 | D.3 Parameter and Variable Index |
9649 | ================================ | |
ccc6cda3 | 9650 | |
37c41ab1 | 9651 | \0\b[index\0\b] |
ccc6cda3 JA |
9652 | * Menu: |
9653 | ||
37c41ab1 CR |
9654 | * !: Special Parameters. (line 46) |
9655 | * #: Special Parameters. (line 30) | |
9656 | * $: Special Parameters. (line 42) | |
9657 | * *: Special Parameters. (line 9) | |
9658 | * -: Special Parameters. (line 37) | |
9659 | * 0: Special Parameters. (line 50) | |
9660 | * ?: Special Parameters. (line 33) | |
9661 | * @: Special Parameters. (line 19) | |
9662 | * _: Special Parameters. (line 59) | |
e8ce775d | 9663 | * auto_resume: Job Control Variables. |
37c41ab1 CR |
9664 | (line 6) |
9665 | * BASH: Bash Variables. (line 13) | |
09767ff0 CR |
9666 | * BASH_ALIASES: Bash Variables. (line 21) |
9667 | * BASH_ARGC: Bash Variables. (line 28) | |
9668 | * BASH_ARGV: Bash Variables. (line 38) | |
9669 | * BASH_CMDS: Bash Variables. (line 48) | |
9670 | * BASH_COMMAND: Bash Variables. (line 55) | |
9671 | * BASH_ENV: Bash Variables. (line 60) | |
9672 | * BASH_EXECUTION_STRING: Bash Variables. (line 66) | |
9673 | * BASH_LINENO: Bash Variables. (line 69) | |
9674 | * BASH_REMATCH: Bash Variables. (line 78) | |
9675 | * BASH_SOURCE: Bash Variables. (line 86) | |
9676 | * BASH_SUBSHELL: Bash Variables. (line 90) | |
9677 | * BASH_VERSINFO: Bash Variables. (line 94) | |
9678 | * BASH_VERSION: Bash Variables. (line 118) | |
d3ad40de | 9679 | * BASHPID: Bash Variables. (line 16) |
e8ce775d | 9680 | * bell-style: Readline Init File Syntax. |
1c72c0cd | 9681 | (line 38) |
eb2bb562 | 9682 | * bind-tty-special-chars: Readline Init File Syntax. |
1c72c0cd | 9683 | (line 45) |
e8ce775d | 9684 | * CDPATH: Bourne Shell Variables. |
37c41ab1 | 9685 | (line 9) |
09767ff0 | 9686 | * COLUMNS: Bash Variables. (line 121) |
e8ce775d | 9687 | * comment-begin: Readline Init File Syntax. |
1c72c0cd | 9688 | (line 50) |
09767ff0 CR |
9689 | * COMP_CWORD: Bash Variables. (line 126) |
9690 | * COMP_KEY: Bash Variables. (line 155) | |
9691 | * COMP_LINE: Bash Variables. (line 132) | |
9692 | * COMP_POINT: Bash Variables. (line 137) | |
9693 | * COMP_TYPE: Bash Variables. (line 145) | |
9694 | * COMP_WORDBREAKS: Bash Variables. (line 159) | |
9695 | * COMP_WORDS: Bash Variables. (line 165) | |
ed35cb4a | 9696 | * completion-prefix-display-length: Readline Init File Syntax. |
1c72c0cd | 9697 | (line 60) |
ed35cb4a CR |
9698 | * completion-query-items: Readline Init File Syntax. |
9699 | (line 67) | |
6932f7f5 | 9700 | * COMPREPLY: Bash Variables. (line 173) |
e8ce775d | 9701 | * convert-meta: Readline Init File Syntax. |
ed35cb4a | 9702 | (line 77) |
6932f7f5 | 9703 | * DIRSTACK: Bash Variables. (line 178) |
e8ce775d | 9704 | * disable-completion: Readline Init File Syntax. |
ed35cb4a | 9705 | (line 83) |
1c72c0cd | 9706 | * editing-mode: Readline Init File Syntax. |
ed35cb4a | 9707 | (line 88) |
6932f7f5 | 9708 | * EMACS: Bash Variables. (line 188) |
e8ce775d | 9709 | * enable-keypad: Readline Init File Syntax. |
ed35cb4a | 9710 | (line 94) |
6932f7f5 | 9711 | * EUID: Bash Variables. (line 193) |
e8ce775d | 9712 | * expand-tilde: Readline Init File Syntax. |
ed35cb4a | 9713 | (line 99) |
6932f7f5 CR |
9714 | * FCEDIT: Bash Variables. (line 197) |
9715 | * FIGNORE: Bash Variables. (line 201) | |
9716 | * FUNCNAME: Bash Variables. (line 207) | |
9717 | * GLOBIGNORE: Bash Variables. (line 216) | |
9718 | * GROUPS: Bash Variables. (line 222) | |
9719 | * histchars: Bash Variables. (line 228) | |
9720 | * HISTCMD: Bash Variables. (line 243) | |
9721 | * HISTCONTROL: Bash Variables. (line 248) | |
9722 | * HISTFILE: Bash Variables. (line 264) | |
9723 | * HISTFILESIZE: Bash Variables. (line 268) | |
9724 | * HISTIGNORE: Bash Variables. (line 276) | |
f73dda09 | 9725 | * history-preserve-point: Readline Init File Syntax. |
ed35cb4a | 9726 | (line 103) |
6a8fd0ed | 9727 | * history-size: Readline Init File Syntax. |
ed35cb4a | 9728 | (line 109) |
6932f7f5 CR |
9729 | * HISTSIZE: Bash Variables. (line 295) |
9730 | * HISTTIMEFORMAT: Bash Variables. (line 299) | |
e8ce775d | 9731 | * HOME: Bourne Shell Variables. |
37c41ab1 | 9732 | (line 13) |
e8ce775d | 9733 | * horizontal-scroll-mode: Readline Init File Syntax. |
ed35cb4a | 9734 | (line 114) |
6932f7f5 CR |
9735 | * HOSTFILE: Bash Variables. (line 308) |
9736 | * HOSTNAME: Bash Variables. (line 319) | |
9737 | * HOSTTYPE: Bash Variables. (line 322) | |
e8ce775d | 9738 | * IFS: Bourne Shell Variables. |
37c41ab1 | 9739 | (line 18) |
6932f7f5 | 9740 | * IGNOREEOF: Bash Variables. (line 325) |
e8ce775d | 9741 | * input-meta: Readline Init File Syntax. |
ed35cb4a | 9742 | (line 121) |
6932f7f5 | 9743 | * INPUTRC: Bash Variables. (line 335) |
b72432fd | 9744 | * isearch-terminators: Readline Init File Syntax. |
6a8fd0ed | 9745 | (line 128) |
ed35cb4a CR |
9746 | * keymap: Readline Init File Syntax. |
9747 | (line 135) | |
6932f7f5 CR |
9748 | * LANG: Bash Variables. (line 339) |
9749 | * LC_ALL: Bash Variables. (line 343) | |
9750 | * LC_COLLATE: Bash Variables. (line 347) | |
9751 | * LC_CTYPE: Bash Variables. (line 354) | |
37c41ab1 | 9752 | * LC_MESSAGES <1>: Locale Translation. (line 11) |
6932f7f5 CR |
9753 | * LC_MESSAGES: Bash Variables. (line 359) |
9754 | * LC_NUMERIC: Bash Variables. (line 363) | |
9755 | * LINENO: Bash Variables. (line 367) | |
9756 | * LINES: Bash Variables. (line 371) | |
9757 | * MACHTYPE: Bash Variables. (line 376) | |
e8ce775d | 9758 | * MAIL: Bourne Shell Variables. |
37c41ab1 | 9759 | (line 22) |
6932f7f5 | 9760 | * MAILCHECK: Bash Variables. (line 380) |
e8ce775d | 9761 | * MAILPATH: Bourne Shell Variables. |
37c41ab1 | 9762 | (line 27) |
e8ce775d | 9763 | * mark-modified-lines: Readline Init File Syntax. |
ed35cb4a | 9764 | (line 148) |
6a8fd0ed | 9765 | * mark-symlinked-directories: Readline Init File Syntax. |
ed35cb4a | 9766 | (line 153) |
6a8fd0ed | 9767 | * match-hidden-files: Readline Init File Syntax. |
ed35cb4a | 9768 | (line 158) |
e8ce775d | 9769 | * meta-flag: Readline Init File Syntax. |
ed35cb4a | 9770 | (line 121) |
6932f7f5 | 9771 | * OLDPWD: Bash Variables. (line 388) |
e8ce775d | 9772 | * OPTARG: Bourne Shell Variables. |
37c41ab1 | 9773 | (line 34) |
6932f7f5 | 9774 | * OPTERR: Bash Variables. (line 391) |
e8ce775d | 9775 | * OPTIND: Bourne Shell Variables. |
37c41ab1 | 9776 | (line 38) |
6932f7f5 | 9777 | * OSTYPE: Bash Variables. (line 395) |
e8ce775d | 9778 | * output-meta: Readline Init File Syntax. |
ed35cb4a | 9779 | (line 165) |
6a8fd0ed | 9780 | * page-completions: Readline Init File Syntax. |
ed35cb4a | 9781 | (line 170) |
e8ce775d | 9782 | * PATH: Bourne Shell Variables. |
37c41ab1 | 9783 | (line 42) |
6932f7f5 CR |
9784 | * PIPESTATUS: Bash Variables. (line 398) |
9785 | * POSIXLY_CORRECT: Bash Variables. (line 403) | |
9786 | * PPID: Bash Variables. (line 412) | |
9787 | * PROMPT_COMMAND: Bash Variables. (line 416) | |
9788 | * PROMPT_DIRTRIM: Bash Variables. (line 420) | |
e8ce775d | 9789 | * PS1: Bourne Shell Variables. |
37c41ab1 | 9790 | (line 48) |
e8ce775d | 9791 | * PS2: Bourne Shell Variables. |
37c41ab1 | 9792 | (line 53) |
6932f7f5 CR |
9793 | * PS3: Bash Variables. (line 426) |
9794 | * PS4: Bash Variables. (line 431) | |
9795 | * PWD: Bash Variables. (line 437) | |
9796 | * RANDOM: Bash Variables. (line 440) | |
9797 | * REPLY: Bash Variables. (line 445) | |
ed35cb4a CR |
9798 | * revert-all-at-newline: Readline Init File Syntax. |
9799 | (line 180) | |
6932f7f5 CR |
9800 | * SECONDS: Bash Variables. (line 448) |
9801 | * SHELL: Bash Variables. (line 454) | |
9802 | * SHELLOPTS: Bash Variables. (line 459) | |
9803 | * SHLVL: Bash Variables. (line 468) | |
e8ce775d | 9804 | * show-all-if-ambiguous: Readline Init File Syntax. |
ed35cb4a | 9805 | (line 186) |
1c72c0cd | 9806 | * show-all-if-unmodified: Readline Init File Syntax. |
ed35cb4a | 9807 | (line 192) |
37c41ab1 CR |
9808 | * TEXTDOMAIN: Locale Translation. (line 11) |
9809 | * TEXTDOMAINDIR: Locale Translation. (line 11) | |
6932f7f5 CR |
9810 | * TIMEFORMAT: Bash Variables. (line 473) |
9811 | * TMOUT: Bash Variables. (line 511) | |
9812 | * TMPDIR: Bash Variables. (line 523) | |
9813 | * UID: Bash Variables. (line 527) | |
e8ce775d | 9814 | * visible-stats: Readline Init File Syntax. |
ed35cb4a | 9815 | (line 201) |
ccc6cda3 JA |
9816 | |
9817 | \1f | |
d3ad40de | 9818 | File: bashref.info, Node: Function Index, Next: Concept Index, Prev: Variable Index, Up: Indexes |
ccc6cda3 | 9819 | |
d3ad40de CR |
9820 | D.4 Function Index |
9821 | ================== | |
ccc6cda3 | 9822 | |
37c41ab1 | 9823 | \0\b[index\0\b] |
ccc6cda3 JA |
9824 | * Menu: |
9825 | ||
e8ce775d | 9826 | * abort (C-g): Miscellaneous Commands. |
37c41ab1 CR |
9827 | (line 10) |
9828 | * accept-line (Newline or Return): Commands For History. (line 6) | |
9829 | * backward-char (C-b): Commands For Moving. (line 15) | |
9830 | * backward-delete-char (Rubout): Commands For Text. (line 11) | |
9831 | * backward-kill-line (C-x Rubout): Commands For Killing. (line 9) | |
9832 | * backward-kill-word (M-<DEL>): Commands For Killing. (line 24) | |
9833 | * backward-word (M-b): Commands For Moving. (line 22) | |
9834 | * beginning-of-history (M-<): Commands For History. (line 20) | |
9835 | * beginning-of-line (C-a): Commands For Moving. (line 6) | |
9836 | * call-last-kbd-macro (C-x e): Keyboard Macros. (line 13) | |
9837 | * capitalize-word (M-c): Commands For Text. (line 46) | |
e8ce775d | 9838 | * character-search (C-]): Miscellaneous Commands. |
37c41ab1 | 9839 | (line 41) |
e8ce775d | 9840 | * character-search-backward (M-C-]): Miscellaneous Commands. |
37c41ab1 | 9841 | (line 46) |
a9fac3b2 | 9842 | * clear-screen (C-l): Commands For Moving. (line 34) |
28ef6c31 | 9843 | * complete (<TAB>): Commands For Completion. |
37c41ab1 | 9844 | (line 6) |
a9fac3b2 CR |
9845 | * copy-backward-word (): Commands For Killing. (line 58) |
9846 | * copy-forward-word (): Commands For Killing. (line 63) | |
9847 | * copy-region-as-kill (): Commands For Killing. (line 54) | |
37c41ab1 | 9848 | * delete-char (C-d): Commands For Text. (line 6) |
b72432fd | 9849 | * delete-char-or-list (): Commands For Completion. |
37c41ab1 | 9850 | (line 34) |
a9fac3b2 | 9851 | * delete-horizontal-space (): Commands For Killing. (line 46) |
37c41ab1 | 9852 | * digit-argument (M-0, M-1, ... M--): Numeric Arguments. (line 6) |
ccc6cda3 | 9853 | * do-uppercase-version (M-a, M-b, M-X, ...): Miscellaneous Commands. |
37c41ab1 CR |
9854 | (line 14) |
9855 | * downcase-word (M-l): Commands For Text. (line 42) | |
e8ce775d | 9856 | * dump-functions (): Miscellaneous Commands. |
37c41ab1 | 9857 | (line 64) |
e8ce775d | 9858 | * dump-macros (): Miscellaneous Commands. |
37c41ab1 | 9859 | (line 76) |
e8ce775d | 9860 | * dump-variables (): Miscellaneous Commands. |
37c41ab1 CR |
9861 | (line 70) |
9862 | * end-kbd-macro (C-x )): Keyboard Macros. (line 9) | |
9863 | * end-of-history (M->): Commands For History. (line 23) | |
9864 | * end-of-line (C-e): Commands For Moving. (line 9) | |
e8ce775d | 9865 | * exchange-point-and-mark (C-x C-x): Miscellaneous Commands. |
37c41ab1 CR |
9866 | (line 36) |
9867 | * forward-backward-delete-char (): Commands For Text. (line 15) | |
9868 | * forward-char (C-f): Commands For Moving. (line 12) | |
9869 | * forward-search-history (C-s): Commands For History. (line 31) | |
9870 | * forward-word (M-f): Commands For Moving. (line 18) | |
9871 | * history-search-backward (): Commands For History. (line 51) | |
9872 | * history-search-forward (): Commands For History. (line 46) | |
e8ce775d | 9873 | * insert-comment (M-#): Miscellaneous Commands. |
37c41ab1 | 9874 | (line 51) |
e8ce775d | 9875 | * insert-completions (M-*): Commands For Completion. |
37c41ab1 CR |
9876 | (line 18) |
9877 | * kill-line (C-k): Commands For Killing. (line 6) | |
a9fac3b2 | 9878 | * kill-region (): Commands For Killing. (line 50) |
37c41ab1 CR |
9879 | * kill-whole-line (): Commands For Killing. (line 15) |
9880 | * kill-word (M-d): Commands For Killing. (line 19) | |
cce855bc | 9881 | * menu-complete (): Commands For Completion. |
37c41ab1 CR |
9882 | (line 22) |
9883 | * next-history (C-n): Commands For History. (line 17) | |
ccc6cda3 | 9884 | * non-incremental-forward-search-history (M-n): Commands For History. |
37c41ab1 | 9885 | (line 41) |
ccc6cda3 | 9886 | * non-incremental-reverse-search-history (M-p): Commands For History. |
37c41ab1 CR |
9887 | (line 36) |
9888 | * overwrite-mode (): Commands For Text. (line 50) | |
e8ce775d | 9889 | * possible-completions (M-?): Commands For Completion. |
37c41ab1 | 9890 | (line 15) |
28ef6c31 | 9891 | * prefix-meta (<ESC>): Miscellaneous Commands. |
37c41ab1 CR |
9892 | (line 18) |
9893 | * previous-history (C-p): Commands For History. (line 13) | |
9894 | * quoted-insert (C-q or C-v): Commands For Text. (line 20) | |
e8ce775d | 9895 | * re-read-init-file (C-x C-r): Miscellaneous Commands. |
37c41ab1 | 9896 | (line 6) |
a9fac3b2 | 9897 | * redraw-current-line (): Commands For Moving. (line 38) |
37c41ab1 | 9898 | * reverse-search-history (C-r): Commands For History. (line 27) |
e8ce775d | 9899 | * revert-line (M-r): Miscellaneous Commands. |
37c41ab1 CR |
9900 | (line 25) |
9901 | * self-insert (a, b, A, 1, !, ...): Commands For Text. (line 24) | |
e8ce775d | 9902 | * set-mark (C-@): Miscellaneous Commands. |
37c41ab1 CR |
9903 | (line 32) |
9904 | * start-kbd-macro (C-x (): Keyboard Macros. (line 6) | |
9905 | * transpose-chars (C-t): Commands For Text. (line 27) | |
9906 | * transpose-words (M-t): Commands For Text. (line 33) | |
28ef6c31 | 9907 | * undo (C-_ or C-x C-u): Miscellaneous Commands. |
37c41ab1 CR |
9908 | (line 22) |
9909 | * universal-argument (): Numeric Arguments. (line 10) | |
a9fac3b2 | 9910 | * unix-filename-rubout (): Commands For Killing. (line 41) |
37c41ab1 | 9911 | * unix-line-discard (C-u): Commands For Killing. (line 12) |
a9fac3b2 | 9912 | * unix-word-rubout (C-w): Commands For Killing. (line 37) |
37c41ab1 | 9913 | * upcase-word (M-u): Commands For Text. (line 38) |
a9fac3b2 | 9914 | * yank (C-y): Commands For Killing. (line 68) |
eb2bb562 | 9915 | * yank-last-arg (M-. or M-_): Commands For History. (line 65) |
37c41ab1 | 9916 | * yank-nth-arg (M-C-y): Commands For History. (line 56) |
a9fac3b2 | 9917 | * yank-pop (M-y): Commands For Killing. (line 71) |
ccc6cda3 JA |
9918 | |
9919 | \1f | |
d3ad40de | 9920 | File: bashref.info, Node: Concept Index, Prev: Function Index, Up: Indexes |
ccc6cda3 | 9921 | |
d3ad40de CR |
9922 | D.5 Concept Index |
9923 | ================= | |
ccc6cda3 | 9924 | |
37c41ab1 | 9925 | \0\b[index\0\b] |
ccc6cda3 JA |
9926 | * Menu: |
9927 | ||
37c41ab1 CR |
9928 | * alias expansion: Aliases. (line 6) |
9929 | * arithmetic evaluation: Shell Arithmetic. (line 6) | |
e8ce775d | 9930 | * arithmetic expansion: Arithmetic Expansion. |
37c41ab1 CR |
9931 | (line 6) |
9932 | * arithmetic, shell: Shell Arithmetic. (line 6) | |
9933 | * arrays: Arrays. (line 6) | |
9934 | * background: Job Control Basics. (line 6) | |
9935 | * Bash configuration: Basic Installation. (line 6) | |
9936 | * Bash installation: Basic Installation. (line 6) | |
e8ce775d | 9937 | * Bourne shell: Basic Shell Features. |
37c41ab1 CR |
9938 | (line 6) |
9939 | * brace expansion: Brace Expansion. (line 6) | |
ac18b312 | 9940 | * builtin: Definitions. (line 17) |
e8ce775d | 9941 | * command editing: Readline Bare Essentials. |
37c41ab1 | 9942 | (line 6) |
e8ce775d | 9943 | * command execution: Command Search and Execution. |
37c41ab1 | 9944 | (line 6) |
cce855bc | 9945 | * command expansion: Simple Command Expansion. |
37c41ab1 | 9946 | (line 6) |
e8ce775d | 9947 | * command history: Bash History Facilities. |
37c41ab1 | 9948 | (line 6) |
e8ce775d | 9949 | * command search: Command Search and Execution. |
37c41ab1 | 9950 | (line 6) |
e8ce775d | 9951 | * command substitution: Command Substitution. |
37c41ab1 | 9952 | (line 6) |
ed35cb4a | 9953 | * command timing: Pipelines. (line 9) |
37c41ab1 | 9954 | * commands, compound: Compound Commands. (line 6) |
e8ce775d | 9955 | * commands, conditional: Conditional Constructs. |
37c41ab1 CR |
9956 | (line 6) |
9957 | * commands, grouping: Command Grouping. (line 6) | |
9958 | * commands, lists: Lists. (line 6) | |
9959 | * commands, looping: Looping Constructs. (line 6) | |
9960 | * commands, pipelines: Pipelines. (line 6) | |
9961 | * commands, shell: Shell Commands. (line 6) | |
9962 | * commands, simple: Simple Commands. (line 6) | |
9963 | * comments, shell: Comments. (line 6) | |
bb70624e | 9964 | * completion builtins: Programmable Completion Builtins. |
37c41ab1 CR |
9965 | (line 6) |
9966 | * configuration: Basic Installation. (line 6) | |
ac18b312 | 9967 | * control operator: Definitions. (line 21) |
8e1a6eaa | 9968 | * coprocess: Coprocesses. (line 6) |
37c41ab1 | 9969 | * directory stack: The Directory Stack. (line 6) |
e8ce775d | 9970 | * editing command lines: Readline Bare Essentials. |
37c41ab1 CR |
9971 | (line 6) |
9972 | * environment: Environment. (line 6) | |
9973 | * evaluation, arithmetic: Shell Arithmetic. (line 6) | |
9974 | * event designators: Event Designators. (line 6) | |
cce855bc | 9975 | * execution environment: Command Execution Environment. |
37c41ab1 CR |
9976 | (line 6) |
9977 | * exit status <1>: Exit Status. (line 6) | |
ed35cb4a | 9978 | * exit status: Definitions. (line 26) |
37c41ab1 | 9979 | * expansion: Shell Expansions. (line 6) |
e8ce775d | 9980 | * expansion, arithmetic: Arithmetic Expansion. |
37c41ab1 CR |
9981 | (line 6) |
9982 | * expansion, brace: Brace Expansion. (line 6) | |
9983 | * expansion, filename: Filename Expansion. (line 9) | |
e8ce775d | 9984 | * expansion, parameter: Shell Parameter Expansion. |
37c41ab1 CR |
9985 | (line 6) |
9986 | * expansion, pathname: Filename Expansion. (line 9) | |
9987 | * expansion, tilde: Tilde Expansion. (line 6) | |
9988 | * expressions, arithmetic: Shell Arithmetic. (line 6) | |
e8ce775d | 9989 | * expressions, conditional: Bash Conditional Expressions. |
37c41ab1 | 9990 | (line 6) |
ed35cb4a CR |
9991 | * field: Definitions. (line 30) |
9992 | * filename: Definitions. (line 35) | |
37c41ab1 CR |
9993 | * filename expansion: Filename Expansion. (line 9) |
9994 | * foreground: Job Control Basics. (line 6) | |
9995 | * functions, shell: Shell Functions. (line 6) | |
cce855bc | 9996 | * history builtins: Bash History Builtins. |
37c41ab1 CR |
9997 | (line 6) |
9998 | * history events: Event Designators. (line 7) | |
9999 | * history expansion: History Interaction. (line 6) | |
e8ce775d | 10000 | * history list: Bash History Facilities. |
37c41ab1 | 10001 | (line 6) |
bb70624e | 10002 | * History, how to use: Programmable Completion Builtins. |
a9fac3b2 | 10003 | (line 225) |
ed35cb4a | 10004 | * identifier: Definitions. (line 51) |
37c41ab1 CR |
10005 | * initialization file, readline: Readline Init File. (line 6) |
10006 | * installation: Basic Installation. (line 6) | |
e8ce775d | 10007 | * interaction, readline: Readline Interaction. |
37c41ab1 CR |
10008 | (line 6) |
10009 | * interactive shell <1>: Interactive Shells. (line 6) | |
ac18b312 | 10010 | * interactive shell: Invoking Bash. (line 127) |
37c41ab1 | 10011 | * internationalization: Locale Translation. (line 6) |
ed35cb4a | 10012 | * job: Definitions. (line 38) |
c2a47ea9 | 10013 | * job control <1>: Job Control Basics. (line 6) |
ed35cb4a | 10014 | * job control: Definitions. (line 42) |
e8ce775d | 10015 | * kill ring: Readline Killing Commands. |
37c41ab1 | 10016 | (line 19) |
e8ce775d | 10017 | * killing text: Readline Killing Commands. |
37c41ab1 CR |
10018 | (line 6) |
10019 | * localization: Locale Translation. (line 6) | |
ac18b312 | 10020 | * login shell: Invoking Bash. (line 124) |
37c41ab1 | 10021 | * matching, pattern: Pattern Matching. (line 6) |
ed35cb4a CR |
10022 | * metacharacter: Definitions. (line 46) |
10023 | * name: Definitions. (line 51) | |
37c41ab1 | 10024 | * native languages: Locale Translation. (line 6) |
e8ce775d | 10025 | * notation, readline: Readline Bare Essentials. |
37c41ab1 | 10026 | (line 6) |
ed35cb4a | 10027 | * operator, shell: Definitions. (line 57) |
e8ce775d | 10028 | * parameter expansion: Shell Parameter Expansion. |
37c41ab1 CR |
10029 | (line 6) |
10030 | * parameters: Shell Parameters. (line 6) | |
e8ce775d | 10031 | * parameters, positional: Positional Parameters. |
37c41ab1 CR |
10032 | (line 6) |
10033 | * parameters, special: Special Parameters. (line 6) | |
10034 | * pathname expansion: Filename Expansion. (line 9) | |
10035 | * pattern matching: Pattern Matching. (line 6) | |
10036 | * pipeline: Pipelines. (line 6) | |
10037 | * POSIX: Definitions. (line 9) | |
10038 | * POSIX Mode: Bash POSIX Mode. (line 6) | |
a9fac3b2 CR |
10039 | * process group: Definitions. (line 62) |
10040 | * process group ID: Definitions. (line 66) | |
e8ce775d | 10041 | * process substitution: Process Substitution. |
37c41ab1 | 10042 | (line 6) |
bb70624e | 10043 | * programmable completion: Programmable Completion. |
37c41ab1 CR |
10044 | (line 6) |
10045 | * prompting: Printing a Prompt. (line 6) | |
10046 | * quoting: Quoting. (line 6) | |
10047 | * quoting, ANSI: ANSI-C Quoting. (line 6) | |
bb70624e | 10048 | * Readline, how to use: Job Control Variables. |
37c41ab1 CR |
10049 | (line 24) |
10050 | * redirection: Redirections. (line 6) | |
a9fac3b2 | 10051 | * reserved word: Definitions. (line 70) |
e8ce775d | 10052 | * restricted shell: The Restricted Shell. |
37c41ab1 | 10053 | (line 6) |
a9fac3b2 | 10054 | * return status: Definitions. (line 75) |
37c41ab1 CR |
10055 | * shell arithmetic: Shell Arithmetic. (line 6) |
10056 | * shell function: Shell Functions. (line 6) | |
10057 | * shell script: Shell Scripts. (line 6) | |
10058 | * shell variable: Shell Parameters. (line 6) | |
10059 | * shell, interactive: Interactive Shells. (line 6) | |
a9fac3b2 | 10060 | * signal: Definitions. (line 78) |
37c41ab1 | 10061 | * signal handling: Signals. (line 6) |
c2a47ea9 | 10062 | * special builtin <1>: Special Builtins. (line 6) |
a9fac3b2 | 10063 | * special builtin: Definitions. (line 82) |
37c41ab1 CR |
10064 | * startup files: Bash Startup Files. (line 6) |
10065 | * suspending jobs: Job Control Basics. (line 6) | |
10066 | * tilde expansion: Tilde Expansion. (line 6) | |
a9fac3b2 | 10067 | * token: Definitions. (line 86) |
37c41ab1 CR |
10068 | * translation, native languages: Locale Translation. (line 6) |
10069 | * variable, shell: Shell Parameters. (line 6) | |
28ef6c31 | 10070 | * variables, readline: Readline Init File Syntax. |
1c72c0cd | 10071 | (line 37) |
a9fac3b2 | 10072 | * word: Definitions. (line 90) |
37c41ab1 | 10073 | * word splitting: Word Splitting. (line 6) |
e8ce775d | 10074 | * yanking text: Readline Killing Commands. |
37c41ab1 | 10075 | (line 6) |
ccc6cda3 JA |
10076 | |
10077 | ||
10078 | \1f | |
10079 | Tag Table: | |
2c471a92 CR |
10080 | Node: Top\7f1338 |
10081 | Node: Introduction\7f3169 | |
10082 | Node: What is Bash?\7f3397 | |
10083 | Node: What is a shell?\7f4510 | |
10084 | Node: Definitions\7f7050 | |
10085 | Node: Basic Shell Features\7f9968 | |
10086 | Node: Shell Syntax\7f11187 | |
10087 | Node: Shell Operation\7f12217 | |
10088 | Node: Quoting\7f13511 | |
10089 | Node: Escape Character\7f14814 | |
10090 | Node: Single Quotes\7f15299 | |
10091 | Node: Double Quotes\7f15647 | |
10092 | Node: ANSI-C Quoting\7f16772 | |
10093 | Node: Locale Translation\7f17728 | |
10094 | Node: Comments\7f18624 | |
10095 | Node: Shell Commands\7f19242 | |
10096 | Node: Simple Commands\7f20066 | |
10097 | Node: Pipelines\7f20697 | |
10098 | Node: Lists\7f22953 | |
10099 | Node: Compound Commands\7f24682 | |
10100 | Node: Looping Constructs\7f25486 | |
10101 | Node: Conditional Constructs\7f27941 | |
10102 | Node: Command Grouping\7f35947 | |
10103 | Node: Coprocesses\7f37426 | |
10104 | Node: Shell Functions\7f39070 | |
10105 | Node: Shell Parameters\7f43624 | |
10106 | Node: Positional Parameters\7f46040 | |
10107 | Node: Special Parameters\7f46940 | |
10108 | Node: Shell Expansions\7f49904 | |
10109 | Node: Brace Expansion\7f51829 | |
10110 | Node: Tilde Expansion\7f54584 | |
10111 | Node: Shell Parameter Expansion\7f56935 | |
10112 | Node: Command Substitution\7f65833 | |
10113 | Node: Arithmetic Expansion\7f67166 | |
10114 | Node: Process Substitution\7f68016 | |
10115 | Node: Word Splitting\7f69066 | |
10116 | Node: Filename Expansion\7f70689 | |
10117 | Node: Pattern Matching\7f72828 | |
10118 | Node: Quote Removal\7f76467 | |
10119 | Node: Redirections\7f76762 | |
10120 | Node: Executing Commands\7f84910 | |
10121 | Node: Simple Command Expansion\7f85580 | |
10122 | Node: Command Search and Execution\7f87510 | |
10123 | Node: Command Execution Environment\7f89847 | |
10124 | Node: Environment\7f92833 | |
10125 | Node: Exit Status\7f94493 | |
10126 | Node: Signals\7f96114 | |
10127 | Node: Shell Scripts\7f98082 | |
10128 | Node: Shell Builtin Commands\7f100600 | |
10129 | Node: Bourne Shell Builtins\7f102628 | |
10130 | Node: Bash Builtins\7f120004 | |
10131 | Node: Modifying Shell Behavior\7f144303 | |
10132 | Node: The Set Builtin\7f144648 | |
10133 | Node: The Shopt Builtin\7f154160 | |
10134 | Node: Special Builtins\7f165022 | |
10135 | Node: Shell Variables\7f166001 | |
10136 | Node: Bourne Shell Variables\7f166441 | |
10137 | Node: Bash Variables\7f168422 | |
10138 | Node: Bash Features\7f190761 | |
10139 | Node: Invoking Bash\7f191644 | |
10140 | Node: Bash Startup Files\7f197453 | |
10141 | Node: Interactive Shells\7f202422 | |
10142 | Node: What is an Interactive Shell?\7f202832 | |
10143 | Node: Is this Shell Interactive?\7f203481 | |
10144 | Node: Interactive Shell Behavior\7f204296 | |
10145 | Node: Bash Conditional Expressions\7f207576 | |
10146 | Node: Shell Arithmetic\7f211101 | |
10147 | Node: Aliases\7f213847 | |
10148 | Node: Arrays\7f216419 | |
10149 | Node: The Directory Stack\7f220377 | |
10150 | Node: Directory Stack Builtins\7f221091 | |
10151 | Node: Printing a Prompt\7f223983 | |
10152 | Node: The Restricted Shell\7f226735 | |
10153 | Node: Bash POSIX Mode\7f228567 | |
10154 | Node: Job Control\7f236420 | |
10155 | Node: Job Control Basics\7f236880 | |
10156 | Node: Job Control Builtins\7f241597 | |
10157 | Node: Job Control Variables\7f245961 | |
10158 | Node: Command Line Editing\7f247119 | |
10159 | Node: Introduction and Notation\7f248686 | |
10160 | Node: Readline Interaction\7f250308 | |
10161 | Node: Readline Bare Essentials\7f251499 | |
10162 | Node: Readline Movement Commands\7f253288 | |
10163 | Node: Readline Killing Commands\7f254253 | |
10164 | Node: Readline Arguments\7f256173 | |
10165 | Node: Searching\7f257217 | |
10166 | Node: Readline Init File\7f259403 | |
10167 | Node: Readline Init File Syntax\7f260550 | |
10168 | Node: Conditional Init Constructs\7f273784 | |
10169 | Node: Sample Init File\7f276317 | |
10170 | Node: Bindable Readline Commands\7f279434 | |
10171 | Node: Commands For Moving\7f280641 | |
10172 | Node: Commands For History\7f281785 | |
10173 | Node: Commands For Text\7f284940 | |
10174 | Node: Commands For Killing\7f287613 | |
10175 | Node: Numeric Arguments\7f290064 | |
10176 | Node: Commands For Completion\7f291203 | |
10177 | Node: Keyboard Macros\7f294970 | |
10178 | Node: Miscellaneous Commands\7f295541 | |
10179 | Node: Readline vi Mode\7f300852 | |
10180 | Node: Programmable Completion\7f301766 | |
10181 | Node: Programmable Completion Builtins\7f307599 | |
10182 | Node: Using History Interactively\7f316025 | |
10183 | Node: Bash History Facilities\7f316709 | |
10184 | Node: Bash History Builtins\7f319623 | |
10185 | Node: History Interaction\7f323480 | |
10186 | Node: Event Designators\7f326185 | |
10187 | Node: Word Designators\7f327200 | |
10188 | Node: Modifiers\7f328839 | |
10189 | Node: Installing Bash\7f330243 | |
10190 | Node: Basic Installation\7f331380 | |
10191 | Node: Compilers and Options\7f334072 | |
10192 | Node: Compiling For Multiple Architectures\7f334813 | |
10193 | Node: Installation Names\7f336477 | |
10194 | Node: Specifying the System Type\7f337295 | |
10195 | Node: Sharing Defaults\7f338011 | |
10196 | Node: Operation Controls\7f338684 | |
10197 | Node: Optional Features\7f339642 | |
10198 | Node: Reporting Bugs\7f349044 | |
10199 | Node: Major Differences From The Bourne Shell\7f350245 | |
10200 | Node: GNU Free Documentation License\7f366932 | |
10201 | Node: Indexes\7f392128 | |
10202 | Node: Builtin Index\7f392582 | |
10203 | Node: Reserved Word Index\7f399409 | |
10204 | Node: Variable Index\7f401857 | |
10205 | Node: Function Index\7f413663 | |
10206 | Node: Concept Index\7f420395 | |
ccc6cda3 JA |
10207 | \1f |
10208 | End Tag Table |