]> git.ipfire.org Git - thirdparty/bash.git/blame - doc/bashref.info
commit bash-20080626 snapshot
[thirdparty/bash.git] / doc / bashref.info
CommitLineData
6a8fd0ed 1This is bashref.info, produced by makeinfo version 4.11 from
ed35cb4a 2/Users/chet/src/bash/src/doc/bashref.texi.
e8ce775d 3
6a8fd0ed 4This text is a brief description of the features that are present in
ed35cb4a 5the Bash shell (version 4.0, 25 May 2008).
d3a24ed2 6
ed35cb4a
CR
7 This is Edition 4.0, last updated 25 May 2008, of `The GNU Bash
8Reference Manual', for `Bash', Version 4.0.
d3a24ed2 9
c2a47ea9 10 Copyright (C) 1988-2007 Free Software Foundation, Inc.
d3a24ed2
CR
11
12 Permission is granted to make and distribute verbatim copies of this
13manual provided the copyright notice and this permission notice are
14preserved 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,
d3ad40de 18 Version 1.2 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
29d25b54
CR
24 (a) The FSF's Back-Cover Text is: "You have the freedom to copy
25 and modify this GNU manual. Buying copies from the FSF supports
26 it in developing GNU and promoting software freedom."
27
37c41ab1 28
d3a24ed2 29INFO-DIR-SECTION Basics
e8ce775d 30START-INFO-DIR-ENTRY
cce855bc 31* Bash: (bash). The GNU Bourne-Again SHell.
e8ce775d 32END-INFO-DIR-ENTRY
ccc6cda3 33
ccc6cda3
JA
34\1f
35File: bashref.info, Node: Top, Next: Introduction, Prev: (dir), Up: (dir)
36
37Bash Features
38*************
39
37c41ab1 40This text is a brief description of the features that are present in
ed35cb4a 41the Bash shell (version 4.0, 25 May 2008).
ccc6cda3 42
ed35cb4a
CR
43 This is Edition 4.0, last updated 25 May 2008, of `The GNU Bash
44Reference Manual', for `Bash', Version 4.0.
ccc6cda3
JA
45
46 Bash contains features that appear in other popular shells, and some
47features that only appear in Bash. Some of the shells that Bash has
48borrowed concepts from are the Bourne Shell (`sh'), the Korn Shell
49(`ksh'), and the C-shell (`csh' and its successor, `tcsh'). The
50following menu breaks the features up into categories based upon which
51one of these other shells inspired the feature.
52
53 This manual is meant as a brief introduction to features found in
54Bash. The Bash manual page should be used as the definitive reference
55on 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
80File: bashref.info, Node: Introduction, Next: Definitions, Prev: Top, Up: Top
81
37c41ab1
CR
821 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
91File: bashref.info, Node: What is Bash?, Next: What is a shell?, Up: Introduction
92
37c41ab1
CR
931.1 What is Bash?
94=================
ccc6cda3 95
37c41ab1 96Bash is the shell, or command language interpreter, for the GNU
bb70624e
JA
97operating system. The name is an acronym for the `Bourne-Again SHell',
98a pun on Stephen Bourne, the author of the direct ancestor of the
d3a24ed2
CR
99current Unix shell `sh', which appeared in the Seventh Edition Bell
100Labs Research version of Unix.
ccc6cda3 101
bb70624e
JA
102 Bash is largely compatible with `sh' and incorporates useful
103features from the Korn shell `ksh' and the C shell `csh'. It is
104intended to be a conformant implementation of the IEEE POSIX Shell and
ac18b312
CR
105Tools portion of the IEEE POSIX specification (IEEE Standard 1003.1).
106It offers functional improvements over `sh' for both interactive and
107programming use.
ccc6cda3 108
bb70624e
JA
109 While the GNU operating system provides other shells, including a
110version of `csh', Bash is the default shell. Like other GNU software,
111Bash is quite portable. It currently runs on nearly every version of
112Unix and a few other operating systems - independently-supported ports
d3a24ed2 113exist for MS-DOS, OS/2, and Windows platforms.
ccc6cda3
JA
114
115\1f
116File: bashref.info, Node: What is a shell?, Prev: What is Bash?, Up: Introduction
117
37c41ab1
CR
1181.2 What is a shell?
119====================
ccc6cda3 120
37c41ab1 121At its base, a shell is simply a macro processor that executes
d3a24ed2
CR
122commands. The term macro processor means functionality where text and
123symbols are expanded to create larger expressions.
124
125 A Unix shell is both a command interpreter and a programming
126language. As a command interpreter, the shell provides the user
127interface to the rich set of GNU utilities. The programming language
d3ad40de 128features allow these utilities to be combined. Files containing
cce855bc 129commands can be created, and become commands themselves. These new
bb70624e 130commands have the same status as system commands in directories such as
d3a24ed2
CR
131`/bin', allowing users or groups to establish custom environments to
132automate their common tasks.
133
134 Shells may be used interactively or non-interactively. In
135interactive mode, they accept input typed from the keyboard. When
136executing 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
139asynchronously. The shell waits for synchronous commands to complete
140before accepting more input; asynchronous commands continue to execute
141in parallel with the shell while it reads and executes additional
142commands. The "redirection" constructs permit fine-grained control of
bb70624e 143the input and output of those commands. Moreover, the shell allows
d3a24ed2 144control over the contents of commands' environments.
bb70624e
JA
145
146 Shells also provide a small set of built-in commands ("builtins")
147implementing functionality impossible or inconvenient to obtain via
148separate utilities. For example, `cd', `break', `continue', and
149`exec') cannot be implemented outside of the shell because they
150directly manipulate the shell itself. The `history', `getopts',
151`kill', or `pwd' builtins, among others, could be implemented in
152separate utilities, but they are more convenient to use as builtin
153commands. All of the shell builtins are described in subsequent
154sections.
ccc6cda3
JA
155
156 While executing commands is essential, most of the power (and
157complexity) of shells is due to their embedded programming languages.
158Like any high-level language, the shell provides variables, flow
159control constructs, quoting, and functions.
160
bb70624e
JA
161 Shells offer features geared specifically for interactive use rather
162than to augment the programming language. These interactive features
d3a24ed2
CR
163include job control, command line editing, command history and aliases.
164Each of these features is described in this manual.
ccc6cda3
JA
165
166\1f
167File: bashref.info, Node: Definitions, Next: Basic Shell Features, Prev: Introduction, Up: Top
168
37c41ab1
CR
1692 Definitions
170*************
ccc6cda3 171
37c41ab1 172These 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
224 Redirections::, for a list of redirection operators.
225
226`process group'
227 A collection of related processes each having the same process
228 group ID.
229
230`process group ID'
d3ad40de 231 A unique identifier that represents a `process group' during its
ccc6cda3
JA
232 lifetime.
233
234`reserved word'
235 A `word' that has a special meaning to the shell. Most reserved
236 words introduce shell flow control constructs, such as `for' and
237 `while'.
238
239`return status'
240 A synonym for `exit status'.
241
242`signal'
bb70624e 243 A mechanism by which a process may be notified by the kernel of an
ccc6cda3
JA
244 event occurring in the system.
245
246`special builtin'
247 A shell builtin command that has been classified as special by the
ac18b312 248 POSIX standard.
ccc6cda3
JA
249
250`token'
251 A sequence of characters considered a single unit by the shell.
252 It is either a `word' or an `operator'.
253
254`word'
255 A `token' that is not an `operator'.
256
257\1f
bb70624e 258File: bashref.info, Node: Basic Shell Features, Next: Shell Builtin Commands, Prev: Definitions, Up: Top
ccc6cda3 259
37c41ab1
CR
2603 Basic Shell Features
261**********************
ccc6cda3 262
37c41ab1
CR
263Bash is an acronym for `Bourne-Again SHell'. The Bourne shell is the
264traditional Unix shell originally written by Stephen Bourne. All of
265the Bourne shell builtin commands are available in Bash, The rules for
266evaluation and quoting are taken from the POSIX specification for the
267`standard' Unix shell.
ccc6cda3 268
cce855bc 269 This chapter briefly summarizes the shell's `building blocks':
ccc6cda3
JA
270commands, control structures, shell functions, shell parameters, shell
271expansions, redirections, which are a way to direct input and output
272from and to named files, and how the shell executes commands.
273
274* Menu:
275
276* Shell Syntax:: What your input means to the shell.
cce855bc 277* Shell Commands:: The types of commands you can use.
ccc6cda3 278* Shell Functions:: Grouping commands by name.
d3a24ed2
CR
279* Shell Parameters:: How the shell stores values.
280* Shell Expansions:: How Bash expands parameters and the various
ccc6cda3
JA
281 expansions available.
282* Redirections:: A way to control where input and output go.
283* Executing Commands:: What happens when you run a command.
284* Shell Scripts:: Executing files of shell commands.
285
286\1f
cce855bc 287File: bashref.info, Node: Shell Syntax, Next: Shell Commands, Up: Basic Shell Features
ccc6cda3 288
37c41ab1
CR
2893.1 Shell Syntax
290================
ccc6cda3
JA
291
292* Menu:
293
294* Shell Operation:: The basic operation of the shell.
ccc6cda3 295* Quoting:: How to remove the special meaning from characters.
ccc6cda3
JA
296* Comments:: How to specify comments.
297
bb70624e
JA
298 When the shell reads input, it proceeds through a sequence of
299operations. If the input indicates the beginning of a comment, the
300shell ignores the comment symbol (`#'), and the rest of that line.
301
302 Otherwise, roughly speaking, the shell reads its input and divides
303the input into words and operators, employing the quoting rules to
304select which meanings to assign various words and characters.
305
306 The shell then parses these tokens into commands and other
307constructs, removes the special meaning of certain words or characters,
308expands others, redirects input and output as needed, executes the
309specified command, waits for the command's exit status, and makes that
310exit status available for further inspection or processing.
311
ccc6cda3
JA
312\1f
313File: bashref.info, Node: Shell Operation, Next: Quoting, Up: Shell Syntax
314
37c41ab1
CR
3153.1.1 Shell Operation
316---------------------
ccc6cda3 317
37c41ab1 318The following is a brief description of the shell's operation when it
ccc6cda3
JA
319reads and executes a command. Basically, the shell does the following:
320
28ef6c31 321 1. Reads its input from a file (*note Shell Scripts::), from a string
ccc6cda3 322 supplied as an argument to the `-c' invocation option (*note
28ef6c31 323 Invoking Bash::), or from the user's terminal.
ccc6cda3
JA
324
325 2. Breaks the input into words and operators, obeying the quoting
6a8fd0ed 326 rules described in *note Quoting::. These tokens are separated by
ccc6cda3 327 `metacharacters'. Alias expansion is performed by this step
28ef6c31 328 (*note Aliases::).
ccc6cda3 329
cce855bc 330 3. Parses the tokens into simple and compound commands (*note Shell
28ef6c31 331 Commands::).
ccc6cda3 332
28ef6c31 333 4. Performs the various shell expansions (*note Shell Expansions::),
ccc6cda3 334 breaking the expanded tokens into lists of filenames (*note
28ef6c31 335 Filename Expansion::) and commands and arguments.
ccc6cda3 336
28ef6c31 337 5. Performs any necessary redirections (*note Redirections::) and
ccc6cda3
JA
338 removes the redirection operators and their operands from the
339 argument list.
340
28ef6c31 341 6. Executes the command (*note Executing Commands::).
ccc6cda3
JA
342
343 7. Optionally waits for the command to complete and collects its exit
28ef6c31 344 status (*note Exit Status::).
ccc6cda3
JA
345
346
347\1f
348File: bashref.info, Node: Quoting, Next: Comments, Prev: Shell Operation, Up: Shell Syntax
349
37c41ab1
CR
3503.1.2 Quoting
351-------------
ccc6cda3
JA
352
353* Menu:
354
355* Escape Character:: How to remove the special meaning from a single
356 character.
357* Single Quotes:: How to inhibit all interpretation of a sequence
358 of characters.
359* Double Quotes:: How to suppress most of the interpretation of a
360 sequence of characters.
361* ANSI-C Quoting:: How to expand ANSI-C sequences in quoted strings.
ccc6cda3
JA
362* Locale Translation:: How to translate strings into different languages.
363
364 Quoting is used to remove the special meaning of certain characters
365or words to the shell. Quoting can be used to disable special
366treatment for special characters, to prevent reserved words from being
367recognized as such, and to prevent parameter expansion.
368
28ef6c31 369 Each of the shell metacharacters (*note Definitions::) has special
cce855bc 370meaning to the shell and must be quoted if it is to represent itself.
01ed5ba4
CR
371When the command history expansion facilities are being used (*note
372History Interaction::), the HISTORY EXPANSION character, usually `!',
373must be quoted to prevent history expansion. *Note Bash History
374Facilities::, for more details concerning history expansion.
d3a24ed2
CR
375
376 There are three quoting mechanisms: the ESCAPE CHARACTER, single
377quotes, and double quotes.
ccc6cda3
JA
378
379\1f
380File: bashref.info, Node: Escape Character, Next: Single Quotes, Up: Quoting
381
37c41ab1
CR
3823.1.2.1 Escape Character
383........................
ccc6cda3 384
37c41ab1
CR
385A non-quoted backslash `\' is the Bash escape character. It preserves
386the literal value of the next character that follows, with the
387exception of `newline'. If a `\newline' pair appears, and the
cce855bc
JA
388backslash itself is not quoted, the `\newline' is treated as a line
389continuation (that is, it is removed from the input stream and
390effectively ignored).
ccc6cda3
JA
391
392\1f
393File: bashref.info, Node: Single Quotes, Next: Double Quotes, Prev: Escape Character, Up: Quoting
394
37c41ab1
CR
3953.1.2.2 Single Quotes
396.....................
ccc6cda3 397
37c41ab1
CR
398Enclosing characters in single quotes (`'') preserves the literal value
399of each character within the quotes. A single quote may not occur
bb70624e 400between single quotes, even when preceded by a backslash.
ccc6cda3
JA
401
402\1f
403File: bashref.info, Node: Double Quotes, Next: ANSI-C Quoting, Prev: Single Quotes, Up: Quoting
404
37c41ab1
CR
4053.1.2.3 Double Quotes
406.....................
ccc6cda3 407
37c41ab1
CR
408Enclosing characters in double quotes (`"') preserves the literal value
409of all characters within the quotes, with the exception of `$', ``',
01ed5ba4
CR
410`\', and, when history expansion is enabled, `!'. The characters `$'
411and ``' retain their special meaning within double quotes (*note Shell
412Expansions::). The backslash retains its special meaning only when
413followed by one of the following characters: `$', ``', `"', `\', or
414`newline'. Within double quotes, backslashes that are followed by one
415of these characters are removed. Backslashes preceding characters
416without a special meaning are left unmodified. A double quote may be
417quoted within double quotes by preceding it with a backslash. If
418enabled, history expansion will be performed unless an `!' appearing in
419double quotes is escaped using a backslash. The backslash preceding
420the `!' is not removed.
ccc6cda3
JA
421
422 The special parameters `*' and `@' have special meaning when in
28ef6c31 423double quotes (*note Shell Parameter Expansion::).
ccc6cda3
JA
424
425\1f
426File: bashref.info, Node: ANSI-C Quoting, Next: Locale Translation, Prev: Double Quotes, Up: Quoting
427
37c41ab1
CR
4283.1.2.4 ANSI-C Quoting
429......................
ccc6cda3 430
37c41ab1
CR
431Words of the form `$'STRING'' are treated specially. The word expands
432to STRING, with backslash-escaped characters replaced as specified by
433the ANSI C standard. Backslash escape sequences, if present, are
434decoded as follows:
ccc6cda3
JA
435
436`\a'
437 alert (bell)
438
439`\b'
440 backspace
441
442`\e'
443 an escape character (not ANSI C)
444
445`\f'
446 form feed
447
448`\n'
449 newline
450
451`\r'
452 carriage return
453
454`\t'
455 horizontal tab
456
457`\v'
458 vertical tab
459
460`\\'
461 backslash
462
bb70624e
JA
463`\''
464 single quote
465
ccc6cda3 466`\NNN'
f73dda09 467 the eight-bit character whose value is the octal value NNN (one to
cce855bc
JA
468 three digits)
469
f73dda09
JA
470`\xHH'
471 the eight-bit character whose value is the hexadecimal value HH
472 (one or two hex digits)
ccc6cda3 473
7117c2d2
JA
474`\cX'
475 a control-X character
476
bb70624e
JA
477The expanded result is single-quoted, as if the dollar sign had not
478been present.
ccc6cda3
JA
479
480\1f
481File: bashref.info, Node: Locale Translation, Prev: ANSI-C Quoting, Up: Quoting
482
37c41ab1
CR
4833.1.2.5 Locale-Specific Translation
484...................................
ccc6cda3 485
37c41ab1
CR
486A double-quoted string preceded by a dollar sign (`$') will cause the
487string to be translated according to the current locale. If the
ccc6cda3
JA
488current locale is `C' or `POSIX', the dollar sign is ignored. If the
489string is translated and replaced, the replacement is double-quoted.
490
28ef6c31
JA
491 Some systems use the message catalog selected by the `LC_MESSAGES'
492shell variable. Others create the name of the message catalog from the
493value of the `TEXTDOMAIN' shell variable, possibly adding a suffix of
494`.mo'. If you use the `TEXTDOMAIN' variable, you may need to set the
495`TEXTDOMAINDIR' variable to the location of the message catalog files.
f73dda09
JA
496Still others use both variables in this fashion:
497`TEXTDOMAINDIR'/`LC_MESSAGES'/LC_MESSAGES/`TEXTDOMAIN'.mo.
28ef6c31 498
ccc6cda3
JA
499\1f
500File: bashref.info, Node: Comments, Prev: Quoting, Up: Shell Syntax
501
37c41ab1
CR
5023.1.3 Comments
503--------------
ccc6cda3 504
37c41ab1 505In a non-interactive shell, or an interactive shell in which the
ccc6cda3 506`interactive_comments' option to the `shopt' builtin is enabled (*note
d3ad40de
CR
507The Shopt Builtin::), a word beginning with `#' causes that word and
508all remaining characters on that line to be ignored. An interactive
509shell without the `interactive_comments' option enabled does not allow
ccc6cda3 510comments. The `interactive_comments' option is on by default in
bb70624e
JA
511interactive shells. *Note Interactive Shells::, for a description of
512what makes a shell interactive.
cce855bc
JA
513
514\1f
515File: bashref.info, Node: Shell Commands, Next: Shell Functions, Prev: Shell Syntax, Up: Basic Shell Features
516
37c41ab1
CR
5173.2 Shell Commands
518==================
cce855bc 519
37c41ab1 520A simple shell command such as `echo a b c' consists of the command
bb70624e
JA
521itself followed by arguments, separated by spaces.
522
523 More complex shell commands are composed of simple commands arranged
524together in a variety of ways: in a pipeline in which the output of one
525command becomes the input of a second, in a loop or conditional
526construct, or in some other grouping.
527
cce855bc
JA
528* Menu:
529
530* Simple Commands:: The most common type of command.
531* Pipelines:: Connecting the input and output of several
532 commands.
533* Lists:: How to execute commands sequentially.
d3a24ed2 534* Compound Commands:: Shell commands for control flow.
ccc6cda3
JA
535
536\1f
cce855bc 537File: bashref.info, Node: Simple Commands, Next: Pipelines, Up: Shell Commands
ccc6cda3 538
37c41ab1
CR
5393.2.1 Simple Commands
540---------------------
ccc6cda3 541
37c41ab1
CR
542A simple command is the kind of command encountered most often. It's
543just a sequence of words separated by `blank's, terminated by one of
544the shell's control operators (*note Definitions::). The first word
28ef6c31 545generally specifies a command to be executed, with the rest of the
bb70624e 546words being that command's arguments.
ccc6cda3 547
28ef6c31 548 The return status (*note Exit Status::) of a simple command is its
bb70624e
JA
549exit status as provided by the POSIX 1003.1 `waitpid' function, or
550128+N if the command was terminated by signal N.
ccc6cda3
JA
551
552\1f
cce855bc 553File: bashref.info, Node: Pipelines, Next: Lists, Prev: Simple Commands, Up: Shell Commands
ccc6cda3 554
37c41ab1
CR
5553.2.2 Pipelines
556---------------
ccc6cda3 557
ed35cb4a
CR
558A `pipeline' is a sequence of simple commands separated by one of the
559control operators `|' or `|&'.
ccc6cda3
JA
560
561 The format for a pipeline is
ed35cb4a 562 [`time' [`-p']] [`!'] COMMAND1 [ [`|' or `|&'] COMMAND2 ...]
ccc6cda3 563
f73dda09
JA
564The output of each command in the pipeline is connected via a pipe to
565the input of the next command. That is, each command reads the
ed35cb4a
CR
566previous command's output. This connection is performed before any
567redirections specified by the command.
568
569 If `|&' is used, the standard error of COMMAND1 is connected to
570COMMAND2's standard input through the pipe; it is shorthand for `2>&1
571|'. This implicit redirection of the standard error is performed after
572any redirections specified by the command.
ccc6cda3
JA
573
574 The reserved word `time' causes timing statistics to be printed for
cce855bc
JA
575the pipeline once it finishes. The statistics currently consist of
576elapsed (wall-clock) time and user and system time consumed by the
577command's execution. The `-p' option changes the output format to that
578specified by POSIX. The `TIMEFORMAT' variable may be set to a format
579string that specifies how the timing information should be displayed.
580*Note Bash Variables::, for a description of the available formats.
581The use of `time' as a reserved word permits the timing of shell
582builtins, shell functions, and pipelines. An external `time' command
583cannot time these easily.
584
28ef6c31 585 If the pipeline is not executed asynchronously (*note Lists::), the
cce855bc 586shell waits for all commands in the pipeline to complete.
ccc6cda3 587
cce855bc 588 Each command in a pipeline is executed in its own subshell (*note
28ef6c31 589Command Execution Environment::). The exit status of a pipeline is the
5e13499c
CR
590exit status of the last command in the pipeline, unless the `pipefail'
591option is enabled (*note The Set Builtin::). If `pipefail' is enabled,
592the pipeline's return status is the value of the last (rightmost)
593command to exit with a non-zero status, or zero if all commands exit
594successfully. If the reserved word `!' precedes the pipeline, the exit
595status is the logical negation of the exit status as described above.
596The shell waits for all commands in the pipeline to terminate before
597returning a value.
ccc6cda3
JA
598
599\1f
d3a24ed2 600File: bashref.info, Node: Lists, Next: Compound Commands, Prev: Pipelines, Up: Shell Commands
ccc6cda3 601
37c41ab1
CR
6023.2.3 Lists of Commands
603-----------------------
ccc6cda3 604
37c41ab1
CR
605A `list' is a sequence of one or more pipelines separated by one of the
606operators `;', `&', `&&', or `||', and optionally terminated by one of
607`;', `&', or a `newline'.
ccc6cda3
JA
608
609 Of these list operators, `&&' and `||' have equal precedence,
610followed by `;' and `&', which have equal precedence.
611
7117c2d2
JA
612 A sequence of one or more newlines may appear in a `list' to delimit
613commands, equivalent to a semicolon.
614
ccc6cda3 615 If a command is terminated by the control operator `&', the shell
cce855bc
JA
616executes the command asynchronously in a subshell. This is known as
617executing the command in the BACKGROUND. The shell does not wait for
bb70624e 618the command to finish, and the return status is 0 (true). When job
28ef6c31 619control is not active (*note Job Control::), the standard input for
bb70624e
JA
620asynchronous commands, in the absence of any explicit redirections, is
621redirected from `/dev/null'.
cce855bc
JA
622
623 Commands separated by a `;' are executed sequentially; the shell
624waits for each command to terminate in turn. The return status is the
625exit status of the last command executed.
ccc6cda3 626
6a8fd0ed
CR
627 AND and OR lists are sequences of one or more pipelines separated by
628the control operators `&&' and `||', respectively. AND and OR lists
629are executed with left associativity.
630
631 An AND list has the form
bb70624e 632 COMMAND1 && COMMAND2
ccc6cda3 633
bb70624e
JA
634COMMAND2 is executed if, and only if, COMMAND1 returns an exit status
635of zero.
ccc6cda3
JA
636
637 An OR list has the form
bb70624e 638 COMMAND1 || COMMAND2
ccc6cda3 639
bb70624e 640COMMAND2 is executed if, and only if, COMMAND1 returns a non-zero exit
ccc6cda3
JA
641status.
642
643 The return status of AND and OR lists is the exit status of the last
644command executed in the list.
645
646\1f
d3a24ed2
CR
647File: bashref.info, Node: Compound Commands, Prev: Lists, Up: Shell Commands
648
37c41ab1
CR
6493.2.4 Compound Commands
650-----------------------
d3a24ed2
CR
651
652* Menu:
653
654* Looping Constructs:: Shell commands for iterative action.
655* Conditional Constructs:: Shell commands for conditional execution.
656* Command Grouping:: Ways to group commands.
657
658 Compound commands are the shell programming constructs. Each
659construct begins with a reserved word or control operator and is
660terminated by a corresponding reserved word or operator. Any
661redirections (*note Redirections::) associated with a compound command
662apply to all commands within that compound command unless explicitly
663overridden.
664
665 Bash provides looping constructs, conditional commands, and
666mechanisms to group commands and execute them as a unit.
667
668\1f
669File: bashref.info, Node: Looping Constructs, Next: Conditional Constructs, Up: Compound Commands
ccc6cda3 670
37c41ab1
CR
6713.2.4.1 Looping Constructs
672..........................
ccc6cda3 673
37c41ab1 674Bash supports the following looping constructs.
ccc6cda3 675
bb70624e 676 Note that wherever a `;' appears in the description of a command's
cce855bc
JA
677syntax, it may be replaced with one or more newlines.
678
ccc6cda3
JA
679`until'
680 The syntax of the `until' command is:
681 until TEST-COMMANDS; do CONSEQUENT-COMMANDS; done
cce855bc
JA
682 Execute CONSEQUENT-COMMANDS as long as TEST-COMMANDS has an exit
683 status which is not zero. The return status is the exit status of
684 the last command executed in CONSEQUENT-COMMANDS, or zero if none
685 was executed.
ccc6cda3
JA
686
687`while'
688 The syntax of the `while' command is:
689 while TEST-COMMANDS; do CONSEQUENT-COMMANDS; done
690
cce855bc
JA
691 Execute CONSEQUENT-COMMANDS as long as TEST-COMMANDS has an exit
692 status of zero. The return status is the exit status of the last
693 command executed in CONSEQUENT-COMMANDS, or zero if none was
694 executed.
ccc6cda3
JA
695
696`for'
697 The syntax of the `for' command is:
698
699 for NAME [in WORDS ...]; do COMMANDS; done
cce855bc
JA
700 Expand WORDS, and execute COMMANDS once for each member in the
701 resultant list, with NAME bound to the current member. If `in
bb70624e
JA
702 WORDS' is not present, the `for' command executes the COMMANDS
703 once for each positional parameter that is set, as if `in "$@"'
28ef6c31 704 had been specified (*note Special Parameters::). The return
bb70624e
JA
705 status is the exit status of the last command that executes. If
706 there are no items in the expansion of WORDS, no commands are
707 executed, and the return status is zero.
708
709 An alternate form of the `for' command is also supported:
710
711 for (( EXPR1 ; EXPR2 ; EXPR3 )) ; do COMMANDS ; done
712 First, the arithmetic expression EXPR1 is evaluated according to
28ef6c31 713 the rules described below (*note Shell Arithmetic::). The
bb70624e
JA
714 arithmetic expression EXPR2 is then evaluated repeatedly until it
715 evaluates to zero. Each time EXPR2 evaluates to a non-zero value,
716 COMMANDS are executed and the arithmetic expression EXPR3 is
717 evaluated. If any expression is omitted, it behaves as if it
718 evaluates to 1. The return value is the exit status of the last
719 command in LIST that is executed, or false if any of the
720 expressions is invalid.
ccc6cda3 721
761783bf 722
28ef6c31 723 The `break' and `continue' builtins (*note Bourne Shell Builtins::)
ccc6cda3
JA
724may be used to control loop execution.
725
726\1f
d3a24ed2 727File: bashref.info, Node: Conditional Constructs, Next: Command Grouping, Prev: Looping Constructs, Up: Compound Commands
ccc6cda3 728
37c41ab1
CR
7293.2.4.2 Conditional Constructs
730..............................
ccc6cda3
JA
731
732`if'
733 The syntax of the `if' command is:
734
735 if TEST-COMMANDS; then
736 CONSEQUENT-COMMANDS;
737 [elif MORE-TEST-COMMANDS; then
738 MORE-CONSEQUENTS;]
739 [else ALTERNATE-CONSEQUENTS;]
740 fi
741
cce855bc
JA
742 The TEST-COMMANDS list is executed, and if its return status is
743 zero, the CONSEQUENT-COMMANDS list is executed. If TEST-COMMANDS
744 returns a non-zero status, each `elif' list is executed in turn,
745 and if its exit status is zero, the corresponding MORE-CONSEQUENTS
746 is executed and the command completes. If `else
747 ALTERNATE-CONSEQUENTS' is present, and the final command in the
748 final `if' or `elif' clause has a non-zero exit status, then
749 ALTERNATE-CONSEQUENTS is executed. The return status is the exit
750 status of the last command executed, or zero if no condition
751 tested true.
ccc6cda3
JA
752
753`case'
754 The syntax of the `case' command is:
755
cce855bc 756 `case WORD in [ [(] PATTERN [| PATTERN]...) COMMAND-LIST ;;]... esac'
ccc6cda3 757
cce855bc 758 `case' will selectively execute the COMMAND-LIST corresponding to
9d2b70f0 759 the first PATTERN that matches WORD. If the shell option
6a8fd0ed 760 `nocasematch' (see the description of `shopt' in *note The Shopt
d3ad40de 761 Builtin::) is enabled, the match is performed without regard to
9d2b70f0 762 the case of alphabetic characters. The `|' is used to separate
cce855bc
JA
763 multiple patterns, and the `)' operator terminates a pattern list.
764 A list of patterns and an associated command-list is known as a
ed35cb4a
CR
765 CLAUSE.
766
767 Each clause must be terminated with `;;', `,&', or `;;&'. The
768 WORD undergoes tilde expansion, parameter expansion, command
cce855bc
JA
769 substitution, arithmetic expansion, and quote removal before
770 matching is attempted. Each PATTERN undergoes tilde expansion,
771 parameter expansion, command substitution, and arithmetic
772 expansion.
773
774 There may be an arbitrary number of `case' clauses, each terminated
ed35cb4a
CR
775 by a `;;', `;&', or `;;&'. The first pattern that matches
776 determines the command-list that is executed.
ccc6cda3
JA
777
778 Here is an example using `case' in a script that could be used to
779 describe one interesting feature of an animal:
780
781 echo -n "Enter the name of an animal: "
782 read ANIMAL
783 echo -n "The $ANIMAL has "
784 case $ANIMAL in
785 horse | dog | cat) echo -n "four";;
786 man | kangaroo ) echo -n "two";;
787 *) echo -n "an unknown number of";;
788 esac
789 echo " legs."
790
ed35cb4a
CR
791 If the `;;' operator is used, no subsequent matches are attempted
792 after the first pattern match. Using `;&' in place of `;;'
793 causes execution to continue with the COMMAND-LIST associated with
794 the next clause, if any. Using `;;&' in place of `;;' causes the
795 shell to test the patterns in the next clause, if any, and execute
796 any associated COMMAND-LIST on a successful match.
797
cce855bc
JA
798 The return status is zero if no PATTERN is matched. Otherwise, the
799 return status is the exit status of the COMMAND-LIST executed.
800
801`select'
802 The `select' construct allows the easy generation of menus. It
803 has almost the same syntax as the `for' command:
804
805 select NAME [in WORDS ...]; do COMMANDS; done
806
807 The list of words following `in' is expanded, generating a list of
808 items. The set of expanded words is printed on the standard error
809 output stream, each preceded by a number. If the `in WORDS' is
810 omitted, the positional parameters are printed, as if `in "$@"'
d3ad40de 811 had been specified. The `PS3' prompt is then displayed and a line
cce855bc
JA
812 is read from the standard input. If the line consists of a number
813 corresponding to one of the displayed words, then the value of
814 NAME is set to that word. If the line is empty, the words and
815 prompt are displayed again. If `EOF' is read, the `select'
816 command completes. Any other value read causes NAME to be set to
817 null. The line read is saved in the variable `REPLY'.
818
f73dda09
JA
819 The COMMANDS are executed after each selection until a `break'
820 command is executed, at which point the `select' command completes.
cce855bc
JA
821
822 Here is an example that allows the user to pick a filename from the
823 current directory, and displays the name and index of the file
824 selected.
825
826 select fname in *;
827 do
828 echo you picked $fname \($REPLY\)
829 break;
830 done
831
ccc6cda3
JA
832`((...))'
833 (( EXPRESSION ))
834
cce855bc 835 The arithmetic EXPRESSION is evaluated according to the rules
28ef6c31 836 described below (*note Shell Arithmetic::). If the value of the
cce855bc
JA
837 expression is non-zero, the return status is 0; otherwise the
838 return status is 1. This is exactly equivalent to
ccc6cda3 839 let "EXPRESSION"
cce855bc
JA
840 *Note Bash Builtins::, for a full description of the `let' builtin.
841
842`[[...]]'
843 [[ EXPRESSION ]]
844
845 Return a status of 0 or 1 depending on the evaluation of the
846 conditional expression EXPRESSION. Expressions are composed of
6a8fd0ed 847 the primaries described below in *note Bash Conditional
cce855bc
JA
848 Expressions::. Word splitting and filename expansion are not
849 performed on the words between the `[[' and `]]'; tilde expansion,
850 parameter and variable expansion, arithmetic expansion, command
851 substitution, process substitution, and quote removal are
d3a24ed2
CR
852 performed. Conditional operators such as `-f' must be unquoted to
853 be recognized as primaries.
cce855bc
JA
854
855 When the `==' and `!=' operators are used, the string to the right
856 of the operator is considered a pattern and matched according to
6a8fd0ed 857 the rules described below in *note Pattern Matching::. If the
9d2b70f0 858 shell option `nocasematch' (see the description of `shopt' in
6a8fd0ed 859 *note The Shopt Builtin::) is enabled, the match is performed
d3ad40de
CR
860 without regard to the case of alphabetic characters. The return
861 value is 0 if the string matches (`==') or does not match
862 (`!=')the pattern, and 1 otherwise. Any part of the pattern may
863 be quoted to force it to be matched as a string.
cce855bc 864
5e13499c
CR
865 An additional binary operator, `=~', is available, with the same
866 precedence as `==' and `!='. When it is used, the string to the
867 right of the operator is considered an extended regular expression
868 and matched accordingly (as in regex3)). The return value is 0 if
869 the string matches the pattern, and 1 otherwise. If the regular
870 expression is syntactically incorrect, the conditional
9d2b70f0 871 expression's return value is 2. If the shell option `nocasematch'
6a8fd0ed 872 (see the description of `shopt' in *note The Shopt Builtin::) is
5e13499c 873 enabled, the match is performed without regard to the case of
3d4e09aa
CR
874 alphabetic characters. Any part of the pattern may be quoted to
875 force it to be matched as a string. Substrings matched by
876 parenthesized subexpressions within the regular expression are
877 saved in the array variable `BASH_REMATCH'. The element of
878 `BASH_REMATCH' with index 0 is the portion of the string matching
879 the entire regular expression. The element of `BASH_REMATCH' with
880 index N is the portion of the string matching the Nth
881 parenthesized subexpression.
5e13499c 882
cce855bc
JA
883 Expressions may be combined using the following operators, listed
884 in decreasing order of precedence:
885
886 `( EXPRESSION )'
887 Returns the value of EXPRESSION. This may be used to
888 override the normal precedence of operators.
889
890 `! EXPRESSION'
891 True if EXPRESSION is false.
892
893 `EXPRESSION1 && EXPRESSION2'
894 True if both EXPRESSION1 and EXPRESSION2 are true.
895
896 `EXPRESSION1 || EXPRESSION2'
897 True if either EXPRESSION1 or EXPRESSION2 is true.
7117c2d2
JA
898 The `&&' and `||' operators do not evaluate EXPRESSION2 if the
899 value of EXPRESSION1 is sufficient to determine the return value
900 of the entire conditional expression.
ccc6cda3 901
761783bf 902
ccc6cda3 903\1f
d3a24ed2 904File: bashref.info, Node: Command Grouping, Prev: Conditional Constructs, Up: Compound Commands
ccc6cda3 905
37c41ab1
CR
9063.2.4.3 Grouping Commands
907.........................
ccc6cda3 908
37c41ab1
CR
909Bash provides two ways to group a list of commands to be executed as a
910unit. When commands are grouped, redirections may be applied to the
ccc6cda3
JA
911entire command list. For example, the output of all the commands in
912the list may be redirected to a single stream.
913
914`()'
915 ( LIST )
916
917 Placing a list of commands between parentheses causes a subshell
d3a24ed2
CR
918 environment to be created (*note Command Execution Environment::),
919 and each of the commands in LIST to be executed in that subshell.
920 Since the LIST is executed in a subshell, variable assignments do
921 not remain in effect after the subshell completes.
ccc6cda3
JA
922
923`{}'
924 { LIST; }
925
926 Placing a list of commands between curly braces causes the list to
927 be executed in the current shell context. No subshell is created.
cce855bc 928 The semicolon (or newline) following LIST is required.
ccc6cda3
JA
929
930 In addition to the creation of a subshell, there is a subtle
931difference between these two constructs due to historical reasons. The
932braces are `reserved words', so they must be separated from the LIST by
d7f49990
CR
933`blank's or other shell metacharacters. The parentheses are
934`operators', and are recognized as separate tokens by the shell even if
935they are not separated from the LIST by whitespace.
ccc6cda3
JA
936
937 The exit status of both of these constructs is the exit status of
938LIST.
939
940\1f
cce855bc 941File: bashref.info, Node: Shell Functions, Next: Shell Parameters, Prev: Shell Commands, Up: Basic Shell Features
ccc6cda3 942
37c41ab1
CR
9433.3 Shell Functions
944===================
ccc6cda3 945
37c41ab1
CR
946Shell functions are a way to group commands for later execution using a
947single name for the group. They are executed just like a "regular"
948command. When the name of a shell function is used as a simple command
949name, the list of commands associated with that function name is
950executed. Shell functions are executed in the current shell context;
951no new process is created to interpret them.
ccc6cda3 952
37c41ab1 953 Functions are declared using this syntax:
d3a24ed2 954 [ `function' ] NAME () COMPOUND-COMMAND [ REDIRECTIONS ]
ccc6cda3
JA
955
956 This defines a shell function named NAME. The reserved word
cce855bc 957`function' is optional. If the `function' reserved word is supplied,
d3a24ed2
CR
958the parentheses are optional. The BODY of the function is the compound
959command COMPOUND-COMMAND (*note Compound Commands::). That command is
960usually a LIST enclosed between { and }, but may be any compound
961command listed above. COMPOUND-COMMAND is executed whenever NAME is
962specified as the name of a command. Any redirections (*note
963Redirections::) associated with the shell function are performed when
964the function is executed.
965
ac18b312
CR
966 A function definition may be deleted using the `-f' option to the
967`unset' builtin (*note Bourne Shell Builtins::).
968
d3a24ed2
CR
969 The exit status of a function definition is zero unless a syntax
970error occurs or a readonly function with the same name already exists.
971When executed, the exit status of a function is the exit status of the
972last command executed in the body.
973
974 Note that for historical reasons, in the most common usage the curly
975braces that surround the body of the function must be separated from
976the body by `blank's or newlines. This is because the braces are
977reserved words and are only recognized as such when they are separated
d7f49990
CR
978from the command list by whitespace or another shell metacharacter.
979Also, when using the braces, the LIST must be terminated by a semicolon,
980a `&', or a newline.
bb70624e 981
ccc6cda3
JA
982 When a function is executed, the arguments to the function become
983the positional parameters during its execution (*note Positional
28ef6c31 984Parameters::). The special parameter `#' that expands to the number of
de8913bd 985positional parameters is updated to reflect the change. Special
d3a24ed2
CR
986parameter `0' is unchanged. The first element of the `FUNCNAME'
987variable is set to the name of the function while the function is
988executing. All other aspects of the shell execution environment are
989identical between a function and its caller with the exception that the
8fed3589
CR
990`DEBUG' and `RETURN' traps are not inherited unless the function has
991been given the `trace' attribute using the `declare' builtin or the `-o
992functrace' option has been enabled with the `set' builtin, (in which
993case all functions inherit the `DEBUG' and `RETURN' traps). *Note
994Bourne Shell Builtins::, for the description of the `trap' builtin.
ccc6cda3
JA
995
996 If the builtin command `return' is executed in a function, the
997function completes and execution resumes with the next command after
d3a24ed2
CR
998the function call. Any command associated with the `RETURN' trap is
999executed before execution resumes. When a function completes, the
1000values of the positional parameters and the special parameter `#' are
1001restored to the values they had prior to the function's execution. If
1002a numeric argument is given to `return', that is the function's return
1003status; otherwise the function's return status is the exit status of
1004the last command executed before the `return'.
ccc6cda3
JA
1005
1006 Variables local to the function may be declared with the `local'
1007builtin. These variables are visible only to the function and the
1008commands it invokes.
1009
d3a24ed2
CR
1010 Function names and definitions may be listed with the `-f' option to
1011the `declare' or `typeset' builtin commands (*note Bash Builtins::).
1012The `-F' option to `declare' or `typeset' will list the function names
1013only (and optionally the source file and line number, if the `extdebug'
1014shell option is enabled). Functions may be exported so that subshells
1015automatically have them defined with the `-f' option to the `export'
1016builtin (*note Bourne Shell Builtins::). Note that shell functions and
1017variables with the same name may result in multiple identically-named
1018entries in the environment passed to the shell's children. Care should
1019be taken in cases where this may cause a problem.
1020
ccc6cda3
JA
1021 Functions may be recursive. No limit is placed on the number of
1022recursive calls.
1023
1024\1f
1025File: bashref.info, Node: Shell Parameters, Next: Shell Expansions, Prev: Shell Functions, Up: Basic Shell Features
1026
37c41ab1
CR
10273.4 Shell Parameters
1028====================
ccc6cda3
JA
1029
1030* Menu:
1031
1032* Positional Parameters:: The shell's command-line arguments.
d3a24ed2 1033* Special Parameters:: Parameters denoted by special characters.
ccc6cda3
JA
1034
1035 A PARAMETER is an entity that stores values. It can be a `name', a
d3a24ed2
CR
1036number, or one of the special characters listed below. A VARIABLE is a
1037parameter denoted by a `name'. A variable has a VALUE and zero or more
1038ATTRIBUTES. Attributes are assigned using the `declare' builtin command
6a8fd0ed 1039(see the description of the `declare' builtin in *note Bash Builtins::).
ccc6cda3
JA
1040
1041 A parameter is set if it has been assigned a value. The null string
1042is a valid value. Once a variable is set, it may be unset only by using
1043the `unset' builtin command.
1044
1045 A variable may be assigned to by a statement of the form
1046 NAME=[VALUE]
37c41ab1 1047 If VALUE is not given, the variable is assigned the null string. All
ccc6cda3
JA
1048VALUEs undergo tilde expansion, parameter and variable expansion,
1049command substitution, arithmetic expansion, and quote removal (detailed
f73dda09 1050below). If the variable has its `integer' attribute set, then VALUE is
d3a24ed2
CR
1051evaluated as an arithmetic expression even if the `$((...))' expansion
1052is not used (*note Arithmetic Expansion::). Word splitting is not
1053performed, with the exception of `"$@"' as explained below. Filename
1054expansion is not performed. Assignment statements may also appear as
5e13499c
CR
1055arguments to the `alias', `declare', `typeset', `export', `readonly',
1056and `local' builtin commands.
ccc6cda3 1057
eb2bb562
CR
1058 In the context where an assignment statement is assigning a value to
1059a shell variable or array index (*note Arrays::), the `+=' operator can
1060be used to append to or add to the variable's previous value. When
1061`+=' is applied to a variable for which the integer attribute has been
1062set, VALUE is evaluated as an arithmetic expression and added to the
1063variable's current value, which is also evaluated. When `+=' is
1064applied to an array variable using compound assignment (*note
1065Arrays::), the variable's value is not unset (as it is when using `='),
1066and new values are appended to the array beginning at one greater than
1067the array's maximum index. When applied to a string-valued variable,
1068VALUE is expanded and appended to the variable's value.
1069
ccc6cda3
JA
1070\1f
1071File: bashref.info, Node: Positional Parameters, Next: Special Parameters, Up: Shell Parameters
1072
37c41ab1
CR
10733.4.1 Positional Parameters
1074---------------------------
ccc6cda3 1075
37c41ab1 1076A POSITIONAL PARAMETER is a parameter denoted by one or more digits,
ccc6cda3
JA
1077other than the single digit `0'. Positional parameters are assigned
1078from the shell's arguments when it is invoked, and may be reassigned
cce855bc 1079using the `set' builtin command. Positional parameter `N' may be
bb70624e
JA
1080referenced as `${N}', or as `$N' when `N' consists of a single digit.
1081Positional parameters may not be assigned to with assignment statements.
1082The `set' and `shift' builtins are used to set and unset them (*note
28ef6c31
JA
1083Shell Builtin Commands::). The positional parameters are temporarily
1084replaced when a shell function is executed (*note Shell Functions::).
ccc6cda3
JA
1085
1086 When a positional parameter consisting of more than a single digit
1087is expanded, it must be enclosed in braces.
1088
1089\1f
1090File: bashref.info, Node: Special Parameters, Prev: Positional Parameters, Up: Shell Parameters
1091
37c41ab1
CR
10923.4.2 Special Parameters
1093------------------------
ccc6cda3 1094
37c41ab1 1095The shell treats several parameters specially. These parameters may
ccc6cda3
JA
1096only be referenced; assignment to them is not allowed.
1097
1098`*'
1099 Expands to the positional parameters, starting from one. When the
1100 expansion occurs within double quotes, it expands to a single word
1101 with the value of each parameter separated by the first character
1102 of the `IFS' special variable. That is, `"$*"' is equivalent to
1103 `"$1C$2C..."', where C is the first character of the value of the
d166f048
JA
1104 `IFS' variable. If `IFS' is unset, the parameters are separated
1105 by spaces. If `IFS' is null, the parameters are joined without
1106 intervening separators.
ccc6cda3
JA
1107
1108`@'
1109 Expands to the positional parameters, starting from one. When the
cce855bc 1110 expansion occurs within double quotes, each parameter expands to a
ccc6cda3 1111 separate word. That is, `"$@"' is equivalent to `"$1" "$2" ...'.
37c41ab1
CR
1112 If the double-quoted expansion occurs within a word, the expansion
1113 of the first parameter is joined with the beginning part of the
1114 original word, and the expansion of the last parameter is joined
1115 with the last part of the original word. When there are no
1116 positional parameters, `"$@"' and `$@' expand to nothing (i.e.,
1117 they are removed).
ccc6cda3
JA
1118
1119`#'
1120 Expands to the number of positional parameters in decimal.
1121
1122`?'
1123 Expands to the exit status of the most recently executed foreground
1124 pipeline.
1125
1126`-'
bb70624e
JA
1127 (A hyphen.) Expands to the current option flags as specified upon
1128 invocation, by the `set' builtin command, or those set by the
1129 shell itself (such as the `-i' option).
ccc6cda3
JA
1130
1131`$'
1132 Expands to the process ID of the shell. In a `()' subshell, it
cce855bc 1133 expands to the process ID of the invoking shell, not the subshell.
ccc6cda3
JA
1134
1135`!'
1136 Expands to the process ID of the most recently executed background
1137 (asynchronous) command.
1138
1139`0'
1140 Expands to the name of the shell or shell script. This is set at
cce855bc 1141 shell initialization. If Bash is invoked with a file of commands
28ef6c31
JA
1142 (*note Shell Scripts::), `$0' is set to the name of that file. If
1143 Bash is started with the `-c' option (*note Invoking Bash::), then
1144 `$0' is set to the first argument after the string to be executed,
1145 if one is present. Otherwise, it is set to the filename used to
1146 invoke Bash, as given by argument zero.
ccc6cda3
JA
1147
1148`_'
2206f89a
CR
1149 (An underscore.) At shell startup, set to the absolute pathname
1150 used to invoke the shell or shell script being executed as passed
1151 in the environment or argument list. Subsequently, expands to the
1152 last argument to the previous command, after expansion. Also set
1153 to the full pathname used to invoke each command executed and
1154 placed in the environment exported to that command. When checking
1155 mail, this parameter holds the name of the mail file.
ccc6cda3
JA
1156
1157\1f
1158File: bashref.info, Node: Shell Expansions, Next: Redirections, Prev: Shell Parameters, Up: Basic Shell Features
1159
37c41ab1
CR
11603.5 Shell Expansions
1161====================
ccc6cda3 1162
37c41ab1
CR
1163Expansion is performed on the command line after it has been split into
1164`token's. There are seven kinds of expansion performed:
ccc6cda3
JA
1165 * brace expansion
1166
1167 * tilde expansion
1168
1169 * parameter and variable expansion
1170
1171 * command substitution
1172
1173 * arithmetic expansion
1174
1175 * word splitting
1176
1177 * filename expansion
1178
1179* Menu:
1180
cce855bc
JA
1181* Brace Expansion:: Expansion of expressions within braces.
1182* Tilde Expansion:: Expansion of the ~ character.
ccc6cda3
JA
1183* Shell Parameter Expansion:: How Bash expands variables to their values.
1184* Command Substitution:: Using the output of a command as an argument.
cce855bc 1185* Arithmetic Expansion:: How to use arithmetic in shell expansions.
ccc6cda3
JA
1186* Process Substitution:: A way to write and read to and from a
1187 command.
1188* Word Splitting:: How the results of expansion are split into separate
1189 arguments.
1190* Filename Expansion:: A shorthand for specifying filenames matching patterns.
1191* Quote Removal:: How and when quote characters are removed from
1192 words.
1193
ccc6cda3
JA
1194 The order of expansions is: brace expansion, tilde expansion,
1195parameter, variable, and arithmetic expansion and command substitution
1196(done in a left-to-right fashion), word splitting, and filename
1197expansion.
1198
1199 On systems that can support it, there is an additional expansion
1200available: PROCESS SUBSTITUTION. This is performed at the same time as
cce855bc 1201parameter, variable, and arithmetic expansion and command substitution.
ccc6cda3
JA
1202
1203 Only brace expansion, word splitting, and filename expansion can
1204change the number of words of the expansion; other expansions expand a
1205single word to a single word. The only exceptions to this are the
28ef6c31
JA
1206expansions of `"$@"' (*note Special Parameters::) and `"${NAME[@]}"'
1207(*note Arrays::).
ccc6cda3 1208
28ef6c31 1209 After all expansions, `quote removal' (*note Quote Removal::) is
ccc6cda3
JA
1210performed.
1211
1212\1f
cce855bc
JA
1213File: bashref.info, Node: Brace Expansion, Next: Tilde Expansion, Up: Shell Expansions
1214
37c41ab1
CR
12153.5.1 Brace Expansion
1216---------------------
cce855bc 1217
37c41ab1 1218Brace expansion is a mechanism by which arbitrary strings may be
cce855bc 1219generated. This mechanism is similar to FILENAME EXPANSION (*note
28ef6c31 1220Filename Expansion::), but the file names generated need not exist.
cce855bc 1221Patterns to be brace expanded take the form of an optional PREAMBLE,
d3ad40de 1222followed by either a series of comma-separated strings or a seqeunce
d3a24ed2
CR
1223expression between a pair of braces, followed by an optional POSTSCRIPT.
1224The preamble is prefixed to each string contained within the braces, and
1225the postscript is then appended to each resulting string, expanding left
1226to right.
cce855bc
JA
1227
1228 Brace expansions may be nested. The results of each expanded string
1229are not sorted; left to right order is preserved. For example,
1230 bash$ echo a{d,c,b}e
1231 ade ace abe
1232
ed35cb4a
CR
1233 A sequence expression takes the form `{X..Y[INCR]}', where X and Y
1234are either integers or single characters, and INCR, an optional
1235increment, is an integer. When integers are supplied, the expression
1236expands to each number between X and Y, inclusive. Supplied integers
1237may be prefixed with `0' to force each term to have the same width.
1238When either X or Y begins with a zero, the shell attempts to force all
1239generated terms to contain the same number of digits, zero-padding
1240where necessary. When characters are supplied, the expression expands
1241to each character lexicographically between X and Y, inclusive. Note
1242that both X and Y must be of the same type. When the increment is
1243supplied, it is used as the difference between each term. The default
1244increment is 1 or -1 as appropriate.
d3a24ed2 1245
cce855bc
JA
1246 Brace expansion is performed before any other expansions, and any
1247characters special to other expansions are preserved in the result. It
1248is strictly textual. Bash does not apply any syntactic interpretation
bb70624e
JA
1249to the context of the expansion or the text between the braces. To
1250avoid conflicts with parameter expansion, the string `${' is not
1251considered eligible for brace expansion.
cce855bc
JA
1252
1253 A correctly-formed brace expansion must contain unquoted opening and
d3a24ed2
CR
1254closing braces, and at least one unquoted comma or a valid sequence
1255expression. Any incorrectly formed brace expansion is left unchanged.
1256
1257 A { or `,' may be quoted with a backslash to prevent its being
1258considered part of a brace expression. To avoid conflicts with
1259parameter expansion, the string `${' is not considered eligible for
1260brace expansion.
cce855bc
JA
1261
1262 This construct is typically used as shorthand when the common prefix
1263of the strings to be generated is longer than in the above example:
1264 mkdir /usr/local/src/bash/{old,new,dist,bugs}
1265 or
1266 chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}
1267
1268\1f
1269File: bashref.info, Node: Tilde Expansion, Next: Shell Parameter Expansion, Prev: Brace Expansion, Up: Shell Expansions
1270
37c41ab1
CR
12713.5.2 Tilde Expansion
1272---------------------
cce855bc 1273
37c41ab1 1274If a word begins with an unquoted tilde character (`~'), all of the
cce855bc
JA
1275characters up to the first unquoted slash (or all characters, if there
1276is no unquoted slash) are considered a TILDE-PREFIX. If none of the
1277characters in the tilde-prefix are quoted, the characters in the
1278tilde-prefix following the tilde are treated as a possible LOGIN NAME.
1279If this login name is the null string, the tilde is replaced with the
1280value of the `HOME' shell variable. If `HOME' is unset, the home
1281directory of the user executing the shell is substituted instead.
1282Otherwise, the tilde-prefix is replaced with the home directory
1283associated with the specified login name.
1284
1285 If the tilde-prefix is `~+', the value of the shell variable `PWD'
1286replaces the tilde-prefix. If the tilde-prefix is `~-', the value of
1287the shell variable `OLDPWD', if it is set, is substituted.
1288
1289 If the characters following the tilde in the tilde-prefix consist of
1290a number N, optionally prefixed by a `+' or a `-', the tilde-prefix is
1291replaced with the corresponding element from the directory stack, as it
1292would be displayed by the `dirs' builtin invoked with the characters
1293following tilde in the tilde-prefix as an argument (*note The Directory
28ef6c31 1294Stack::). If the tilde-prefix, sans the tilde, consists of a number
cce855bc
JA
1295without a leading `+' or `-', `+' is assumed.
1296
1297 If the login name is invalid, or the tilde expansion fails, the word
1298is left unchanged.
1299
1300 Each variable assignment is checked for unquoted tilde-prefixes
eb2bb562
CR
1301immediately following a `:' or the first `='. In these cases, tilde
1302expansion is also performed. Consequently, one may use file names with
1303tildes in assignments to `PATH', `MAILPATH', and `CDPATH', and the
1304shell assigns the expanded value.
cce855bc
JA
1305
1306 The following table shows how Bash treats unquoted tilde-prefixes:
1307
1308`~'
1309 The value of `$HOME'
1310
1311`~/foo'
1312 `$HOME/foo'
1313
1314`~fred/foo'
1315 The subdirectory `foo' of the home directory of the user `fred'
1316
1317`~+/foo'
1318 `$PWD/foo'
1319
1320`~-/foo'
1321 `${OLDPWD-'~-'}/foo'
1322
1323`~N'
1324 The string that would be displayed by `dirs +N'
1325
1326`~+N'
1327 The string that would be displayed by `dirs +N'
1328
1329`~-N'
1330 The string that would be displayed by `dirs -N'
1331
761783bf 1332
cce855bc
JA
1333\1f
1334File: bashref.info, Node: Shell Parameter Expansion, Next: Command Substitution, Prev: Tilde Expansion, Up: Shell Expansions
ccc6cda3 1335
37c41ab1
CR
13363.5.3 Shell Parameter Expansion
1337-------------------------------
ccc6cda3 1338
37c41ab1
CR
1339The `$' character introduces parameter expansion, command substitution,
1340or arithmetic expansion. The parameter name or symbol to be expanded
1341may be enclosed in braces, which are optional but serve to protect the
1342variable to be expanded from characters immediately following it which
1343could be interpreted as part of the name.
ccc6cda3 1344
cce855bc
JA
1345 When braces are used, the matching ending brace is the first `}' not
1346escaped by a backslash or within a quoted string, and not within an
1347embedded arithmetic expansion, command substitution, or parameter
1348expansion.
1349
ccc6cda3
JA
1350 The basic form of parameter expansion is ${PARAMETER}. The value of
1351PARAMETER is substituted. The braces are required when PARAMETER is a
1352positional parameter with more than one digit, or when PARAMETER is
1353followed by a character that is not to be interpreted as part of its
1354name.
1355
1356 If the first character of PARAMETER is an exclamation point, a level
1357of variable indirection is introduced. Bash uses the value of the
1358variable formed from the rest of PARAMETER as the name of the variable;
d166f048
JA
1359this variable is then expanded and that value is used in the rest of
1360the substitution, rather than the value of PARAMETER itself. This is
d3a24ed2
CR
1361known as `indirect expansion'. The exceptions to this are the
1362expansions of ${!PREFIX*} and ${!NAME[@]} described below. The
1363exclamation point must immediately follow the left brace in order to
1364introduce indirection.
ccc6cda3
JA
1365
1366 In each of the cases below, WORD is subject to tilde expansion,
1367parameter expansion, command substitution, and arithmetic expansion.
bb70624e
JA
1368
1369 When not performing substring expansion, Bash tests for a parameter
ccc6cda3 1370that is unset or null; omitting the colon results in a test only for a
bb70624e
JA
1371parameter that is unset. Put another way, if the colon is included,
1372the operator tests for both existence and that the value is not null;
1373if the colon is omitted, the operator tests only for existence.
ccc6cda3
JA
1374
1375`${PARAMETER:-WORD}'
1376 If PARAMETER is unset or null, the expansion of WORD is
1377 substituted. Otherwise, the value of PARAMETER is substituted.
1378
1379`${PARAMETER:=WORD}'
1380 If PARAMETER is unset or null, the expansion of WORD is assigned
1381 to PARAMETER. The value of PARAMETER is then substituted.
de8913bd
CR
1382 Positional parameters and special parameters may not be assigned to
1383 in this way.
ccc6cda3
JA
1384
1385`${PARAMETER:?WORD}'
1386 If PARAMETER is null or unset, the expansion of WORD (or a message
1387 to that effect if WORD is not present) is written to the standard
1388 error and the shell, if it is not interactive, exits. Otherwise,
1389 the value of PARAMETER is substituted.
1390
1391`${PARAMETER:+WORD}'
1392 If PARAMETER is null or unset, nothing is substituted, otherwise
1393 the expansion of WORD is substituted.
1394
1395`${PARAMETER:OFFSET}'
1396`${PARAMETER:OFFSET:LENGTH}'
bb70624e 1397 Expands to up to LENGTH characters of PARAMETER starting at the
cce855bc 1398 character specified by OFFSET. If LENGTH is omitted, expands to
bb70624e 1399 the substring of PARAMETER starting at the character specified by
cce855bc 1400 OFFSET. LENGTH and OFFSET are arithmetic expressions (*note Shell
28ef6c31 1401 Arithmetic::). This is referred to as Substring Expansion.
ccc6cda3
JA
1402
1403 LENGTH must evaluate to a number greater than or equal to zero.
1404 If OFFSET evaluates to a number less than zero, the value is used
1405 as an offset from the end of the value of PARAMETER. If PARAMETER
1406 is `@', the result is LENGTH positional parameters beginning at
1407 OFFSET. If PARAMETER is an array name indexed by `@' or `*', the
1408 result is the LENGTH members of the array beginning with
eb2bb562
CR
1409 `${PARAMETER[OFFSET]}'. A negative OFFSET is taken relative to
1410 one greater than the maximum index of the specified array. Note
1411 that a negative offset must be separated from the colon by at least
1412 one space to avoid being confused with the `:-' expansion.
1413 Substring indexing is zero-based unless the positional parameters
d3ad40de
CR
1414 are used, in which case the indexing starts at 1 by default. If
1415 OFFSET is 0, and the positional parameters are used, `$@' is
1416 prefixed to the list.
ccc6cda3 1417
bb70624e 1418`${!PREFIX*}'
d3a24ed2 1419`${!PREFIX@}'
bb70624e
JA
1420 Expands to the names of variables whose names begin with PREFIX,
1421 separated by the first character of the `IFS' special variable.
d3ad40de
CR
1422 When `@' is used and the expansion appears within double quotes,
1423 each variable name expands to a separate word.
bb70624e 1424
d3a24ed2
CR
1425`${!NAME[@]}'
1426`${!NAME[*]}'
1427 If NAME is an array variable, expands to the list of array indices
1428 (keys) assigned in NAME. If NAME is not an array, expands to 0 if
1429 NAME is set and null otherwise. When `@' is used and the
1430 expansion appears within double quotes, each key expands to a
1431 separate word.
1432
ccc6cda3 1433`${#PARAMETER}'
cce855bc
JA
1434 The length in characters of the expanded value of PARAMETER is
1435 substituted. If PARAMETER is `*' or `@', the value substituted is
1436 the number of positional parameters. If PARAMETER is an array
1437 name subscripted by `*' or `@', the value substituted is the
1438 number of elements in the array.
ccc6cda3
JA
1439
1440`${PARAMETER#WORD}'
1441`${PARAMETER##WORD}'
1442 The WORD is expanded to produce a pattern just as in filename
28ef6c31 1443 expansion (*note Filename Expansion::). If the pattern matches
cce855bc
JA
1444 the beginning of the expanded value of PARAMETER, then the result
1445 of the expansion is the expanded value of PARAMETER with the
1446 shortest matching pattern (the `#' case) or the longest matching
1447 pattern (the `##' case) deleted. If PARAMETER is `@' or `*', the
1448 pattern removal operation is applied to each positional parameter
1449 in turn, and the expansion is the resultant list. If PARAMETER is
1450 an array variable subscripted with `@' or `*', the pattern removal
1451 operation is applied to each member of the array in turn, and the
1452 expansion is the resultant list.
ccc6cda3
JA
1453
1454`${PARAMETER%WORD}'
1455`${PARAMETER%%WORD}'
1456 The WORD is expanded to produce a pattern just as in filename
cce855bc
JA
1457 expansion. If the pattern matches a trailing portion of the
1458 expanded value of PARAMETER, then the result of the expansion is
1459 the value of PARAMETER with the shortest matching pattern (the `%'
1460 case) or the longest matching pattern (the `%%' case) deleted. If
1461 PARAMETER is `@' or `*', the pattern removal operation is applied
1462 to each positional parameter in turn, and the expansion is the
1463 resultant list. If PARAMETER is an array variable subscripted
1464 with `@' or `*', the pattern removal operation is applied to each
1465 member of the array in turn, and the expansion is the resultant
1466 list.
ccc6cda3
JA
1467
1468`${PARAMETER/PATTERN/STRING}'
ccc6cda3
JA
1469 The PATTERN is expanded to produce a pattern just as in filename
1470 expansion. PARAMETER is expanded and the longest match of PATTERN
ac18b312
CR
1471 against its value is replaced with STRING. If PATTERN begins with
1472 `/', all matches of PATTERN are replaced with STRING. Normally
1473 only the first match is replaced. If PATTERN begins with `#', it
1474 must match at the beginning of the expanded value of PARAMETER.
1475 If PATTERN begins with `%', it must match at the end of the
1476 expanded value of PARAMETER. If STRING is null, matches of
b72432fd
JA
1477 PATTERN are deleted and the `/' following PATTERN may be omitted.
1478 If PARAMETER is `@' or `*', the substitution operation is applied
1479 to each positional parameter in turn, and the expansion is the
1480 resultant list. If PARAMETER is an array variable subscripted
1481 with `@' or `*', the substitution operation is applied to each
1482 member of the array in turn, and the expansion is the resultant
1483 list.
ccc6cda3 1484
761783bf 1485
ccc6cda3 1486\1f
cce855bc 1487File: bashref.info, Node: Command Substitution, Next: Arithmetic Expansion, Prev: Shell Parameter Expansion, Up: Shell Expansions
ccc6cda3 1488
37c41ab1
CR
14893.5.4 Command Substitution
1490--------------------------
ccc6cda3 1491
37c41ab1 1492Command substitution allows the output of a command to replace the
bb70624e
JA
1493command itself. Command substitution occurs when a command is enclosed
1494as follows:
ccc6cda3 1495 $(COMMAND)
37c41ab1 1496 or
ccc6cda3
JA
1497 `COMMAND`
1498
1499Bash performs the expansion by executing COMMAND and replacing the
1500command substitution with the standard output of the command, with any
cce855bc
JA
1501trailing newlines deleted. Embedded newlines are not deleted, but they
1502may be removed during word splitting. The command substitution `$(cat
1503FILE)' can be replaced by the equivalent but faster `$(< FILE)'.
ccc6cda3
JA
1504
1505 When the old-style backquote form of substitution is used, backslash
1506retains its literal meaning except when followed by `$', ``', or `\'.
cce855bc
JA
1507The first backquote not preceded by a backslash terminates the command
1508substitution. When using the `$(COMMAND)' form, all characters between
1509the parentheses make up the command; none are treated specially.
ccc6cda3 1510
cce855bc
JA
1511 Command substitutions may be nested. To nest when using the
1512backquoted form, escape the inner backquotes with backslashes.
ccc6cda3
JA
1513
1514 If the substitution appears within double quotes, word splitting and
1515filename expansion are not performed on the results.
1516
1517\1f
cce855bc
JA
1518File: bashref.info, Node: Arithmetic Expansion, Next: Process Substitution, Prev: Command Substitution, Up: Shell Expansions
1519
37c41ab1
CR
15203.5.5 Arithmetic Expansion
1521--------------------------
cce855bc 1522
37c41ab1
CR
1523Arithmetic expansion allows the evaluation of an arithmetic expression
1524and the substitution of the result. The format for arithmetic
1525expansion is:
cce855bc
JA
1526
1527 $(( EXPRESSION ))
1528
1529 The expression is treated as if it were within double quotes, but a
1530double quote inside the parentheses is not treated specially. All
1531tokens in the expression undergo parameter expansion, command
d3a24ed2 1532substitution, and quote removal. Arithmetic expansions may be nested.
cce855bc
JA
1533
1534 The evaluation is performed according to the rules listed below
28ef6c31 1535(*note Shell Arithmetic::). If the expression is invalid, Bash prints
cce855bc
JA
1536a message indicating failure to the standard error and no substitution
1537occurs.
1538
1539\1f
1540File: bashref.info, Node: Process Substitution, Next: Word Splitting, Prev: Arithmetic Expansion, Up: Shell Expansions
ccc6cda3 1541
37c41ab1
CR
15423.5.6 Process Substitution
1543--------------------------
ccc6cda3 1544
37c41ab1
CR
1545Process substitution is supported on systems that support named pipes
1546(FIFOs) or the `/dev/fd' method of naming open files. It takes the
1547form of
ccc6cda3 1548 <(LIST)
37c41ab1 1549 or
ccc6cda3 1550 >(LIST)
37c41ab1
CR
1551 The process LIST is run with its input or output connected to a FIFO
1552or some file in `/dev/fd'. The name of this file is passed as an
1553argument to the current command as the result of the expansion. If the
ccc6cda3
JA
1554`>(LIST)' form is used, writing to the file will provide input for
1555LIST. If the `<(LIST)' form is used, the file passed as an argument
bb70624e
JA
1556should be read to obtain the output of LIST. Note that no space may
1557appear between the `<' or `>' and the left parenthesis, otherwise the
1558construct would be interpreted as a redirection.
ccc6cda3 1559
cce855bc
JA
1560 When available, process substitution is performed simultaneously with
1561parameter and variable expansion, command substitution, and arithmetic
1562expansion.
ccc6cda3
JA
1563
1564\1f
1565File: bashref.info, Node: Word Splitting, Next: Filename Expansion, Prev: Process Substitution, Up: Shell Expansions
1566
37c41ab1
CR
15673.5.7 Word Splitting
1568--------------------
ccc6cda3 1569
37c41ab1 1570The shell scans the results of parameter expansion, command
ccc6cda3
JA
1571substitution, and arithmetic expansion that did not occur within double
1572quotes for word splitting.
1573
1574 The shell treats each character of `$IFS' as a delimiter, and splits
1575the results of the other expansions into words on these characters. If
1576`IFS' is unset, or its value is exactly `<space><tab><newline>', the
d3ad40de
CR
1577default, then sequences of ` <space>', `<tab>', and `<newline>' at the
1578beginning and end of the results of the previous expansions are
1579ignored, and any sequence of `IFS' characters not at the beginning or
1580end serves to delimit words. If `IFS' has a value other than the
1581default, then sequences of the whitespace characters `space' and `tab'
1582are ignored at the beginning and end of the word, as long as the
1583whitespace character is in the value of `IFS' (an `IFS' whitespace
1584character). Any character in `IFS' that is not `IFS' whitespace, along
1585with any adjacent `IFS' whitespace characters, delimits a field. A
1586sequence of `IFS' whitespace characters is also treated as a delimiter.
1587If the value of `IFS' is null, no word splitting occurs.
ccc6cda3
JA
1588
1589 Explicit null arguments (`""' or `''') are retained. Unquoted
bb70624e 1590implicit null arguments, resulting from the expansion of parameters
ccc6cda3
JA
1591that have no values, are removed. If a parameter with no value is
1592expanded within double quotes, a null argument results and is retained.
1593
1594 Note that if no expansion occurs, no splitting is performed.
1595
1596\1f
1597File: bashref.info, Node: Filename Expansion, Next: Quote Removal, Prev: Word Splitting, Up: Shell Expansions
1598
37c41ab1
CR
15993.5.8 Filename Expansion
1600------------------------
ccc6cda3 1601
cce855bc
JA
1602* Menu:
1603
1604* Pattern Matching:: How the shell matches patterns.
1605
ccc6cda3 1606 After word splitting, unless the `-f' option has been set (*note The
28ef6c31 1607Set Builtin::), Bash scans each word for the characters `*', `?', and
bb70624e
JA
1608`['. If one of these characters appears, then the word is regarded as
1609a PATTERN, and replaced with an alphabetically sorted list of file
ccc6cda3 1610names matching the pattern. If no matching file names are found, and
cce855bc
JA
1611the shell option `nullglob' is disabled, the word is left unchanged.
1612If the `nullglob' option is set, and no matches are found, the word is
5e13499c
CR
1613removed. If the `failglob' shell option is set, and no matches are
1614found, an error message is printed and the command is not executed. If
1615the shell option `nocaseglob' is enabled, the match is performed
1616without regard to the case of alphabetic characters.
cce855bc 1617
28ef6c31
JA
1618 When a pattern is used for filename generation, the character `.' at
1619the start of a filename or immediately following a slash must be
cce855bc
JA
1620matched explicitly, unless the shell option `dotglob' is set. When
1621matching a file name, the slash character must always be matched
1622explicitly. In other cases, the `.' character is not treated specially.
1623
6a8fd0ed 1624 See the description of `shopt' in *note The Shopt Builtin::, for a
5e13499c
CR
1625description of the `nocaseglob', `nullglob', `failglob', and `dotglob'
1626options.
ccc6cda3
JA
1627
1628 The `GLOBIGNORE' shell variable may be used to restrict the set of
cce855bc 1629filenames matching a pattern. If `GLOBIGNORE' is set, each matching
ccc6cda3 1630filename that also matches one of the patterns in `GLOBIGNORE' is
28ef6c31 1631removed from the list of matches. The filenames `.' and `..' are
d3a24ed2
CR
1632always ignored when `GLOBIGNORE' is set and not null. However, setting
1633`GLOBIGNORE' to a non-null value has the effect of enabling the
1634`dotglob' shell option, so all other filenames beginning with a `.'
1635will match. To get the old behavior of ignoring filenames beginning
1636with a `.', make `.*' one of the patterns in `GLOBIGNORE'. The
1637`dotglob' option is disabled when `GLOBIGNORE' is unset.
ccc6cda3 1638
cce855bc
JA
1639\1f
1640File: bashref.info, Node: Pattern Matching, Up: Filename Expansion
1641
37c41ab1
CR
16423.5.8.1 Pattern Matching
1643........................
cce855bc 1644
37c41ab1
CR
1645Any character that appears in a pattern, other than the special pattern
1646characters described below, matches itself. The NUL character may not
1647occur in a pattern. A backslash escapes the following character; the
1648escaping backslash is discarded when matching. The special pattern
1649characters must be quoted if they are to be matched literally.
cce855bc 1650
ccc6cda3
JA
1651 The special pattern characters have the following meanings:
1652`*'
ed35cb4a
CR
1653 Matches any string, including the null string. When the
1654 `globstar' shell option is enabled, and `*' is used in a filename
1655 expansion context, two adjacent `*'s used as a single pattern will
1656 match all files and zero or more directories and subdirectories.
1657 If followed by a `/', two adjacent `*'s will match only
1658 directories and subdirectories.
ccc6cda3
JA
1659
1660`?'
1661 Matches any single character.
1662
1663`[...]'
1664 Matches any one of the enclosed characters. A pair of characters
28ef6c31
JA
1665 separated by a hyphen denotes a RANGE EXPRESSION; any character
1666 that sorts between those two characters, inclusive, using the
1667 current locale's collating sequence and character set, is matched.
1668 If the first character following the `[' is a `!' or a `^' then
1669 any character not enclosed is matched. A `-' may be matched by
1670 including it as the first or last character in the set. A `]' may
1671 be matched by including it as the first character in the set. The
1672 sorting order of characters in range expressions is determined by
1673 the current locale and the value of the `LC_COLLATE' shell
1674 variable, if set.
1675
1676 For example, in the default C locale, `[a-dx-z]' is equivalent to
1677 `[abcdxyz]'. Many locales sort characters in dictionary order,
1678 and in these locales `[a-dx-z]' is typically not equivalent to
1679 `[abcdxyz]'; it might be equivalent to `[aBbCcDdxXyYz]', for
1680 example. To obtain the traditional interpretation of ranges in
1681 bracket expressions, you can force the use of the C locale by
1682 setting the `LC_COLLATE' or `LC_ALL' environment variable to the
1683 value `C'.
ccc6cda3 1684
cce855bc
JA
1685 Within `[' and `]', CHARACTER CLASSES can be specified using the
1686 syntax `[:'CLASS`:]', where CLASS is one of the following classes
ac18b312 1687 defined in the POSIX standard:
cce855bc 1688 alnum alpha ascii blank cntrl digit graph lower
7117c2d2 1689 print punct space upper word xdigit
cce855bc 1690 A character class matches any character belonging to that class.
7117c2d2
JA
1691 The `word' character class matches letters, digits, and the
1692 character `_'.
cce855bc
JA
1693
1694 Within `[' and `]', an EQUIVALENCE CLASS can be specified using
1695 the syntax `[='C`=]', which matches all characters with the same
1696 collation weight (as defined by the current locale) as the
1697 character C.
1698
28ef6c31 1699 Within `[' and `]', the syntax `[.'SYMBOL`.]' matches the
cce855bc
JA
1700 collating symbol SYMBOL.
1701
1702 If the `extglob' shell option is enabled using the `shopt' builtin,
1703several extended pattern matching operators are recognized. In the
1704following description, a PATTERN-LIST is a list of one or more patterns
1705separated by a `|'. Composite patterns may be formed using one or more
1706of the following sub-patterns:
1707
1708`?(PATTERN-LIST)'
1709 Matches zero or one occurrence of the given patterns.
1710
1711`*(PATTERN-LIST)'
1712 Matches zero or more occurrences of the given patterns.
1713
1714`+(PATTERN-LIST)'
1715 Matches one or more occurrences of the given patterns.
1716
1717`@(PATTERN-LIST)'
eb2bb562 1718 Matches one of the given patterns.
cce855bc
JA
1719
1720`!(PATTERN-LIST)'
1721 Matches anything except one of the given patterns.
1722
ccc6cda3
JA
1723\1f
1724File: bashref.info, Node: Quote Removal, Prev: Filename Expansion, Up: Shell Expansions
1725
37c41ab1
CR
17263.5.9 Quote Removal
1727-------------------
ccc6cda3 1728
37c41ab1 1729After the preceding expansions, all unquoted occurrences of the
ccc6cda3
JA
1730characters `\', `'', and `"' that did not result from one of the above
1731expansions are removed.
1732
1733\1f
1734File: bashref.info, Node: Redirections, Next: Executing Commands, Prev: Shell Expansions, Up: Basic Shell Features
1735
37c41ab1
CR
17363.6 Redirections
1737================
ccc6cda3 1738
37c41ab1 1739Before a command is executed, its input and output may be REDIRECTED
ccc6cda3
JA
1740using a special notation interpreted by the shell. Redirection may
1741also be used to open and close files for the current shell execution
1742environment. The following redirection operators may precede or appear
1743anywhere within a simple command or may follow a command. Redirections
1744are processed in the order they appear, from left to right.
1745
1746 In the following descriptions, if the file descriptor number is
1747omitted, and the first character of the redirection operator is `<',
1748the redirection refers to the standard input (file descriptor 0). If
1749the first character of the redirection operator is `>', the redirection
1750refers to the standard output (file descriptor 1).
1751
cce855bc
JA
1752 The word following the redirection operator in the following
1753descriptions, unless otherwise noted, is subjected to brace expansion,
1754tilde expansion, parameter expansion, command substitution, arithmetic
bb70624e
JA
1755expansion, quote removal, filename expansion, and word splitting. If
1756it expands to more than one word, Bash reports an error.
ccc6cda3
JA
1757
1758 Note that the order of redirections is significant. For example,
1759the command
1760 ls > DIRLIST 2>&1
37c41ab1 1761 directs both standard output (file descriptor 1) and standard error
bb70624e 1762(file descriptor 2) to the file DIRLIST, while the command
ccc6cda3 1763 ls 2>&1 > DIRLIST
37c41ab1
CR
1764 directs only the standard output to file DIRLIST, because the
1765standard error was duplicated as standard output before the standard
1766output was redirected to DIRLIST.
ccc6cda3 1767
bb70624e
JA
1768 Bash handles several filenames specially when they are used in
1769redirections, as described in the following table:
1770
1771`/dev/fd/FD'
1772 If FD is a valid integer, file descriptor FD is duplicated.
1773
1774`/dev/stdin'
1775 File descriptor 0 is duplicated.
1776
1777`/dev/stdout'
1778 File descriptor 1 is duplicated.
1779
1780`/dev/stderr'
1781 File descriptor 2 is duplicated.
1782
1783`/dev/tcp/HOST/PORT'
1784 If HOST is a valid hostname or Internet address, and PORT is an
f73dda09
JA
1785 integer port number or service name, Bash attempts to open a TCP
1786 connection to the corresponding socket.
bb70624e
JA
1787
1788`/dev/udp/HOST/PORT'
1789 If HOST is a valid hostname or Internet address, and PORT is an
f73dda09
JA
1790 integer port number or service name, Bash attempts to open a UDP
1791 connection to the corresponding socket.
bb70624e 1792
761783bf 1793
cce855bc
JA
1794 A failure to open or create a file causes the redirection to fail.
1795
eb2bb562
CR
1796 Redirections using file descriptors greater than 9 should be used
1797with care, as they may conflict with file descriptors the shell uses
1798internally.
1799
37c41ab1
CR
18003.6.1 Redirecting Input
1801-----------------------
ccc6cda3 1802
37c41ab1 1803Redirection of input causes the file whose name results from the
ccc6cda3
JA
1804expansion of WORD to be opened for reading on file descriptor `n', or
1805the standard input (file descriptor 0) if `n' is not specified.
1806
1807 The general format for redirecting input is:
7117c2d2 1808 [N]<WORD
ccc6cda3 1809
37c41ab1
CR
18103.6.2 Redirecting Output
1811------------------------
ccc6cda3 1812
37c41ab1 1813Redirection of output causes the file whose name results from the
7117c2d2
JA
1814expansion of WORD to be opened for writing on file descriptor N, or the
1815standard output (file descriptor 1) if N is not specified. If the file
1816does not exist it is created; if it does exist it is truncated to zero
1817size.
ccc6cda3
JA
1818
1819 The general format for redirecting output is:
7117c2d2 1820 [N]>[|]WORD
ccc6cda3 1821
cce855bc
JA
1822 If the redirection operator is `>', and the `noclobber' option to
1823the `set' builtin has been enabled, the redirection will fail if the
bb70624e 1824file whose name results from the expansion of WORD exists and is a
cce855bc
JA
1825regular file. If the redirection operator is `>|', or the redirection
1826operator is `>' and the `noclobber' option is not enabled, the
1827redirection is attempted even if the file named by WORD exists.
ccc6cda3 1828
37c41ab1
CR
18293.6.3 Appending Redirected Output
1830---------------------------------
ccc6cda3 1831
37c41ab1 1832Redirection of output in this fashion causes the file whose name
ccc6cda3 1833results from the expansion of WORD to be opened for appending on file
7117c2d2
JA
1834descriptor N, or the standard output (file descriptor 1) if N is not
1835specified. If the file does not exist it is created.
ccc6cda3
JA
1836
1837 The general format for appending output is:
7117c2d2 1838 [N]>>WORD
ccc6cda3 1839
37c41ab1
CR
18403.6.4 Redirecting Standard Output and Standard Error
1841----------------------------------------------------
ccc6cda3 1842
ed35cb4a
CR
1843This construct allows both the standard output (file descriptor 1) and
1844the standard error output (file descriptor 2) to be redirected to the
1845file whose name is the expansion of WORD.
ccc6cda3
JA
1846
1847 There are two formats for redirecting standard output and standard
1848error:
1849 &>WORD
37c41ab1 1850 and
ccc6cda3 1851 >&WORD
37c41ab1 1852 Of the two forms, the first is preferred. This is semantically
ccc6cda3
JA
1853equivalent to
1854 >WORD 2>&1
1855
ed35cb4a
CR
18563.6.5 Appending Standard Output and Standard Error
1857--------------------------------------------------
1858
1859This construct allows both the standard output (file descriptor 1) and
1860the standard error output (file descriptor 2) to be appended to the
1861file whose name is the expansion of WORD.
1862
1863 The format for appending standard output and standard error is:
1864 &>>WORD
1865 This is semantically equivalent to
1866 >>WORD 2>&1
1867
18683.6.6 Here Documents
37c41ab1 1869--------------------
ccc6cda3 1870
37c41ab1 1871This type of redirection instructs the shell to read input from the
ccc6cda3
JA
1872current source until a line containing only WORD (with no trailing
1873blanks) is seen. All of the lines read up to that point are then used
1874as the standard input for a command.
1875
7117c2d2 1876 The format of here-documents is:
ccc6cda3
JA
1877 <<[-]WORD
1878 HERE-DOCUMENT
1879 DELIMITER
1880
bb70624e
JA
1881 No parameter expansion, command substitution, arithmetic expansion,
1882or filename expansion is performed on WORD. If any characters in WORD
ccc6cda3 1883are quoted, the DELIMITER is the result of quote removal on WORD, and
cce855bc
JA
1884the lines in the here-document are not expanded. If WORD is unquoted,
1885all lines of the here-document are subjected to parameter expansion,
1886command substitution, and arithmetic expansion. In the latter case,
bb70624e
JA
1887the character sequence `\newline' is ignored, and `\' must be used to
1888quote the characters `\', `$', and ``'.
ccc6cda3
JA
1889
1890 If the redirection operator is `<<-', then all leading tab
1891characters are stripped from input lines and the line containing
1892DELIMITER. This allows here-documents within shell scripts to be
1893indented in a natural fashion.
1894
ed35cb4a 18953.6.7 Here Strings
37c41ab1 1896------------------
7117c2d2 1897
37c41ab1 1898A variant of here documents, the format is:
7117c2d2
JA
1899 <<< WORD
1900
1901 The WORD is expanded and supplied to the command on its standard
1902input.
1903
ed35cb4a 19043.6.8 Duplicating File Descriptors
37c41ab1 1905----------------------------------
ccc6cda3 1906
37c41ab1 1907The redirection operator
7117c2d2 1908 [N]<&WORD
37c41ab1
CR
1909 is used to duplicate input file descriptors. If WORD expands to one
1910or more digits, the file descriptor denoted by N is made to be a copy
1911of that file descriptor. If the digits in WORD do not specify a file
cce855bc 1912descriptor open for input, a redirection error occurs. If WORD
7117c2d2
JA
1913evaluates to `-', file descriptor N is closed. If N is not specified,
1914the standard input (file descriptor 0) is used.
ccc6cda3
JA
1915
1916 The operator
7117c2d2 1917 [N]>&WORD
37c41ab1 1918 is used similarly to duplicate output file descriptors. If N is not
cce855bc
JA
1919specified, the standard output (file descriptor 1) is used. If the
1920digits in WORD do not specify a file descriptor open for output, a
7117c2d2
JA
1921redirection error occurs. As a special case, if N is omitted, and WORD
1922does not expand to one or more digits, the standard output and standard
1923error are redirected as described previously.
1924
ed35cb4a 19253.6.9 Moving File Descriptors
37c41ab1 1926-----------------------------
7117c2d2 1927
37c41ab1 1928The redirection operator
7117c2d2 1929 [N]<&DIGIT-
37c41ab1
CR
1930 moves the file descriptor DIGIT to file descriptor N, or the
1931standard input (file descriptor 0) if N is not specified. DIGIT is
1932closed after being duplicated to N.
7117c2d2
JA
1933
1934 Similarly, the redirection operator
1935 [N]>&DIGIT-
37c41ab1
CR
1936 moves the file descriptor DIGIT to file descriptor N, or the
1937standard output (file descriptor 1) if N is not specified.
7117c2d2 1938
ed35cb4a
CR
19393.6.10 Opening File Descriptors for Reading and Writing
1940-------------------------------------------------------
ccc6cda3 1941
37c41ab1 1942The redirection operator
7117c2d2 1943 [N]<>WORD
37c41ab1 1944 causes the file whose name is the expansion of WORD to be opened for
7117c2d2
JA
1945both reading and writing on file descriptor N, or on file descriptor 0
1946if N is not specified. If the file does not exist, it is created.
ccc6cda3
JA
1947
1948\1f
1949File: bashref.info, Node: Executing Commands, Next: Shell Scripts, Prev: Redirections, Up: Basic Shell Features
1950
37c41ab1
CR
19513.7 Executing Commands
1952======================
ccc6cda3
JA
1953
1954* Menu:
1955
cce855bc
JA
1956* Simple Command Expansion:: How Bash expands simple commands before
1957 executing them.
ccc6cda3 1958* Command Search and Execution:: How Bash finds commands and runs them.
cce855bc
JA
1959* Command Execution Environment:: The environment in which Bash
1960 executes commands that are not
1961 shell builtins.
ccc6cda3 1962* Environment:: The environment given to a command.
ccc6cda3
JA
1963* Exit Status:: The status returned by commands and how Bash
1964 interprets it.
ccc6cda3
JA
1965* Signals:: What happens when Bash or a command it runs
1966 receives a signal.
1967
1968\1f
cce855bc
JA
1969File: bashref.info, Node: Simple Command Expansion, Next: Command Search and Execution, Up: Executing Commands
1970
37c41ab1
CR
19713.7.1 Simple Command Expansion
1972------------------------------
cce855bc 1973
37c41ab1 1974When a simple command is executed, the shell performs the following
cce855bc
JA
1975expansions, assignments, and redirections, from left to right.
1976
1977 1. The words that the parser has marked as variable assignments (those
1978 preceding the command name) and redirections are saved for later
1979 processing.
1980
1981 2. The words that are not variable assignments or redirections are
28ef6c31 1982 expanded (*note Shell Expansions::). If any words remain after
cce855bc
JA
1983 expansion, the first word is taken to be the name of the command
1984 and the remaining words are the arguments.
1985
1986 3. Redirections are performed as described above (*note
28ef6c31 1987 Redirections::).
cce855bc
JA
1988
1989 4. The text after the `=' in each variable assignment undergoes tilde
1990 expansion, parameter expansion, command substitution, arithmetic
1991 expansion, and quote removal before being assigned to the variable.
1992
1993 If no command name results, the variable assignments affect the
1994current shell environment. Otherwise, the variables are added to the
1995environment of the executed command and do not affect the current shell
1996environment. If any of the assignments attempts to assign a value to a
1997readonly variable, an error occurs, and the command exits with a
1998non-zero status.
1999
2000 If no command name results, redirections are performed, but do not
2001affect the current shell environment. A redirection error causes the
2002command to exit with a non-zero status.
2003
2004 If there is a command name left after expansion, execution proceeds
2005as described below. Otherwise, the command exits. If one of the
2006expansions contained a command substitution, the exit status of the
2007command is the exit status of the last command substitution performed.
2008If there were no command substitutions, the command exits with a status
2009of zero.
2010
2011\1f
2012File: bashref.info, Node: Command Search and Execution, Next: Command Execution Environment, Prev: Simple Command Expansion, Up: Executing Commands
ccc6cda3 2013
37c41ab1
CR
20143.7.2 Command Search and Execution
2015----------------------------------
ccc6cda3 2016
37c41ab1 2017After a command has been split into words, if it results in a simple
ccc6cda3
JA
2018command and an optional list of arguments, the following actions are
2019taken.
2020
2021 1. If the command name contains no slashes, the shell attempts to
2022 locate it. If there exists a shell function by that name, that
6a8fd0ed 2023 function is invoked as described in *note Shell Functions::.
ccc6cda3
JA
2024
2025 2. If the name does not match a function, the shell searches for it
2026 in the list of shell builtins. If a match is found, that builtin
2027 is invoked.
2028
2029 3. If the name is neither a shell function nor a builtin, and
2030 contains no slashes, Bash searches each element of `$PATH' for a
2031 directory containing an executable file by that name. Bash uses a
cce855bc
JA
2032 hash table to remember the full pathnames of executable files to
2033 avoid multiple `PATH' searches (see the description of `hash' in
6a8fd0ed 2034 *note Bourne Shell Builtins::). A full search of the directories
ccc6cda3 2035 in `$PATH' is performed only if the command is not found in the
ed35cb4a
CR
2036 hash table. If the search is unsuccessful, the shell searches for
2037 a defined shell function named `command_not_found_handle'. If
2038 that function exists, it is invoked with the original command and
2039 the original command's arguments as its arguments, and the
2040 function's exit status becomes the exit status of the shell. If
2041 that function is not defined, the shell prints an error message
2042 and returns an exit status of 127.
ccc6cda3
JA
2043
2044 4. If the search is successful, or if the command name contains one
cce855bc
JA
2045 or more slashes, the shell executes the named program in a
2046 separate execution environment. Argument 0 is set to the name
2047 given, and the remaining arguments to the command are set to the
2048 arguments supplied, if any.
ccc6cda3
JA
2049
2050 5. If this execution fails because the file is not in executable
cce855bc 2051 format, and the file is not a directory, it is assumed to be a
6a8fd0ed 2052 SHELL SCRIPT and the shell executes it as described in *note Shell
cce855bc
JA
2053 Scripts::.
2054
2055 6. If the command was not begun asynchronously, the shell waits for
2056 the command to complete and collects its exit status.
2057
2058
2059\1f
2060File: bashref.info, Node: Command Execution Environment, Next: Environment, Prev: Command Search and Execution, Up: Executing Commands
2061
37c41ab1
CR
20623.7.3 Command Execution Environment
2063-----------------------------------
cce855bc 2064
37c41ab1 2065The shell has an EXECUTION ENVIRONMENT, which consists of the following:
cce855bc
JA
2066
2067 * open files inherited by the shell at invocation, as modified by
2068 redirections supplied to the `exec' builtin
2069
2070 * the current working directory as set by `cd', `pushd', or `popd',
2071 or inherited by the shell at invocation
2072
2073 * the file creation mode mask as set by `umask' or inherited from
2074 the shell's parent
2075
2076 * current traps set by `trap'
2077
2078 * shell parameters that are set by variable assignment or with `set'
2079 or inherited from the shell's parent in the environment
2080
2081 * shell functions defined during execution or inherited from the
2082 shell's parent in the environment
2083
2084 * options enabled at invocation (either by default or with
2085 command-line arguments) or by `set'
2086
d3ad40de 2087 * options enabled by `shopt' (*note The Shopt Builtin::)
cce855bc 2088
28ef6c31 2089 * shell aliases defined with `alias' (*note Aliases::)
cce855bc
JA
2090
2091 * various process IDs, including those of background jobs (*note
28ef6c31
JA
2092 Lists::), the value of `$$', and the value of `$PPID'
2093
cce855bc
JA
2094
2095 When a simple command other than a builtin or shell function is to
2096be executed, it is invoked in a separate execution environment that
2097consists of the following. Unless otherwise noted, the values are
2098inherited from the shell.
2099
2100 * the shell's open files, plus any modifications and additions
2101 specified by redirections to the command
2102
2103 * the current working directory
2104
2105 * the file creation mode mask
2106
d3a24ed2
CR
2107 * shell variables and functions marked for export, along with
2108 variables exported for the command, passed in the environment
2109 (*note Environment::)
cce855bc
JA
2110
2111 * traps caught by the shell are reset to the values inherited from
2112 the shell's parent, and traps ignored by the shell are ignored
2113
28ef6c31 2114
cce855bc
JA
2115 A command invoked in this separate environment cannot affect the
2116shell's execution environment.
2117
d3a24ed2
CR
2118 Command substitution, commands grouped with parentheses, and
2119asynchronous commands are invoked in a subshell environment that is a
2120duplicate of the shell environment, except that traps caught by the
2121shell are reset to the values that the shell inherited from its parent
2122at invocation. Builtin commands that are invoked as part of a pipeline
2123are also executed in a subshell environment. Changes made to the
2124subshell environment cannot affect the shell's execution environment.
ccc6cda3 2125
f73dda09
JA
2126 If a command is followed by a `&' and job control is not active, the
2127default standard input for the command is the empty file `/dev/null'.
2128Otherwise, the invoked command inherits the file descriptors of the
2129calling shell as modified by redirections.
2130
ccc6cda3 2131\1f
cce855bc 2132File: bashref.info, Node: Environment, Next: Exit Status, Prev: Command Execution Environment, Up: Executing Commands
ccc6cda3 2133
37c41ab1
CR
21343.7.4 Environment
2135-----------------
ccc6cda3 2136
37c41ab1 2137When a program is invoked it is given an array of strings called the
ccc6cda3
JA
2138ENVIRONMENT. This is a list of name-value pairs, of the form
2139`name=value'.
2140
bb70624e 2141 Bash provides several ways to manipulate the environment. On
ccc6cda3
JA
2142invocation, the shell scans its own environment and creates a parameter
2143for each name found, automatically marking it for EXPORT to child
2144processes. Executed commands inherit the environment. The `export'
2145and `declare -x' commands allow parameters and functions to be added to
2146and deleted from the environment. If the value of a parameter in the
2147environment is modified, the new value becomes part of the environment,
2148replacing the old. The environment inherited by any executed command
2149consists of the shell's initial environment, whose values may be
cce855bc
JA
2150modified in the shell, less any pairs removed by the `unset' and
2151`export -n' commands, plus any additions via the `export' and `declare
2152-x' commands.
ccc6cda3
JA
2153
2154 The environment for any simple command or function may be augmented
2155temporarily by prefixing it with parameter assignments, as described in
6a8fd0ed 2156*note Shell Parameters::. These assignment statements affect only the
ccc6cda3
JA
2157environment seen by that command.
2158
28ef6c31 2159 If the `-k' option is set (*note The Set Builtin::), then all
ccc6cda3
JA
2160parameter assignments are placed in the environment for a command, not
2161just those that precede the command name.
2162
2163 When Bash invokes an external command, the variable `$_' is set to
2164the full path name of the command and passed to that command in its
2165environment.
2166
2167\1f
2168File: bashref.info, Node: Exit Status, Next: Signals, Prev: Environment, Up: Executing Commands
2169
37c41ab1
CR
21703.7.5 Exit Status
2171-----------------
ccc6cda3 2172
29d25b54
CR
2173The exit status of an executed command is the value returned by the
2174WAITPID system call or equivalent function. Exit statuses fall between
21750 and 255, though, as explained below, the shell may use values above
2176125 specially. Exit statuses from shell builtins and compound commands
2177are also limited to this range. Under certain circumstances, the shell
2178will use special values to indicate specific failure modes.
2179
2180 For the shell's purposes, a command which exits with a zero exit
2181status has succeeded. A non-zero exit status indicates failure. This
cce855bc
JA
2182seemingly counter-intuitive scheme is used so there is one well-defined
2183way to indicate success and a variety of ways to indicate various
2184failure modes. When a command terminates on a fatal signal whose
2185number is N, Bash uses the value 128+N as the exit status.
ccc6cda3
JA
2186
2187 If a command is not found, the child process created to execute it
2188returns a status of 127. If a command is found but is not executable,
2189the return status is 126.
2190
cce855bc
JA
2191 If a command fails because of an error during expansion or
2192redirection, the exit status is greater than zero.
2193
ccc6cda3 2194 The exit status is used by the Bash conditional commands (*note
28ef6c31
JA
2195Conditional Constructs::) and some of the list constructs (*note
2196Lists::).
ccc6cda3
JA
2197
2198 All of the Bash builtins return an exit status of zero if they
2199succeed and a non-zero status on failure, so they may be used by the
cce855bc
JA
2200conditional and list constructs. All builtins return an exit status of
22012 to indicate incorrect usage.
ccc6cda3
JA
2202
2203\1f
2204File: bashref.info, Node: Signals, Prev: Exit Status, Up: Executing Commands
2205
37c41ab1
CR
22063.7.6 Signals
2207-------------
ccc6cda3 2208
37c41ab1 2209When Bash is interactive, in the absence of any traps, it ignores
cce855bc
JA
2210`SIGTERM' (so that `kill 0' does not kill an interactive shell), and
2211`SIGINT' is caught and handled (so that the `wait' builtin is
2212interruptible). When Bash receives a `SIGINT', it breaks out of any
2213executing loops. In all cases, Bash ignores `SIGQUIT'. If job control
28ef6c31 2214is in effect (*note Job Control::), Bash ignores `SIGTTIN', `SIGTTOU',
cce855bc 2215and `SIGTSTP'.
ccc6cda3 2216
5e13499c
CR
2217 Non-builtin commands started by Bash have signal handlers set to the
2218values inherited by the shell from its parent. When job control is not
2219in effect, asynchronous commands ignore `SIGINT' and `SIGQUIT' in
2220addition to these inherited handlers. Commands run as a result of
2221command substitution ignore the keyboard-generated job control signals
2222`SIGTTIN', `SIGTTOU', and `SIGTSTP'.
ccc6cda3
JA
2223
2224 The shell exits by default upon receipt of a `SIGHUP'. Before
f73dda09
JA
2225exiting, an interactive shell resends the `SIGHUP' to all jobs, running
2226or stopped. Stopped jobs are sent `SIGCONT' to ensure that they receive
2227the `SIGHUP'. To prevent the shell from sending the `SIGHUP' signal to
2228a particular job, it should be removed from the jobs table with the
28ef6c31 2229`disown' builtin (*note Job Control Builtins::) or marked to not
cce855bc
JA
2230receive `SIGHUP' using `disown -h'.
2231
2232 If the `huponexit' shell option has been set with `shopt' (*note
d3ad40de
CR
2233The Shopt Builtin::), Bash sends a `SIGHUP' to all jobs when an
2234interactive login shell exits.
cce855bc 2235
5e13499c
CR
2236 If Bash is waiting for a command to complete and receives a signal
2237for which a trap has been set, the trap will not be executed until the
2238command completes. When Bash is waiting for an asynchronous command
2239via the `wait' builtin, the reception of a signal for which a trap has
2240been set will cause the `wait' builtin to return immediately with an
2241exit status greater than 128, immediately after which the trap is
2242executed.
ccc6cda3
JA
2243
2244\1f
2245File: bashref.info, Node: Shell Scripts, Prev: Executing Commands, Up: Basic Shell Features
2246
37c41ab1
CR
22473.8 Shell Scripts
2248=================
ccc6cda3 2249
37c41ab1
CR
2250A shell script is a text file containing shell commands. When such a
2251file is used as the first non-option argument when invoking Bash, and
28ef6c31 2252neither the `-c' nor `-s' option is supplied (*note Invoking Bash::),
ccc6cda3 2253Bash reads and executes commands from the file, then exits. This mode
f73dda09
JA
2254of operation creates a non-interactive shell. The shell first searches
2255for the file in the current directory, and looks in the directories in
2256`$PATH' if not found there.
2257
2258 When Bash runs a shell script, it sets the special parameter `0' to
2259the name of the file, rather than the name of the shell, and the
2260positional parameters are set to the remaining arguments, if any are
2261given. If no additional arguments are supplied, the positional
2262parameters are unset.
ccc6cda3
JA
2263
2264 A shell script may be made executable by using the `chmod' command
2265to turn on the execute bit. When Bash finds such a file while
2266searching the `$PATH' for a command, it spawns a subshell to execute
2267it. In other words, executing
2268 filename ARGUMENTS
37c41ab1 2269 is equivalent to executing
ccc6cda3
JA
2270 bash filename ARGUMENTS
2271
2272if `filename' is an executable shell script. This subshell
2273reinitializes itself, so that the effect is as if a new shell had been
cce855bc
JA
2274invoked to interpret the script, with the exception that the locations
2275of commands remembered by the parent (see the description of `hash' in
6a8fd0ed 2276*note Bourne Shell Builtins::) are retained by the child.
ccc6cda3 2277
bb70624e
JA
2278 Most versions of Unix make this a part of the operating system's
2279command execution mechanism. If the first line of a script begins with
2280the two characters `#!', the remainder of the line specifies an
2281interpreter for the program. Thus, you can specify Bash, `awk', Perl,
2282or some other interpreter and write the rest of the script file in that
2283language.
2284
2285 The arguments to the interpreter consist of a single optional
2286argument following the interpreter name on the first line of the script
2287file, followed by the name of the script file, followed by the rest of
2288the arguments. Bash will perform this action on operating systems that
2289do not handle it themselves. Note that some older versions of Unix
2290limit the interpreter name and argument to a maximum of 32 characters.
2291
2292 Bash scripts often begin with `#! /bin/bash' (assuming that Bash has
2293been installed in `/bin'), since this ensures that Bash will be used to
2294interpret the script, even if it is executed under another shell.
ccc6cda3
JA
2295
2296\1f
bb70624e 2297File: bashref.info, Node: Shell Builtin Commands, Next: Shell Variables, Prev: Basic Shell Features, Up: Top
ccc6cda3 2298
37c41ab1
CR
22994 Shell Builtin Commands
2300************************
ccc6cda3
JA
2301
2302* Menu:
2303
2304* Bourne Shell Builtins:: Builtin commands inherited from the Bourne
2305 Shell.
bb70624e 2306* Bash Builtins:: Table of builtins specific to Bash.
d3ad40de
CR
2307* Modifying Shell Behavior:: Builtins to modify shell attributes and
2308 optional behavior.
bb70624e 2309* Special Builtins:: Builtin commands classified specially by
ac18b312 2310 POSIX.
bb70624e
JA
2311
2312 Builtin commands are contained within the shell itself. When the
2313name of a builtin command is used as the first word of a simple command
28ef6c31 2314(*note Simple Commands::), the shell executes the command directly,
bb70624e
JA
2315without invoking another program. Builtin commands are necessary to
2316implement functionality impossible or inconvenient to obtain with
2317separate utilities.
ccc6cda3 2318
ac18b312
CR
2319 This section briefly describes the builtins which Bash inherits from
2320the Bourne Shell, as well as the builtin commands which are unique to
2321or have been extended in Bash.
bb70624e
JA
2322
2323 Several builtin commands are described in other chapters: builtin
2324commands which provide the Bash interface to the job control facilities
28ef6c31
JA
2325(*note Job Control Builtins::), the directory stack (*note Directory
2326Stack Builtins::), the command history (*note Bash History Builtins::),
2327and the programmable completion facilities (*note Programmable
2328Completion Builtins::).
bb70624e
JA
2329
2330 Many of the builtins have been extended by POSIX or Bash.
ccc6cda3 2331
c2258e1c
CR
2332 Unless otherwise noted, each builtin command documented as accepting
2333options preceded by `-' accepts `--' to signify the end of the options.
1c72c0cd
CR
2334For example, the `:', `true', `false', and `test' builtins do not
2335accept options.
c2258e1c 2336
ccc6cda3 2337\1f
bb70624e 2338File: bashref.info, Node: Bourne Shell Builtins, Next: Bash Builtins, Up: Shell Builtin Commands
ccc6cda3 2339
37c41ab1
CR
23404.1 Bourne Shell Builtins
2341=========================
ccc6cda3 2342
37c41ab1 2343The following shell builtin commands are inherited from the Bourne
ac18b312 2344Shell. These commands are implemented as specified by the POSIX
ccc6cda3
JA
2345standard.
2346
bb70624e 2347`: (a colon)'
ccc6cda3
JA
2348 : [ARGUMENTS]
2349 Do nothing beyond expanding ARGUMENTS and performing redirections.
cce855bc 2350 The return status is zero.
ccc6cda3 2351
bb70624e 2352`. (a period)'
b72432fd 2353 . FILENAME [ARGUMENTS]
ccc6cda3 2354 Read and execute commands from the FILENAME argument in the
cce855bc 2355 current shell context. If FILENAME does not contain a slash, the
28ef6c31
JA
2356 `PATH' variable is used to find FILENAME. When Bash is not in
2357 POSIX mode, the current directory is searched if FILENAME is not
2358 found in `$PATH'. If any ARGUMENTS are supplied, they become the
2359 positional parameters when FILENAME is executed. Otherwise the
2360 positional parameters are unchanged. The return status is the
2361 exit status of the last command executed, or zero if no commands
2362 are executed. If FILENAME is not found, or cannot be read, the
2363 return status is non-zero. This builtin is equivalent to `source'.
ccc6cda3
JA
2364
2365`break'
2366 break [N]
2367 Exit from a `for', `while', `until', or `select' loop. If N is
cce855bc
JA
2368 supplied, the Nth enclosing loop is exited. N must be greater
2369 than or equal to 1. The return status is zero unless N is not
2370 greater than or equal to 1.
ccc6cda3
JA
2371
2372`cd'
7117c2d2 2373 cd [-L|-P] [DIRECTORY]
ccc6cda3
JA
2374 Change the current working directory to DIRECTORY. If DIRECTORY
2375 is not given, the value of the `HOME' shell variable is used. If
2376 the shell variable `CDPATH' exists, it is used as a search path.
d3a24ed2
CR
2377 If DIRECTORY begins with a slash, `CDPATH' is not used.
2378
2379 The `-P' option means to not follow symbolic links; symbolic links
2380 are followed by default or with the `-L' option. If DIRECTORY is
2381 `-', it is equivalent to `$OLDPWD'.
2382
2383 If a non-empty directory name from `CDPATH' is used, or if `-' is
2384 the first argument, and the directory change is successful, the
2385 absolute pathname of the new working directory is written to the
2386 standard output.
2387
2388 The return status is zero if the directory is successfully changed,
2389 non-zero otherwise.
ccc6cda3
JA
2390
2391`continue'
2392 continue [N]
2393 Resume the next iteration of an enclosing `for', `while', `until',
2394 or `select' loop. If N is supplied, the execution of the Nth
cce855bc
JA
2395 enclosing loop is resumed. N must be greater than or equal to 1.
2396 The return status is zero unless N is not greater than or equal to
2397 1.
ccc6cda3
JA
2398
2399`eval'
2400 eval [ARGUMENTS]
2401 The arguments are concatenated together into a single command,
cce855bc
JA
2402 which is then read and executed, and its exit status returned as
2403 the exit status of `eval'. If there are no arguments or only
2404 empty arguments, the return status is zero.
ccc6cda3
JA
2405
2406`exec'
cce855bc
JA
2407 exec [-cl] [-a NAME] [COMMAND [ARGUMENTS]]
2408 If COMMAND is supplied, it replaces the shell without creating a
2409 new process. If the `-l' option is supplied, the shell places a
d3ad40de
CR
2410 dash at the beginning of the zeroth argument passed to COMMAND.
2411 This is what the `login' program does. The `-c' option causes
2412 COMMAND to be executed with an empty environment. If `-a' is
2413 supplied, the shell passes NAME as the zeroth argument to COMMAND.
2414 If no COMMAND is specified, redirections may be used to affect the
cce855bc
JA
2415 current shell environment. If there are no redirection errors, the
2416 return status is zero; otherwise the return status is non-zero.
ccc6cda3
JA
2417
2418`exit'
2419 exit [N]
bb70624e
JA
2420 Exit the shell, returning a status of N to the shell's parent. If
2421 N is omitted, the exit status is that of the last command executed.
cce855bc 2422 Any trap on `EXIT' is executed before the shell terminates.
ccc6cda3
JA
2423
2424`export'
2425 export [-fn] [-p] [NAME[=VALUE]]
2426 Mark each NAME to be passed to child processes in the environment.
2427 If the `-f' option is supplied, the NAMEs refer to shell
cce855bc
JA
2428 functions; otherwise the names refer to shell variables. The `-n'
2429 option means to no longer mark each NAME for export. If no NAMES
2430 are supplied, or if the `-p' option is given, a list of exported
2431 names is displayed. The `-p' option displays output in a form
d3a24ed2
CR
2432 that may be reused as input. If a variable name is followed by
2433 =VALUE, the value of the variable is set to VALUE.
2434
2435 The return status is zero unless an invalid option is supplied,
2436 one of the names is not a valid shell variable name, or `-f' is
2437 supplied with a name that is not a shell function.
ccc6cda3
JA
2438
2439`getopts'
2440 getopts OPTSTRING NAME [ARGS]
2441 `getopts' is used by shell scripts to parse positional parameters.
bb70624e
JA
2442 OPTSTRING contains the option characters to be recognized; if a
2443 character is followed by a colon, the option is expected to have an
2444 argument, which should be separated from it by white space. The
2445 colon (`:') and question mark (`?') may not be used as option
2446 characters. Each time it is invoked, `getopts' places the next
2447 option in the shell variable NAME, initializing NAME if it does
2448 not exist, and the index of the next argument to be processed into
2449 the variable `OPTIND'. `OPTIND' is initialized to 1 each time the
2450 shell or a shell script is invoked. When an option requires an
2451 argument, `getopts' places that argument into the variable
2452 `OPTARG'. The shell does not reset `OPTIND' automatically; it
2453 must be manually reset between multiple calls to `getopts' within
2454 the same shell invocation if a new set of parameters is to be used.
ccc6cda3 2455
cce855bc
JA
2456 When the end of options is encountered, `getopts' exits with a
2457 return value greater than zero. `OPTIND' is set to the index of
2458 the first non-option argument, and `name' is set to `?'.
2459
2460 `getopts' normally parses the positional parameters, but if more
2461 arguments are given in ARGS, `getopts' parses those instead.
2462
ccc6cda3
JA
2463 `getopts' can report errors in two ways. If the first character of
2464 OPTSTRING is a colon, SILENT error reporting is used. In normal
cce855bc 2465 operation diagnostic messages are printed when invalid options or
ccc6cda3 2466 missing option arguments are encountered. If the variable `OPTERR'
cce855bc 2467 is set to 0, no error messages will be displayed, even if the first
ccc6cda3
JA
2468 character of `optstring' is not a colon.
2469
cce855bc 2470 If an invalid option is seen, `getopts' places `?' into NAME and,
ccc6cda3
JA
2471 if not silent, prints an error message and unsets `OPTARG'. If
2472 `getopts' is silent, the option character found is placed in
2473 `OPTARG' and no diagnostic message is printed.
2474
2475 If a required argument is not found, and `getopts' is not silent,
2476 a question mark (`?') is placed in NAME, `OPTARG' is unset, and a
2477 diagnostic message is printed. If `getopts' is silent, then a
2478 colon (`:') is placed in NAME and `OPTARG' is set to the option
2479 character found.
2480
ccc6cda3 2481`hash'
ac18b312 2482 hash [-r] [-p FILENAME] [-dt] [NAME]
cce855bc
JA
2483 Remember the full pathnames of commands specified as NAME
2484 arguments, so they need not be searched for on subsequent
2485 invocations. The commands are found by searching through the
2486 directories listed in `$PATH'. The `-p' option inhibits the path
2487 search, and FILENAME is used as the location of NAME. The `-r'
7117c2d2
JA
2488 option causes the shell to forget all remembered locations. The
2489 `-d' option causes the shell to forget the remembered location of
2490 each NAME. If the `-t' option is supplied, the full pathname to
2491 which each NAME corresponds is printed. If multiple NAME
2492 arguments are supplied with `-t' the NAME is printed before the
2493 hashed full pathname. The `-l' option causes output to be
2494 displayed in a format that may be reused as input. If no
2495 arguments are given, or if only `-l' is supplied, information
2496 about remembered commands is printed. The return status is zero
2497 unless a NAME is not found or an invalid option is supplied.
ccc6cda3
JA
2498
2499`pwd'
2500 pwd [-LP]
bb70624e
JA
2501 Print the absolute pathname of the current working directory. If
2502 the `-P' option is supplied, the pathname printed will not contain
2503 symbolic links. If the `-L' option is supplied, the pathname
2504 printed may contain symbolic links. The return status is zero
2505 unless an error is encountered while determining the name of the
2506 current directory or an invalid option is supplied.
ccc6cda3
JA
2507
2508`readonly'
d3a24ed2 2509 readonly [-apf] [NAME[=VALUE]] ...
cce855bc
JA
2510 Mark each NAME as readonly. The values of these names may not be
2511 changed by subsequent assignment. If the `-f' option is supplied,
2512 each NAME refers to a shell function. The `-a' option means each
2513 NAME refers to an array variable. If no NAME arguments are given,
2514 or if the `-p' option is supplied, a list of all readonly names is
2515 printed. The `-p' option causes output to be displayed in a
d3a24ed2
CR
2516 format that may be reused as input. If a variable name is
2517 followed by =VALUE, the value of the variable is set to VALUE.
2518 The return status is zero unless an invalid option is supplied,
2519 one of the NAME arguments is not a valid shell variable or
2520 function name, or the `-f' option is supplied with a name that is
2521 not a shell function.
ccc6cda3
JA
2522
2523`return'
2524 return [N]
bb70624e
JA
2525 Cause a shell function to exit with the return value N. If N is
2526 not supplied, the return value is the exit status of the last
2527 command executed in the function. This may also be used to
2528 terminate execution of a script being executed with the `.' (or
2529 `source') builtin, returning either N or the exit status of the
cce855bc 2530 last command executed within the script as the exit status of the
d3a24ed2
CR
2531 script. Any command associated with the `RETURN' trap is executed
2532 before execution resumes after the function or script. The return
2533 status is non-zero if `return' is used outside a function and not
2534 during the execution of a script by `.' or `source'.
ccc6cda3
JA
2535
2536`shift'
2537 shift [N]
cce855bc 2538 Shift the positional parameters to the left by N. The positional
d3ad40de
CR
2539 parameters from N+1 ... `$#' are renamed to `$1' ... `$#'-N.
2540 Parameters represented by the numbers `$#' to `$#'-N+1 are unset.
2541 N must be a non-negative number less than or equal to `$#'. If N
2542 is zero or greater than `$#', the positional parameters are not
bb70624e
JA
2543 changed. If N is not supplied, it is assumed to be 1. The return
2544 status is zero unless N is greater than `$#' or less than zero,
2545 non-zero otherwise.
ccc6cda3
JA
2546
2547`test'
2548`['
cce855bc
JA
2549 Evaluate a conditional expression EXPR. Each operator and operand
2550 must be a separate argument. Expressions are composed of the
6a8fd0ed 2551 primaries described below in *note Bash Conditional Expressions::.
1c72c0cd
CR
2552 `test' does not accept any options, nor does it accept and ignore
2553 an argument of `--' as signifying the end of options.
cce855bc 2554
bb70624e
JA
2555 When the `[' form is used, the last argument to the command must
2556 be a `]'.
2557
cce855bc 2558 Expressions may be combined using the following operators, listed
d7f49990
CR
2559 in decreasing order of precedence. The evaluation depends on the
2560 number of arguments; see below.
cce855bc
JA
2561
2562 `! EXPR'
2563 True if EXPR is false.
2564
2565 `( EXPR )'
2566 Returns the value of EXPR. This may be used to override the
2567 normal precedence of operators.
2568
2569 `EXPR1 -a EXPR2'
2570 True if both EXPR1 and EXPR2 are true.
2571
2572 `EXPR1 -o EXPR2'
2573 True if either EXPR1 or EXPR2 is true.
2574
2575 The `test' and `[' builtins evaluate conditional expressions using
2576 a set of rules based on the number of arguments.
2577
2578 0 arguments
2579 The expression is false.
2580
2581 1 argument
2582 The expression is true if and only if the argument is not
2583 null.
2584
2585 2 arguments
2586 If the first argument is `!', the expression is true if and
2587 only if the second argument is null. If the first argument
2588 is one of the unary conditional operators (*note Bash
28ef6c31 2589 Conditional Expressions::), the expression is true if the
cce855bc
JA
2590 unary test is true. If the first argument is not a valid
2591 unary operator, the expression is false.
2592
2593 3 arguments
2594 If the second argument is one of the binary conditional
28ef6c31 2595 operators (*note Bash Conditional Expressions::), the result
cce855bc 2596 of the expression is the result of the binary test using the
d7f49990
CR
2597 first and third arguments as operands. The `-a' and `-o'
2598 operators are considered binary operators when there are
2599 three arguments. If the first argument is `!', the value is
2600 the negation of the two-argument test using the second and
2601 third arguments. If the first argument is exactly `(' and
2602 the third argument is exactly `)', the result is the
2603 one-argument test of the second argument. Otherwise, the
2604 expression is false.
cce855bc
JA
2605
2606 4 arguments
2607 If the first argument is `!', the result is the negation of
2608 the three-argument expression composed of the remaining
2609 arguments. Otherwise, the expression is parsed and evaluated
2610 according to precedence using the rules listed above.
2611
2612 5 or more arguments
2613 The expression is parsed and evaluated according to precedence
2614 using the rules listed above.
ccc6cda3
JA
2615
2616`times'
2617 times
2618 Print out the user and system times used by the shell and its
cce855bc 2619 children. The return status is zero.
ccc6cda3
JA
2620
2621`trap'
d166f048 2622 trap [-lp] [ARG] [SIGSPEC ...]
ccc6cda3 2623 The commands in ARG are to be read and executed when the shell
9f422431
CR
2624 receives signal SIGSPEC. If ARG is absent (and there is a single
2625 SIGSPEC) or equal to `-', each specified signal's disposition is
2626 reset to the value it had when the shell was started. If ARG is
2627 the null string, then the signal specified by each SIGSPEC is
2628 ignored by the shell and commands it invokes. If ARG is not
2629 present and `-p' has been supplied, the shell displays the trap
2630 commands associated with each SIGSPEC. If no arguments are
2631 supplied, or only `-p' is given, `trap' prints the list of commands
2632 associated with each signal number in a form that may be reused as
2633 shell input. The `-l' option causes the shell to print a list of
2634 signal names and their corresponding numbers. Each SIGSPEC is
2635 either a signal name or a signal number. Signal names are case
2636 insensitive and the `SIG' prefix is optional. If a SIGSPEC is `0'
d3a24ed2
CR
2637 or `EXIT', ARG is executed when the shell exits. If a SIGSPEC is
2638 `DEBUG', the command ARG is executed before every simple command,
2639 `for' command, `case' command, `select' command, every arithmetic
2640 `for' command, and before the first command executes in a shell
2641 function. Refer to the description of the `extglob' option to the
d3ad40de
CR
2642 `shopt' builtin (*note The Shopt Builtin::) for details of its
2643 effect on the `DEBUG' trap. If a SIGSPEC is `ERR', the command ARG
2644 is executed whenever a simple command has a non-zero exit status,
5e13499c
CR
2645 subject to the following conditions. The `ERR' trap is not
2646 executed if the failed command is part of the command list
2647 immediately following an `until' or `while' keyword, part of the
c2a47ea9
CR
2648 test in an `if' statement, part of a command executed in a `&&' or
2649 `||' list, or if the command's return status is being inverted
2650 using `!'. These are the same conditions obeyed by the `errexit'
2651 option. If a SIGSPEC is `RETURN', the command ARG is executed
2652 each time a shell function or a script executed with the `.' or
2653 `source' builtins finishes executing.
d3a24ed2 2654
ccc6cda3 2655 Signals ignored upon entry to the shell cannot be trapped or reset.
d3ad40de
CR
2656 Trapped signals that are not being ignored are reset to their
2657 original values in a child process when it is created.
ccc6cda3 2658
cce855bc
JA
2659 The return status is zero unless a SIGSPEC does not specify a
2660 valid signal.
2661
ccc6cda3 2662`umask'
cce855bc 2663 umask [-p] [-S] [MODE]
ccc6cda3
JA
2664 Set the shell process's file creation mask to MODE. If MODE
2665 begins with a digit, it is interpreted as an octal number; if not,
2666 it is interpreted as a symbolic mode mask similar to that accepted
2667 by the `chmod' command. If MODE is omitted, the current value of
2668 the mask is printed. If the `-S' option is supplied without a
cce855bc
JA
2669 MODE argument, the mask is printed in a symbolic format. If the
2670 `-p' option is supplied, and MODE is omitted, the output is in a
2671 form that may be reused as input. The return status is zero if
2672 the mode is successfully changed or if no MODE argument is
2673 supplied, and non-zero otherwise.
ccc6cda3 2674
bb70624e
JA
2675 Note that when the mode is interpreted as an octal number, each
2676 number of the umask is subtracted from `7'. Thus, a umask of `022'
2677 results in permissions of `755'.
2678
ccc6cda3
JA
2679`unset'
2680 unset [-fv] [NAME]
2681 Each variable or function NAME is removed. If no options are
2682 supplied, or the `-v' option is given, each NAME refers to a shell
2683 variable. If the `-f' option is given, the NAMEs refer to shell
cce855bc
JA
2684 functions, and the function definition is removed. Readonly
2685 variables and functions may not be unset. The return status is
d3a24ed2 2686 zero unless a NAME is readonly.
ccc6cda3
JA
2687
2688\1f
d3ad40de 2689File: bashref.info, Node: Bash Builtins, Next: Modifying Shell Behavior, Prev: Bourne Shell Builtins, Up: Shell Builtin Commands
ccc6cda3 2690
37c41ab1
CR
26914.2 Bash Builtin Commands
2692=========================
ccc6cda3 2693
37c41ab1 2694This section describes builtin commands which are unique to or have
bb70624e 2695been extended in Bash. Some of these commands are specified in the
ac18b312 2696POSIX standard.
ccc6cda3 2697
bb70624e
JA
2698`alias'
2699 alias [`-p'] [NAME[=VALUE] ...]
ccc6cda3 2700
bb70624e
JA
2701 Without arguments or with the `-p' option, `alias' prints the list
2702 of aliases on the standard output in a form that allows them to be
2703 reused as input. If arguments are supplied, an alias is defined
2704 for each NAME whose VALUE is given. If no VALUE is given, the name
6a8fd0ed 2705 and value of the alias is printed. Aliases are described in *note
bb70624e 2706 Aliases::.
ccc6cda3 2707
bb70624e
JA
2708`bind'
2709 bind [-m KEYMAP] [-lpsvPSV]
2710 bind [-m KEYMAP] [-q FUNCTION] [-u FUNCTION] [-r KEYSEQ]
2711 bind [-m KEYMAP] -f FILENAME
2712 bind [-m KEYMAP] -x KEYSEQ:SHELL-COMMAND
2713 bind [-m KEYMAP] KEYSEQ:FUNCTION-NAME
7117c2d2 2714 bind READLINE-COMMAND
ccc6cda3 2715
28ef6c31 2716 Display current Readline (*note Command Line Editing::) key and
7117c2d2
JA
2717 function bindings, bind a key sequence to a Readline function or
2718 macro, or set a Readline variable. Each non-option argument is a
d3ad40de 2719 command as it would appear in a Readline initialization file
7117c2d2
JA
2720 (*note Readline Init File::), but each binding or command must be
2721 passed as a separate argument; e.g.,
ed35cb4a
CR
2722 `"\C-x\C-r":re-read-init-file'.
2723
2724 Options, if supplied, have the following meanings:
ccc6cda3 2725
bb70624e
JA
2726 `-m KEYMAP'
2727 Use KEYMAP as the keymap to be affected by the subsequent
2728 bindings. Acceptable KEYMAP names are `emacs',
28ef6c31 2729 `emacs-standard', `emacs-meta', `emacs-ctlx', `vi', `vi-move',
bb70624e
JA
2730 `vi-command', and `vi-insert'. `vi' is equivalent to
2731 `vi-command'; `emacs' is equivalent to `emacs-standard'.
cce855bc 2732
bb70624e
JA
2733 `-l'
2734 List the names of all Readline functions.
cce855bc 2735
bb70624e
JA
2736 `-p'
2737 Display Readline function names and bindings in such a way
2738 that they can be used as input or in a Readline
2739 initialization file.
cce855bc 2740
bb70624e
JA
2741 `-P'
2742 List current Readline function names and bindings.
cce855bc 2743
bb70624e
JA
2744 `-v'
2745 Display Readline variable names and values in such a way that
2746 they can be used as input or in a Readline initialization
2747 file.
ccc6cda3 2748
bb70624e
JA
2749 `-V'
2750 List current Readline variable names and values.
ccc6cda3 2751
bb70624e
JA
2752 `-s'
2753 Display Readline key sequences bound to macros and the
2754 strings they output in such a way that they can be used as
2755 input or in a Readline initialization file.
ccc6cda3 2756
bb70624e
JA
2757 `-S'
2758 Display Readline key sequences bound to macros and the
2759 strings they output.
ccc6cda3 2760
bb70624e
JA
2761 `-f FILENAME'
2762 Read key bindings from FILENAME.
ccc6cda3 2763
bb70624e
JA
2764 `-q FUNCTION'
2765 Query about which keys invoke the named FUNCTION.
ccc6cda3 2766
bb70624e
JA
2767 `-u FUNCTION'
2768 Unbind all keys bound to the named FUNCTION.
ccc6cda3 2769
bb70624e
JA
2770 `-r KEYSEQ'
2771 Remove any current binding for KEYSEQ.
ccc6cda3 2772
bb70624e
JA
2773 `-x KEYSEQ:SHELL-COMMAND'
2774 Cause SHELL-COMMAND to be executed whenever KEYSEQ is entered.
ed35cb4a
CR
2775 When SHELL-COMMAND is executed, the shell sets the
2776 `READLINE_LINE' variable to the contents of the Readline line
2777 buffer and the `READLINE_POINT' variable to the current
2778 location of the insertion point. If the executed command
2779 changes the value of `READLINE_LINE' or `READLINE_POINT',
2780 those new values will be reflected in the editing state.
761783bf 2781
bb70624e
JA
2782 The return status is zero unless an invalid option is supplied or
2783 an error occurs.
ccc6cda3 2784
bb70624e
JA
2785`builtin'
2786 builtin [SHELL-BUILTIN [ARGS]]
2787 Run a shell builtin, passing it ARGS, and return its exit status.
2788 This is useful when defining a shell function with the same name
2789 as a shell builtin, retaining the functionality of the builtin
2790 within the function. The return status is non-zero if
2791 SHELL-BUILTIN is not a shell builtin command.
ccc6cda3 2792
d3a24ed2
CR
2793`caller'
2794 caller [EXPR]
2795 Returns the context of any active subroutine call (a shell
5e13499c 2796 function or a script executed with the `.' or `source' builtins).
d3a24ed2
CR
2797
2798 Without EXPR, `caller' displays the line number and source
2799 filename of the current subroutine call. If a non-negative
2800 integer is supplied as EXPR, `caller' displays the line number,
2801 subroutine name, and source file corresponding to that position in
2802 the current execution call stack. This extra information may be
2803 used, for example, to print a stack trace. The current frame is
2804 frame 0.
2805
2806 The return value is 0 unless the shell is not executing a
2807 subroutine call or EXPR does not correspond to a valid position in
2808 the call stack.
2809
bb70624e
JA
2810`command'
2811 command [-pVv] COMMAND [ARGUMENTS ...]
2812 Runs COMMAND with ARGUMENTS ignoring any shell function named
2813 COMMAND. Only shell builtin commands or commands found by
2814 searching the `PATH' are executed. If there is a shell function
2815 named `ls', running `command ls' within the function will execute
2816 the external command `ls' instead of calling the function
2817 recursively. The `-p' option means to use a default value for
28ef6c31 2818 `PATH' that is guaranteed to find all of the standard utilities.
bb70624e
JA
2819 The return status in this case is 127 if COMMAND cannot be found
2820 or an error occurred, and the exit status of COMMAND otherwise.
ccc6cda3 2821
bb70624e
JA
2822 If either the `-V' or `-v' option is supplied, a description of
2823 COMMAND is printed. The `-v' option causes a single word
2824 indicating the command or file name used to invoke COMMAND to be
2825 displayed; the `-V' option produces a more verbose description.
2826 In this case, the return status is zero if COMMAND is found, and
2827 non-zero if not.
ccc6cda3 2828
bb70624e 2829`declare'
d3a24ed2 2830 declare [-afFirtx] [-p] [NAME[=VALUE] ...]
ccc6cda3 2831
bb70624e
JA
2832 Declare variables and give them attributes. If no NAMEs are
2833 given, then display the values of variables instead.
ccc6cda3 2834
bb70624e 2835 The `-p' option will display the attributes and values of each
6a8fd0ed
CR
2836 NAME. When `-p' is used with NAME arguments, additional options
2837 are ignored.
2838
2839 When `-p' is supplied without NAME arguments, `declare' will
2840 display the attributes and values of all variables having the
2841 attributes specified by the additional options. If no other
2842 options are supplied with `-p', `declare' will display the
2843 attributes and values of all shell variables. The `-f' option
2844 will restrict the display to shell functions.
2845
2846 The `-F' option inhibits the display of function definitions; only
2847 the function name and attributes are printed. If the `extdebug'
2848 shell option is enabled using `shopt' (*note The Shopt Builtin::),
2849 the source file name and line number where the function is defined
2850 are displayed as well. `-F' implies `-f'. The following options
2851 can be used to restrict output to variables with the specified
d3a24ed2 2852 attributes or to give variables attributes:
ccc6cda3 2853
bb70624e 2854 `-a'
28ef6c31 2855 Each NAME is an array variable (*note Arrays::).
ccc6cda3 2856
bb70624e
JA
2857 `-f'
2858 Use function names only.
ccc6cda3 2859
bb70624e
JA
2860 `-i'
2861 The variable is to be treated as an integer; arithmetic
28ef6c31 2862 evaluation (*note Shell Arithmetic::) is performed when the
bb70624e 2863 variable is assigned a value.
ccc6cda3 2864
bb70624e
JA
2865 `-r'
2866 Make NAMEs readonly. These names cannot then be assigned
2867 values by subsequent assignment statements or unset.
ccc6cda3 2868
7117c2d2
JA
2869 `-t'
2870 Give each NAME the `trace' attribute. Traced functions
8fed3589
CR
2871 inherit the `DEBUG' and `RETURN' traps from the calling shell.
2872 The trace attribute has no special meaning for variables.
7117c2d2 2873
bb70624e
JA
2874 `-x'
2875 Mark each NAME for export to subsequent commands via the
2876 environment.
ccc6cda3 2877
d3ad40de
CR
2878 Using `+' instead of `-' turns off the attribute instead, with the
2879 exceptions that `+a' may not be used to destroy an array variable
2880 and `+r' will not remove the readonly attribute. When used in a
2881 function, `declare' makes each NAME local, as with the `local'
2882 command. If a variable name is followed by =VALUE, the value of
2883 the variable is set to VALUE.
ccc6cda3 2884
bb70624e
JA
2885 The return status is zero unless an invalid option is encountered,
2886 an attempt is made to define a function using `-f foo=bar', an
2887 attempt is made to assign a value to a readonly variable, an
2888 attempt is made to assign a value to an array variable without
28ef6c31 2889 using the compound assignment syntax (*note Arrays::), one of the
bb70624e
JA
2890 NAMES is not a valid shell variable name, an attempt is made to
2891 turn off readonly status for a readonly variable, an attempt is
2892 made to turn off array status for an array variable, or an attempt
2893 is made to display a non-existent function with `-f'.
ccc6cda3 2894
bb70624e
JA
2895`echo'
2896 echo [-neE] [ARG ...]
2897 Output the ARGs, separated by spaces, terminated with a newline.
2898 The return status is always 0. If `-n' is specified, the trailing
2899 newline is suppressed. If the `-e' option is given,
2900 interpretation of the following backslash-escaped characters is
2901 enabled. The `-E' option disables the interpretation of these
2902 escape characters, even on systems where they are interpreted by
2903 default. The `xpg_echo' shell option may be used to dynamically
2904 determine whether or not `echo' expands these escape characters by
1c72c0cd
CR
2905 default. `echo' does not interpret `--' to mean the end of
2906 options.
2907
2908 `echo' interprets the following escape sequences:
bb70624e
JA
2909 `\a'
2910 alert (bell)
ccc6cda3 2911
bb70624e
JA
2912 `\b'
2913 backspace
ccc6cda3 2914
bb70624e
JA
2915 `\c'
2916 suppress trailing newline
ccc6cda3 2917
bb70624e
JA
2918 `\e'
2919 escape
ccc6cda3 2920
bb70624e
JA
2921 `\f'
2922 form feed
ccc6cda3 2923
bb70624e
JA
2924 `\n'
2925 new line
ccc6cda3 2926
bb70624e
JA
2927 `\r'
2928 carriage return
ccc6cda3 2929
bb70624e
JA
2930 `\t'
2931 horizontal tab
ccc6cda3 2932
bb70624e
JA
2933 `\v'
2934 vertical tab
ccc6cda3 2935
bb70624e
JA
2936 `\\'
2937 backslash
ccc6cda3 2938
7117c2d2
JA
2939 `\0NNN'
2940 the eight-bit character whose value is the octal value NNN
2941 (zero to three octal digits)
2942
f73dda09
JA
2943 `\xHH'
2944 the eight-bit character whose value is the hexadecimal value
2945 HH (one or two hex digits)
2946
bb70624e 2947`enable'
d3ad40de 2948 enable [-a] [-dnps] [-f FILENAME] [NAME ...]
bb70624e
JA
2949 Enable and disable builtin shell commands. Disabling a builtin
2950 allows a disk command which has the same name as a shell builtin
2951 to be executed without specifying a full pathname, even though the
2952 shell normally searches for builtins before disk commands. If
2953 `-n' is used, the NAMEs become disabled. Otherwise NAMEs are
2954 enabled. For example, to use the `test' binary found via `$PATH'
2955 instead of the shell builtin version, type `enable -n test'.
ccc6cda3 2956
bb70624e
JA
2957 If the `-p' option is supplied, or no NAME arguments appear, a
2958 list of shell builtins is printed. With no other arguments, the
2959 list consists of all enabled shell builtins. The `-a' option
2960 means to list each builtin with an indication of whether or not it
2961 is enabled.
ccc6cda3 2962
bb70624e
JA
2963 The `-f' option means to load the new builtin command NAME from
2964 shared object FILENAME, on systems that support dynamic loading.
2965 The `-d' option will delete a builtin loaded with `-f'.
ccc6cda3 2966
bb70624e
JA
2967 If there are no options, a list of the shell builtins is displayed.
2968 The `-s' option restricts `enable' to the POSIX special builtins.
2969 If `-s' is used with `-f', the new builtin becomes a special
28ef6c31 2970 builtin (*note Special Builtins::).
ccc6cda3 2971
bb70624e
JA
2972 The return status is zero unless a NAME is not a shell builtin or
2973 there is an error loading a new builtin from a shared object.
ccc6cda3 2974
bb70624e 2975`help'
ed35cb4a 2976 help [-dms] [PATTERN]
bb70624e
JA
2977 Display helpful information about builtin commands. If PATTERN is
2978 specified, `help' gives detailed help on all commands matching
ed35cb4a
CR
2979 PATTERN, otherwise a list of the builtins is printed.
2980
2981 Options, if supplied, have the following meanings:
2982
2983 `-d'
2984 Display a short description of each PATTERN
2985
2986 `-m'
2987 Display the description of each PATTERN in a manpage-like
2988 format
2989
2990 `-s'
2991 Display only a short usage synopsis for each PATTERN
2992
2993 The return status is zero unless no command matches PATTERN.
ccc6cda3 2994
bb70624e
JA
2995`let'
2996 let EXPRESSION [EXPRESSION]
2997 The `let' builtin allows arithmetic to be performed on shell
2998 variables. Each EXPRESSION is evaluated according to the rules
6a8fd0ed 2999 given below in *note Shell Arithmetic::. If the last EXPRESSION
bb70624e 3000 evaluates to 0, `let' returns 1; otherwise 0 is returned.
ccc6cda3 3001
bb70624e 3002`local'
d3a24ed2 3003 local [OPTION] NAME[=VALUE] ...
bb70624e
JA
3004 For each argument, a local variable named NAME is created, and
3005 assigned VALUE. The OPTION can be any of the options accepted by
3006 `declare'. `local' can only be used within a function; it makes
3007 the variable NAME have a visible scope restricted to that function
3008 and its children. The return status is zero unless `local' is
3009 used outside a function, an invalid NAME is supplied, or NAME is a
3010 readonly variable.
ccc6cda3 3011
bb70624e
JA
3012`logout'
3013 logout [N]
3014 Exit a login shell, returning a status of N to the shell's parent.
ccc6cda3 3015
ed35cb4a
CR
3016`mapfile'
3017 mapfile [-n COUNT] [-O ORIGIN] [-s COUNT] [-t] [-u FD] [
3018 -C CALLBACK] [-c QUANTUM] [ARRAY]
3019 Read lines from the standard input into array variable ARRAY, or
3020 from file descriptor FD if the `-u' option is supplied. The
3021 variable `MAPFILE' is the default ARRAY. Options, if supplied,
3022 have the following meanings:
3023 `-n'
3024 Copy at most COUNT lines. If COUNT is 0, all lines are
3025 copied.
3026
3027 `-O'
3028 Begin assigning to ARRAY at index ORIGIN. The default index
3029 is 0.
3030
3031 `-s'
3032 Discard the first COUNT lines read.
3033
3034 `-t'
3035 Remove a trailing line from each line read.
3036
3037 `-u'
3038 Read lines from file descriptor FD instead of the standard
3039 input.
3040
3041 `-C'
3042 Evaluate CALLBACK each time QUANTUMP lines are read. The
3043 `-c' option specifies QUANTUM.
3044
3045 `-c'
3046 Specify the number of lines read between each call to
3047 CALLBACK.
3048
3049 If `-C' is specified without `-c', the default quantum is 5000.
3050
3051 If not supplied with an explicit origin, `mapfile' will clear ARRAY
3052 before assigning to it.
3053
3054 `mapfile' returns successfully unless an invalid option or option
3055 argument is supplied, or ARRAY is invalid or unassignable.
3056
bb70624e 3057`printf'
29d25b54 3058 printf [-v VAR] FORMAT [ARGUMENTS]
bb70624e
JA
3059 Write the formatted ARGUMENTS to the standard output under the
3060 control of the FORMAT. The FORMAT is a character string which
3061 contains three types of objects: plain characters, which are
3062 simply copied to standard output, character escape sequences,
3063 which are converted and copied to the standard output, and format
3064 specifications, each of which causes printing of the next
3065 successive ARGUMENT. In addition to the standard `printf(1)'
3066 formats, `%b' causes `printf' to expand backslash escape sequences
5e13499c
CR
3067 in the corresponding ARGUMENT, (except that `\c' terminates
3068 output, backslashes in `\'', `\"', and `\?' are not removed, and
3069 octal escapes beginning with `\0' may contain up to four digits),
3070 and `%q' causes `printf' to output the corresponding ARGUMENT in a
3071 format that can be reused as shell input.
ccc6cda3 3072
3ee6b87d
CR
3073 The `-v' option causes the output to be assigned to the variable
3074 VAR rather than being printed to the standard output.
3075
bb70624e
JA
3076 The FORMAT is reused as necessary to consume all of the ARGUMENTS.
3077 If the FORMAT requires more ARGUMENTS than are supplied, the extra
3078 format specifications behave as if a zero value or null string, as
3079 appropriate, had been supplied. The return value is zero on
3080 success, non-zero on failure.
ccc6cda3 3081
bb70624e 3082`read'
6a8fd0ed 3083 read [-ers] [-a ANAME] [-d DELIM] [-i TEXT] [-n NCHARS] [-p PROMPT] [-t TIMEOUT] [-u FD] [NAME ...]
7117c2d2
JA
3084 One line is read from the standard input, or from the file
3085 descriptor FD supplied as an argument to the `-u' option, and the
3086 first word is assigned to the first NAME, the second word to the
3087 second NAME, and so on, with leftover words and their intervening
3088 separators assigned to the last NAME. If there are fewer words
3089 read from the input stream than names, the remaining names are
3090 assigned empty values. The characters in the value of the `IFS'
3091 variable are used to split the line into words. The backslash
3092 character `\' may be used to remove any special meaning for the
3093 next character read and for line continuation. If no names are
3094 supplied, the line read is assigned to the variable `REPLY'. The
3095 return code is zero, unless end-of-file is encountered, `read'
3096 times out, or an invalid file descriptor is supplied as the
3097 argument to `-u'. Options, if supplied, have the following
3098 meanings:
ccc6cda3 3099
bb70624e
JA
3100 `-a ANAME'
3101 The words are assigned to sequential indices of the array
3102 variable ANAME, starting at 0. All elements are removed from
3103 ANAME before the assignment. Other NAME arguments are
3104 ignored.
ccc6cda3 3105
bb70624e
JA
3106 `-d DELIM'
3107 The first character of DELIM is used to terminate the input
3108 line, rather than newline.
ccc6cda3 3109
bb70624e 3110 `-e'
28ef6c31
JA
3111 Readline (*note Command Line Editing::) is used to obtain the
3112 line.
ccc6cda3 3113
6a8fd0ed
CR
3114 `-i TEXT'
3115 If Readline is being used to read the line, TEXT is placed
3116 into the editing buffer before editing begins.
3117
bb70624e
JA
3118 `-n NCHARS'
3119 `read' returns after reading NCHARS characters rather than
3120 waiting for a complete line of input.
cce855bc 3121
bb70624e
JA
3122 `-p PROMPT'
3123 Display PROMPT, without a trailing newline, before attempting
3124 to read any input. The prompt is displayed only if input is
3125 coming from a terminal.
ccc6cda3 3126
bb70624e
JA
3127 `-r'
3128 If this option is given, backslash does not act as an escape
3129 character. The backslash is considered to be part of the
3130 line. In particular, a backslash-newline pair may not be
3131 used as a line continuation.
ccc6cda3 3132
bb70624e
JA
3133 `-s'
3134 Silent mode. If input is coming from a terminal, characters
3135 are not echoed.
cce855bc 3136
bb70624e
JA
3137 `-t TIMEOUT'
3138 Cause `read' to time out and return failure if a complete
ed35cb4a
CR
3139 line of input is not read within TIMEOUT seconds. TIMEOUT
3140 may be a decimal number with a fractional portion following
3141 the decimal point. This option has no effect if `read' is
3142 not reading input from the terminal or a pipe.
cce855bc 3143
7117c2d2
JA
3144 `-u FD'
3145 Read input from file descriptor FD.
3146
761783bf 3147
bb70624e
JA
3148`source'
3149 source FILENAME
28ef6c31 3150 A synonym for `.' (*note Bourne Shell Builtins::).
ccc6cda3 3151
bb70624e 3152`type'
7117c2d2 3153 type [-afptP] [NAME ...]
bb70624e
JA
3154 For each NAME, indicate how it would be interpreted if used as a
3155 command name.
cce855bc 3156
bb70624e
JA
3157 If the `-t' option is used, `type' prints a single word which is
3158 one of `alias', `function', `builtin', `file' or `keyword', if
3159 NAME is an alias, shell function, shell builtin, disk file, or
3160 shell reserved word, respectively. If the NAME is not found, then
3161 nothing is printed, and `type' returns a failure status.
ccc6cda3 3162
bb70624e
JA
3163 If the `-p' option is used, `type' either returns the name of the
3164 disk file that would be executed, or nothing if `-t' would not
3165 return `file'.
ccc6cda3 3166
7117c2d2
JA
3167 The `-P' option forces a path search for each NAME, even if `-t'
3168 would not return `file'.
3169
3170 If a command is hashed, `-p' and `-P' print the hashed value, not
3171 necessarily the file that appears first in `$PATH'.
3172
bb70624e
JA
3173 If the `-a' option is used, `type' returns all of the places that
3174 contain an executable named FILE. This includes aliases and
3175 functions, if and only if the `-p' option is not also used.
ccc6cda3 3176
7117c2d2
JA
3177 If the `-f' option is used, `type' does not attempt to find shell
3178 functions, as with the `command' builtin.
3179
ed35cb4a
CR
3180 The return status is zero if all of the NAMES are found, non-zero
3181 if any are not found.
ccc6cda3 3182
bb70624e 3183`typeset'
d3a24ed2 3184 typeset [-afFrxi] [-p] [NAME[=VALUE] ...]
bb70624e
JA
3185 The `typeset' command is supplied for compatibility with the Korn
3186 shell; however, it has been deprecated in favor of the `declare'
3187 builtin command.
ccc6cda3 3188
bb70624e 3189`ulimit'
6a8fd0ed 3190 ulimit [-abcdefilmnpqrstuvxHST] [LIMIT]
bb70624e
JA
3191 `ulimit' provides control over the resources available to processes
3192 started by the shell, on systems that allow such control. If an
3193 option is given, it is interpreted as follows:
3194 `-S'
3195 Change and report the soft limit associated with a resource.
ccc6cda3 3196
bb70624e
JA
3197 `-H'
3198 Change and report the hard limit associated with a resource.
ccc6cda3 3199
bb70624e
JA
3200 `-a'
3201 All current limits are reported.
ccc6cda3 3202
6a8fd0ed
CR
3203 `-b'
3204 The maximum socket buffer size.
3205
bb70624e
JA
3206 `-c'
3207 The maximum size of core files created.
ccc6cda3 3208
bb70624e
JA
3209 `-d'
3210 The maximum size of a process's data segment.
ccc6cda3 3211
ac18b312
CR
3212 `-e'
3213 The maximum scheduling priority ("nice").
3214
bb70624e 3215 `-f'
d3ad40de
CR
3216 The maximum size of files written by the shell and its
3217 children.
ccc6cda3 3218
ac18b312
CR
3219 `-i'
3220 The maximum number of pending signals.
3221
bb70624e
JA
3222 `-l'
3223 The maximum size that may be locked into memory.
ccc6cda3 3224
bb70624e
JA
3225 `-m'
3226 The maximum resident set size.
ccc6cda3 3227
bb70624e
JA
3228 `-n'
3229 The maximum number of open file descriptors.
ccc6cda3 3230
bb70624e
JA
3231 `-p'
3232 The pipe buffer size.
ccc6cda3 3233
ac18b312
CR
3234 `-q'
3235 The maximum number of bytes in POSIX message queues.
3236
3237 `-r'
3238 The maximum real-time scheduling priority.
3239
bb70624e
JA
3240 `-s'
3241 The maximum stack size.
ccc6cda3 3242
bb70624e
JA
3243 `-t'
3244 The maximum amount of cpu time in seconds.
ccc6cda3 3245
bb70624e
JA
3246 `-u'
3247 The maximum number of processes available to a single user.
cce855bc 3248
bb70624e
JA
3249 `-v'
3250 The maximum amount of virtual memory available to the process.
ccc6cda3 3251
ac18b312
CR
3252 `-x'
3253 The maximum number of file locks.
3254
6a8fd0ed
CR
3255 `-T'
3256 The maximum number of threads.
3257
761783bf 3258
f73dda09
JA
3259 If LIMIT is given, it is the new value of the specified resource;
3260 the special LIMIT values `hard', `soft', and `unlimited' stand for
3261 the current hard limit, the current soft limit, and no limit,
3d4e09aa
CR
3262 respectively. A hard limit cannot be increased by a non-root user
3263 once it is set; a soft limit may be increased up to the value of
3264 the hard limit. Otherwise, the current value of the soft limit
3265 for the specified resource is printed, unless the `-H' option is
f73dda09
JA
3266 supplied. When setting new limits, if neither `-H' nor `-S' is
3267 supplied, both the hard and soft limits are set. If no option is
3268 given, then `-f' is assumed. Values are in 1024-byte increments,
3269 except for `-t', which is in seconds, `-p', which is in units of
3270 512-byte blocks, and `-n' and `-u', which are unscaled values.
ccc6cda3 3271
f73dda09
JA
3272 The return status is zero unless an invalid option or argument is
3273 supplied, or an error occurs while setting a new limit.
ccc6cda3 3274
bb70624e
JA
3275`unalias'
3276 unalias [-a] [NAME ... ]
ccc6cda3 3277
bb70624e 3278 Remove each NAME from the list of aliases. If `-a' is supplied,
6a8fd0ed 3279 all aliases are removed. Aliases are described in *note Aliases::.
ccc6cda3 3280
761783bf 3281
bb70624e 3282\1f
d3ad40de 3283File: bashref.info, Node: Modifying Shell Behavior, Next: Special Builtins, Prev: Bash Builtins, Up: Shell Builtin Commands
ccc6cda3 3284
d3ad40de
CR
32854.3 Modifying Shell Behavior
3286============================
3287
3288* Menu:
3289
3290* The Set Builtin:: Change the values of shell attributes and
3291 positional parameters.
3292* The Shopt Builtin:: Modify shell optional behavior.
3293
3294\1f
3295File: bashref.info, Node: The Set Builtin, Next: The Shopt Builtin, Up: Modifying Shell Behavior
3296
32974.3.1 The Set Builtin
3298---------------------
9d6e5e30 3299
d3ad40de
CR
3300This builtin is so complicated that it deserves its own section. `set'
3301allows you to change the values of shell options and set the positional
3302parameters, or to display the names and values of shell variables.
ccc6cda3 3303
bb70624e 3304`set'
d3ad40de
CR
3305 set [--abefhkmnptuvxBCEHPT] [-o OPTION] [ARGUMENT ...]
3306 set [+abefhkmnptuvxBCEHPT] [+o OPTION] [ARGUMENT ...]
ccc6cda3 3307
bb70624e
JA
3308 If no options or arguments are supplied, `set' displays the names
3309 and values of all shell variables and functions, sorted according
54cdd75a
CR
3310 to the current locale, in a format that may be reused as input for
3311 setting or resetting the currently-set variables. Read-only
3312 variables cannot be reset. In POSIX mode, only shell variables
3313 are listed.
ccc6cda3 3314
bb70624e
JA
3315 When options are supplied, they set or unset shell attributes.
3316 Options, if specified, have the following meanings:
ccc6cda3 3317
bb70624e 3318 `-a'
28ef6c31
JA
3319 Mark variables and function which are modified or created for
3320 export to the environment of subsequent commands.
ccc6cda3 3321
bb70624e
JA
3322 `-b'
3323 Cause the status of terminated background jobs to be reported
3324 immediately, rather than before printing the next primary
3325 prompt.
ccc6cda3 3326
bb70624e
JA
3327 `-e'
3328 Exit immediately if a simple command (*note Simple
28ef6c31 3329 Commands::) exits with a non-zero status, unless the command
d3a24ed2
CR
3330 that fails is part of the command list immediately following
3331 a `while' or `until' keyword, part of the test in an `if'
c2a47ea9
CR
3332 statement, part of a command executed in a `&&' or `||b' list,
3333 any command in a pipeline but the last, or if the command's
3334 return status is being inverted using `!'. Failing simple
3335 commands that are part of shell functions or command lists
3336 enclosed in braces or parentheses satisfying the above
3337 conditions do not cause the shell to exit. A trap on `ERR',
3338 if set, is executed before the shell exits.
ccc6cda3 3339
bb70624e
JA
3340 `-f'
3341 Disable file name generation (globbing).
ccc6cda3 3342
bb70624e
JA
3343 `-h'
3344 Locate and remember (hash) commands as they are looked up for
3345 execution. This option is enabled by default.
ccc6cda3 3346
bb70624e
JA
3347 `-k'
3348 All arguments in the form of assignment statements are placed
3349 in the environment for a command, not just those that precede
3350 the command name.
ccc6cda3 3351
bb70624e 3352 `-m'
28ef6c31 3353 Job control is enabled (*note Job Control::).
b72432fd 3354
bb70624e
JA
3355 `-n'
3356 Read commands but do not execute them; this may be used to
3357 check a script for syntax errors. This option is ignored by
3358 interactive shells.
ccc6cda3 3359
bb70624e
JA
3360 `-o OPTION-NAME'
3361 Set the option corresponding to OPTION-NAME:
ccc6cda3 3362
bb70624e
JA
3363 `allexport'
3364 Same as `-a'.
ccc6cda3 3365
bb70624e
JA
3366 `braceexpand'
3367 Same as `-B'.
ccc6cda3 3368
bb70624e
JA
3369 `emacs'
3370 Use an `emacs'-style line editing interface (*note
28ef6c31 3371 Command Line Editing::).
ccc6cda3 3372
bb70624e
JA
3373 `errexit'
3374 Same as `-e'.
d166f048 3375
d3a24ed2
CR
3376 `errtrace'
3377 Same as `-E'.
3378
3379 `functrace'
3380 Same as `-T'.
3381
bb70624e
JA
3382 `hashall'
3383 Same as `-h'.
d166f048 3384
bb70624e
JA
3385 `histexpand'
3386 Same as `-H'.
ccc6cda3 3387
bb70624e 3388 `history'
6a8fd0ed 3389 Enable command history, as described in *note Bash
bb70624e
JA
3390 History Facilities::. This option is on by default in
3391 interactive shells.
ccc6cda3 3392
bb70624e
JA
3393 `ignoreeof'
3394 An interactive shell will not exit upon reading EOF.
ccc6cda3 3395
bb70624e
JA
3396 `keyword'
3397 Same as `-k'.
ccc6cda3 3398
bb70624e
JA
3399 `monitor'
3400 Same as `-m'.
ccc6cda3 3401
bb70624e
JA
3402 `noclobber'
3403 Same as `-C'.
ccc6cda3 3404
bb70624e
JA
3405 `noexec'
3406 Same as `-n'.
ccc6cda3 3407
28157acd
CR
3408 `noglob'
3409 Same as `-f'.
9d6e5e30 3410
d3ad40de
CR
3411 `nolog'
3412 Currently ignored.
3413
3414 `notify'
3415 Same as `-b'.
3416
3417 `nounset'
3418 Same as `-u'.
3419
3420 `onecmd'
3421 Same as `-t'.
3422
3423 `physical'
3424 Same as `-P'.
3425
3426 `pipefail'
3427 If set, the return value of a pipeline is the value of
3428 the last (rightmost) command to exit with a non-zero
3429 status, or zero if all commands in the pipeline exit
3430 successfully. This option is disabled by default.
3431
3432 `posix'
3433 Change the behavior of Bash where the default operation
3434 differs from the POSIX standard to match the standard
3435 (*note Bash POSIX Mode::). This is intended to make
3436 Bash behave as a strict superset of that standard.
3437
3438 `privileged'
3439 Same as `-p'.
3440
3441 `verbose'
3442 Same as `-v'.
3443
3444 `vi'
3445 Use a `vi'-style line editing interface.
3446
3447 `xtrace'
3448 Same as `-x'.
3449
3450 `-p'
3451 Turn on privileged mode. In this mode, the `$BASH_ENV' and
3452 `$ENV' files are not processed, shell functions are not
3453 inherited from the environment, and the `SHELLOPTS' variable,
3454 if it appears in the environment, is ignored. If the shell
3455 is started with the effective user (group) id not equal to the
3456 real user (group) id, and the `-p' option is not supplied,
3457 these actions are taken and the effective user id is set to
3458 the real user id. If the `-p' option is supplied at startup,
3459 the effective user id is not reset. Turning this option off
3460 causes the effective user and group ids to be set to the real
3461 user and group ids.
3462
3463 `-t'
3464 Exit after reading and executing one command.
3465
3466 `-u'
3467 Treat unset variables as an error when performing parameter
3468 expansion. An error message will be written to the standard
3469 error, and a non-interactive shell will exit.
3470
3471 `-v'
3472 Print shell input lines as they are read.
3473
3474 `-x'
3475 Print a trace of simple commands, `for' commands, `case'
3476 commands, `select' commands, and arithmetic `for' commands
3477 and their arguments or associated word lists after they are
3478 expanded and before they are executed. The value of the `PS4'
3479 variable is expanded and the resultant value is printed before
3480 the command and its expanded arguments.
3481
3482 `-B'
3483 The shell will perform brace expansion (*note Brace
3484 Expansion::). This option is on by default.
3485
3486 `-C'
3487 Prevent output redirection using `>', `>&', and `<>' from
3488 overwriting existing files.
3489
3490 `-E'
3491 If set, any trap on `ERR' is inherited by shell functions,
3492 command substitutions, and commands executed in a subshell
3493 environment. The `ERR' trap is normally not inherited in
3494 such cases.
3495
3496 `-H'
3497 Enable `!' style history substitution (*note History
3498 Interaction::). This option is on by default for interactive
3499 shells.
3500
3501 `-P'
3502 If set, do not follow symbolic links when performing commands
3503 such as `cd' which change the current directory. The
3504 physical directory is used instead. By default, Bash follows
3505 the logical chain of directories when performing commands
3506 which change the current directory.
3507
3508 For example, if `/usr/sys' is a symbolic link to
3509 `/usr/local/sys' then:
3510 $ cd /usr/sys; echo $PWD
3511 /usr/sys
3512 $ cd ..; pwd
3513 /usr
3514
3515 If `set -P' is on, then:
3516 $ cd /usr/sys; echo $PWD
3517 /usr/local/sys
3518 $ cd ..; pwd
3519 /usr/local
3520
3521 `-T'
3522 If set, any trap on `DEBUG' and `RETURN' are inherited by
3523 shell functions, command substitutions, and commands executed
3524 in a subshell environment. The `DEBUG' and `RETURN' traps
3525 are normally not inherited in such cases.
3526
3527 `--'
3528 If no arguments follow this option, then the positional
3529 parameters are unset. Otherwise, the positional parameters
3530 are set to the ARGUMENTS, even if some of them begin with a
3531 `-'.
3532
3533 `-'
3534 Signal the end of options, cause all remaining ARGUMENTS to
3535 be assigned to the positional parameters. The `-x' and `-v'
3536 options are turned off. If there are no arguments, the
3537 positional parameters remain unchanged.
3538
3539 Using `+' rather than `-' causes these options to be turned off.
3540 The options can also be used upon invocation of the shell. The
3541 current set of options may be found in `$-'.
3542
3543 The remaining N ARGUMENTS are positional parameters and are
3544 assigned, in order, to `$1', `$2', ... `$N'. The special
3545 parameter `#' is set to N.
3546
3547 The return status is always zero unless an invalid option is
3548 supplied.
3549
3550\1f
3551File: bashref.info, Node: The Shopt Builtin, Prev: The Set Builtin, Up: Modifying Shell Behavior
3552
35534.3.2 The Shopt Builtin
3554-----------------------
3555
3556This builtin allows you to change additional shell optional behavior.
3557
3558`shopt'
3559 shopt [-pqsu] [-o] [OPTNAME ...]
3560 Toggle the values of variables controlling optional shell behavior.
3561 With no options, or with the `-p' option, a list of all settable
3562 options is displayed, with an indication of whether or not each is
3563 set. The `-p' option causes output to be displayed in a form that
3564 may be reused as input. Other options have the following meanings:
3565
3566 `-s'
3567 Enable (set) each OPTNAME.
3568
3569 `-u'
3570 Disable (unset) each OPTNAME.
3571
3572 `-q'
3573 Suppresses normal output; the return status indicates whether
3574 the OPTNAME is set or unset. If multiple OPTNAME arguments
3575 are given with `-q', the return status is zero if all
3576 OPTNAMES are enabled; non-zero otherwise.
3577
3578 `-o'
3579 Restricts the values of OPTNAME to be those defined for the
3580 `-o' option to the `set' builtin (*note The Set Builtin::).
3581
3582 If either `-s' or `-u' is used with no OPTNAME arguments, the
3583 display is limited to those options which are set or unset,
3584 respectively.
3585
3586 Unless otherwise noted, the `shopt' options are disabled (off) by
3587 default.
3588
3589 The return status when listing options is zero if all OPTNAMES are
3590 enabled, non-zero otherwise. When setting or unsetting options,
3591 the return status is zero unless an OPTNAME is not a valid shell
3592 option.
3593
3594 The list of `shopt' options is:
3595 `autocd'
3596 If set, a command name that is the name of a directory is
3597 executed as if it were the argument to the `cd' command.
3598 This option is only used by interactive shells.
3599
3600 `cdable_vars'
3601 If this is set, an argument to the `cd' builtin command that
3602 is not a directory is assumed to be the name of a variable
3603 whose value is the directory to change to.
3604
3605 `cdspell'
3606 If set, minor errors in the spelling of a directory component
3607 in a `cd' command will be corrected. The errors checked for
3608 are transposed characters, a missing character, and a
3609 character too many. If a correction is found, the corrected
3610 path is printed, and the command proceeds. This option is
3611 only used by interactive shells.
3612
3613 `checkhash'
3614 If this is set, Bash checks that a command found in the hash
3615 table exists before trying to execute it. If a hashed
3616 command no longer exists, a normal path search is performed.
3617
3618 `checkjobs'
3619 If set, Bash lists the status of any stopped and running jobs
3620 before exiting an interactive shell. If any jobs are
3621 running, this causes the exit to be deferred until a second
3622 exit is attempted without an intervening command (*note Job
3623 Control::). The shell always postpones exiting if any jobs
3624 are stopped.
3625
3626 `checkwinsize'
3627 If set, Bash checks the window size after each command and,
3628 if necessary, updates the values of `LINES' and `COLUMNS'.
3629
3630 `cmdhist'
3631 If set, Bash attempts to save all lines of a multiple-line
3632 command in the same history entry. This allows easy
3633 re-editing of multi-line commands.
3634
29d25b54
CR
3635 `compat31'
3636 If set, Bash changes its behavior to that of version 3.1 with
3637 respect to quoted arguments to the conditional command's =~
3638 operator.
3639
ed35cb4a
CR
3640 `dirspell'
3641 If set, Bash attempts spelling correction on directory names
3642 during word completion if the directory name initially
3643 supplied does not exist.
3644
d3ad40de
CR
3645 `dotglob'
3646 If set, Bash includes filenames beginning with a `.' in the
3647 results of filename expansion.
3648
3649 `execfail'
3650 If this is set, a non-interactive shell will not exit if it
3651 cannot execute the file specified as an argument to the `exec'
3652 builtin command. An interactive shell does not exit if `exec'
3653 fails.
3654
3655 `expand_aliases'
3656 If set, aliases are expanded as described below under Aliases,
6a8fd0ed 3657 *note Aliases::. This option is enabled by default for
d3ad40de
CR
3658 interactive shells.
3659
3660 `extdebug'
3661 If set, behavior intended for use by debuggers is enabled:
3662
3663 1. The `-F' option to the `declare' builtin (*note Bash
3664 Builtins::) displays the source file name and line
3665 number corresponding to each function name supplied as
3666 an argument.
3667
3668 2. If the command run by the `DEBUG' trap returns a
3669 non-zero value, the next command is skipped and not
3670 executed.
3671
3672 3. If the command run by the `DEBUG' trap returns a value
3673 of 2, and the shell is executing in a subroutine (a
3674 shell function or a shell script executed by the `.' or
3675 `source' builtins), a call to `return' is simulated.
3676
3677 4. `BASH_ARGC' and `BASH_ARGV' are updated as described in
3678 their descriptions (*note Bash Variables::).
3679
3680 5. Function tracing is enabled: command substitution,
3681 shell functions, and subshells invoked with `( COMMAND
3682 )' inherit the `DEBUG' and `RETURN' traps.
9d6e5e30 3683
d3ad40de
CR
3684 6. Error tracing is enabled: command substitution, shell
3685 functions, and subshells invoked with `( COMMAND )'
3686 inherit the `ERROR' trap.
9d6e5e30 3687
d3ad40de
CR
3688 `extglob'
3689 If set, the extended pattern matching features described above
3690 (*note Pattern Matching::) are enabled.
9d6e5e30 3691
d3ad40de
CR
3692 `extquote'
3693 If set, `$'STRING'' and `$"STRING"' quoting is performed
3694 within `${PARAMETER}' expansions enclosed in double quotes.
3695 This option is enabled by default.
9d6e5e30 3696
d3ad40de
CR
3697 `failglob'
3698 If set, patterns which fail to match filenames during
3699 pathname expansion result in an expansion error.
9d6e5e30 3700
d3ad40de
CR
3701 `force_fignore'
3702 If set, the suffixes specified by the `FIGNORE' shell variable
3703 cause words to be ignored when performing word completion
3704 even if the ignored words are the only possible completions.
3705 *Note Bash Variables::, for a description of `FIGNORE'. This
3706 option is enabled by default.
9d6e5e30 3707
ed35cb4a
CR
3708 `globstar'
3709 If set, the pattern `**' used in a filename expansion context
3710 will match a files and zero or more directories and
3711 subdirectories. If the pattern is followed by a `/', only
3712 directories and subdirectories match.
3713
d3ad40de
CR
3714 `gnu_errfmt'
3715 If set, shell error messages are written in the standard GNU
3716 error message format.
9d6e5e30 3717
d3ad40de
CR
3718 `histappend'
3719 If set, the history list is appended to the file named by the
3720 value of the `HISTFILE' variable when the shell exits, rather
3721 than overwriting the file.
9d6e5e30 3722
d3ad40de
CR
3723 `histreedit'
3724 If set, and Readline is being used, a user is given the
3725 opportunity to re-edit a failed history substitution.
9d6e5e30 3726
d3ad40de
CR
3727 `histverify'
3728 If set, and Readline is being used, the results of history
3729 substitution are not immediately passed to the shell parser.
3730 Instead, the resulting line is loaded into the Readline
3731 editing buffer, allowing further modification.
9d6e5e30 3732
d3ad40de
CR
3733 `hostcomplete'
3734 If set, and Readline is being used, Bash will attempt to
3735 perform hostname completion when a word containing a `@' is
3736 being completed (*note Commands For Completion::). This
3737 option is enabled by default.
9d6e5e30 3738
d3ad40de
CR
3739 `huponexit'
3740 If set, Bash will send `SIGHUP' to all jobs when an
3741 interactive login shell exits (*note Signals::).
9d6e5e30 3742
d3ad40de
CR
3743 `interactive_comments'
3744 Allow a word beginning with `#' to cause that word and all
3745 remaining characters on that line to be ignored in an
3746 interactive shell. This option is enabled by default.
9d6e5e30 3747
d3ad40de
CR
3748 `lithist'
3749 If enabled, and the `cmdhist' option is enabled, multi-line
3750 commands are saved to the history with embedded newlines
3751 rather than using semicolon separators where possible.
9d6e5e30 3752
d3ad40de
CR
3753 `login_shell'
3754 The shell sets this option if it is started as a login shell
3755 (*note Invoking Bash::). The value may not be changed.
9d6e5e30 3756
d3ad40de
CR
3757 `mailwarn'
3758 If set, and a file that Bash is checking for mail has been
3759 accessed since the last time it was checked, the message
3760 `"The mail in MAILFILE has been read"' is displayed.
9d6e5e30 3761
d3ad40de
CR
3762 `no_empty_cmd_completion'
3763 If set, and Readline is being used, Bash will not attempt to
3764 search the `PATH' for possible completions when completion is
3765 attempted on an empty line.
9d6e5e30 3766
d3ad40de
CR
3767 `nocaseglob'
3768 If set, Bash matches filenames in a case-insensitive fashion
3769 when performing filename expansion.
9d6e5e30 3770
d3ad40de
CR
3771 `nocasematch'
3772 If set, Bash matches patterns in a case-insensitive fashion
3773 when performing matching while executing `case' or `[['
3774 conditional commands.
9d6e5e30 3775
d3ad40de
CR
3776 `nullglob'
3777 If set, Bash allows filename patterns which match no files to
3778 expand to a null string, rather than themselves.
9d6e5e30 3779
d3ad40de
CR
3780 `progcomp'
3781 If set, the programmable completion facilities (*note
3782 Programmable Completion::) are enabled. This option is
3783 enabled by default.
9d6e5e30 3784
d3ad40de
CR
3785 `promptvars'
3786 If set, prompt strings undergo parameter expansion, command
3787 substitution, arithmetic expansion, and quote removal after
3788 being expanded as described below (*note Printing a Prompt::).
3789 This option is enabled by default.
9d6e5e30 3790
d3ad40de
CR
3791 `restricted_shell'
3792 The shell sets this option if it is started in restricted mode
3793 (*note The Restricted Shell::). The value may not be changed.
3794 This is not reset when the startup files are executed,
3795 allowing the startup files to discover whether or not a shell
3796 is restricted.
9d6e5e30 3797
d3ad40de
CR
3798 `shift_verbose'
3799 If this is set, the `shift' builtin prints an error message
3800 when the shift count exceeds the number of positional
3801 parameters.
9d6e5e30 3802
d3ad40de
CR
3803 `sourcepath'
3804 If set, the `source' builtin uses the value of `PATH' to find
3805 the directory containing the file supplied as an argument.
3806 This option is enabled by default.
9d6e5e30 3807
d3ad40de
CR
3808 `xpg_echo'
3809 If set, the `echo' builtin expands backslash-escape sequences
3810 by default.
9d6e5e30
CR
3811
3812
d3ad40de
CR
3813 The return status when listing options is zero if all OPTNAMES are
3814 enabled, non-zero otherwise. When setting or unsetting options,
3815 the return status is zero unless an OPTNAME is not a valid shell
3816 option.
9d6e5e30
CR
3817
3818
3819\1f
d3ad40de 3820File: bashref.info, Node: Special Builtins, Prev: Modifying Shell Behavior, Up: Shell Builtin Commands
ccc6cda3 3821
37c41ab1
CR
38224.4 Special Builtins
3823====================
ccc6cda3 3824
ac18b312
CR
3825For historical reasons, the POSIX standard has classified several
3826builtin commands as _special_. When Bash is executing in POSIX mode,
3827the special builtins differ from other builtin commands in three
bb70624e 3828respects:
ccc6cda3 3829
bb70624e
JA
3830 1. Special builtins are found before shell functions during command
3831 lookup.
ccc6cda3 3832
bb70624e
JA
3833 2. If a special builtin returns an error status, a non-interactive
3834 shell exits.
ccc6cda3 3835
bb70624e
JA
3836 3. Assignment statements preceding the command stay in effect in the
3837 shell environment after the command completes.
ccc6cda3 3838
bb70624e
JA
3839 When Bash is not executing in POSIX mode, these builtins behave no
3840differently than the rest of the Bash builtin commands. The Bash POSIX
6a8fd0ed 3841mode is described in *note Bash POSIX Mode::.
ccc6cda3 3842
bb70624e
JA
3843 These are the POSIX special builtins:
3844 break : . continue eval exec exit export readonly return set
3845 shift trap unset
ccc6cda3 3846
bb70624e
JA
3847\1f
3848File: bashref.info, Node: Shell Variables, Next: Bash Features, Prev: Shell Builtin Commands, Up: Top
cce855bc 3849
37c41ab1
CR
38505 Shell Variables
3851*****************
ccc6cda3 3852
bb70624e 3853* Menu:
ccc6cda3 3854
bb70624e
JA
3855* Bourne Shell Variables:: Variables which Bash uses in the same way
3856 as the Bourne Shell.
3857* Bash Variables:: List of variables that exist in Bash.
ccc6cda3 3858
bb70624e
JA
3859 This chapter describes the shell variables that Bash uses. Bash
3860automatically assigns default values to a number of variables.
cce855bc 3861
bb70624e
JA
3862\1f
3863File: bashref.info, Node: Bourne Shell Variables, Next: Bash Variables, Up: Shell Variables
ccc6cda3 3864
37c41ab1
CR
38655.1 Bourne Shell Variables
3866==========================
cce855bc 3867
37c41ab1
CR
3868Bash uses certain shell variables in the same way as the Bourne shell.
3869In some cases, Bash assigns a default value to the variable.
cce855bc 3870
bb70624e
JA
3871`CDPATH'
3872 A colon-separated list of directories used as a search path for
3873 the `cd' builtin command.
ccc6cda3 3874
bb70624e
JA
3875`HOME'
3876 The current user's home directory; the default for the `cd' builtin
3877 command. The value of this variable is also used by tilde
28ef6c31 3878 expansion (*note Tilde Expansion::).
ccc6cda3 3879
bb70624e
JA
3880`IFS'
3881 A list of characters that separate fields; used when the shell
3882 splits words as part of expansion.
ccc6cda3 3883
bb70624e
JA
3884`MAIL'
3885 If this parameter is set to a filename and the `MAILPATH' variable
3886 is not set, Bash informs the user of the arrival of mail in the
3887 specified file.
cce855bc 3888
bb70624e
JA
3889`MAILPATH'
3890 A colon-separated list of filenames which the shell periodically
3891 checks for new mail. Each list entry can specify the message that
3892 is printed when new mail arrives in the mail file by separating
3893 the file name from the message with a `?'. When used in the text
3894 of the message, `$_' expands to the name of the current mail file.
cce855bc 3895
bb70624e
JA
3896`OPTARG'
3897 The value of the last option argument processed by the `getopts'
3898 builtin.
ccc6cda3 3899
bb70624e
JA
3900`OPTIND'
3901 The index of the last option argument processed by the `getopts'
3902 builtin.
ccc6cda3 3903
bb70624e
JA
3904`PATH'
3905 A colon-separated list of directories in which the shell looks for
d3a24ed2
CR
3906 commands. A zero-length (null) directory name in the value of
3907 `PATH' indicates the current directory. A null directory name may
3908 appear as two adjacent colons, or as an initial or trailing colon.
ccc6cda3 3909
bb70624e
JA
3910`PS1'
3911 The primary prompt string. The default value is `\s-\v\$ '.
3912 *Note Printing a Prompt::, for the complete list of escape
3913 sequences that are expanded before `PS1' is displayed.
ccc6cda3 3914
bb70624e
JA
3915`PS2'
3916 The secondary prompt string. The default value is `> '.
ccc6cda3 3917
761783bf 3918
bb70624e
JA
3919\1f
3920File: bashref.info, Node: Bash Variables, Prev: Bourne Shell Variables, Up: Shell Variables
ccc6cda3 3921
37c41ab1
CR
39225.2 Bash Variables
3923==================
ccc6cda3 3924
37c41ab1 3925These variables are set or used by Bash, but other shells do not
bb70624e 3926normally treat them specially.
ccc6cda3 3927
bb70624e
JA
3928 A few variables used by Bash are described in different chapters:
3929variables for controlling the job control facilities (*note Job Control
28ef6c31 3930Variables::).
ccc6cda3 3931
bb70624e
JA
3932`BASH'
3933 The full pathname used to execute the current instance of Bash.
ccc6cda3 3934
d3ad40de
CR
3935`BASHPID'
3936 Expands to the process id of the current Bash process. This
3937 differs from `$$' under certain circumstances, such as subshells
3938 that do not require Bash to be re-initialized.
3939
d3a24ed2
CR
3940`BASH_ARGC'
3941 An array variable whose values are the number of parameters in each
3942 frame of the current bash execution call stack. The number of
3943 parameters to the current subroutine (shell function or script
3944 executed with `.' or `source') is at the top of the stack. When a
3945 subroutine is executed, the number of parameters passed is pushed
9d2b70f0 3946 onto `BASH_ARGC'. The shell sets `BASH_ARGC' only when in
6a8fd0ed 3947 extended debugging mode (see *note The Shopt Builtin:: for a
9d2b70f0 3948 description of the `extdebug' option to the `shopt' builtin).
d3a24ed2
CR
3949
3950`BASH_ARGV'
3951 An array variable containing all of the parameters in the current
3952 bash execution call stack. The final parameter of the last
3953 subroutine call is at the top of the stack; the first parameter of
3954 the initial call is at the bottom. When a subroutine is executed,
9d2b70f0 3955 the parameters supplied are pushed onto `BASH_ARGV'. The shell
6a8fd0ed 3956 sets `BASH_ARGV' only when in extended debugging mode (see *note
d3ad40de
CR
3957 The Shopt Builtin:: for a description of the `extdebug' option to
3958 the `shopt' builtin).
d3a24ed2
CR
3959
3960`BASH_COMMAND'
3961 The command currently being executed or about to be executed,
3962 unless the shell is executing a command as the result of a trap,
3963 in which case it is the command executing at the time of the trap.
3964
bb70624e
JA
3965`BASH_ENV'
3966 If this variable is set when Bash is invoked to execute a shell
3967 script, its value is expanded and used as the name of a startup
3968 file to read before executing the script. *Note Bash Startup
3969 Files::.
ccc6cda3 3970
d3a24ed2
CR
3971`BASH_EXECUTION_STRING'
3972 The command argument to the `-c' invocation option.
3973
3974`BASH_LINENO'
3975 An array variable whose members are the line numbers in source
3976 files corresponding to each member of FUNCNAME.
3977 `${BASH_LINENO[$i]}' is the line number in the source file where
c2a47ea9
CR
3978 `${FUNCNAME[$i]}' was called (or `${BASH_LINENO[$i-1]}' if
3979 referenced within another shell function). The corresponding
3980 source file name is `${BASH_SOURCE[$i]}'. Use `LINENO' to obtain
3981 the current line number.
d3a24ed2 3982
5e13499c
CR
3983`BASH_REMATCH'
3984 An array variable whose members are assigned by the `=~' binary
3985 operator to the `[[' conditional command (*note Conditional
3986 Constructs::). The element with index 0 is the portion of the
3987 string matching the entire regular expression. The element with
3988 index N is the portion of the string matching the Nth
3989 parenthesized subexpression. This variable is read-only.
3990
d3a24ed2
CR
3991`BASH_SOURCE'
3992 An array variable whose members are the source filenames
3993 corresponding to the elements in the `FUNCNAME' array variable.
3994
3995`BASH_SUBSHELL'
3996 Incremented by one each time a subshell or subshell environment is
3997 spawned. The initial value is 0.
ccc6cda3 3998
bb70624e 3999`BASH_VERSINFO'
28ef6c31 4000 A readonly array variable (*note Arrays::) whose members hold
bb70624e
JA
4001 version information for this instance of Bash. The values
4002 assigned to the array members are as follows:
ccc6cda3 4003
bb70624e
JA
4004 `BASH_VERSINFO[0]'
4005 The major version number (the RELEASE).
ccc6cda3 4006
bb70624e
JA
4007 `BASH_VERSINFO[1]'
4008 The minor version number (the VERSION).
ccc6cda3 4009
bb70624e
JA
4010 `BASH_VERSINFO[2]'
4011 The patch level.
ccc6cda3 4012
bb70624e
JA
4013 `BASH_VERSINFO[3]'
4014 The build version.
ccc6cda3 4015
bb70624e
JA
4016 `BASH_VERSINFO[4]'
4017 The release status (e.g., BETA1).
ccc6cda3 4018
bb70624e
JA
4019 `BASH_VERSINFO[5]'
4020 The value of `MACHTYPE'.
ccc6cda3 4021
761783bf 4022
d3a24ed2
CR
4023`BASH_VERSION'
4024 The version number of the current instance of Bash.
4025
f73dda09
JA
4026`COLUMNS'
4027 Used by the `select' builtin command to determine the terminal
4028 width when printing selection lists. Automatically set upon
4029 receipt of a `SIGWINCH'.
bb70624e
JA
4030
4031`COMP_CWORD'
4032 An index into `${COMP_WORDS}' of the word containing the current
4033 cursor position. This variable is available only in shell
4034 functions invoked by the programmable completion facilities (*note
28ef6c31 4035 Programmable Completion::).
bb70624e
JA
4036
4037`COMP_LINE'
4038 The current command line. This variable is available only in
4039 shell functions and external commands invoked by the programmable
28ef6c31 4040 completion facilities (*note Programmable Completion::).
bb70624e
JA
4041
4042`COMP_POINT'
4043 The index of the current cursor position relative to the beginning
4044 of the current command. If the current cursor position is at the
4045 end of the current command, the value of this variable is equal to
4046 `${#COMP_LINE}'. This variable is available only in shell
4047 functions and external commands invoked by the programmable
28ef6c31 4048 completion facilities (*note Programmable Completion::).
bb70624e 4049
d3ad40de
CR
4050`COMP_TYPE'
4051 Set to an integer value corresponding to the type of completion
4052 attempted that caused a completion function to be called: TAB, for
4053 normal completion, `?', for listing completions after successive
4054 tabs, `!', for listing alternatives on partial word completion,
4055 `@', to list completions if the word is not unmodified, or `%',
4056 for menu completion. This variable is available only in shell
4057 functions and external commands invoked by the programmable
4058 completion facilities (*note Programmable Completion::).
4059
4060`COMP_KEY'
4061 The key (or final key of a key sequence) used to invoke the current
4062 completion function.
4063
d3a24ed2
CR
4064`COMP_WORDBREAKS'
4065 The set of characters that the Readline library treats as word
4066 separators when performing word completion. If `COMP_WORDBREAKS'
4067 is unset, it loses its special properties, even if it is
4068 subsequently reset.
4069
f73dda09
JA
4070`COMP_WORDS'
4071 An array variable consisting of the individual words in the
d3ad40de
CR
4072 current command line. The words are split on shell metacharacters
4073 as the shell parser would separate them. This variable is
4074 available only in shell functions invoked by the programmable
4075 completion facilities (*note Programmable Completion::).
f73dda09 4076
bb70624e
JA
4077`COMPREPLY'
4078 An array variable from which Bash reads the possible completions
4079 generated by a shell function invoked by the programmable
28ef6c31 4080 completion facility (*note Programmable Completion::).
ccc6cda3 4081
bb70624e
JA
4082`DIRSTACK'
4083 An array variable containing the current contents of the directory
4084 stack. Directories appear in the stack in the order they are
4085 displayed by the `dirs' builtin. Assigning to members of this
4086 array variable may be used to modify directories already in the
4087 stack, but the `pushd' and `popd' builtins must be used to add and
4088 remove directories. Assignment to this variable will not change
4089 the current directory. If `DIRSTACK' is unset, it loses its
4090 special properties, even if it is subsequently reset.
cce855bc 4091
d3a24ed2
CR
4092`EMACS'
4093 If Bash finds this variable in the environment when the shell
4094 starts with value `t', it assumes that the shell is running in an
4095 emacs shell buffer and disables line editing.
4096
bb70624e
JA
4097`EUID'
4098 The numeric effective user id of the current user. This variable
4099 is readonly.
cce855bc 4100
bb70624e
JA
4101`FCEDIT'
4102 The editor used as a default by the `-e' option to the `fc'
4103 builtin command.
ccc6cda3 4104
bb70624e
JA
4105`FIGNORE'
4106 A colon-separated list of suffixes to ignore when performing
4107 filename completion. A file name whose suffix matches one of the
4108 entries in `FIGNORE' is excluded from the list of matched file
4109 names. A sample value is `.o:~'
ccc6cda3 4110
f73dda09 4111`FUNCNAME'
d3a24ed2
CR
4112 An array variable containing the names of all shell functions
4113 currently in the execution call stack. The element with index 0
4114 is the name of any currently-executing shell function. The
d3ad40de 4115 bottom-most element is `"main"'. This variable exists only when a
d3a24ed2
CR
4116 shell function is executing. Assignments to `FUNCNAME' have no
4117 effect and return an error status. If `FUNCNAME' is unset, it
4118 loses its special properties, even if it is subsequently reset.
f73dda09 4119
bb70624e
JA
4120`GLOBIGNORE'
4121 A colon-separated list of patterns defining the set of filenames to
4122 be ignored by filename expansion. If a filename matched by a
4123 filename expansion pattern also matches one of the patterns in
4124 `GLOBIGNORE', it is removed from the list of matches.
ccc6cda3 4125
bb70624e
JA
4126`GROUPS'
4127 An array variable containing the list of groups of which the
4128 current user is a member. Assignments to `GROUPS' have no effect
28ef6c31 4129 and return an error status. If `GROUPS' is unset, it loses its
bb70624e 4130 special properties, even if it is subsequently reset.
ccc6cda3 4131
bb70624e
JA
4132`histchars'
4133 Up to three characters which control history expansion, quick
28ef6c31
JA
4134 substitution, and tokenization (*note History Interaction::). The
4135 first character is the HISTORY EXPANSION character, that is, the
4136 character which signifies the start of a history expansion,
bb70624e
JA
4137 normally `!'. The second character is the character which
4138 signifies `quick substitution' when seen as the first character on
4139 a line, normally `^'. The optional third character is the
4140 character which indicates that the remainder of the line is a
4141 comment when found as the first character of a word, usually `#'.
4142 The history comment character causes history substitution to be
4143 skipped for the remaining words on the line. It does not
4144 necessarily cause the shell parser to treat the rest of the line
4145 as a comment.
cce855bc 4146
bb70624e
JA
4147`HISTCMD'
4148 The history number, or index in the history list, of the current
4149 command. If `HISTCMD' is unset, it loses its special properties,
4150 even if it is subsequently reset.
ccc6cda3 4151
bb70624e 4152`HISTCONTROL'
d3a24ed2
CR
4153 A colon-separated list of values controlling how commands are
4154 saved on the history list. If the list of values includes
4155 `ignorespace', lines which begin with a space character are not
4156 saved in the history list. A value of `ignoredups' causes lines
4157 which match the previous history entry to not be saved. A value
4158 of `ignoreboth' is shorthand for `ignorespace' and `ignoredups'.
4159 A value of `erasedups' causes all previous lines matching the
4160 current line to be removed from the history list before that line
4161 is saved. Any value not in the above list is ignored. If
4162 `HISTCONTROL' is unset, or does not include a valid value, all
4163 lines read by the shell parser are saved on the history list,
4164 subject to the value of `HISTIGNORE'. The second and subsequent
4165 lines of a multi-line compound command are not tested, and are
4166 added to the history regardless of the value of `HISTCONTROL'.
ccc6cda3 4167
f73dda09
JA
4168`HISTFILE'
4169 The name of the file to which the command history is saved. The
4170 default value is `~/.bash_history'.
4171
4172`HISTFILESIZE'
4173 The maximum number of lines contained in the history file. When
4174 this variable is assigned a value, the history file is truncated,
d3ad40de
CR
4175 if necessary, by removing the oldest entries, to contain no more
4176 than that number of lines. The history file is also truncated to
4177 this size after writing it when an interactive shell exits. The
4178 default value is 500.
f73dda09 4179
bb70624e
JA
4180`HISTIGNORE'
4181 A colon-separated list of patterns used to decide which command
4182 lines should be saved on the history list. Each pattern is
4183 anchored at the beginning of the line and must match the complete
4184 line (no implicit `*' is appended). Each pattern is tested
4185 against the line after the checks specified by `HISTCONTROL' are
4186 applied. In addition to the normal shell pattern matching
4187 characters, `&' matches the previous history line. `&' may be
4188 escaped using a backslash; the backslash is removed before
4189 attempting a match. The second and subsequent lines of a
4190 multi-line compound command are not tested, and are added to the
4191 history regardless of the value of `HISTIGNORE'.
cce855bc 4192
bb70624e
JA
4193 `HISTIGNORE' subsumes the function of `HISTCONTROL'. A pattern of
4194 `&' is identical to `ignoredups', and a pattern of `[ ]*' is
4195 identical to `ignorespace'. Combining these two patterns,
4196 separating them with a colon, provides the functionality of
4197 `ignoreboth'.
ccc6cda3 4198
bb70624e
JA
4199`HISTSIZE'
4200 The maximum number of commands to remember on the history list.
4201 The default value is 500.
b72432fd 4202
d3a24ed2
CR
4203`HISTTIMEFORMAT'
4204 If this variable is set and not null, its value is used as a
4205 format string for STRFTIME to print the time stamp associated with
4206 each history entry displayed by the `history' builtin. If this
4207 variable is set, time stamps are written to the history file so
d3ad40de
CR
4208 they may be preserved across shell sessions. This uses the
4209 history comment character to distinguish timestamps from other
4210 history lines.
d3a24ed2 4211
bb70624e
JA
4212`HOSTFILE'
4213 Contains the name of a file in the same format as `/etc/hosts' that
4214 should be read when the shell needs to complete a hostname. The
4215 list of possible hostname completions may be changed while the
4216 shell is running; the next time hostname completion is attempted
4217 after the value is changed, Bash adds the contents of the new file
4218 to the existing list. If `HOSTFILE' is set, but has no value,
4219 Bash attempts to read `/etc/hosts' to obtain the list of possible
4220 hostname completions. When `HOSTFILE' is unset, the hostname list
4221 is cleared.
cce855bc 4222
bb70624e
JA
4223`HOSTNAME'
4224 The name of the current host.
cce855bc 4225
bb70624e
JA
4226`HOSTTYPE'
4227 A string describing the machine Bash is running on.
ccc6cda3 4228
bb70624e
JA
4229`IGNOREEOF'
4230 Controls the action of the shell on receipt of an `EOF' character
4231 as the sole input. If set, the value denotes the number of
4232 consecutive `EOF' characters that can be read as the first
4233 character on an input line before the shell will exit. If the
4234 variable exists but does not have a numeric value (or has no
4235 value) then the default is 10. If the variable does not exist,
4236 then `EOF' signifies the end of input to the shell. This is only
4237 in effect for interactive shells.
ccc6cda3 4238
bb70624e
JA
4239`INPUTRC'
4240 The name of the Readline initialization file, overriding the
4241 default of `~/.inputrc'.
ccc6cda3 4242
bb70624e
JA
4243`LANG'
4244 Used to determine the locale category for any category not
4245 specifically selected with a variable starting with `LC_'.
ccc6cda3 4246
bb70624e
JA
4247`LC_ALL'
4248 This variable overrides the value of `LANG' and any other `LC_'
4249 variable specifying a locale category.
cce855bc 4250
bb70624e
JA
4251`LC_COLLATE'
4252 This variable determines the collation order used when sorting the
4253 results of filename expansion, and determines the behavior of
4254 range expressions, equivalence classes, and collating sequences
4255 within filename expansion and pattern matching (*note Filename
28ef6c31 4256 Expansion::).
ccc6cda3 4257
bb70624e
JA
4258`LC_CTYPE'
4259 This variable determines the interpretation of characters and the
4260 behavior of character classes within filename expansion and pattern
28ef6c31 4261 matching (*note Filename Expansion::).
ccc6cda3 4262
bb70624e
JA
4263`LC_MESSAGES'
4264 This variable determines the locale used to translate double-quoted
28ef6c31 4265 strings preceded by a `$' (*note Locale Translation::).
ccc6cda3 4266
bb70624e
JA
4267`LC_NUMERIC'
4268 This variable determines the locale category used for number
4269 formatting.
ccc6cda3 4270
f73dda09
JA
4271`LINENO'
4272 The line number in the script or shell function currently
4273 executing.
4274
28ef6c31
JA
4275`LINES'
4276 Used by the `select' builtin command to determine the column length
4277 for printing selection lists. Automatically set upon receipt of a
4278 `SIGWINCH'.
4279
bb70624e
JA
4280`MACHTYPE'
4281 A string that fully describes the system type on which Bash is
4282 executing, in the standard GNU CPU-COMPANY-SYSTEM format.
ccc6cda3 4283
bb70624e
JA
4284`MAILCHECK'
4285 How often (in seconds) that the shell should check for mail in the
28ef6c31
JA
4286 files specified in the `MAILPATH' or `MAIL' variables. The
4287 default is 60 seconds. When it is time to check for mail, the
4288 shell does so before displaying the primary prompt. If this
4289 variable is unset, or set to a value that is not a number greater
4290 than or equal to zero, the shell disables mail checking.
ccc6cda3 4291
bb70624e
JA
4292`OLDPWD'
4293 The previous working directory as set by the `cd' builtin.
ccc6cda3 4294
bb70624e
JA
4295`OPTERR'
4296 If set to the value 1, Bash displays error messages generated by
4297 the `getopts' builtin command.
ccc6cda3 4298
bb70624e
JA
4299`OSTYPE'
4300 A string describing the operating system Bash is running on.
ccc6cda3 4301
bb70624e 4302`PIPESTATUS'
28ef6c31 4303 An array variable (*note Arrays::) containing a list of exit
bb70624e
JA
4304 status values from the processes in the most-recently-executed
4305 foreground pipeline (which may contain only a single command).
ccc6cda3 4306
f73dda09
JA
4307`POSIXLY_CORRECT'
4308 If this variable is in the environment when `bash' starts, the
4309 shell enters POSIX mode (*note Bash POSIX Mode::) before reading
4310 the startup files, as if the `--posix' invocation option had been
4311 supplied. If it is set while the shell is running, `bash' enables
4312 POSIX mode, as if the command
4313 `set -o posix'
f73dda09
JA
4314 had been executed.
4315
bb70624e
JA
4316`PPID'
4317 The process ID of the shell's parent process. This variable is
4318 readonly.
ccc6cda3 4319
bb70624e
JA
4320`PROMPT_COMMAND'
4321 If set, the value is interpreted as a command to execute before
4322 the printing of each primary prompt (`$PS1').
ccc6cda3 4323
bb70624e
JA
4324`PS3'
4325 The value of this variable is used as the prompt for the `select'
4326 command. If this variable is not set, the `select' command
4327 prompts with `#? '
ccc6cda3 4328
bb70624e
JA
4329`PS4'
4330 The value is the prompt printed before the command line is echoed
28ef6c31 4331 when the `-x' option is set (*note The Set Builtin::). The first
bb70624e
JA
4332 character of `PS4' is replicated multiple times, as necessary, to
4333 indicate multiple levels of indirection. The default is `+ '.
ccc6cda3 4334
bb70624e
JA
4335`PWD'
4336 The current working directory as set by the `cd' builtin.
ccc6cda3 4337
bb70624e
JA
4338`RANDOM'
4339 Each time this parameter is referenced, a random integer between 0
4340 and 32767 is generated. Assigning a value to this variable seeds
4341 the random number generator.
cce855bc 4342
bb70624e
JA
4343`REPLY'
4344 The default variable for the `read' builtin.
ccc6cda3 4345
bb70624e
JA
4346`SECONDS'
4347 This variable expands to the number of seconds since the shell was
4348 started. Assignment to this variable resets the count to the
4349 value assigned, and the expanded value becomes the value assigned
4350 plus the number of seconds since the assignment.
ccc6cda3 4351
9f422431
CR
4352`SHELL'
4353 The full pathname to the shell is kept in this environment
4354 variable. If it is not set when the shell starts, Bash assigns to
4355 it the full pathname of the current user's login shell.
4356
bb70624e
JA
4357`SHELLOPTS'
4358 A colon-separated list of enabled shell options. Each word in the
4359 list is a valid argument for the `-o' option to the `set' builtin
28ef6c31 4360 command (*note The Set Builtin::). The options appearing in
bb70624e
JA
4361 `SHELLOPTS' are those reported as `on' by `set -o'. If this
4362 variable is in the environment when Bash starts up, each shell
4363 option in the list will be enabled before reading any startup
4364 files. This variable is readonly.
ccc6cda3 4365
bb70624e
JA
4366`SHLVL'
4367 Incremented by one each time a new instance of Bash is started.
4368 This is intended to be a count of how deeply your Bash shells are
4369 nested.
cce855bc 4370
bb70624e
JA
4371`TIMEFORMAT'
4372 The value of this parameter is used as a format string specifying
4373 how the timing information for pipelines prefixed with the `time'
4374 reserved word should be displayed. The `%' character introduces an
4375 escape sequence that is expanded to a time value or other
4376 information. The escape sequences and their meanings are as
4377 follows; the braces denote optional portions.
cce855bc 4378
bb70624e
JA
4379 `%%'
4380 A literal `%'.
ccc6cda3 4381
bb70624e
JA
4382 `%[P][l]R'
4383 The elapsed time in seconds.
ccc6cda3 4384
bb70624e
JA
4385 `%[P][l]U'
4386 The number of CPU seconds spent in user mode.
ccc6cda3 4387
bb70624e
JA
4388 `%[P][l]S'
4389 The number of CPU seconds spent in system mode.
ccc6cda3 4390
bb70624e
JA
4391 `%P'
4392 The CPU percentage, computed as (%U + %S) / %R.
ccc6cda3 4393
bb70624e
JA
4394 The optional P is a digit specifying the precision, the number of
4395 fractional digits after a decimal point. A value of 0 causes no
4396 decimal point or fraction to be output. At most three places
4397 after the decimal point may be specified; values of P greater than
4398 3 are changed to 3. If P is not specified, the value 3 is used.
ccc6cda3 4399
bb70624e
JA
4400 The optional `l' specifies a longer format, including minutes, of
4401 the form MMmSS.FFs. The value of P determines whether or not the
4402 fraction is included.
ccc6cda3 4403
bb70624e
JA
4404 If this variable is not set, Bash acts as if it had the value
4405 `$'\nreal\t%3lR\nuser\t%3lU\nsys\t%3lS''
4406 If the value is null, no timing information is displayed. A
4407 trailing newline is added when the format string is displayed.
ccc6cda3 4408
bb70624e 4409`TMOUT'
7117c2d2
JA
4410 If set to a value greater than zero, `TMOUT' is treated as the
4411 default timeout for the `read' builtin (*note Bash Builtins::).
4412 The `select' command (*note Conditional Constructs::) terminates
4413 if input does not arrive after `TMOUT' seconds when input is coming
4414 from a terminal.
4415
d3ad40de 4416 In an interactive shell, the value is interpreted as the number of
7117c2d2
JA
4417 seconds to wait for input after issuing the primary prompt when
4418 the shell is interactive. Bash terminates after that number of
4419 seconds if input does not arrive.
ccc6cda3 4420
1c72c0cd
CR
4421`TMPDIR'
4422 If set, Bash uses its value as the name of a directory in which
4423 Bash creates temporary files for the shell's use.
4424
bb70624e
JA
4425`UID'
4426 The numeric real user id of the current user. This variable is
4427 readonly.
ccc6cda3 4428
761783bf 4429
bb70624e
JA
4430\1f
4431File: bashref.info, Node: Bash Features, Next: Job Control, Prev: Shell Variables, Up: Top
ccc6cda3 4432
37c41ab1
CR
44336 Bash Features
4434***************
ccc6cda3 4435
37c41ab1 4436This section describes features unique to Bash.
ccc6cda3 4437
bb70624e 4438* Menu:
ccc6cda3 4439
bb70624e
JA
4440* Invoking Bash:: Command line options that you can give
4441 to Bash.
4442* Bash Startup Files:: When and how Bash executes scripts.
4443* Interactive Shells:: What an interactive shell is.
4444* Bash Conditional Expressions:: Primitives used in composing expressions for
4445 the `test' builtin.
4446* Shell Arithmetic:: Arithmetic on shell variables.
4447* Aliases:: Substituting one command for another.
4448* Arrays:: Array Variables.
4449* The Directory Stack:: History of visited directories.
4450* Printing a Prompt:: Controlling the PS1 string.
4451* The Restricted Shell:: A more controlled mode of shell execution.
4452* Bash POSIX Mode:: Making Bash behave more closely to what
4453 the POSIX standard specifies.
ccc6cda3 4454
bb70624e
JA
4455\1f
4456File: bashref.info, Node: Invoking Bash, Next: Bash Startup Files, Up: Bash Features
ccc6cda3 4457
37c41ab1
CR
44586.1 Invoking Bash
4459=================
ccc6cda3 4460
f73dda09
JA
4461 bash [long-opt] [-ir] [-abefhkmnptuvxdBCDHP] [-o OPTION] [-O SHOPT_OPTION] [ARGUMENT ...]
4462 bash [long-opt] [-abefhkmnptuvxdBCDHP] [-o OPTION] [-O SHOPT_OPTION] -c STRING [ARGUMENT ...]
4463 bash [long-opt] -s [-abefhkmnptuvxdBCDHP] [-o OPTION] [-O SHOPT_OPTION] [ARGUMENT ...]
ccc6cda3 4464
bb70624e 4465 In addition to the single-character shell command-line options
28ef6c31 4466(*note The Set Builtin::), there are several multi-character options
bb70624e 4467that you can use. These options must appear on the command line before
7117c2d2 4468the single-character options to be recognized.
ccc6cda3 4469
d3a24ed2
CR
4470`--debugger'
4471 Arrange for the debugger profile to be executed before the shell
6a8fd0ed 4472 starts. Turns on extended debugging mode (see *note The Shopt
d3ad40de 4473 Builtin:: for a description of the `extdebug' option to the `shopt'
6a8fd0ed 4474 builtin) and shell function tracing (see *note The Set Builtin::
d3ad40de 4475 for a description of the `-o functrace' option).
d3a24ed2 4476
bb70624e
JA
4477`--dump-po-strings'
4478 A list of all double-quoted strings preceded by `$' is printed on
eb2bb562 4479 the standard output in the GNU `gettext' PO (portable object) file
bb70624e 4480 format. Equivalent to `-D' except for the output format.
ccc6cda3 4481
bb70624e
JA
4482`--dump-strings'
4483 Equivalent to `-D'.
ccc6cda3 4484
bb70624e 4485`--help'
d3ad40de 4486 Display a usage message on standard output and exit successfully.
ccc6cda3 4487
28ef6c31
JA
4488`--init-file FILENAME'
4489`--rcfile FILENAME'
4490 Execute commands from FILENAME (instead of `~/.bashrc') in an
4491 interactive shell.
4492
bb70624e 4493`--login'
7117c2d2 4494 Equivalent to `-l'.
ccc6cda3 4495
bb70624e 4496`--noediting'
28ef6c31 4497 Do not use the GNU Readline library (*note Command Line Editing::)
bb70624e 4498 to read command lines when the shell is interactive.
ccc6cda3 4499
bb70624e
JA
4500`--noprofile'
4501 Don't load the system-wide startup file `/etc/profile' or any of
4502 the personal initialization files `~/.bash_profile',
4503 `~/.bash_login', or `~/.profile' when Bash is invoked as a login
4504 shell.
ccc6cda3 4505
bb70624e
JA
4506`--norc'
4507 Don't read the `~/.bashrc' initialization file in an interactive
4508 shell. This is on by default if the shell is invoked as `sh'.
ccc6cda3 4509
bb70624e
JA
4510`--posix'
4511 Change the behavior of Bash where the default operation differs
ac18b312
CR
4512 from the POSIX standard to match the standard. This is intended
4513 to make Bash behave as a strict superset of that standard. *Note
4514 Bash POSIX Mode::, for a description of the Bash POSIX mode.
ccc6cda3 4515
bb70624e 4516`--restricted'
28ef6c31 4517 Make the shell a restricted shell (*note The Restricted Shell::).
ccc6cda3 4518
bb70624e
JA
4519`--verbose'
4520 Equivalent to `-v'. Print shell input lines as they're read.
ccc6cda3 4521
bb70624e
JA
4522`--version'
4523 Show version information for this instance of Bash on the standard
4524 output and exit successfully.
ccc6cda3 4525
761783bf 4526
bb70624e
JA
4527 There are several single-character options that may be supplied at
4528invocation which are not available with the `set' builtin.
ccc6cda3 4529
bb70624e
JA
4530`-c STRING'
4531 Read and execute commands from STRING after processing the
4532 options, then exit. Any remaining arguments are assigned to the
4533 positional parameters, starting with `$0'.
ccc6cda3 4534
bb70624e
JA
4535`-i'
4536 Force the shell to run interactively. Interactive shells are
6a8fd0ed 4537 described in *note Interactive Shells::.
ccc6cda3 4538
7117c2d2
JA
4539`-l'
4540 Make this shell act as if it had been directly invoked by login.
4541 When the shell is interactive, this is equivalent to starting a
4542 login shell with `exec -l bash'. When the shell is not
4543 interactive, the login shell startup files will be executed.
4544 `exec bash -l' or `exec bash --login' will replace the current
4545 shell with a Bash login shell. *Note Bash Startup Files::, for a
4546 description of the special behavior of a login shell.
4547
bb70624e 4548`-r'
28ef6c31 4549 Make the shell a restricted shell (*note The Restricted Shell::).
ccc6cda3 4550
bb70624e
JA
4551`-s'
4552 If this option is present, or if no arguments remain after option
4553 processing, then commands are read from the standard input. This
4554 option allows the positional parameters to be set when invoking an
4555 interactive shell.
ccc6cda3 4556
bb70624e
JA
4557`-D'
4558 A list of all double-quoted strings preceded by `$' is printed on
eb2bb562 4559 the standard output. These are the strings that are subject to
bb70624e 4560 language translation when the current locale is not `C' or `POSIX'
28ef6c31 4561 (*note Locale Translation::). This implies the `-n' option; no
bb70624e 4562 commands will be executed.
ccc6cda3 4563
f73dda09
JA
4564`[-+]O [SHOPT_OPTION]'
4565 SHOPT_OPTION is one of the shell options accepted by the `shopt'
d3ad40de
CR
4566 builtin (*note The Shopt Builtin::). If SHOPT_OPTION is present,
4567 `-O' sets the value of that option; `+O' unsets it. If
f73dda09
JA
4568 SHOPT_OPTION is not supplied, the names and values of the shell
4569 options accepted by `shopt' are printed on the standard output.
4570 If the invocation option is `+O', the output is displayed in a
4571 format that may be reused as input.
4572
bb70624e
JA
4573`--'
4574 A `--' signals the end of options and disables further option
4575 processing. Any arguments after the `--' are treated as filenames
4576 and arguments.
ccc6cda3 4577
761783bf 4578
f73dda09
JA
4579 A _login_ shell is one whose first character of argument zero is
4580`-', or one invoked with the `--login' option.
4581
28ef6c31 4582 An _interactive_ shell is one started without non-option arguments,
bb70624e
JA
4583unless `-s' is specified, without specifying the `-c' option, and whose
4584input and output are both connected to terminals (as determined by
4585`isatty(3)'), or one started with the `-i' option. *Note Interactive
28ef6c31 4586Shells::, for more information.
ccc6cda3 4587
bb70624e
JA
4588 If arguments remain after option processing, and neither the `-c'
4589nor the `-s' option has been supplied, the first argument is assumed to
28ef6c31
JA
4590be the name of a file containing shell commands (*note Shell Scripts::).
4591When Bash is invoked in this fashion, `$0' is set to the name of the
4592file, and the positional parameters are set to the remaining arguments.
4593Bash reads and executes commands from this file, then exits. Bash's
4594exit status is the exit status of the last command executed in the
4595script. If no commands are executed, the exit status is 0.
ccc6cda3 4596
bb70624e
JA
4597\1f
4598File: bashref.info, Node: Bash Startup Files, Next: Interactive Shells, Prev: Invoking Bash, Up: Bash Features
ccc6cda3 4599
37c41ab1
CR
46006.2 Bash Startup Files
4601======================
ccc6cda3 4602
d3ad40de 4603This section describes how Bash executes its startup files. If any of
37c41ab1
CR
4604the files exist but cannot be read, Bash reports an error. Tildes are
4605expanded in file names as described above under Tilde Expansion (*note
4606Tilde Expansion::).
ccc6cda3 4607
6a8fd0ed 4608 Interactive shells are described in *note Interactive Shells::.
ccc6cda3 4609
bb70624e
JA
4610Invoked as an interactive login shell, or with `--login'
4611........................................................
cce855bc 4612
37c41ab1 4613When Bash is invoked as an interactive login shell, or as a
bb70624e
JA
4614non-interactive shell with the `--login' option, it first reads and
4615executes commands from the file `/etc/profile', if that file exists.
4616After reading that file, it looks for `~/.bash_profile',
4617`~/.bash_login', and `~/.profile', in that order, and reads and
4618executes commands from the first one that exists and is readable. The
4619`--noprofile' option may be used when the shell is started to inhibit
4620this behavior.
ccc6cda3 4621
bb70624e
JA
4622 When a login shell exits, Bash reads and executes commands from the
4623file `~/.bash_logout', if it exists.
ccc6cda3 4624
bb70624e
JA
4625Invoked as an interactive non-login shell
4626.........................................
ccc6cda3 4627
37c41ab1 4628When an interactive shell that is not a login shell is started, Bash
bb70624e
JA
4629reads and executes commands from `~/.bashrc', if that file exists.
4630This may be inhibited by using the `--norc' option. The `--rcfile
4631FILE' option will force Bash to read and execute commands from FILE
4632instead of `~/.bashrc'.
ccc6cda3 4633
bb70624e
JA
4634 So, typically, your `~/.bash_profile' contains the line
4635 `if [ -f ~/.bashrc ]; then . ~/.bashrc; fi'
37c41ab1 4636 after (or before) any login-specific initializations.
ccc6cda3 4637
bb70624e
JA
4638Invoked non-interactively
4639.........................
ccc6cda3 4640
37c41ab1 4641When Bash is started non-interactively, to run a shell script, for
bb70624e
JA
4642example, it looks for the variable `BASH_ENV' in the environment,
4643expands its value if it appears there, and uses the expanded value as
4644the name of a file to read and execute. Bash behaves as if the
4645following command were executed:
4646 `if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi'
37c41ab1
CR
4647 but the value of the `PATH' variable is not used to search for the
4648file name.
ccc6cda3 4649
28ef6c31
JA
4650 As noted above, if a non-interactive shell is invoked with the
4651`--login' option, Bash attempts to read and execute commands from the
4652login shell startup files.
4653
bb70624e
JA
4654Invoked with name `sh'
4655......................
ccc6cda3 4656
37c41ab1 4657If Bash is invoked with the name `sh', it tries to mimic the startup
bb70624e
JA
4658behavior of historical versions of `sh' as closely as possible, while
4659conforming to the POSIX standard as well.
ccc6cda3 4660
bb70624e
JA
4661 When invoked as an interactive login shell, or as a non-interactive
4662shell with the `--login' option, it first attempts to read and execute
4663commands from `/etc/profile' and `~/.profile', in that order. The
4664`--noprofile' option may be used to inhibit this behavior. When
4665invoked as an interactive shell with the name `sh', Bash looks for the
4666variable `ENV', expands its value if it is defined, and uses the
4667expanded value as the name of a file to read and execute. Since a
4668shell invoked as `sh' does not attempt to read and execute commands
4669from any other startup files, the `--rcfile' option has no effect. A
4670non-interactive shell invoked with the name `sh' does not attempt to
4671read any other startup files.
ccc6cda3 4672
bb70624e
JA
4673 When invoked as `sh', Bash enters POSIX mode after the startup files
4674are read.
b72432fd 4675
bb70624e
JA
4676Invoked in POSIX mode
4677.....................
ccc6cda3 4678
37c41ab1
CR
4679When Bash is started in POSIX mode, as with the `--posix' command line
4680option, it follows the POSIX standard for startup files. In this mode,
4681interactive shells expand the `ENV' variable and commands are read and
4682executed from the file whose name is the expanded value. No other
4683startup files are read.
ccc6cda3 4684
bb70624e
JA
4685Invoked by remote shell daemon
4686..............................
ccc6cda3 4687
c2a47ea9
CR
4688Bash attempts to determine when it is being run with its standard input
4689connected to a a network connection, as if by the remote shell daemon,
4690usually `rshd', or the secure shell daemon `sshd'. If Bash determines
4691it is being run in this fashion, it reads and executes commands from
4692`~/.bashrc', if that file exists and is readable. It will not do this
4693if invoked as `sh'. The `--norc' option may be used to inhibit this
4694behavior, and the `--rcfile' option may be used to force another file
4695to be read, but `rshd' does not generally invoke the shell with those
4696options or allow them to be specified.
ccc6cda3 4697
bb70624e
JA
4698Invoked with unequal effective and real UID/GIDs
4699................................................
4700
37c41ab1
CR
4701If Bash is started with the effective user (group) id not equal to the
4702real user (group) id, and the `-p' option is not supplied, no startup
4703files are read, shell functions are not inherited from the environment,
4704the `SHELLOPTS' variable, if it appears in the environment, is ignored,
4705and the effective user id is set to the real user id. If the `-p'
4706option is supplied at invocation, the startup behavior is the same, but
4707the effective user id is not reset.
bb70624e
JA
4708
4709\1f
4710File: bashref.info, Node: Interactive Shells, Next: Bash Conditional Expressions, Prev: Bash Startup Files, Up: Bash Features
4711
37c41ab1
CR
47126.3 Interactive Shells
4713======================
bb70624e
JA
4714
4715* Menu:
4716
4717* What is an Interactive Shell?:: What determines whether a shell is Interactive.
4718* Is this Shell Interactive?:: How to tell if a shell is interactive.
4719* Interactive Shell Behavior:: What changes in a interactive shell?
4720
4721\1f
4722File: bashref.info, Node: What is an Interactive Shell?, Next: Is this Shell Interactive?, Up: Interactive Shells
4723
37c41ab1
CR
47246.3.1 What is an Interactive Shell?
4725-----------------------------------
bb70624e 4726
37c41ab1 4727An interactive shell is one started without non-option arguments,
d3ad40de
CR
4728unless `-s' is specified, without specifying the `-c' option, and whose
4729input and error output are both connected to terminals (as determined
4730by `isatty(3)'), or one started with the `-i' option.
bb70624e
JA
4731
4732 An interactive shell generally reads from and writes to a user's
4733terminal.
4734
4735 The `-s' invocation option may be used to set the positional
4736parameters when an interactive shell is started.
4737
4738\1f
4739File: bashref.info, Node: Is this Shell Interactive?, Next: Interactive Shell Behavior, Prev: What is an Interactive Shell?, Up: Interactive Shells
4740
37c41ab1
CR
47416.3.2 Is this Shell Interactive?
4742--------------------------------
bb70624e 4743
37c41ab1 4744To determine within a startup script whether or not Bash is running
bb70624e
JA
4745interactively, test the value of the `-' special parameter. It
4746contains `i' when the shell is interactive. For example:
4747
4748 case "$-" in
4749 *i*) echo This shell is interactive ;;
4750 *) echo This shell is not interactive ;;
4751 esac
4752
28ef6c31
JA
4753 Alternatively, startup scripts may examine the variable `PS1'; it is
4754unset in non-interactive shells, and set in interactive shells. Thus:
bb70624e
JA
4755
4756 if [ -z "$PS1" ]; then
4757 echo This shell is not interactive
4758 else
4759 echo This shell is interactive
4760 fi
4761
4762\1f
4763File: bashref.info, Node: Interactive Shell Behavior, Prev: Is this Shell Interactive?, Up: Interactive Shells
4764
37c41ab1
CR
47656.3.3 Interactive Shell Behavior
4766--------------------------------
bb70624e 4767
37c41ab1 4768When the shell is running interactively, it changes its behavior in
bb70624e
JA
4769several ways.
4770
6a8fd0ed 4771 1. Startup files are read and executed as described in *note Bash
bb70624e
JA
4772 Startup Files::.
4773
28ef6c31 4774 2. Job Control (*note Job Control::) is enabled by default. When job
bb70624e
JA
4775 control is in effect, Bash ignores the keyboard-generated job
4776 control signals `SIGTTIN', `SIGTTOU', and `SIGTSTP'.
4777
28ef6c31
JA
4778 3. Bash expands and displays `PS1' before reading the first line of a
4779 command, and expands and displays `PS2' before reading the second
4780 and subsequent lines of a multi-line command.
bb70624e
JA
4781
4782 4. Bash executes the value of the `PROMPT_COMMAND' variable as a
4783 command before printing the primary prompt, `$PS1' (*note Bash
28ef6c31 4784 Variables::).
bb70624e 4785
28ef6c31 4786 5. Readline (*note Command Line Editing::) is used to read commands
bb70624e
JA
4787 from the user's terminal.
4788
4789 6. Bash inspects the value of the `ignoreeof' option to `set -o'
4790 instead of exiting immediately when it receives an `EOF' on its
28ef6c31 4791 standard input when reading a command (*note The Set Builtin::).
bb70624e 4792
28ef6c31
JA
4793 7. Command history (*note Bash History Facilities::) and history
4794 expansion (*note History Interaction::) are enabled by default.
bb70624e
JA
4795 Bash will save the command history to the file named by `$HISTFILE'
4796 when an interactive shell exits.
4797
28ef6c31 4798 8. Alias expansion (*note Aliases::) is performed by default.
bb70624e
JA
4799
4800 9. In the absence of any traps, Bash ignores `SIGTERM' (*note
28ef6c31 4801 Signals::).
bb70624e
JA
4802
4803 10. In the absence of any traps, `SIGINT' is caught and handled
28ef6c31 4804 ((*note Signals::). `SIGINT' will interrupt some shell builtins.
bb70624e
JA
4805
4806 11. An interactive login shell sends a `SIGHUP' to all jobs on exit if
d3ad40de 4807 the `huponexit' shell option has been enabled (*note Signals::).
bb70624e
JA
4808
4809 12. The `-n' invocation option is ignored, and `set -n' has no effect
28ef6c31 4810 (*note The Set Builtin::).
bb70624e
JA
4811
4812 13. Bash will check for mail periodically, depending on the values of
4813 the `MAIL', `MAILPATH', and `MAILCHECK' shell variables (*note
28ef6c31 4814 Bash Variables::).
bb70624e
JA
4815
4816 14. Expansion errors due to references to unbound shell variables after
4817 `set -u' has been enabled will not cause the shell to exit (*note
28ef6c31 4818 The Set Builtin::).
bb70624e
JA
4819
4820 15. The shell will not exit on expansion errors caused by VAR being
4821 unset or null in `${VAR:?WORD}' expansions (*note Shell Parameter
28ef6c31 4822 Expansion::).
bb70624e
JA
4823
4824 16. Redirection errors encountered by shell builtins will not cause the
4825 shell to exit.
4826
4827 17. When running in POSIX mode, a special builtin returning an error
28ef6c31 4828 status will not cause the shell to exit (*note Bash POSIX Mode::).
bb70624e
JA
4829
4830 18. A failed `exec' will not cause the shell to exit (*note Bourne
28ef6c31 4831 Shell Builtins::).
bb70624e
JA
4832
4833 19. Parser syntax errors will not cause the shell to exit.
4834
4835 20. Simple spelling correction for directory arguments to the `cd'
4836 builtin is enabled by default (see the description of the `cdspell'
6a8fd0ed 4837 option to the `shopt' builtin in *note The Shopt Builtin::).
bb70624e
JA
4838
4839 21. The shell will check the value of the `TMOUT' variable and exit if
4840 a command is not read within the specified number of seconds after
28ef6c31 4841 printing `$PS1' (*note Bash Variables::).
bb70624e
JA
4842
4843
4844\1f
4845File: bashref.info, Node: Bash Conditional Expressions, Next: Shell Arithmetic, Prev: Interactive Shells, Up: Bash Features
4846
37c41ab1
CR
48476.4 Bash Conditional Expressions
4848================================
bb70624e 4849
37c41ab1
CR
4850Conditional expressions are used by the `[[' compound command and the
4851`test' and `[' builtin commands.
bb70624e
JA
4852
4853 Expressions may be unary or binary. Unary expressions are often
4854used to examine the status of a file. There are string operators and
4855numeric comparison operators as well. If the FILE argument to one of
4856the primaries is of the form `/dev/fd/N', then file descriptor N is
4857checked. If the FILE argument to one of the primaries is one of
4858`/dev/stdin', `/dev/stdout', or `/dev/stderr', file descriptor 0, 1, or
48592, respectively, is checked.
4860
37c41ab1
CR
4861 Unless otherwise specified, primaries that operate on files follow
4862symbolic links and operate on the target of the link, rather than the
4863link itself.
4864
bb70624e
JA
4865`-a FILE'
4866 True if FILE exists.
4867
4868`-b FILE'
4869 True if FILE exists and is a block special file.
4870
4871`-c FILE'
4872 True if FILE exists and is a character special file.
4873
4874`-d FILE'
4875 True if FILE exists and is a directory.
4876
4877`-e FILE'
4878 True if FILE exists.
4879
4880`-f FILE'
4881 True if FILE exists and is a regular file.
4882
4883`-g FILE'
4884 True if FILE exists and its set-group-id bit is set.
4885
4886`-h FILE'
4887 True if FILE exists and is a symbolic link.
4888
4889`-k FILE'
4890 True if FILE exists and its "sticky" bit is set.
4891
4892`-p FILE'
4893 True if FILE exists and is a named pipe (FIFO).
4894
4895`-r FILE'
4896 True if FILE exists and is readable.
4897
4898`-s FILE'
4899 True if FILE exists and has a size greater than zero.
4900
4901`-t FD'
4902 True if file descriptor FD is open and refers to a terminal.
ccc6cda3
JA
4903
4904`-u FILE'
4905 True if FILE exists and its set-user-id bit is set.
4906
4907`-w FILE'
4908 True if FILE exists and is writable.
4909
4910`-x FILE'
4911 True if FILE exists and is executable.
4912
4913`-O FILE'
4914 True if FILE exists and is owned by the effective user id.
4915
4916`-G FILE'
4917 True if FILE exists and is owned by the effective group id.
4918
cce855bc
JA
4919`-L FILE'
4920 True if FILE exists and is a symbolic link.
4921
4922`-S FILE'
4923 True if FILE exists and is a socket.
4924
4925`-N FILE'
4926 True if FILE exists and has been modified since it was last read.
4927
ccc6cda3 4928`FILE1 -nt FILE2'
7117c2d2
JA
4929 True if FILE1 is newer (according to modification date) than
4930 FILE2, or if FILE1 exists and FILE2 does not.
ccc6cda3
JA
4931
4932`FILE1 -ot FILE2'
7117c2d2
JA
4933 True if FILE1 is older than FILE2, or if FILE2 exists and FILE1
4934 does not.
ccc6cda3
JA
4935
4936`FILE1 -ef FILE2'
7117c2d2 4937 True if FILE1 and FILE2 refer to the same device and inode numbers.
ccc6cda3
JA
4938
4939`-o OPTNAME'
4940 True if shell option OPTNAME is enabled. The list of options
4941 appears in the description of the `-o' option to the `set' builtin
28ef6c31 4942 (*note The Set Builtin::).
ccc6cda3
JA
4943
4944`-z STRING'
4945 True if the length of STRING is zero.
4946
4947`-n STRING'
4948`STRING'
4949 True if the length of STRING is non-zero.
4950
cce855bc 4951`STRING1 == STRING2'
7117c2d2
JA
4952 True if the strings are equal. `=' may be used in place of `=='
4953 for strict POSIX compliance.
ccc6cda3
JA
4954
4955`STRING1 != STRING2'
4956 True if the strings are not equal.
4957
4958`STRING1 < STRING2'
cce855bc
JA
4959 True if STRING1 sorts before STRING2 lexicographically in the
4960 current locale.
ccc6cda3
JA
4961
4962`STRING1 > STRING2'
cce855bc
JA
4963 True if STRING1 sorts after STRING2 lexicographically in the
4964 current locale.
ccc6cda3
JA
4965
4966`ARG1 OP ARG2'
4967 `OP' is one of `-eq', `-ne', `-lt', `-le', `-gt', or `-ge'. These
4968 arithmetic binary operators return true if ARG1 is equal to, not
4969 equal to, less than, less than or equal to, greater than, or
4970 greater than or equal to ARG2, respectively. ARG1 and ARG2 may be
4971 positive or negative integers.
4972
761783bf 4973
ccc6cda3 4974\1f
bb70624e 4975File: bashref.info, Node: Shell Arithmetic, Next: Aliases, Prev: Bash Conditional Expressions, Up: Bash Features
ccc6cda3 4976
37c41ab1
CR
49776.5 Shell Arithmetic
4978====================
ccc6cda3 4979
37c41ab1
CR
4980The shell allows arithmetic expressions to be evaluated, as one of the
4981shell expansions or by the `let' and the `-i' option to the `declare'
4982builtins.
ccc6cda3 4983
7117c2d2
JA
4984 Evaluation is done in fixed-width integers with no check for
4985overflow, though division by 0 is trapped and flagged as an error. The
d3a24ed2
CR
4986operators and their precedence, associativity, and values are the same
4987as in the C language. The following list of operators is grouped into
4988levels of equal-precedence operators. The levels are listed in order
4989of decreasing precedence.
cce855bc 4990
bb70624e
JA
4991`ID++ ID--'
4992 variable post-increment and post-decrement
d166f048 4993
bb70624e
JA
4994`++ID --ID'
4995 variable pre-increment and pre-decrement
ccc6cda3 4996
bb70624e
JA
4997`- +'
4998 unary minus and plus
ccc6cda3 4999
bb70624e
JA
5000`! ~'
5001 logical and bitwise negation
ccc6cda3 5002
bb70624e
JA
5003`**'
5004 exponentiation
ccc6cda3 5005
bb70624e
JA
5006`* / %'
5007 multiplication, division, remainder
ccc6cda3 5008
bb70624e
JA
5009`+ -'
5010 addition, subtraction
ccc6cda3 5011
bb70624e
JA
5012`<< >>'
5013 left and right bitwise shifts
cce855bc 5014
bb70624e
JA
5015`<= >= < >'
5016 comparison
cce855bc 5017
bb70624e
JA
5018`== !='
5019 equality and inequality
cce855bc 5020
bb70624e
JA
5021`&'
5022 bitwise AND
cce855bc 5023
bb70624e
JA
5024`^'
5025 bitwise exclusive OR
cce855bc 5026
bb70624e
JA
5027`|'
5028 bitwise OR
cce855bc 5029
bb70624e
JA
5030`&&'
5031 logical AND
ccc6cda3 5032
bb70624e
JA
5033`||'
5034 logical OR
ccc6cda3 5035
bb70624e 5036`expr ? expr : expr'
d3a24ed2 5037 conditional operator
cce855bc 5038
bb70624e
JA
5039`= *= /= %= += -= <<= >>= &= ^= |='
5040 assignment
ccc6cda3 5041
bb70624e
JA
5042`expr1 , expr2'
5043 comma
ccc6cda3 5044
bb70624e
JA
5045 Shell variables are allowed as operands; parameter expansion is
5046performed before the expression is evaluated. Within an expression,
5047shell variables may also be referenced by name without using the
d3a24ed2
CR
5048parameter expansion syntax. A shell variable that is null or unset
5049evaluates to 0 when referenced by name without using the parameter
5050expansion syntax. The value of a variable is evaluated as an
5051arithmetic expression when it is referenced, or when a variable which
5052has been given the INTEGER attribute using `declare -i' is assigned a
5053value. A null value evaluates to 0. A shell variable need not have
5054its integer attribute turned on to be used in an expression.
ccc6cda3 5055
bb70624e
JA
5056 Constants with a leading 0 are interpreted as octal numbers. A
5057leading `0x' or `0X' denotes hexadecimal. Otherwise, numbers take the
5058form [BASE`#']N, where BASE is a decimal number between 2 and 64
5059representing the arithmetic base, and N is a number in that base. If
5060BASE`#' is omitted, then base 10 is used. The digits greater than 9
f73dda09
JA
5061are represented by the lowercase letters, the uppercase letters, `@',
5062and `_', in that order. If BASE is less than or equal to 36, lowercase
eb2bb562 5063and uppercase letters may be used interchangeably to represent numbers
bb70624e 5064between 10 and 35.
ccc6cda3 5065
bb70624e
JA
5066 Operators are evaluated in order of precedence. Sub-expressions in
5067parentheses are evaluated first and may override the precedence rules
5068above.
ccc6cda3 5069
bb70624e
JA
5070\1f
5071File: bashref.info, Node: Aliases, Next: Arrays, Prev: Shell Arithmetic, Up: Bash Features
ccc6cda3 5072
37c41ab1
CR
50736.6 Aliases
5074===========
ccc6cda3 5075
37c41ab1
CR
5076ALIASES allow a string to be substituted for a word when it is used as
5077the first word of a simple command. The shell maintains a list of
bb70624e 5078aliases that may be set and unset with the `alias' and `unalias'
cce855bc
JA
5079builtin commands.
5080
5081 The first word of each simple command, if unquoted, is checked to see
5082if it has an alias. If so, that word is replaced by the text of the
de8913bd
CR
5083alias. The characters `/', `$', ``', `=' and any of the shell
5084metacharacters or quoting characters listed above may not appear in an
5085alias name. The replacement text may contain any valid shell input,
5086including shell metacharacters. The first word of the replacement text
5087is tested for aliases, but a word that is identical to an alias being
5088expanded is not expanded a second time. This means that one may alias
5089`ls' to `"ls -F"', for instance, and Bash does not try to recursively
5090expand the replacement text. If the last character of the alias value
5091is a space or tab character, then the next command word following the
5092alias is also checked for alias expansion.
cce855bc
JA
5093
5094 Aliases are created and listed with the `alias' command, and removed
5095with the `unalias' command.
5096
5097 There is no mechanism for using arguments in the replacement text,
5098as in `csh'. If arguments are needed, a shell function should be used
28ef6c31 5099(*note Shell Functions::).
cce855bc
JA
5100
5101 Aliases are not expanded when the shell is not interactive, unless
d3ad40de
CR
5102the `expand_aliases' shell option is set using `shopt' (*note The Shopt
5103Builtin::).
ccc6cda3 5104
cce855bc
JA
5105 The rules concerning the definition and use of aliases are somewhat
5106confusing. Bash always reads at least one complete line of input
5107before executing any of the commands on that line. Aliases are
5108expanded when a command is read, not when it is executed. Therefore, an
5109alias definition appearing on the same line as another command does not
5110take effect until the next line of input is read. The commands
5111following the alias definition on that line are not affected by the new
5112alias. This behavior is also an issue when functions are executed.
5113Aliases are expanded when a function definition is read, not when the
5114function is executed, because a function definition is itself a
5115compound command. As a consequence, aliases defined in a function are
5116not available until after that function is executed. To be safe,
5117always put alias definitions on a separate line, and do not use `alias'
5118in compound commands.
ccc6cda3 5119
bb70624e 5120 For almost every purpose, shell functions are preferred over aliases.
ccc6cda3
JA
5121
5122\1f
cce855bc 5123File: bashref.info, Node: Arrays, Next: The Directory Stack, Prev: Aliases, Up: Bash Features
ccc6cda3 5124
37c41ab1
CR
51256.7 Arrays
5126==========
ccc6cda3 5127
37c41ab1 5128Bash provides one-dimensional array variables. Any variable may be
ccc6cda3
JA
5129used as an array; the `declare' builtin will explicitly declare an
5130array. There is no maximum limit on the size of an array, nor any
5131requirement that members be indexed or assigned contiguously. Arrays
5132are zero-based.
5133
5134 An array is created automatically if any variable is assigned to
5135using the syntax
5136 name[SUBSCRIPT]=VALUE
5137
5138The SUBSCRIPT is treated as an arithmetic expression that must evaluate
5139to a number greater than or equal to zero. To explicitly declare an
5140array, use
5141 declare -a NAME
37c41ab1 5142 The syntax
ccc6cda3 5143 declare -a NAME[SUBSCRIPT]
37c41ab1 5144 is also accepted; the SUBSCRIPT is ignored. Attributes may be
ccc6cda3
JA
5145specified for an array variable using the `declare' and `readonly'
5146builtins. Each attribute applies to all members of an array.
5147
5148 Arrays are assigned to using compound assignments of the form
5149 name=(value1 ... valueN)
37c41ab1 5150 where each VALUE is of the form `[[SUBSCRIPT]=]'STRING. If the
ccc6cda3
JA
5151optional subscript is supplied, that index is assigned to; otherwise
5152the index of the element assigned is the last index assigned to by the
5153statement plus one. Indexing starts at zero. This syntax is also
5154accepted by the `declare' builtin. Individual array elements may be
5155assigned to using the `name['SUBSCRIPT`]='VALUE syntax introduced above.
5156
5157 Any element of an array may be referenced using
5158`${name['SUBSCRIPT`]}'. The braces are required to avoid conflicts
5159with the shell's filename expansion operators. If the SUBSCRIPT is `@'
5160or `*', the word expands to all members of the array NAME. These
5161subscripts differ only when the word appears within double quotes. If
5162the word is double-quoted, `${name[*]}' expands to a single word with
5163the value of each array member separated by the first character of the
5164`IFS' variable, and `${name[@]}' expands each element of NAME to a
5165separate word. When there are no array members, `${name[@]}' expands
37c41ab1
CR
5166to nothing. If the double-quoted expansion occurs within a word, the
5167expansion of the first parameter is joined with the beginning part of
5168the original word, and the expansion of the last parameter is joined
5169with the last part of the original word. This is analogous to the
5170expansion of the special parameters `@' and `*'.
5171`${#name['SUBSCRIPT`]}' expands to the length of `${name['SUBSCRIPT`]}'.
5172If SUBSCRIPT is `@' or `*', the expansion is the number of elements in
5173the array. Referencing an array variable without a subscript is
5174equivalent to referencing element zero.
ccc6cda3
JA
5175
5176 The `unset' builtin is used to destroy arrays. `unset'
1c72c0cd
CR
5177NAME[SUBSCRIPT] destroys the array element at index SUBSCRIPT. Care
5178must be taken to avoid unwanted side effects caused by filename
5179generation. `unset' NAME, where NAME is an array, removes the entire
5180array. A subscript of `*' or `@' also removes the entire array.
ccc6cda3
JA
5181
5182 The `declare', `local', and `readonly' builtins each accept a `-a'
5183option to specify an array. The `read' builtin accepts a `-a' option
5184to assign a list of words read from the standard input to an array, and
5185can read values from the standard input into individual array elements.
5186The `set' and `declare' builtins display array values in a way that
5187allows them to be reused as input.
5188
5189\1f
cce855bc
JA
5190File: bashref.info, Node: The Directory Stack, Next: Printing a Prompt, Prev: Arrays, Up: Bash Features
5191
37c41ab1
CR
51926.8 The Directory Stack
5193=======================
cce855bc 5194
bb70624e
JA
5195* Menu:
5196
5197* Directory Stack Builtins:: Bash builtin commands to manipulate
5198 the directory stack.
5199
5200 The directory stack is a list of recently-visited directories. The
cce855bc
JA
5201`pushd' builtin adds directories to the stack as it changes the current
5202directory, and the `popd' builtin removes specified directories from
5203the stack and changes the current directory to the directory removed.
5204The `dirs' builtin displays the contents of the directory stack.
5205
5206 The contents of the directory stack are also visible as the value of
5207the `DIRSTACK' shell variable.
5208
bb70624e
JA
5209\1f
5210File: bashref.info, Node: Directory Stack Builtins, Up: The Directory Stack
5211
37c41ab1
CR
52126.8.1 Directory Stack Builtins
5213------------------------------
bb70624e 5214
cce855bc 5215`dirs'
bb70624e 5216 dirs [+N | -N] [-clpv]
cce855bc
JA
5217 Display the list of currently remembered directories. Directories
5218 are added to the list with the `pushd' command; the `popd' command
5219 removes directories from the list.
5220 `+N'
5221 Displays the Nth directory (counting from the left of the
5222 list printed by `dirs' when invoked without options), starting
5223 with zero.
5224
5225 `-N'
5226 Displays the Nth directory (counting from the right of the
5227 list printed by `dirs' when invoked without options), starting
5228 with zero.
5229
5230 `-c'
5231 Clears the directory stack by deleting all of the elements.
5232
5233 `-l'
5234 Produces a longer listing; the default listing format uses a
5235 tilde to denote the home directory.
5236
5237 `-p'
5238 Causes `dirs' to print the directory stack with one entry per
5239 line.
5240
5241 `-v'
5242 Causes `dirs' to print the directory stack with one entry per
5243 line, prefixing each entry with its index in the stack.
5244
5245`popd'
5246 popd [+N | -N] [-n]
5247
5248 Remove the top entry from the directory stack, and `cd' to the new
5249 top directory. When no arguments are given, `popd' removes the
5250 top directory from the stack and performs a `cd' to the new top
5251 directory. The elements are numbered from 0 starting at the first
5252 directory listed with `dirs'; i.e., `popd' is equivalent to `popd
5253 +0'.
5254 `+N'
5255 Removes the Nth directory (counting from the left of the list
5256 printed by `dirs'), starting with zero.
5257
5258 `-N'
5259 Removes the Nth directory (counting from the right of the
5260 list printed by `dirs'), starting with zero.
5261
5262 `-n'
5263 Suppresses the normal change of directory when removing
5264 directories from the stack, so that only the stack is
5265 manipulated.
5266
5267`pushd'
d3ad40de 5268 pushd [-n] [+N | -N | DIR ]
cce855bc
JA
5269
5270 Save the current directory on the top of the directory stack and
5271 then `cd' to DIR. With no arguments, `pushd' exchanges the top
5272 two directories.
5273
d3ad40de
CR
5274 `-n'
5275 Suppresses the normal change of directory when adding
5276 directories to the stack, so that only the stack is
5277 manipulated.
5278
cce855bc
JA
5279 `+N'
5280 Brings the Nth directory (counting from the left of the list
5281 printed by `dirs', starting with zero) to the top of the list
5282 by rotating the stack.
5283
5284 `-N'
5285 Brings the Nth directory (counting from the right of the list
5286 printed by `dirs', starting with zero) to the top of the list
5287 by rotating the stack.
5288
cce855bc
JA
5289 `DIR'
5290 Makes the current working directory be the top of the stack,
5291 and then executes the equivalent of ``cd' DIR'. `cd's to DIR.
5292
761783bf 5293
cce855bc
JA
5294\1f
5295File: bashref.info, Node: Printing a Prompt, Next: The Restricted Shell, Prev: The Directory Stack, Up: Bash Features
ccc6cda3 5296
37c41ab1
CR
52976.9 Controlling the Prompt
5298==========================
ccc6cda3 5299
37c41ab1
CR
5300The value of the variable `PROMPT_COMMAND' is examined just before Bash
5301prints each primary prompt. If `PROMPT_COMMAND' is set and has a
bb70624e
JA
5302non-null value, then the value is executed just as if it had been typed
5303on the command line.
ccc6cda3
JA
5304
5305 In addition, the following table describes the special characters
5306which can appear in the prompt variables:
5307
5308`\a'
cce855bc 5309 A bell character.
ccc6cda3
JA
5310
5311`\d'
cce855bc 5312 The date, in "Weekday Month Date" format (e.g., "Tue May 26").
ccc6cda3 5313
7117c2d2
JA
5314`\D{FORMAT}'
5315 The FORMAT is passed to `strftime'(3) and the result is inserted
5316 into the prompt string; an empty FORMAT results in a
5317 locale-specific time representation. The braces are required.
5318
ccc6cda3 5319`\e'
cce855bc 5320 An escape character.
ccc6cda3
JA
5321
5322`\h'
cce855bc 5323 The hostname, up to the first `.'.
ccc6cda3
JA
5324
5325`\H'
cce855bc 5326 The hostname.
ccc6cda3 5327
bb70624e
JA
5328`\j'
5329 The number of jobs currently managed by the shell.
5330
5331`\l'
5332 The basename of the shell's terminal device name.
5333
ccc6cda3 5334`\n'
cce855bc
JA
5335 A newline.
5336
5337`\r'
5338 A carriage return.
ccc6cda3
JA
5339
5340`\s'
cce855bc 5341 The name of the shell, the basename of `$0' (the portion following
ccc6cda3
JA
5342 the final slash).
5343
5344`\t'
cce855bc 5345 The time, in 24-hour HH:MM:SS format.
ccc6cda3
JA
5346
5347`\T'
cce855bc 5348 The time, in 12-hour HH:MM:SS format.
ccc6cda3
JA
5349
5350`\@'
cce855bc
JA
5351 The time, in 12-hour am/pm format.
5352
f73dda09
JA
5353`\A'
5354 The time, in 24-hour HH:MM format.
5355
cce855bc
JA
5356`\u'
5357 The username of the current user.
ccc6cda3
JA
5358
5359`\v'
cce855bc 5360 The version of Bash (e.g., 2.00)
ccc6cda3
JA
5361
5362`\V'
cce855bc 5363 The release of Bash, version + patchlevel (e.g., 2.00.0)
ccc6cda3
JA
5364
5365`\w'
12d937f9
CR
5366 The current working directory, with `$HOME' abbreviated with a
5367 tilde.
ccc6cda3
JA
5368
5369`\W'
12d937f9 5370 The basename of `$PWD', with `$HOME' abbreviated with a tilde.
ccc6cda3
JA
5371
5372`\!'
cce855bc 5373 The history number of this command.
ccc6cda3
JA
5374
5375`\#'
cce855bc 5376 The command number of this command.
ccc6cda3
JA
5377
5378`\$'
cce855bc 5379 If the effective uid is 0, `#', otherwise `$'.
ccc6cda3 5380
cce855bc
JA
5381`\NNN'
5382 The character whose ASCII code is the octal value NNN.
ccc6cda3
JA
5383
5384`\\'
cce855bc 5385 A backslash.
ccc6cda3
JA
5386
5387`\['
cce855bc 5388 Begin a sequence of non-printing characters. This could be used to
ccc6cda3
JA
5389 embed a terminal control sequence into the prompt.
5390
5391`\]'
cce855bc 5392 End a sequence of non-printing characters.
ccc6cda3 5393
bb70624e
JA
5394 The command number and the history number are usually different: the
5395history number of a command is its position in the history list, which
5396may include commands restored from the history file (*note Bash History
28ef6c31
JA
5397Facilities::), while the command number is the position in the sequence
5398of commands executed during the current shell session.
bb70624e
JA
5399
5400 After the string is decoded, it is expanded via parameter expansion,
5401command substitution, arithmetic expansion, and quote removal, subject
28ef6c31 5402to the value of the `promptvars' shell option (*note Bash Builtins::).
bb70624e 5403
ccc6cda3
JA
5404\1f
5405File: bashref.info, Node: The Restricted Shell, Next: Bash POSIX Mode, Prev: Printing a Prompt, Up: Bash Features
5406
37c41ab1
CR
54076.10 The Restricted Shell
5408=========================
ccc6cda3 5409
37c41ab1
CR
5410If Bash is started with the name `rbash', or the `--restricted' or `-r'
5411option is supplied at invocation, the shell becomes restricted. A
ccc6cda3
JA
5412restricted shell is used to set up an environment more controlled than
5413the standard shell. A restricted shell behaves identically to `bash'
7117c2d2
JA
5414with the exception that the following are disallowed or not performed:
5415
ccc6cda3
JA
5416 * Changing directories with the `cd' builtin.
5417
b72432fd
JA
5418 * Setting or unsetting the values of the `SHELL', `PATH', `ENV', or
5419 `BASH_ENV' variables.
ccc6cda3
JA
5420
5421 * Specifying command names containing slashes.
5422
5423 * Specifying a filename containing a slash as an argument to the `.'
5424 builtin command.
5425
bb70624e
JA
5426 * Specifying a filename containing a slash as an argument to the `-p'
5427 option to the `hash' builtin command.
5428
ccc6cda3
JA
5429 * Importing function definitions from the shell environment at
5430 startup.
5431
cce855bc
JA
5432 * Parsing the value of `SHELLOPTS' from the shell environment at
5433 startup.
5434
ccc6cda3
JA
5435 * Redirecting output using the `>', `>|', `<>', `>&', `&>', and `>>'
5436 redirection operators.
5437
5438 * Using the `exec' builtin to replace the shell with another command.
5439
5440 * Adding or deleting builtin commands with the `-f' and `-d' options
5441 to the `enable' builtin.
5442
7117c2d2
JA
5443 * Using the `enable' builtin command to enable disabled shell
5444 builtins.
5445
ccc6cda3
JA
5446 * Specifying the `-p' option to the `command' builtin.
5447
cce855bc 5448 * Turning off restricted mode with `set +r' or `set +o restricted'.
ccc6cda3 5449
7117c2d2
JA
5450 These restrictions are enforced after any startup files are read.
5451
5452 When a command that is found to be a shell script is executed (*note
5453Shell Scripts::), `rbash' turns off any restrictions in the shell
5454spawned to execute the script.
5455
ccc6cda3
JA
5456\1f
5457File: bashref.info, Node: Bash POSIX Mode, Prev: The Restricted Shell, Up: Bash Features
5458
37c41ab1
CR
54596.11 Bash POSIX Mode
5460====================
ccc6cda3 5461
37c41ab1
CR
5462Starting Bash with the `--posix' command-line option or executing `set
5463-o posix' while Bash is running will cause Bash to conform more closely
ac18b312
CR
5464to the POSIX standard by changing the behavior to match that specified
5465by POSIX in areas where the Bash default differs.
ccc6cda3 5466
7117c2d2
JA
5467 When invoked as `sh', Bash enters POSIX mode after reading the
5468startup files.
5469
ccc6cda3
JA
5470 The following list is what's changed when `POSIX mode' is in effect:
5471
5472 1. When a command in the hash table no longer exists, Bash will
5473 re-search `$PATH' to find the new location. This is also
5474 available with `shopt -s checkhash'.
5475
28ef6c31
JA
5476 2. The message printed by the job control code and builtins when a job
5477 exits with a non-zero status is `Done(status)'.
ccc6cda3
JA
5478
5479 3. The message printed by the job control code and builtins when a job
28ef6c31
JA
5480 is stopped is `Stopped(SIGNAME)', where SIGNAME is, for example,
5481 `SIGTSTP'.
ccc6cda3 5482
1c72c0cd
CR
5483 4. The `bg' builtin uses the required format to describe each job
5484 placed in the background, which does not include an indication of
5485 whether the job is the current or previous job.
5486
5487 5. Reserved words appearing in a context where reserved words are
3ee6b87d 5488 recognized do not undergo alias expansion.
ccc6cda3 5489
ac18b312
CR
5490 6. The POSIX `PS1' and `PS2' expansions of `!' to the history number
5491 and `!!' to `!' are enabled, and parameter expansion is performed
5492 on the values of `PS1' and `PS2' regardless of the setting of the
5493 `promptvars' option.
ccc6cda3 5494
ac18b312
CR
5495 7. The POSIX startup files are executed (`$ENV') rather than the
5496 normal Bash files.
ccc6cda3 5497
1c72c0cd 5498 8. Tilde expansion is only performed on assignments preceding a
ccc6cda3
JA
5499 command name, rather than on all assignment statements on the line.
5500
1c72c0cd 5501 9. The default history file is `~/.sh_history' (this is the default
ccc6cda3
JA
5502 value of `$HISTFILE').
5503
1c72c0cd 5504 10. The output of `kill -l' prints all the signal names on a single
d3a24ed2
CR
5505 line, separated by spaces, without the `SIG' prefix.
5506
1c72c0cd 5507 11. The `kill' builtin does not accept signal names with a `SIG'
d3a24ed2 5508 prefix.
ccc6cda3 5509
1c72c0cd 5510 12. Non-interactive shells exit if FILENAME in `.' FILENAME is not
ccc6cda3
JA
5511 found.
5512
1c72c0cd 5513 13. Non-interactive shells exit if a syntax error in an arithmetic
cce855bc
JA
5514 expansion results in an invalid expression.
5515
1c72c0cd 5516 14. Redirection operators do not perform filename expansion on the word
ccc6cda3
JA
5517 in the redirection unless the shell is interactive.
5518
1c72c0cd 5519 15. Redirection operators do not perform word splitting on the word in
bb70624e
JA
5520 the redirection.
5521
1c72c0cd 5522 16. Function names must be valid shell `name's. That is, they may not
ccc6cda3 5523 contain characters other than letters, digits, and underscores, and
cce855bc 5524 may not start with a digit. Declaring a function with an invalid
ccc6cda3
JA
5525 name causes a fatal syntax error in non-interactive shells.
5526
ac18b312
CR
5527 17. POSIX special builtins are found before shell functions during
5528 command lookup.
ccc6cda3 5529
ac18b312 5530 18. If a POSIX special builtin returns an error status, a
ccc6cda3 5531 non-interactive shell exits. The fatal errors are those listed in
ac18b312 5532 the POSIX standard, and include things like passing incorrect
ccc6cda3
JA
5533 options, redirection errors, variable assignment errors for
5534 assignments preceding the command name, and so on.
5535
1c72c0cd 5536 19. If `CDPATH' is set, the `cd' builtin will not implicitly append
cce855bc
JA
5537 the current directory to it. This means that `cd' will fail if no
5538 valid directory name can be constructed from any of the entries in
5539 `$CDPATH', even if the a directory with the same name as the name
5540 given as an argument to `cd' exists in the current directory.
5541
1c72c0cd 5542 20. A non-interactive shell exits with an error status if a variable
ccc6cda3
JA
5543 assignment error occurs when no command name follows the assignment
5544 statements. A variable assignment error occurs, for example, when
cce855bc 5545 trying to assign a value to a readonly variable.
ccc6cda3 5546
1c72c0cd 5547 21. A non-interactive shell exits with an error status if the iteration
ccc6cda3 5548 variable in a `for' statement or the selection variable in a
cce855bc 5549 `select' statement is a readonly variable.
ccc6cda3 5550
1c72c0cd 5551 22. Process substitution is not available.
ccc6cda3 5552
ac18b312
CR
5553 23. Assignment statements preceding POSIX special builtins persist in
5554 the shell environment after the builtin completes.
ccc6cda3 5555
1c72c0cd 5556 24. Assignment statements preceding shell function calls persist in the
28ef6c31
JA
5557 shell environment after the function returns, as if a POSIX
5558 special builtin command had been executed.
5559
1c72c0cd 5560 25. The `export' and `readonly' builtin commands display their output
ac18b312 5561 in the format required by POSIX.
d166f048 5562
1c72c0cd 5563 26. The `trap' builtin displays signal names without the leading `SIG'.
28ef6c31 5564
1c72c0cd 5565 27. The `trap' builtin doesn't check the first argument for a possible
d3a24ed2 5566 signal specification and revert the signal handling to the original
8a9c66f6
CR
5567 disposition if it is, unless that argument consists solely of
5568 digits and is a valid signal number. If users want to reset the
5569 handler for a given signal to the original disposition, they
5570 should use `-' as the first argument.
d3a24ed2 5571
1c72c0cd 5572 28. The `.' and `source' builtins do not search the current directory
28ef6c31
JA
5573 for the filename argument if it is not found by searching `PATH'.
5574
1c72c0cd 5575 29. Subshells spawned to execute command substitutions inherit the
28ef6c31
JA
5576 value of the `-e' option from the parent shell. When not in POSIX
5577 mode, Bash clears the `-e' option in such subshells.
5578
1c72c0cd 5579 30. Alias expansion is always enabled, even in non-interactive shells.
28ef6c31 5580
1c72c0cd 5581 31. When the `alias' builtin displays alias definitions, it does not
d3a24ed2
CR
5582 display them with a leading `alias ' unless the `-p' option is
5583 supplied.
5584
1c72c0cd 5585 32. When the `set' builtin is invoked without options, it does not
28ef6c31
JA
5586 display shell function names and definitions.
5587
1c72c0cd 5588 33. When the `set' builtin is invoked without options, it displays
f73dda09
JA
5589 variable values without quotes, unless they contain shell
5590 metacharacters, even if the result contains nonprinting characters.
ccc6cda3 5591
1c72c0cd 5592 34. When the `cd' builtin is invoked in LOGICAL mode, and the pathname
7117c2d2
JA
5593 constructed from `$PWD' and the directory name supplied as an
5594 argument does not refer to an existing directory, `cd' will fail
5595 instead of falling back to PHYSICAL mode.
5596
1c72c0cd 5597 35. When the `pwd' builtin is supplied the `-P' option, it resets
9d2b70f0
CR
5598 `$PWD' to a pathname containing no symlinks.
5599
1c72c0cd
CR
5600 36. The `pwd' builtin verifies that the value it prints is the same as
5601 the current directory, even if it is not asked to check the file
5602 system with the `-P' option.
5603
5604 37. When listing the history, the `fc' builtin does not include an
8a9c66f6
CR
5605 indication of whether or not a history entry has been modified.
5606
1c72c0cd 5607 38. The default editor used by `fc' is `ed'.
8a9c66f6 5608
1c72c0cd 5609 39. The `type' and `command' builtins will not report a non-executable
37c41ab1
CR
5610 file as having been found, though the shell will attempt to
5611 execute such a file if it is the only so-named file found in
5612 `$PATH'.
5613
1c72c0cd
CR
5614 40. The `vi' editing mode will invoke the `vi' editor directly when
5615 the `v' command is run, instead of checking `$FCEDIT' and
5616 `$EDITOR'.
5617
5618 41. When the `xpg_echo' option is enabled, Bash does not attempt to
37c41ab1
CR
5619 interpret any arguments to `echo' as options. Each argument is
5620 displayed, after escape characters are converted.
5621
8a9c66f6 5622
ac18b312 5623 There is other POSIX behavior that Bash does not implement by
1c72c0cd 5624default even when in POSIX mode. Specifically:
ccc6cda3 5625
1c72c0cd
CR
5626 1. The `fc' builtin checks `$EDITOR' as a program to edit history
5627 entries if `FCEDIT' is unset, rather than defaulting directly to
5628 `ed'. `fc' uses `ed' if `EDITOR' is unset.
ccc6cda3 5629
1c72c0cd
CR
5630 2. As noted above, Bash requires the `xpg_echo' option to be enabled
5631 for the `echo' builtin to be fully conformant.
28ef6c31 5632
28ef6c31 5633
1c72c0cd
CR
5634 Bash can be configured to be POSIX-conformant by default, by
5635specifying the `--enable-strict-posix-default' to `configure' when
5636building (*note Optional Features::).
28ef6c31 5637
ccc6cda3 5638\1f
c2a47ea9 5639File: bashref.info, Node: Job Control, Next: Command Line Editing, Prev: Bash Features, Up: Top
ccc6cda3 5640
37c41ab1
CR
56417 Job Control
5642*************
ccc6cda3 5643
37c41ab1
CR
5644This chapter discusses what job control is, how it works, and how Bash
5645allows you to access its facilities.
ccc6cda3
JA
5646
5647* Menu:
5648
5649* Job Control Basics:: How job control works.
5650* Job Control Builtins:: Bash builtin commands used to interact
5651 with job control.
5652* Job Control Variables:: Variables Bash uses to customize job
5653 control.
5654
5655\1f
5656File: bashref.info, Node: Job Control Basics, Next: Job Control Builtins, Up: Job Control
5657
37c41ab1
CR
56587.1 Job Control Basics
5659======================
ccc6cda3 5660
37c41ab1 5661Job control refers to the ability to selectively stop (suspend) the
ccc6cda3
JA
5662execution of processes and continue (resume) their execution at a later
5663point. A user typically employs this facility via an interactive
5664interface supplied jointly by the system's terminal driver and Bash.
5665
5666 The shell associates a JOB with each pipeline. It keeps a table of
5667currently executing jobs, which may be listed with the `jobs' command.
cce855bc 5668When Bash starts a job asynchronously, it prints a line that looks like:
ccc6cda3 5669 [1] 25647
37c41ab1
CR
5670 indicating that this job is job number 1 and that the process ID of
5671the last process in the pipeline associated with this job is 25647.
5672All of the processes in a single pipeline are members of the same job.
5673Bash uses the JOB abstraction as the basis for job control.
ccc6cda3
JA
5674
5675 To facilitate the implementation of the user interface to job
bb70624e
JA
5676control, the operating system maintains the notion of a current terminal
5677process group ID. Members of this process group (processes whose
5678process group ID is equal to the current terminal process group ID)
5679receive keyboard-generated signals such as `SIGINT'. These processes
5680are said to be in the foreground. Background processes are those whose
5681process group ID differs from the terminal's; such processes are immune
5682to keyboard-generated signals. Only foreground processes are allowed
5683to read from or write to the terminal. Background processes which
5684attempt to read from (write to) the terminal are sent a `SIGTTIN'
5685(`SIGTTOU') signal by the terminal driver, which, unless caught,
5686suspends the process.
ccc6cda3
JA
5687
5688 If the operating system on which Bash is running supports job
cce855bc
JA
5689control, Bash contains facilities to use it. Typing the SUSPEND
5690character (typically `^Z', Control-Z) while a process is running causes
5691that process to be stopped and returns control to Bash. Typing the
5692DELAYED SUSPEND character (typically `^Y', Control-Y) causes the
5693process to be stopped when it attempts to read input from the terminal,
5694and control to be returned to Bash. The user then manipulates the
5695state of this job, using the `bg' command to continue it in the
5696background, the `fg' command to continue it in the foreground, or the
5697`kill' command to kill it. A `^Z' takes effect immediately, and has
5698the additional side effect of causing pending output and typeahead to
5699be discarded.
ccc6cda3
JA
5700
5701 There are a number of ways to refer to a job in the shell. The
bb70624e
JA
5702character `%' introduces a job name.
5703
5704 Job number `n' may be referred to as `%n'. The symbols `%%' and
5705`%+' refer to the shell's notion of the current job, which is the last
eb2bb562
CR
5706job stopped while it was in the foreground or started in the background.
5707A single `%' (with no accompanying job specification) also refers to
5708the current job. The previous job may be referenced using `%-'. In
5709output pertaining to jobs (e.g., the output of the `jobs' command), the
bb70624e
JA
5710current job is always flagged with a `+', and the previous job with a
5711`-'.
5712
5713 A job may also be referred to using a prefix of the name used to
5714start it, or using a substring that appears in its command line. For
5715example, `%ce' refers to a stopped `ce' job. Using `%?ce', on the other
5716hand, refers to any job containing the string `ce' in its command line.
5717If the prefix or substring matches more than one job, Bash reports an
5718error.
ccc6cda3
JA
5719
5720 Simply naming a job can be used to bring it into the foreground:
5721`%1' is a synonym for `fg %1', bringing job 1 from the background into
5722the foreground. Similarly, `%1 &' resumes job 1 in the background,
5723equivalent to `bg %1'
5724
5725 The shell learns immediately whenever a job changes state.
5726Normally, Bash waits until it is about to print a prompt before
5727reporting changes in a job's status so as to not interrupt any other
f73dda09
JA
5728output. If the `-b' option to the `set' builtin is enabled, Bash
5729reports such changes immediately (*note The Set Builtin::). Any trap
5730on `SIGCHLD' is executed for each child process that exits.
ccc6cda3 5731
d3ad40de 5732 If an attempt to exit Bash is made while jobs are stopped, (or
6a8fd0ed 5733running, if the `checkjobs' option is enabled - see *note The Shopt
d3ad40de
CR
5734Builtin::), the shell prints a warning message, and if the `checkjobs'
5735option is enabled, lists the jobs and their statuses. The `jobs'
cce855bc
JA
5736command may then be used to inspect their status. If a second attempt
5737to exit is made without an intervening command, Bash does not print
d3ad40de 5738another warning, and any stopped jobs are terminated.
ccc6cda3
JA
5739
5740\1f
5741File: bashref.info, Node: Job Control Builtins, Next: Job Control Variables, Prev: Job Control Basics, Up: Job Control
5742
37c41ab1
CR
57437.2 Job Control Builtins
5744========================
ccc6cda3
JA
5745
5746`bg'
37c41ab1
CR
5747 bg [JOBSPEC ...]
5748 Resume each suspended job JOBSPEC in the background, as if it had
cce855bc
JA
5749 been started with `&'. If JOBSPEC is not supplied, the current
5750 job is used. The return status is zero unless it is run when job
1c72c0cd
CR
5751 control is not enabled, or, when run with job control enabled, any
5752 JOBSPEC was not found or specifies a job that was started without
5753 job control.
ccc6cda3
JA
5754
5755`fg'
5756 fg [JOBSPEC]
cce855bc
JA
5757 Resume the job JOBSPEC in the foreground and make it the current
5758 job. If JOBSPEC is not supplied, the current job is used. The
5759 return status is that of the command placed into the foreground,
5760 or non-zero if run when job control is disabled or, when run with
5761 job control enabled, JOBSPEC does not specify a valid job or
5762 JOBSPEC specifies a job that was started without job control.
ccc6cda3
JA
5763
5764`jobs'
bb70624e 5765 jobs [-lnprs] [JOBSPEC]
cce855bc 5766 jobs -x COMMAND [ARGUMENTS]
ccc6cda3
JA
5767
5768 The first form lists the active jobs. The options have the
5769 following meanings:
5770
5771 `-l'
cce855bc 5772 List process IDs in addition to the normal information.
ccc6cda3
JA
5773
5774 `-n'
5775 Display information only about jobs that have changed status
cce855bc 5776 since the user was last notified of their status.
ccc6cda3
JA
5777
5778 `-p'
5779 List only the process ID of the job's process group leader.
5780
5781 `-r'
5782 Restrict output to running jobs.
5783
5784 `-s'
5785 Restrict output to stopped jobs.
5786
5787 If JOBSPEC is given, output is restricted to information about
5788 that job. If JOBSPEC is not supplied, the status of all jobs is
5789 listed.
5790
5791 If the `-x' option is supplied, `jobs' replaces any JOBSPEC found
5792 in COMMAND or ARGUMENTS with the corresponding process group ID,
5793 and executes COMMAND, passing it ARGUMENTs, returning its exit
5794 status.
5795
5796`kill'
cce855bc
JA
5797 kill [-s SIGSPEC] [-n SIGNUM] [-SIGSPEC] JOBSPEC or PID
5798 kill -l [EXIT_STATUS]
ccc6cda3 5799 Send a signal specified by SIGSPEC or SIGNUM to the process named
cce855bc 5800 by job specification JOBSPEC or process ID PID. SIGSPEC is either
9f422431
CR
5801 a case-insensitive signal name such as `SIGINT' (with or without
5802 the `SIG' prefix) or a signal number; SIGNUM is a signal number.
5803 If SIGSPEC and SIGNUM are not present, `SIGTERM' is used. The
5804 `-l' option lists the signal names. If any arguments are supplied
5805 when `-l' is given, the names of the signals corresponding to the
5806 arguments are listed, and the return status is zero. EXIT_STATUS
5807 is a number specifying a signal number or the exit status of a
5808 process terminated by a signal. The return status is zero if at
5809 least one signal was successfully sent, or non-zero if an error
5810 occurs or an invalid option is encountered.
ccc6cda3
JA
5811
5812`wait'
eb2bb562
CR
5813 wait [JOBSPEC or PID ...]
5814 Wait until the child process specified by each process ID PID or
5815 job specification JOBSPEC exits and return the exit status of the
5816 last command waited for. If a job spec is given, all processes in
5817 the job are waited for. If no arguments are given, all currently
cce855bc
JA
5818 active child processes are waited for, and the return status is
5819 zero. If neither JOBSPEC nor PID specifies an active child process
5820 of the shell, the return status is 127.
ccc6cda3
JA
5821
5822`disown'
cce855bc 5823 disown [-ar] [-h] [JOBSPEC ...]
ccc6cda3
JA
5824 Without options, each JOBSPEC is removed from the table of active
5825 jobs. If the `-h' option is given, the job is not removed from
5826 the table, but is marked so that `SIGHUP' is not sent to the job
cce855bc
JA
5827 if the shell receives a `SIGHUP'. If JOBSPEC is not present, and
5828 neither the `-a' nor `-r' option is supplied, the current job is
5829 used. If no JOBSPEC is supplied, the `-a' option means to remove
5830 or mark all jobs; the `-r' option without a JOBSPEC argument
5831 restricts operation to running jobs.
ccc6cda3
JA
5832
5833`suspend'
5834 suspend [-f]
5835 Suspend the execution of this shell until it receives a `SIGCONT'
5836 signal. The `-f' option means to suspend even if the shell is a
5837 login shell.
5838
761783bf 5839
ccc6cda3
JA
5840 When job control is not active, the `kill' and `wait' builtins do
5841not accept JOBSPEC arguments. They must be supplied process IDs.
5842
5843\1f
5844File: bashref.info, Node: Job Control Variables, Prev: Job Control Builtins, Up: Job Control
5845
37c41ab1
CR
58467.3 Job Control Variables
5847=========================
ccc6cda3
JA
5848
5849`auto_resume'
5850 This variable controls how the shell interacts with the user and
5851 job control. If this variable exists then single word simple
cce855bc
JA
5852 commands without redirections are treated as candidates for
5853 resumption of an existing job. There is no ambiguity allowed; if
5854 there is more than one job beginning with the string typed, then
5855 the most recently accessed job will be selected. The name of a
5856 stopped job, in this context, is the command line used to start
5857 it. If this variable is set to the value `exact', the string
5858 supplied must match the name of a stopped job exactly; if set to
ccc6cda3
JA
5859 `substring', the string supplied needs to match a substring of the
5860 name of a stopped job. The `substring' value provides
5861 functionality analogous to the `%?' job ID (*note Job Control
28ef6c31
JA
5862 Basics::). If set to any other value, the supplied string must be
5863 a prefix of a stopped job's name; this provides functionality
ccc6cda3
JA
5864 analogous to the `%' job ID.
5865
761783bf 5866
ccc6cda3 5867\1f
c2a47ea9 5868File: bashref.info, Node: Command Line Editing, Next: Using History Interactively, Prev: Job Control, Up: Top
ccc6cda3 5869
37c41ab1
CR
58708 Command Line Editing
5871**********************
ccc6cda3 5872
37c41ab1 5873This chapter describes the basic features of the GNU command line
bb70624e
JA
5874editing interface. Command line editing is provided by the Readline
5875library, which is used by several different programs, including Bash.
ccc6cda3
JA
5876
5877* Menu:
5878
bb70624e
JA
5879* Introduction and Notation:: Notation used in this text.
5880* Readline Interaction:: The minimum set of commands for editing a line.
5881* Readline Init File:: Customizing Readline from a user's view.
5882* Bindable Readline Commands:: A description of most of the Readline commands
5883 available for binding
5884* Readline vi Mode:: A short description of how to make Readline
5885 behave like the vi editor.
5886
5887* Programmable Completion:: How to specify the possible completions for
5888 a specific command.
5889* Programmable Completion Builtins:: Builtin commands to specify how to
5890 complete arguments for a particular command.
ccc6cda3
JA
5891
5892\1f
bb70624e 5893File: bashref.info, Node: Introduction and Notation, Next: Readline Interaction, Up: Command Line Editing
ccc6cda3 5894
37c41ab1
CR
58958.1 Introduction to Line Editing
5896================================
ccc6cda3 5897
37c41ab1 5898The following paragraphs describe the notation used to represent
bb70624e 5899keystrokes.
ccc6cda3 5900
28ef6c31 5901 The text `C-k' is read as `Control-K' and describes the character
bb70624e 5902produced when the <k> key is pressed while the Control key is depressed.
ccc6cda3 5903
28ef6c31 5904 The text `M-k' is read as `Meta-K' and describes the character
bb70624e
JA
5905produced when the Meta key (if you have one) is depressed, and the <k>
5906key is pressed. The Meta key is labeled <ALT> on many keyboards. On
5907keyboards with two keys labeled <ALT> (usually to either side of the
5908space bar), the <ALT> on the left side is generally set to work as a
5909Meta key. The <ALT> key on the right may also be configured to work as
5910a Meta key or may be configured as some other modifier, such as a
5911Compose key for typing accented characters.
5912
5913 If you do not have a Meta or <ALT> key, or another key working as a
5914Meta key, the identical keystroke can be generated by typing <ESC>
28ef6c31
JA
5915_first_, and then typing <k>. Either process is known as "metafying"
5916the <k> key.
bb70624e 5917
28ef6c31
JA
5918 The text `M-C-k' is read as `Meta-Control-k' and describes the
5919character produced by "metafying" `C-k'.
bb70624e
JA
5920
5921 In addition, several keys have their own names. Specifically,
5922<DEL>, <ESC>, <LFD>, <SPC>, <RET>, and <TAB> all stand for themselves
28ef6c31
JA
5923when seen in this text, or in an init file (*note Readline Init File::).
5924If your keyboard lacks a <LFD> key, typing <C-j> will produce the
5925desired character. The <RET> key may be labeled <Return> or <Enter> on
5926some keyboards.
ccc6cda3
JA
5927
5928\1f
bb70624e 5929File: bashref.info, Node: Readline Interaction, Next: Readline Init File, Prev: Introduction and Notation, Up: Command Line Editing
cce855bc 5930
37c41ab1
CR
59318.2 Readline Interaction
5932========================
cce855bc 5933
37c41ab1 5934Often during an interactive session you type in a long line of text,
bb70624e
JA
5935only to notice that the first word on the line is misspelled. The
5936Readline library gives you a set of commands for manipulating the text
5937as you type it in, allowing you to just fix your typo, and not forcing
5938you to retype the majority of the line. Using these editing commands,
5939you move the cursor to the place that needs correction, and delete or
5940insert the text of the corrections. Then, when you are satisfied with
28ef6c31
JA
5941the line, you simply press <RET>. You do not have to be at the end of
5942the line to press <RET>; the entire line is accepted regardless of the
5943location of the cursor within the line.
cce855bc 5944
bb70624e 5945* Menu:
cce855bc 5946
bb70624e
JA
5947* Readline Bare Essentials:: The least you need to know about Readline.
5948* Readline Movement Commands:: Moving about the input line.
5949* Readline Killing Commands:: How to delete text, and how to get it back!
5950* Readline Arguments:: Giving numeric arguments to commands.
5951* Searching:: Searching through previous lines.
cce855bc 5952
bb70624e
JA
5953\1f
5954File: bashref.info, Node: Readline Bare Essentials, Next: Readline Movement Commands, Up: Readline Interaction
cce855bc 5955
37c41ab1
CR
59568.2.1 Readline Bare Essentials
5957------------------------------
cce855bc 5958
37c41ab1
CR
5959In order to enter characters into the line, simply type them. The typed
5960character appears where the cursor was, and then the cursor moves one
5961space to the right. If you mistype a character, you can use your erase
5962character to back up and delete the mistyped character.
cce855bc 5963
bb70624e
JA
5964 Sometimes you may mistype a character, and not notice the error
5965until you have typed several other characters. In that case, you can
28ef6c31
JA
5966type `C-b' to move the cursor to the left, and then correct your
5967mistake. Afterwards, you can move the cursor to the right with `C-f'.
cce855bc 5968
bb70624e
JA
5969 When you add text in the middle of a line, you will notice that
5970characters to the right of the cursor are `pushed over' to make room
5971for the text that you have inserted. Likewise, when you delete text
5972behind the cursor, characters to the right of the cursor are `pulled
5973back' to fill in the blank space created by the removal of the text. A
5974list of the bare essentials for editing the text of an input line
5975follows.
cce855bc 5976
28ef6c31 5977`C-b'
bb70624e 5978 Move back one character.
cce855bc 5979
28ef6c31 5980`C-f'
bb70624e 5981 Move forward one character.
cce855bc 5982
bb70624e
JA
5983<DEL> or <Backspace>
5984 Delete the character to the left of the cursor.
cce855bc 5985
28ef6c31 5986`C-d'
bb70624e 5987 Delete the character underneath the cursor.
cce855bc 5988
bb70624e
JA
5989Printing characters
5990 Insert the character into the line at the cursor.
cce855bc 5991
28ef6c31 5992`C-_' or `C-x C-u'
bb70624e
JA
5993 Undo the last editing command. You can undo all the way back to an
5994 empty line.
cce855bc 5995
bb70624e
JA
5996(Depending on your configuration, the <Backspace> key be set to delete
5997the character to the left of the cursor and the <DEL> key set to delete
28ef6c31 5998the character underneath the cursor, like `C-d', rather than the
bb70624e 5999character to the left of the cursor.)
cce855bc
JA
6000
6001\1f
bb70624e 6002File: bashref.info, Node: Readline Movement Commands, Next: Readline Killing Commands, Prev: Readline Bare Essentials, Up: Readline Interaction
ccc6cda3 6003
37c41ab1
CR
60048.2.2 Readline Movement Commands
6005--------------------------------
ccc6cda3 6006
37c41ab1 6007The above table describes the most basic keystrokes that you need in
bb70624e 6008order to do editing of the input line. For your convenience, many
28ef6c31 6009other commands have been added in addition to `C-b', `C-f', `C-d', and
bb70624e 6010<DEL>. Here are some commands for moving more rapidly about the line.
ccc6cda3 6011
28ef6c31 6012`C-a'
bb70624e 6013 Move to the start of the line.
ccc6cda3 6014
28ef6c31 6015`C-e'
bb70624e 6016 Move to the end of the line.
ccc6cda3 6017
28ef6c31 6018`M-f'
bb70624e
JA
6019 Move forward a word, where a word is composed of letters and
6020 digits.
ccc6cda3 6021
28ef6c31 6022`M-b'
bb70624e 6023 Move backward a word.
ccc6cda3 6024
28ef6c31 6025`C-l'
bb70624e 6026 Clear the screen, reprinting the current line at the top.
ccc6cda3 6027
28ef6c31 6028 Notice how `C-f' moves forward a character, while `M-f' moves
bb70624e
JA
6029forward a word. It is a loose convention that control keystrokes
6030operate on characters while meta keystrokes operate on words.
ccc6cda3
JA
6031
6032\1f
bb70624e 6033File: bashref.info, Node: Readline Killing Commands, Next: Readline Arguments, Prev: Readline Movement Commands, Up: Readline Interaction
ccc6cda3 6034
37c41ab1
CR
60358.2.3 Readline Killing Commands
6036-------------------------------
ccc6cda3 6037
37c41ab1
CR
6038"Killing" text means to delete the text from the line, but to save it
6039away for later use, usually by "yanking" (re-inserting) it back into
bb70624e
JA
6040the line. (`Cut' and `paste' are more recent jargon for `kill' and
6041`yank'.)
ccc6cda3 6042
bb70624e
JA
6043 If the description for a command says that it `kills' text, then you
6044can be sure that you can get the text back in a different (or the same)
6045place later.
ccc6cda3 6046
bb70624e
JA
6047 When you use a kill command, the text is saved in a "kill-ring".
6048Any number of consecutive kills save all of the killed text together, so
6049that when you yank it back, you get it all. The kill ring is not line
6050specific; the text that you killed on a previously typed line is
37c41ab1 6051available to be yanked back later, when you are typing another line.
ccc6cda3 6052
bb70624e 6053 Here is the list of commands for killing text.
ccc6cda3 6054
28ef6c31 6055`C-k'
bb70624e
JA
6056 Kill the text from the current cursor position to the end of the
6057 line.
ccc6cda3 6058
28ef6c31 6059`M-d'
bb70624e
JA
6060 Kill from the cursor to the end of the current word, or, if between
6061 words, to the end of the next word. Word boundaries are the same
28ef6c31 6062 as those used by `M-f'.
ccc6cda3 6063
28ef6c31 6064`M-<DEL>'
f73dda09 6065 Kill from the cursor the start of the current word, or, if between
bb70624e 6066 words, to the start of the previous word. Word boundaries are the
28ef6c31 6067 same as those used by `M-b'.
ccc6cda3 6068
28ef6c31 6069`C-w'
ccc6cda3 6070 Kill from the cursor to the previous whitespace. This is
28ef6c31 6071 different than `M-<DEL>' because the word boundaries differ.
ccc6cda3 6072
761783bf 6073
cce855bc
JA
6074 Here is how to "yank" the text back into the line. Yanking means to
6075copy the most-recently-killed text from the kill buffer.
ccc6cda3 6076
28ef6c31 6077`C-y'
ccc6cda3
JA
6078 Yank the most recently killed text back into the buffer at the
6079 cursor.
6080
28ef6c31 6081`M-y'
ccc6cda3 6082 Rotate the kill-ring, and yank the new top. You can only do this
28ef6c31 6083 if the prior command is `C-y' or `M-y'.
ccc6cda3
JA
6084
6085\1f
6086File: bashref.info, Node: Readline Arguments, Next: Searching, Prev: Readline Killing Commands, Up: Readline Interaction
6087
37c41ab1
CR
60888.2.4 Readline Arguments
6089------------------------
ccc6cda3 6090
37c41ab1 6091You can pass numeric arguments to Readline commands. Sometimes the
ccc6cda3
JA
6092argument acts as a repeat count, other times it is the sign of the
6093argument that is significant. If you pass a negative argument to a
6094command which normally acts in a forward direction, that command will
6095act in a backward direction. For example, to kill text back to the
6096start of the line, you might type `M-- C-k'.
6097
6098 The general way to pass numeric arguments to a command is to type
cce855bc 6099meta digits before the command. If the first `digit' typed is a minus
bb70624e 6100sign (`-'), then the sign of the argument will be negative. Once you
cce855bc
JA
6101have typed one meta digit to get the argument started, you can type the
6102remainder of the digits, and then the command. For example, to give
28ef6c31
JA
6103the `C-d' command an argument of 10, you could type `M-1 0 C-d', which
6104will delete the next ten characters on the input line.
ccc6cda3
JA
6105
6106\1f
6107File: bashref.info, Node: Searching, Prev: Readline Arguments, Up: Readline Interaction
6108
37c41ab1
CR
61098.2.5 Searching for Commands in the History
6110-------------------------------------------
ccc6cda3 6111
37c41ab1 6112Readline provides commands for searching through the command history
28ef6c31
JA
6113(*note Bash History Facilities::) for lines containing a specified
6114string. There are two search modes: "incremental" and
6115"non-incremental".
ccc6cda3
JA
6116
6117 Incremental searches begin before the user has finished typing the
6118search string. As each character of the search string is typed,
cce855bc 6119Readline displays the next entry from the history matching the string
ccc6cda3 6120typed so far. An incremental search requires only as many characters
bb70624e 6121as needed to find the desired history entry. To search backward in the
28ef6c31 6122history for a particular string, type `C-r'. Typing `C-s' searches
bb70624e
JA
6123forward through the history. The characters present in the value of
6124the `isearch-terminators' variable are used to terminate an incremental
6125search. If that variable has not been assigned a value, the <ESC> and
28ef6c31 6126`C-J' characters will terminate an incremental search. `C-g' will
bb70624e
JA
6127abort an incremental search and restore the original line. When the
6128search is terminated, the history entry containing the search string
6129becomes the current line.
6130
28ef6c31
JA
6131 To find other matching entries in the history list, type `C-r' or
6132`C-s' as appropriate. This will search backward or forward in the
bb70624e
JA
6133history for the next entry matching the search string typed so far.
6134Any other key sequence bound to a Readline command will terminate the
6135search and execute that command. For instance, a <RET> will terminate
6136the search and accept the line, thereby executing the command from the
28ef6c31
JA
6137history list. A movement command will terminate the search, make the
6138last line found the current line, and begin editing.
ccc6cda3 6139
f73dda09
JA
6140 Readline remembers the last incremental search string. If two
6141`C-r's are typed without any intervening characters defining a new
6142search string, any remembered search string is used.
6143
ccc6cda3
JA
6144 Non-incremental searches read the entire search string before
6145starting to search for matching history lines. The search string may be
cce855bc 6146typed by the user or be part of the contents of the current line.
ccc6cda3
JA
6147
6148\1f
6149File: bashref.info, Node: Readline Init File, Next: Bindable Readline Commands, Prev: Readline Interaction, Up: Command Line Editing
6150
37c41ab1
CR
61518.3 Readline Init File
6152======================
ccc6cda3 6153
37c41ab1 6154Although the Readline library comes with a set of Emacs-like
cce855bc
JA
6155keybindings installed by default, it is possible to use a different set
6156of keybindings. Any user can customize programs that use Readline by
bb70624e
JA
6157putting commands in an "inputrc" file, conventionally in his home
6158directory. The name of this file is taken from the value of the shell
6159variable `INPUTRC'. If that variable is unset, the default is
d3ad40de
CR
6160`~/.inputrc'. If that file does not exist or cannot be read, the
6161ultimate default is `/etc/inputrc'.
ccc6cda3
JA
6162
6163 When a program which uses the Readline library starts up, the init
6164file is read, and the key bindings are set.
6165
6166 In addition, the `C-x C-r' command re-reads this init file, thus
6167incorporating any changes that you might have made to it.
6168
6169* Menu:
6170
6171* Readline Init File Syntax:: Syntax for the commands in the inputrc file.
6172
6173* Conditional Init Constructs:: Conditional key bindings in the inputrc file.
6174
6175* Sample Init File:: An example inputrc file.
6176
6177\1f
6178File: bashref.info, Node: Readline Init File Syntax, Next: Conditional Init Constructs, Up: Readline Init File
6179
37c41ab1
CR
61808.3.1 Readline Init File Syntax
6181-------------------------------
ccc6cda3 6182
37c41ab1 6183There are only a few basic constructs allowed in the Readline init
ccc6cda3
JA
6184file. Blank lines are ignored. Lines beginning with a `#' are
6185comments. Lines beginning with a `$' indicate conditional constructs
28ef6c31 6186(*note Conditional Init Constructs::). Other lines denote variable
ccc6cda3
JA
6187settings and key bindings.
6188
6189Variable Settings
cce855bc
JA
6190 You can modify the run-time behavior of Readline by altering the
6191 values of variables in Readline using the `set' command within the
28ef6c31
JA
6192 init file. The syntax is simple:
6193
6194 set VARIABLE VALUE
6195
6196 Here, for example, is how to change from the default Emacs-like
6197 key binding to use `vi' line editing commands:
ccc6cda3
JA
6198
6199 set editing-mode vi
6200
28ef6c31 6201 Variable names and values, where appropriate, are recognized
1c72c0cd
CR
6202 without regard to case. Unrecognized variable names are ignored.
6203
6204 Boolean variables (those that can be set to on or off) are set to
6205 on if the value is null or empty, ON (case-insensitive), or 1.
6206 Any other value results in the variable being set to off.
28ef6c31 6207
bb70624e
JA
6208 The `bind -V' command lists the current Readline variable names
6209 and values. *Note Bash Builtins::.
6210
cce855bc
JA
6211 A great deal of run-time behavior is changeable with the following
6212 variables.
ccc6cda3
JA
6213
6214 `bell-style'
6215 Controls what happens when Readline wants to ring the
6216 terminal bell. If set to `none', Readline never rings the
6217 bell. If set to `visible', Readline uses a visible bell if
6218 one is available. If set to `audible' (the default),
6219 Readline attempts to ring the terminal's bell.
6220
eb2bb562
CR
6221 `bind-tty-special-chars'
6222 If set to `on', Readline attempts to bind the control
6223 characters treated specially by the kernel's terminal driver
6224 to their Readline equivalents.
6225
ccc6cda3
JA
6226 `comment-begin'
6227 The string to insert at the beginning of the line when the
6228 `insert-comment' command is executed. The default value is
6229 `"#"'.
6230
cce855bc
JA
6231 `completion-ignore-case'
6232 If set to `on', Readline performs filename matching and
6233 completion in a case-insensitive fashion. The default value
6234 is `off'.
6235
ed35cb4a
CR
6236 `completion-prefix-display-length'
6237 The length in characters of the common prefix of a list of
6238 possible completions that is displayed without modification.
6239 When set to a value greater than zero, common prefixes longer
6240 than this value are replaced with an ellipsis when displaying
6241 possible completions.
6242
ccc6cda3
JA
6243 `completion-query-items'
6244 The number of possible completions that determines when the
d3a24ed2
CR
6245 user is asked whether the list of possibilities should be
6246 displayed. If the number of possible completions is greater
6247 than this value, Readline will ask the user whether or not he
6248 wishes to view them; otherwise, they are simply listed. This
6249 variable must be set to an integer value greater than or
1c72c0cd
CR
6250 equal to 0. A negative value means Readline should never ask.
6251 The default limit is `100'.
ccc6cda3
JA
6252
6253 `convert-meta'
6254 If set to `on', Readline will convert characters with the
cce855bc 6255 eighth bit set to an ASCII key sequence by stripping the
bb70624e 6256 eighth bit and prefixing an <ESC> character, converting them
cce855bc 6257 to a meta-prefixed key sequence. The default value is `on'.
ccc6cda3
JA
6258
6259 `disable-completion'
cce855bc 6260 If set to `On', Readline will inhibit word completion.
ccc6cda3
JA
6261 Completion characters will be inserted into the line as if
6262 they had been mapped to `self-insert'. The default is `off'.
6263
6264 `editing-mode'
cce855bc
JA
6265 The `editing-mode' variable controls which default set of key
6266 bindings is used. By default, Readline starts up in Emacs
6267 editing mode, where the keystrokes are most similar to Emacs.
6268 This variable can be set to either `emacs' or `vi'.
ccc6cda3
JA
6269
6270 `enable-keypad'
cce855bc 6271 When set to `on', Readline will try to enable the application
ccc6cda3
JA
6272 keypad when it is called. Some systems need this to enable
6273 the arrow keys. The default is `off'.
6274
6275 `expand-tilde'
6276 If set to `on', tilde expansion is performed when Readline
6277 attempts word completion. The default is `off'.
6278
1c72c0cd 6279 `history-preserve-point'
d7f49990
CR
6280 If set to `on', the history code attempts to place the point
6281 (the current cursor position) at the same location on each
6282 history line retrieved with `previous-history' or
6283 `next-history'. The default is `off'.
f73dda09 6284
6a8fd0ed
CR
6285 `history-size'
6286 Set the maximum number of history entries saved in the
6287 history list. If set to zero, the number of entries in the
6288 history list is not limited.
6289
ccc6cda3
JA
6290 `horizontal-scroll-mode'
6291 This variable can be set to either `on' or `off'. Setting it
cce855bc 6292 to `on' means that the text of the lines being edited will
ccc6cda3
JA
6293 scroll horizontally on a single screen line when they are
6294 longer than the width of the screen, instead of wrapping onto
6295 a new screen line. By default, this variable is set to `off'.
6296
b72432fd
JA
6297 `input-meta'
6298 If set to `on', Readline will enable eight-bit input (it will
28ef6c31 6299 not clear the eighth bit in the characters it reads),
b72432fd
JA
6300 regardless of what the terminal claims it can support. The
6301 default value is `off'. The name `meta-flag' is a synonym
6302 for this variable.
6303
6304 `isearch-terminators'
6305 The string of characters that should terminate an incremental
6306 search without subsequently executing the character as a
28ef6c31
JA
6307 command (*note Searching::). If this variable has not been
6308 given a value, the characters <ESC> and `C-J' will terminate
b72432fd
JA
6309 an incremental search.
6310
ccc6cda3
JA
6311 `keymap'
6312 Sets Readline's idea of the current keymap for key binding
6313 commands. Acceptable `keymap' names are `emacs',
28ef6c31 6314 `emacs-standard', `emacs-meta', `emacs-ctlx', `vi', `vi-move',
ccc6cda3
JA
6315 `vi-command', and `vi-insert'. `vi' is equivalent to
6316 `vi-command'; `emacs' is equivalent to `emacs-standard'. The
6317 default value is `emacs'. The value of the `editing-mode'
6318 variable also affects the default keymap.
6319
6320 `mark-directories'
6321 If set to `on', completed directory names have a slash
6322 appended. The default is `on'.
6323
6324 `mark-modified-lines'
cce855bc
JA
6325 This variable, when set to `on', causes Readline to display an
6326 asterisk (`*') at the start of history lines which have been
6327 modified. This variable is `off' by default.
ccc6cda3 6328
7117c2d2
JA
6329 `mark-symlinked-directories'
6330 If set to `on', completed names which are symbolic links to
6331 directories have a slash appended (subject to the value of
6332 `mark-directories'). The default is `off'.
6333
f73dda09
JA
6334 `match-hidden-files'
6335 This variable, when set to `on', causes Readline to match
6336 files whose names begin with a `.' (hidden files) when
6337 performing filename completion, unless the leading `.' is
6338 supplied by the user in the filename to be completed. This
6339 variable is `on' by default.
6340
ccc6cda3
JA
6341 `output-meta'
6342 If set to `on', Readline will display characters with the
6343 eighth bit set directly rather than as a meta-prefixed escape
6344 sequence. The default is `off'.
6345
7117c2d2
JA
6346 `page-completions'
6347 If set to `on', Readline uses an internal `more'-like pager
6348 to display a screenful of possible completions at a time.
6349 This variable is `on' by default.
6350
cce855bc
JA
6351 `print-completions-horizontally'
6352 If set to `on', Readline will display completions with matches
6353 sorted horizontally in alphabetical order, rather than down
6354 the screen. The default is `off'.
6355
ed35cb4a
CR
6356 `revert-all-at-newline'
6357 If set to `on', Readline will undo all changes to history
6358 lines before returning when `accept-line' is executed. By
6359 default, history lines may be modified and retain individual
6360 undo lists across calls to `readline'. The default is `off'.
6361
ccc6cda3
JA
6362 `show-all-if-ambiguous'
6363 This alters the default behavior of the completion functions.
6364 If set to `on', words which have more than one possible
6365 completion cause the matches to be listed immediately instead
6366 of ringing the bell. The default value is `off'.
6367
d3a24ed2
CR
6368 `show-all-if-unmodified'
6369 This alters the default behavior of the completion functions
6370 in a fashion similar to SHOW-ALL-IF-AMBIGUOUS. If set to
6371 `on', words which have more than one possible completion
6372 without any possible partial completion (the possible
6373 completions don't share a common prefix) cause the matches to
6374 be listed immediately instead of ringing the bell. The
6375 default value is `off'.
6376
ccc6cda3
JA
6377 `visible-stats'
6378 If set to `on', a character denoting a file's type is
6379 appended to the filename when listing possible completions.
6380 The default is `off'.
6381
761783bf 6382
ccc6cda3
JA
6383Key Bindings
6384 The syntax for controlling key bindings in the init file is
bb70624e 6385 simple. First you need to find the name of the command that you
cce855bc
JA
6386 want to change. The following sections contain tables of the
6387 command name, the default keybinding, if any, and a short
6388 description of what the command does.
ccc6cda3 6389
28ef6c31
JA
6390 Once you know the name of the command, simply place on a line in
6391 the init file the name of the key you wish to bind the command to,
d3ad40de
CR
6392 a colon, and then the name of the command. There can be no space
6393 between the key name and the colon - that will be interpreted as
6394 part of the key name. The name of the key can be expressed in
6395 different ways, depending on what you find most comfortable.
28ef6c31
JA
6396
6397 In addition to command names, readline allows keys to be bound to
6398 a string that is inserted when the key is pressed (a MACRO).
ccc6cda3 6399
bb70624e
JA
6400 The `bind -p' command displays Readline function names and
6401 bindings in a format that can put directly into an initialization
6402 file. *Note Bash Builtins::.
6403
ccc6cda3
JA
6404 KEYNAME: FUNCTION-NAME or MACRO
6405 KEYNAME is the name of a key spelled out in English. For
6406 example:
6407 Control-u: universal-argument
6408 Meta-Rubout: backward-kill-word
6409 Control-o: "> output"
6410
28ef6c31
JA
6411 In the above example, `C-u' is bound to the function
6412 `universal-argument', `M-DEL' is bound to the function
6413 `backward-kill-word', and `C-o' is bound to run the macro
ccc6cda3
JA
6414 expressed on the right hand side (that is, to insert the text
6415 `> output' into the line).
6416
28ef6c31
JA
6417 A number of symbolic character names are recognized while
6418 processing this key binding syntax: DEL, ESC, ESCAPE, LFD,
6419 NEWLINE, RET, RETURN, RUBOUT, SPACE, SPC, and TAB.
6420
ccc6cda3
JA
6421 "KEYSEQ": FUNCTION-NAME or MACRO
6422 KEYSEQ differs from KEYNAME above in that strings denoting an
6423 entire key sequence can be specified, by placing the key
6424 sequence in double quotes. Some GNU Emacs style key escapes
6425 can be used, as in the following example, but the special
6426 character names are not recognized.
6427
6428 "\C-u": universal-argument
6429 "\C-x\C-r": re-read-init-file
6430 "\e[11~": "Function Key 1"
6431
28ef6c31 6432 In the above example, `C-u' is again bound to the function
ccc6cda3 6433 `universal-argument' (just as it was in the first example),
28ef6c31
JA
6434 `C-x C-r' is bound to the function `re-read-init-file', and
6435 `<ESC> <[> <1> <1> <~>' is bound to insert the text `Function
6436 Key 1'.
cce855bc 6437
761783bf 6438
cce855bc
JA
6439 The following GNU Emacs style escape sequences are available when
6440 specifying key sequences:
6441
6442 `\C-'
6443 control prefix
6444
6445 `\M-'
6446 meta prefix
6447
6448 `\e'
6449 an escape character
6450
6451 `\\'
6452 backslash
6453
6454 `\"'
bb70624e 6455 <">, a double quotation mark
cce855bc
JA
6456
6457 `\''
bb70624e 6458 <'>, a single quote or apostrophe
cce855bc
JA
6459
6460 In addition to the GNU Emacs style escape sequences, a second set
6461 of backslash escapes is available:
ccc6cda3 6462
cce855bc
JA
6463 `\a'
6464 alert (bell)
6465
6466 `\b'
6467 backspace
6468
6469 `\d'
6470 delete
6471
6472 `\f'
6473 form feed
6474
6475 `\n'
6476 newline
ccc6cda3 6477
cce855bc
JA
6478 `\r'
6479 carriage return
ccc6cda3 6480
cce855bc
JA
6481 `\t'
6482 horizontal tab
ccc6cda3 6483
cce855bc
JA
6484 `\v'
6485 vertical tab
ccc6cda3 6486
cce855bc 6487 `\NNN'
f73dda09 6488 the eight-bit character whose value is the octal value NNN
cce855bc 6489 (one to three digits)
ccc6cda3 6490
f73dda09
JA
6491 `\xHH'
6492 the eight-bit character whose value is the hexadecimal value
6493 HH (one or two hex digits)
6494
cce855bc
JA
6495 When entering the text of a macro, single or double quotes must be
6496 used to indicate a macro definition. Unquoted text is assumed to
6497 be a function name. In the macro body, the backslash escapes
6498 described above are expanded. Backslash will quote any other
6499 character in the macro text, including `"' and `''. For example,
6500 the following binding will make `C-x \' insert a single `\' into
6501 the line:
6502 "\C-x\\": "\\"
ccc6cda3 6503
761783bf 6504
ccc6cda3
JA
6505\1f
6506File: bashref.info, Node: Conditional Init Constructs, Next: Sample Init File, Prev: Readline Init File Syntax, Up: Readline Init File
6507
37c41ab1
CR
65088.3.2 Conditional Init Constructs
6509---------------------------------
ccc6cda3 6510
37c41ab1 6511Readline implements a facility similar in spirit to the conditional
ccc6cda3
JA
6512compilation features of the C preprocessor which allows key bindings
6513and variable settings to be performed as the result of tests. There
cce855bc 6514are four parser directives used.
ccc6cda3
JA
6515
6516`$if'
6517 The `$if' construct allows bindings to be made based on the
6518 editing mode, the terminal being used, or the application using
6519 Readline. The text of the test extends to the end of the line; no
6520 characters are required to isolate it.
6521
6522 `mode'
6523 The `mode=' form of the `$if' directive is used to test
6524 whether Readline is in `emacs' or `vi' mode. This may be
6525 used in conjunction with the `set keymap' command, for
6526 instance, to set bindings in the `emacs-standard' and
6527 `emacs-ctlx' keymaps only if Readline is starting out in
6528 `emacs' mode.
6529
6530 `term'
6531 The `term=' form may be used to include terminal-specific key
6532 bindings, perhaps to bind the key sequences output by the
6533 terminal's function keys. The word on the right side of the
cce855bc
JA
6534 `=' is tested against both the full name of the terminal and
6535 the portion of the terminal name before the first `-'. This
ccc6cda3
JA
6536 allows `sun' to match both `sun' and `sun-cmd', for instance.
6537
6538 `application'
6539 The APPLICATION construct is used to include
6540 application-specific settings. Each program using the
6541 Readline library sets the APPLICATION NAME, and you can test
28ef6c31
JA
6542 for a particular value. This could be used to bind key
6543 sequences to functions useful for a specific program. For
6544 instance, the following command adds a key sequence that
6545 quotes the current or previous word in Bash:
ccc6cda3
JA
6546 $if Bash
6547 # Quote the current or previous word
6548 "\C-xq": "\eb\"\ef\""
6549 $endif
6550
6551`$endif'
cce855bc
JA
6552 This command, as seen in the previous example, terminates an `$if'
6553 command.
ccc6cda3
JA
6554
6555`$else'
6556 Commands in this branch of the `$if' directive are executed if the
6557 test fails.
6558
cce855bc
JA
6559`$include'
6560 This directive takes a single filename as an argument and reads
28ef6c31
JA
6561 commands and bindings from that file. For example, the following
6562 directive reads from `/etc/inputrc':
cce855bc
JA
6563 $include /etc/inputrc
6564
ccc6cda3
JA
6565\1f
6566File: bashref.info, Node: Sample Init File, Prev: Conditional Init Constructs, Up: Readline Init File
6567
37c41ab1
CR
65688.3.3 Sample Init File
6569----------------------
ccc6cda3 6570
37c41ab1
CR
6571Here is an example of an INPUTRC file. This illustrates key binding,
6572variable assignment, and conditional syntax.
ccc6cda3
JA
6573
6574
6575 # This file controls the behaviour of line input editing for
7117c2d2
JA
6576 # programs that use the GNU Readline library. Existing
6577 # programs include FTP, Bash, and GDB.
ccc6cda3
JA
6578 #
6579 # You can re-read the inputrc file with C-x C-r.
6580 # Lines beginning with '#' are comments.
cce855bc 6581 #
7117c2d2
JA
6582 # First, include any systemwide bindings and variable
6583 # assignments from /etc/Inputrc
cce855bc 6584 $include /etc/Inputrc
37c41ab1 6585
ccc6cda3
JA
6586 #
6587 # Set various bindings for emacs mode.
37c41ab1 6588
ccc6cda3 6589 set editing-mode emacs
37c41ab1 6590
ccc6cda3 6591 $if mode=emacs
37c41ab1 6592
ccc6cda3 6593 Meta-Control-h: backward-kill-word Text after the function name is ignored
37c41ab1 6594
ccc6cda3
JA
6595 #
6596 # Arrow keys in keypad mode
6597 #
d166f048
JA
6598 #"\M-OD": backward-char
6599 #"\M-OC": forward-char
6600 #"\M-OA": previous-history
6601 #"\M-OB": next-history
ccc6cda3
JA
6602 #
6603 # Arrow keys in ANSI mode
6604 #
d166f048
JA
6605 "\M-[D": backward-char
6606 "\M-[C": forward-char
6607 "\M-[A": previous-history
6608 "\M-[B": next-history
ccc6cda3
JA
6609 #
6610 # Arrow keys in 8 bit keypad mode
6611 #
d166f048
JA
6612 #"\M-\C-OD": backward-char
6613 #"\M-\C-OC": forward-char
6614 #"\M-\C-OA": previous-history
6615 #"\M-\C-OB": next-history
ccc6cda3
JA
6616 #
6617 # Arrow keys in 8 bit ANSI mode
6618 #
d166f048
JA
6619 #"\M-\C-[D": backward-char
6620 #"\M-\C-[C": forward-char
6621 #"\M-\C-[A": previous-history
6622 #"\M-\C-[B": next-history
37c41ab1 6623
ccc6cda3 6624 C-q: quoted-insert
37c41ab1 6625
ccc6cda3 6626 $endif
37c41ab1 6627
ccc6cda3
JA
6628 # An old-style binding. This happens to be the default.
6629 TAB: complete
37c41ab1 6630
ccc6cda3
JA
6631 # Macros that are convenient for shell interaction
6632 $if Bash
6633 # edit the path
6634 "\C-xp": "PATH=${PATH}\e\C-e\C-a\ef\C-f"
7117c2d2
JA
6635 # prepare to type a quoted word --
6636 # insert open and close double quotes
ccc6cda3
JA
6637 # and move to just after the open quote
6638 "\C-x\"": "\"\"\C-b"
7117c2d2
JA
6639 # insert a backslash (testing backslash escapes
6640 # in sequences and macros)
ccc6cda3
JA
6641 "\C-x\\": "\\"
6642 # Quote the current or previous word
6643 "\C-xq": "\eb\"\ef\""
6644 # Add a binding to refresh the line, which is unbound
6645 "\C-xr": redraw-current-line
6646 # Edit variable on current line.
6647 "\M-\C-v": "\C-a\C-k$\C-y\M-\C-e\C-a\C-y="
6648 $endif
37c41ab1 6649
ccc6cda3
JA
6650 # use a visible bell if one is available
6651 set bell-style visible
37c41ab1 6652
ccc6cda3
JA
6653 # don't strip characters to 7 bits when reading
6654 set input-meta on
37c41ab1 6655
7117c2d2
JA
6656 # allow iso-latin1 characters to be inserted rather
6657 # than converted to prefix-meta sequences
ccc6cda3 6658 set convert-meta off
37c41ab1 6659
7117c2d2
JA
6660 # display characters with the eighth bit set directly
6661 # rather than as meta-prefixed characters
ccc6cda3 6662 set output-meta on
37c41ab1 6663
7117c2d2
JA
6664 # if there are more than 150 possible completions for
6665 # a word, ask the user if he wants to see all of them
ccc6cda3 6666 set completion-query-items 150
37c41ab1 6667
ccc6cda3
JA
6668 # For FTP
6669 $if Ftp
6670 "\C-xg": "get \M-?"
6671 "\C-xt": "put \M-?"
6672 "\M-.": yank-last-arg
6673 $endif
6674
6675\1f
bb70624e
JA
6676File: bashref.info, Node: Bindable Readline Commands, Next: Readline vi Mode, Prev: Readline Init File, Up: Command Line Editing
6677
37c41ab1
CR
66788.4 Bindable Readline Commands
6679==============================
bb70624e
JA
6680
6681* Menu:
6682
6683* Commands For Moving:: Moving about the line.
6684* Commands For History:: Getting at previous lines.
6685* Commands For Text:: Commands for changing text.
6686* Commands For Killing:: Commands for killing and yanking.
6687* Numeric Arguments:: Specifying numeric arguments, repeat counts.
6688* Commands For Completion:: Getting Readline to do the typing for you.
6689* Keyboard Macros:: Saving and re-executing typed characters
6690* Miscellaneous Commands:: Other miscellaneous commands.
6691
6692 This section describes Readline commands that may be bound to key
6693sequences. You can list your key bindings by executing `bind -P' or,
6694for a more terse format, suitable for an INPUTRC file, `bind -p'.
28ef6c31
JA
6695(*Note Bash Builtins::.) Command names without an accompanying key
6696sequence are unbound by default.
bb70624e 6697
28ef6c31
JA
6698 In the following descriptions, "point" refers to the current cursor
6699position, and "mark" refers to a cursor position saved by the
bb70624e 6700`set-mark' command. The text between the point and mark is referred to
28ef6c31 6701as the "region".
bb70624e
JA
6702
6703\1f
6704File: bashref.info, Node: Commands For Moving, Next: Commands For History, Up: Bindable Readline Commands
6705
37c41ab1
CR
67068.4.1 Commands For Moving
6707-------------------------
bb70624e
JA
6708
6709`beginning-of-line (C-a)'
6710 Move to the start of the current line.
6711
6712`end-of-line (C-e)'
6713 Move to the end of the line.
6714
6715`forward-char (C-f)'
6716 Move forward a character.
6717
6718`backward-char (C-b)'
6719 Move back a character.
6720
6721`forward-word (M-f)'
6722 Move forward to the end of the next word. Words are composed of
6723 letters and digits.
6724
6725`backward-word (M-b)'
6726 Move back to the start of the current or previous word. Words are
6727 composed of letters and digits.
6728
6729`clear-screen (C-l)'
6730 Clear the screen and redraw the current line, leaving the current
6731 line at the top of the screen.
6732
6733`redraw-current-line ()'
6734 Refresh the current line. By default, this is unbound.
6735
761783bf 6736
bb70624e
JA
6737\1f
6738File: bashref.info, Node: Commands For History, Next: Commands For Text, Prev: Commands For Moving, Up: Bindable Readline Commands
6739
37c41ab1
CR
67408.4.2 Commands For Manipulating The History
6741-------------------------------------------
bb70624e 6742
28ef6c31 6743`accept-line (Newline or Return)'
bb70624e
JA
6744 Accept the line regardless of where the cursor is. If this line is
6745 non-empty, add it to the history list according to the setting of
28ef6c31
JA
6746 the `HISTCONTROL' and `HISTIGNORE' variables. If this line is a
6747 modified history line, then restore the history line to its
6748 original state.
bb70624e
JA
6749
6750`previous-history (C-p)'
28ef6c31
JA
6751 Move `back' through the history list, fetching the previous
6752 command.
bb70624e
JA
6753
6754`next-history (C-n)'
28ef6c31 6755 Move `forward' through the history list, fetching the next command.
bb70624e
JA
6756
6757`beginning-of-history (M-<)'
6758 Move to the first line in the history.
6759
6760`end-of-history (M->)'
6761 Move to the end of the input history, i.e., the line currently
6762 being entered.
6763
6764`reverse-search-history (C-r)'
6765 Search backward starting at the current line and moving `up'
6766 through the history as necessary. This is an incremental search.
6767
6768`forward-search-history (C-s)'
6769 Search forward starting at the current line and moving `down'
6770 through the the history as necessary. This is an incremental
6771 search.
6772
6773`non-incremental-reverse-search-history (M-p)'
6774 Search backward starting at the current line and moving `up'
6775 through the history as necessary using a non-incremental search
6776 for a string supplied by the user.
6777
6778`non-incremental-forward-search-history (M-n)'
6779 Search forward starting at the current line and moving `down'
6780 through the the history as necessary using a non-incremental search
6781 for a string supplied by the user.
6782
6783`history-search-forward ()'
6784 Search forward through the history for the string of characters
6785 between the start of the current line and the point. This is a
6786 non-incremental search. By default, this command is unbound.
6787
6788`history-search-backward ()'
6789 Search backward through the history for the string of characters
6790 between the start of the current line and the point. This is a
6791 non-incremental search. By default, this command is unbound.
6792
6793`yank-nth-arg (M-C-y)'
6794 Insert the first argument to the previous command (usually the
28ef6c31
JA
6795 second word on the previous line) at point. With an argument N,
6796 insert the Nth word from the previous command (the words in the
6797 previous command begin with word 0). A negative argument inserts
eb2bb562
CR
6798 the Nth word from the end of the previous command. Once the
6799 argument N is computed, the argument is extracted as if the `!N'
6800 history expansion had been specified.
bb70624e 6801
28ef6c31 6802`yank-last-arg (M-. or M-_)'
bb70624e
JA
6803 Insert last argument to the previous command (the last word of the
6804 previous history entry). With an argument, behave exactly like
6805 `yank-nth-arg'. Successive calls to `yank-last-arg' move back
6806 through the history list, inserting the last argument of each line
eb2bb562
CR
6807 in turn. The history expansion facilities are used to extract the
6808 last argument, as if the `!$' history expansion had been specified.
bb70624e 6809
761783bf 6810
bb70624e
JA
6811\1f
6812File: bashref.info, Node: Commands For Text, Next: Commands For Killing, Prev: Commands For History, Up: Bindable Readline Commands
6813
37c41ab1
CR
68148.4.3 Commands For Changing Text
6815--------------------------------
bb70624e
JA
6816
6817`delete-char (C-d)'
28ef6c31
JA
6818 Delete the character at point. If point is at the beginning of
6819 the line, there are no characters in the line, and the last
6820 character typed was not bound to `delete-char', then return EOF.
bb70624e
JA
6821
6822`backward-delete-char (Rubout)'
6823 Delete the character behind the cursor. A numeric argument means
6824 to kill the characters instead of deleting them.
6825
6826`forward-backward-delete-char ()'
6827 Delete the character under the cursor, unless the cursor is at the
6828 end of the line, in which case the character behind the cursor is
6829 deleted. By default, this is not bound to a key.
6830
28ef6c31 6831`quoted-insert (C-q or C-v)'
bb70624e 6832 Add the next character typed to the line verbatim. This is how to
28ef6c31 6833 insert key sequences like `C-q', for example.
bb70624e
JA
6834
6835`self-insert (a, b, A, 1, !, ...)'
6836 Insert yourself.
6837
6838`transpose-chars (C-t)'
6839 Drag the character before the cursor forward over the character at
6840 the cursor, moving the cursor forward as well. If the insertion
6841 point is at the end of the line, then this transposes the last two
6842 characters of the line. Negative arguments have no effect.
6843
6844`transpose-words (M-t)'
6845 Drag the word before point past the word after point, moving point
f73dda09
JA
6846 past that word as well. If the insertion point is at the end of
6847 the line, this transposes the last two words on the line.
bb70624e
JA
6848
6849`upcase-word (M-u)'
6850 Uppercase the current (or following) word. With a negative
6851 argument, uppercase the previous word, but do not move the cursor.
6852
6853`downcase-word (M-l)'
6854 Lowercase the current (or following) word. With a negative
6855 argument, lowercase the previous word, but do not move the cursor.
6856
6857`capitalize-word (M-c)'
6858 Capitalize the current (or following) word. With a negative
6859 argument, capitalize the previous word, but do not move the cursor.
6860
7117c2d2
JA
6861`overwrite-mode ()'
6862 Toggle overwrite mode. With an explicit positive numeric argument,
6863 switches to overwrite mode. With an explicit non-positive numeric
6864 argument, switches to insert mode. This command affects only
6865 `emacs' mode; `vi' mode does overwrite differently. Each call to
6866 `readline()' starts in insert mode.
6867
6868 In overwrite mode, characters bound to `self-insert' replace the
6869 text at point rather than pushing the text to the right.
6870 Characters bound to `backward-delete-char' replace the character
6871 before point with a space.
6872
6873 By default, this command is unbound.
6874
761783bf 6875
bb70624e
JA
6876\1f
6877File: bashref.info, Node: Commands For Killing, Next: Numeric Arguments, Prev: Commands For Text, Up: Bindable Readline Commands
6878
37c41ab1
CR
68798.4.4 Killing And Yanking
6880-------------------------
bb70624e
JA
6881
6882`kill-line (C-k)'
6883 Kill the text from point to the end of the line.
6884
6885`backward-kill-line (C-x Rubout)'
6886 Kill backward to the beginning of the line.
6887
6888`unix-line-discard (C-u)'
6889 Kill backward from the cursor to the beginning of the current line.
6890
6891`kill-whole-line ()'
28ef6c31
JA
6892 Kill all characters on the current line, no matter where point is.
6893 By default, this is unbound.
bb70624e
JA
6894
6895`kill-word (M-d)'
6896 Kill from point to the end of the current word, or if between
6897 words, to the end of the next word. Word boundaries are the same
6898 as `forward-word'.
6899
28ef6c31 6900`backward-kill-word (M-<DEL>)'
bb70624e
JA
6901 Kill the word behind point. Word boundaries are the same as
6902 `backward-word'.
6903
6904`unix-word-rubout (C-w)'
6905 Kill the word behind point, using white space as a word boundary.
6906 The killed text is saved on the kill-ring.
6907
113d85a4
CR
6908`unix-filename-rubout ()'
6909 Kill the word behind point, using white space and the slash
6910 character as the word boundaries. The killed text is saved on the
6911 kill-ring.
6912
bb70624e
JA
6913`delete-horizontal-space ()'
6914 Delete all spaces and tabs around point. By default, this is
6915 unbound.
6916
6917`kill-region ()'
6918 Kill the text in the current region. By default, this command is
6919 unbound.
6920
6921`copy-region-as-kill ()'
6922 Copy the text in the region to the kill buffer, so it can be yanked
6923 right away. By default, this command is unbound.
6924
6925`copy-backward-word ()'
6926 Copy the word before point to the kill buffer. The word
6927 boundaries are the same as `backward-word'. By default, this
6928 command is unbound.
6929
6930`copy-forward-word ()'
6931 Copy the word following point to the kill buffer. The word
6932 boundaries are the same as `forward-word'. By default, this
6933 command is unbound.
6934
6935`yank (C-y)'
28ef6c31 6936 Yank the top of the kill ring into the buffer at point.
bb70624e
JA
6937
6938`yank-pop (M-y)'
6939 Rotate the kill-ring, and yank the new top. You can only do this
28ef6c31 6940 if the prior command is `yank' or `yank-pop'.
bb70624e
JA
6941
6942\1f
6943File: bashref.info, Node: Numeric Arguments, Next: Commands For Completion, Prev: Commands For Killing, Up: Bindable Readline Commands
6944
37c41ab1
CR
69458.4.5 Specifying Numeric Arguments
6946----------------------------------
bb70624e
JA
6947
6948`digit-argument (M-0, M-1, ... M--)'
6949 Add this digit to the argument already accumulating, or start a new
28ef6c31 6950 argument. `M--' starts a negative argument.
bb70624e
JA
6951
6952`universal-argument ()'
6953 This is another way to specify an argument. If this command is
6954 followed by one or more digits, optionally with a leading minus
6955 sign, those digits define the argument. If the command is
6956 followed by digits, executing `universal-argument' again ends the
6957 numeric argument, but is otherwise ignored. As a special case, if
6958 this command is immediately followed by a character that is
6959 neither a digit or minus sign, the argument count for the next
6960 command is multiplied by four. The argument count is initially
6961 one, so executing this function the first time makes the argument
6962 count four, a second time makes the argument count sixteen, and so
6963 on. By default, this is not bound to a key.
6964
6965\1f
6966File: bashref.info, Node: Commands For Completion, Next: Keyboard Macros, Prev: Numeric Arguments, Up: Bindable Readline Commands
6967
37c41ab1
CR
69688.4.6 Letting Readline Type For You
6969-----------------------------------
bb70624e 6970
28ef6c31
JA
6971`complete (<TAB>)'
6972 Attempt to perform completion on the text before point. The
6973 actual completion performed is application-specific. Bash
6974 attempts completion treating the text as a variable (if the text
6975 begins with `$'), username (if the text begins with `~'), hostname
6976 (if the text begins with `@'), or command (including aliases and
6977 functions) in turn. If none of these produces a match, filename
6978 completion is attempted.
bb70624e
JA
6979
6980`possible-completions (M-?)'
28ef6c31 6981 List the possible completions of the text before point.
bb70624e
JA
6982
6983`insert-completions (M-*)'
6984 Insert all completions of the text before point that would have
6985 been generated by `possible-completions'.
6986
6987`menu-complete ()'
6988 Similar to `complete', but replaces the word to be completed with
6989 a single match from the list of possible completions. Repeated
6990 execution of `menu-complete' steps through the list of possible
6991 completions, inserting each match in turn. At the end of the list
28ef6c31
JA
6992 of completions, the bell is rung (subject to the setting of
6993 `bell-style') and the original text is restored. An argument of N
6994 moves N positions forward in the list of matches; a negative
6995 argument may be used to move backward through the list. This
6996 command is intended to be bound to <TAB>, but is unbound by
bb70624e
JA
6997 default.
6998
6999`delete-char-or-list ()'
7000 Deletes the character under the cursor if not at the beginning or
7001 end of the line (like `delete-char'). If at the end of the line,
7002 behaves identically to `possible-completions'. This command is
7003 unbound by default.
7004
7005`complete-filename (M-/)'
7006 Attempt filename completion on the text before point.
7007
7008`possible-filename-completions (C-x /)'
7009 List the possible completions of the text before point, treating
7010 it as a filename.
7011
7012`complete-username (M-~)'
7013 Attempt completion on the text before point, treating it as a
7014 username.
7015
7016`possible-username-completions (C-x ~)'
7017 List the possible completions of the text before point, treating
7018 it as a username.
7019
7020`complete-variable (M-$)'
7021 Attempt completion on the text before point, treating it as a
7022 shell variable.
7023
7024`possible-variable-completions (C-x $)'
7025 List the possible completions of the text before point, treating
7026 it as a shell variable.
7027
7028`complete-hostname (M-@)'
7029 Attempt completion on the text before point, treating it as a
7030 hostname.
7031
7032`possible-hostname-completions (C-x @)'
7033 List the possible completions of the text before point, treating
7034 it as a hostname.
7035
7036`complete-command (M-!)'
7037 Attempt completion on the text before point, treating it as a
7038 command name. Command completion attempts to match the text
7039 against aliases, reserved words, shell functions, shell builtins,
7040 and finally executable filenames, in that order.
7041
7042`possible-command-completions (C-x !)'
7043 List the possible completions of the text before point, treating
7044 it as a command name.
7045
28ef6c31 7046`dynamic-complete-history (M-<TAB>)'
bb70624e
JA
7047 Attempt completion on the text before point, comparing the text
7048 against lines from the history list for possible completion
7049 matches.
7050
ed35cb4a
CR
7051`dabbrev-expand ()'
7052 Attempt menu completion on the text before point, comparing the
7053 text against lines from the history list for possible completion
7054 matches.
7055
bb70624e
JA
7056`complete-into-braces (M-{)'
7057 Perform filename completion and insert the list of possible
7058 completions enclosed within braces so the list is available to the
28ef6c31 7059 shell (*note Brace Expansion::).
bb70624e 7060
761783bf 7061
bb70624e
JA
7062\1f
7063File: bashref.info, Node: Keyboard Macros, Next: Miscellaneous Commands, Prev: Commands For Completion, Up: Bindable Readline Commands
7064
37c41ab1
CR
70658.4.7 Keyboard Macros
7066---------------------
bb70624e
JA
7067
7068`start-kbd-macro (C-x ()'
7069 Begin saving the characters typed into the current keyboard macro.
7070
7071`end-kbd-macro (C-x ))'
7072 Stop saving the characters typed into the current keyboard macro
7073 and save the definition.
7074
7075`call-last-kbd-macro (C-x e)'
7076 Re-execute the last keyboard macro defined, by making the
7077 characters in the macro appear as if typed at the keyboard.
7078
761783bf 7079
bb70624e
JA
7080\1f
7081File: bashref.info, Node: Miscellaneous Commands, Prev: Keyboard Macros, Up: Bindable Readline Commands
7082
37c41ab1
CR
70838.4.8 Some Miscellaneous Commands
7084---------------------------------
bb70624e
JA
7085
7086`re-read-init-file (C-x C-r)'
7087 Read in the contents of the INPUTRC file, and incorporate any
7088 bindings or variable assignments found there.
7089
7090`abort (C-g)'
7091 Abort the current editing command and ring the terminal's bell
7092 (subject to the setting of `bell-style').
7093
7094`do-uppercase-version (M-a, M-b, M-X, ...)'
7095 If the metafied character X is lowercase, run the command that is
7096 bound to the corresponding uppercase character.
7097
28ef6c31
JA
7098`prefix-meta (<ESC>)'
7099 Metafy the next character typed. This is for keyboards without a
7100 meta key. Typing `<ESC> f' is equivalent to typing `M-f'.
bb70624e 7101
28ef6c31 7102`undo (C-_ or C-x C-u)'
bb70624e
JA
7103 Incremental undo, separately remembered for each line.
7104
7105`revert-line (M-r)'
7106 Undo all changes made to this line. This is like executing the
7107 `undo' command enough times to get back to the beginning.
7108
7109`tilde-expand (M-&)'
7110 Perform tilde expansion on the current word.
7111
7112`set-mark (C-@)'
28ef6c31
JA
7113 Set the mark to the point. If a numeric argument is supplied, the
7114 mark is set to that position.
bb70624e
JA
7115
7116`exchange-point-and-mark (C-x C-x)'
7117 Swap the point with the mark. The current cursor position is set
7118 to the saved position, and the old cursor position is saved as the
7119 mark.
7120
7121`character-search (C-])'
7122 A character is read and point is moved to the next occurrence of
7123 that character. A negative count searches for previous
7124 occurrences.
7125
7126`character-search-backward (M-C-])'
7127 A character is read and point is moved to the previous occurrence
7128 of that character. A negative count searches for subsequent
7129 occurrences.
7130
7131`insert-comment (M-#)'
7117c2d2
JA
7132 Without a numeric argument, the value of the `comment-begin'
7133 variable is inserted at the beginning of the current line. If a
7134 numeric argument is supplied, this command acts as a toggle: if
7135 the characters at the beginning of the line do not match the value
7136 of `comment-begin', the value is inserted, otherwise the
7137 characters in `comment-begin' are deleted from the beginning of
7138 the line. In either case, the line is accepted as if a newline
7139 had been typed. The default value of `comment-begin' causes this
7140 command to make the current line a shell comment. If a numeric
7141 argument causes the comment character to be removed, the line will
7142 be executed by the shell.
bb70624e
JA
7143
7144`dump-functions ()'
7145 Print all of the functions and their key bindings to the Readline
7146 output stream. If a numeric argument is supplied, the output is
7147 formatted in such a way that it can be made part of an INPUTRC
7148 file. This command is unbound by default.
7149
7150`dump-variables ()'
7151 Print all of the settable variables and their values to the
7152 Readline output stream. If a numeric argument is supplied, the
7153 output is formatted in such a way that it can be made part of an
7154 INPUTRC file. This command is unbound by default.
7155
7156`dump-macros ()'
7157 Print all of the Readline key sequences bound to macros and the
28ef6c31
JA
7158 strings they output. If a numeric argument is supplied, the
7159 output is formatted in such a way that it can be made part of an
7160 INPUTRC file. This command is unbound by default.
bb70624e 7161
7117c2d2
JA
7162`glob-complete-word (M-g)'
7163 The word before point is treated as a pattern for pathname
7164 expansion, with an asterisk implicitly appended. This pattern is
7165 used to generate a list of matching file names for possible
7166 completions.
7167
bb70624e
JA
7168`glob-expand-word (C-x *)'
7169 The word before point is treated as a pattern for pathname
7170 expansion, and the list of matching file names is inserted,
7117c2d2
JA
7171 replacing the word. If a numeric argument is supplied, a `*' is
7172 appended before pathname expansion.
bb70624e
JA
7173
7174`glob-list-expansions (C-x g)'
7175 The list of expansions that would have been generated by
7117c2d2
JA
7176 `glob-expand-word' is displayed, and the line is redrawn. If a
7177 numeric argument is supplied, a `*' is appended before pathname
7178 expansion.
bb70624e
JA
7179
7180`display-shell-version (C-x C-v)'
7181 Display version information about the current instance of Bash.
7182
7183`shell-expand-line (M-C-e)'
7184 Expand the line as the shell does. This performs alias and
7185 history expansion as well as all of the shell word expansions
28ef6c31 7186 (*note Shell Expansions::).
bb70624e
JA
7187
7188`history-expand-line (M-^)'
7189 Perform history expansion on the current line.
7190
7191`magic-space ()'
7192 Perform history expansion on the current line and insert a space
28ef6c31 7193 (*note History Interaction::).
bb70624e
JA
7194
7195`alias-expand-line ()'
28ef6c31 7196 Perform alias expansion on the current line (*note Aliases::).
bb70624e
JA
7197
7198`history-and-alias-expand-line ()'
7199 Perform history and alias expansion on the current line.
7200
28ef6c31 7201`insert-last-argument (M-. or M-_)'
bb70624e
JA
7202 A synonym for `yank-last-arg'.
7203
7204`operate-and-get-next (C-o)'
7205 Accept the current line for execution and fetch the next line
7206 relative to the current line from the history for editing. Any
7207 argument is ignored.
7208
7117c2d2
JA
7209`edit-and-execute-command (C-xC-e)'
7210 Invoke an editor on the current command line, and execute the
c2258e1c 7211 result as shell commands. Bash attempts to invoke `$VISUAL',
7117c2d2 7212 `$EDITOR', and `emacs' as the editor, in that order.
bb70624e 7213
761783bf 7214
bb70624e
JA
7215\1f
7216File: bashref.info, Node: Readline vi Mode, Next: Programmable Completion, Prev: Bindable Readline Commands, Up: Command Line Editing
7217
37c41ab1
CR
72188.5 Readline vi Mode
7219====================
bb70624e 7220
37c41ab1 7221While the Readline library does not have a full set of `vi' editing
bb70624e
JA
7222functions, it does contain enough to allow simple editing of the line.
7223The Readline `vi' mode behaves as specified in the POSIX 1003.2
7224standard.
7225
7226 In order to switch interactively between `emacs' and `vi' editing
7227modes, use the `set -o emacs' and `set -o vi' commands (*note The Set
28ef6c31 7228Builtin::). The Readline default is `emacs' mode.
bb70624e
JA
7229
7230 When you enter a line in `vi' mode, you are already placed in
7231`insertion' mode, as if you had typed an `i'. Pressing <ESC> switches
7232you into `command' mode, where you can edit the text of the line with
7233the standard `vi' movement keys, move to previous history lines with
7234`k' and subsequent lines with `j', and so forth.
7235
7236\1f
7237File: bashref.info, Node: Programmable Completion, Next: Programmable Completion Builtins, Prev: Readline vi Mode, Up: Command Line Editing
7238
37c41ab1
CR
72398.6 Programmable Completion
7240===========================
bb70624e 7241
37c41ab1 7242When word completion is attempted for an argument to a command for
bb70624e 7243which a completion specification (a COMPSPEC) has been defined using
28ef6c31 7244the `complete' builtin (*note Programmable Completion Builtins::), the
bb70624e
JA
7245programmable completion facilities are invoked.
7246
7247 First, the command name is identified. If a compspec has been
7248defined for that command, the compspec is used to generate the list of
7249possible completions for the word. If the command word is a full
7250pathname, a compspec for the full pathname is searched for first. If
7251no compspec is found for the full pathname, an attempt is made to find
7252a compspec for the portion following the final slash.
7253
7254 Once a compspec has been found, it is used to generate the list of
7255matching words. If a compspec is not found, the default Bash completion
28ef6c31 7256described above (*note Commands For Completion::) is performed.
bb70624e
JA
7257
7258 First, the actions specified by the compspec are used. Only matches
7259which are prefixed by the word being completed are returned. When the
7260`-f' or `-d' option is used for filename or directory name completion,
7261the shell variable `FIGNORE' is used to filter the matches. *Note Bash
7262Variables::, for a description of `FIGNORE'.
7263
7264 Any completions specified by a filename expansion pattern to the
7265`-G' option are generated next. The words generated by the pattern
7266need not match the word being completed. The `GLOBIGNORE' shell
7267variable is not used to filter the matches, but the `FIGNORE' shell
7268variable is used.
7269
7270 Next, the string specified as the argument to the `-W' option is
7271considered. The string is first split using the characters in the `IFS'
7272special variable as delimiters. Shell quoting is honored. Each word
7273is then expanded using brace expansion, tilde expansion, parameter and
2206f89a
CR
7274variable expansion, command substitution, and arithmetic expansion, as
7275described above (*note Shell Expansions::). The results are split
7276using the rules described above (*note Word Splitting::). The results
7277of the expansion are prefix-matched against the word being completed,
7278and the matching words become the possible completions.
bb70624e
JA
7279
7280 After these matches have been generated, any shell function or
7281command specified with the `-F' and `-C' options is invoked. When the
d3ad40de
CR
7282command or function is invoked, the `COMP_LINE', `COMP_POINT',
7283`COMP_KEY', and `COMP_TYPE' variables are assigned values as described
7284above (*note Bash Variables::). If a shell function is being invoked,
7285the `COMP_WORDS' and `COMP_CWORD' variables are also set. When the
7286function or command is invoked, the first argument is the name of the
7287command whose arguments are being completed, the second argument is the
7288word being completed, and the third argument is the word preceding the
7289word being completed on the current command line. No filtering of the
7290generated completions against the word being completed is performed;
7291the function or command has complete freedom in generating the matches.
bb70624e
JA
7292
7293 Any function specified with `-F' is invoked first. The function may
6a8fd0ed
CR
7294use any of the shell facilities, including the `compgen' and `compopt'
7295builtins described below (*note Programmable Completion Builtins::), to
7296generate the matches. It must put the possible completions in the
7297`COMPREPLY' array variable.
bb70624e
JA
7298
7299 Next, any command specified with the `-C' option is invoked in an
7300environment equivalent to command substitution. It should print a list
7301of completions, one per line, to the standard output. Backslash may be
7302used to escape a newline, if necessary.
7303
7304 After all of the possible completions are generated, any filter
7305specified with the `-X' option is applied to the list. The filter is a
7306pattern as used for pathname expansion; a `&' in the pattern is
7307replaced with the text of the word being completed. A literal `&' may
7308be escaped with a backslash; the backslash is removed before attempting
7309a match. Any completion that matches the pattern will be removed from
7310the list. A leading `!' negates the pattern; in this case any
7311completion not matching the pattern will be removed.
7312
7313 Finally, any prefix and suffix specified with the `-P' and `-S'
7314options are added to each member of the completion list, and the result
7315is returned to the Readline completion code as the list of possible
7316completions.
7317
28ef6c31
JA
7318 If the previously-applied actions do not generate any matches, and
7319the `-o dirnames' option was supplied to `complete' when the compspec
7320was defined, directory name completion is attempted.
7321
d3a24ed2
CR
7322 If the `-o plusdirs' option was supplied to `complete' when the
7323compspec was defined, directory name completion is attempted and any
7324matches are added to the results of the other actions.
7325
28ef6c31
JA
7326 By default, if a compspec is found, whatever it generates is
7327returned to the completion code as the full set of possible completions.
7328The default Bash completions are not attempted, and the Readline default
d3a24ed2
CR
7329of filename completion is disabled. If the `-o bashdefault' option was
7330supplied to `complete' when the compspec was defined, the default Bash
7331completions are attempted if the compspec generates no matches. If the
7332`-o default' option was supplied to `complete' when the compspec was
7333defined, Readline's default completion will be performed if the
7334compspec (and, if attempted, the default Bash completions) generate no
28ef6c31 7335matches.
bb70624e 7336
7117c2d2
JA
7337 When a compspec indicates that directory name completion is desired,
7338the programmable completion functions force Readline to append a slash
7339to completed names which are symbolic links to directories, subject to
7340the value of the MARK-DIRECTORIES Readline variable, regardless of the
7341setting of the MARK-SYMLINKED-DIRECTORIES Readline variable.
7342
bb70624e
JA
7343\1f
7344File: bashref.info, Node: Programmable Completion Builtins, Prev: Programmable Completion, Up: Command Line Editing
7345
37c41ab1
CR
73468.7 Programmable Completion Builtins
7347====================================
bb70624e 7348
37c41ab1 7349Two builtin commands are available to manipulate the programmable
bb70624e
JA
7350completion facilities.
7351
7352`compgen'
7353 `compgen [OPTION] [WORD]'
7354
7355 Generate possible completion matches for WORD according to the
7356 OPTIONs, which may be any option accepted by the `complete'
7357 builtin with the exception of `-p' and `-r', and write the matches
7358 to the standard output. When using the `-F' or `-C' options, the
7359 various shell variables set by the programmable completion
7360 facilities, while available, will not have useful values.
7361
7362 The matches will be generated in the same way as if the
7363 programmable completion code had generated them directly from a
7364 completion specification with the same flags. If WORD is
7365 specified, only those completions matching WORD will be displayed.
7366
7367 The return value is true unless an invalid option is supplied, or
7368 no matches were generated.
7369
7370`complete'
ed35cb4a 7371 `complete [-abcdefgjksuv] [-o COMP-OPTION] [-E] [-A ACTION] [-G GLOBPAT] [-W WORDLIST]
d3ad40de
CR
7372 [-F FUNCTION] [-C COMMAND] [-X FILTERPAT]
7373 [-P PREFIX] [-S SUFFIX] NAME [NAME ...]'
ed35cb4a 7374 `complete -pr [-E] [NAME ...]'
bb70624e
JA
7375
7376 Specify how arguments to each NAME should be completed. If the
7377 `-p' option is supplied, or if no options are supplied, existing
7378 completion specifications are printed in a way that allows them to
7379 be reused as input. The `-r' option removes a completion
7380 specification for each NAME, or, if no NAMEs are supplied, all
ed35cb4a
CR
7381 completion specifications. The `-E' option indicates that the
7382 remaining options and actions should apply to "empty" command
7383 completion; that is, completion attempted on a blank line.
bb70624e
JA
7384
7385 The process of applying these completion specifications when word
7386 completion is attempted is described above (*note Programmable
28ef6c31 7387 Completion::).
bb70624e
JA
7388
7389 Other options, if specified, have the following meanings. The
7390 arguments to the `-G', `-W', and `-X' options (and, if necessary,
7391 the `-P' and `-S' options) should be quoted to protect them from
7392 expansion before the `complete' builtin is invoked.
7393
28ef6c31
JA
7394 `-o COMP-OPTION'
7395 The COMP-OPTION controls several aspects of the compspec's
7396 behavior beyond the simple generation of completions.
7397 COMP-OPTION may be one of:
7398
d3a24ed2
CR
7399 `bashdefault'
7400 Perform the rest of the default Bash completions if the
7401 compspec generates no matches.
7402
28ef6c31 7403 `default'
7117c2d2
JA
7404 Use Readline's default filename completion if the
7405 compspec generates no matches.
28ef6c31
JA
7406
7407 `dirnames'
7408 Perform directory name completion if the compspec
7409 generates no matches.
7410
7411 `filenames'
7412 Tell Readline that the compspec generates filenames, so
d3a24ed2 7413 it can perform any filename-specific processing (like
28ef6c31
JA
7414 adding a slash to directory names or suppressing
7415 trailing spaces). This option is intended to be used
7416 with shell functions specified with `-F'.
7417
7117c2d2
JA
7418 `nospace'
7419 Tell Readline not to append a space (the default) to
7420 words completed at the end of the line.
7421
22e63b05
CR
7422 `plusdirs'
7423 After any matches defined by the compspec are generated,
7424 directory name completion is attempted and any matches
7425 are added to the results of the other actions.
7426
7427
bb70624e
JA
7428 `-A ACTION'
7429 The ACTION may be one of the following to generate a list of
7430 possible completions:
7431
7432 `alias'
7433 Alias names. May also be specified as `-a'.
7434
7435 `arrayvar'
7436 Array variable names.
7437
7438 `binding'
7439 Readline key binding names (*note Bindable Readline
28ef6c31 7440 Commands::).
bb70624e
JA
7441
7442 `builtin'
7443 Names of shell builtin commands. May also be specified
7444 as `-b'.
7445
7446 `command'
7447 Command names. May also be specified as `-c'.
7448
7449 `directory'
7450 Directory names. May also be specified as `-d'.
7451
7452 `disabled'
7453 Names of disabled shell builtins.
7454
7455 `enabled'
7456 Names of enabled shell builtins.
7457
7458 `export'
7459 Names of exported shell variables. May also be
7460 specified as `-e'.
7461
7462 `file'
7463 File names. May also be specified as `-f'.
7464
7465 `function'
7466 Names of shell functions.
7467
f73dda09
JA
7468 `group'
7469 Group names. May also be specified as `-g'.
7470
bb70624e
JA
7471 `helptopic'
7472 Help topics as accepted by the `help' builtin (*note
28ef6c31 7473 Bash Builtins::).
bb70624e
JA
7474
7475 `hostname'
7476 Hostnames, as taken from the file specified by the
28ef6c31 7477 `HOSTFILE' shell variable (*note Bash Variables::).
bb70624e
JA
7478
7479 `job'
7480 Job names, if job control is active. May also be
7481 specified as `-j'.
7482
7483 `keyword'
7484 Shell reserved words. May also be specified as `-k'.
7485
7486 `running'
7487 Names of running jobs, if job control is active.
7488
7117c2d2
JA
7489 `service'
7490 Service names. May also be specified as `-s'.
7491
bb70624e
JA
7492 `setopt'
7493 Valid arguments for the `-o' option to the `set' builtin
28ef6c31 7494 (*note The Set Builtin::).
bb70624e
JA
7495
7496 `shopt'
7497 Shell option names as accepted by the `shopt' builtin
28ef6c31 7498 (*note Bash Builtins::).
bb70624e
JA
7499
7500 `signal'
7501 Signal names.
7502
7503 `stopped'
7504 Names of stopped jobs, if job control is active.
7505
7506 `user'
7507 User names. May also be specified as `-u'.
7508
7509 `variable'
7510 Names of all shell variables. May also be specified as
7511 `-v'.
7512
7513 `-G GLOBPAT'
7514 The filename expansion pattern GLOBPAT is expanded to generate
7515 the possible completions.
7516
7517 `-W WORDLIST'
7518 The WORDLIST is split using the characters in the `IFS'
7519 special variable as delimiters, and each resultant word is
7520 expanded. The possible completions are the members of the
7521 resultant list which match the word being completed.
7522
7523 `-C COMMAND'
7524 COMMAND is executed in a subshell environment, and its output
7525 is used as the possible completions.
7526
7527 `-F FUNCTION'
7528 The shell function FUNCTION is executed in the current shell
7529 environment. When it finishes, the possible completions are
7530 retrieved from the value of the `COMPREPLY' array variable.
7531
7532 `-X FILTERPAT'
7533 FILTERPAT is a pattern as used for filename expansion. It is
7534 applied to the list of possible completions generated by the
7535 preceding options and arguments, and each completion matching
7536 FILTERPAT is removed from the list. A leading `!' in
7537 FILTERPAT negates the pattern; in this case, any completion
7538 not matching FILTERPAT is removed.
7539
7540 `-P PREFIX'
7541 PREFIX is added at the beginning of each possible completion
7542 after all other options have been applied.
7543
7544 `-S SUFFIX'
7545 SUFFIX is appended to each possible completion after all
7546 other options have been applied.
7547
7548 The return value is true unless an invalid option is supplied, an
7549 option other than `-p' or `-r' is supplied without a NAME
7550 argument, an attempt is made to remove a completion specification
7551 for a NAME for which no specification exists, or an error occurs
7552 adding a completion specification.
7553
6a8fd0ed
CR
7554`compopt'
7555 `compopt' [-o OPTION] [+o OPTION] [NAME]
7556 Modify completion options for each NAME according to the OPTIONs,
7557 or for the currently-execution completion if no NAMEs are supplied.
7558 If no OPTIONs are given, display the completion options for each
7559 NAME or the current completion. The possible values of OPTION are
7560 those valid for the `complete' builtin described above.
7561
7562 The return value is true unless an invalid option is supplied, an
7563 attempt is made to modify the options for a NAME for which no
7564 completion specification exists, or an output error occurs.
7565
7566
bb70624e 7567\1f
c2a47ea9 7568File: bashref.info, Node: Using History Interactively, Next: Installing Bash, Prev: Command Line Editing, Up: Top
bb70624e 7569
37c41ab1
CR
75709 Using History Interactively
7571*****************************
bb70624e 7572
37c41ab1 7573This chapter describes how to use the GNU History Library
bb70624e
JA
7574interactively, from a user's standpoint. It should be considered a
7575user's guide. For information on using the GNU History Library in
7576other programs, see the GNU Readline Library Manual.
7577
7578* Menu:
7579
7580* Bash History Facilities:: How Bash lets you manipulate your command
7581 history.
7582* Bash History Builtins:: The Bash builtin commands that manipulate
7583 the command history.
7584* History Interaction:: What it feels like using History as a user.
7585
7586\1f
7587File: bashref.info, Node: Bash History Facilities, Next: Bash History Builtins, Up: Using History Interactively
7588
37c41ab1
CR
75899.1 Bash History Facilities
7590===========================
bb70624e 7591
37c41ab1
CR
7592When the `-o history' option to the `set' builtin is enabled (*note The
7593Set Builtin::), the shell provides access to the "command history", the
7594list of commands previously typed. The value of the `HISTSIZE' shell
7595variable is used as the number of commands to save in a history list.
7596The text of the last `$HISTSIZE' commands (default 500) is saved. The
7597shell stores each command in the history list prior to parameter and
7598variable expansion but after history expansion is performed, subject to
7599the values of the shell variables `HISTIGNORE' and `HISTCONTROL'.
bb70624e
JA
7600
7601 When the shell starts up, the history is initialized from the file
7602named by the `HISTFILE' variable (default `~/.bash_history'). The file
7603named by the value of `HISTFILE' is truncated, if necessary, to contain
7604no more than the number of lines specified by the value of the
7605`HISTFILESIZE' variable. When an interactive shell exits, the last
7606`$HISTSIZE' lines are copied from the history list to the file named by
7607`$HISTFILE'. If the `histappend' shell option is set (*note Bash
28ef6c31 7608Builtins::), the lines are appended to the history file, otherwise the
bb70624e
JA
7609history file is overwritten. If `HISTFILE' is unset, or if the history
7610file is unwritable, the history is not saved. After saving the
7611history, the history file is truncated to contain no more than
7612`$HISTFILESIZE' lines. If `HISTFILESIZE' is not set, no truncation is
7613performed.
7614
d3a24ed2 7615 If the `HISTTIMEFORMAT' is set, the time stamp information
d3ad40de
CR
7616associated with each history entry is written to the history file,
7617marked with the history comment character. When the history file is
7618read, lines beginning with the history comment character followed
7619immediately by a digit are interpreted as timestamps for the previous
7620history line.
d3a24ed2 7621
bb70624e
JA
7622 The builtin command `fc' may be used to list or edit and re-execute
7623a portion of the history list. The `history' builtin may be used to
7624display or modify the history list and manipulate the history file.
7625When using command-line editing, search commands are available in each
7626editing mode that provide access to the history list (*note Commands
28ef6c31 7627For History::).
bb70624e
JA
7628
7629 The shell allows control over which commands are saved on the history
7630list. The `HISTCONTROL' and `HISTIGNORE' variables may be set to cause
7631the shell to save only a subset of the commands entered. The `cmdhist'
7632shell option, if enabled, causes the shell to attempt to save each line
7633of a multi-line command in the same history entry, adding semicolons
7634where necessary to preserve syntactic correctness. The `lithist' shell
7635option causes the shell to save the command with embedded newlines
7636instead of semicolons. The `shopt' builtin is used to set these
7637options. *Note Bash Builtins::, for a description of `shopt'.
7638
7639\1f
7640File: bashref.info, Node: Bash History Builtins, Next: History Interaction, Prev: Bash History Facilities, Up: Using History Interactively
7641
37c41ab1
CR
76429.2 Bash History Builtins
7643=========================
bb70624e 7644
37c41ab1 7645Bash provides two builtin commands which manipulate the history list
bb70624e
JA
7646and history file.
7647
7648`fc'
d3ad40de 7649 `fc [-e ENAME] [-lnr] [FIRST] [LAST]'
bb70624e
JA
7650 `fc -s [PAT=REP] [COMMAND]'
7651
7652 Fix Command. In the first form, a range of commands from FIRST to
7653 LAST is selected from the history list. Both FIRST and LAST may
7654 be specified as a string (to locate the most recent command
7655 beginning with that string) or as a number (an index into the
7656 history list, where a negative number is used as an offset from the
7657 current command number). If LAST is not specified it is set to
7658 FIRST. If FIRST is not specified it is set to the previous
7659 command for editing and -16 for listing. If the `-l' flag is
7660 given, the commands are listed on standard output. The `-n' flag
7661 suppresses the command numbers when listing. The `-r' flag
7662 reverses the order of the listing. Otherwise, the editor given by
7663 ENAME is invoked on a file containing those commands. If ENAME is
7664 not given, the value of the following variable expansion is used:
7665 `${FCEDIT:-${EDITOR:-vi}}'. This says to use the value of the
7666 `FCEDIT' variable if set, or the value of the `EDITOR' variable if
7667 that is set, or `vi' if neither is set. When editing is complete,
7668 the edited commands are echoed and executed.
7669
7670 In the second form, COMMAND is re-executed after each instance of
7671 PAT in the selected command is replaced by REP.
7672
7673 A useful alias to use with the `fc' command is `r='fc -s'', so
7674 that typing `r cc' runs the last command beginning with `cc' and
28ef6c31 7675 typing `r' re-executes the last command (*note Aliases::).
bb70624e
JA
7676
7677`history'
7678 history [N]
7679 history -c
7680 history -d OFFSET
7681 history [-anrw] [FILENAME]
7682 history -ps ARG
7683
7684 With no options, display the history list with line numbers.
28ef6c31 7685 Lines prefixed with a `*' have been modified. An argument of N
d3a24ed2
CR
7686 lists only the last N lines. If the shell variable
7687 `HISTTIMEFORMAT' is set and not null, it is used as a format
7688 string for STRFTIME to display the time stamp associated with each
7689 displayed history entry. No intervening blank is printed between
7690 the formatted time stamp and the history line.
7691
7692 Options, if supplied, have the following meanings:
bb70624e
JA
7693
7694 `-c'
7695 Clear the history list. This may be combined with the other
7696 options to replace the history list completely.
7697
7698 `-d OFFSET'
7699 Delete the history entry at position OFFSET. OFFSET should
7700 be specified as it appears when the history is displayed.
7701
7702 `-a'
7703 Append the new history lines (history lines entered since the
7704 beginning of the current Bash session) to the history file.
7705
7706 `-n'
7707 Append the history lines not already read from the history
7708 file to the current history list. These are lines appended
7709 to the history file since the beginning of the current Bash
7710 session.
7711
7712 `-r'
7713 Read the current history file and append its contents to the
7714 history list.
7715
7716 `-w'
7717 Write out the current history to the history file.
7718
7719 `-p'
7720 Perform history substitution on the ARGs and display the
7721 result on the standard output, without storing the results in
7722 the history list.
7723
7724 `-s'
7725 The ARGs are added to the end of the history list as a single
7726 entry.
7727
761783bf 7728
bb70624e
JA
7729 When any of the `-w', `-r', `-a', or `-n' options is used, if
7730 FILENAME is given, then it is used as the history file. If not,
7731 then the value of the `HISTFILE' variable is used.
7732
761783bf 7733
bb70624e
JA
7734\1f
7735File: bashref.info, Node: History Interaction, Prev: Bash History Builtins, Up: Using History Interactively
ccc6cda3 7736
37c41ab1
CR
77379.3 History Expansion
7738=====================
ccc6cda3 7739
37c41ab1
CR
7740The History library provides a history expansion feature that is similar
7741to the history expansion provided by `csh'. This section describes the
7742syntax used to manipulate the history information.
ccc6cda3 7743
bb70624e
JA
7744 History expansions introduce words from the history list into the
7745input stream, making it easy to repeat commands, insert the arguments
7746to a previous command into the current input line, or fix errors in
7747previous commands quickly.
ccc6cda3 7748
bb70624e
JA
7749 History expansion takes place in two parts. The first is to
7750determine which line from the history list should be used during
7751substitution. The second is to select portions of that line for
7752inclusion into the current one. The line selected from the history is
7753called the "event", and the portions of that line that are acted upon
7754are called "words". Various "modifiers" are available to manipulate
7755the selected words. The line is broken into words in the same fashion
7756that Bash does, so that several words surrounded by quotes are
7757considered one word. History expansions are introduced by the
7758appearance of the history expansion character, which is `!' by default.
7759Only `\' and `'' may be used to escape the history expansion character.
7760
7761 Several shell options settable with the `shopt' builtin (*note Bash
28ef6c31 7762Builtins::) may be used to tailor the behavior of history expansion.
bb70624e
JA
7763If the `histverify' shell option is enabled, and Readline is being
7764used, history substitutions are not immediately passed to the shell
7765parser. Instead, the expanded line is reloaded into the Readline
7766editing buffer for further modification. If Readline is being used,
7767and the `histreedit' shell option is enabled, a failed history
7768expansion will be reloaded into the Readline editing buffer for
7769correction. The `-p' option to the `history' builtin command may be
7770used to see what a history expansion will do before using it. The `-s'
7771option to the `history' builtin may be used to add commands to the end
7772of the history list without actually executing them, so that they are
7773available for subsequent recall. This is most useful in conjunction
7774with Readline.
7775
7776 The shell allows control of the various characters used by the
d3ad40de
CR
7777history expansion mechanism with the `histchars' variable, as explained
7778above (*note Bash Variables::). The shell uses the history comment
7779character to mark history timestamps when writing the history file.
bb70624e
JA
7780
7781* Menu:
7782
7783* Event Designators:: How to specify which history line to use.
7784* Word Designators:: Specifying which words are of interest.
7785* Modifiers:: Modifying the results of substitution.
ccc6cda3
JA
7786
7787\1f
bb70624e 7788File: bashref.info, Node: Event Designators, Next: Word Designators, Up: History Interaction
ccc6cda3 7789
37c41ab1
CR
77909.3.1 Event Designators
7791-----------------------
ccc6cda3 7792
37c41ab1
CR
7793An event designator is a reference to a command line entry in the
7794history list.
ccc6cda3 7795
bb70624e
JA
7796`!'
7797 Start a history substitution, except when followed by a space, tab,
d3a24ed2
CR
7798 the end of the line, `=' or `(' (when the `extglob' shell option
7799 is enabled using the `shopt' builtin).
ccc6cda3 7800
bb70624e
JA
7801`!N'
7802 Refer to command line N.
ccc6cda3 7803
bb70624e
JA
7804`!-N'
7805 Refer to the command N lines back.
ccc6cda3 7806
bb70624e
JA
7807`!!'
7808 Refer to the previous command. This is a synonym for `!-1'.
ccc6cda3 7809
bb70624e
JA
7810`!STRING'
7811 Refer to the most recent command starting with STRING.
ccc6cda3 7812
bb70624e
JA
7813`!?STRING[?]'
7814 Refer to the most recent command containing STRING. The trailing
7815 `?' may be omitted if the STRING is followed immediately by a
7816 newline.
ccc6cda3 7817
bb70624e
JA
7818`^STRING1^STRING2^'
7819 Quick Substitution. Repeat the last command, replacing STRING1
7820 with STRING2. Equivalent to `!!:s/STRING1/STRING2/'.
7821
7822`!#'
7823 The entire command line typed so far.
ccc6cda3 7824
761783bf 7825
ccc6cda3 7826\1f
bb70624e 7827File: bashref.info, Node: Word Designators, Next: Modifiers, Prev: Event Designators, Up: History Interaction
ccc6cda3 7828
37c41ab1
CR
78299.3.2 Word Designators
7830----------------------
ccc6cda3 7831
37c41ab1 7832Word designators are used to select desired words from the event. A
bb70624e
JA
7833`:' separates the event specification from the word designator. It may
7834be omitted if the word designator begins with a `^', `$', `*', `-', or
7835`%'. Words are numbered from the beginning of the line, with the first
7836word being denoted by 0 (zero). Words are inserted into the current
7837line separated by single spaces.
ccc6cda3 7838
bb70624e 7839 For example,
ccc6cda3 7840
bb70624e
JA
7841`!!'
7842 designates the preceding command. When you type this, the
7843 preceding command is repeated in toto.
ccc6cda3 7844
bb70624e
JA
7845`!!:$'
7846 designates the last argument of the preceding command. This may be
7847 shortened to `!$'.
ccc6cda3 7848
bb70624e
JA
7849`!fi:2'
7850 designates the second argument of the most recent command starting
7851 with the letters `fi'.
ccc6cda3 7852
bb70624e 7853 Here are the word designators:
ccc6cda3 7854
bb70624e
JA
7855`0 (zero)'
7856 The `0'th word. For many applications, this is the command word.
ccc6cda3 7857
bb70624e
JA
7858`N'
7859 The Nth word.
ccc6cda3 7860
bb70624e
JA
7861`^'
7862 The first argument; that is, word 1.
ccc6cda3 7863
bb70624e
JA
7864`$'
7865 The last argument.
ccc6cda3 7866
bb70624e
JA
7867`%'
7868 The word matched by the most recent `?STRING?' search.
ccc6cda3 7869
bb70624e
JA
7870`X-Y'
7871 A range of words; `-Y' abbreviates `0-Y'.
ccc6cda3 7872
bb70624e
JA
7873`*'
7874 All of the words, except the `0'th. This is a synonym for `1-$'.
7875 It is not an error to use `*' if there is just one word in the
7876 event; the empty string is returned in that case.
7877
7878`X*'
7879 Abbreviates `X-$'
7880
7881`X-'
7882 Abbreviates `X-$' like `X*', but omits the last word.
7883
761783bf 7884
bb70624e
JA
7885 If a word designator is supplied without an event specification, the
7886previous command is used as the event.
ccc6cda3
JA
7887
7888\1f
bb70624e 7889File: bashref.info, Node: Modifiers, Prev: Word Designators, Up: History Interaction
ccc6cda3 7890
37c41ab1
CR
78919.3.3 Modifiers
7892---------------
ccc6cda3 7893
37c41ab1 7894After the optional word designator, you can add a sequence of one or
bb70624e 7895more of the following modifiers, each preceded by a `:'.
ccc6cda3 7896
bb70624e
JA
7897`h'
7898 Remove a trailing pathname component, leaving only the head.
ccc6cda3 7899
bb70624e 7900`t'
d3ad40de 7901 Remove all leading pathname components, leaving the tail.
bb70624e
JA
7902
7903`r'
7904 Remove a trailing suffix of the form `.SUFFIX', leaving the
7905 basename.
7906
7907`e'
7908 Remove all but the trailing suffix.
7909
7910`p'
7911 Print the new command but do not execute it.
7912
7913`q'
7914 Quote the substituted words, escaping further substitutions.
7915
7916`x'
7917 Quote the substituted words as with `q', but break into words at
7918 spaces, tabs, and newlines.
7919
7920`s/OLD/NEW/'
7921 Substitute NEW for the first occurrence of OLD in the event line.
7922 Any delimiter may be used in place of `/'. The delimiter may be
7923 quoted in OLD and NEW with a single backslash. If `&' appears in
7924 NEW, it is replaced by OLD. A single backslash will quote the
7925 `&'. The final delimiter is optional if it is the last character
7926 on the input line.
7927
7928`&'
7929 Repeat the previous substitution.
7930
7931`g'
d3a24ed2 7932`a'
bb70624e
JA
7933 Cause changes to be applied over the entire event line. Used in
7934 conjunction with `s', as in `gs/OLD/NEW/', or with `&'.
7935
d3a24ed2
CR
7936`G'
7937 Apply the following `s' modifier once to each word in the event.
7938
761783bf 7939
bb70624e 7940\1f
c2a47ea9 7941File: bashref.info, Node: Installing Bash, Next: Reporting Bugs, Prev: Using History Interactively, Up: Top
bb70624e 7942
37c41ab1
CR
794310 Installing Bash
7944******************
b72432fd 7945
37c41ab1 7946This chapter provides basic instructions for installing Bash on the
bb70624e
JA
7947various supported platforms. The distribution supports the GNU
7948operating systems, nearly every version of Unix, and several non-Unix
7949systems such as BeOS and Interix. Other independent ports exist for
d3a24ed2 7950MS-DOS, OS/2, and Windows platforms.
ccc6cda3 7951
bb70624e 7952* Menu:
ccc6cda3 7953
bb70624e 7954* Basic Installation:: Installation instructions.
bb70624e
JA
7955* Compilers and Options:: How to set special options for various
7956 systems.
bb70624e
JA
7957* Compiling For Multiple Architectures:: How to compile Bash for more
7958 than one kind of system from
7959 the same source tree.
bb70624e 7960* Installation Names:: How to set the various paths used by the installation.
bb70624e 7961* Specifying the System Type:: How to configure Bash for a particular system.
bb70624e
JA
7962* Sharing Defaults:: How to share default configuration values among GNU
7963 programs.
bb70624e 7964* Operation Controls:: Options recognized by the configuration program.
bb70624e
JA
7965* Optional Features:: How to enable and disable optional features when
7966 building Bash.
ccc6cda3 7967
bb70624e
JA
7968\1f
7969File: bashref.info, Node: Basic Installation, Next: Compilers and Options, Up: Installing Bash
ccc6cda3 7970
37c41ab1
CR
797110.1 Basic Installation
7972=======================
ccc6cda3 7973
37c41ab1 7974These are installation instructions for Bash.
ccc6cda3 7975
bb70624e 7976 The simplest way to compile Bash is:
ccc6cda3 7977
bb70624e
JA
7978 1. `cd' to the directory containing the source code and type
7979 `./configure' to configure Bash for your system. If you're using
7980 `csh' on an old version of System V, you might need to type `sh
7981 ./configure' instead to prevent `csh' from trying to execute
7982 `configure' itself.
ccc6cda3 7983
bb70624e
JA
7984 Running `configure' takes some time. While running, it prints
7985 messages telling which features it is checking for.
ccc6cda3 7986
bb70624e
JA
7987 2. Type `make' to compile Bash and build the `bashbug' bug reporting
7988 script.
ccc6cda3 7989
bb70624e 7990 3. Optionally, type `make tests' to run the Bash test suite.
ccc6cda3 7991
bb70624e
JA
7992 4. Type `make install' to install `bash' and `bashbug'. This will
7993 also install the manual pages and Info file.
ccc6cda3 7994
ccc6cda3 7995
bb70624e
JA
7996 The `configure' shell script attempts to guess correct values for
7997various system-dependent variables used during compilation. It uses
7998those values to create a `Makefile' in each directory of the package
7999(the top directory, the `builtins', `doc', and `support' directories,
8000each directory under `lib', and several others). It also creates a
8001`config.h' file containing system-dependent definitions. Finally, it
8002creates a shell script named `config.status' that you can run in the
8003future to recreate the current configuration, a file `config.cache'
8004that saves the results of its tests to speed up reconfiguring, and a
8005file `config.log' containing compiler output (useful mainly for
8006debugging `configure'). If at some point `config.cache' contains
8007results you don't want to keep, you may remove or edit it.
ccc6cda3 8008
bb70624e
JA
8009 To find out more about the options and arguments that the
8010`configure' script understands, type
ccc6cda3 8011
bb70624e 8012 bash-2.04$ ./configure --help
ccc6cda3 8013
bb70624e 8014at the Bash prompt in your Bash source directory.
ccc6cda3 8015
bb70624e
JA
8016 If you need to do unusual things to compile Bash, please try to
8017figure out how `configure' could check whether or not to do them, and
8018mail diffs or instructions to <bash-maintainers@gnu.org> so they can be
8019considered for the next release.
ccc6cda3 8020
bb70624e
JA
8021 The file `configure.in' is used to create `configure' by a program
8022called Autoconf. You only need `configure.in' if you want to change it
8023or regenerate `configure' using a newer version of Autoconf. If you do
f73dda09 8024this, make sure you are using Autoconf version 2.50 or newer.
ccc6cda3 8025
bb70624e
JA
8026 You can remove the program binaries and object files from the source
8027code directory by typing `make clean'. To also remove the files that
8028`configure' created (so you can compile Bash for a different kind of
8029computer), type `make distclean'.
ccc6cda3 8030
bb70624e
JA
8031\1f
8032File: bashref.info, Node: Compilers and Options, Next: Compiling For Multiple Architectures, Prev: Basic Installation, Up: Installing Bash
ccc6cda3 8033
37c41ab1
CR
803410.2 Compilers and Options
8035==========================
ccc6cda3 8036
37c41ab1 8037Some systems require unusual options for compilation or linking that
bb70624e
JA
8038the `configure' script does not know about. You can give `configure'
8039initial values for variables by setting them in the environment. Using
8040a Bourne-compatible shell, you can do that on the command line like
8041this:
ccc6cda3 8042
bb70624e 8043 CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure
ccc6cda3 8044
bb70624e 8045 On systems that have the `env' program, you can do it like this:
cce855bc 8046
bb70624e 8047 env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure
b72432fd 8048
bb70624e 8049 The configuration process uses GCC to build Bash if it is available.
ccc6cda3 8050
bb70624e
JA
8051\1f
8052File: bashref.info, Node: Compiling For Multiple Architectures, Next: Installation Names, Prev: Compilers and Options, Up: Installing Bash
ccc6cda3 8053
37c41ab1
CR
805410.3 Compiling For Multiple Architectures
8055=========================================
ccc6cda3 8056
37c41ab1 8057You can compile Bash for more than one kind of computer at the same
bb70624e
JA
8058time, by placing the object files for each architecture in their own
8059directory. To do this, you must use a version of `make' that supports
8060the `VPATH' variable, such as GNU `make'. `cd' to the directory where
8061you want the object files and executables to go and run the `configure'
8062script from the source directory. You may need to supply the
8063`--srcdir=PATH' argument to tell `configure' where the source files
8064are. `configure' automatically checks for the source code in the
8065directory that `configure' is in and in `..'.
ccc6cda3 8066
bb70624e
JA
8067 If you have to use a `make' that does not supports the `VPATH'
8068variable, you can compile Bash for one architecture at a time in the
8069source code directory. After you have installed Bash for one
8070architecture, use `make distclean' before reconfiguring for another
8071architecture.
ccc6cda3 8072
bb70624e
JA
8073 Alternatively, if your system supports symbolic links, you can use
8074the `support/mkclone' script to create a build tree which has symbolic
8075links back to each file in the source directory. Here's an example
8076that creates a build directory in the current directory from a source
8077directory `/usr/gnu/src/bash-2.0':
ccc6cda3 8078
bb70624e 8079 bash /usr/gnu/src/bash-2.0/support/mkclone -s /usr/gnu/src/bash-2.0 .
ccc6cda3 8080
bb70624e
JA
8081The `mkclone' script requires Bash, so you must have already built Bash
8082for at least one architecture before you can create build directories
8083for other architectures.
ccc6cda3 8084
bb70624e
JA
8085\1f
8086File: bashref.info, Node: Installation Names, Next: Specifying the System Type, Prev: Compiling For Multiple Architectures, Up: Installing Bash
ccc6cda3 8087
37c41ab1
CR
808810.4 Installation Names
8089=======================
ccc6cda3 8090
37c41ab1 8091By default, `make install' will install into `/usr/local/bin',
bb70624e 8092`/usr/local/man', etc. You can specify an installation prefix other
f73dda09
JA
8093than `/usr/local' by giving `configure' the option `--prefix=PATH', or
8094by specifying a value for the `DESTDIR' `make' variable when running
8095`make install'.
ccc6cda3 8096
bb70624e
JA
8097 You can specify separate installation prefixes for
8098architecture-specific files and architecture-independent files. If you
8099give `configure' the option `--exec-prefix=PATH', `make install' will
8100use PATH as the prefix for installing programs and libraries.
8101Documentation and other data files will still use the regular prefix.
ccc6cda3
JA
8102
8103\1f
bb70624e 8104File: bashref.info, Node: Specifying the System Type, Next: Sharing Defaults, Prev: Installation Names, Up: Installing Bash
ccc6cda3 8105
37c41ab1
CR
810610.5 Specifying the System Type
8107===============================
ccc6cda3 8108
37c41ab1 8109There may be some features `configure' can not figure out
f73dda09 8110automatically, but need to determine by the type of host Bash will run
bb70624e
JA
8111on. Usually `configure' can figure that out, but if it prints a
8112message saying it can not guess the host type, give it the
8113`--host=TYPE' option. `TYPE' can either be a short name for the system
8114type, such as `sun4', or a canonical name with three fields:
f73dda09 8115`CPU-COMPANY-SYSTEM' (e.g., `i386-unknown-freebsd4.2').
ccc6cda3 8116
bb70624e
JA
8117 See the file `support/config.sub' for the possible values of each
8118field.
ccc6cda3 8119
bb70624e
JA
8120\1f
8121File: bashref.info, Node: Sharing Defaults, Next: Operation Controls, Prev: Specifying the System Type, Up: Installing Bash
8122
37c41ab1
CR
812310.6 Sharing Defaults
8124=====================
bb70624e 8125
37c41ab1
CR
8126If you want to set default values for `configure' scripts to share, you
8127can create a site shell script called `config.site' that gives default
8128values for variables like `CC', `cache_file', and `prefix'. `configure'
8129looks for `PREFIX/share/config.site' if it exists, then
bb70624e
JA
8130`PREFIX/etc/config.site' if it exists. Or, you can set the
8131`CONFIG_SITE' environment variable to the location of the site script.
8132A warning: the Bash `configure' looks for a site script, but not all
8133`configure' scripts do.
ccc6cda3
JA
8134
8135\1f
bb70624e 8136File: bashref.info, Node: Operation Controls, Next: Optional Features, Prev: Sharing Defaults, Up: Installing Bash
ccc6cda3 8137
37c41ab1
CR
813810.7 Operation Controls
8139=======================
ccc6cda3 8140
37c41ab1 8141`configure' recognizes the following options to control how it operates.
ccc6cda3 8142
bb70624e
JA
8143`--cache-file=FILE'
8144 Use and save the results of the tests in FILE instead of
8145 `./config.cache'. Set FILE to `/dev/null' to disable caching, for
8146 debugging `configure'.
ccc6cda3 8147
bb70624e
JA
8148`--help'
8149 Print a summary of the options to `configure', and exit.
ccc6cda3 8150
bb70624e
JA
8151`--quiet'
8152`--silent'
8153`-q'
8154 Do not print messages saying which checks are being made.
ccc6cda3 8155
bb70624e
JA
8156`--srcdir=DIR'
8157 Look for the Bash source code in directory DIR. Usually
8158 `configure' can determine that directory automatically.
ccc6cda3 8159
bb70624e
JA
8160`--version'
8161 Print the version of Autoconf used to generate the `configure'
8162 script, and exit.
ccc6cda3 8163
bb70624e
JA
8164 `configure' also accepts some other, not widely used, boilerplate
8165options. `configure --help' prints the complete list.
ccc6cda3 8166
bb70624e
JA
8167\1f
8168File: bashref.info, Node: Optional Features, Prev: Operation Controls, Up: Installing Bash
ccc6cda3 8169
37c41ab1
CR
817010.8 Optional Features
8171======================
ccc6cda3 8172
37c41ab1
CR
8173The Bash `configure' has a number of `--enable-FEATURE' options, where
8174FEATURE indicates an optional part of Bash. There are also several
8175`--with-PACKAGE' options, where PACKAGE is something like `bash-malloc'
8176or `purify'. To turn off the default use of a package, use
8177`--without-PACKAGE'. To configure Bash without a feature that is
bb70624e 8178enabled by default, use `--disable-FEATURE'.
ccc6cda3 8179
bb70624e
JA
8180 Here is a complete list of the `--enable-' and `--with-' options
8181that the Bash `configure' recognizes.
ccc6cda3 8182
bb70624e
JA
8183`--with-afs'
8184 Define if you are using the Andrew File System from Transarc.
ccc6cda3 8185
bb70624e 8186`--with-bash-malloc'
1c72c0cd
CR
8187 Use the Bash version of `malloc' in the directory `lib/malloc'.
8188 This is not the same `malloc' that appears in GNU libc, but an
8189 older version originally derived from the 4.2 BSD `malloc'. This
8190 `malloc' is very fast, but wastes some space on each allocation.
8191 This option is enabled by default. The `NOTES' file contains a
8192 list of systems for which this should be turned off, and
8193 `configure' disables this option automatically for a number of
8194 systems.
ccc6cda3 8195
bb70624e
JA
8196`--with-curses'
8197 Use the curses library instead of the termcap library. This should
8198 be supplied if your system has an inadequate or incomplete termcap
8199 database.
ccc6cda3 8200
bb70624e
JA
8201`--with-gnu-malloc'
8202 A synonym for `--with-bash-malloc'.
ccc6cda3 8203
f73dda09 8204`--with-installed-readline[=PREFIX]'
bb70624e
JA
8205 Define this to make Bash link with a locally-installed version of
8206 Readline rather than the version in `lib/readline'. This works
01ed5ba4 8207 only with Readline 5.0 and later versions. If PREFIX is `yes' or
f73dda09
JA
8208 not supplied, `configure' uses the values of the make variables
8209 `includedir' and `libdir', which are subdirectories of `prefix' by
8210 default, to find the installed version of Readline if it is not in
8211 the standard system include and library directories. If PREFIX is
8212 `no', Bash links with the version in `lib/readline'. If PREFIX is
8213 set to any other value, `configure' treats it as a directory
8214 pathname and looks for the installed version of Readline in
8215 subdirectories of that directory (include files in
8216 PREFIX/`include' and the library in PREFIX/`lib').
ccc6cda3 8217
bb70624e
JA
8218`--with-purify'
8219 Define this to use the Purify memory allocation checker from
8220 Rational Software.
ccc6cda3 8221
bb70624e
JA
8222`--enable-minimal-config'
8223 This produces a shell with minimal features, close to the
8224 historical Bourne shell.
ccc6cda3 8225
bb70624e
JA
8226 There are several `--enable-' options that alter how Bash is
8227compiled and linked, rather than changing run-time features.
ccc6cda3 8228
f73dda09
JA
8229`--enable-largefile'
8230 Enable support for large files
8231 (http://www.sas.com/standards/large_file/x_open.20Mar96.html) if
8232 the operating system requires special compiler options to build
7117c2d2
JA
8233 programs which can access large files. This is enabled by
8234 default, if the operating system provides large file support.
f73dda09 8235
bb70624e
JA
8236`--enable-profiling'
8237 This builds a Bash binary that produces profiling information to be
8238 processed by `gprof' each time it is executed.
cce855bc 8239
bb70624e
JA
8240`--enable-static-link'
8241 This causes Bash to be linked statically, if `gcc' is being used.
8242 This could be used to build a version to use as root's shell.
d166f048 8243
bb70624e
JA
8244 The `minimal-config' option can be used to disable all of the
8245following options, but it is processed first, so individual options may
8246be enabled using `enable-FEATURE'.
d166f048 8247
bb70624e
JA
8248 All of the following options except for `disabled-builtins' and
8249`xpg-echo-default' are enabled by default, unless the operating system
8250does not provide the necessary support.
ccc6cda3 8251
bb70624e
JA
8252`--enable-alias'
8253 Allow alias expansion and include the `alias' and `unalias'
28ef6c31 8254 builtins (*note Aliases::).
ccc6cda3 8255
bb70624e
JA
8256`--enable-arith-for-command'
8257 Include support for the alternate form of the `for' command that
8258 behaves like the C language `for' statement (*note Looping
28ef6c31 8259 Constructs::).
ccc6cda3 8260
bb70624e
JA
8261`--enable-array-variables'
8262 Include support for one-dimensional array shell variables (*note
28ef6c31 8263 Arrays::).
ccc6cda3 8264
bb70624e
JA
8265`--enable-bang-history'
8266 Include support for `csh'-like history substitution (*note History
28ef6c31 8267 Interaction::).
ccc6cda3 8268
bb70624e
JA
8269`--enable-brace-expansion'
8270 Include `csh'-like brace expansion ( `b{a,b}c' ==> `bac bbc' ).
6a8fd0ed 8271 See *note Brace Expansion::, for a complete description.
ccc6cda3 8272
bb70624e
JA
8273`--enable-command-timing'
8274 Include support for recognizing `time' as a reserved word and for
8275 displaying timing statistics for the pipeline following `time'
28ef6c31 8276 (*note Pipelines::). This allows pipelines as well as shell
bb70624e 8277 builtins and functions to be timed.
ccc6cda3 8278
bb70624e 8279`--enable-cond-command'
5e13499c
CR
8280 Include support for the `[[' conditional command. (*note
8281 Conditional Constructs::).
8282
8283`--enable-cond-regexp'
8284 Include support for matching POSIX regular expressions using the
8285 `=~' binary operator in the `[[' conditional command. (*note
28ef6c31 8286 Conditional Constructs::).
ccc6cda3 8287
01ed5ba4
CR
8288`--enable-debugger'
8289 Include support for the bash debugger (distributed separately).
8290
bb70624e
JA
8291`--enable-directory-stack'
8292 Include support for a `csh'-like directory stack and the `pushd',
28ef6c31 8293 `popd', and `dirs' builtins (*note The Directory Stack::).
ccc6cda3 8294
bb70624e
JA
8295`--enable-disabled-builtins'
8296 Allow builtin commands to be invoked via `builtin xxx' even after
6a8fd0ed 8297 `xxx' has been disabled using `enable -n xxx'. See *note Bash
bb70624e
JA
8298 Builtins::, for details of the `builtin' and `enable' builtin
8299 commands.
ccc6cda3 8300
bb70624e
JA
8301`--enable-dparen-arithmetic'
8302 Include support for the `((...))' command (*note Conditional
28ef6c31 8303 Constructs::).
ccc6cda3 8304
bb70624e
JA
8305`--enable-extended-glob'
8306 Include support for the extended pattern matching features
6a8fd0ed 8307 described above under *note Pattern Matching::.
ccc6cda3 8308
bb70624e
JA
8309`--enable-help-builtin'
8310 Include the `help' builtin, which displays help on shell builtins
28ef6c31 8311 and variables (*note Bash Builtins::).
ccc6cda3 8312
bb70624e
JA
8313`--enable-history'
8314 Include command history and the `fc' and `history' builtin
28ef6c31 8315 commands (*note Bash History Facilities::).
ccc6cda3 8316
bb70624e 8317`--enable-job-control'
28ef6c31 8318 This enables the job control features (*note Job Control::), if
bb70624e 8319 the operating system supports them.
ccc6cda3 8320
d3a24ed2
CR
8321`--enable-multibyte'
8322 This enables support for multibyte characters if the operating
8323 system provides the necessary support.
8324
bb70624e
JA
8325`--enable-net-redirections'
8326 This enables the special handling of filenames of the form
8327 `/dev/tcp/HOST/PORT' and `/dev/udp/HOST/PORT' when used in
28ef6c31 8328 redirections (*note Redirections::).
ccc6cda3 8329
bb70624e 8330`--enable-process-substitution'
28ef6c31
JA
8331 This enables process substitution (*note Process Substitution::) if
8332 the operating system provides the necessary support.
ccc6cda3 8333
01ed5ba4
CR
8334`--enable-progcomp'
8335 Enable the programmable completion facilities (*note Programmable
8336 Completion::). If Readline is not enabled, this option has no
8337 effect.
8338
bb70624e
JA
8339`--enable-prompt-string-decoding'
8340 Turn on the interpretation of a number of backslash-escaped
8341 characters in the `$PS1', `$PS2', `$PS3', and `$PS4' prompt
6a8fd0ed 8342 strings. See *note Printing a Prompt::, for a complete list of
bb70624e 8343 prompt string escape sequences.
ccc6cda3 8344
bb70624e
JA
8345`--enable-readline'
8346 Include support for command-line editing and history with the Bash
28ef6c31 8347 version of the Readline library (*note Command Line Editing::).
ccc6cda3 8348
bb70624e
JA
8349`--enable-restricted'
8350 Include support for a "restricted shell". If this is enabled,
6a8fd0ed 8351 Bash, when called as `rbash', enters a restricted mode. See *note
bb70624e 8352 The Restricted Shell::, for a description of restricted mode.
ccc6cda3 8353
bb70624e
JA
8354`--enable-select'
8355 Include the `select' builtin, which allows the generation of simple
28ef6c31 8356 menus (*note Conditional Constructs::).
ccc6cda3 8357
01ed5ba4
CR
8358`--enable-separate-helpfiles'
8359 Use external files for the documentation displayed by the `help'
8360 builtin instead of storing the text internally.
8361
8362`--enable-single-help-strings'
8363 Store the text displayed by the `help' builtin as a single string
8364 for each help topic. This aids in translating the text to
8365 different languages. You may need to disable this if your
8366 compiler cannot handle very long string literals.
8367
1c72c0cd
CR
8368`--enable-strict-posix-default'
8369 Make Bash POSIX-conformant by default (*note Bash POSIX Mode::).
8370
bb70624e
JA
8371`--enable-usg-echo-default'
8372 A synonym for `--enable-xpg-echo-default'.
ccc6cda3 8373
bb70624e
JA
8374`--enable-xpg-echo-default'
8375 Make the `echo' builtin expand backslash-escaped characters by
8376 default, without requiring the `-e' option. This sets the default
8377 value of the `xpg_echo' shell option to `on', which makes the Bash
8378 `echo' behave more like the version specified in the Single Unix
01ed5ba4 8379 Specification, version 3. *Note Bash Builtins::, for a
bb70624e 8380 description of the escape sequences that `echo' recognizes.
ccc6cda3 8381
761783bf 8382
bb70624e
JA
8383 The file `config-top.h' contains C Preprocessor `#define' statements
8384for options which are not settable from `configure'. Some of these are
8385not meant to be changed; beware of the consequences if you do. Read
8386the comments associated with each definition for more information about
8387its effect.
ccc6cda3 8388
bb70624e
JA
8389\1f
8390File: bashref.info, Node: Reporting Bugs, Next: Major Differences From The Bourne Shell, Prev: Installing Bash, Up: Top
d166f048 8391
37c41ab1
CR
8392Appendix A Reporting Bugs
8393*************************
ccc6cda3 8394
37c41ab1 8395Please report all bugs you find in Bash. But first, you should make
bb70624e 8396sure that it really is a bug, and that it appears in the latest version
d3a24ed2
CR
8397of Bash. The latest version of Bash is always available for FTP from
8398`ftp://ftp.gnu.org/pub/bash/'.
ccc6cda3 8399
bb70624e
JA
8400 Once you have determined that a bug actually exists, use the
8401`bashbug' command to submit a bug report. If you have a fix, you are
8402encouraged to mail that as well! Suggestions and `philosophical' bug
8403reports may be mailed to <bug-bash@gnu.org> or posted to the Usenet
8404newsgroup `gnu.bash.bug'.
ccc6cda3 8405
bb70624e
JA
8406 All bug reports should include:
8407 * The version number of Bash.
ccc6cda3 8408
bb70624e 8409 * The hardware and operating system.
ccc6cda3 8410
bb70624e 8411 * The compiler used to compile Bash.
ccc6cda3 8412
bb70624e 8413 * A description of the bug behaviour.
ccc6cda3 8414
bb70624e
JA
8415 * A short script or `recipe' which exercises the bug and may be used
8416 to reproduce it.
ccc6cda3 8417
bb70624e
JA
8418`bashbug' inserts the first three items automatically into the template
8419it provides for filing a bug report.
8420
8421 Please send all reports concerning this manual to <chet@po.CWRU.Edu>.
ccc6cda3
JA
8422
8423\1f
c2a47ea9 8424File: bashref.info, Node: Major Differences From The Bourne Shell, Next: GNU Free Documentation License, Prev: Reporting Bugs, Up: Top
ccc6cda3 8425
37c41ab1
CR
8426Appendix B Major Differences From The Bourne Shell
8427**************************************************
ccc6cda3 8428
37c41ab1 8429Bash implements essentially the same grammar, parameter and variable
bb70624e 8430expansion, redirection, and quoting as the Bourne Shell. Bash uses the
ac18b312
CR
8431POSIX standard as the specification of how these features are to be
8432implemented. There are some differences between the traditional Bourne
8433shell and Bash; this section quickly details the differences of
bb70624e
JA
8434significance. A number of these differences are explained in greater
8435depth in previous sections. This section uses the version of `sh'
1c72c0cd
CR
8436included in SVR4.2 (the last version of the historical Bourne shell) as
8437the baseline reference.
ccc6cda3 8438
bb70624e 8439 * Bash is POSIX-conformant, even where the POSIX specification
28ef6c31 8440 differs from traditional `sh' behavior (*note Bash POSIX Mode::).
ccc6cda3 8441
bb70624e 8442 * Bash has multi-character invocation options (*note Invoking
28ef6c31 8443 Bash::).
ccc6cda3 8444
28ef6c31 8445 * Bash has command-line editing (*note Command Line Editing::) and
bb70624e 8446 the `bind' builtin.
ccc6cda3 8447
bb70624e 8448 * Bash provides a programmable word completion mechanism (*note
6a8fd0ed
CR
8449 Programmable Completion::), and builtin commands `complete',
8450 `compgen', and `compopt', to manipulate it.
ccc6cda3 8451
28ef6c31 8452 * Bash has command history (*note Bash History Facilities::) and the
5e13499c
CR
8453 `history' and `fc' builtins to manipulate it. The Bash history
8454 list maintains timestamp information and uses the value of the
8455 `HISTTIMEFORMAT' variable to display it.
ccc6cda3 8456
bb70624e 8457 * Bash implements `csh'-like history expansion (*note History
28ef6c31 8458 Interaction::).
ccc6cda3 8459
28ef6c31 8460 * Bash has one-dimensional array variables (*note Arrays::), and the
bb70624e
JA
8461 appropriate variable expansions and assignment syntax to use them.
8462 Several of the Bash builtins take options to act on arrays. Bash
8463 provides a number of built-in array variables.
ccc6cda3 8464
bb70624e
JA
8465 * The `$'...'' quoting syntax, which expands ANSI-C
8466 backslash-escaped characters in the text between the single quotes,
28ef6c31 8467 is supported (*note ANSI-C Quoting::).
ccc6cda3 8468
bb70624e
JA
8469 * Bash supports the `$"..."' quoting syntax to do locale-specific
8470 translation of the characters between the double quotes. The
8471 `-D', `--dump-strings', and `--dump-po-strings' invocation options
8472 list the translatable strings found in a script (*note Locale
28ef6c31 8473 Translation::).
ccc6cda3 8474
bb70624e 8475 * Bash implements the `!' keyword to negate the return value of a
28ef6c31 8476 pipeline (*note Pipelines::). Very useful when an `if' statement
1c72c0cd
CR
8477 needs to act only if a test fails. The Bash `-o pipefail' option
8478 to `set' will cause a pipeline to return a failure status if any
8479 command fails.
ccc6cda3 8480
bb70624e 8481 * Bash has the `time' reserved word and command timing (*note
28ef6c31 8482 Pipelines::). The display of the timing statistics may be
bb70624e 8483 controlled with the `TIMEFORMAT' variable.
ccc6cda3 8484
bb70624e
JA
8485 * Bash implements the `for (( EXPR1 ; EXPR2 ; EXPR3 ))' arithmetic
8486 for command, similar to the C language (*note Looping
28ef6c31 8487 Constructs::).
ccc6cda3 8488
bb70624e 8489 * Bash includes the `select' compound command, which allows the
28ef6c31 8490 generation of simple menus (*note Conditional Constructs::).
ccc6cda3 8491
bb70624e 8492 * Bash includes the `[[' compound command, which makes conditional
1c72c0cd
CR
8493 testing part of the shell grammar (*note Conditional
8494 Constructs::), including optional regular expression matching.
8495
8496 * Bash provides optional case-insensitive matching for the `case' and
8497 `[[' constructs.
ccc6cda3 8498
28ef6c31
JA
8499 * Bash includes brace expansion (*note Brace Expansion::) and tilde
8500 expansion (*note Tilde Expansion::).
ccc6cda3 8501
bb70624e 8502 * Bash implements command aliases and the `alias' and `unalias'
28ef6c31 8503 builtins (*note Aliases::).
ccc6cda3 8504
bb70624e 8505 * Bash provides shell arithmetic, the `((' compound command (*note
28ef6c31
JA
8506 Conditional Constructs::), and arithmetic expansion (*note Shell
8507 Arithmetic::).
ccc6cda3 8508
bb70624e
JA
8509 * Variables present in the shell's initial environment are
8510 automatically exported to child processes. The Bourne shell does
8511 not normally do this unless the variables are explicitly marked
8512 using the `export' command.
ccc6cda3 8513
1c72c0cd
CR
8514 * Bash supports the `+=' assignment operator, which appends to the
8515 value of the variable named on the left hand side.
8516
bb70624e
JA
8517 * Bash includes the POSIX pattern removal `%', `#', `%%' and `##'
8518 expansions to remove leading or trailing substrings from variable
28ef6c31 8519 values (*note Shell Parameter Expansion::).
ccc6cda3 8520
bb70624e 8521 * The expansion `${#xx}', which returns the length of `${xx}', is
28ef6c31 8522 supported (*note Shell Parameter Expansion::).
ccc6cda3 8523
bb70624e
JA
8524 * The expansion `${var:'OFFSET`[:'LENGTH`]}', which expands to the
8525 substring of `var''s value of length LENGTH, beginning at OFFSET,
28ef6c31 8526 is present (*note Shell Parameter Expansion::).
ccc6cda3 8527
bb70624e
JA
8528 * The expansion `${var/[/]'PATTERN`[/'REPLACEMENT`]}', which matches
8529 PATTERN and replaces it with REPLACEMENT in the value of `var', is
28ef6c31 8530 available (*note Shell Parameter Expansion::).
ccc6cda3 8531
bb70624e
JA
8532 * The expansion `${!PREFIX}*' expansion, which expands to the names
8533 of all shell variables whose names begin with PREFIX, is available
28ef6c31 8534 (*note Shell Parameter Expansion::).
ccc6cda3 8535
bb70624e 8536 * Bash has INDIRECT variable expansion using `${!word}' (*note Shell
28ef6c31 8537 Parameter Expansion::).
ccc6cda3 8538
bb70624e 8539 * Bash can expand positional parameters beyond `$9' using `${NUM}'.
ccc6cda3 8540
bb70624e 8541 * The POSIX `$()' form of command substitution is implemented (*note
28ef6c31 8542 Command Substitution::), and preferred to the Bourne shell's ```'
bb70624e 8543 (which is also implemented for backwards compatibility).
ccc6cda3 8544
28ef6c31 8545 * Bash has process substitution (*note Process Substitution::).
ccc6cda3 8546
bb70624e
JA
8547 * Bash automatically assigns variables that provide information
8548 about the current user (`UID', `EUID', and `GROUPS'), the current
8549 host (`HOSTTYPE', `OSTYPE', `MACHTYPE', and `HOSTNAME'), and the
8550 instance of Bash that is running (`BASH', `BASH_VERSION', and
8551 `BASH_VERSINFO'). *Note Bash Variables::, for details.
ccc6cda3 8552
bb70624e 8553 * The `IFS' variable is used to split only the results of expansion,
28ef6c31 8554 not all words (*note Word Splitting::). This closes a
bb70624e 8555 longstanding shell security hole.
ccc6cda3 8556
ac18b312
CR
8557 * Bash implements the full set of POSIX filename expansion operators,
8558 including CHARACTER CLASSES, EQUIVALENCE CLASSES, and COLLATING
8559 SYMBOLS (*note Filename Expansion::).
ccc6cda3 8560
bb70624e 8561 * Bash implements extended pattern matching features when the
28ef6c31 8562 `extglob' shell option is enabled (*note Pattern Matching::).
ccc6cda3 8563
bb70624e
JA
8564 * It is possible to have a variable and a function with the same
8565 name; `sh' does not separate the two name spaces.
ccc6cda3 8566
bb70624e
JA
8567 * Bash functions are permitted to have local variables using the
8568 `local' builtin, and thus useful recursive functions may be written
28ef6c31 8569 (*note Bash Builtins::).
ccc6cda3 8570
bb70624e 8571 * Variable assignments preceding commands affect only that command,
28ef6c31 8572 even builtins and functions (*note Environment::). In `sh', all
bb70624e
JA
8573 variable assignments preceding commands are global unless the
8574 command is executed from the file system.
ccc6cda3 8575
bb70624e 8576 * Bash performs filename expansion on filenames specified as operands
28ef6c31 8577 to input and output redirection operators (*note Redirections::).
ccc6cda3 8578
bb70624e
JA
8579 * Bash contains the `<>' redirection operator, allowing a file to be
8580 opened for both reading and writing, and the `&>' redirection
8581 operator, for directing standard output and standard error to the
28ef6c31 8582 same file (*note Redirections::).
d166f048 8583
1c72c0cd
CR
8584 * Bash includes the `<<<' redirection operator, allowing a string to
8585 be used as the standard input to a command.
8586
8587 * Bash implements the `[n]<&WORD' and `[n]>&WORD' redirection
8588 operators, which move one file descriptor to another.
8589
bb70624e 8590 * Bash treats a number of filenames specially when they are used in
28ef6c31 8591 redirection operators (*note Redirections::).
ccc6cda3 8592
bb70624e 8593 * Bash can open network connections to arbitrary machines and
28ef6c31 8594 services with the redirection operators (*note Redirections::).
ccc6cda3 8595
bb70624e 8596 * The `noclobber' option is available to avoid overwriting existing
28ef6c31
JA
8597 files with output redirection (*note The Set Builtin::). The `>|'
8598 redirection operator may be used to override `noclobber'.
ccc6cda3 8599
28ef6c31
JA
8600 * The Bash `cd' and `pwd' builtins (*note Bourne Shell Builtins::)
8601 each take `-L' and `-P' options to switch between logical and
bb70624e 8602 physical modes.
b72432fd 8603
bb70624e
JA
8604 * Bash allows a function to override a builtin with the same name,
8605 and provides access to that builtin's functionality within the
8606 function via the `builtin' and `command' builtins (*note Bash
28ef6c31 8607 Builtins::).
ccc6cda3 8608
bb70624e 8609 * The `command' builtin allows selective disabling of functions when
28ef6c31 8610 command lookup is performed (*note Bash Builtins::).
ccc6cda3 8611
bb70624e 8612 * Individual builtins may be enabled or disabled using the `enable'
28ef6c31 8613 builtin (*note Bash Builtins::).
cce855bc 8614
bb70624e
JA
8615 * The Bash `exec' builtin takes additional options that allow users
8616 to control the contents of the environment passed to the executed
8617 command, and what the zeroth argument to the command is to be
28ef6c31 8618 (*note Bourne Shell Builtins::).
cce855bc 8619
bb70624e 8620 * Shell functions may be exported to children via the environment
28ef6c31 8621 using `export -f' (*note Shell Functions::).
cce855bc 8622
bb70624e
JA
8623 * The Bash `export', `readonly', and `declare' builtins can take a
8624 `-f' option to act on shell functions, a `-p' option to display
8625 variables with various attributes set in a format that can be used
8626 as shell input, a `-n' option to remove various variable
8627 attributes, and `name=value' arguments to set variable attributes
8628 and values simultaneously.
ccc6cda3 8629
bb70624e
JA
8630 * The Bash `hash' builtin allows a name to be associated with an
8631 arbitrary filename, even when that filename cannot be found by
8632 searching the `$PATH', using `hash -p' (*note Bourne Shell
28ef6c31 8633 Builtins::).
ccc6cda3 8634
bb70624e 8635 * Bash includes a `help' builtin for quick reference to shell
28ef6c31 8636 facilities (*note Bash Builtins::).
ccc6cda3 8637
bb70624e 8638 * The `printf' builtin is available to display formatted output
28ef6c31 8639 (*note Bash Builtins::).
ccc6cda3 8640
28ef6c31 8641 * The Bash `read' builtin (*note Bash Builtins::) will read a line
bb70624e
JA
8642 ending in `\' with the `-r' option, and will use the `REPLY'
8643 variable as a default if no non-option arguments are supplied.
8644 The Bash `read' builtin also accepts a prompt string with the `-p'
8645 option and will use Readline to obtain the line when given the
8646 `-e' option. The `read' builtin also has additional options to
8647 control input: the `-s' option will turn off echoing of input
8648 characters as they are read, the `-t' option will allow `read' to
8649 time out if input does not arrive within a specified number of
8650 seconds, the `-n' option will allow reading only a specified
8651 number of characters rather than a full line, and the `-d' option
8652 will read until a particular character rather than newline.
ccc6cda3 8653
bb70624e
JA
8654 * The `return' builtin may be used to abort execution of scripts
8655 executed with the `.' or `source' builtins (*note Bourne Shell
28ef6c31 8656 Builtins::).
d166f048 8657
bb70624e 8658 * Bash includes the `shopt' builtin, for finer control of shell
d3ad40de
CR
8659 optional capabilities (*note The Shopt Builtin::), and allows
8660 these options to be set and unset at shell invocation (*note
8661 Invoking Bash::).
d166f048 8662
bb70624e 8663 * Bash has much more optional behavior controllable with the `set'
28ef6c31 8664 builtin (*note The Set Builtin::).
cce855bc 8665
5e13499c
CR
8666 * The `-x' (`xtrace') option displays commands other than simple
8667 commands when performing an execution trace (*note The Set
8668 Builtin::).
8669
28ef6c31 8670 * The `test' builtin (*note Bourne Shell Builtins::) is slightly
bb70624e
JA
8671 different, as it implements the POSIX algorithm, which specifies
8672 the behavior based on the number of arguments.
ccc6cda3 8673
5e13499c
CR
8674 * Bash includes the `caller' builtin, which displays the context of
8675 any active subroutine call (a shell function or a script executed
8676 with the `.' or `source' builtins). This supports the bash
8677 debugger.
8678
28ef6c31 8679 * The `trap' builtin (*note Bourne Shell Builtins::) allows a
bb70624e 8680 `DEBUG' pseudo-signal specification, similar to `EXIT'. Commands
d3a24ed2
CR
8681 specified with a `DEBUG' trap are executed before every simple
8682 command, `for' command, `case' command, `select' command, every
8683 arithmetic `for' command, and before the first command executes in
8684 a shell function. The `DEBUG' trap is not inherited by shell
8685 functions unless the function has been given the `trace' attribute
8686 or the `functrace' option has been enabled using the `shopt'
8687 builtin. The `extdebug' shell option has additional effects on the
8688 `DEBUG' trap.
d166f048 8689
f73dda09
JA
8690 The `trap' builtin (*note Bourne Shell Builtins::) allows an `ERR'
8691 pseudo-signal specification, similar to `EXIT' and `DEBUG'.
8692 Commands specified with an `ERR' trap are executed after a simple
8693 command fails, with a few exceptions. The `ERR' trap is not
d3a24ed2
CR
8694 inherited by shell functions unless the `-o errtrace' option to
8695 the `set' builtin is enabled.
8696
8697 The `trap' builtin (*note Bourne Shell Builtins::) allows a
8698 `RETURN' pseudo-signal specification, similar to `EXIT' and
8699 `DEBUG'. Commands specified with an `RETURN' trap are executed
8700 before execution resumes after a shell function or a shell script
8701 executed with `.' or `source' returns. The `RETURN' trap is not
8fed3589
CR
8702 inherited by shell functions unless the function has been given
8703 the `trace' attribute or the `functrace' option has been enabled
8704 using the `shopt' builtin.
f73dda09 8705
bb70624e 8706 * The Bash `type' builtin is more extensive and gives more
28ef6c31 8707 information about the names it finds (*note Bash Builtins::).
cce855bc 8708
bb70624e
JA
8709 * The Bash `umask' builtin permits a `-p' option to cause the output
8710 to be displayed in the form of a `umask' command that may be
28ef6c31 8711 reused as input (*note Bourne Shell Builtins::).
d166f048 8712
bb70624e
JA
8713 * Bash implements a `csh'-like directory stack, and provides the
8714 `pushd', `popd', and `dirs' builtins to manipulate it (*note The
28ef6c31 8715 Directory Stack::). Bash also makes the directory stack visible
bb70624e 8716 as the value of the `DIRSTACK' shell variable.
d166f048 8717
bb70624e 8718 * Bash interprets special backslash-escaped characters in the prompt
28ef6c31 8719 strings when interactive (*note Printing a Prompt::).
d166f048 8720
bb70624e 8721 * The Bash restricted mode is more useful (*note The Restricted
28ef6c31 8722 Shell::); the SVR4.2 shell restricted mode is too limited.
ccc6cda3 8723
bb70624e 8724 * The `disown' builtin can remove a job from the internal shell job
28ef6c31 8725 table (*note Job Control Builtins::) or suppress the sending of
bb70624e 8726 `SIGHUP' to a job when the shell exits as the result of a `SIGHUP'.
ccc6cda3 8727
1c72c0cd
CR
8728 * Bash includes a number of features to support a separate debugger
8729 for shell scripts.
8730
bb70624e
JA
8731 * The SVR4.2 shell has two privilege-related builtins (`mldmode' and
8732 `priv') not present in Bash.
ccc6cda3 8733
bb70624e 8734 * Bash does not have the `stop' or `newgrp' builtins.
d166f048 8735
bb70624e
JA
8736 * Bash does not use the `SHACCT' variable or perform shell
8737 accounting.
d166f048 8738
bb70624e 8739 * The SVR4.2 `sh' uses a `TIMEOUT' variable like Bash uses `TMOUT'.
ccc6cda3 8740
28ef6c31 8741
6a8fd0ed 8742More features unique to Bash may be found in *note Bash Features::.
ccc6cda3 8743
37c41ab1
CR
8744B.1 Implementation Differences From The SVR4.2 Shell
8745====================================================
ccc6cda3 8746
37c41ab1
CR
8747Since Bash is a completely new implementation, it does not suffer from
8748many of the limitations of the SVR4.2 shell. For instance:
ccc6cda3 8749
bb70624e
JA
8750 * Bash does not fork a subshell when redirecting into or out of a
8751 shell control structure such as an `if' or `while' statement.
ccc6cda3 8752
bb70624e
JA
8753 * Bash does not allow unbalanced quotes. The SVR4.2 shell will
8754 silently insert a needed closing quote at `EOF' under certain
8755 circumstances. This can be the cause of some hard-to-find errors.
ccc6cda3 8756
bb70624e
JA
8757 * The SVR4.2 shell uses a baroque memory management scheme based on
8758 trapping `SIGSEGV'. If the shell is started from a process with
8759 `SIGSEGV' blocked (e.g., by using the `system()' C library
8760 function call), it misbehaves badly.
ccc6cda3 8761
bb70624e
JA
8762 * In a questionable attempt at security, the SVR4.2 shell, when
8763 invoked without the `-p' option, will alter its real and effective
8764 UID and GID if they are less than some magic threshold value,
8765 commonly 100. This can lead to unexpected results.
ccc6cda3 8766
bb70624e
JA
8767 * The SVR4.2 shell does not allow users to trap `SIGSEGV',
8768 `SIGALRM', or `SIGCHLD'.
ccc6cda3 8769
bb70624e
JA
8770 * The SVR4.2 shell does not allow the `IFS', `MAILCHECK', `PATH',
8771 `PS1', or `PS2' variables to be unset.
ccc6cda3 8772
bb70624e 8773 * The SVR4.2 shell treats `^' as the undocumented equivalent of `|'.
ccc6cda3 8774
bb70624e
JA
8775 * Bash allows multiple option arguments when it is invoked (`-x -v');
8776 the SVR4.2 shell allows only one option argument (`-xv'). In
8777 fact, some versions of the shell dump core if the second argument
8778 begins with a `-'.
ccc6cda3 8779
bb70624e 8780 * The SVR4.2 shell exits a script if any builtin fails; Bash exits a
ac18b312
CR
8781 script only if one of the POSIX special builtins fails, and only
8782 for certain failures, as enumerated in the POSIX standard.
ccc6cda3 8783
bb70624e
JA
8784 * The SVR4.2 shell behaves differently when invoked as `jsh' (it
8785 turns on job control).
ccc6cda3
JA
8786
8787\1f
c2a47ea9 8788File: bashref.info, Node: GNU Free Documentation License, Next: Indexes, Prev: Major Differences From The Bourne Shell, Up: Top
d3a24ed2 8789
c2a47ea9
CR
8790Appendix C GNU Free Documentation License
8791*****************************************
d3a24ed2
CR
8792
8793 Version 1.2, November 2002
37c41ab1 8794
d3a24ed2 8795 Copyright (C) 2000,2001,2002 Free Software Foundation, Inc.
c2a47ea9 8796 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
37c41ab1 8797
d3a24ed2
CR
8798 Everyone is permitted to copy and distribute verbatim copies
8799 of this license document, but changing it is not allowed.
8800
8801 0. PREAMBLE
8802
8803 The purpose of this License is to make a manual, textbook, or other
8804 functional and useful document "free" in the sense of freedom: to
8805 assure everyone the effective freedom to copy and redistribute it,
8806 with or without modifying it, either commercially or
8807 noncommercially. Secondarily, this License preserves for the
8808 author and publisher a way to get credit for their work, while not
8809 being considered responsible for modifications made by others.
8810
8811 This License is a kind of "copyleft", which means that derivative
8812 works of the document must themselves be free in the same sense.
8813 It complements the GNU General Public License, which is a copyleft
8814 license designed for free software.
8815
8816 We have designed this License in order to use it for manuals for
8817 free software, because free software needs free documentation: a
8818 free program should come with manuals providing the same freedoms
8819 that the software does. But this License is not limited to
8820 software manuals; it can be used for any textual work, regardless
8821 of subject matter or whether it is published as a printed book.
8822 We recommend this License principally for works whose purpose is
8823 instruction or reference.
8824
8825 1. APPLICABILITY AND DEFINITIONS
8826
8827 This License applies to any manual or other work, in any medium,
8828 that contains a notice placed by the copyright holder saying it
8829 can be distributed under the terms of this License. Such a notice
8830 grants a world-wide, royalty-free license, unlimited in duration,
8831 to use that work under the conditions stated herein. The
8832 "Document", below, refers to any such manual or work. Any member
8833 of the public is a licensee, and is addressed as "you". You
8834 accept the license if you copy, modify or distribute the work in a
8835 way requiring permission under copyright law.
8836
8837 A "Modified Version" of the Document means any work containing the
8838 Document or a portion of it, either copied verbatim, or with
8839 modifications and/or translated into another language.
8840
8841 A "Secondary Section" is a named appendix or a front-matter section
8842 of the Document that deals exclusively with the relationship of the
8843 publishers or authors of the Document to the Document's overall
8844 subject (or to related matters) and contains nothing that could
8845 fall directly within that overall subject. (Thus, if the Document
8846 is in part a textbook of mathematics, a Secondary Section may not
8847 explain any mathematics.) The relationship could be a matter of
8848 historical connection with the subject or with related matters, or
8849 of legal, commercial, philosophical, ethical or political position
8850 regarding them.
8851
8852 The "Invariant Sections" are certain Secondary Sections whose
8853 titles are designated, as being those of Invariant Sections, in
8854 the notice that says that the Document is released under this
8855 License. If a section does not fit the above definition of
8856 Secondary then it is not allowed to be designated as Invariant.
8857 The Document may contain zero Invariant Sections. If the Document
8858 does not identify any Invariant Sections then there are none.
8859
8860 The "Cover Texts" are certain short passages of text that are
8861 listed, as Front-Cover Texts or Back-Cover Texts, in the notice
8862 that says that the Document is released under this License. A
8863 Front-Cover Text may be at most 5 words, and a Back-Cover Text may
8864 be at most 25 words.
8865
8866 A "Transparent" copy of the Document means a machine-readable copy,
8867 represented in a format whose specification is available to the
8868 general public, that is suitable for revising the document
8869 straightforwardly with generic text editors or (for images
8870 composed of pixels) generic paint programs or (for drawings) some
8871 widely available drawing editor, and that is suitable for input to
8872 text formatters or for automatic translation to a variety of
8873 formats suitable for input to text formatters. A copy made in an
8874 otherwise Transparent file format whose markup, or absence of
8875 markup, has been arranged to thwart or discourage subsequent
8876 modification by readers is not Transparent. An image format is
8877 not Transparent if used for any substantial amount of text. A
8878 copy that is not "Transparent" is called "Opaque".
8879
8880 Examples of suitable formats for Transparent copies include plain
8881 ASCII without markup, Texinfo input format, LaTeX input format,
8882 SGML or XML using a publicly available DTD, and
8883 standard-conforming simple HTML, PostScript or PDF designed for
8884 human modification. Examples of transparent image formats include
8885 PNG, XCF and JPG. Opaque formats include proprietary formats that
8886 can be read and edited only by proprietary word processors, SGML or
8887 XML for which the DTD and/or processing tools are not generally
8888 available, and the machine-generated HTML, PostScript or PDF
8889 produced by some word processors for output purposes only.
8890
8891 The "Title Page" means, for a printed book, the title page itself,
8892 plus such following pages as are needed to hold, legibly, the
8893 material this License requires to appear in the title page. For
8894 works in formats which do not have any title page as such, "Title
8895 Page" means the text near the most prominent appearance of the
8896 work's title, preceding the beginning of the body of the text.
8897
8898 A section "Entitled XYZ" means a named subunit of the Document
8899 whose title either is precisely XYZ or contains XYZ in parentheses
8900 following text that translates XYZ in another language. (Here XYZ
8901 stands for a specific section name mentioned below, such as
8902 "Acknowledgements", "Dedications", "Endorsements", or "History".)
8903 To "Preserve the Title" of such a section when you modify the
8904 Document means that it remains a section "Entitled XYZ" according
8905 to this definition.
8906
8907 The Document may include Warranty Disclaimers next to the notice
8908 which states that this License applies to the Document. These
8909 Warranty Disclaimers are considered to be included by reference in
8910 this License, but only as regards disclaiming warranties: any other
8911 implication that these Warranty Disclaimers may have is void and
8912 has no effect on the meaning of this License.
8913
8914 2. VERBATIM COPYING
8915
8916 You may copy and distribute the Document in any medium, either
8917 commercially or noncommercially, provided that this License, the
8918 copyright notices, and the license notice saying this License
8919 applies to the Document are reproduced in all copies, and that you
8920 add no other conditions whatsoever to those of this License. You
8921 may not use technical measures to obstruct or control the reading
8922 or further copying of the copies you make or distribute. However,
8923 you may accept compensation in exchange for copies. If you
8924 distribute a large enough number of copies you must also follow
8925 the conditions in section 3.
8926
8927 You may also lend copies, under the same conditions stated above,
8928 and you may publicly display copies.
8929
8930 3. COPYING IN QUANTITY
8931
8932 If you publish printed copies (or copies in media that commonly
8933 have printed covers) of the Document, numbering more than 100, and
8934 the Document's license notice requires Cover Texts, you must
8935 enclose the copies in covers that carry, clearly and legibly, all
8936 these Cover Texts: Front-Cover Texts on the front cover, and
8937 Back-Cover Texts on the back cover. Both covers must also clearly
8938 and legibly identify you as the publisher of these copies. The
8939 front cover must present the full title with all words of the
8940 title equally prominent and visible. You may add other material
8941 on the covers in addition. Copying with changes limited to the
8942 covers, as long as they preserve the title of the Document and
8943 satisfy these conditions, can be treated as verbatim copying in
8944 other respects.
8945
8946 If the required texts for either cover are too voluminous to fit
8947 legibly, you should put the first ones listed (as many as fit
8948 reasonably) on the actual cover, and continue the rest onto
8949 adjacent pages.
8950
8951 If you publish or distribute Opaque copies of the Document
8952 numbering more than 100, you must either include a
8953 machine-readable Transparent copy along with each Opaque copy, or
8954 state in or with each Opaque copy a computer-network location from
8955 which the general network-using public has access to download
8956 using public-standard network protocols a complete Transparent
8957 copy of the Document, free of added material. If you use the
8958 latter option, you must take reasonably prudent steps, when you
8959 begin distribution of Opaque copies in quantity, to ensure that
8960 this Transparent copy will remain thus accessible at the stated
8961 location until at least one year after the last time you
8962 distribute an Opaque copy (directly or through your agents or
8963 retailers) of that edition to the public.
8964
8965 It is requested, but not required, that you contact the authors of
8966 the Document well before redistributing any large number of
8967 copies, to give them a chance to provide you with an updated
8968 version of the Document.
8969
8970 4. MODIFICATIONS
8971
8972 You may copy and distribute a Modified Version of the Document
8973 under the conditions of sections 2 and 3 above, provided that you
8974 release the Modified Version under precisely this License, with
8975 the Modified Version filling the role of the Document, thus
8976 licensing distribution and modification of the Modified Version to
8977 whoever possesses a copy of it. In addition, you must do these
8978 things in the Modified Version:
8979
8980 A. Use in the Title Page (and on the covers, if any) a title
8981 distinct from that of the Document, and from those of
8982 previous versions (which should, if there were any, be listed
8983 in the History section of the Document). You may use the
8984 same title as a previous version if the original publisher of
8985 that version gives permission.
8986
8987 B. List on the Title Page, as authors, one or more persons or
8988 entities responsible for authorship of the modifications in
8989 the Modified Version, together with at least five of the
8990 principal authors of the Document (all of its principal
8991 authors, if it has fewer than five), unless they release you
8992 from this requirement.
8993
8994 C. State on the Title page the name of the publisher of the
8995 Modified Version, as the publisher.
8996
8997 D. Preserve all the copyright notices of the Document.
8998
8999 E. Add an appropriate copyright notice for your modifications
9000 adjacent to the other copyright notices.
9001
9002 F. Include, immediately after the copyright notices, a license
9003 notice giving the public permission to use the Modified
9004 Version under the terms of this License, in the form shown in
9005 the Addendum below.
9006
9007 G. Preserve in that license notice the full lists of Invariant
9008 Sections and required Cover Texts given in the Document's
9009 license notice.
9010
9011 H. Include an unaltered copy of this License.
9012
9013 I. Preserve the section Entitled "History", Preserve its Title,
9014 and add to it an item stating at least the title, year, new
9015 authors, and publisher of the Modified Version as given on
9016 the Title Page. If there is no section Entitled "History" in
9017 the Document, create one stating the title, year, authors,
9018 and publisher of the Document as given on its Title Page,
9019 then add an item describing the Modified Version as stated in
9020 the previous sentence.
9021
9022 J. Preserve the network location, if any, given in the Document
9023 for public access to a Transparent copy of the Document, and
9024 likewise the network locations given in the Document for
9025 previous versions it was based on. These may be placed in
9026 the "History" section. You may omit a network location for a
9027 work that was published at least four years before the
9028 Document itself, or if the original publisher of the version
9029 it refers to gives permission.
9030
9031 K. For any section Entitled "Acknowledgements" or "Dedications",
9032 Preserve the Title of the section, and preserve in the
9033 section all the substance and tone of each of the contributor
9034 acknowledgements and/or dedications given therein.
9035
9036 L. Preserve all the Invariant Sections of the Document,
9037 unaltered in their text and in their titles. Section numbers
9038 or the equivalent are not considered part of the section
9039 titles.
9040
9041 M. Delete any section Entitled "Endorsements". Such a section
9042 may not be included in the Modified Version.
9043
9044 N. Do not retitle any existing section to be Entitled
9045 "Endorsements" or to conflict in title with any Invariant
9046 Section.
9047
9048 O. Preserve any Warranty Disclaimers.
9049
9050 If the Modified Version includes new front-matter sections or
9051 appendices that qualify as Secondary Sections and contain no
9052 material copied from the Document, you may at your option
9053 designate some or all of these sections as invariant. To do this,
9054 add their titles to the list of Invariant Sections in the Modified
9055 Version's license notice. These titles must be distinct from any
9056 other section titles.
9057
9058 You may add a section Entitled "Endorsements", provided it contains
9059 nothing but endorsements of your Modified Version by various
9060 parties--for example, statements of peer review or that the text
9061 has been approved by an organization as the authoritative
9062 definition of a standard.
9063
9064 You may add a passage of up to five words as a Front-Cover Text,
9065 and a passage of up to 25 words as a Back-Cover Text, to the end
9066 of the list of Cover Texts in the Modified Version. Only one
9067 passage of Front-Cover Text and one of Back-Cover Text may be
9068 added by (or through arrangements made by) any one entity. If the
9069 Document already includes a cover text for the same cover,
9070 previously added by you or by arrangement made by the same entity
9071 you are acting on behalf of, you may not add another; but you may
9072 replace the old one, on explicit permission from the previous
9073 publisher that added the old one.
9074
9075 The author(s) and publisher(s) of the Document do not by this
9076 License give permission to use their names for publicity for or to
9077 assert or imply endorsement of any Modified Version.
9078
9079 5. COMBINING DOCUMENTS
9080
9081 You may combine the Document with other documents released under
9082 this License, under the terms defined in section 4 above for
9083 modified versions, provided that you include in the combination
9084 all of the Invariant Sections of all of the original documents,
9085 unmodified, and list them all as Invariant Sections of your
9086 combined work in its license notice, and that you preserve all
9087 their Warranty Disclaimers.
9088
9089 The combined work need only contain one copy of this License, and
9090 multiple identical Invariant Sections may be replaced with a single
9091 copy. If there are multiple Invariant Sections with the same name
9092 but different contents, make the title of each such section unique
9093 by adding at the end of it, in parentheses, the name of the
9094 original author or publisher of that section if known, or else a
9095 unique number. Make the same adjustment to the section titles in
9096 the list of Invariant Sections in the license notice of the
9097 combined work.
9098
9099 In the combination, you must combine any sections Entitled
9100 "History" in the various original documents, forming one section
9101 Entitled "History"; likewise combine any sections Entitled
9102 "Acknowledgements", and any sections Entitled "Dedications". You
9103 must delete all sections Entitled "Endorsements."
9104
9105 6. COLLECTIONS OF DOCUMENTS
9106
9107 You may make a collection consisting of the Document and other
9108 documents released under this License, and replace the individual
9109 copies of this License in the various documents with a single copy
9110 that is included in the collection, provided that you follow the
9111 rules of this License for verbatim copying of each of the
9112 documents in all other respects.
9113
9114 You may extract a single document from such a collection, and
9115 distribute it individually under this License, provided you insert
9116 a copy of this License into the extracted document, and follow
9117 this License in all other respects regarding verbatim copying of
9118 that document.
9119
9120 7. AGGREGATION WITH INDEPENDENT WORKS
9121
9122 A compilation of the Document or its derivatives with other
9123 separate and independent documents or works, in or on a volume of
9124 a storage or distribution medium, is called an "aggregate" if the
9125 copyright resulting from the compilation is not used to limit the
9126 legal rights of the compilation's users beyond what the individual
c2a47ea9 9127 works permit. When the Document is included in an aggregate, this
d3a24ed2
CR
9128 License does not apply to the other works in the aggregate which
9129 are not themselves derivative works of the Document.
9130
9131 If the Cover Text requirement of section 3 is applicable to these
9132 copies of the Document, then if the Document is less than one half
9133 of the entire aggregate, the Document's Cover Texts may be placed
9134 on covers that bracket the Document within the aggregate, or the
9135 electronic equivalent of covers if the Document is in electronic
9136 form. Otherwise they must appear on printed covers that bracket
9137 the whole aggregate.
9138
9139 8. TRANSLATION
9140
9141 Translation is considered a kind of modification, so you may
9142 distribute translations of the Document under the terms of section
9143 4. Replacing Invariant Sections with translations requires special
9144 permission from their copyright holders, but you may include
9145 translations of some or all Invariant Sections in addition to the
9146 original versions of these Invariant Sections. You may include a
9147 translation of this License, and all the license notices in the
9148 Document, and any Warranty Disclaimers, provided that you also
9149 include the original English version of this License and the
9150 original versions of those notices and disclaimers. In case of a
9151 disagreement between the translation and the original version of
9152 this License or a notice or disclaimer, the original version will
9153 prevail.
9154
9155 If a section in the Document is Entitled "Acknowledgements",
9156 "Dedications", or "History", the requirement (section 4) to
9157 Preserve its Title (section 1) will typically require changing the
9158 actual title.
9159
9160 9. TERMINATION
9161
9162 You may not copy, modify, sublicense, or distribute the Document
9163 except as expressly provided for under this License. Any other
9164 attempt to copy, modify, sublicense or distribute the Document is
9165 void, and will automatically terminate your rights under this
9166 License. However, parties who have received copies, or rights,
9167 from you under this License will not have their licenses
9168 terminated so long as such parties remain in full compliance.
9169
9170 10. FUTURE REVISIONS OF THIS LICENSE
9171
9172 The Free Software Foundation may publish new, revised versions of
9173 the GNU Free Documentation License from time to time. Such new
9174 versions will be similar in spirit to the present version, but may
9175 differ in detail to address new problems or concerns. See
9176 `http://www.gnu.org/copyleft/'.
9177
9178 Each version of the License is given a distinguishing version
9179 number. If the Document specifies that a particular numbered
9180 version of this License "or any later version" applies to it, you
9181 have the option of following the terms and conditions either of
9182 that specified version or of any later version that has been
9183 published (not as a draft) by the Free Software Foundation. If
9184 the Document does not specify a version number of this License,
9185 you may choose any version ever published (not as a draft) by the
9186 Free Software Foundation.
9187
c2a47ea9
CR
9188ADDENDUM: How to use this License for your documents
9189====================================================
d3a24ed2 9190
37c41ab1 9191To use this License in a document you have written, include a copy of
d3a24ed2
CR
9192the License in the document and put the following copyright and license
9193notices just after the title page:
9194
9195 Copyright (C) YEAR YOUR NAME.
9196 Permission is granted to copy, distribute and/or modify this document
9197 under the terms of the GNU Free Documentation License, Version 1.2
9198 or any later version published by the Free Software Foundation;
c2a47ea9
CR
9199 with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
9200 Texts. A copy of the license is included in the section entitled ``GNU
d3a24ed2
CR
9201 Free Documentation License''.
9202
9203 If you have Invariant Sections, Front-Cover Texts and Back-Cover
9204Texts, replace the "with...Texts." line with this:
9205
9206 with the Invariant Sections being LIST THEIR TITLES, with
9207 the Front-Cover Texts being LIST, and with the Back-Cover Texts
9208 being LIST.
9209
9210 If you have Invariant Sections without Cover Texts, or some other
9211combination of the three, merge those two alternatives to suit the
9212situation.
9213
9214 If your document contains nontrivial examples of program code, we
9215recommend releasing these examples in parallel under your choice of
9216free software license, such as the GNU General Public License, to
9217permit their use in free software.
9218
9219\1f
c2a47ea9 9220File: bashref.info, Node: Indexes, Prev: GNU Free Documentation License, Up: Top
d3ad40de
CR
9221
9222Appendix D Indexes
9223******************
9224
9225* Menu:
9226
9227* Builtin Index:: Index of Bash builtin commands.
9228* Reserved Word Index:: Index of Bash reserved words.
9229* Variable Index:: Quick reference helps you find the
9230 variable you want.
9231* Function Index:: Index of bindable Readline functions.
9232* Concept Index:: General index for concepts described in
9233 this manual.
9234
9235\1f
9236File: bashref.info, Node: Builtin Index, Next: Reserved Word Index, Up: Indexes
5cfe250d 9237
d3ad40de
CR
9238D.1 Index of Shell Builtin Commands
9239===================================
ccc6cda3 9240
37c41ab1 9241\0\b[index\0\b]
ccc6cda3
JA
9242* Menu:
9243
e8ce775d 9244* .: Bourne Shell Builtins.
37c41ab1 9245 (line 16)
e8ce775d 9246* :: Bourne Shell Builtins.
37c41ab1 9247 (line 11)
e8ce775d 9248* [: Bourne Shell Builtins.
37c41ab1
CR
9249 (line 212)
9250* alias: Bash Builtins. (line 11)
e8ce775d 9251* bg: Job Control Builtins.
37c41ab1
CR
9252 (line 7)
9253* bind: Bash Builtins. (line 21)
e8ce775d 9254* break: Bourne Shell Builtins.
37c41ab1 9255 (line 29)
ed35cb4a
CR
9256* builtin: Bash Builtins. (line 98)
9257* caller: Bash Builtins. (line 106)
e8ce775d 9258* cd: Bourne Shell Builtins.
37c41ab1 9259 (line 36)
ed35cb4a 9260* command: Bash Builtins. (line 123)
bb70624e 9261* compgen: Programmable Completion Builtins.
37c41ab1 9262 (line 10)
bb70624e 9263* complete: Programmable Completion Builtins.
37c41ab1 9264 (line 28)
6a8fd0ed 9265* compopt: Programmable Completion Builtins.
ed35cb4a 9266 (line 212)
e8ce775d 9267* continue: Bourne Shell Builtins.
37c41ab1 9268 (line 55)
ed35cb4a 9269* declare: Bash Builtins. (line 142)
bb70624e 9270* dirs: Directory Stack Builtins.
37c41ab1 9271 (line 7)
e8ce775d 9272* disown: Job Control Builtins.
37c41ab1 9273 (line 83)
ed35cb4a
CR
9274* echo: Bash Builtins. (line 208)
9275* enable: Bash Builtins. (line 260)
e8ce775d 9276* eval: Bourne Shell Builtins.
37c41ab1 9277 (line 63)
e8ce775d 9278* exec: Bourne Shell Builtins.
37c41ab1 9279 (line 70)
e8ce775d 9280* exit: Bourne Shell Builtins.
37c41ab1 9281 (line 82)
e8ce775d 9282* export: Bourne Shell Builtins.
37c41ab1 9283 (line 88)
cce855bc 9284* fc: Bash History Builtins.
37c41ab1 9285 (line 10)
e8ce775d 9286* fg: Job Control Builtins.
37c41ab1 9287 (line 16)
e8ce775d 9288* getopts: Bourne Shell Builtins.
37c41ab1 9289 (line 103)
e8ce775d 9290* hash: Bourne Shell Builtins.
37c41ab1 9291 (line 145)
ed35cb4a 9292* help: Bash Builtins. (line 288)
cce855bc 9293* history: Bash History Builtins.
37c41ab1 9294 (line 39)
e8ce775d 9295* jobs: Job Control Builtins.
37c41ab1 9296 (line 25)
e8ce775d 9297* kill: Job Control Builtins.
37c41ab1 9298 (line 57)
ed35cb4a
CR
9299* let: Bash Builtins. (line 308)
9300* local: Bash Builtins. (line 315)
9301* logout: Bash Builtins. (line 325)
9302* mapfile: Bash Builtins. (line 329)
bb70624e 9303* popd: Directory Stack Builtins.
37c41ab1 9304 (line 37)
ed35cb4a 9305* printf: Bash Builtins. (line 370)
bb70624e 9306* pushd: Directory Stack Builtins.
37c41ab1 9307 (line 58)
e8ce775d 9308* pwd: Bourne Shell Builtins.
37c41ab1 9309 (line 163)
ed35cb4a 9310* read: Bash Builtins. (line 395)
e8ce775d 9311* readonly: Bourne Shell Builtins.
37c41ab1 9312 (line 172)
e8ce775d 9313* return: Bourne Shell Builtins.
37c41ab1 9314 (line 187)
d3ad40de 9315* set: The Set Builtin. (line 11)
e8ce775d 9316* shift: Bourne Shell Builtins.
37c41ab1 9317 (line 200)
d3ad40de 9318* shopt: The Shopt Builtin. (line 9)
ed35cb4a 9319* source: Bash Builtins. (line 461)
e8ce775d 9320* suspend: Job Control Builtins.
37c41ab1 9321 (line 94)
e8ce775d 9322* test: Bourne Shell Builtins.
37c41ab1 9323 (line 212)
e8ce775d 9324* times: Bourne Shell Builtins.
d7f49990 9325 (line 280)
e8ce775d 9326* trap: Bourne Shell Builtins.
d7f49990 9327 (line 285)
ed35cb4a
CR
9328* type: Bash Builtins. (line 465)
9329* typeset: Bash Builtins. (line 496)
9330* ulimit: Bash Builtins. (line 502)
e8ce775d 9331* umask: Bourne Shell Builtins.
d7f49990 9332 (line 326)
ed35cb4a 9333* unalias: Bash Builtins. (line 588)
e8ce775d 9334* unset: Bourne Shell Builtins.
d7f49990 9335 (line 343)
e8ce775d 9336* wait: Job Control Builtins.
37c41ab1 9337 (line 73)
ccc6cda3
JA
9338
9339\1f
d3ad40de 9340File: bashref.info, Node: Reserved Word Index, Next: Variable Index, Prev: Builtin Index, Up: Indexes
ccc6cda3 9341
d3ad40de
CR
9342D.2 Index of Shell Reserved Words
9343=================================
ccc6cda3 9344
37c41ab1 9345\0\b[index\0\b]
ccc6cda3
JA
9346* Menu:
9347
ed35cb4a 9348* !: Pipelines. (line 9)
cce855bc 9349* [[: Conditional Constructs.
ed35cb4a 9350 (line 117)
cce855bc 9351* ]]: Conditional Constructs.
ed35cb4a 9352 (line 117)
e8ce775d 9353* case: Conditional Constructs.
37c41ab1
CR
9354 (line 28)
9355* do: Looping Constructs. (line 12)
9356* done: Looping Constructs. (line 12)
e8ce775d 9357* elif: Conditional Constructs.
37c41ab1 9358 (line 7)
e8ce775d 9359* else: Conditional Constructs.
37c41ab1 9360 (line 7)
e8ce775d 9361* esac: Conditional Constructs.
37c41ab1 9362 (line 28)
e8ce775d 9363* fi: Conditional Constructs.
37c41ab1
CR
9364 (line 7)
9365* for: Looping Constructs. (line 29)
9366* function: Shell Functions. (line 13)
e8ce775d 9367* if: Conditional Constructs.
37c41ab1 9368 (line 7)
e8ce775d 9369* in: Conditional Constructs.
37c41ab1 9370 (line 28)
cce855bc 9371* select: Conditional Constructs.
ed35cb4a 9372 (line 76)
e8ce775d 9373* then: Conditional Constructs.
37c41ab1 9374 (line 7)
ed35cb4a 9375* time: Pipelines. (line 9)
37c41ab1
CR
9376* until: Looping Constructs. (line 12)
9377* while: Looping Constructs. (line 20)
9378* {: Command Grouping. (line 21)
9379* }: Command Grouping. (line 21)
ccc6cda3
JA
9380
9381\1f
d3ad40de 9382File: bashref.info, Node: Variable Index, Next: Function Index, Prev: Reserved Word Index, Up: Indexes
ccc6cda3 9383
d3ad40de
CR
9384D.3 Parameter and Variable Index
9385================================
ccc6cda3 9386
37c41ab1 9387\0\b[index\0\b]
ccc6cda3
JA
9388* Menu:
9389
37c41ab1
CR
9390* !: Special Parameters. (line 46)
9391* #: Special Parameters. (line 30)
9392* $: Special Parameters. (line 42)
9393* *: Special Parameters. (line 9)
9394* -: Special Parameters. (line 37)
9395* 0: Special Parameters. (line 50)
9396* ?: Special Parameters. (line 33)
9397* @: Special Parameters. (line 19)
9398* _: Special Parameters. (line 59)
e8ce775d 9399* auto_resume: Job Control Variables.
37c41ab1
CR
9400 (line 6)
9401* BASH: Bash Variables. (line 13)
d3ad40de
CR
9402* BASH_ARGC: Bash Variables. (line 21)
9403* BASH_ARGV: Bash Variables. (line 31)
9404* BASH_COMMAND: Bash Variables. (line 41)
9405* BASH_ENV: Bash Variables. (line 46)
9406* BASH_EXECUTION_STRING: Bash Variables. (line 52)
9407* BASH_LINENO: Bash Variables. (line 55)
c2a47ea9
CR
9408* BASH_REMATCH: Bash Variables. (line 64)
9409* BASH_SOURCE: Bash Variables. (line 72)
9410* BASH_SUBSHELL: Bash Variables. (line 76)
9411* BASH_VERSINFO: Bash Variables. (line 80)
9412* BASH_VERSION: Bash Variables. (line 104)
d3ad40de 9413* BASHPID: Bash Variables. (line 16)
e8ce775d 9414* bell-style: Readline Init File Syntax.
1c72c0cd 9415 (line 38)
eb2bb562 9416* bind-tty-special-chars: Readline Init File Syntax.
1c72c0cd 9417 (line 45)
e8ce775d 9418* CDPATH: Bourne Shell Variables.
37c41ab1 9419 (line 9)
c2a47ea9 9420* COLUMNS: Bash Variables. (line 107)
e8ce775d 9421* comment-begin: Readline Init File Syntax.
1c72c0cd 9422 (line 50)
c2a47ea9
CR
9423* COMP_CWORD: Bash Variables. (line 112)
9424* COMP_KEY: Bash Variables. (line 141)
9425* COMP_LINE: Bash Variables. (line 118)
9426* COMP_POINT: Bash Variables. (line 123)
9427* COMP_TYPE: Bash Variables. (line 131)
9428* COMP_WORDBREAKS: Bash Variables. (line 145)
9429* COMP_WORDS: Bash Variables. (line 151)
ed35cb4a 9430* completion-prefix-display-length: Readline Init File Syntax.
1c72c0cd 9431 (line 60)
ed35cb4a
CR
9432* completion-query-items: Readline Init File Syntax.
9433 (line 67)
c2a47ea9 9434* COMPREPLY: Bash Variables. (line 158)
e8ce775d 9435* convert-meta: Readline Init File Syntax.
ed35cb4a 9436 (line 77)
c2a47ea9 9437* DIRSTACK: Bash Variables. (line 163)
e8ce775d 9438* disable-completion: Readline Init File Syntax.
ed35cb4a 9439 (line 83)
1c72c0cd 9440* editing-mode: Readline Init File Syntax.
ed35cb4a 9441 (line 88)
c2a47ea9 9442* EMACS: Bash Variables. (line 173)
e8ce775d 9443* enable-keypad: Readline Init File Syntax.
ed35cb4a 9444 (line 94)
c2a47ea9 9445* EUID: Bash Variables. (line 178)
e8ce775d 9446* expand-tilde: Readline Init File Syntax.
ed35cb4a 9447 (line 99)
c2a47ea9
CR
9448* FCEDIT: Bash Variables. (line 182)
9449* FIGNORE: Bash Variables. (line 186)
9450* FUNCNAME: Bash Variables. (line 192)
9451* GLOBIGNORE: Bash Variables. (line 201)
9452* GROUPS: Bash Variables. (line 207)
9453* histchars: Bash Variables. (line 213)
9454* HISTCMD: Bash Variables. (line 228)
9455* HISTCONTROL: Bash Variables. (line 233)
9456* HISTFILE: Bash Variables. (line 249)
9457* HISTFILESIZE: Bash Variables. (line 253)
9458* HISTIGNORE: Bash Variables. (line 261)
f73dda09 9459* history-preserve-point: Readline Init File Syntax.
ed35cb4a 9460 (line 103)
6a8fd0ed 9461* history-size: Readline Init File Syntax.
ed35cb4a 9462 (line 109)
c2a47ea9
CR
9463* HISTSIZE: Bash Variables. (line 280)
9464* HISTTIMEFORMAT: Bash Variables. (line 284)
e8ce775d 9465* HOME: Bourne Shell Variables.
37c41ab1 9466 (line 13)
e8ce775d 9467* horizontal-scroll-mode: Readline Init File Syntax.
ed35cb4a 9468 (line 114)
c2a47ea9
CR
9469* HOSTFILE: Bash Variables. (line 293)
9470* HOSTNAME: Bash Variables. (line 304)
9471* HOSTTYPE: Bash Variables. (line 307)
e8ce775d 9472* IFS: Bourne Shell Variables.
37c41ab1 9473 (line 18)
c2a47ea9 9474* IGNOREEOF: Bash Variables. (line 310)
e8ce775d 9475* input-meta: Readline Init File Syntax.
ed35cb4a 9476 (line 121)
c2a47ea9 9477* INPUTRC: Bash Variables. (line 320)
b72432fd 9478* isearch-terminators: Readline Init File Syntax.
6a8fd0ed 9479 (line 128)
ed35cb4a
CR
9480* keymap: Readline Init File Syntax.
9481 (line 135)
c2a47ea9
CR
9482* LANG: Bash Variables. (line 324)
9483* LC_ALL: Bash Variables. (line 328)
9484* LC_COLLATE: Bash Variables. (line 332)
9485* LC_CTYPE: Bash Variables. (line 339)
37c41ab1 9486* LC_MESSAGES <1>: Locale Translation. (line 11)
c2a47ea9
CR
9487* LC_MESSAGES: Bash Variables. (line 344)
9488* LC_NUMERIC: Bash Variables. (line 348)
9489* LINENO: Bash Variables. (line 352)
9490* LINES: Bash Variables. (line 356)
9491* MACHTYPE: Bash Variables. (line 361)
e8ce775d 9492* MAIL: Bourne Shell Variables.
37c41ab1 9493 (line 22)
c2a47ea9 9494* MAILCHECK: Bash Variables. (line 365)
e8ce775d 9495* MAILPATH: Bourne Shell Variables.
37c41ab1 9496 (line 27)
e8ce775d 9497* mark-modified-lines: Readline Init File Syntax.
ed35cb4a 9498 (line 148)
6a8fd0ed 9499* mark-symlinked-directories: Readline Init File Syntax.
ed35cb4a 9500 (line 153)
6a8fd0ed 9501* match-hidden-files: Readline Init File Syntax.
ed35cb4a 9502 (line 158)
e8ce775d 9503* meta-flag: Readline Init File Syntax.
ed35cb4a 9504 (line 121)
c2a47ea9 9505* OLDPWD: Bash Variables. (line 373)
e8ce775d 9506* OPTARG: Bourne Shell Variables.
37c41ab1 9507 (line 34)
c2a47ea9 9508* OPTERR: Bash Variables. (line 376)
e8ce775d 9509* OPTIND: Bourne Shell Variables.
37c41ab1 9510 (line 38)
c2a47ea9 9511* OSTYPE: Bash Variables. (line 380)
e8ce775d 9512* output-meta: Readline Init File Syntax.
ed35cb4a 9513 (line 165)
6a8fd0ed 9514* page-completions: Readline Init File Syntax.
ed35cb4a 9515 (line 170)
e8ce775d 9516* PATH: Bourne Shell Variables.
37c41ab1 9517 (line 42)
c2a47ea9
CR
9518* PIPESTATUS: Bash Variables. (line 383)
9519* POSIXLY_CORRECT: Bash Variables. (line 388)
9520* PPID: Bash Variables. (line 397)
9521* PROMPT_COMMAND: Bash Variables. (line 401)
e8ce775d 9522* PS1: Bourne Shell Variables.
37c41ab1 9523 (line 48)
e8ce775d 9524* PS2: Bourne Shell Variables.
37c41ab1 9525 (line 53)
c2a47ea9
CR
9526* PS3: Bash Variables. (line 405)
9527* PS4: Bash Variables. (line 410)
9528* PWD: Bash Variables. (line 416)
9529* RANDOM: Bash Variables. (line 419)
9530* REPLY: Bash Variables. (line 424)
ed35cb4a
CR
9531* revert-all-at-newline: Readline Init File Syntax.
9532 (line 180)
c2a47ea9
CR
9533* SECONDS: Bash Variables. (line 427)
9534* SHELL: Bash Variables. (line 433)
9535* SHELLOPTS: Bash Variables. (line 438)
9536* SHLVL: Bash Variables. (line 447)
e8ce775d 9537* show-all-if-ambiguous: Readline Init File Syntax.
ed35cb4a 9538 (line 186)
1c72c0cd 9539* show-all-if-unmodified: Readline Init File Syntax.
ed35cb4a 9540 (line 192)
37c41ab1
CR
9541* TEXTDOMAIN: Locale Translation. (line 11)
9542* TEXTDOMAINDIR: Locale Translation. (line 11)
c2a47ea9
CR
9543* TIMEFORMAT: Bash Variables. (line 452)
9544* TMOUT: Bash Variables. (line 490)
9545* TMPDIR: Bash Variables. (line 502)
9546* UID: Bash Variables. (line 506)
e8ce775d 9547* visible-stats: Readline Init File Syntax.
ed35cb4a 9548 (line 201)
ccc6cda3
JA
9549
9550\1f
d3ad40de 9551File: bashref.info, Node: Function Index, Next: Concept Index, Prev: Variable Index, Up: Indexes
ccc6cda3 9552
d3ad40de
CR
9553D.4 Function Index
9554==================
ccc6cda3 9555
37c41ab1 9556\0\b[index\0\b]
ccc6cda3
JA
9557* Menu:
9558
e8ce775d 9559* abort (C-g): Miscellaneous Commands.
37c41ab1
CR
9560 (line 10)
9561* accept-line (Newline or Return): Commands For History. (line 6)
9562* backward-char (C-b): Commands For Moving. (line 15)
9563* backward-delete-char (Rubout): Commands For Text. (line 11)
9564* backward-kill-line (C-x Rubout): Commands For Killing. (line 9)
9565* backward-kill-word (M-<DEL>): Commands For Killing. (line 24)
9566* backward-word (M-b): Commands For Moving. (line 22)
9567* beginning-of-history (M-<): Commands For History. (line 20)
9568* beginning-of-line (C-a): Commands For Moving. (line 6)
9569* call-last-kbd-macro (C-x e): Keyboard Macros. (line 13)
9570* capitalize-word (M-c): Commands For Text. (line 46)
e8ce775d 9571* character-search (C-]): Miscellaneous Commands.
37c41ab1 9572 (line 41)
e8ce775d 9573* character-search-backward (M-C-]): Miscellaneous Commands.
37c41ab1
CR
9574 (line 46)
9575* clear-screen (C-l): Commands For Moving. (line 26)
28ef6c31 9576* complete (<TAB>): Commands For Completion.
37c41ab1
CR
9577 (line 6)
9578* copy-backward-word (): Commands For Killing. (line 49)
9579* copy-forward-word (): Commands For Killing. (line 54)
9580* copy-region-as-kill (): Commands For Killing. (line 45)
9581* delete-char (C-d): Commands For Text. (line 6)
b72432fd 9582* delete-char-or-list (): Commands For Completion.
37c41ab1
CR
9583 (line 34)
9584* delete-horizontal-space (): Commands For Killing. (line 37)
9585* digit-argument (M-0, M-1, ... M--): Numeric Arguments. (line 6)
ccc6cda3 9586* do-uppercase-version (M-a, M-b, M-X, ...): Miscellaneous Commands.
37c41ab1
CR
9587 (line 14)
9588* downcase-word (M-l): Commands For Text. (line 42)
e8ce775d 9589* dump-functions (): Miscellaneous Commands.
37c41ab1 9590 (line 64)
e8ce775d 9591* dump-macros (): Miscellaneous Commands.
37c41ab1 9592 (line 76)
e8ce775d 9593* dump-variables (): Miscellaneous Commands.
37c41ab1
CR
9594 (line 70)
9595* end-kbd-macro (C-x )): Keyboard Macros. (line 9)
9596* end-of-history (M->): Commands For History. (line 23)
9597* end-of-line (C-e): Commands For Moving. (line 9)
e8ce775d 9598* exchange-point-and-mark (C-x C-x): Miscellaneous Commands.
37c41ab1
CR
9599 (line 36)
9600* forward-backward-delete-char (): Commands For Text. (line 15)
9601* forward-char (C-f): Commands For Moving. (line 12)
9602* forward-search-history (C-s): Commands For History. (line 31)
9603* forward-word (M-f): Commands For Moving. (line 18)
9604* history-search-backward (): Commands For History. (line 51)
9605* history-search-forward (): Commands For History. (line 46)
e8ce775d 9606* insert-comment (M-#): Miscellaneous Commands.
37c41ab1 9607 (line 51)
e8ce775d 9608* insert-completions (M-*): Commands For Completion.
37c41ab1
CR
9609 (line 18)
9610* kill-line (C-k): Commands For Killing. (line 6)
9611* kill-region (): Commands For Killing. (line 41)
9612* kill-whole-line (): Commands For Killing. (line 15)
9613* kill-word (M-d): Commands For Killing. (line 19)
cce855bc 9614* menu-complete (): Commands For Completion.
37c41ab1
CR
9615 (line 22)
9616* next-history (C-n): Commands For History. (line 17)
ccc6cda3 9617* non-incremental-forward-search-history (M-n): Commands For History.
37c41ab1 9618 (line 41)
ccc6cda3 9619* non-incremental-reverse-search-history (M-p): Commands For History.
37c41ab1
CR
9620 (line 36)
9621* overwrite-mode (): Commands For Text. (line 50)
e8ce775d 9622* possible-completions (M-?): Commands For Completion.
37c41ab1 9623 (line 15)
28ef6c31 9624* prefix-meta (<ESC>): Miscellaneous Commands.
37c41ab1
CR
9625 (line 18)
9626* previous-history (C-p): Commands For History. (line 13)
9627* quoted-insert (C-q or C-v): Commands For Text. (line 20)
e8ce775d 9628* re-read-init-file (C-x C-r): Miscellaneous Commands.
37c41ab1
CR
9629 (line 6)
9630* redraw-current-line (): Commands For Moving. (line 30)
9631* reverse-search-history (C-r): Commands For History. (line 27)
e8ce775d 9632* revert-line (M-r): Miscellaneous Commands.
37c41ab1
CR
9633 (line 25)
9634* self-insert (a, b, A, 1, !, ...): Commands For Text. (line 24)
e8ce775d 9635* set-mark (C-@): Miscellaneous Commands.
37c41ab1
CR
9636 (line 32)
9637* start-kbd-macro (C-x (): Keyboard Macros. (line 6)
9638* transpose-chars (C-t): Commands For Text. (line 27)
9639* transpose-words (M-t): Commands For Text. (line 33)
28ef6c31 9640* undo (C-_ or C-x C-u): Miscellaneous Commands.
37c41ab1
CR
9641 (line 22)
9642* universal-argument (): Numeric Arguments. (line 10)
9643* unix-filename-rubout (): Commands For Killing. (line 32)
9644* unix-line-discard (C-u): Commands For Killing. (line 12)
9645* unix-word-rubout (C-w): Commands For Killing. (line 28)
9646* upcase-word (M-u): Commands For Text. (line 38)
9647* yank (C-y): Commands For Killing. (line 59)
eb2bb562 9648* yank-last-arg (M-. or M-_): Commands For History. (line 65)
37c41ab1
CR
9649* yank-nth-arg (M-C-y): Commands For History. (line 56)
9650* yank-pop (M-y): Commands For Killing. (line 62)
ccc6cda3
JA
9651
9652\1f
d3ad40de 9653File: bashref.info, Node: Concept Index, Prev: Function Index, Up: Indexes
ccc6cda3 9654
d3ad40de
CR
9655D.5 Concept Index
9656=================
ccc6cda3 9657
37c41ab1 9658\0\b[index\0\b]
ccc6cda3
JA
9659* Menu:
9660
37c41ab1
CR
9661* alias expansion: Aliases. (line 6)
9662* arithmetic evaluation: Shell Arithmetic. (line 6)
e8ce775d 9663* arithmetic expansion: Arithmetic Expansion.
37c41ab1
CR
9664 (line 6)
9665* arithmetic, shell: Shell Arithmetic. (line 6)
9666* arrays: Arrays. (line 6)
9667* background: Job Control Basics. (line 6)
9668* Bash configuration: Basic Installation. (line 6)
9669* Bash installation: Basic Installation. (line 6)
e8ce775d 9670* Bourne shell: Basic Shell Features.
37c41ab1
CR
9671 (line 6)
9672* brace expansion: Brace Expansion. (line 6)
ac18b312 9673* builtin: Definitions. (line 17)
e8ce775d 9674* command editing: Readline Bare Essentials.
37c41ab1 9675 (line 6)
e8ce775d 9676* command execution: Command Search and Execution.
37c41ab1 9677 (line 6)
cce855bc 9678* command expansion: Simple Command Expansion.
37c41ab1 9679 (line 6)
e8ce775d 9680* command history: Bash History Facilities.
37c41ab1 9681 (line 6)
e8ce775d 9682* command search: Command Search and Execution.
37c41ab1 9683 (line 6)
e8ce775d 9684* command substitution: Command Substitution.
37c41ab1 9685 (line 6)
ed35cb4a 9686* command timing: Pipelines. (line 9)
37c41ab1 9687* commands, compound: Compound Commands. (line 6)
e8ce775d 9688* commands, conditional: Conditional Constructs.
37c41ab1
CR
9689 (line 6)
9690* commands, grouping: Command Grouping. (line 6)
9691* commands, lists: Lists. (line 6)
9692* commands, looping: Looping Constructs. (line 6)
9693* commands, pipelines: Pipelines. (line 6)
9694* commands, shell: Shell Commands. (line 6)
9695* commands, simple: Simple Commands. (line 6)
9696* comments, shell: Comments. (line 6)
bb70624e 9697* completion builtins: Programmable Completion Builtins.
37c41ab1
CR
9698 (line 6)
9699* configuration: Basic Installation. (line 6)
ac18b312 9700* control operator: Definitions. (line 21)
37c41ab1 9701* directory stack: The Directory Stack. (line 6)
e8ce775d 9702* editing command lines: Readline Bare Essentials.
37c41ab1
CR
9703 (line 6)
9704* environment: Environment. (line 6)
9705* evaluation, arithmetic: Shell Arithmetic. (line 6)
9706* event designators: Event Designators. (line 6)
cce855bc 9707* execution environment: Command Execution Environment.
37c41ab1
CR
9708 (line 6)
9709* exit status <1>: Exit Status. (line 6)
ed35cb4a 9710* exit status: Definitions. (line 26)
37c41ab1 9711* expansion: Shell Expansions. (line 6)
e8ce775d 9712* expansion, arithmetic: Arithmetic Expansion.
37c41ab1
CR
9713 (line 6)
9714* expansion, brace: Brace Expansion. (line 6)
9715* expansion, filename: Filename Expansion. (line 9)
e8ce775d 9716* expansion, parameter: Shell Parameter Expansion.
37c41ab1
CR
9717 (line 6)
9718* expansion, pathname: Filename Expansion. (line 9)
9719* expansion, tilde: Tilde Expansion. (line 6)
9720* expressions, arithmetic: Shell Arithmetic. (line 6)
e8ce775d 9721* expressions, conditional: Bash Conditional Expressions.
37c41ab1 9722 (line 6)
ed35cb4a
CR
9723* field: Definitions. (line 30)
9724* filename: Definitions. (line 35)
37c41ab1
CR
9725* filename expansion: Filename Expansion. (line 9)
9726* foreground: Job Control Basics. (line 6)
9727* functions, shell: Shell Functions. (line 6)
cce855bc 9728* history builtins: Bash History Builtins.
37c41ab1
CR
9729 (line 6)
9730* history events: Event Designators. (line 7)
9731* history expansion: History Interaction. (line 6)
e8ce775d 9732* history list: Bash History Facilities.
37c41ab1 9733 (line 6)
bb70624e 9734* History, how to use: Programmable Completion Builtins.
ed35cb4a
CR
9735 (line 224)
9736* identifier: Definitions. (line 51)
37c41ab1
CR
9737* initialization file, readline: Readline Init File. (line 6)
9738* installation: Basic Installation. (line 6)
e8ce775d 9739* interaction, readline: Readline Interaction.
37c41ab1
CR
9740 (line 6)
9741* interactive shell <1>: Interactive Shells. (line 6)
ac18b312 9742* interactive shell: Invoking Bash. (line 127)
37c41ab1 9743* internationalization: Locale Translation. (line 6)
ed35cb4a 9744* job: Definitions. (line 38)
c2a47ea9 9745* job control <1>: Job Control Basics. (line 6)
ed35cb4a 9746* job control: Definitions. (line 42)
e8ce775d 9747* kill ring: Readline Killing Commands.
37c41ab1 9748 (line 19)
e8ce775d 9749* killing text: Readline Killing Commands.
37c41ab1
CR
9750 (line 6)
9751* localization: Locale Translation. (line 6)
ac18b312 9752* login shell: Invoking Bash. (line 124)
37c41ab1 9753* matching, pattern: Pattern Matching. (line 6)
ed35cb4a
CR
9754* metacharacter: Definitions. (line 46)
9755* name: Definitions. (line 51)
37c41ab1 9756* native languages: Locale Translation. (line 6)
e8ce775d 9757* notation, readline: Readline Bare Essentials.
37c41ab1 9758 (line 6)
ed35cb4a 9759* operator, shell: Definitions. (line 57)
e8ce775d 9760* parameter expansion: Shell Parameter Expansion.
37c41ab1
CR
9761 (line 6)
9762* parameters: Shell Parameters. (line 6)
e8ce775d 9763* parameters, positional: Positional Parameters.
37c41ab1
CR
9764 (line 6)
9765* parameters, special: Special Parameters. (line 6)
9766* pathname expansion: Filename Expansion. (line 9)
9767* pattern matching: Pattern Matching. (line 6)
9768* pipeline: Pipelines. (line 6)
9769* POSIX: Definitions. (line 9)
9770* POSIX Mode: Bash POSIX Mode. (line 6)
ed35cb4a
CR
9771* process group: Definitions. (line 61)
9772* process group ID: Definitions. (line 65)
e8ce775d 9773* process substitution: Process Substitution.
37c41ab1 9774 (line 6)
bb70624e 9775* programmable completion: Programmable Completion.
37c41ab1
CR
9776 (line 6)
9777* prompting: Printing a Prompt. (line 6)
9778* quoting: Quoting. (line 6)
9779* quoting, ANSI: ANSI-C Quoting. (line 6)
bb70624e 9780* Readline, how to use: Job Control Variables.
37c41ab1
CR
9781 (line 24)
9782* redirection: Redirections. (line 6)
ed35cb4a 9783* reserved word: Definitions. (line 69)
e8ce775d 9784* restricted shell: The Restricted Shell.
37c41ab1 9785 (line 6)
ed35cb4a 9786* return status: Definitions. (line 74)
37c41ab1
CR
9787* shell arithmetic: Shell Arithmetic. (line 6)
9788* shell function: Shell Functions. (line 6)
9789* shell script: Shell Scripts. (line 6)
9790* shell variable: Shell Parameters. (line 6)
9791* shell, interactive: Interactive Shells. (line 6)
ed35cb4a 9792* signal: Definitions. (line 77)
37c41ab1 9793* signal handling: Signals. (line 6)
c2a47ea9 9794* special builtin <1>: Special Builtins. (line 6)
ed35cb4a 9795* special builtin: Definitions. (line 81)
37c41ab1
CR
9796* startup files: Bash Startup Files. (line 6)
9797* suspending jobs: Job Control Basics. (line 6)
9798* tilde expansion: Tilde Expansion. (line 6)
ed35cb4a 9799* token: Definitions. (line 85)
37c41ab1
CR
9800* translation, native languages: Locale Translation. (line 6)
9801* variable, shell: Shell Parameters. (line 6)
28ef6c31 9802* variables, readline: Readline Init File Syntax.
1c72c0cd 9803 (line 37)
ed35cb4a 9804* word: Definitions. (line 89)
37c41ab1 9805* word splitting: Word Splitting. (line 6)
e8ce775d 9806* yanking text: Readline Killing Commands.
37c41ab1 9807 (line 6)
ccc6cda3
JA
9808
9809
9810\1f
9811Tag Table:
ed35cb4a
CR
9812Node: Top\7f1338
9813Node: Introduction\7f3167
9814Node: What is Bash?\7f3395
9815Node: What is a shell?\7f4508
9816Node: Definitions\7f7048
9817Node: Basic Shell Features\7f9828
9818Node: Shell Syntax\7f11047
9819Node: Shell Operation\7f12077
9820Node: Quoting\7f13371
9821Node: Escape Character\7f14674
9822Node: Single Quotes\7f15159
9823Node: Double Quotes\7f15507
9824Node: ANSI-C Quoting\7f16632
9825Node: Locale Translation\7f17588
9826Node: Comments\7f18484
9827Node: Shell Commands\7f19102
9828Node: Simple Commands\7f19868
9829Node: Pipelines\7f20499
9830Node: Lists\7f22755
9831Node: Compound Commands\7f24484
9832Node: Looping Constructs\7f25268
9833Node: Conditional Constructs\7f27715
9834Node: Command Grouping\7f35721
9835Node: Shell Functions\7f37200
9836Node: Shell Parameters\7f41661
9837Node: Positional Parameters\7f43991
9838Node: Special Parameters\7f44891
9839Node: Shell Expansions\7f47855
9840Node: Brace Expansion\7f49780
9841Node: Tilde Expansion\7f52533
9842Node: Shell Parameter Expansion\7f54884
9843Node: Command Substitution\7f62584
9844Node: Arithmetic Expansion\7f63917
9845Node: Process Substitution\7f64767
9846Node: Word Splitting\7f65817
9847Node: Filename Expansion\7f67440
9848Node: Pattern Matching\7f69580
9849Node: Quote Removal\7f73219
9850Node: Redirections\7f73514
9851Node: Executing Commands\7f81657
9852Node: Simple Command Expansion\7f82327
9853Node: Command Search and Execution\7f84257
9854Node: Command Execution Environment\7f86594
9855Node: Environment\7f89393
9856Node: Exit Status\7f91053
9857Node: Signals\7f92674
9858Node: Shell Scripts\7f94642
9859Node: Shell Builtin Commands\7f97160
9860Node: Bourne Shell Builtins\7f98837
9861Node: Bash Builtins\7f116067
9862Node: Modifying Shell Behavior\7f138853
9863Node: The Set Builtin\7f139198
9864Node: The Shopt Builtin\7f148046
9865Node: Special Builtins\7f158908
9866Node: Shell Variables\7f159887
9867Node: Bourne Shell Variables\7f160327
9868Node: Bash Variables\7f162308
9869Node: Bash Features\7f183680
9870Node: Invoking Bash\7f184563
9871Node: Bash Startup Files\7f190372
9872Node: Interactive Shells\7f195341
9873Node: What is an Interactive Shell?\7f195751
9874Node: Is this Shell Interactive?\7f196400
9875Node: Interactive Shell Behavior\7f197215
9876Node: Bash Conditional Expressions\7f200495
9877Node: Shell Arithmetic\7f204074
9878Node: Aliases\7f206820
9879Node: Arrays\7f209392
9880Node: The Directory Stack\7f212741
9881Node: Directory Stack Builtins\7f213455
9882Node: Printing a Prompt\7f216347
9883Node: The Restricted Shell\7f219061
9884Node: Bash POSIX Mode\7f220893
9885Node: Job Control\7f228652
9886Node: Job Control Basics\7f229112
9887Node: Job Control Builtins\7f233621
9888Node: Job Control Variables\7f237948
9889Node: Command Line Editing\7f239106
9890Node: Introduction and Notation\7f240101
9891Node: Readline Interaction\7f241723
9892Node: Readline Bare Essentials\7f242914
9893Node: Readline Movement Commands\7f244703
9894Node: Readline Killing Commands\7f245668
9895Node: Readline Arguments\7f247588
9896Node: Searching\7f248632
9897Node: Readline Init File\7f250818
9898Node: Readline Init File Syntax\7f251965
9899Node: Conditional Init Constructs\7f265199
9900Node: Sample Init File\7f267732
9901Node: Bindable Readline Commands\7f270849
9902Node: Commands For Moving\7f272056
9903Node: Commands For History\7f272917
9904Node: Commands For Text\7f276072
9905Node: Commands For Killing\7f278745
9906Node: Numeric Arguments\7f280887
9907Node: Commands For Completion\7f282026
9908Node: Keyboard Macros\7f285793
9909Node: Miscellaneous Commands\7f286364
9910Node: Readline vi Mode\7f291675
9911Node: Programmable Completion\7f292589
9912Node: Programmable Completion Builtins\7f298422
9913Node: Using History Interactively\7f306805
9914Node: Bash History Facilities\7f307489
9915Node: Bash History Builtins\7f310403
9916Node: History Interaction\7f314260
9917Node: Event Designators\7f316965
9918Node: Word Designators\7f317980
9919Node: Modifiers\7f319619
9920Node: Installing Bash\7f321023
9921Node: Basic Installation\7f322160
9922Node: Compilers and Options\7f324852
9923Node: Compiling For Multiple Architectures\7f325593
9924Node: Installation Names\7f327257
9925Node: Specifying the System Type\7f328075
9926Node: Sharing Defaults\7f328791
9927Node: Operation Controls\7f329464
9928Node: Optional Features\7f330422
9929Node: Reporting Bugs\7f339353
9930Node: Major Differences From The Bourne Shell\7f340547
9931Node: GNU Free Documentation License\7f357234
9932Node: Indexes\7f379695
9933Node: Builtin Index\7f380149
9934Node: Reserved Word Index\7f386903
9935Node: Variable Index\7f389351
9936Node: Function Index\7f400938
9937Node: Concept Index\7f407670
ccc6cda3
JA
9938\1f
9939End Tag Table