]> git.ipfire.org Git - thirdparty/bash.git/blame - doc/bashref.info
commit bash-20111021 snapshot
[thirdparty/bash.git] / doc / bashref.info
CommitLineData
db31fb26 1This is bashref.info, produced by makeinfo version 4.13 from
7d92f73f 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
122f603c 5the Bash shell (version 4.2, 25 September 2011).
d3a24ed2 6
122f603c
CR
7 This is Edition 4.2, last updated 25 September 2011, of `The GNU
8Bash Reference Manual', for `Bash', Version 4.2.
d3a24ed2 9
d9e1f41e 10 Copyright (C) 1988-2011 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,
c302751c 18 Version 1.3 or any later version published by the Free Software
d3a24ed2 19 Foundation; with no Invariant Sections, with the Front-Cover texts
c2a47ea9 20 being "A GNU Manual", and with the Back-Cover Texts as in (a)
d3a24ed2 21 below. A copy of the license is included in the section entitled
c2a47ea9 22 "GNU Free Documentation License".
d3a24ed2 23
a9fac3b2
CR
24 (a) The FSF's Back-Cover Text is: You are free to copy and modify
25 this GNU manual. Buying copies from GNU Press supports the FSF in
26 developing GNU and promoting software freedom."
29d25b54 27
37c41ab1 28
d3a24ed2 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
122f603c 41the Bash shell (version 4.2, 25 September 2011).
ccc6cda3 42
122f603c
CR
43 This is Edition 4.2, last updated 25 September 2011, of `The GNU
44Bash Reference Manual', for `Bash', Version 4.2.
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
122f603c 49(`ksh'), and the C-shell (`csh' and its successor, `tcsh'). The
ccc6cda3
JA
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
74d0116b
CR
148separate utilities. For example, `cd', `break', `continue', and `exec'
149cannot be implemented outside of the shell because they directly
150manipulate the shell itself. The `history', `getopts', `kill', or `pwd'
151builtins, among others, could be implemented in separate utilities, but
152they are more convenient to use as builtin commands. All of the shell
153builtins are described in subsequent sections.
ccc6cda3
JA
154
155 While executing commands is essential, most of the power (and
156complexity) of shells is due to their embedded programming languages.
157Like any high-level language, the shell provides variables, flow
158control constructs, quoting, and functions.
159
bb70624e
JA
160 Shells offer features geared specifically for interactive use rather
161than to augment the programming language. These interactive features
d3a24ed2
CR
162include job control, command line editing, command history and aliases.
163Each of these features is described in this manual.
ccc6cda3
JA
164
165\1f
166File: bashref.info, Node: Definitions, Next: Basic Shell Features, Prev: Introduction, Up: Top
167
37c41ab1
CR
1682 Definitions
169*************
ccc6cda3 170
37c41ab1 171These definitions are used throughout the remainder of this manual.
ccc6cda3
JA
172
173`POSIX'
174 A family of open system standards based on Unix. Bash is
ac18b312
CR
175 primarily concerned with the Shell and Utilities portion of the
176 POSIX 1003.1 standard.
ccc6cda3
JA
177
178`blank'
179 A space or tab character.
180
181`builtin'
182 A command that is implemented internally by the shell itself,
183 rather than by an executable program somewhere in the file system.
184
185`control operator'
3d4e09aa 186 A `token' that performs a control function. It is a `newline' or
ed35cb4a
CR
187 one of the following: `||', `&&', `&', `;', `;;', `|', `|&', `(',
188 or `)'.
ccc6cda3
JA
189
190`exit status'
f73dda09
JA
191 The value returned by a command to its caller. The value is
192 restricted to eight bits, so the maximum value is 255.
ccc6cda3
JA
193
194`field'
195 A unit of text that is the result of one of the shell expansions.
196 After expansion, when executing a command, the resulting fields
197 are used as the command name and arguments.
198
199`filename'
200 A string of characters used to identify a file.
201
202`job'
203 A set of processes comprising a pipeline, and any processes
204 descended from it, that are all in the same process group.
205
206`job control'
d166f048
JA
207 A mechanism by which users can selectively stop (suspend) and
208 restart (resume) execution of processes.
ccc6cda3
JA
209
210`metacharacter'
211 A character that, when unquoted, separates words. A metacharacter
212 is a `blank' or one of the following characters: `|', `&', `;',
213 `(', `)', `<', or `>'.
214
215`name'
216 A `word' consisting solely of letters, numbers, and underscores,
217 and beginning with a letter or underscore. `Name's are used as
218 shell variable and function names. Also referred to as an
219 `identifier'.
220
221`operator'
222 A `control operator' or a `redirection operator'. *Note
a9fac3b2
CR
223 Redirections::, for a list of redirection operators. Operators
224 contain at least one unquoted `metacharacter'.
ccc6cda3
JA
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'
a9fac3b2
CR
255 A sequence of characters treated as a unit by the shell. Words
256 may not include unquoted `metacharacters'.
ccc6cda3
JA
257
258\1f
bb70624e 259File: bashref.info, Node: Basic Shell Features, Next: Shell Builtin Commands, Prev: Definitions, Up: Top
ccc6cda3 260
37c41ab1
CR
2613 Basic Shell Features
262**********************
ccc6cda3 263
37c41ab1
CR
264Bash is an acronym for `Bourne-Again SHell'. The Bourne shell is the
265traditional Unix shell originally written by Stephen Bourne. All of
266the Bourne shell builtin commands are available in Bash, The rules for
267evaluation and quoting are taken from the POSIX specification for the
268`standard' Unix shell.
ccc6cda3 269
cce855bc 270 This chapter briefly summarizes the shell's `building blocks':
ccc6cda3
JA
271commands, control structures, shell functions, shell parameters, shell
272expansions, redirections, which are a way to direct input and output
273from and to named files, and how the shell executes commands.
274
275* Menu:
276
277* Shell Syntax:: What your input means to the shell.
cce855bc 278* Shell Commands:: The types of commands you can use.
ccc6cda3 279* Shell Functions:: Grouping commands by name.
d3a24ed2
CR
280* Shell Parameters:: How the shell stores values.
281* Shell Expansions:: How Bash expands parameters and the various
ccc6cda3
JA
282 expansions available.
283* Redirections:: A way to control where input and output go.
284* Executing Commands:: What happens when you run a command.
285* Shell Scripts:: Executing files of shell commands.
286
287\1f
cce855bc 288File: bashref.info, Node: Shell Syntax, Next: Shell Commands, Up: Basic Shell Features
ccc6cda3 289
37c41ab1
CR
2903.1 Shell Syntax
291================
ccc6cda3
JA
292
293* Menu:
294
295* Shell Operation:: The basic operation of the shell.
ccc6cda3 296* Quoting:: How to remove the special meaning from characters.
ccc6cda3
JA
297* Comments:: How to specify comments.
298
bb70624e
JA
299 When the shell reads input, it proceeds through a sequence of
300operations. If the input indicates the beginning of a comment, the
301shell ignores the comment symbol (`#'), and the rest of that line.
302
303 Otherwise, roughly speaking, the shell reads its input and divides
304the input into words and operators, employing the quoting rules to
305select which meanings to assign various words and characters.
306
307 The shell then parses these tokens into commands and other
308constructs, removes the special meaning of certain words or characters,
309expands others, redirects input and output as needed, executes the
310specified command, waits for the command's exit status, and makes that
311exit status available for further inspection or processing.
312
ccc6cda3
JA
313\1f
314File: bashref.info, Node: Shell Operation, Next: Quoting, Up: Shell Syntax
315
37c41ab1
CR
3163.1.1 Shell Operation
317---------------------
ccc6cda3 318
37c41ab1 319The following is a brief description of the shell's operation when it
ccc6cda3
JA
320reads and executes a command. Basically, the shell does the following:
321
28ef6c31 322 1. Reads its input from a file (*note Shell Scripts::), from a string
ccc6cda3 323 supplied as an argument to the `-c' invocation option (*note
28ef6c31 324 Invoking Bash::), or from the user's terminal.
ccc6cda3
JA
325
326 2. Breaks the input into words and operators, obeying the quoting
6a8fd0ed 327 rules described in *note Quoting::. These tokens are separated by
ccc6cda3 328 `metacharacters'. Alias expansion is performed by this step
28ef6c31 329 (*note Aliases::).
ccc6cda3 330
cce855bc 331 3. Parses the tokens into simple and compound commands (*note Shell
28ef6c31 332 Commands::).
ccc6cda3 333
28ef6c31 334 4. Performs the various shell expansions (*note Shell Expansions::),
ccc6cda3 335 breaking the expanded tokens into lists of filenames (*note
28ef6c31 336 Filename Expansion::) and commands and arguments.
ccc6cda3 337
28ef6c31 338 5. Performs any necessary redirections (*note Redirections::) and
ccc6cda3
JA
339 removes the redirection operators and their operands from the
340 argument list.
341
28ef6c31 342 6. Executes the command (*note Executing Commands::).
ccc6cda3
JA
343
344 7. Optionally waits for the command to complete and collects its exit
28ef6c31 345 status (*note Exit Status::).
ccc6cda3
JA
346
347
348\1f
349File: bashref.info, Node: Quoting, Next: Comments, Prev: Shell Operation, Up: Shell Syntax
350
37c41ab1
CR
3513.1.2 Quoting
352-------------
ccc6cda3
JA
353
354* Menu:
355
356* Escape Character:: How to remove the special meaning from a single
357 character.
358* Single Quotes:: How to inhibit all interpretation of a sequence
359 of characters.
360* Double Quotes:: How to suppress most of the interpretation of a
361 sequence of characters.
362* ANSI-C Quoting:: How to expand ANSI-C sequences in quoted strings.
ccc6cda3
JA
363* Locale Translation:: How to translate strings into different languages.
364
365 Quoting is used to remove the special meaning of certain characters
366or words to the shell. Quoting can be used to disable special
367treatment for special characters, to prevent reserved words from being
368recognized as such, and to prevent parameter expansion.
369
28ef6c31 370 Each of the shell metacharacters (*note Definitions::) has special
cce855bc 371meaning to the shell and must be quoted if it is to represent itself.
01ed5ba4
CR
372When the command history expansion facilities are being used (*note
373History Interaction::), the HISTORY EXPANSION character, usually `!',
374must be quoted to prevent history expansion. *Note Bash History
375Facilities::, for more details concerning history expansion.
d3a24ed2
CR
376
377 There are three quoting mechanisms: the ESCAPE CHARACTER, single
378quotes, and double quotes.
ccc6cda3
JA
379
380\1f
381File: bashref.info, Node: Escape Character, Next: Single Quotes, Up: Quoting
382
37c41ab1
CR
3833.1.2.1 Escape Character
384........................
ccc6cda3 385
37c41ab1
CR
386A non-quoted backslash `\' is the Bash escape character. It preserves
387the literal value of the next character that follows, with the
388exception of `newline'. If a `\newline' pair appears, and the
cce855bc
JA
389backslash itself is not quoted, the `\newline' is treated as a line
390continuation (that is, it is removed from the input stream and
391effectively ignored).
ccc6cda3
JA
392
393\1f
394File: bashref.info, Node: Single Quotes, Next: Double Quotes, Prev: Escape Character, Up: Quoting
395
37c41ab1
CR
3963.1.2.2 Single Quotes
397.....................
ccc6cda3 398
37c41ab1
CR
399Enclosing characters in single quotes (`'') preserves the literal value
400of each character within the quotes. A single quote may not occur
bb70624e 401between single quotes, even when preceded by a backslash.
ccc6cda3
JA
402
403\1f
404File: bashref.info, Node: Double Quotes, Next: ANSI-C Quoting, Prev: Single Quotes, Up: Quoting
405
37c41ab1
CR
4063.1.2.3 Double Quotes
407.....................
ccc6cda3 408
37c41ab1
CR
409Enclosing characters in double quotes (`"') preserves the literal value
410of all characters within the quotes, with the exception of `$', ``',
01ed5ba4
CR
411`\', and, when history expansion is enabled, `!'. The characters `$'
412and ``' retain their special meaning within double quotes (*note Shell
413Expansions::). The backslash retains its special meaning only when
414followed by one of the following characters: `$', ``', `"', `\', or
415`newline'. Within double quotes, backslashes that are followed by one
416of these characters are removed. Backslashes preceding characters
417without a special meaning are left unmodified. A double quote may be
418quoted within double quotes by preceding it with a backslash. If
419enabled, history expansion will be performed unless an `!' appearing in
420double quotes is escaped using a backslash. The backslash preceding
421the `!' is not removed.
ccc6cda3
JA
422
423 The special parameters `*' and `@' have special meaning when in
28ef6c31 424double quotes (*note Shell Parameter Expansion::).
ccc6cda3
JA
425
426\1f
427File: bashref.info, Node: ANSI-C Quoting, Next: Locale Translation, Prev: Double Quotes, Up: Quoting
428
37c41ab1
CR
4293.1.2.4 ANSI-C Quoting
430......................
ccc6cda3 431
37c41ab1
CR
432Words of the form `$'STRING'' are treated specially. The word expands
433to STRING, with backslash-escaped characters replaced as specified by
434the ANSI C standard. Backslash escape sequences, if present, are
435decoded as follows:
ccc6cda3
JA
436
437`\a'
438 alert (bell)
439
440`\b'
441 backspace
442
443`\e'
984a1947 444`\E'
ccc6cda3
JA
445 an escape character (not ANSI C)
446
447`\f'
448 form feed
449
450`\n'
451 newline
452
453`\r'
454 carriage return
455
456`\t'
457 horizontal tab
458
459`\v'
460 vertical tab
461
462`\\'
463 backslash
464
bb70624e
JA
465`\''
466 single quote
467
984a1947
CR
468`\"'
469 double quote
470
ccc6cda3 471`\NNN'
f73dda09 472 the eight-bit character whose value is the octal value NNN (one to
cce855bc
JA
473 three digits)
474
f73dda09
JA
475`\xHH'
476 the eight-bit character whose value is the hexadecimal value HH
477 (one or two hex digits)
ccc6cda3 478
220537f2
CR
479`\uHHHH'
480 the Unicode (ISO/IEC 10646) character whose value is the
481 hexadecimal value HHHH (one to four hex digits)
482
483`\UHHHHHHHH'
484 the Unicode (ISO/IEC 10646) character whose value is the
485 hexadecimal value HHHHHHHH (one to eight hex digits)
486
7117c2d2
JA
487`\cX'
488 a control-X character
489
bb70624e
JA
490The expanded result is single-quoted, as if the dollar sign had not
491been present.
ccc6cda3
JA
492
493\1f
494File: bashref.info, Node: Locale Translation, Prev: ANSI-C Quoting, Up: Quoting
495
37c41ab1
CR
4963.1.2.5 Locale-Specific Translation
497...................................
ccc6cda3 498
37c41ab1
CR
499A double-quoted string preceded by a dollar sign (`$') will cause the
500string to be translated according to the current locale. If the
ccc6cda3
JA
501current locale is `C' or `POSIX', the dollar sign is ignored. If the
502string is translated and replaced, the replacement is double-quoted.
503
28ef6c31
JA
504 Some systems use the message catalog selected by the `LC_MESSAGES'
505shell variable. Others create the name of the message catalog from the
506value of the `TEXTDOMAIN' shell variable, possibly adding a suffix of
507`.mo'. If you use the `TEXTDOMAIN' variable, you may need to set the
508`TEXTDOMAINDIR' variable to the location of the message catalog files.
f73dda09
JA
509Still others use both variables in this fashion:
510`TEXTDOMAINDIR'/`LC_MESSAGES'/LC_MESSAGES/`TEXTDOMAIN'.mo.
28ef6c31 511
ccc6cda3
JA
512\1f
513File: bashref.info, Node: Comments, Prev: Quoting, Up: Shell Syntax
514
37c41ab1
CR
5153.1.3 Comments
516--------------
ccc6cda3 517
37c41ab1 518In a non-interactive shell, or an interactive shell in which the
ccc6cda3 519`interactive_comments' option to the `shopt' builtin is enabled (*note
d3ad40de
CR
520The Shopt Builtin::), a word beginning with `#' causes that word and
521all remaining characters on that line to be ignored. An interactive
522shell without the `interactive_comments' option enabled does not allow
ccc6cda3 523comments. The `interactive_comments' option is on by default in
bb70624e
JA
524interactive shells. *Note Interactive Shells::, for a description of
525what makes a shell interactive.
cce855bc
JA
526
527\1f
528File: bashref.info, Node: Shell Commands, Next: Shell Functions, Prev: Shell Syntax, Up: Basic Shell Features
529
37c41ab1
CR
5303.2 Shell Commands
531==================
cce855bc 532
37c41ab1 533A simple shell command such as `echo a b c' consists of the command
bb70624e
JA
534itself followed by arguments, separated by spaces.
535
536 More complex shell commands are composed of simple commands arranged
537together in a variety of ways: in a pipeline in which the output of one
538command becomes the input of a second, in a loop or conditional
539construct, or in some other grouping.
540
cce855bc
JA
541* Menu:
542
543* Simple Commands:: The most common type of command.
544* Pipelines:: Connecting the input and output of several
545 commands.
546* Lists:: How to execute commands sequentially.
d3a24ed2 547* Compound Commands:: Shell commands for control flow.
8e1a6eaa 548* Coprocesses:: Two-way communication between commands.
220537f2 549* GNU Parallel:: Running commands in parallel.
ccc6cda3
JA
550
551\1f
cce855bc 552File: bashref.info, Node: Simple Commands, Next: Pipelines, Up: Shell Commands
ccc6cda3 553
37c41ab1
CR
5543.2.1 Simple Commands
555---------------------
ccc6cda3 556
37c41ab1
CR
557A simple command is the kind of command encountered most often. It's
558just a sequence of words separated by `blank's, terminated by one of
559the shell's control operators (*note Definitions::). The first word
28ef6c31 560generally specifies a command to be executed, with the rest of the
bb70624e 561words being that command's arguments.
ccc6cda3 562
28ef6c31 563 The return status (*note Exit Status::) of a simple command is its
bb70624e
JA
564exit status as provided by the POSIX 1003.1 `waitpid' function, or
565128+N if the command was terminated by signal N.
ccc6cda3
JA
566
567\1f
cce855bc 568File: bashref.info, Node: Pipelines, Next: Lists, Prev: Simple Commands, Up: Shell Commands
ccc6cda3 569
37c41ab1
CR
5703.2.2 Pipelines
571---------------
ccc6cda3 572
ed35cb4a
CR
573A `pipeline' is a sequence of simple commands separated by one of the
574control operators `|' or `|&'.
ccc6cda3
JA
575
576 The format for a pipeline is
122f603c 577 [time [-p]] [!] COMMAND1 [ | or |& COMMAND2 ] ...
ccc6cda3 578
f73dda09
JA
579The output of each command in the pipeline is connected via a pipe to
580the input of the next command. That is, each command reads the
ed35cb4a
CR
581previous command's output. This connection is performed before any
582redirections specified by the command.
583
122f603c
CR
584 If `|&' is used, COMMAND1's standard output and standard error are
585connected to COMMAND2's standard input through the pipe; it is
586shorthand for `2>&1 |'. This implicit redirection of the standard
587error is performed after any redirections specified by the command.
ccc6cda3
JA
588
589 The reserved word `time' causes timing statistics to be printed for
cce855bc
JA
590the pipeline once it finishes. The statistics currently consist of
591elapsed (wall-clock) time and user and system time consumed by the
592command's execution. The `-p' option changes the output format to that
9ec5ed66
CR
593specified by POSIX. When the shell is in POSIX mode (*note Bash POSIX
594Mode::), it does not recognize `time' as a reserved word if the next
595token begins with a `-'. The `TIMEFORMAT' variable may be set to a
596format string that specifies how the timing information should be
597displayed. *Note Bash Variables::, for a description of the available
598formats. The use of `time' as a reserved word permits the timing of
599shell builtins, shell functions, and pipelines. An external `time'
600command cannot time these easily.
cce855bc 601
220537f2
CR
602 When the shell is in POSIX mode (*note Bash POSIX Mode::), `time'
603may be followed by a newline. In this case, the shell displays the
604total user and system time consumed by the shell and its children. The
605`TIMEFORMAT' variable may be used to specify the format of the time
606information.
607
28ef6c31 608 If the pipeline is not executed asynchronously (*note Lists::), the
cce855bc 609shell waits for all commands in the pipeline to complete.
ccc6cda3 610
cce855bc 611 Each command in a pipeline is executed in its own subshell (*note
28ef6c31 612Command Execution Environment::). The exit status of a pipeline is the
5e13499c
CR
613exit status of the last command in the pipeline, unless the `pipefail'
614option is enabled (*note The Set Builtin::). If `pipefail' is enabled,
615the pipeline's return status is the value of the last (rightmost)
616command to exit with a non-zero status, or zero if all commands exit
617successfully. If the reserved word `!' precedes the pipeline, the exit
618status is the logical negation of the exit status as described above.
619The shell waits for all commands in the pipeline to terminate before
620returning a value.
ccc6cda3
JA
621
622\1f
d3a24ed2 623File: bashref.info, Node: Lists, Next: Compound Commands, Prev: Pipelines, Up: Shell Commands
ccc6cda3 624
37c41ab1
CR
6253.2.3 Lists of Commands
626-----------------------
ccc6cda3 627
37c41ab1
CR
628A `list' is a sequence of one or more pipelines separated by one of the
629operators `;', `&', `&&', or `||', and optionally terminated by one of
630`;', `&', or a `newline'.
ccc6cda3
JA
631
632 Of these list operators, `&&' and `||' have equal precedence,
633followed by `;' and `&', which have equal precedence.
634
7117c2d2
JA
635 A sequence of one or more newlines may appear in a `list' to delimit
636commands, equivalent to a semicolon.
637
ccc6cda3 638 If a command is terminated by the control operator `&', the shell
cce855bc
JA
639executes the command asynchronously in a subshell. This is known as
640executing the command in the BACKGROUND. The shell does not wait for
bb70624e 641the command to finish, and the return status is 0 (true). When job
28ef6c31 642control is not active (*note Job Control::), the standard input for
bb70624e
JA
643asynchronous commands, in the absence of any explicit redirections, is
644redirected from `/dev/null'.
cce855bc
JA
645
646 Commands separated by a `;' are executed sequentially; the shell
647waits for each command to terminate in turn. The return status is the
648exit status of the last command executed.
ccc6cda3 649
6a8fd0ed
CR
650 AND and OR lists are sequences of one or more pipelines separated by
651the control operators `&&' and `||', respectively. AND and OR lists
652are executed with left associativity.
653
654 An AND list has the form
bb70624e 655 COMMAND1 && COMMAND2
ccc6cda3 656
bb70624e
JA
657COMMAND2 is executed if, and only if, COMMAND1 returns an exit status
658of zero.
ccc6cda3
JA
659
660 An OR list has the form
bb70624e 661 COMMAND1 || COMMAND2
ccc6cda3 662
bb70624e 663COMMAND2 is executed if, and only if, COMMAND1 returns a non-zero exit
ccc6cda3
JA
664status.
665
666 The return status of AND and OR lists is the exit status of the last
667command executed in the list.
668
669\1f
8e1a6eaa 670File: bashref.info, Node: Compound Commands, Next: Coprocesses, Prev: Lists, Up: Shell Commands
d3a24ed2 671
37c41ab1
CR
6723.2.4 Compound Commands
673-----------------------
d3a24ed2
CR
674
675* Menu:
676
677* Looping Constructs:: Shell commands for iterative action.
678* Conditional Constructs:: Shell commands for conditional execution.
679* Command Grouping:: Ways to group commands.
680
681 Compound commands are the shell programming constructs. Each
682construct begins with a reserved word or control operator and is
683terminated by a corresponding reserved word or operator. Any
684redirections (*note Redirections::) associated with a compound command
685apply to all commands within that compound command unless explicitly
686overridden.
687
74d0116b
CR
688 In most cases a list of commands in a compound command's description
689may be separated from the rest of the command by one or more newlines,
690and may be followed by a newline in place of a semicolon.
691
d3a24ed2
CR
692 Bash provides looping constructs, conditional commands, and
693mechanisms to group commands and execute them as a unit.
694
695\1f
696File: bashref.info, Node: Looping Constructs, Next: Conditional Constructs, Up: Compound Commands
ccc6cda3 697
37c41ab1
CR
6983.2.4.1 Looping Constructs
699..........................
ccc6cda3 700
37c41ab1 701Bash supports the following looping constructs.
ccc6cda3 702
bb70624e 703 Note that wherever a `;' appears in the description of a command's
cce855bc
JA
704syntax, it may be replaced with one or more newlines.
705
ccc6cda3
JA
706`until'
707 The syntax of the `until' command is:
122f603c 708
ccc6cda3 709 until TEST-COMMANDS; do CONSEQUENT-COMMANDS; done
122f603c 710
cce855bc
JA
711 Execute CONSEQUENT-COMMANDS as long as TEST-COMMANDS has an exit
712 status which is not zero. The return status is the exit status of
713 the last command executed in CONSEQUENT-COMMANDS, or zero if none
714 was executed.
ccc6cda3
JA
715
716`while'
717 The syntax of the `while' command is:
122f603c 718
ccc6cda3
JA
719 while TEST-COMMANDS; do CONSEQUENT-COMMANDS; done
720
cce855bc
JA
721 Execute CONSEQUENT-COMMANDS as long as TEST-COMMANDS has an exit
722 status of zero. The return status is the exit status of the last
723 command executed in CONSEQUENT-COMMANDS, or zero if none was
724 executed.
ccc6cda3
JA
725
726`for'
727 The syntax of the `for' command is:
728
4a8bb13f 729 for NAME [ [in [WORDS ...] ] ; ] do COMMANDS; done
122f603c 730
cce855bc
JA
731 Expand WORDS, and execute COMMANDS once for each member in the
732 resultant list, with NAME bound to the current member. If `in
bb70624e
JA
733 WORDS' is not present, the `for' command executes the COMMANDS
734 once for each positional parameter that is set, as if `in "$@"'
28ef6c31 735 had been specified (*note Special Parameters::). The return
bb70624e
JA
736 status is the exit status of the last command that executes. If
737 there are no items in the expansion of WORDS, no commands are
738 executed, and the return status is zero.
739
740 An alternate form of the `for' command is also supported:
741
742 for (( EXPR1 ; EXPR2 ; EXPR3 )) ; do COMMANDS ; done
122f603c 743
bb70624e 744 First, the arithmetic expression EXPR1 is evaluated according to
28ef6c31 745 the rules described below (*note Shell Arithmetic::). The
bb70624e
JA
746 arithmetic expression EXPR2 is then evaluated repeatedly until it
747 evaluates to zero. Each time EXPR2 evaluates to a non-zero value,
748 COMMANDS are executed and the arithmetic expression EXPR3 is
749 evaluated. If any expression is omitted, it behaves as if it
750 evaluates to 1. The return value is the exit status of the last
9ec5ed66 751 command in COMMANDS that is executed, or false if any of the
bb70624e 752 expressions is invalid.
ccc6cda3 753
28ef6c31 754 The `break' and `continue' builtins (*note Bourne Shell Builtins::)
ccc6cda3
JA
755may be used to control loop execution.
756
757\1f
d3a24ed2 758File: bashref.info, Node: Conditional Constructs, Next: Command Grouping, Prev: Looping Constructs, Up: Compound Commands
ccc6cda3 759
37c41ab1
CR
7603.2.4.2 Conditional Constructs
761..............................
ccc6cda3
JA
762
763`if'
764 The syntax of the `if' command is:
765
766 if TEST-COMMANDS; then
767 CONSEQUENT-COMMANDS;
768 [elif MORE-TEST-COMMANDS; then
769 MORE-CONSEQUENTS;]
770 [else ALTERNATE-CONSEQUENTS;]
771 fi
772
cce855bc
JA
773 The TEST-COMMANDS list is executed, and if its return status is
774 zero, the CONSEQUENT-COMMANDS list is executed. If TEST-COMMANDS
775 returns a non-zero status, each `elif' list is executed in turn,
776 and if its exit status is zero, the corresponding MORE-CONSEQUENTS
777 is executed and the command completes. If `else
778 ALTERNATE-CONSEQUENTS' is present, and the final command in the
779 final `if' or `elif' clause has a non-zero exit status, then
780 ALTERNATE-CONSEQUENTS is executed. The return status is the exit
781 status of the last command executed, or zero if no condition
782 tested true.
ccc6cda3
JA
783
784`case'
785 The syntax of the `case' command is:
786
122f603c 787 case WORD in [ [(] PATTERN [| PATTERN]...) COMMAND-LIST ;;]... esac
ccc6cda3 788
cce855bc 789 `case' will selectively execute the COMMAND-LIST corresponding to
9d2b70f0 790 the first PATTERN that matches WORD. If the shell option
6a8fd0ed 791 `nocasematch' (see the description of `shopt' in *note The Shopt
d3ad40de 792 Builtin::) is enabled, the match is performed without regard to
9d2b70f0 793 the case of alphabetic characters. The `|' is used to separate
cce855bc
JA
794 multiple patterns, and the `)' operator terminates a pattern list.
795 A list of patterns and an associated command-list is known as a
ed35cb4a
CR
796 CLAUSE.
797
c302751c 798 Each clause must be terminated with `;;', `;&', or `;;&'. The
ed35cb4a 799 WORD undergoes tilde expansion, parameter expansion, command
cce855bc
JA
800 substitution, arithmetic expansion, and quote removal before
801 matching is attempted. Each PATTERN undergoes tilde expansion,
802 parameter expansion, command substitution, and arithmetic
803 expansion.
804
805 There may be an arbitrary number of `case' clauses, each terminated
ed35cb4a
CR
806 by a `;;', `;&', or `;;&'. The first pattern that matches
807 determines the command-list that is executed.
ccc6cda3
JA
808
809 Here is an example using `case' in a script that could be used to
810 describe one interesting feature of an animal:
811
812 echo -n "Enter the name of an animal: "
813 read ANIMAL
814 echo -n "The $ANIMAL has "
815 case $ANIMAL in
816 horse | dog | cat) echo -n "four";;
817 man | kangaroo ) echo -n "two";;
818 *) echo -n "an unknown number of";;
819 esac
820 echo " legs."
821
ed35cb4a
CR
822 If the `;;' operator is used, no subsequent matches are attempted
823 after the first pattern match. Using `;&' in place of `;;'
824 causes execution to continue with the COMMAND-LIST associated with
825 the next clause, if any. Using `;;&' in place of `;;' causes the
826 shell to test the patterns in the next clause, if any, and execute
827 any associated COMMAND-LIST on a successful match.
828
cce855bc
JA
829 The return status is zero if no PATTERN is matched. Otherwise, the
830 return status is the exit status of the COMMAND-LIST executed.
831
832`select'
833 The `select' construct allows the easy generation of menus. It
834 has almost the same syntax as the `for' command:
835
836 select NAME [in WORDS ...]; do COMMANDS; done
837
838 The list of words following `in' is expanded, generating a list of
839 items. The set of expanded words is printed on the standard error
840 output stream, each preceded by a number. If the `in WORDS' is
841 omitted, the positional parameters are printed, as if `in "$@"'
d3ad40de 842 had been specified. The `PS3' prompt is then displayed and a line
cce855bc
JA
843 is read from the standard input. If the line consists of a number
844 corresponding to one of the displayed words, then the value of
845 NAME is set to that word. If the line is empty, the words and
846 prompt are displayed again. If `EOF' is read, the `select'
847 command completes. Any other value read causes NAME to be set to
848 null. The line read is saved in the variable `REPLY'.
849
f73dda09
JA
850 The COMMANDS are executed after each selection until a `break'
851 command is executed, at which point the `select' command completes.
cce855bc
JA
852
853 Here is an example that allows the user to pick a filename from the
854 current directory, and displays the name and index of the file
855 selected.
856
857 select fname in *;
858 do
859 echo you picked $fname \($REPLY\)
860 break;
861 done
862
ccc6cda3
JA
863`((...))'
864 (( EXPRESSION ))
865
cce855bc 866 The arithmetic EXPRESSION is evaluated according to the rules
28ef6c31 867 described below (*note Shell Arithmetic::). If the value of the
cce855bc
JA
868 expression is non-zero, the return status is 0; otherwise the
869 return status is 1. This is exactly equivalent to
ccc6cda3 870 let "EXPRESSION"
cce855bc
JA
871 *Note Bash Builtins::, for a full description of the `let' builtin.
872
873`[[...]]'
874 [[ EXPRESSION ]]
875
876 Return a status of 0 or 1 depending on the evaluation of the
877 conditional expression EXPRESSION. Expressions are composed of
6a8fd0ed 878 the primaries described below in *note Bash Conditional
cce855bc
JA
879 Expressions::. Word splitting and filename expansion are not
880 performed on the words between the `[[' and `]]'; tilde expansion,
881 parameter and variable expansion, arithmetic expansion, command
882 substitution, process substitution, and quote removal are
d3a24ed2
CR
883 performed. Conditional operators such as `-f' must be unquoted to
884 be recognized as primaries.
cce855bc 885
54a1fa7c 886 When used with `[[', the `<' and `>' operators sort
d5362af8
CR
887 lexicographically using the current locale.
888
cce855bc
JA
889 When the `==' and `!=' operators are used, the string to the right
890 of the operator is considered a pattern and matched according to
6a8fd0ed 891 the rules described below in *note Pattern Matching::. If the
9d2b70f0 892 shell option `nocasematch' (see the description of `shopt' in
6a8fd0ed 893 *note The Shopt Builtin::) is enabled, the match is performed
d3ad40de
CR
894 without regard to the case of alphabetic characters. The return
895 value is 0 if the string matches (`==') or does not match
896 (`!=')the pattern, and 1 otherwise. Any part of the pattern may
d9e1f41e 897 be quoted to force the quoted portion to be matched as a string.
cce855bc 898
5e13499c
CR
899 An additional binary operator, `=~', is available, with the same
900 precedence as `==' and `!='. When it is used, the string to the
901 right of the operator is considered an extended regular expression
902 and matched accordingly (as in regex3)). The return value is 0 if
903 the string matches the pattern, and 1 otherwise. If the regular
904 expression is syntactically incorrect, the conditional
9d2b70f0 905 expression's return value is 2. If the shell option `nocasematch'
6a8fd0ed 906 (see the description of `shopt' in *note The Shopt Builtin::) is
5e13499c 907 enabled, the match is performed without regard to the case of
3d4e09aa 908 alphabetic characters. Any part of the pattern may be quoted to
d9e1f41e
CR
909 force the quoted portion to be matched as a string. Substrings
910 matched by parenthesized subexpressions within the regular
911 expression are saved in the array variable `BASH_REMATCH'. The
912 element of `BASH_REMATCH' with index 0 is the portion of the string
913 matching the entire regular expression. The element of
914 `BASH_REMATCH' with index N is the portion of the string matching
915 the Nth parenthesized subexpression.
5e13499c 916
cce855bc
JA
917 Expressions may be combined using the following operators, listed
918 in decreasing order of precedence:
919
920 `( EXPRESSION )'
921 Returns the value of EXPRESSION. This may be used to
922 override the normal precedence of operators.
923
924 `! EXPRESSION'
925 True if EXPRESSION is false.
926
927 `EXPRESSION1 && EXPRESSION2'
928 True if both EXPRESSION1 and EXPRESSION2 are true.
929
930 `EXPRESSION1 || EXPRESSION2'
931 True if either EXPRESSION1 or EXPRESSION2 is true.
122f603c
CR
932
933 The `&&' and `||' operators do not evaluate [BEXPRESSION2 if the
7117c2d2
JA
934 value of EXPRESSION1 is sufficient to determine the return value
935 of the entire conditional expression.
ccc6cda3
JA
936
937\1f
d3a24ed2 938File: bashref.info, Node: Command Grouping, Prev: Conditional Constructs, Up: Compound Commands
ccc6cda3 939
37c41ab1
CR
9403.2.4.3 Grouping Commands
941.........................
ccc6cda3 942
37c41ab1
CR
943Bash provides two ways to group a list of commands to be executed as a
944unit. When commands are grouped, redirections may be applied to the
ccc6cda3
JA
945entire command list. For example, the output of all the commands in
946the list may be redirected to a single stream.
947
948`()'
949 ( LIST )
950
951 Placing a list of commands between parentheses causes a subshell
d3a24ed2
CR
952 environment to be created (*note Command Execution Environment::),
953 and each of the commands in LIST to be executed in that subshell.
954 Since the LIST is executed in a subshell, variable assignments do
955 not remain in effect after the subshell completes.
ccc6cda3
JA
956
957`{}'
958 { LIST; }
959
960 Placing a list of commands between curly braces causes the list to
961 be executed in the current shell context. No subshell is created.
cce855bc 962 The semicolon (or newline) following LIST is required.
ccc6cda3
JA
963
964 In addition to the creation of a subshell, there is a subtle
965difference between these two constructs due to historical reasons. The
966braces are `reserved words', so they must be separated from the LIST by
d7f49990
CR
967`blank's or other shell metacharacters. The parentheses are
968`operators', and are recognized as separate tokens by the shell even if
969they are not separated from the LIST by whitespace.
ccc6cda3
JA
970
971 The exit status of both of these constructs is the exit status of
972LIST.
973
8e1a6eaa 974\1f
220537f2 975File: bashref.info, Node: Coprocesses, Next: GNU Parallel, Prev: Compound Commands, Up: Shell Commands
8e1a6eaa
CR
976
9773.2.5 Coprocesses
978-----------------
979
980A `coprocess' is a shell command preceded by the `coproc' reserved word.
981A coprocess is executed asynchronously in a subshell, as if the command
982had been terminated with the `&' control operator, with a two-way pipe
983established between the executing shell and the coprocess.
984
985 The format for a coprocess is:
122f603c 986 coproc [NAME] COMMAND [REDIRECTIONS]
8e1a6eaa
CR
987
988This creates a coprocess named NAME. If NAME is not supplied, the
db31fb26
CR
989default name is COPROC. NAME must not be supplied if COMMAND is a
990simple command (*note Simple Commands::); otherwise, it is interpreted
991as the first word of the simple command.
8e1a6eaa 992
122f603c
CR
993 When the coprocess is executed, the shell creates an array variable
994(*note Arrays::) named `NAME' in the context of the executing shell.
995The standard output of COMMAND is connected via a pipe to a file
8e1a6eaa 996descriptor in the executing shell, and that file descriptor is assigned
122f603c
CR
997to `NAME'[0]. The standard input of COMMAND is connected via a pipe to
998a file descriptor in the executing shell, and that file descriptor is
999assigned to `NAME'[1]. This pipe is established before any
1000redirections specified by the command (*note Redirections::). The file
1001descriptors can be utilized as arguments to shell commands and
1002redirections using standard word expansions.
8e1a6eaa 1003
e05be32d 1004 The process ID of the shell spawned to execute the coprocess is
122f603c 1005available as the value of the variable `NAME'_PID. The `wait' builtin
8e1a6eaa
CR
1006command may be used to wait for the coprocess to terminate.
1007
1008 The return status of a coprocess is the exit status of COMMAND.
1009
220537f2
CR
1010\1f
1011File: bashref.info, Node: GNU Parallel, Prev: Coprocesses, Up: Shell Commands
1012
10133.2.6 GNU Parallel
1014------------------
1015
1016GNU Parallel, as its name suggests, can be used to build and run
1017commands in parallel. You may run the same command with different
1018arguments, whether they are filenames, usernames, hostnames, or lines
1019read from files.
1020
1021 For a complete description, refer to the GNU Parallel documentation.
1022A few examples should provide a brief introduction to its use.
1023
1024 For example, it is easy to prefix each line in a text file with a
1025specified string:
1026 cat file | parallel -k echo prefix_string
1027 The `-k' option is required to preserve the lines' order.
1028
1029 Similarly, you can append a specified string to each line in a text
1030file:
1031 cat file | parallel -k echo {} append_string
1032
1033 You can use Parallel to move files from the current directory when
1034the number of files is too large to process with one `mv' invocation:
1035 ls | parallel mv {} destdir
1036
1037 As you can see, the {} is replaced with each line read from standard
1038input. This will run as many `mv' commands as there are files in the
1039current directory. You can emulate a parallel `xargs' by adding the
1040`-X' option:
1041 ls | parallel -X mv {} destdir
1042
1043 GNU Parallel can replace certain common idioms that operate on lines
1044read from a file (in this case, filenames):
1045 for x in $(cat list); do
1046 do-something1 $x config-$x
1047 do-something2 < $x
1048 done | process-output
1049
1050with a more compact syntax reminiscent of lambdas:
1051 cat list | parallel "do-something1 {} config-{} ; do-something2 < {}" | process-output
1052
1053 Parallel provides a built-in mechanism to remove filename
1054extensions, which lends itself to batch file transformations or
1055renaming:
1056 ls *.gz | parallel -j+0 "zcat {} | bzip2 >{.}.bz2 && rm {}"
1057 This will recompress all files in the current directory with names
1058ending in .gz using bzip2, running one job per CPU (-j+0) in parallel.
1059
1060 If a command generates output, you may want to preserve the input
1061order in the output. For instance, the following command
1062 { echo foss.org.my ; echo debian.org; echo freenetproject.org; } | parallel traceroute
1063 will display as output the traceroute invocation that finishes
1064first. Using the `-k' option, as we saw above
1065 { echo foss.org.my ; echo debian.org; echo freenetproject.org; } | parallel -k traceroute
1066 will ensure that the output of `traceroute foss.org.my' is displayed
1067first.
1068
ccc6cda3 1069\1f
cce855bc 1070File: bashref.info, Node: Shell Functions, Next: Shell Parameters, Prev: Shell Commands, Up: Basic Shell Features
ccc6cda3 1071
37c41ab1
CR
10723.3 Shell Functions
1073===================
ccc6cda3 1074
37c41ab1
CR
1075Shell functions are a way to group commands for later execution using a
1076single name for the group. They are executed just like a "regular"
1077command. When the name of a shell function is used as a simple command
1078name, the list of commands associated with that function name is
1079executed. Shell functions are executed in the current shell context;
1080no new process is created to interpret them.
ccc6cda3 1081
37c41ab1 1082 Functions are declared using this syntax:
9ec5ed66 1083 NAME () COMPOUND-COMMAND [ REDIRECTIONS ]
9ec5ed66 1084
122f603c
CR
1085 or
1086
1087 function NAME [()] COMPOUND-COMMAND [ REDIRECTIONS ]
ccc6cda3
JA
1088
1089 This defines a shell function named NAME. The reserved word
cce855bc 1090`function' is optional. If the `function' reserved word is supplied,
d3a24ed2
CR
1091the parentheses are optional. The BODY of the function is the compound
1092command COMPOUND-COMMAND (*note Compound Commands::). That command is
1093usually a LIST enclosed between { and }, but may be any compound
1094command listed above. COMPOUND-COMMAND is executed whenever NAME is
122f603c
CR
1095specified as the name of a command. When the shell is in POSIX mode
1096(*note Bash POSIX Mode::), NAME may not be the same as one of the
1097special builtins (*note Special Builtins::). Any redirections (*note
d3a24ed2
CR
1098Redirections::) associated with the shell function are performed when
1099the function is executed.
1100
ac18b312
CR
1101 A function definition may be deleted using the `-f' option to the
1102`unset' builtin (*note Bourne Shell Builtins::).
1103
d3a24ed2
CR
1104 The exit status of a function definition is zero unless a syntax
1105error occurs or a readonly function with the same name already exists.
1106When executed, the exit status of a function is the exit status of the
1107last command executed in the body.
1108
1109 Note that for historical reasons, in the most common usage the curly
1110braces that surround the body of the function must be separated from
1111the body by `blank's or newlines. This is because the braces are
1112reserved words and are only recognized as such when they are separated
d7f49990
CR
1113from the command list by whitespace or another shell metacharacter.
1114Also, when using the braces, the LIST must be terminated by a semicolon,
1115a `&', or a newline.
bb70624e 1116
ccc6cda3
JA
1117 When a function is executed, the arguments to the function become
1118the positional parameters during its execution (*note Positional
28ef6c31 1119Parameters::). The special parameter `#' that expands to the number of
de8913bd 1120positional parameters is updated to reflect the change. Special
d3a24ed2
CR
1121parameter `0' is unchanged. The first element of the `FUNCNAME'
1122variable is set to the name of the function while the function is
4a8bb13f
CR
1123executing.
1124
1125 All other aspects of the shell execution environment are identical
1126between a function and its caller with these exceptions: the `DEBUG'
1127and `RETURN' traps are not inherited unless the function has been given
1128the `trace' attribute using the `declare' builtin or the `-o functrace'
1129option has been enabled with the `set' builtin, (in which case all
1130functions inherit the `DEBUG' and `RETURN' traps), and the `ERR' trap
1131is not inherited unless the `-o errtrace' shell option has been enabled.
1132*Note Bourne Shell Builtins::, for the description of the `trap'
1133builtin.
ccc6cda3 1134
220537f2
CR
1135 The `FUNCNEST' variable, if set to a numeric value greater than 0,
1136defines a maximum function nesting level. Function invocations that
1137exceed the limit cause the entire command to abort.
1138
ccc6cda3
JA
1139 If the builtin command `return' is executed in a function, the
1140function completes and execution resumes with the next command after
d3a24ed2
CR
1141the function call. Any command associated with the `RETURN' trap is
1142executed before execution resumes. When a function completes, the
1143values of the positional parameters and the special parameter `#' are
1144restored to the values they had prior to the function's execution. If
1145a numeric argument is given to `return', that is the function's return
1146status; otherwise the function's return status is the exit status of
1147the last command executed before the `return'.
ccc6cda3
JA
1148
1149 Variables local to the function may be declared with the `local'
1150builtin. These variables are visible only to the function and the
1151commands it invokes.
1152
d3a24ed2 1153 Function names and definitions may be listed with the `-f' option to
122f603c
CR
1154the `declare' (`typeset') builtin command (*note Bash Builtins::). The
1155`-F' option to `declare' or `typeset' will list the function names only
1156(and optionally the source file and line number, if the `extdebug'
d3a24ed2
CR
1157shell option is enabled). Functions may be exported so that subshells
1158automatically have them defined with the `-f' option to the `export'
1159builtin (*note Bourne Shell Builtins::). Note that shell functions and
1160variables with the same name may result in multiple identically-named
1161entries in the environment passed to the shell's children. Care should
1162be taken in cases where this may cause a problem.
1163
9ec5ed66
CR
1164 Functions may be recursive. The `FUNCNEST' variable may be used to
1165limit the depth of the function call stack and restrict the number of
1166function invocations. By default, no limit is placed on the number of
ccc6cda3
JA
1167recursive calls.
1168
1169\1f
1170File: bashref.info, Node: Shell Parameters, Next: Shell Expansions, Prev: Shell Functions, Up: Basic Shell Features
1171
37c41ab1
CR
11723.4 Shell Parameters
1173====================
ccc6cda3
JA
1174
1175* Menu:
1176
1177* Positional Parameters:: The shell's command-line arguments.
d3a24ed2 1178* Special Parameters:: Parameters denoted by special characters.
ccc6cda3
JA
1179
1180 A PARAMETER is an entity that stores values. It can be a `name', a
d3a24ed2
CR
1181number, or one of the special characters listed below. A VARIABLE is a
1182parameter denoted by a `name'. A variable has a VALUE and zero or more
1183ATTRIBUTES. Attributes are assigned using the `declare' builtin command
6a8fd0ed 1184(see the description of the `declare' builtin in *note Bash Builtins::).
ccc6cda3
JA
1185
1186 A parameter is set if it has been assigned a value. The null string
1187is a valid value. Once a variable is set, it may be unset only by using
1188the `unset' builtin command.
1189
1190 A variable may be assigned to by a statement of the form
1191 NAME=[VALUE]
37c41ab1 1192 If VALUE is not given, the variable is assigned the null string. All
ccc6cda3
JA
1193VALUEs undergo tilde expansion, parameter and variable expansion,
1194command substitution, arithmetic expansion, and quote removal (detailed
f73dda09 1195below). If the variable has its `integer' attribute set, then VALUE is
d3a24ed2
CR
1196evaluated as an arithmetic expression even if the `$((...))' expansion
1197is not used (*note Arithmetic Expansion::). Word splitting is not
1198performed, with the exception of `"$@"' as explained below. Filename
1199expansion is not performed. Assignment statements may also appear as
5e13499c 1200arguments to the `alias', `declare', `typeset', `export', `readonly',
122f603c
CR
1201and `local' builtin commands. When in POSIX mode (*note Bash POSIX
1202Mode::), these builtins may appear in a command after one or more
1203instances of the `command' builtin and retain these assignment
1204statement properties.
ccc6cda3 1205
eb2bb562
CR
1206 In the context where an assignment statement is assigning a value to
1207a shell variable or array index (*note Arrays::), the `+=' operator can
1208be used to append to or add to the variable's previous value. When
e05be32d 1209`+=' is applied to a variable for which the INTEGER attribute has been
eb2bb562
CR
1210set, VALUE is evaluated as an arithmetic expression and added to the
1211variable's current value, which is also evaluated. When `+=' is
1212applied to an array variable using compound assignment (*note
1213Arrays::), the variable's value is not unset (as it is when using `='),
1214and new values are appended to the array beginning at one greater than
09767ff0
CR
1215the array's maximum index (for indexed arrays), or added as additional
1216key-value pairs in an associative array. When applied to a
1217string-valued variable, VALUE is expanded and appended to the
1218variable's value.
eb2bb562 1219
ccc6cda3
JA
1220\1f
1221File: bashref.info, Node: Positional Parameters, Next: Special Parameters, Up: Shell Parameters
1222
37c41ab1
CR
12233.4.1 Positional Parameters
1224---------------------------
ccc6cda3 1225
37c41ab1 1226A POSITIONAL PARAMETER is a parameter denoted by one or more digits,
ccc6cda3
JA
1227other than the single digit `0'. Positional parameters are assigned
1228from the shell's arguments when it is invoked, and may be reassigned
cce855bc 1229using the `set' builtin command. Positional parameter `N' may be
bb70624e
JA
1230referenced as `${N}', or as `$N' when `N' consists of a single digit.
1231Positional parameters may not be assigned to with assignment statements.
1232The `set' and `shift' builtins are used to set and unset them (*note
28ef6c31
JA
1233Shell Builtin Commands::). The positional parameters are temporarily
1234replaced when a shell function is executed (*note Shell Functions::).
ccc6cda3
JA
1235
1236 When a positional parameter consisting of more than a single digit
1237is expanded, it must be enclosed in braces.
1238
1239\1f
1240File: bashref.info, Node: Special Parameters, Prev: Positional Parameters, Up: Shell Parameters
1241
37c41ab1
CR
12423.4.2 Special Parameters
1243------------------------
ccc6cda3 1244
37c41ab1 1245The shell treats several parameters specially. These parameters may
ccc6cda3
JA
1246only be referenced; assignment to them is not allowed.
1247
1248`*'
1249 Expands to the positional parameters, starting from one. When the
1250 expansion occurs within double quotes, it expands to a single word
1251 with the value of each parameter separated by the first character
1252 of the `IFS' special variable. That is, `"$*"' is equivalent to
1253 `"$1C$2C..."', where C is the first character of the value of the
d166f048
JA
1254 `IFS' variable. If `IFS' is unset, the parameters are separated
1255 by spaces. If `IFS' is null, the parameters are joined without
1256 intervening separators.
ccc6cda3
JA
1257
1258`@'
1259 Expands to the positional parameters, starting from one. When the
cce855bc 1260 expansion occurs within double quotes, each parameter expands to a
ccc6cda3 1261 separate word. That is, `"$@"' is equivalent to `"$1" "$2" ...'.
37c41ab1
CR
1262 If the double-quoted expansion occurs within a word, the expansion
1263 of the first parameter is joined with the beginning part of the
1264 original word, and the expansion of the last parameter is joined
1265 with the last part of the original word. When there are no
1266 positional parameters, `"$@"' and `$@' expand to nothing (i.e.,
1267 they are removed).
ccc6cda3
JA
1268
1269`#'
1270 Expands to the number of positional parameters in decimal.
1271
1272`?'
1273 Expands to the exit status of the most recently executed foreground
1274 pipeline.
1275
1276`-'
bb70624e
JA
1277 (A hyphen.) Expands to the current option flags as specified upon
1278 invocation, by the `set' builtin command, or those set by the
1279 shell itself (such as the `-i' option).
ccc6cda3
JA
1280
1281`$'
1282 Expands to the process ID of the shell. In a `()' subshell, it
cce855bc 1283 expands to the process ID of the invoking shell, not the subshell.
ccc6cda3
JA
1284
1285`!'
1286 Expands to the process ID of the most recently executed background
1287 (asynchronous) command.
1288
1289`0'
1290 Expands to the name of the shell or shell script. This is set at
cce855bc 1291 shell initialization. If Bash is invoked with a file of commands
28ef6c31
JA
1292 (*note Shell Scripts::), `$0' is set to the name of that file. If
1293 Bash is started with the `-c' option (*note Invoking Bash::), then
1294 `$0' is set to the first argument after the string to be executed,
1295 if one is present. Otherwise, it is set to the filename used to
1296 invoke Bash, as given by argument zero.
ccc6cda3
JA
1297
1298`_'
2206f89a
CR
1299 (An underscore.) At shell startup, set to the absolute pathname
1300 used to invoke the shell or shell script being executed as passed
1301 in the environment or argument list. Subsequently, expands to the
1302 last argument to the previous command, after expansion. Also set
1303 to the full pathname used to invoke each command executed and
1304 placed in the environment exported to that command. When checking
1305 mail, this parameter holds the name of the mail file.
ccc6cda3
JA
1306
1307\1f
1308File: bashref.info, Node: Shell Expansions, Next: Redirections, Prev: Shell Parameters, Up: Basic Shell Features
1309
37c41ab1
CR
13103.5 Shell Expansions
1311====================
ccc6cda3 1312
37c41ab1
CR
1313Expansion is performed on the command line after it has been split into
1314`token's. There are seven kinds of expansion performed:
122f603c 1315
ccc6cda3
JA
1316 * brace expansion
1317
1318 * tilde expansion
1319
1320 * parameter and variable expansion
1321
1322 * command substitution
1323
1324 * arithmetic expansion
1325
1326 * word splitting
1327
1328 * filename expansion
1329
1330* Menu:
1331
cce855bc
JA
1332* Brace Expansion:: Expansion of expressions within braces.
1333* Tilde Expansion:: Expansion of the ~ character.
ccc6cda3
JA
1334* Shell Parameter Expansion:: How Bash expands variables to their values.
1335* Command Substitution:: Using the output of a command as an argument.
cce855bc 1336* Arithmetic Expansion:: How to use arithmetic in shell expansions.
ccc6cda3
JA
1337* Process Substitution:: A way to write and read to and from a
1338 command.
1339* Word Splitting:: How the results of expansion are split into separate
1340 arguments.
1341* Filename Expansion:: A shorthand for specifying filenames matching patterns.
1342* Quote Removal:: How and when quote characters are removed from
1343 words.
1344
ccc6cda3
JA
1345 The order of expansions is: brace expansion, tilde expansion,
1346parameter, variable, and arithmetic expansion and command substitution
1347(done in a left-to-right fashion), word splitting, and filename
1348expansion.
1349
1350 On systems that can support it, there is an additional expansion
1351available: PROCESS SUBSTITUTION. This is performed at the same time as
cce855bc 1352parameter, variable, and arithmetic expansion and command substitution.
ccc6cda3
JA
1353
1354 Only brace expansion, word splitting, and filename expansion can
1355change the number of words of the expansion; other expansions expand a
1356single word to a single word. The only exceptions to this are the
28ef6c31
JA
1357expansions of `"$@"' (*note Special Parameters::) and `"${NAME[@]}"'
1358(*note Arrays::).
ccc6cda3 1359
28ef6c31 1360 After all expansions, `quote removal' (*note Quote Removal::) is
ccc6cda3
JA
1361performed.
1362
1363\1f
cce855bc
JA
1364File: bashref.info, Node: Brace Expansion, Next: Tilde Expansion, Up: Shell Expansions
1365
37c41ab1
CR
13663.5.1 Brace Expansion
1367---------------------
cce855bc 1368
37c41ab1 1369Brace expansion is a mechanism by which arbitrary strings may be
cce855bc 1370generated. This mechanism is similar to FILENAME EXPANSION (*note
122f603c 1371Filename Expansion::), but the filenames generated need not exist.
cce855bc 1372Patterns to be brace expanded take the form of an optional PREAMBLE,
f6da9f85 1373followed by either a series of comma-separated strings or a sequence
d3a24ed2
CR
1374expression between a pair of braces, followed by an optional POSTSCRIPT.
1375The preamble is prefixed to each string contained within the braces, and
1376the postscript is then appended to each resulting string, expanding left
1377to right.
cce855bc
JA
1378
1379 Brace expansions may be nested. The results of each expanded string
1380are not sorted; left to right order is preserved. For example,
1381 bash$ echo a{d,c,b}e
1382 ade ace abe
1383
4a8bb13f 1384 A sequence expression takes the form `{X..Y[..INCR]}', where X and Y
ed35cb4a
CR
1385are either integers or single characters, and INCR, an optional
1386increment, is an integer. When integers are supplied, the expression
1387expands to each number between X and Y, inclusive. Supplied integers
1388may be prefixed with `0' to force each term to have the same width.
1389When either X or Y begins with a zero, the shell attempts to force all
1390generated terms to contain the same number of digits, zero-padding
1391where necessary. When characters are supplied, the expression expands
1392to each character lexicographically between X and Y, inclusive. Note
1393that both X and Y must be of the same type. When the increment is
1394supplied, it is used as the difference between each term. The default
1395increment is 1 or -1 as appropriate.
d3a24ed2 1396
cce855bc
JA
1397 Brace expansion is performed before any other expansions, and any
1398characters special to other expansions are preserved in the result. It
1399is strictly textual. Bash does not apply any syntactic interpretation
bb70624e
JA
1400to the context of the expansion or the text between the braces. To
1401avoid conflicts with parameter expansion, the string `${' is not
1402considered eligible for brace expansion.
cce855bc
JA
1403
1404 A correctly-formed brace expansion must contain unquoted opening and
d3a24ed2
CR
1405closing braces, and at least one unquoted comma or a valid sequence
1406expression. Any incorrectly formed brace expansion is left unchanged.
1407
1408 A { or `,' may be quoted with a backslash to prevent its being
1409considered part of a brace expression. To avoid conflicts with
1410parameter expansion, the string `${' is not considered eligible for
1411brace expansion.
cce855bc
JA
1412
1413 This construct is typically used as shorthand when the common prefix
1414of the strings to be generated is longer than in the above example:
1415 mkdir /usr/local/src/bash/{old,new,dist,bugs}
1416 or
1417 chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}
1418
1419\1f
1420File: bashref.info, Node: Tilde Expansion, Next: Shell Parameter Expansion, Prev: Brace Expansion, Up: Shell Expansions
1421
37c41ab1
CR
14223.5.2 Tilde Expansion
1423---------------------
cce855bc 1424
37c41ab1 1425If a word begins with an unquoted tilde character (`~'), all of the
cce855bc
JA
1426characters up to the first unquoted slash (or all characters, if there
1427is no unquoted slash) are considered a TILDE-PREFIX. If none of the
1428characters in the tilde-prefix are quoted, the characters in the
1429tilde-prefix following the tilde are treated as a possible LOGIN NAME.
1430If this login name is the null string, the tilde is replaced with the
1431value of the `HOME' shell variable. If `HOME' is unset, the home
1432directory of the user executing the shell is substituted instead.
1433Otherwise, the tilde-prefix is replaced with the home directory
1434associated with the specified login name.
1435
1436 If the tilde-prefix is `~+', the value of the shell variable `PWD'
1437replaces the tilde-prefix. If the tilde-prefix is `~-', the value of
1438the shell variable `OLDPWD', if it is set, is substituted.
1439
1440 If the characters following the tilde in the tilde-prefix consist of
1441a number N, optionally prefixed by a `+' or a `-', the tilde-prefix is
1442replaced with the corresponding element from the directory stack, as it
1443would be displayed by the `dirs' builtin invoked with the characters
1444following tilde in the tilde-prefix as an argument (*note The Directory
28ef6c31 1445Stack::). If the tilde-prefix, sans the tilde, consists of a number
cce855bc
JA
1446without a leading `+' or `-', `+' is assumed.
1447
1448 If the login name is invalid, or the tilde expansion fails, the word
1449is left unchanged.
1450
1451 Each variable assignment is checked for unquoted tilde-prefixes
eb2bb562 1452immediately following a `:' or the first `='. In these cases, tilde
122f603c 1453expansion is also performed. Consequently, one may use filenames with
eb2bb562
CR
1454tildes in assignments to `PATH', `MAILPATH', and `CDPATH', and the
1455shell assigns the expanded value.
cce855bc
JA
1456
1457 The following table shows how Bash treats unquoted tilde-prefixes:
1458
1459`~'
1460 The value of `$HOME'
1461
1462`~/foo'
1463 `$HOME/foo'
1464
1465`~fred/foo'
1466 The subdirectory `foo' of the home directory of the user `fred'
1467
1468`~+/foo'
1469 `$PWD/foo'
1470
1471`~-/foo'
1472 `${OLDPWD-'~-'}/foo'
1473
1474`~N'
1475 The string that would be displayed by `dirs +N'
1476
1477`~+N'
1478 The string that would be displayed by `dirs +N'
1479
1480`~-N'
1481 The string that would be displayed by `dirs -N'
1482
1483\1f
1484File: bashref.info, Node: Shell Parameter Expansion, Next: Command Substitution, Prev: Tilde Expansion, Up: Shell Expansions
ccc6cda3 1485
37c41ab1
CR
14863.5.3 Shell Parameter Expansion
1487-------------------------------
ccc6cda3 1488
37c41ab1
CR
1489The `$' character introduces parameter expansion, command substitution,
1490or arithmetic expansion. The parameter name or symbol to be expanded
1491may be enclosed in braces, which are optional but serve to protect the
1492variable to be expanded from characters immediately following it which
1493could be interpreted as part of the name.
ccc6cda3 1494
cce855bc
JA
1495 When braces are used, the matching ending brace is the first `}' not
1496escaped by a backslash or within a quoted string, and not within an
1497embedded arithmetic expansion, command substitution, or parameter
1498expansion.
1499
ccc6cda3
JA
1500 The basic form of parameter expansion is ${PARAMETER}. The value of
1501PARAMETER is substituted. The braces are required when PARAMETER is a
1502positional parameter with more than one digit, or when PARAMETER is
1503followed by a character that is not to be interpreted as part of its
1504name.
1505
d5362af8
CR
1506 If the first character of PARAMETER is an exclamation point (!), a
1507level of variable indirection is introduced. Bash uses the value of
1508the variable formed from the rest of PARAMETER as the name of the
1509variable; this variable is then expanded and that value is used in the
1510rest of the substitution, rather than the value of PARAMETER itself.
1511This is known as `indirect expansion'. The exceptions to this are the
e05be32d
CR
1512expansions of ${!PREFIX
1513} and ${!NAME[@]} described below. The exclamation point must
1514immediately follow the left brace in order to introduce indirection.
ccc6cda3
JA
1515
1516 In each of the cases below, WORD is subject to tilde expansion,
1517parameter expansion, command substitution, and arithmetic expansion.
bb70624e 1518
db31fb26
CR
1519 When not performing substring expansion, using the form described
1520below, Bash tests for a parameter that is unset or null. Omitting the
1521colon results in a test only for a parameter that is unset. Put
1522another way, if the colon is included, the operator tests for both
1523PARAMETER's existence and that its value is not null; if the colon is
1524omitted, the operator tests only for existence.
ccc6cda3
JA
1525
1526`${PARAMETER:-WORD}'
1527 If PARAMETER is unset or null, the expansion of WORD is
1528 substituted. Otherwise, the value of PARAMETER is substituted.
1529
1530`${PARAMETER:=WORD}'
1531 If PARAMETER is unset or null, the expansion of WORD is assigned
1532 to PARAMETER. The value of PARAMETER is then substituted.
de8913bd
CR
1533 Positional parameters and special parameters may not be assigned to
1534 in this way.
ccc6cda3
JA
1535
1536`${PARAMETER:?WORD}'
1537 If PARAMETER is null or unset, the expansion of WORD (or a message
1538 to that effect if WORD is not present) is written to the standard
1539 error and the shell, if it is not interactive, exits. Otherwise,
1540 the value of PARAMETER is substituted.
1541
1542`${PARAMETER:+WORD}'
1543 If PARAMETER is null or unset, nothing is substituted, otherwise
1544 the expansion of WORD is substituted.
1545
1546`${PARAMETER:OFFSET}'
1547`${PARAMETER:OFFSET:LENGTH}'
bb70624e 1548 Expands to up to LENGTH characters of PARAMETER starting at the
cce855bc 1549 character specified by OFFSET. If LENGTH is omitted, expands to
bb70624e 1550 the substring of PARAMETER starting at the character specified by
cce855bc 1551 OFFSET. LENGTH and OFFSET are arithmetic expressions (*note Shell
28ef6c31 1552 Arithmetic::). This is referred to as Substring Expansion.
ccc6cda3 1553
ccc6cda3 1554 If OFFSET evaluates to a number less than zero, the value is used
7d92f73f
CR
1555 as an offset from the end of the value of PARAMETER. If LENGTH
1556 evaluates to a number less than zero, and PARAMETER is not `@' and
1557 not an indexed or associative array, it is interpreted as an
1558 offset from the end of the value of PARAMETER rather than a number
1559 of characters, and the expansion is the characters between the two
1560 offsets. If PARAMETER is `@', the result is LENGTH positional
1561 parameters beginning at OFFSET. If PARAMETER is an indexed array
1562 name subscripted by `@' or `*', the result is the LENGTH members
1563 of the array beginning with `${PARAMETER[OFFSET]}'. A negative
1564 OFFSET is taken relative to one greater than the maximum index of
1565 the specified array. Substring expansion applied to an
1566 associative array produces undefined results.
09767ff0
CR
1567
1568 Note that a negative offset must be separated from the colon by at
1569 least one space to avoid being confused with the `:-' expansion.
eb2bb562 1570 Substring indexing is zero-based unless the positional parameters
d3ad40de
CR
1571 are used, in which case the indexing starts at 1 by default. If
1572 OFFSET is 0, and the positional parameters are used, `$@' is
1573 prefixed to the list.
ccc6cda3 1574
bb70624e 1575`${!PREFIX*}'
d3a24ed2 1576`${!PREFIX@}'
bb70624e
JA
1577 Expands to the names of variables whose names begin with PREFIX,
1578 separated by the first character of the `IFS' special variable.
d3ad40de
CR
1579 When `@' is used and the expansion appears within double quotes,
1580 each variable name expands to a separate word.
bb70624e 1581
d3a24ed2
CR
1582`${!NAME[@]}'
1583`${!NAME[*]}'
1584 If NAME is an array variable, expands to the list of array indices
1585 (keys) assigned in NAME. If NAME is not an array, expands to 0 if
1586 NAME is set and null otherwise. When `@' is used and the
1587 expansion appears within double quotes, each key expands to a
1588 separate word.
1589
ccc6cda3 1590`${#PARAMETER}'
cce855bc
JA
1591 The length in characters of the expanded value of PARAMETER is
1592 substituted. If PARAMETER is `*' or `@', the value substituted is
1593 the number of positional parameters. If PARAMETER is an array
1594 name subscripted by `*' or `@', the value substituted is the
1595 number of elements in the array.
ccc6cda3
JA
1596
1597`${PARAMETER#WORD}'
1598`${PARAMETER##WORD}'
1599 The WORD is expanded to produce a pattern just as in filename
28ef6c31 1600 expansion (*note Filename Expansion::). If the pattern matches
cce855bc
JA
1601 the beginning of the expanded value of PARAMETER, then the result
1602 of the expansion is the expanded value of PARAMETER with the
1603 shortest matching pattern (the `#' case) or the longest matching
1604 pattern (the `##' case) deleted. If PARAMETER is `@' or `*', the
1605 pattern removal operation is applied to each positional parameter
1606 in turn, and the expansion is the resultant list. If PARAMETER is
1607 an array variable subscripted with `@' or `*', the pattern removal
1608 operation is applied to each member of the array in turn, and the
1609 expansion is the resultant list.
ccc6cda3
JA
1610
1611`${PARAMETER%WORD}'
1612`${PARAMETER%%WORD}'
1613 The WORD is expanded to produce a pattern just as in filename
cce855bc
JA
1614 expansion. If the pattern matches a trailing portion of the
1615 expanded value of PARAMETER, then the result of the expansion is
1616 the value of PARAMETER with the shortest matching pattern (the `%'
1617 case) or the longest matching pattern (the `%%' case) deleted. If
1618 PARAMETER is `@' or `*', the pattern removal operation is applied
1619 to each positional parameter in turn, and the expansion is the
1620 resultant list. If PARAMETER is an array variable subscripted
1621 with `@' or `*', the pattern removal operation is applied to each
1622 member of the array in turn, and the expansion is the resultant
1623 list.
ccc6cda3
JA
1624
1625`${PARAMETER/PATTERN/STRING}'
ccc6cda3
JA
1626 The PATTERN is expanded to produce a pattern just as in filename
1627 expansion. PARAMETER is expanded and the longest match of PATTERN
ac18b312
CR
1628 against its value is replaced with STRING. If PATTERN begins with
1629 `/', all matches of PATTERN are replaced with STRING. Normally
1630 only the first match is replaced. If PATTERN begins with `#', it
1631 must match at the beginning of the expanded value of PARAMETER.
1632 If PATTERN begins with `%', it must match at the end of the
1633 expanded value of PARAMETER. If STRING is null, matches of
b72432fd
JA
1634 PATTERN are deleted and the `/' following PATTERN may be omitted.
1635 If PARAMETER is `@' or `*', the substitution operation is applied
1636 to each positional parameter in turn, and the expansion is the
1637 resultant list. If PARAMETER is an array variable subscripted
1638 with `@' or `*', the substitution operation is applied to each
1639 member of the array in turn, and the expansion is the resultant
1640 list.
ccc6cda3 1641
09767ff0
CR
1642`${PARAMETER^PATTERN}'
1643`${PARAMETER^^PATTERN}'
1644`${PARAMETER,PATTERN}'
1645`${PARAMETER,,PATTERN}'
1646 This expansion modifies the case of alphabetic characters in
1647 PARAMETER. The PATTERN is expanded to produce a pattern just as in
4a8bb13f 1648 filename expansion. The `^' operator converts lowercase letters
09767ff0
CR
1649 matching PATTERN to uppercase; the `,' operator converts matching
1650 uppercase letters to lowercase. The `^^' and `,,' expansions
1651 convert each matched character in the expanded value; the `^' and
db31fb26
CR
1652 `,' expansions match and convert only the first character in the
1653 expanded value. If PATTERN is omitted, it is treated like a `?',
1654 which matches every character. If PARAMETER is `@' or `*', the
1655 case modification operation is applied to each positional
1656 parameter in turn, and the expansion is the resultant list. If
1657 PARAMETER is an array variable subscripted with `@' or `*', the
1658 case modification operation is applied to each member of the array
1659 in turn, and the expansion is the resultant list.
09767ff0 1660
ccc6cda3 1661\1f
cce855bc 1662File: bashref.info, Node: Command Substitution, Next: Arithmetic Expansion, Prev: Shell Parameter Expansion, Up: Shell Expansions
ccc6cda3 1663
37c41ab1
CR
16643.5.4 Command Substitution
1665--------------------------
ccc6cda3 1666
37c41ab1 1667Command substitution allows the output of a command to replace the
bb70624e
JA
1668command itself. Command substitution occurs when a command is enclosed
1669as follows:
ccc6cda3 1670 $(COMMAND)
37c41ab1 1671 or
ccc6cda3
JA
1672 `COMMAND`
1673
1674Bash performs the expansion by executing COMMAND and replacing the
1675command substitution with the standard output of the command, with any
cce855bc
JA
1676trailing newlines deleted. Embedded newlines are not deleted, but they
1677may be removed during word splitting. The command substitution `$(cat
1678FILE)' can be replaced by the equivalent but faster `$(< FILE)'.
ccc6cda3
JA
1679
1680 When the old-style backquote form of substitution is used, backslash
1681retains its literal meaning except when followed by `$', ``', or `\'.
cce855bc
JA
1682The first backquote not preceded by a backslash terminates the command
1683substitution. When using the `$(COMMAND)' form, all characters between
1684the parentheses make up the command; none are treated specially.
ccc6cda3 1685
cce855bc
JA
1686 Command substitutions may be nested. To nest when using the
1687backquoted form, escape the inner backquotes with backslashes.
ccc6cda3
JA
1688
1689 If the substitution appears within double quotes, word splitting and
1690filename expansion are not performed on the results.
1691
1692\1f
cce855bc
JA
1693File: bashref.info, Node: Arithmetic Expansion, Next: Process Substitution, Prev: Command Substitution, Up: Shell Expansions
1694
37c41ab1
CR
16953.5.5 Arithmetic Expansion
1696--------------------------
cce855bc 1697
37c41ab1
CR
1698Arithmetic expansion allows the evaluation of an arithmetic expression
1699and the substitution of the result. The format for arithmetic
1700expansion is:
cce855bc
JA
1701
1702 $(( EXPRESSION ))
1703
1704 The expression is treated as if it were within double quotes, but a
1705double quote inside the parentheses is not treated specially. All
1706tokens in the expression undergo parameter expansion, command
d3a24ed2 1707substitution, and quote removal. Arithmetic expansions may be nested.
cce855bc
JA
1708
1709 The evaluation is performed according to the rules listed below
28ef6c31 1710(*note Shell Arithmetic::). If the expression is invalid, Bash prints
cce855bc
JA
1711a message indicating failure to the standard error and no substitution
1712occurs.
1713
1714\1f
1715File: bashref.info, Node: Process Substitution, Next: Word Splitting, Prev: Arithmetic Expansion, Up: Shell Expansions
ccc6cda3 1716
37c41ab1
CR
17173.5.6 Process Substitution
1718--------------------------
ccc6cda3 1719
37c41ab1
CR
1720Process substitution is supported on systems that support named pipes
1721(FIFOs) or the `/dev/fd' method of naming open files. It takes the
1722form of
ccc6cda3 1723 <(LIST)
37c41ab1 1724 or
ccc6cda3 1725 >(LIST)
37c41ab1
CR
1726 The process LIST is run with its input or output connected to a FIFO
1727or some file in `/dev/fd'. The name of this file is passed as an
1728argument to the current command as the result of the expansion. If the
ccc6cda3
JA
1729`>(LIST)' form is used, writing to the file will provide input for
1730LIST. If the `<(LIST)' form is used, the file passed as an argument
bb70624e
JA
1731should be read to obtain the output of LIST. Note that no space may
1732appear between the `<' or `>' and the left parenthesis, otherwise the
1733construct would be interpreted as a redirection.
ccc6cda3 1734
cce855bc
JA
1735 When available, process substitution is performed simultaneously with
1736parameter and variable expansion, command substitution, and arithmetic
1737expansion.
ccc6cda3
JA
1738
1739\1f
1740File: bashref.info, Node: Word Splitting, Next: Filename Expansion, Prev: Process Substitution, Up: Shell Expansions
1741
37c41ab1
CR
17423.5.7 Word Splitting
1743--------------------
ccc6cda3 1744
37c41ab1 1745The shell scans the results of parameter expansion, command
ccc6cda3
JA
1746substitution, and arithmetic expansion that did not occur within double
1747quotes for word splitting.
1748
1749 The shell treats each character of `$IFS' as a delimiter, and splits
1750the results of the other expansions into words on these characters. If
1751`IFS' is unset, or its value is exactly `<space><tab><newline>', the
d3ad40de
CR
1752default, then sequences of ` <space>', `<tab>', and `<newline>' at the
1753beginning and end of the results of the previous expansions are
1754ignored, and any sequence of `IFS' characters not at the beginning or
1755end serves to delimit words. If `IFS' has a value other than the
1756default, then sequences of the whitespace characters `space' and `tab'
1757are ignored at the beginning and end of the word, as long as the
1758whitespace character is in the value of `IFS' (an `IFS' whitespace
1759character). Any character in `IFS' that is not `IFS' whitespace, along
1760with any adjacent `IFS' whitespace characters, delimits a field. A
1761sequence of `IFS' whitespace characters is also treated as a delimiter.
1762If the value of `IFS' is null, no word splitting occurs.
ccc6cda3
JA
1763
1764 Explicit null arguments (`""' or `''') are retained. Unquoted
bb70624e 1765implicit null arguments, resulting from the expansion of parameters
ccc6cda3
JA
1766that have no values, are removed. If a parameter with no value is
1767expanded within double quotes, a null argument results and is retained.
1768
1769 Note that if no expansion occurs, no splitting is performed.
1770
1771\1f
1772File: bashref.info, Node: Filename Expansion, Next: Quote Removal, Prev: Word Splitting, Up: Shell Expansions
1773
37c41ab1
CR
17743.5.8 Filename Expansion
1775------------------------
ccc6cda3 1776
cce855bc
JA
1777* Menu:
1778
1779* Pattern Matching:: How the shell matches patterns.
1780
ccc6cda3 1781 After word splitting, unless the `-f' option has been set (*note The
28ef6c31 1782Set Builtin::), Bash scans each word for the characters `*', `?', and
bb70624e 1783`['. If one of these characters appears, then the word is regarded as
122f603c
CR
1784a PATTERN, and replaced with an alphabetically sorted list of filenames
1785matching the pattern (*note Pattern Matching::). If no matching
1786filenames are found, and the shell option `nullglob' is disabled, the
74d0116b
CR
1787word is left unchanged. If the `nullglob' option is set, and no
1788matches are found, the word is removed. If the `failglob' shell option
1789is set, and no matches are found, an error message is printed and the
1790command is not executed. If the shell option `nocaseglob' is enabled,
1791the match is performed without regard to the case of alphabetic
1792characters.
cce855bc 1793
4a8bb13f 1794 When a pattern is used for filename expansion, the character `.' at
28ef6c31 1795the start of a filename or immediately following a slash must be
cce855bc 1796matched explicitly, unless the shell option `dotglob' is set. When
122f603c 1797matching a filename, the slash character must always be matched
cce855bc
JA
1798explicitly. In other cases, the `.' character is not treated specially.
1799
6a8fd0ed 1800 See the description of `shopt' in *note The Shopt Builtin::, for a
5e13499c
CR
1801description of the `nocaseglob', `nullglob', `failglob', and `dotglob'
1802options.
ccc6cda3
JA
1803
1804 The `GLOBIGNORE' shell variable may be used to restrict the set of
cce855bc 1805filenames matching a pattern. If `GLOBIGNORE' is set, each matching
ccc6cda3 1806filename that also matches one of the patterns in `GLOBIGNORE' is
28ef6c31 1807removed from the list of matches. The filenames `.' and `..' are
d3a24ed2
CR
1808always ignored when `GLOBIGNORE' is set and not null. However, setting
1809`GLOBIGNORE' to a non-null value has the effect of enabling the
1810`dotglob' shell option, so all other filenames beginning with a `.'
1811will match. To get the old behavior of ignoring filenames beginning
1812with a `.', make `.*' one of the patterns in `GLOBIGNORE'. The
1813`dotglob' option is disabled when `GLOBIGNORE' is unset.
ccc6cda3 1814
cce855bc
JA
1815\1f
1816File: bashref.info, Node: Pattern Matching, Up: Filename Expansion
1817
37c41ab1
CR
18183.5.8.1 Pattern Matching
1819........................
cce855bc 1820
37c41ab1
CR
1821Any character that appears in a pattern, other than the special pattern
1822characters described below, matches itself. The NUL character may not
1823occur in a pattern. A backslash escapes the following character; the
1824escaping backslash is discarded when matching. The special pattern
1825characters must be quoted if they are to be matched literally.
cce855bc 1826
ccc6cda3
JA
1827 The special pattern characters have the following meanings:
1828`*'
ed35cb4a
CR
1829 Matches any string, including the null string. When the
1830 `globstar' shell option is enabled, and `*' is used in a filename
1831 expansion context, two adjacent `*'s used as a single pattern will
1832 match all files and zero or more directories and subdirectories.
1833 If followed by a `/', two adjacent `*'s will match only
1834 directories and subdirectories.
ccc6cda3
JA
1835
1836`?'
1837 Matches any single character.
1838
1839`[...]'
1840 Matches any one of the enclosed characters. A pair of characters
28ef6c31
JA
1841 separated by a hyphen denotes a RANGE EXPRESSION; any character
1842 that sorts between those two characters, inclusive, using the
1843 current locale's collating sequence and character set, is matched.
1844 If the first character following the `[' is a `!' or a `^' then
1845 any character not enclosed is matched. A `-' may be matched by
1846 including it as the first or last character in the set. A `]' may
1847 be matched by including it as the first character in the set. The
1848 sorting order of characters in range expressions is determined by
74d0116b
CR
1849 the current locale and the values of the `LC_COLLATE' and `LC_ALL'
1850 shell variables, if set.
28ef6c31
JA
1851
1852 For example, in the default C locale, `[a-dx-z]' is equivalent to
1853 `[abcdxyz]'. Many locales sort characters in dictionary order,
1854 and in these locales `[a-dx-z]' is typically not equivalent to
1855 `[abcdxyz]'; it might be equivalent to `[aBbCcDdxXyYz]', for
1856 example. To obtain the traditional interpretation of ranges in
1857 bracket expressions, you can force the use of the C locale by
1858 setting the `LC_COLLATE' or `LC_ALL' environment variable to the
74d0116b 1859 value `C', or enable the `globasciiranges' shell option.
ccc6cda3 1860
cce855bc
JA
1861 Within `[' and `]', CHARACTER CLASSES can be specified using the
1862 syntax `[:'CLASS`:]', where CLASS is one of the following classes
ac18b312 1863 defined in the POSIX standard:
cce855bc 1864 alnum alpha ascii blank cntrl digit graph lower
7117c2d2 1865 print punct space upper word xdigit
cce855bc 1866 A character class matches any character belonging to that class.
7117c2d2
JA
1867 The `word' character class matches letters, digits, and the
1868 character `_'.
cce855bc
JA
1869
1870 Within `[' and `]', an EQUIVALENCE CLASS can be specified using
1871 the syntax `[='C`=]', which matches all characters with the same
1872 collation weight (as defined by the current locale) as the
1873 character C.
1874
28ef6c31 1875 Within `[' and `]', the syntax `[.'SYMBOL`.]' matches the
cce855bc
JA
1876 collating symbol SYMBOL.
1877
1878 If the `extglob' shell option is enabled using the `shopt' builtin,
1879several extended pattern matching operators are recognized. In the
1880following description, a PATTERN-LIST is a list of one or more patterns
1881separated by a `|'. Composite patterns may be formed using one or more
1882of the following sub-patterns:
1883
1884`?(PATTERN-LIST)'
1885 Matches zero or one occurrence of the given patterns.
1886
1887`*(PATTERN-LIST)'
1888 Matches zero or more occurrences of the given patterns.
1889
1890`+(PATTERN-LIST)'
1891 Matches one or more occurrences of the given patterns.
1892
1893`@(PATTERN-LIST)'
eb2bb562 1894 Matches one of the given patterns.
cce855bc
JA
1895
1896`!(PATTERN-LIST)'
1897 Matches anything except one of the given patterns.
1898
ccc6cda3
JA
1899\1f
1900File: bashref.info, Node: Quote Removal, Prev: Filename Expansion, Up: Shell Expansions
1901
37c41ab1
CR
19023.5.9 Quote Removal
1903-------------------
ccc6cda3 1904
37c41ab1 1905After the preceding expansions, all unquoted occurrences of the
ccc6cda3
JA
1906characters `\', `'', and `"' that did not result from one of the above
1907expansions are removed.
1908
1909\1f
1910File: bashref.info, Node: Redirections, Next: Executing Commands, Prev: Shell Expansions, Up: Basic Shell Features
1911
37c41ab1
CR
19123.6 Redirections
1913================
ccc6cda3 1914
37c41ab1 1915Before a command is executed, its input and output may be REDIRECTED
ccc6cda3
JA
1916using a special notation interpreted by the shell. Redirection may
1917also be used to open and close files for the current shell execution
1918environment. The following redirection operators may precede or appear
1919anywhere within a simple command or may follow a command. Redirections
1920are processed in the order they appear, from left to right.
1921
a8fd3f3e
CR
1922 Each redirection that may be preceded by a file descriptor number
1923may instead be preceded by a word of the form {VARNAME}. In this case,
1924for each redirection operator except >&- and <&-, the shell will
1925allocate a file descriptor greater than 10 and assign it to {VARNAME}.
d5362af8 1926If >&- or <&- is preceded by {VARNAME}, the value of VARNAME defines
a8fd3f3e
CR
1927the file descriptor to close.
1928
ccc6cda3
JA
1929 In the following descriptions, if the file descriptor number is
1930omitted, and the first character of the redirection operator is `<',
1931the redirection refers to the standard input (file descriptor 0). If
1932the first character of the redirection operator is `>', the redirection
1933refers to the standard output (file descriptor 1).
1934
cce855bc
JA
1935 The word following the redirection operator in the following
1936descriptions, unless otherwise noted, is subjected to brace expansion,
1937tilde expansion, parameter expansion, command substitution, arithmetic
bb70624e
JA
1938expansion, quote removal, filename expansion, and word splitting. If
1939it expands to more than one word, Bash reports an error.
ccc6cda3
JA
1940
1941 Note that the order of redirections is significant. For example,
1942the command
1943 ls > DIRLIST 2>&1
37c41ab1 1944 directs both standard output (file descriptor 1) and standard error
bb70624e 1945(file descriptor 2) to the file DIRLIST, while the command
ccc6cda3 1946 ls 2>&1 > DIRLIST
37c41ab1 1947 directs only the standard output to file DIRLIST, because the
6932f7f5
CR
1948standard error was made a copy of the standard output before the
1949standard output was redirected to DIRLIST.
ccc6cda3 1950
bb70624e
JA
1951 Bash handles several filenames specially when they are used in
1952redirections, as described in the following table:
1953
1954`/dev/fd/FD'
1955 If FD is a valid integer, file descriptor FD is duplicated.
1956
1957`/dev/stdin'
1958 File descriptor 0 is duplicated.
1959
1960`/dev/stdout'
1961 File descriptor 1 is duplicated.
1962
1963`/dev/stderr'
1964 File descriptor 2 is duplicated.
1965
1966`/dev/tcp/HOST/PORT'
1967 If HOST is a valid hostname or Internet address, and PORT is an
f73dda09
JA
1968 integer port number or service name, Bash attempts to open a TCP
1969 connection to the corresponding socket.
bb70624e
JA
1970
1971`/dev/udp/HOST/PORT'
1972 If HOST is a valid hostname or Internet address, and PORT is an
f73dda09
JA
1973 integer port number or service name, Bash attempts to open a UDP
1974 connection to the corresponding socket.
bb70624e 1975
cce855bc
JA
1976 A failure to open or create a file causes the redirection to fail.
1977
eb2bb562
CR
1978 Redirections using file descriptors greater than 9 should be used
1979with care, as they may conflict with file descriptors the shell uses
1980internally.
1981
37c41ab1
CR
19823.6.1 Redirecting Input
1983-----------------------
ccc6cda3 1984
37c41ab1 1985Redirection of input causes the file whose name results from the
ccc6cda3
JA
1986expansion of WORD to be opened for reading on file descriptor `n', or
1987the standard input (file descriptor 0) if `n' is not specified.
1988
1989 The general format for redirecting input is:
7117c2d2 1990 [N]<WORD
ccc6cda3 1991
37c41ab1
CR
19923.6.2 Redirecting Output
1993------------------------
ccc6cda3 1994
37c41ab1 1995Redirection of output causes the file whose name results from the
7117c2d2
JA
1996expansion of WORD to be opened for writing on file descriptor N, or the
1997standard output (file descriptor 1) if N is not specified. If the file
1998does not exist it is created; if it does exist it is truncated to zero
1999size.
ccc6cda3
JA
2000
2001 The general format for redirecting output is:
7117c2d2 2002 [N]>[|]WORD
ccc6cda3 2003
cce855bc
JA
2004 If the redirection operator is `>', and the `noclobber' option to
2005the `set' builtin has been enabled, the redirection will fail if the
bb70624e 2006file whose name results from the expansion of WORD exists and is a
cce855bc
JA
2007regular file. If the redirection operator is `>|', or the redirection
2008operator is `>' and the `noclobber' option is not enabled, the
2009redirection is attempted even if the file named by WORD exists.
ccc6cda3 2010
37c41ab1
CR
20113.6.3 Appending Redirected Output
2012---------------------------------
ccc6cda3 2013
37c41ab1 2014Redirection of output in this fashion causes the file whose name
ccc6cda3 2015results from the expansion of WORD to be opened for appending on file
7117c2d2
JA
2016descriptor N, or the standard output (file descriptor 1) if N is not
2017specified. If the file does not exist it is created.
ccc6cda3
JA
2018
2019 The general format for appending output is:
7117c2d2 2020 [N]>>WORD
ccc6cda3 2021
37c41ab1
CR
20223.6.4 Redirecting Standard Output and Standard Error
2023----------------------------------------------------
ccc6cda3 2024
ed35cb4a
CR
2025This construct allows both the standard output (file descriptor 1) and
2026the standard error output (file descriptor 2) to be redirected to the
2027file whose name is the expansion of WORD.
ccc6cda3
JA
2028
2029 There are two formats for redirecting standard output and standard
2030error:
2031 &>WORD
37c41ab1 2032 and
ccc6cda3 2033 >&WORD
37c41ab1 2034 Of the two forms, the first is preferred. This is semantically
ccc6cda3
JA
2035equivalent to
2036 >WORD 2>&1
f6da9f85 2037 (see Duplicating File Descriptors below).
ccc6cda3 2038
ed35cb4a
CR
20393.6.5 Appending Standard Output and Standard Error
2040--------------------------------------------------
2041
2042This construct allows both the standard output (file descriptor 1) and
2043the standard error output (file descriptor 2) to be appended to the
2044file whose name is the expansion of WORD.
2045
2046 The format for appending standard output and standard error is:
2047 &>>WORD
2048 This is semantically equivalent to
2049 >>WORD 2>&1
f6da9f85 2050 (see Duplicating File Descriptors below).
ed35cb4a
CR
2051
20523.6.6 Here Documents
37c41ab1 2053--------------------
ccc6cda3 2054
37c41ab1 2055This type of redirection instructs the shell to read input from the
ccc6cda3
JA
2056current source until a line containing only WORD (with no trailing
2057blanks) is seen. All of the lines read up to that point are then used
2058as the standard input for a command.
2059
7117c2d2 2060 The format of here-documents is:
ccc6cda3
JA
2061 <<[-]WORD
2062 HERE-DOCUMENT
2063 DELIMITER
2064
122f603c
CR
2065 No parameter and variable expansion, command substitution,
2066arithmetic expansion, or filename expansion is performed on WORD. If
2067any characters in WORD are quoted, the DELIMITER is the result of quote
2068removal on WORD, and the lines in the here-document are not expanded.
2069If WORD is unquoted, all lines of the here-document are subjected to
2070parameter expansion, command substitution, and arithmetic expansion.
2071In the latter case, the character sequence `\newline' is ignored, and
2072`\' must be used to quote the characters `\', `$', and ``'.
ccc6cda3
JA
2073
2074 If the redirection operator is `<<-', then all leading tab
2075characters are stripped from input lines and the line containing
2076DELIMITER. This allows here-documents within shell scripts to be
2077indented in a natural fashion.
2078
ed35cb4a 20793.6.7 Here Strings
37c41ab1 2080------------------
7117c2d2 2081
37c41ab1 2082A variant of here documents, the format is:
7117c2d2
JA
2083 <<< WORD
2084
122f603c
CR
2085 The WORD undergoes brace expansion, tilde expansion, parameter and
2086variable expansion, command substitution, arithmetic expansion, and
2087quote removal. Pathname expansion word splitting are not performed.
2088The result is supplied as a single string to the command on its
2089standard input.
7117c2d2 2090
ed35cb4a 20913.6.8 Duplicating File Descriptors
37c41ab1 2092----------------------------------
ccc6cda3 2093
37c41ab1 2094The redirection operator
7117c2d2 2095 [N]<&WORD
37c41ab1
CR
2096 is used to duplicate input file descriptors. If WORD expands to one
2097or more digits, the file descriptor denoted by N is made to be a copy
2098of that file descriptor. If the digits in WORD do not specify a file
cce855bc 2099descriptor open for input, a redirection error occurs. If WORD
7117c2d2
JA
2100evaluates to `-', file descriptor N is closed. If N is not specified,
2101the standard input (file descriptor 0) is used.
ccc6cda3
JA
2102
2103 The operator
7117c2d2 2104 [N]>&WORD
37c41ab1 2105 is used similarly to duplicate output file descriptors. If N is not
cce855bc
JA
2106specified, the standard output (file descriptor 1) is used. If the
2107digits in WORD do not specify a file descriptor open for output, a
7117c2d2
JA
2108redirection error occurs. As a special case, if N is omitted, and WORD
2109does not expand to one or more digits, the standard output and standard
2110error are redirected as described previously.
2111
ed35cb4a 21123.6.9 Moving File Descriptors
37c41ab1 2113-----------------------------
7117c2d2 2114
37c41ab1 2115The redirection operator
7117c2d2 2116 [N]<&DIGIT-
37c41ab1
CR
2117 moves the file descriptor DIGIT to file descriptor N, or the
2118standard input (file descriptor 0) if N is not specified. DIGIT is
2119closed after being duplicated to N.
7117c2d2
JA
2120
2121 Similarly, the redirection operator
2122 [N]>&DIGIT-
37c41ab1
CR
2123 moves the file descriptor DIGIT to file descriptor N, or the
2124standard output (file descriptor 1) if N is not specified.
7117c2d2 2125
ed35cb4a
CR
21263.6.10 Opening File Descriptors for Reading and Writing
2127-------------------------------------------------------
ccc6cda3 2128
37c41ab1 2129The redirection operator
7117c2d2 2130 [N]<>WORD
37c41ab1 2131 causes the file whose name is the expansion of WORD to be opened for
7117c2d2
JA
2132both reading and writing on file descriptor N, or on file descriptor 0
2133if N is not specified. If the file does not exist, it is created.
ccc6cda3
JA
2134
2135\1f
2136File: bashref.info, Node: Executing Commands, Next: Shell Scripts, Prev: Redirections, Up: Basic Shell Features
2137
37c41ab1
CR
21383.7 Executing Commands
2139======================
ccc6cda3
JA
2140
2141* Menu:
2142
cce855bc
JA
2143* Simple Command Expansion:: How Bash expands simple commands before
2144 executing them.
ccc6cda3 2145* Command Search and Execution:: How Bash finds commands and runs them.
cce855bc
JA
2146* Command Execution Environment:: The environment in which Bash
2147 executes commands that are not
2148 shell builtins.
ccc6cda3 2149* Environment:: The environment given to a command.
ccc6cda3
JA
2150* Exit Status:: The status returned by commands and how Bash
2151 interprets it.
ccc6cda3
JA
2152* Signals:: What happens when Bash or a command it runs
2153 receives a signal.
2154
2155\1f
cce855bc
JA
2156File: bashref.info, Node: Simple Command Expansion, Next: Command Search and Execution, Up: Executing Commands
2157
37c41ab1
CR
21583.7.1 Simple Command Expansion
2159------------------------------
cce855bc 2160
37c41ab1 2161When a simple command is executed, the shell performs the following
cce855bc
JA
2162expansions, assignments, and redirections, from left to right.
2163
2164 1. The words that the parser has marked as variable assignments (those
2165 preceding the command name) and redirections are saved for later
2166 processing.
2167
2168 2. The words that are not variable assignments or redirections are
28ef6c31 2169 expanded (*note Shell Expansions::). If any words remain after
cce855bc
JA
2170 expansion, the first word is taken to be the name of the command
2171 and the remaining words are the arguments.
2172
2173 3. Redirections are performed as described above (*note
28ef6c31 2174 Redirections::).
cce855bc
JA
2175
2176 4. The text after the `=' in each variable assignment undergoes tilde
2177 expansion, parameter expansion, command substitution, arithmetic
2178 expansion, and quote removal before being assigned to the variable.
2179
2180 If no command name results, the variable assignments affect the
2181current shell environment. Otherwise, the variables are added to the
2182environment of the executed command and do not affect the current shell
2183environment. If any of the assignments attempts to assign a value to a
2184readonly variable, an error occurs, and the command exits with a
2185non-zero status.
2186
2187 If no command name results, redirections are performed, but do not
2188affect the current shell environment. A redirection error causes the
2189command to exit with a non-zero status.
2190
2191 If there is a command name left after expansion, execution proceeds
2192as described below. Otherwise, the command exits. If one of the
2193expansions contained a command substitution, the exit status of the
2194command is the exit status of the last command substitution performed.
2195If there were no command substitutions, the command exits with a status
2196of zero.
2197
2198\1f
2199File: bashref.info, Node: Command Search and Execution, Next: Command Execution Environment, Prev: Simple Command Expansion, Up: Executing Commands
ccc6cda3 2200
37c41ab1
CR
22013.7.2 Command Search and Execution
2202----------------------------------
ccc6cda3 2203
37c41ab1 2204After a command has been split into words, if it results in a simple
ccc6cda3
JA
2205command and an optional list of arguments, the following actions are
2206taken.
2207
2208 1. If the command name contains no slashes, the shell attempts to
2209 locate it. If there exists a shell function by that name, that
6a8fd0ed 2210 function is invoked as described in *note Shell Functions::.
ccc6cda3
JA
2211
2212 2. If the name does not match a function, the shell searches for it
2213 in the list of shell builtins. If a match is found, that builtin
2214 is invoked.
2215
2216 3. If the name is neither a shell function nor a builtin, and
2217 contains no slashes, Bash searches each element of `$PATH' for a
2218 directory containing an executable file by that name. Bash uses a
cce855bc
JA
2219 hash table to remember the full pathnames of executable files to
2220 avoid multiple `PATH' searches (see the description of `hash' in
6a8fd0ed 2221 *note Bourne Shell Builtins::). A full search of the directories
ccc6cda3 2222 in `$PATH' is performed only if the command is not found in the
ed35cb4a
CR
2223 hash table. If the search is unsuccessful, the shell searches for
2224 a defined shell function named `command_not_found_handle'. If
2225 that function exists, it is invoked with the original command and
2226 the original command's arguments as its arguments, and the
2227 function's exit status becomes the exit status of the shell. If
2228 that function is not defined, the shell prints an error message
2229 and returns an exit status of 127.
ccc6cda3
JA
2230
2231 4. If the search is successful, or if the command name contains one
cce855bc
JA
2232 or more slashes, the shell executes the named program in a
2233 separate execution environment. Argument 0 is set to the name
2234 given, and the remaining arguments to the command are set to the
2235 arguments supplied, if any.
ccc6cda3
JA
2236
2237 5. If this execution fails because the file is not in executable
cce855bc 2238 format, and the file is not a directory, it is assumed to be a
6a8fd0ed 2239 SHELL SCRIPT and the shell executes it as described in *note Shell
cce855bc
JA
2240 Scripts::.
2241
2242 6. If the command was not begun asynchronously, the shell waits for
2243 the command to complete and collects its exit status.
2244
2245
2246\1f
2247File: bashref.info, Node: Command Execution Environment, Next: Environment, Prev: Command Search and Execution, Up: Executing Commands
2248
37c41ab1
CR
22493.7.3 Command Execution Environment
2250-----------------------------------
cce855bc 2251
37c41ab1 2252The shell has an EXECUTION ENVIRONMENT, which consists of the following:
cce855bc
JA
2253
2254 * open files inherited by the shell at invocation, as modified by
2255 redirections supplied to the `exec' builtin
2256
2257 * the current working directory as set by `cd', `pushd', or `popd',
2258 or inherited by the shell at invocation
2259
2260 * the file creation mode mask as set by `umask' or inherited from
2261 the shell's parent
2262
2263 * current traps set by `trap'
2264
2265 * shell parameters that are set by variable assignment or with `set'
2266 or inherited from the shell's parent in the environment
2267
2268 * shell functions defined during execution or inherited from the
2269 shell's parent in the environment
2270
2271 * options enabled at invocation (either by default or with
2272 command-line arguments) or by `set'
2273
d3ad40de 2274 * options enabled by `shopt' (*note The Shopt Builtin::)
cce855bc 2275
28ef6c31 2276 * shell aliases defined with `alias' (*note Aliases::)
cce855bc
JA
2277
2278 * various process IDs, including those of background jobs (*note
28ef6c31
JA
2279 Lists::), the value of `$$', and the value of `$PPID'
2280
cce855bc
JA
2281
2282 When a simple command other than a builtin or shell function is to
2283be executed, it is invoked in a separate execution environment that
2284consists of the following. Unless otherwise noted, the values are
2285inherited from the shell.
2286
2287 * the shell's open files, plus any modifications and additions
2288 specified by redirections to the command
2289
2290 * the current working directory
2291
2292 * the file creation mode mask
2293
d3a24ed2
CR
2294 * shell variables and functions marked for export, along with
2295 variables exported for the command, passed in the environment
2296 (*note Environment::)
cce855bc
JA
2297
2298 * traps caught by the shell are reset to the values inherited from
2299 the shell's parent, and traps ignored by the shell are ignored
2300
28ef6c31 2301
cce855bc
JA
2302 A command invoked in this separate environment cannot affect the
2303shell's execution environment.
2304
d3a24ed2
CR
2305 Command substitution, commands grouped with parentheses, and
2306asynchronous commands are invoked in a subshell environment that is a
2307duplicate of the shell environment, except that traps caught by the
2308shell are reset to the values that the shell inherited from its parent
2309at invocation. Builtin commands that are invoked as part of a pipeline
2310are also executed in a subshell environment. Changes made to the
2311subshell environment cannot affect the shell's execution environment.
ccc6cda3 2312
db31fb26
CR
2313 Subshells spawned to execute command substitutions inherit the value
2314of the `-e' option from the parent shell. When not in POSIX mode, Bash
2315clears the `-e' option in such subshells.
2316
f73dda09
JA
2317 If a command is followed by a `&' and job control is not active, the
2318default standard input for the command is the empty file `/dev/null'.
2319Otherwise, the invoked command inherits the file descriptors of the
2320calling shell as modified by redirections.
2321
ccc6cda3 2322\1f
cce855bc 2323File: bashref.info, Node: Environment, Next: Exit Status, Prev: Command Execution Environment, Up: Executing Commands
ccc6cda3 2324
37c41ab1
CR
23253.7.4 Environment
2326-----------------
ccc6cda3 2327
37c41ab1 2328When a program is invoked it is given an array of strings called the
ccc6cda3
JA
2329ENVIRONMENT. This is a list of name-value pairs, of the form
2330`name=value'.
2331
bb70624e 2332 Bash provides several ways to manipulate the environment. On
ccc6cda3
JA
2333invocation, the shell scans its own environment and creates a parameter
2334for each name found, automatically marking it for EXPORT to child
2335processes. Executed commands inherit the environment. The `export'
2336and `declare -x' commands allow parameters and functions to be added to
2337and deleted from the environment. If the value of a parameter in the
2338environment is modified, the new value becomes part of the environment,
2339replacing the old. The environment inherited by any executed command
2340consists of the shell's initial environment, whose values may be
cce855bc
JA
2341modified in the shell, less any pairs removed by the `unset' and
2342`export -n' commands, plus any additions via the `export' and `declare
2343-x' commands.
ccc6cda3
JA
2344
2345 The environment for any simple command or function may be augmented
2346temporarily by prefixing it with parameter assignments, as described in
6a8fd0ed 2347*note Shell Parameters::. These assignment statements affect only the
ccc6cda3
JA
2348environment seen by that command.
2349
28ef6c31 2350 If the `-k' option is set (*note The Set Builtin::), then all
ccc6cda3
JA
2351parameter assignments are placed in the environment for a command, not
2352just those that precede the command name.
2353
2354 When Bash invokes an external command, the variable `$_' is set to
122f603c 2355the full pathname of the command and passed to that command in its
ccc6cda3
JA
2356environment.
2357
2358\1f
2359File: bashref.info, Node: Exit Status, Next: Signals, Prev: Environment, Up: Executing Commands
2360
37c41ab1
CR
23613.7.5 Exit Status
2362-----------------
ccc6cda3 2363
29d25b54
CR
2364The exit status of an executed command is the value returned by the
2365WAITPID system call or equivalent function. Exit statuses fall between
23660 and 255, though, as explained below, the shell may use values above
2367125 specially. Exit statuses from shell builtins and compound commands
122f603c 2368are also limited to this range. Under certain circumstances, the shell
29d25b54
CR
2369will use special values to indicate specific failure modes.
2370
2371 For the shell's purposes, a command which exits with a zero exit
2372status has succeeded. A non-zero exit status indicates failure. This
cce855bc
JA
2373seemingly counter-intuitive scheme is used so there is one well-defined
2374way to indicate success and a variety of ways to indicate various
2375failure modes. When a command terminates on a fatal signal whose
2376number is N, Bash uses the value 128+N as the exit status.
ccc6cda3
JA
2377
2378 If a command is not found, the child process created to execute it
2379returns a status of 127. If a command is found but is not executable,
2380the return status is 126.
2381
cce855bc
JA
2382 If a command fails because of an error during expansion or
2383redirection, the exit status is greater than zero.
2384
ccc6cda3 2385 The exit status is used by the Bash conditional commands (*note
28ef6c31
JA
2386Conditional Constructs::) and some of the list constructs (*note
2387Lists::).
ccc6cda3
JA
2388
2389 All of the Bash builtins return an exit status of zero if they
2390succeed and a non-zero status on failure, so they may be used by the
cce855bc
JA
2391conditional and list constructs. All builtins return an exit status of
23922 to indicate incorrect usage.
ccc6cda3
JA
2393
2394\1f
2395File: bashref.info, Node: Signals, Prev: Exit Status, Up: Executing Commands
2396
37c41ab1
CR
23973.7.6 Signals
2398-------------
ccc6cda3 2399
37c41ab1 2400When Bash is interactive, in the absence of any traps, it ignores
cce855bc
JA
2401`SIGTERM' (so that `kill 0' does not kill an interactive shell), and
2402`SIGINT' is caught and handled (so that the `wait' builtin is
2403interruptible). When Bash receives a `SIGINT', it breaks out of any
2404executing loops. In all cases, Bash ignores `SIGQUIT'. If job control
28ef6c31 2405is in effect (*note Job Control::), Bash ignores `SIGTTIN', `SIGTTOU',
cce855bc 2406and `SIGTSTP'.
ccc6cda3 2407
5e13499c
CR
2408 Non-builtin commands started by Bash have signal handlers set to the
2409values inherited by the shell from its parent. When job control is not
2410in effect, asynchronous commands ignore `SIGINT' and `SIGQUIT' in
2411addition to these inherited handlers. Commands run as a result of
2412command substitution ignore the keyboard-generated job control signals
2413`SIGTTIN', `SIGTTOU', and `SIGTSTP'.
ccc6cda3
JA
2414
2415 The shell exits by default upon receipt of a `SIGHUP'. Before
f73dda09
JA
2416exiting, an interactive shell resends the `SIGHUP' to all jobs, running
2417or stopped. Stopped jobs are sent `SIGCONT' to ensure that they receive
2418the `SIGHUP'. To prevent the shell from sending the `SIGHUP' signal to
2419a particular job, it should be removed from the jobs table with the
28ef6c31 2420`disown' builtin (*note Job Control Builtins::) or marked to not
cce855bc
JA
2421receive `SIGHUP' using `disown -h'.
2422
2423 If the `huponexit' shell option has been set with `shopt' (*note
d3ad40de
CR
2424The Shopt Builtin::), Bash sends a `SIGHUP' to all jobs when an
2425interactive login shell exits.
cce855bc 2426
5e13499c
CR
2427 If Bash is waiting for a command to complete and receives a signal
2428for which a trap has been set, the trap will not be executed until the
2429command completes. When Bash is waiting for an asynchronous command
2430via the `wait' builtin, the reception of a signal for which a trap has
2431been set will cause the `wait' builtin to return immediately with an
2432exit status greater than 128, immediately after which the trap is
2433executed.
ccc6cda3
JA
2434
2435\1f
2436File: bashref.info, Node: Shell Scripts, Prev: Executing Commands, Up: Basic Shell Features
2437
37c41ab1
CR
24383.8 Shell Scripts
2439=================
ccc6cda3 2440
37c41ab1
CR
2441A shell script is a text file containing shell commands. When such a
2442file is used as the first non-option argument when invoking Bash, and
28ef6c31 2443neither the `-c' nor `-s' option is supplied (*note Invoking Bash::),
ccc6cda3 2444Bash reads and executes commands from the file, then exits. This mode
f73dda09
JA
2445of operation creates a non-interactive shell. The shell first searches
2446for the file in the current directory, and looks in the directories in
2447`$PATH' if not found there.
2448
2449 When Bash runs a shell script, it sets the special parameter `0' to
2450the name of the file, rather than the name of the shell, and the
2451positional parameters are set to the remaining arguments, if any are
2452given. If no additional arguments are supplied, the positional
2453parameters are unset.
ccc6cda3
JA
2454
2455 A shell script may be made executable by using the `chmod' command
2456to turn on the execute bit. When Bash finds such a file while
2457searching the `$PATH' for a command, it spawns a subshell to execute
2458it. In other words, executing
2459 filename ARGUMENTS
37c41ab1 2460 is equivalent to executing
ccc6cda3
JA
2461 bash filename ARGUMENTS
2462
2463if `filename' is an executable shell script. This subshell
2464reinitializes itself, so that the effect is as if a new shell had been
cce855bc
JA
2465invoked to interpret the script, with the exception that the locations
2466of commands remembered by the parent (see the description of `hash' in
6a8fd0ed 2467*note Bourne Shell Builtins::) are retained by the child.
ccc6cda3 2468
bb70624e
JA
2469 Most versions of Unix make this a part of the operating system's
2470command execution mechanism. If the first line of a script begins with
2471the two characters `#!', the remainder of the line specifies an
2472interpreter for the program. Thus, you can specify Bash, `awk', Perl,
2473or some other interpreter and write the rest of the script file in that
2474language.
2475
2476 The arguments to the interpreter consist of a single optional
2477argument following the interpreter name on the first line of the script
2478file, followed by the name of the script file, followed by the rest of
2479the arguments. Bash will perform this action on operating systems that
2480do not handle it themselves. Note that some older versions of Unix
2481limit the interpreter name and argument to a maximum of 32 characters.
2482
2483 Bash scripts often begin with `#! /bin/bash' (assuming that Bash has
2484been installed in `/bin'), since this ensures that Bash will be used to
2485interpret the script, even if it is executed under another shell.
ccc6cda3
JA
2486
2487\1f
bb70624e 2488File: bashref.info, Node: Shell Builtin Commands, Next: Shell Variables, Prev: Basic Shell Features, Up: Top
ccc6cda3 2489
37c41ab1
CR
24904 Shell Builtin Commands
2491************************
ccc6cda3
JA
2492
2493* Menu:
2494
2495* Bourne Shell Builtins:: Builtin commands inherited from the Bourne
2496 Shell.
bb70624e 2497* Bash Builtins:: Table of builtins specific to Bash.
d3ad40de
CR
2498* Modifying Shell Behavior:: Builtins to modify shell attributes and
2499 optional behavior.
bb70624e 2500* Special Builtins:: Builtin commands classified specially by
ac18b312 2501 POSIX.
bb70624e
JA
2502
2503 Builtin commands are contained within the shell itself. When the
2504name of a builtin command is used as the first word of a simple command
28ef6c31 2505(*note Simple Commands::), the shell executes the command directly,
bb70624e
JA
2506without invoking another program. Builtin commands are necessary to
2507implement functionality impossible or inconvenient to obtain with
2508separate utilities.
ccc6cda3 2509
ac18b312
CR
2510 This section briefly describes the builtins which Bash inherits from
2511the Bourne Shell, as well as the builtin commands which are unique to
2512or have been extended in Bash.
bb70624e
JA
2513
2514 Several builtin commands are described in other chapters: builtin
2515commands which provide the Bash interface to the job control facilities
28ef6c31
JA
2516(*note Job Control Builtins::), the directory stack (*note Directory
2517Stack Builtins::), the command history (*note Bash History Builtins::),
2518and the programmable completion facilities (*note Programmable
2519Completion Builtins::).
bb70624e
JA
2520
2521 Many of the builtins have been extended by POSIX or Bash.
ccc6cda3 2522
c2258e1c
CR
2523 Unless otherwise noted, each builtin command documented as accepting
2524options preceded by `-' accepts `--' to signify the end of the options.
6932f7f5
CR
2525The `:', `true', `false', and `test' builtins do not accept options and
2526do not treat `--' specially. The `exit', `logout', `break',
2527`continue', `let', and `shift' builtins accept and process arguments
2528beginning with `-' without requiring `--'. Other builtins that accept
2529arguments but are not specified as accepting options interpret
2530arguments beginning with `-' as invalid options and require `--' to
2531prevent this interpretation.
c2258e1c 2532
ccc6cda3 2533\1f
bb70624e 2534File: bashref.info, Node: Bourne Shell Builtins, Next: Bash Builtins, Up: Shell Builtin Commands
ccc6cda3 2535
37c41ab1
CR
25364.1 Bourne Shell Builtins
2537=========================
ccc6cda3 2538
37c41ab1 2539The following shell builtin commands are inherited from the Bourne
ac18b312 2540Shell. These commands are implemented as specified by the POSIX
ccc6cda3
JA
2541standard.
2542
bb70624e 2543`: (a colon)'
ccc6cda3 2544 : [ARGUMENTS]
122f603c 2545
ccc6cda3 2546 Do nothing beyond expanding ARGUMENTS and performing redirections.
cce855bc 2547 The return status is zero.
ccc6cda3 2548
bb70624e 2549`. (a period)'
b72432fd 2550 . FILENAME [ARGUMENTS]
122f603c 2551
ccc6cda3 2552 Read and execute commands from the FILENAME argument in the
cce855bc 2553 current shell context. If FILENAME does not contain a slash, the
28ef6c31
JA
2554 `PATH' variable is used to find FILENAME. When Bash is not in
2555 POSIX mode, the current directory is searched if FILENAME is not
2556 found in `$PATH'. If any ARGUMENTS are supplied, they become the
2557 positional parameters when FILENAME is executed. Otherwise the
2558 positional parameters are unchanged. The return status is the
2559 exit status of the last command executed, or zero if no commands
2560 are executed. If FILENAME is not found, or cannot be read, the
2561 return status is non-zero. This builtin is equivalent to `source'.
ccc6cda3
JA
2562
2563`break'
2564 break [N]
122f603c 2565
ccc6cda3 2566 Exit from a `for', `while', `until', or `select' loop. If N is
cce855bc
JA
2567 supplied, the Nth enclosing loop is exited. N must be greater
2568 than or equal to 1. The return status is zero unless N is not
2569 greater than or equal to 1.
ccc6cda3
JA
2570
2571`cd'
67362c60 2572 cd [-L|[-P [-e]]] [DIRECTORY]
122f603c 2573
ccc6cda3
JA
2574 Change the current working directory to DIRECTORY. If DIRECTORY
2575 is not given, the value of the `HOME' shell variable is used. If
2576 the shell variable `CDPATH' exists, it is used as a search path.
d3a24ed2
CR
2577 If DIRECTORY begins with a slash, `CDPATH' is not used.
2578
2579 The `-P' option means to not follow symbolic links; symbolic links
67362c60
CR
2580 are followed by default or with the `-L' option. If the `-e'
2581 option is supplied with `-P' and the current working directory
2582 cannot be successfully determined after a successful directory
2583 change, `cd' will return an unsuccessful status. If DIRECTORY is
122f603c
CR
2584 `-', it is converted to `$OLDPWD' before the directory change is
2585 attempted.
d3a24ed2
CR
2586
2587 If a non-empty directory name from `CDPATH' is used, or if `-' is
2588 the first argument, and the directory change is successful, the
2589 absolute pathname of the new working directory is written to the
2590 standard output.
2591
2592 The return status is zero if the directory is successfully changed,
2593 non-zero otherwise.
ccc6cda3
JA
2594
2595`continue'
2596 continue [N]
122f603c 2597
ccc6cda3
JA
2598 Resume the next iteration of an enclosing `for', `while', `until',
2599 or `select' loop. If N is supplied, the execution of the Nth
cce855bc
JA
2600 enclosing loop is resumed. N must be greater than or equal to 1.
2601 The return status is zero unless N is not greater than or equal to
2602 1.
ccc6cda3
JA
2603
2604`eval'
2605 eval [ARGUMENTS]
122f603c 2606
ccc6cda3 2607 The arguments are concatenated together into a single command,
cce855bc
JA
2608 which is then read and executed, and its exit status returned as
2609 the exit status of `eval'. If there are no arguments or only
2610 empty arguments, the return status is zero.
ccc6cda3
JA
2611
2612`exec'
cce855bc 2613 exec [-cl] [-a NAME] [COMMAND [ARGUMENTS]]
122f603c 2614
cce855bc
JA
2615 If COMMAND is supplied, it replaces the shell without creating a
2616 new process. If the `-l' option is supplied, the shell places a
d3ad40de
CR
2617 dash at the beginning of the zeroth argument passed to COMMAND.
2618 This is what the `login' program does. The `-c' option causes
2619 COMMAND to be executed with an empty environment. If `-a' is
2620 supplied, the shell passes NAME as the zeroth argument to COMMAND.
122f603c
CR
2621 If COMMAND cannot be executed for some reason, a non-interactive
2622 shell exits, unless the `execfail' shell option is enabled. In
2623 that case, it returns failure. An interactive shell returns
2624 failure if the file cannot be executed. If no COMMAND is
2625 specified, redirections may be used to affect the current shell
2626 environment. If there are no redirection errors, the return
2627 status is zero; otherwise the return status is non-zero.
ccc6cda3
JA
2628
2629`exit'
2630 exit [N]
122f603c 2631
bb70624e
JA
2632 Exit the shell, returning a status of N to the shell's parent. If
2633 N is omitted, the exit status is that of the last command executed.
cce855bc 2634 Any trap on `EXIT' is executed before the shell terminates.
ccc6cda3
JA
2635
2636`export'
2637 export [-fn] [-p] [NAME[=VALUE]]
122f603c 2638
ccc6cda3
JA
2639 Mark each NAME to be passed to child processes in the environment.
2640 If the `-f' option is supplied, the NAMEs refer to shell
cce855bc
JA
2641 functions; otherwise the names refer to shell variables. The `-n'
2642 option means to no longer mark each NAME for export. If no NAMES
122f603c
CR
2643 are supplied, or if the `-p' option is given, a list of names of
2644 all exported variables is displayed. The `-p' option displays
2645 output in a form that may be reused as input. If a variable name
2646 is followed by =VALUE, the value of the variable is set to VALUE.
d3a24ed2
CR
2647
2648 The return status is zero unless an invalid option is supplied,
2649 one of the names is not a valid shell variable name, or `-f' is
2650 supplied with a name that is not a shell function.
ccc6cda3
JA
2651
2652`getopts'
2653 getopts OPTSTRING NAME [ARGS]
122f603c 2654
ccc6cda3 2655 `getopts' is used by shell scripts to parse positional parameters.
bb70624e
JA
2656 OPTSTRING contains the option characters to be recognized; if a
2657 character is followed by a colon, the option is expected to have an
122f603c 2658 argument, which should be separated from it by whitespace. The
bb70624e
JA
2659 colon (`:') and question mark (`?') may not be used as option
2660 characters. Each time it is invoked, `getopts' places the next
2661 option in the shell variable NAME, initializing NAME if it does
2662 not exist, and the index of the next argument to be processed into
2663 the variable `OPTIND'. `OPTIND' is initialized to 1 each time the
2664 shell or a shell script is invoked. When an option requires an
2665 argument, `getopts' places that argument into the variable
2666 `OPTARG'. The shell does not reset `OPTIND' automatically; it
2667 must be manually reset between multiple calls to `getopts' within
2668 the same shell invocation if a new set of parameters is to be used.
ccc6cda3 2669
cce855bc
JA
2670 When the end of options is encountered, `getopts' exits with a
2671 return value greater than zero. `OPTIND' is set to the index of
e05be32d 2672 the first non-option argument, and NAME is set to `?'.
cce855bc
JA
2673
2674 `getopts' normally parses the positional parameters, but if more
2675 arguments are given in ARGS, `getopts' parses those instead.
2676
ccc6cda3
JA
2677 `getopts' can report errors in two ways. If the first character of
2678 OPTSTRING is a colon, SILENT error reporting is used. In normal
122f603c 2679 operation, diagnostic messages are printed when invalid options or
ccc6cda3 2680 missing option arguments are encountered. If the variable `OPTERR'
cce855bc 2681 is set to 0, no error messages will be displayed, even if the first
ccc6cda3
JA
2682 character of `optstring' is not a colon.
2683
cce855bc 2684 If an invalid option is seen, `getopts' places `?' into NAME and,
ccc6cda3
JA
2685 if not silent, prints an error message and unsets `OPTARG'. If
2686 `getopts' is silent, the option character found is placed in
2687 `OPTARG' and no diagnostic message is printed.
2688
2689 If a required argument is not found, and `getopts' is not silent,
2690 a question mark (`?') is placed in NAME, `OPTARG' is unset, and a
2691 diagnostic message is printed. If `getopts' is silent, then a
2692 colon (`:') is placed in NAME and `OPTARG' is set to the option
2693 character found.
2694
ccc6cda3 2695`hash'
ac18b312 2696 hash [-r] [-p FILENAME] [-dt] [NAME]
122f603c 2697
eb0b2ad8
CR
2698 Each time `hash' is invoked, it remembers the full pathnames of the
2699 commands specified as NAME arguments, so they need not be searched
2700 for on subsequent invocations. The commands are found by
2701 searching through the directories listed in `$PATH'. Any
2702 previously-remembered pathname is discarded. The `-p' option
2703 inhibits the path search, and FILENAME is used as the location of
2704 NAME. The `-r' option causes the shell to forget all remembered
2705 locations. The `-d' option causes the shell to forget the
2706 remembered location of each NAME. If the `-t' option is supplied,
2707 the full pathname to which each NAME corresponds is printed. If
2708 multiple NAME arguments are supplied with `-t' the NAME is printed
2709 before the hashed full pathname. The `-l' option causes output to
2710 be displayed in a format that may be reused as input. If no
7117c2d2
JA
2711 arguments are given, or if only `-l' is supplied, information
2712 about remembered commands is printed. The return status is zero
2713 unless a NAME is not found or an invalid option is supplied.
ccc6cda3
JA
2714
2715`pwd'
2716 pwd [-LP]
122f603c 2717
bb70624e
JA
2718 Print the absolute pathname of the current working directory. If
2719 the `-P' option is supplied, the pathname printed will not contain
2720 symbolic links. If the `-L' option is supplied, the pathname
2721 printed may contain symbolic links. The return status is zero
2722 unless an error is encountered while determining the name of the
2723 current directory or an invalid option is supplied.
ccc6cda3
JA
2724
2725`readonly'
d9e1f41e 2726 readonly [-aAf] [-p] [NAME[=VALUE]] ...
122f603c 2727
cce855bc
JA
2728 Mark each NAME as readonly. The values of these names may not be
2729 changed by subsequent assignment. If the `-f' option is supplied,
2730 each NAME refers to a shell function. The `-a' option means each
09767ff0 2731 NAME refers to an indexed array variable; the `-A' option means
d9e1f41e
CR
2732 each NAME refers to an associative array variable. If both
2733 options are supplied, `-A' takes precedence. If no NAME arguments
2734 are given, or if the `-p' option is supplied, a list of all
2735 readonly names is printed. The other options may be used to
2736 restrict the output to a subset of the set of readonly names. The
2737 `-p' option causes output to be displayed in a format that may be
2738 reused as input. If a variable name is followed by =VALUE, the
2739 value of the variable is set to VALUE. The return status is zero
2740 unless an invalid option is supplied, one of the NAME arguments is
2741 not a valid shell variable or function name, or the `-f' option is
2742 supplied with a name that is not a shell function.
ccc6cda3
JA
2743
2744`return'
2745 return [N]
122f603c
CR
2746
2747 Cause a shell function to stop executing and return the value N to
2748 its caller. If N is not supplied, the return value is the exit
2749 status of the last command executed in the function. `return' may
2750 also be used to terminate execution of a script being executed
2751 with the `.' (`source') builtin, returning either N or the exit
2752 status of the last command executed within the script as the exit
2753 status of the script. Any command associated with the `RETURN'
2754 trap is executed before execution resumes after the function or
2755 script. The return status is non-zero if `return' is used outside
2756 a function and not during the execution of a script by `.' or
2757 `source'.
ccc6cda3
JA
2758
2759`shift'
2760 shift [N]
122f603c 2761
cce855bc 2762 Shift the positional parameters to the left by N. The positional
d3ad40de
CR
2763 parameters from N+1 ... `$#' are renamed to `$1' ... `$#'-N.
2764 Parameters represented by the numbers `$#' to `$#'-N+1 are unset.
2765 N must be a non-negative number less than or equal to `$#'. If N
2766 is zero or greater than `$#', the positional parameters are not
bb70624e
JA
2767 changed. If N is not supplied, it is assumed to be 1. The return
2768 status is zero unless N is greater than `$#' or less than zero,
2769 non-zero otherwise.
ccc6cda3 2770
122f603c 2771`test[B'
ccc6cda3 2772`['
122f603c
CR
2773 test EXPR
2774
2775 Evaluate a conditional expression EXPR and return a status of 0
2776 (true) or 1 (false). Each operator and operand must be a separate
2777 argument. Expressions are composed of the primaries described
2778 below in *note Bash Conditional Expressions::. `test' does not
2779 accept any options, nor does it accept and ignore an argument of
2780 `--' as signifying the end of options.
cce855bc 2781
bb70624e
JA
2782 When the `[' form is used, the last argument to the command must
2783 be a `]'.
2784
cce855bc 2785 Expressions may be combined using the following operators, listed
d7f49990 2786 in decreasing order of precedence. The evaluation depends on the
510e20a2
CR
2787 number of arguments; see below. Operator precedence is used when
2788 there are five or more arguments.
cce855bc
JA
2789
2790 `! EXPR'
2791 True if EXPR is false.
2792
2793 `( EXPR )'
2794 Returns the value of EXPR. This may be used to override the
2795 normal precedence of operators.
2796
2797 `EXPR1 -a EXPR2'
2798 True if both EXPR1 and EXPR2 are true.
2799
2800 `EXPR1 -o EXPR2'
2801 True if either EXPR1 or EXPR2 is true.
2802
2803 The `test' and `[' builtins evaluate conditional expressions using
2804 a set of rules based on the number of arguments.
2805
2806 0 arguments
2807 The expression is false.
2808
2809 1 argument
2810 The expression is true if and only if the argument is not
2811 null.
2812
2813 2 arguments
2814 If the first argument is `!', the expression is true if and
2815 only if the second argument is null. If the first argument
2816 is one of the unary conditional operators (*note Bash
28ef6c31 2817 Conditional Expressions::), the expression is true if the
cce855bc
JA
2818 unary test is true. If the first argument is not a valid
2819 unary operator, the expression is false.
2820
2821 3 arguments
510e20a2
CR
2822 The following conditions are applied in the order listed. If
2823 the second argument is one of the binary conditional
28ef6c31 2824 operators (*note Bash Conditional Expressions::), the result
cce855bc 2825 of the expression is the result of the binary test using the
d7f49990
CR
2826 first and third arguments as operands. The `-a' and `-o'
2827 operators are considered binary operators when there are
2828 three arguments. If the first argument is `!', the value is
2829 the negation of the two-argument test using the second and
2830 third arguments. If the first argument is exactly `(' and
2831 the third argument is exactly `)', the result is the
2832 one-argument test of the second argument. Otherwise, the
2833 expression is false.
cce855bc
JA
2834
2835 4 arguments
2836 If the first argument is `!', the result is the negation of
2837 the three-argument expression composed of the remaining
2838 arguments. Otherwise, the expression is parsed and evaluated
2839 according to precedence using the rules listed above.
2840
2841 5 or more arguments
2842 The expression is parsed and evaluated according to precedence
2843 using the rules listed above.
ccc6cda3 2844
54a1fa7c
CR
2845 When used with `test' or `[', the `<' and `>' operators sort
2846 lexicographically using ASCII ordering.
2847
ccc6cda3
JA
2848`times'
2849 times
122f603c 2850
ccc6cda3 2851 Print out the user and system times used by the shell and its
cce855bc 2852 children. The return status is zero.
ccc6cda3
JA
2853
2854`trap'
d166f048 2855 trap [-lp] [ARG] [SIGSPEC ...]
122f603c 2856
ccc6cda3 2857 The commands in ARG are to be read and executed when the shell
9f422431
CR
2858 receives signal SIGSPEC. If ARG is absent (and there is a single
2859 SIGSPEC) or equal to `-', each specified signal's disposition is
2860 reset to the value it had when the shell was started. If ARG is
2861 the null string, then the signal specified by each SIGSPEC is
2862 ignored by the shell and commands it invokes. If ARG is not
2863 present and `-p' has been supplied, the shell displays the trap
2864 commands associated with each SIGSPEC. If no arguments are
2865 supplied, or only `-p' is given, `trap' prints the list of commands
2866 associated with each signal number in a form that may be reused as
2867 shell input. The `-l' option causes the shell to print a list of
2868 signal names and their corresponding numbers. Each SIGSPEC is
2869 either a signal name or a signal number. Signal names are case
4a8bb13f
CR
2870 insensitive and the `SIG' prefix is optional.
2871
2872 If a SIGSPEC is `0' or `EXIT', ARG is executed when the shell
2873 exits. If a SIGSPEC is `DEBUG', the command ARG is executed
2874 before every simple command, `for' command, `case' command,
2875 `select' command, every arithmetic `for' command, and before the
2876 first command executes in a shell function. Refer to the
2877 description of the `extdebug' option to the `shopt' builtin (*note
2878 The Shopt Builtin::) for details of its effect on the `DEBUG' trap.
2879 If a SIGSPEC is `RETURN', the command ARG is executed each time a
2880 shell function or a script executed with the `.' or `source'
2881 builtins finishes executing.
2882
2883 If a SIGSPEC is `ERR', the command ARG is executed whenever a
2884 simple command has a non-zero exit status, subject to the
2885 following conditions. The `ERR' trap is not executed if the
2886 failed command is part of the command list immediately following
2887 an `until' or `while' keyword, part of the test following the `if'
2888 or `elif' reserved words, part of a command executed in a `&&' or
2889 `||' list, or if the command's return status is being inverted
2890 using `!'. These are the same conditions obeyed by the `errexit'
2891 option.
d3a24ed2 2892
ccc6cda3 2893 Signals ignored upon entry to the shell cannot be trapped or reset.
d3ad40de 2894 Trapped signals that are not being ignored are reset to their
4a8bb13f
CR
2895 original values in a subshell or subshell environment when one is
2896 created.
ccc6cda3 2897
cce855bc
JA
2898 The return status is zero unless a SIGSPEC does not specify a
2899 valid signal.
2900
ccc6cda3 2901`umask'
cce855bc 2902 umask [-p] [-S] [MODE]
122f603c 2903
ccc6cda3
JA
2904 Set the shell process's file creation mask to MODE. If MODE
2905 begins with a digit, it is interpreted as an octal number; if not,
2906 it is interpreted as a symbolic mode mask similar to that accepted
2907 by the `chmod' command. If MODE is omitted, the current value of
2908 the mask is printed. If the `-S' option is supplied without a
cce855bc
JA
2909 MODE argument, the mask is printed in a symbolic format. If the
2910 `-p' option is supplied, and MODE is omitted, the output is in a
2911 form that may be reused as input. The return status is zero if
2912 the mode is successfully changed or if no MODE argument is
2913 supplied, and non-zero otherwise.
ccc6cda3 2914
bb70624e
JA
2915 Note that when the mode is interpreted as an octal number, each
2916 number of the umask is subtracted from `7'. Thus, a umask of `022'
2917 results in permissions of `755'.
2918
ccc6cda3
JA
2919`unset'
2920 unset [-fv] [NAME]
122f603c
CR
2921
2922 Remove each variable or function NAME. If the `-v' option is
74d0116b
CR
2923 given, each NAME refers to a shell variable and that variable is
2924 remvoved. If the `-f' option is given, the NAMEs refer to shell
2925 functions, and the function definition is removed. If no options
2926 are supplied, each NAME refers to a variable; if there is no
2927 variable by that name, any function with that name is unset.
2928 Readonly variables and functions may not be unset. The return
2929 status is zero unless a NAME is readonly.
ccc6cda3
JA
2930
2931\1f
d3ad40de 2932File: bashref.info, Node: Bash Builtins, Next: Modifying Shell Behavior, Prev: Bourne Shell Builtins, Up: Shell Builtin Commands
ccc6cda3 2933
37c41ab1
CR
29344.2 Bash Builtin Commands
2935=========================
ccc6cda3 2936
37c41ab1 2937This section describes builtin commands which are unique to or have
bb70624e 2938been extended in Bash. Some of these commands are specified in the
ac18b312 2939POSIX standard.
ccc6cda3 2940
bb70624e 2941`alias'
122f603c 2942 alias [-p] [NAME[=VALUE] ...]
ccc6cda3 2943
bb70624e
JA
2944 Without arguments or with the `-p' option, `alias' prints the list
2945 of aliases on the standard output in a form that allows them to be
2946 reused as input. If arguments are supplied, an alias is defined
2947 for each NAME whose VALUE is given. If no VALUE is given, the name
6a8fd0ed 2948 and value of the alias is printed. Aliases are described in *note
bb70624e 2949 Aliases::.
ccc6cda3 2950
bb70624e
JA
2951`bind'
2952 bind [-m KEYMAP] [-lpsvPSV]
2953 bind [-m KEYMAP] [-q FUNCTION] [-u FUNCTION] [-r KEYSEQ]
2954 bind [-m KEYMAP] -f FILENAME
2955 bind [-m KEYMAP] -x KEYSEQ:SHELL-COMMAND
2956 bind [-m KEYMAP] KEYSEQ:FUNCTION-NAME
7117c2d2 2957 bind READLINE-COMMAND
ccc6cda3 2958
28ef6c31 2959 Display current Readline (*note Command Line Editing::) key and
7117c2d2
JA
2960 function bindings, bind a key sequence to a Readline function or
2961 macro, or set a Readline variable. Each non-option argument is a
d3ad40de 2962 command as it would appear in a Readline initialization file
7117c2d2
JA
2963 (*note Readline Init File::), but each binding or command must be
2964 passed as a separate argument; e.g.,
ed35cb4a
CR
2965 `"\C-x\C-r":re-read-init-file'.
2966
2967 Options, if supplied, have the following meanings:
ccc6cda3 2968
bb70624e
JA
2969 `-m KEYMAP'
2970 Use KEYMAP as the keymap to be affected by the subsequent
2971 bindings. Acceptable KEYMAP names are `emacs',
28ef6c31 2972 `emacs-standard', `emacs-meta', `emacs-ctlx', `vi', `vi-move',
bb70624e
JA
2973 `vi-command', and `vi-insert'. `vi' is equivalent to
2974 `vi-command'; `emacs' is equivalent to `emacs-standard'.
cce855bc 2975
bb70624e
JA
2976 `-l'
2977 List the names of all Readline functions.
cce855bc 2978
bb70624e
JA
2979 `-p'
2980 Display Readline function names and bindings in such a way
2981 that they can be used as input or in a Readline
2982 initialization file.
cce855bc 2983
bb70624e
JA
2984 `-P'
2985 List current Readline function names and bindings.
cce855bc 2986
bb70624e
JA
2987 `-v'
2988 Display Readline variable names and values in such a way that
2989 they can be used as input or in a Readline initialization
2990 file.
ccc6cda3 2991
bb70624e
JA
2992 `-V'
2993 List current Readline variable names and values.
ccc6cda3 2994
bb70624e
JA
2995 `-s'
2996 Display Readline key sequences bound to macros and the
2997 strings they output in such a way that they can be used as
2998 input or in a Readline initialization file.
ccc6cda3 2999
bb70624e
JA
3000 `-S'
3001 Display Readline key sequences bound to macros and the
3002 strings they output.
ccc6cda3 3003
bb70624e
JA
3004 `-f FILENAME'
3005 Read key bindings from FILENAME.
ccc6cda3 3006
bb70624e
JA
3007 `-q FUNCTION'
3008 Query about which keys invoke the named FUNCTION.
ccc6cda3 3009
bb70624e
JA
3010 `-u FUNCTION'
3011 Unbind all keys bound to the named FUNCTION.
ccc6cda3 3012
bb70624e
JA
3013 `-r KEYSEQ'
3014 Remove any current binding for KEYSEQ.
ccc6cda3 3015
bb70624e
JA
3016 `-x KEYSEQ:SHELL-COMMAND'
3017 Cause SHELL-COMMAND to be executed whenever KEYSEQ is entered.
ed35cb4a
CR
3018 When SHELL-COMMAND is executed, the shell sets the
3019 `READLINE_LINE' variable to the contents of the Readline line
3020 buffer and the `READLINE_POINT' variable to the current
3021 location of the insertion point. If the executed command
3022 changes the value of `READLINE_LINE' or `READLINE_POINT',
3023 those new values will be reflected in the editing state.
761783bf 3024
bb70624e
JA
3025 The return status is zero unless an invalid option is supplied or
3026 an error occurs.
ccc6cda3 3027
bb70624e
JA
3028`builtin'
3029 builtin [SHELL-BUILTIN [ARGS]]
122f603c 3030
bb70624e
JA
3031 Run a shell builtin, passing it ARGS, and return its exit status.
3032 This is useful when defining a shell function with the same name
3033 as a shell builtin, retaining the functionality of the builtin
3034 within the function. The return status is non-zero if
3035 SHELL-BUILTIN is not a shell builtin command.
ccc6cda3 3036
d3a24ed2
CR
3037`caller'
3038 caller [EXPR]
122f603c 3039
d3a24ed2 3040 Returns the context of any active subroutine call (a shell
5e13499c 3041 function or a script executed with the `.' or `source' builtins).
d3a24ed2
CR
3042
3043 Without EXPR, `caller' displays the line number and source
3044 filename of the current subroutine call. If a non-negative
3045 integer is supplied as EXPR, `caller' displays the line number,
3046 subroutine name, and source file corresponding to that position in
3047 the current execution call stack. This extra information may be
3048 used, for example, to print a stack trace. The current frame is
3049 frame 0.
3050
3051 The return value is 0 unless the shell is not executing a
3052 subroutine call or EXPR does not correspond to a valid position in
3053 the call stack.
3054
bb70624e
JA
3055`command'
3056 command [-pVv] COMMAND [ARGUMENTS ...]
122f603c 3057
bb70624e
JA
3058 Runs COMMAND with ARGUMENTS ignoring any shell function named
3059 COMMAND. Only shell builtin commands or commands found by
3060 searching the `PATH' are executed. If there is a shell function
3061 named `ls', running `command ls' within the function will execute
3062 the external command `ls' instead of calling the function
3063 recursively. The `-p' option means to use a default value for
28ef6c31 3064 `PATH' that is guaranteed to find all of the standard utilities.
bb70624e
JA
3065 The return status in this case is 127 if COMMAND cannot be found
3066 or an error occurred, and the exit status of COMMAND otherwise.
ccc6cda3 3067
bb70624e
JA
3068 If either the `-V' or `-v' option is supplied, a description of
3069 COMMAND is printed. The `-v' option causes a single word
3070 indicating the command or file name used to invoke COMMAND to be
3071 displayed; the `-V' option produces a more verbose description.
3072 In this case, the return status is zero if COMMAND is found, and
3073 non-zero if not.
ccc6cda3 3074
bb70624e 3075`declare'
122f603c 3076 declare [-aAfFgilrtux] [-p] [NAME[=VALUE] ...]
ccc6cda3 3077
bb70624e
JA
3078 Declare variables and give them attributes. If no NAMEs are
3079 given, then display the values of variables instead.
ccc6cda3 3080
bb70624e 3081 The `-p' option will display the attributes and values of each
6a8fd0ed
CR
3082 NAME. When `-p' is used with NAME arguments, additional options
3083 are ignored.
3084
3085 When `-p' is supplied without NAME arguments, `declare' will
3086 display the attributes and values of all variables having the
3087 attributes specified by the additional options. If no other
3088 options are supplied with `-p', `declare' will display the
3089 attributes and values of all shell variables. The `-f' option
3090 will restrict the display to shell functions.
3091
3092 The `-F' option inhibits the display of function definitions; only
3093 the function name and attributes are printed. If the `extdebug'
3094 shell option is enabled using `shopt' (*note The Shopt Builtin::),
3095 the source file name and line number where the function is defined
220537f2
CR
3096 are displayed as well. `-F' implies `-f'.
3097
3098 The `-g' option forces variables to be created or modified at the
d9e1f41e
CR
3099 global scope, even when `declare' is executed in a shell function.
3100 It is ignored in all other cases.
220537f2
CR
3101
3102 The following options can be used to restrict output to variables
3103 with the specified attributes or to give variables attributes:
ccc6cda3 3104
bb70624e 3105 `-a'
09767ff0
CR
3106 Each NAME is an indexed array variable (*note Arrays::).
3107
3108 `-A'
3109 Each NAME is an associative array variable (*note Arrays::).
ccc6cda3 3110
bb70624e
JA
3111 `-f'
3112 Use function names only.
ccc6cda3 3113
bb70624e
JA
3114 `-i'
3115 The variable is to be treated as an integer; arithmetic
28ef6c31 3116 evaluation (*note Shell Arithmetic::) is performed when the
bb70624e 3117 variable is assigned a value.
ccc6cda3 3118
8e1a6eaa
CR
3119 `-l'
3120 When the variable is assigned a value, all upper-case
3121 characters are converted to lower-case. The upper-case
3122 attribute is disabled.
3123
bb70624e
JA
3124 `-r'
3125 Make NAMEs readonly. These names cannot then be assigned
3126 values by subsequent assignment statements or unset.
ccc6cda3 3127
7117c2d2
JA
3128 `-t'
3129 Give each NAME the `trace' attribute. Traced functions
8fed3589
CR
3130 inherit the `DEBUG' and `RETURN' traps from the calling shell.
3131 The trace attribute has no special meaning for variables.
7117c2d2 3132
8e1a6eaa
CR
3133 `-u'
3134 When the variable is assigned a value, all lower-case
3135 characters are converted to upper-case. The lower-case
3136 attribute is disabled.
3137
bb70624e
JA
3138 `-x'
3139 Mark each NAME for export to subsequent commands via the
3140 environment.
ccc6cda3 3141
d3ad40de
CR
3142 Using `+' instead of `-' turns off the attribute instead, with the
3143 exceptions that `+a' may not be used to destroy an array variable
3144 and `+r' will not remove the readonly attribute. When used in a
3145 function, `declare' makes each NAME local, as with the `local'
220537f2
CR
3146 command, unless the `-g' option is used. If a variable name is
3147 followed by =VALUE, the value of the variable is set to VALUE.
ccc6cda3 3148
bb70624e
JA
3149 The return status is zero unless an invalid option is encountered,
3150 an attempt is made to define a function using `-f foo=bar', an
3151 attempt is made to assign a value to a readonly variable, an
3152 attempt is made to assign a value to an array variable without
28ef6c31 3153 using the compound assignment syntax (*note Arrays::), one of the
bb70624e
JA
3154 NAMES is not a valid shell variable name, an attempt is made to
3155 turn off readonly status for a readonly variable, an attempt is
3156 made to turn off array status for an array variable, or an attempt
3157 is made to display a non-existent function with `-f'.
ccc6cda3 3158
bb70624e
JA
3159`echo'
3160 echo [-neE] [ARG ...]
122f603c 3161
bb70624e 3162 Output the ARGs, separated by spaces, terminated with a newline.
74d0116b
CR
3163 The return status is 0 unless a write error occurs. If `-n' is
3164 specified, the trailing newline is suppressed. If the `-e' option
3165 is given, interpretation of the following backslash-escaped
3166 characters is enabled. The `-E' option disables the
3167 interpretation of these escape characters, even on systems where
3168 they are interpreted by default. The `xpg_echo' shell option may
3169 be used to dynamically determine whether or not `echo' expands
3170 these escape characters by default. `echo' does not interpret
3171 `--' to mean the end of options.
1c72c0cd
CR
3172
3173 `echo' interprets the following escape sequences:
bb70624e
JA
3174 `\a'
3175 alert (bell)
ccc6cda3 3176
bb70624e
JA
3177 `\b'
3178 backspace
ccc6cda3 3179
bb70624e 3180 `\c'
a9fac3b2 3181 suppress further output
ccc6cda3 3182
bb70624e 3183 `\e'
9ec5ed66 3184 `\E'
bb70624e 3185 escape
ccc6cda3 3186
bb70624e
JA
3187 `\f'
3188 form feed
ccc6cda3 3189
bb70624e
JA
3190 `\n'
3191 new line
ccc6cda3 3192
bb70624e
JA
3193 `\r'
3194 carriage return
ccc6cda3 3195
bb70624e
JA
3196 `\t'
3197 horizontal tab
ccc6cda3 3198
bb70624e
JA
3199 `\v'
3200 vertical tab
ccc6cda3 3201
bb70624e
JA
3202 `\\'
3203 backslash
ccc6cda3 3204
7117c2d2
JA
3205 `\0NNN'
3206 the eight-bit character whose value is the octal value NNN
3207 (zero to three octal digits)
3208
f73dda09
JA
3209 `\xHH'
3210 the eight-bit character whose value is the hexadecimal value
3211 HH (one or two hex digits)
3212
220537f2
CR
3213 `\uHHHH'
3214 the Unicode (ISO/IEC 10646) character whose value is the
3215 hexadecimal value HHHH (one to four hex digits)
3216
3217 `\UHHHHHHHH'
3218 the Unicode (ISO/IEC 10646) character whose value is the
3219 hexadecimal value HHHHHHHH (one to eight hex digits)
3220
bb70624e 3221`enable'
d3ad40de 3222 enable [-a] [-dnps] [-f FILENAME] [NAME ...]
122f603c 3223
bb70624e
JA
3224 Enable and disable builtin shell commands. Disabling a builtin
3225 allows a disk command which has the same name as a shell builtin
3226 to be executed without specifying a full pathname, even though the
3227 shell normally searches for builtins before disk commands. If
3228 `-n' is used, the NAMEs become disabled. Otherwise NAMEs are
3229 enabled. For example, to use the `test' binary found via `$PATH'
3230 instead of the shell builtin version, type `enable -n test'.
ccc6cda3 3231
bb70624e
JA
3232 If the `-p' option is supplied, or no NAME arguments appear, a
3233 list of shell builtins is printed. With no other arguments, the
3234 list consists of all enabled shell builtins. The `-a' option
3235 means to list each builtin with an indication of whether or not it
3236 is enabled.
ccc6cda3 3237
bb70624e
JA
3238 The `-f' option means to load the new builtin command NAME from
3239 shared object FILENAME, on systems that support dynamic loading.
3240 The `-d' option will delete a builtin loaded with `-f'.
ccc6cda3 3241
bb70624e
JA
3242 If there are no options, a list of the shell builtins is displayed.
3243 The `-s' option restricts `enable' to the POSIX special builtins.
3244 If `-s' is used with `-f', the new builtin becomes a special
28ef6c31 3245 builtin (*note Special Builtins::).
ccc6cda3 3246
bb70624e
JA
3247 The return status is zero unless a NAME is not a shell builtin or
3248 there is an error loading a new builtin from a shared object.
ccc6cda3 3249
bb70624e 3250`help'
ed35cb4a 3251 help [-dms] [PATTERN]
122f603c 3252
bb70624e
JA
3253 Display helpful information about builtin commands. If PATTERN is
3254 specified, `help' gives detailed help on all commands matching
ed35cb4a
CR
3255 PATTERN, otherwise a list of the builtins is printed.
3256
3257 Options, if supplied, have the following meanings:
3258
3259 `-d'
3260 Display a short description of each PATTERN
3261
3262 `-m'
3263 Display the description of each PATTERN in a manpage-like
3264 format
3265
3266 `-s'
3267 Display only a short usage synopsis for each PATTERN
3268
3269 The return status is zero unless no command matches PATTERN.
ccc6cda3 3270
bb70624e 3271`let'
122f603c
CR
3272 let EXPRESSION [EXPRESSION ...]
3273
bb70624e
JA
3274 The `let' builtin allows arithmetic to be performed on shell
3275 variables. Each EXPRESSION is evaluated according to the rules
6a8fd0ed 3276 given below in *note Shell Arithmetic::. If the last EXPRESSION
bb70624e 3277 evaluates to 0, `let' returns 1; otherwise 0 is returned.
ccc6cda3 3278
bb70624e 3279`local'
d3a24ed2 3280 local [OPTION] NAME[=VALUE] ...
122f603c 3281
bb70624e
JA
3282 For each argument, a local variable named NAME is created, and
3283 assigned VALUE. The OPTION can be any of the options accepted by
3284 `declare'. `local' can only be used within a function; it makes
3285 the variable NAME have a visible scope restricted to that function
3286 and its children. The return status is zero unless `local' is
3287 used outside a function, an invalid NAME is supplied, or NAME is a
3288 readonly variable.
ccc6cda3 3289
bb70624e
JA
3290`logout'
3291 logout [N]
122f603c 3292
bb70624e 3293 Exit a login shell, returning a status of N to the shell's parent.
ccc6cda3 3294
ed35cb4a 3295`mapfile'
122f603c
CR
3296 mapfile [-n COUNT] [-O ORIGIN] [-s COUNT] [-t] [-u FD]
3297 [-C CALLBACK] [-c QUANTUM] [ARRAY]
3298
d6593885
CR
3299 Read lines from the standard input into the indexed array variable
3300 ARRAY, or from file descriptor FD if the `-u' option is supplied.
3301 The variable `MAPFILE' is the default ARRAY. Options, if
3302 supplied, have the following meanings:
122f603c 3303
ed35cb4a
CR
3304 `-n'
3305 Copy at most COUNT lines. If COUNT is 0, all lines are
3306 copied.
3307
3308 `-O'
3309 Begin assigning to ARRAY at index ORIGIN. The default index
3310 is 0.
3311
3312 `-s'
3313 Discard the first COUNT lines read.
3314
3315 `-t'
984a1947 3316 Remove a trailing newline from each line read.
ed35cb4a
CR
3317
3318 `-u'
3319 Read lines from file descriptor FD instead of the standard
3320 input.
3321
3322 `-C'
3323 Evaluate CALLBACK each time QUANTUMP lines are read. The
3324 `-c' option specifies QUANTUM.
3325
3326 `-c'
3327 Specify the number of lines read between each call to
3328 CALLBACK.
3329
3330 If `-C' is specified without `-c', the default quantum is 5000.
db31fb26 3331 When CALLBACK is evaluated, it is supplied the index of the next
220537f2
CR
3332 array element to be assigned and the line to be assigned to that
3333 element as additional arguments. CALLBACK is evaluated after the
3334 line is read but before the array element is assigned.
ed35cb4a
CR
3335
3336 If not supplied with an explicit origin, `mapfile' will clear ARRAY
3337 before assigning to it.
3338
3339 `mapfile' returns successfully unless an invalid option or option
d6593885
CR
3340 argument is supplied, ARRAY is invalid or unassignable, or ARRAY
3341 is not an indexed array.
ed35cb4a 3342
bb70624e 3343`printf'
29d25b54 3344 printf [-v VAR] FORMAT [ARGUMENTS]
122f603c 3345
bb70624e 3346 Write the formatted ARGUMENTS to the standard output under the
220537f2
CR
3347 control of the FORMAT. The `-v' option causes the output to be
3348 assigned to the variable VAR rather than being printed to the
3349 standard output.
3350
3351 The FORMAT is a character string which contains three types of
3352 objects: plain characters, which are simply copied to standard
3353 output, character escape sequences, which are converted and copied
3354 to the standard output, and format specifications, each of which
3355 causes printing of the next successive ARGUMENT. In addition to
3356 the standard `printf(1)' formats, `printf' interprets the
3357 following extensions:
3358
3359 `%b'
122f603c
CR
3360 Causes `printf' to expand backslash escape sequences in the
3361 corresponding ARGUMENT, except that `\c' terminates output,
220537f2
CR
3362 backslashes in `\'', `\"', and `\?' are not removed, and
3363 octal escapes beginning with `\0' may contain up to four
122f603c 3364 digits.
220537f2
CR
3365
3366 `%q'
122f603c 3367 Causes `printf' to output the corresponding ARGUMENT in a
220537f2
CR
3368 format that can be reused as shell input.
3369
3370 `%(DATEFMT)T'
122f603c 3371 Causes `printf' to output the date-time string resulting from
220537f2
CR
3372 using DATEFMT as a format string for `strftime'(3). The
3373 corresponding ARGUMENT is an integer representing the number
3374 of seconds since the epoch. Two special argument values may
3375 be used: -1 represents the current time, and -2 represents
3376 the time the shell was invoked.
ccc6cda3 3377
eb0b2ad8
CR
3378 Arguments to non-string format specifiers are treated as C
3379 language constants, except that a leading plus or minus sign is
3380 allowed, and if the leading character is a single or double quote,
3381 the value is the ASCII value of the following character.
3382
bb70624e
JA
3383 The FORMAT is reused as necessary to consume all of the ARGUMENTS.
3384 If the FORMAT requires more ARGUMENTS than are supplied, the extra
3385 format specifications behave as if a zero value or null string, as
3386 appropriate, had been supplied. The return value is zero on
3387 success, non-zero on failure.
ccc6cda3 3388
bb70624e 3389`read'
122f603c
CR
3390 read [-ers] [-a ANAME] [-d DELIM] [-i TEXT] [-n NCHARS]
3391 [-N NCHARS] [-p PROMPT] [-t TIMEOUT] [-u FD] [NAME ...]
3392
7117c2d2
JA
3393 One line is read from the standard input, or from the file
3394 descriptor FD supplied as an argument to the `-u' option, and the
3395 first word is assigned to the first NAME, the second word to the
3396 second NAME, and so on, with leftover words and their intervening
3397 separators assigned to the last NAME. If there are fewer words
3398 read from the input stream than names, the remaining names are
3399 assigned empty values. The characters in the value of the `IFS'
3400 variable are used to split the line into words. The backslash
3401 character `\' may be used to remove any special meaning for the
3402 next character read and for line continuation. If no names are
3403 supplied, the line read is assigned to the variable `REPLY'. The
3404 return code is zero, unless end-of-file is encountered, `read'
8e1a6eaa
CR
3405 times out (in which case the return code is greater than 128), or
3406 an invalid file descriptor is supplied as the argument to `-u'.
3407
3408 Options, if supplied, have the following meanings:
ccc6cda3 3409
bb70624e
JA
3410 `-a ANAME'
3411 The words are assigned to sequential indices of the array
3412 variable ANAME, starting at 0. All elements are removed from
3413 ANAME before the assignment. Other NAME arguments are
3414 ignored.
ccc6cda3 3415
bb70624e
JA
3416 `-d DELIM'
3417 The first character of DELIM is used to terminate the input
3418 line, rather than newline.
ccc6cda3 3419
bb70624e 3420 `-e'
28ef6c31 3421 Readline (*note Command Line Editing::) is used to obtain the
a9fac3b2
CR
3422 line. Readline uses the current (or default, if line editing
3423 was not previously active) editing settings.
ccc6cda3 3424
6a8fd0ed
CR
3425 `-i TEXT'
3426 If Readline is being used to read the line, TEXT is placed
3427 into the editing buffer before editing begins.
3428
bb70624e
JA
3429 `-n NCHARS'
3430 `read' returns after reading NCHARS characters rather than
d5362af8
CR
3431 waiting for a complete line of input, but honor a delimiter
3432 if fewer than NCHARS characters are read before the delimiter.
3433
3434 `-N NCHARS'
3435 `read' returns after reading exactly NCHARS characters rather
3436 than waiting for a complete line of input, unless EOF is
a3143574
CR
3437 encountered or `read' times out. Delimiter characters
3438 encountered in the input are not treated specially and do not
3439 cause `read' to return until NCHARS characters are read.
cce855bc 3440
bb70624e
JA
3441 `-p PROMPT'
3442 Display PROMPT, without a trailing newline, before attempting
3443 to read any input. The prompt is displayed only if input is
3444 coming from a terminal.
ccc6cda3 3445
bb70624e
JA
3446 `-r'
3447 If this option is given, backslash does not act as an escape
3448 character. The backslash is considered to be part of the
3449 line. In particular, a backslash-newline pair may not be
3450 used as a line continuation.
ccc6cda3 3451
bb70624e
JA
3452 `-s'
3453 Silent mode. If input is coming from a terminal, characters
3454 are not echoed.
cce855bc 3455
bb70624e
JA
3456 `-t TIMEOUT'
3457 Cause `read' to time out and return failure if a complete
ed35cb4a
CR
3458 line of input is not read within TIMEOUT seconds. TIMEOUT
3459 may be a decimal number with a fractional portion following
09767ff0
CR
3460 the decimal point. This option is only effective if `read'
3461 is reading input from a terminal, pipe, or other special
a9fac3b2 3462 file; it has no effect when reading from regular files. If
122f603c
CR
3463 TIMEOUT is 0, `read' returns immediately, without trying to
3464 read and data. The exit status is 0 if input is available on
3465 the specified file descriptor, non-zero otherwise. The exit
a9fac3b2 3466 status is greater than 128 if the timeout is exceeded.
cce855bc 3467
7117c2d2
JA
3468 `-u FD'
3469 Read input from file descriptor FD.
3470
db31fb26 3471`readarray'
122f603c
CR
3472 readarray [-n COUNT] [-O ORIGIN] [-s COUNT] [-t] [-u FD]
3473 [-C CALLBACK] [-c QUANTUM] [ARRAY]
3474
d6593885
CR
3475 Read lines from the standard input into the indexed array variable
3476 ARRAY, or from file descriptor FD if the `-u' option is supplied.
db31fb26
CR
3477
3478 A synonym for `mapfile'.
3479
bb70624e
JA
3480`source'
3481 source FILENAME
122f603c 3482
28ef6c31 3483 A synonym for `.' (*note Bourne Shell Builtins::).
ccc6cda3 3484
bb70624e 3485`type'
7117c2d2 3486 type [-afptP] [NAME ...]
122f603c 3487
bb70624e
JA
3488 For each NAME, indicate how it would be interpreted if used as a
3489 command name.
cce855bc 3490
bb70624e
JA
3491 If the `-t' option is used, `type' prints a single word which is
3492 one of `alias', `function', `builtin', `file' or `keyword', if
3493 NAME is an alias, shell function, shell builtin, disk file, or
3494 shell reserved word, respectively. If the NAME is not found, then
3495 nothing is printed, and `type' returns a failure status.
ccc6cda3 3496
bb70624e
JA
3497 If the `-p' option is used, `type' either returns the name of the
3498 disk file that would be executed, or nothing if `-t' would not
3499 return `file'.
ccc6cda3 3500
7117c2d2
JA
3501 The `-P' option forces a path search for each NAME, even if `-t'
3502 would not return `file'.
3503
122f603c
CR
3504 If a command is hashed, `-p' and `-P' print the hashed value,
3505 which is not necessarily the file that appears first in `$PATH'.
7117c2d2 3506
bb70624e
JA
3507 If the `-a' option is used, `type' returns all of the places that
3508 contain an executable named FILE. This includes aliases and
3509 functions, if and only if the `-p' option is not also used.
ccc6cda3 3510
7117c2d2
JA
3511 If the `-f' option is used, `type' does not attempt to find shell
3512 functions, as with the `command' builtin.
3513
ed35cb4a
CR
3514 The return status is zero if all of the NAMES are found, non-zero
3515 if any are not found.
ccc6cda3 3516
bb70624e 3517`typeset'
122f603c
CR
3518 typeset [-afFgrxilrtux] [-p] [NAME[=VALUE] ...]
3519
bb70624e 3520 The `typeset' command is supplied for compatibility with the Korn
122f603c 3521 shell. It is a synonym for the `declare' builtin command.
ccc6cda3 3522
bb70624e 3523`ulimit'
6a8fd0ed 3524 ulimit [-abcdefilmnpqrstuvxHST] [LIMIT]
122f603c 3525
bb70624e
JA
3526 `ulimit' provides control over the resources available to processes
3527 started by the shell, on systems that allow such control. If an
3528 option is given, it is interpreted as follows:
122f603c 3529
bb70624e
JA
3530 `-S'
3531 Change and report the soft limit associated with a resource.
ccc6cda3 3532
bb70624e
JA
3533 `-H'
3534 Change and report the hard limit associated with a resource.
ccc6cda3 3535
bb70624e
JA
3536 `-a'
3537 All current limits are reported.
ccc6cda3 3538
6a8fd0ed
CR
3539 `-b'
3540 The maximum socket buffer size.
3541
bb70624e
JA
3542 `-c'
3543 The maximum size of core files created.
ccc6cda3 3544
bb70624e
JA
3545 `-d'
3546 The maximum size of a process's data segment.
ccc6cda3 3547
ac18b312
CR
3548 `-e'
3549 The maximum scheduling priority ("nice").
3550
bb70624e 3551 `-f'
d3ad40de
CR
3552 The maximum size of files written by the shell and its
3553 children.
ccc6cda3 3554
ac18b312
CR
3555 `-i'
3556 The maximum number of pending signals.
3557
bb70624e
JA
3558 `-l'
3559 The maximum size that may be locked into memory.
ccc6cda3 3560
bb70624e 3561 `-m'
6932f7f5
CR
3562 The maximum resident set size (many systems do not honor this
3563 limit).
ccc6cda3 3564
bb70624e 3565 `-n'
6932f7f5
CR
3566 The maximum number of open file descriptors (most systems do
3567 not allow this value to be set).
ccc6cda3 3568
bb70624e
JA
3569 `-p'
3570 The pipe buffer size.
ccc6cda3 3571
ac18b312
CR
3572 `-q'
3573 The maximum number of bytes in POSIX message queues.
3574
3575 `-r'
3576 The maximum real-time scheduling priority.
3577
bb70624e
JA
3578 `-s'
3579 The maximum stack size.
ccc6cda3 3580
bb70624e
JA
3581 `-t'
3582 The maximum amount of cpu time in seconds.
ccc6cda3 3583
bb70624e
JA
3584 `-u'
3585 The maximum number of processes available to a single user.
cce855bc 3586
bb70624e 3587 `-v'
eb0b2ad8
CR
3588 The maximum amount of virtual memory available to the shell,
3589 and, on some systems, to its children.
ccc6cda3 3590
ac18b312
CR
3591 `-x'
3592 The maximum number of file locks.
3593
6a8fd0ed
CR
3594 `-T'
3595 The maximum number of threads.
3596
122f603c
CR
3597 If LIMIT is given, and the `-a' option is not used, LIMIT is the
3598 new value of the specified resource. The special LIMIT values
3599 `hard', `soft', and `unlimited' stand for the current hard limit,
3600 the current soft limit, and no limit, respectively. A hard limit
3601 cannot be increased by a non-root user once it is set; a soft
3602 limit may be increased up to the value of the hard limit.
3603 Otherwise, the current value of the soft limit for the specified
3604 resource is printed, unless the `-H' option is supplied. When
3605 setting new limits, if neither `-H' nor `-S' is supplied, both the
3606 hard and soft limits are set. If no option is given, then `-f' is
3607 assumed. Values are in 1024-byte increments, except for `-t',
3608 which is in seconds; `-p', which is in units of 512-byte blocks;
3609 and `-T', `-b', `-n' and `-u', which are unscaled values.
ccc6cda3 3610
f73dda09
JA
3611 The return status is zero unless an invalid option or argument is
3612 supplied, or an error occurs while setting a new limit.
ccc6cda3 3613
bb70624e
JA
3614`unalias'
3615 unalias [-a] [NAME ... ]
ccc6cda3 3616
bb70624e 3617 Remove each NAME from the list of aliases. If `-a' is supplied,
6a8fd0ed 3618 all aliases are removed. Aliases are described in *note Aliases::.
ccc6cda3 3619
bb70624e 3620\1f
d3ad40de 3621File: bashref.info, Node: Modifying Shell Behavior, Next: Special Builtins, Prev: Bash Builtins, Up: Shell Builtin Commands
ccc6cda3 3622
d3ad40de
CR
36234.3 Modifying Shell Behavior
3624============================
3625
3626* Menu:
3627
3628* The Set Builtin:: Change the values of shell attributes and
3629 positional parameters.
3630* The Shopt Builtin:: Modify shell optional behavior.
3631
3632\1f
3633File: bashref.info, Node: The Set Builtin, Next: The Shopt Builtin, Up: Modifying Shell Behavior
3634
36354.3.1 The Set Builtin
3636---------------------
9d6e5e30 3637
d3ad40de
CR
3638This builtin is so complicated that it deserves its own section. `set'
3639allows you to change the values of shell options and set the positional
3640parameters, or to display the names and values of shell variables.
ccc6cda3 3641
bb70624e 3642`set'
e05be32d
CR
3643 set [--abefhkmnptuvxBCEHPT] [-o OPTION-NAME] [ARGUMENT ...]
3644 set [+abefhkmnptuvxBCEHPT] [+o OPTION-NAME] [ARGUMENT ...]
ccc6cda3 3645
bb70624e
JA
3646 If no options or arguments are supplied, `set' displays the names
3647 and values of all shell variables and functions, sorted according
54cdd75a
CR
3648 to the current locale, in a format that may be reused as input for
3649 setting or resetting the currently-set variables. Read-only
3650 variables cannot be reset. In POSIX mode, only shell variables
3651 are listed.
ccc6cda3 3652
bb70624e
JA
3653 When options are supplied, they set or unset shell attributes.
3654 Options, if specified, have the following meanings:
ccc6cda3 3655
bb70624e 3656 `-a'
28ef6c31
JA
3657 Mark variables and function which are modified or created for
3658 export to the environment of subsequent commands.
ccc6cda3 3659
bb70624e
JA
3660 `-b'
3661 Cause the status of terminated background jobs to be reported
3662 immediately, rather than before printing the next primary
3663 prompt.
ccc6cda3 3664
bb70624e 3665 `-e'
6932f7f5
CR
3666 Exit immediately if a pipeline (*note Pipelines::), which may
3667 consist of a single simple command (*note Simple Commands::),
122f603c
CR
3668 a list (*note Lists::), or a compound command (*note Compound
3669 Commands::) returns a non-zero status. The shell does not
3670 exit if the command that fails is part of the command list
3671 immediately following a `while' or `until' keyword, part of
3672 the test in an `if' statement, part of any command executed
3673 in a `&&' or `||' list except the command following the final
3674 `&&' or `||', any command in a pipeline but the last, or if
3675 the command's return status is being inverted with `!'. If a
3676 compound command other than a subshell returns a non-zero
3677 status because a command failed while `-e' was being ignored,
3678 the shell does not exit. A trap on `ERR', if set, is
3679 executed before the shell exits.
ccc6cda3 3680
6932f7f5
CR
3681 This option applies to the shell environment and each
3682 subshell environment separately (*note Command Execution
3683 Environment::), and may cause subshells to exit before
3684 executing all the commands in the subshell.
3685
bb70624e 3686 `-f'
4a8bb13f 3687 Disable filename expansion (globbing).
ccc6cda3 3688
bb70624e
JA
3689 `-h'
3690 Locate and remember (hash) commands as they are looked up for
3691 execution. This option is enabled by default.
ccc6cda3 3692
bb70624e
JA
3693 `-k'
3694 All arguments in the form of assignment statements are placed
3695 in the environment for a command, not just those that precede
3696 the command name.
ccc6cda3 3697
bb70624e 3698 `-m'
74d0116b
CR
3699 Job control is enabled (*note Job Control::). All processes
3700 run in a separate process group. When a background job
3701 completes, the shell prints a line containing its exit status.
b72432fd 3702
bb70624e
JA
3703 `-n'
3704 Read commands but do not execute them; this may be used to
3705 check a script for syntax errors. This option is ignored by
3706 interactive shells.
ccc6cda3 3707
bb70624e
JA
3708 `-o OPTION-NAME'
3709 Set the option corresponding to OPTION-NAME:
ccc6cda3 3710
bb70624e
JA
3711 `allexport'
3712 Same as `-a'.
ccc6cda3 3713
bb70624e
JA
3714 `braceexpand'
3715 Same as `-B'.
ccc6cda3 3716
bb70624e
JA
3717 `emacs'
3718 Use an `emacs'-style line editing interface (*note
a9fac3b2
CR
3719 Command Line Editing::). This also affects the editing
3720 interface used for `read -e'.
ccc6cda3 3721
bb70624e
JA
3722 `errexit'
3723 Same as `-e'.
d166f048 3724
d3a24ed2
CR
3725 `errtrace'
3726 Same as `-E'.
3727
3728 `functrace'
3729 Same as `-T'.
3730
bb70624e
JA
3731 `hashall'
3732 Same as `-h'.
d166f048 3733
bb70624e
JA
3734 `histexpand'
3735 Same as `-H'.
ccc6cda3 3736
bb70624e 3737 `history'
6a8fd0ed 3738 Enable command history, as described in *note Bash
bb70624e
JA
3739 History Facilities::. This option is on by default in
3740 interactive shells.
ccc6cda3 3741
bb70624e
JA
3742 `ignoreeof'
3743 An interactive shell will not exit upon reading EOF.
ccc6cda3 3744
bb70624e
JA
3745 `keyword'
3746 Same as `-k'.
ccc6cda3 3747
bb70624e
JA
3748 `monitor'
3749 Same as `-m'.
ccc6cda3 3750
bb70624e
JA
3751 `noclobber'
3752 Same as `-C'.
ccc6cda3 3753
bb70624e
JA
3754 `noexec'
3755 Same as `-n'.
ccc6cda3 3756
28157acd
CR
3757 `noglob'
3758 Same as `-f'.
9d6e5e30 3759
d3ad40de
CR
3760 `nolog'
3761 Currently ignored.
3762
3763 `notify'
3764 Same as `-b'.
3765
3766 `nounset'
3767 Same as `-u'.
3768
3769 `onecmd'
3770 Same as `-t'.
3771
3772 `physical'
3773 Same as `-P'.
3774
3775 `pipefail'
3776 If set, the return value of a pipeline is the value of
3777 the last (rightmost) command to exit with a non-zero
3778 status, or zero if all commands in the pipeline exit
3779 successfully. This option is disabled by default.
3780
3781 `posix'
3782 Change the behavior of Bash where the default operation
3783 differs from the POSIX standard to match the standard
3784 (*note Bash POSIX Mode::). This is intended to make
3785 Bash behave as a strict superset of that standard.
3786
3787 `privileged'
3788 Same as `-p'.
3789
3790 `verbose'
3791 Same as `-v'.
3792
3793 `vi'
a9fac3b2
CR
3794 Use a `vi'-style line editing interface. This also
3795 affects the editing interface used for `read -e'.
d3ad40de
CR
3796
3797 `xtrace'
3798 Same as `-x'.
3799
3800 `-p'
3801 Turn on privileged mode. In this mode, the `$BASH_ENV' and
3802 `$ENV' files are not processed, shell functions are not
8f714a7c
CR
3803 inherited from the environment, and the `SHELLOPTS',
3804 `BASHOPTS', `CDPATH' and `GLOBIGNORE' variables, if they
3805 appear in the environment, are ignored. If the shell is
3806 started with the effective user (group) id not equal to the
3807 real user (group) id, and the `-p' option is not supplied,
3808 these actions are taken and the effective user id is set to
3809 the real user id. If the `-p' option is supplied at startup,
3810 the effective user id is not reset. Turning this option off
3811 causes the effective user and group ids to be set to the real
3812 user and group ids.
d3ad40de
CR
3813
3814 `-t'
3815 Exit after reading and executing one command.
3816
3817 `-u'
2c471a92
CR
3818 Treat unset variables and parameters other than the special
3819 parameters `@' or `*' as an error when performing parameter
d3ad40de
CR
3820 expansion. An error message will be written to the standard
3821 error, and a non-interactive shell will exit.
3822
3823 `-v'
3824 Print shell input lines as they are read.
3825
3826 `-x'
3827 Print a trace of simple commands, `for' commands, `case'
3828 commands, `select' commands, and arithmetic `for' commands
3829 and their arguments or associated word lists after they are
3830 expanded and before they are executed. The value of the `PS4'
3831 variable is expanded and the resultant value is printed before
3832 the command and its expanded arguments.
3833
3834 `-B'
3835 The shell will perform brace expansion (*note Brace
3836 Expansion::). This option is on by default.
3837
3838 `-C'
3839 Prevent output redirection using `>', `>&', and `<>' from
3840 overwriting existing files.
3841
3842 `-E'
3843 If set, any trap on `ERR' is inherited by shell functions,
3844 command substitutions, and commands executed in a subshell
3845 environment. The `ERR' trap is normally not inherited in
3846 such cases.
3847
3848 `-H'
3849 Enable `!' style history substitution (*note History
3850 Interaction::). This option is on by default for interactive
3851 shells.
3852
3853 `-P'
3854 If set, do not follow symbolic links when performing commands
3855 such as `cd' which change the current directory. The
3856 physical directory is used instead. By default, Bash follows
3857 the logical chain of directories when performing commands
3858 which change the current directory.
3859
3860 For example, if `/usr/sys' is a symbolic link to
3861 `/usr/local/sys' then:
3862 $ cd /usr/sys; echo $PWD
3863 /usr/sys
3864 $ cd ..; pwd
3865 /usr
3866
3867 If `set -P' is on, then:
3868 $ cd /usr/sys; echo $PWD
3869 /usr/local/sys
3870 $ cd ..; pwd
3871 /usr/local
3872
3873 `-T'
3874 If set, any trap on `DEBUG' and `RETURN' are inherited by
3875 shell functions, command substitutions, and commands executed
3876 in a subshell environment. The `DEBUG' and `RETURN' traps
3877 are normally not inherited in such cases.
3878
3879 `--'
3880 If no arguments follow this option, then the positional
3881 parameters are unset. Otherwise, the positional parameters
3882 are set to the ARGUMENTS, even if some of them begin with a
3883 `-'.
3884
3885 `-'
3886 Signal the end of options, cause all remaining ARGUMENTS to
3887 be assigned to the positional parameters. The `-x' and `-v'
3888 options are turned off. If there are no arguments, the
3889 positional parameters remain unchanged.
3890
3891 Using `+' rather than `-' causes these options to be turned off.
3892 The options can also be used upon invocation of the shell. The
3893 current set of options may be found in `$-'.
3894
3895 The remaining N ARGUMENTS are positional parameters and are
3896 assigned, in order, to `$1', `$2', ... `$N'. The special
3897 parameter `#' is set to N.
3898
3899 The return status is always zero unless an invalid option is
3900 supplied.
3901
3902\1f
3903File: bashref.info, Node: The Shopt Builtin, Prev: The Set Builtin, Up: Modifying Shell Behavior
3904
39054.3.2 The Shopt Builtin
3906-----------------------
3907
3908This builtin allows you to change additional shell optional behavior.
3909
3910`shopt'
3911 shopt [-pqsu] [-o] [OPTNAME ...]
122f603c 3912
d3ad40de
CR
3913 Toggle the values of variables controlling optional shell behavior.
3914 With no options, or with the `-p' option, a list of all settable
3915 options is displayed, with an indication of whether or not each is
3916 set. The `-p' option causes output to be displayed in a form that
3917 may be reused as input. Other options have the following meanings:
3918
3919 `-s'
3920 Enable (set) each OPTNAME.
3921
3922 `-u'
3923 Disable (unset) each OPTNAME.
3924
3925 `-q'
3926 Suppresses normal output; the return status indicates whether
3927 the OPTNAME is set or unset. If multiple OPTNAME arguments
3928 are given with `-q', the return status is zero if all
3929 OPTNAMES are enabled; non-zero otherwise.
3930
3931 `-o'
3932 Restricts the values of OPTNAME to be those defined for the
3933 `-o' option to the `set' builtin (*note The Set Builtin::).
3934
122f603c
CR
3935 If either `-s' or `-u' is used with no OPTNAME arguments, `shopt'
3936 shows only those options which are set or unset, respectively.
d3ad40de
CR
3937
3938 Unless otherwise noted, the `shopt' options are disabled (off) by
3939 default.
3940
3941 The return status when listing options is zero if all OPTNAMES are
3942 enabled, non-zero otherwise. When setting or unsetting options,
3943 the return status is zero unless an OPTNAME is not a valid shell
3944 option.
3945
3946 The list of `shopt' options is:
3947 `autocd'
3948 If set, a command name that is the name of a directory is
3949 executed as if it were the argument to the `cd' command.
3950 This option is only used by interactive shells.
3951
3952 `cdable_vars'
3953 If this is set, an argument to the `cd' builtin command that
3954 is not a directory is assumed to be the name of a variable
3955 whose value is the directory to change to.
3956
3957 `cdspell'
3958 If set, minor errors in the spelling of a directory component
3959 in a `cd' command will be corrected. The errors checked for
3960 are transposed characters, a missing character, and a
3961 character too many. If a correction is found, the corrected
3962 path is printed, and the command proceeds. This option is
3963 only used by interactive shells.
3964
3965 `checkhash'
3966 If this is set, Bash checks that a command found in the hash
3967 table exists before trying to execute it. If a hashed
3968 command no longer exists, a normal path search is performed.
3969
3970 `checkjobs'
3971 If set, Bash lists the status of any stopped and running jobs
3972 before exiting an interactive shell. If any jobs are
3973 running, this causes the exit to be deferred until a second
3974 exit is attempted without an intervening command (*note Job
3975 Control::). The shell always postpones exiting if any jobs
3976 are stopped.
3977
3978 `checkwinsize'
74d0116b 3979 If set, Bash checks the window size after each command and,
d3ad40de
CR
3980 if necessary, updates the values of `LINES' and `COLUMNS'.
3981
3982 `cmdhist'
3983 If set, Bash attempts to save all lines of a multiple-line
3984 command in the same history entry. This allows easy
3985 re-editing of multi-line commands.
3986
29d25b54
CR
3987 `compat31'
3988 If set, Bash changes its behavior to that of version 3.1 with
e05be32d 3989 respect to quoted arguments to the conditional command's `=~'
29d25b54
CR
3990 operator.
3991
5cdaaf76
CR
3992 `compat32'
3993 If set, Bash changes its behavior to that of version 3.2 with
3994 respect to locale-specific string comparison when using the
54a1fa7c
CR
3995 `[[' conditional command's `<' and `>' operators. Bash
3996 versions prior to bash-4.0 use ASCII collation and strcmp(3);
3997 bash-4.1 and later use the current locale's collation
3998 sequence and strcoll(3).
5cdaaf76
CR
3999
4000 `compat40'
4001 If set, Bash changes its behavior to that of version 4.0 with
4002 respect to locale-specific string comparison when using the
54a1fa7c
CR
4003 `[[' conditional command's `<' and `>' operators (see
4004 previous item) and the effect of interrupting a command list.
5cdaaf76 4005
7d92f73f
CR
4006 `compat41'
4007 If set, Bash, when in posix mode, treats a single quote in a
4008 double-quoted parameter expansion as a special character.
4009 The single quotes must match (an even number) and the
4010 characters between the single quotes are considered quoted.
4011 This is the behavior of POSIX mode through version 4.1. The
4012 default Bash behavior remains as in previous versions.
4013
122f603c
CR
4014 `complete_fullquote'
4015 If set, Bash quotes all shell metacharacters in filenames and
4016 directory names when performing completion. If not set, Bash
4017 removes metacharacters such as the dollar sign from the set of
4018 characters that will be quoted in completed filenames when
4019 these metacharacters appear in shell variable references in
4020 words to be completed. This means that dollar signs in
4021 variable names that expand to directories will not be quoted;
4022 however, any dollar signs appearing in filenames will not be
4023 quoted, either. This is active only when bash is using
4024 backslashes to quote completed filenames. This variable is
4025 set by default, which is the default Bash behavior in
4026 versions through 4.2.
4027
74d0116b
CR
4028 `direxpand'
4029 If set, Bash replaces directory names with the results of
4030 word expansion when performing filename completion. This
4031 changes the contents of the readline editing buffer. If not
4032 set, Bash attempts to preserve what the user typed.
4033
ed35cb4a
CR
4034 `dirspell'
4035 If set, Bash attempts spelling correction on directory names
4036 during word completion if the directory name initially
4037 supplied does not exist.
4038
d3ad40de
CR
4039 `dotglob'
4040 If set, Bash includes filenames beginning with a `.' in the
4041 results of filename expansion.
4042
4043 `execfail'
4044 If this is set, a non-interactive shell will not exit if it
4045 cannot execute the file specified as an argument to the `exec'
4046 builtin command. An interactive shell does not exit if `exec'
4047 fails.
4048
4049 `expand_aliases'
4050 If set, aliases are expanded as described below under Aliases,
6a8fd0ed 4051 *note Aliases::. This option is enabled by default for
d3ad40de
CR
4052 interactive shells.
4053
4054 `extdebug'
4055 If set, behavior intended for use by debuggers is enabled:
4056
4057 1. The `-F' option to the `declare' builtin (*note Bash
4058 Builtins::) displays the source file name and line
4059 number corresponding to each function name supplied as
4060 an argument.
4061
4062 2. If the command run by the `DEBUG' trap returns a
4063 non-zero value, the next command is skipped and not
4064 executed.
4065
4066 3. If the command run by the `DEBUG' trap returns a value
4067 of 2, and the shell is executing in a subroutine (a
4068 shell function or a shell script executed by the `.' or
4069 `source' builtins), a call to `return' is simulated.
4070
4071 4. `BASH_ARGC' and `BASH_ARGV' are updated as described in
4072 their descriptions (*note Bash Variables::).
4073
4074 5. Function tracing is enabled: command substitution,
4075 shell functions, and subshells invoked with `( COMMAND
4076 )' inherit the `DEBUG' and `RETURN' traps.
9d6e5e30 4077
d3ad40de
CR
4078 6. Error tracing is enabled: command substitution, shell
4079 functions, and subshells invoked with `( COMMAND )'
5cdaaf76 4080 inherit the `ERR' trap.
9d6e5e30 4081
d3ad40de
CR
4082 `extglob'
4083 If set, the extended pattern matching features described above
4084 (*note Pattern Matching::) are enabled.
9d6e5e30 4085
d3ad40de
CR
4086 `extquote'
4087 If set, `$'STRING'' and `$"STRING"' quoting is performed
4088 within `${PARAMETER}' expansions enclosed in double quotes.
4089 This option is enabled by default.
9d6e5e30 4090
d3ad40de
CR
4091 `failglob'
4092 If set, patterns which fail to match filenames during
4a8bb13f 4093 filename expansion result in an expansion error.
9d6e5e30 4094
d3ad40de
CR
4095 `force_fignore'
4096 If set, the suffixes specified by the `FIGNORE' shell variable
4097 cause words to be ignored when performing word completion
4098 even if the ignored words are the only possible completions.
4099 *Note Bash Variables::, for a description of `FIGNORE'. This
4100 option is enabled by default.
9d6e5e30 4101
74d0116b
CR
4102 `globasciiranges'
4103 If set, range expressions used in pattern matching (*note
4104 Pattern Matching::) behave as if in the traditional C locale
4105 when performing comparisons. That is, the current locale's
4106 collating sequence is not taken into account, so `b' will not
4107 collate between `A' and `B', and upper-case and lower-case
4108 ASCII characters will collate together.
4109
ed35cb4a
CR
4110 `globstar'
4111 If set, the pattern `**' used in a filename expansion context
d9e1f41e 4112 will match all files and zero or more directories and
ed35cb4a
CR
4113 subdirectories. If the pattern is followed by a `/', only
4114 directories and subdirectories match.
4115
d3ad40de
CR
4116 `gnu_errfmt'
4117 If set, shell error messages are written in the standard GNU
4118 error message format.
9d6e5e30 4119
d3ad40de
CR
4120 `histappend'
4121 If set, the history list is appended to the file named by the
4122 value of the `HISTFILE' variable when the shell exits, rather
4123 than overwriting the file.
9d6e5e30 4124
d3ad40de
CR
4125 `histreedit'
4126 If set, and Readline is being used, a user is given the
4127 opportunity to re-edit a failed history substitution.
9d6e5e30 4128
d3ad40de
CR
4129 `histverify'
4130 If set, and Readline is being used, the results of history
4131 substitution are not immediately passed to the shell parser.
4132 Instead, the resulting line is loaded into the Readline
4133 editing buffer, allowing further modification.
9d6e5e30 4134
d3ad40de
CR
4135 `hostcomplete'
4136 If set, and Readline is being used, Bash will attempt to
4137 perform hostname completion when a word containing a `@' is
4138 being completed (*note Commands For Completion::). This
4139 option is enabled by default.
9d6e5e30 4140
d3ad40de
CR
4141 `huponexit'
4142 If set, Bash will send `SIGHUP' to all jobs when an
4143 interactive login shell exits (*note Signals::).
9d6e5e30 4144
d3ad40de
CR
4145 `interactive_comments'
4146 Allow a word beginning with `#' to cause that word and all
4147 remaining characters on that line to be ignored in an
4148 interactive shell. This option is enabled by default.
9d6e5e30 4149
9ec5ed66
CR
4150 `lastpipe'
4151 If set, and job control is not active, the shell runs the
4152 last command of a pipeline not executed in the background in
4153 the current shell environment.
4154
d3ad40de
CR
4155 `lithist'
4156 If enabled, and the `cmdhist' option is enabled, multi-line
4157 commands are saved to the history with embedded newlines
4158 rather than using semicolon separators where possible.
9d6e5e30 4159
d3ad40de
CR
4160 `login_shell'
4161 The shell sets this option if it is started as a login shell
4162 (*note Invoking Bash::). The value may not be changed.
9d6e5e30 4163
d3ad40de
CR
4164 `mailwarn'
4165 If set, and a file that Bash is checking for mail has been
4166 accessed since the last time it was checked, the message
4167 `"The mail in MAILFILE has been read"' is displayed.
9d6e5e30 4168
d3ad40de
CR
4169 `no_empty_cmd_completion'
4170 If set, and Readline is being used, Bash will not attempt to
4171 search the `PATH' for possible completions when completion is
4172 attempted on an empty line.
9d6e5e30 4173
d3ad40de
CR
4174 `nocaseglob'
4175 If set, Bash matches filenames in a case-insensitive fashion
4176 when performing filename expansion.
9d6e5e30 4177
d3ad40de
CR
4178 `nocasematch'
4179 If set, Bash matches patterns in a case-insensitive fashion
4180 when performing matching while executing `case' or `[['
4181 conditional commands.
9d6e5e30 4182
d3ad40de
CR
4183 `nullglob'
4184 If set, Bash allows filename patterns which match no files to
4185 expand to a null string, rather than themselves.
9d6e5e30 4186
d3ad40de
CR
4187 `progcomp'
4188 If set, the programmable completion facilities (*note
4189 Programmable Completion::) are enabled. This option is
4190 enabled by default.
9d6e5e30 4191
d3ad40de
CR
4192 `promptvars'
4193 If set, prompt strings undergo parameter expansion, command
4194 substitution, arithmetic expansion, and quote removal after
122f603c
CR
4195 being expanded as described below (*note Controlling the
4196 Prompt::). This option is enabled by default.
9d6e5e30 4197
d3ad40de
CR
4198 `restricted_shell'
4199 The shell sets this option if it is started in restricted mode
4200 (*note The Restricted Shell::). The value may not be changed.
4201 This is not reset when the startup files are executed,
4202 allowing the startup files to discover whether or not a shell
4203 is restricted.
9d6e5e30 4204
d3ad40de
CR
4205 `shift_verbose'
4206 If this is set, the `shift' builtin prints an error message
4207 when the shift count exceeds the number of positional
4208 parameters.
9d6e5e30 4209
d3ad40de
CR
4210 `sourcepath'
4211 If set, the `source' builtin uses the value of `PATH' to find
4212 the directory containing the file supplied as an argument.
4213 This option is enabled by default.
9d6e5e30 4214
d3ad40de
CR
4215 `xpg_echo'
4216 If set, the `echo' builtin expands backslash-escape sequences
4217 by default.
9d6e5e30
CR
4218
4219
d3ad40de
CR
4220 The return status when listing options is zero if all OPTNAMES are
4221 enabled, non-zero otherwise. When setting or unsetting options,
4222 the return status is zero unless an OPTNAME is not a valid shell
4223 option.
9d6e5e30 4224
9d6e5e30 4225\1f
d3ad40de 4226File: bashref.info, Node: Special Builtins, Prev: Modifying Shell Behavior, Up: Shell Builtin Commands
ccc6cda3 4227
37c41ab1
CR
42284.4 Special Builtins
4229====================
ccc6cda3 4230
ac18b312
CR
4231For historical reasons, the POSIX standard has classified several
4232builtin commands as _special_. When Bash is executing in POSIX mode,
4233the special builtins differ from other builtin commands in three
bb70624e 4234respects:
ccc6cda3 4235
bb70624e
JA
4236 1. Special builtins are found before shell functions during command
4237 lookup.
ccc6cda3 4238
bb70624e
JA
4239 2. If a special builtin returns an error status, a non-interactive
4240 shell exits.
ccc6cda3 4241
bb70624e
JA
4242 3. Assignment statements preceding the command stay in effect in the
4243 shell environment after the command completes.
ccc6cda3 4244
bb70624e
JA
4245 When Bash is not executing in POSIX mode, these builtins behave no
4246differently than the rest of the Bash builtin commands. The Bash POSIX
6a8fd0ed 4247mode is described in *note Bash POSIX Mode::.
ccc6cda3 4248
bb70624e
JA
4249 These are the POSIX special builtins:
4250 break : . continue eval exec exit export readonly return set
4251 shift trap unset
ccc6cda3 4252
bb70624e
JA
4253\1f
4254File: bashref.info, Node: Shell Variables, Next: Bash Features, Prev: Shell Builtin Commands, Up: Top
cce855bc 4255
37c41ab1
CR
42565 Shell Variables
4257*****************
ccc6cda3 4258
bb70624e 4259* Menu:
ccc6cda3 4260
bb70624e
JA
4261* Bourne Shell Variables:: Variables which Bash uses in the same way
4262 as the Bourne Shell.
4263* Bash Variables:: List of variables that exist in Bash.
ccc6cda3 4264
bb70624e
JA
4265 This chapter describes the shell variables that Bash uses. Bash
4266automatically assigns default values to a number of variables.
cce855bc 4267
bb70624e
JA
4268\1f
4269File: bashref.info, Node: Bourne Shell Variables, Next: Bash Variables, Up: Shell Variables
ccc6cda3 4270
37c41ab1
CR
42715.1 Bourne Shell Variables
4272==========================
cce855bc 4273
37c41ab1
CR
4274Bash uses certain shell variables in the same way as the Bourne shell.
4275In some cases, Bash assigns a default value to the variable.
cce855bc 4276
bb70624e
JA
4277`CDPATH'
4278 A colon-separated list of directories used as a search path for
4279 the `cd' builtin command.
ccc6cda3 4280
bb70624e
JA
4281`HOME'
4282 The current user's home directory; the default for the `cd' builtin
4283 command. The value of this variable is also used by tilde
28ef6c31 4284 expansion (*note Tilde Expansion::).
ccc6cda3 4285
bb70624e
JA
4286`IFS'
4287 A list of characters that separate fields; used when the shell
4288 splits words as part of expansion.
ccc6cda3 4289
bb70624e 4290`MAIL'
e05be32d
CR
4291 If this parameter is set to a filename or directory name and the
4292 `MAILPATH' variable is not set, Bash informs the user of the
4293 arrival of mail in the specified file or Maildir-format directory.
cce855bc 4294
bb70624e
JA
4295`MAILPATH'
4296 A colon-separated list of filenames which the shell periodically
4297 checks for new mail. Each list entry can specify the message that
4298 is printed when new mail arrives in the mail file by separating
122f603c 4299 the filename from the message with a `?'. When used in the text
bb70624e 4300 of the message, `$_' expands to the name of the current mail file.
cce855bc 4301
bb70624e
JA
4302`OPTARG'
4303 The value of the last option argument processed by the `getopts'
4304 builtin.
ccc6cda3 4305
bb70624e
JA
4306`OPTIND'
4307 The index of the last option argument processed by the `getopts'
4308 builtin.
ccc6cda3 4309
bb70624e
JA
4310`PATH'
4311 A colon-separated list of directories in which the shell looks for
d3a24ed2
CR
4312 commands. A zero-length (null) directory name in the value of
4313 `PATH' indicates the current directory. A null directory name may
4314 appear as two adjacent colons, or as an initial or trailing colon.
ccc6cda3 4315
bb70624e
JA
4316`PS1'
4317 The primary prompt string. The default value is `\s-\v\$ '.
122f603c 4318 *Note Controlling the Prompt::, for the complete list of escape
bb70624e 4319 sequences that are expanded before `PS1' is displayed.
ccc6cda3 4320
bb70624e
JA
4321`PS2'
4322 The secondary prompt string. The default value is `> '.
ccc6cda3 4323
761783bf 4324
bb70624e
JA
4325\1f
4326File: bashref.info, Node: Bash Variables, Prev: Bourne Shell Variables, Up: Shell Variables
ccc6cda3 4327
37c41ab1
CR
43285.2 Bash Variables
4329==================
ccc6cda3 4330
37c41ab1 4331These variables are set or used by Bash, but other shells do not
bb70624e 4332normally treat them specially.
ccc6cda3 4333
bb70624e
JA
4334 A few variables used by Bash are described in different chapters:
4335variables for controlling the job control facilities (*note Job Control
28ef6c31 4336Variables::).
ccc6cda3 4337
bb70624e
JA
4338`BASH'
4339 The full pathname used to execute the current instance of Bash.
ccc6cda3 4340
8f714a7c
CR
4341`BASHOPTS'
4342 A colon-separated list of enabled shell options. Each word in the
4343 list is a valid argument for the `-s' option to the `shopt'
4344 builtin command (*note The Shopt Builtin::). The options
4345 appearing in `BASHOPTS' are those reported as `on' by `shopt'. If
4346 this variable is in the environment when Bash starts up, each
4347 shell option in the list will be enabled before reading any
4348 startup files. This variable is readonly.
4349
d3ad40de 4350`BASHPID'
e05be32d 4351 Expands to the process ID of the current Bash process. This
d3ad40de
CR
4352 differs from `$$' under certain circumstances, such as subshells
4353 that do not require Bash to be re-initialized.
4354
09767ff0
CR
4355`BASH_ALIASES'
4356 An associative array variable whose members correspond to the
e05be32d 4357 internal list of aliases as maintained by the `alias' builtin.
09767ff0
CR
4358 (*note Bourne Shell Builtins::). Elements added to this array
4359 appear in the alias list; unsetting array elements cause aliases
4360 to be removed from the alias list.
4361
d3a24ed2
CR
4362`BASH_ARGC'
4363 An array variable whose values are the number of parameters in each
4364 frame of the current bash execution call stack. The number of
4365 parameters to the current subroutine (shell function or script
4366 executed with `.' or `source') is at the top of the stack. When a
4367 subroutine is executed, the number of parameters passed is pushed
9d2b70f0 4368 onto `BASH_ARGC'. The shell sets `BASH_ARGC' only when in
6a8fd0ed 4369 extended debugging mode (see *note The Shopt Builtin:: for a
9d2b70f0 4370 description of the `extdebug' option to the `shopt' builtin).
d3a24ed2
CR
4371
4372`BASH_ARGV'
4373 An array variable containing all of the parameters in the current
4374 bash execution call stack. The final parameter of the last
4375 subroutine call is at the top of the stack; the first parameter of
4376 the initial call is at the bottom. When a subroutine is executed,
9d2b70f0 4377 the parameters supplied are pushed onto `BASH_ARGV'. The shell
6a8fd0ed 4378 sets `BASH_ARGV' only when in extended debugging mode (see *note
d3ad40de
CR
4379 The Shopt Builtin:: for a description of the `extdebug' option to
4380 the `shopt' builtin).
d3a24ed2 4381
09767ff0
CR
4382`BASH_CMDS'
4383 An associative array variable whose members correspond to the
4384 internal hash table of commands as maintained by the `hash' builtin
4385 (*note Bourne Shell Builtins::). Elements added to this array
4386 appear in the hash table; unsetting array elements cause commands
4387 to be removed from the hash table.
4388
d3a24ed2
CR
4389`BASH_COMMAND'
4390 The command currently being executed or about to be executed,
4391 unless the shell is executing a command as the result of a trap,
4392 in which case it is the command executing at the time of the trap.
4393
bb70624e
JA
4394`BASH_ENV'
4395 If this variable is set when Bash is invoked to execute a shell
4396 script, its value is expanded and used as the name of a startup
4397 file to read before executing the script. *Note Bash Startup
4398 Files::.
ccc6cda3 4399
d3a24ed2
CR
4400`BASH_EXECUTION_STRING'
4401 The command argument to the `-c' invocation option.
4402
4403`BASH_LINENO'
4404 An array variable whose members are the line numbers in source
9ec5ed66
CR
4405 files where each corresponding member of FUNCNAME was invoked.
4406 `${BASH_LINENO[$i]}' is the line number in the source file
4407 (`${BASH_SOURCE[$i+1]}') where `${FUNCNAME[$i]}' was called (or
4408 `${BASH_LINENO[$i-1]}' if referenced within another shell
4409 function). Use `LINENO' to obtain the current line number.
d3a24ed2 4410
5e13499c
CR
4411`BASH_REMATCH'
4412 An array variable whose members are assigned by the `=~' binary
4413 operator to the `[[' conditional command (*note Conditional
4414 Constructs::). The element with index 0 is the portion of the
4415 string matching the entire regular expression. The element with
4416 index N is the portion of the string matching the Nth
4417 parenthesized subexpression. This variable is read-only.
4418
d3a24ed2 4419`BASH_SOURCE'
9ec5ed66
CR
4420 An array variable whose members are the source filenames where the
4421 corresponding shell function names in the `FUNCNAME' array
4422 variable are defined. The shell function `${FUNCNAME[$i]}' is
4423 defined in the file `${BASH_SOURCE[$i]}' and called from
4424 `${BASH_SOURCE[$i+1]}'
d3a24ed2
CR
4425
4426`BASH_SUBSHELL'
f6da9f85
CR
4427 Incremented by one within each subshell or subshell environment
4428 when the shell begins executing in that environment. The initial
4429 value is 0.
ccc6cda3 4430
bb70624e 4431`BASH_VERSINFO'
28ef6c31 4432 A readonly array variable (*note Arrays::) whose members hold
bb70624e
JA
4433 version information for this instance of Bash. The values
4434 assigned to the array members are as follows:
ccc6cda3 4435
bb70624e
JA
4436 `BASH_VERSINFO[0]'
4437 The major version number (the RELEASE).
ccc6cda3 4438
bb70624e
JA
4439 `BASH_VERSINFO[1]'
4440 The minor version number (the VERSION).
ccc6cda3 4441
bb70624e
JA
4442 `BASH_VERSINFO[2]'
4443 The patch level.
ccc6cda3 4444
bb70624e
JA
4445 `BASH_VERSINFO[3]'
4446 The build version.
ccc6cda3 4447
bb70624e
JA
4448 `BASH_VERSINFO[4]'
4449 The release status (e.g., BETA1).
ccc6cda3 4450
bb70624e
JA
4451 `BASH_VERSINFO[5]'
4452 The value of `MACHTYPE'.
ccc6cda3 4453
d3a24ed2
CR
4454`BASH_VERSION'
4455 The version number of the current instance of Bash.
4456
8f714a7c
CR
4457`BASH_XTRACEFD'
4458 If set to an integer corresponding to a valid file descriptor, Bash
4459 will write the trace output generated when `set -x' is enabled to
4460 that file descriptor. This allows tracing output to be separated
4461 from diagnostic and error messages. The file descriptor is closed
4462 when `BASH_XTRACEFD' is unset or assigned a new value. Unsetting
4463 `BASH_XTRACEFD' or assigning it the empty string causes the trace
4464 output to be sent to the standard error. Note that setting
4465 `BASH_XTRACEFD' to 2 (the standard error file descriptor) and then
4466 unsetting it will result in the standard error being closed.
4467
f73dda09 4468`COLUMNS'
54a1fa7c 4469 Used by the `select' command to determine the terminal width when
74d0116b
CR
4470 printing selection lists. Automatically set by an interactive
4471 shell upon receipt of a `SIGWINCH'.
bb70624e
JA
4472
4473`COMP_CWORD'
4474 An index into `${COMP_WORDS}' of the word containing the current
4475 cursor position. This variable is available only in shell
4476 functions invoked by the programmable completion facilities (*note
28ef6c31 4477 Programmable Completion::).
bb70624e
JA
4478
4479`COMP_LINE'
4480 The current command line. This variable is available only in
4481 shell functions and external commands invoked by the programmable
28ef6c31 4482 completion facilities (*note Programmable Completion::).
bb70624e
JA
4483
4484`COMP_POINT'
4485 The index of the current cursor position relative to the beginning
4486 of the current command. If the current cursor position is at the
4487 end of the current command, the value of this variable is equal to
4488 `${#COMP_LINE}'. This variable is available only in shell
4489 functions and external commands invoked by the programmable
28ef6c31 4490 completion facilities (*note Programmable Completion::).
bb70624e 4491
d3ad40de
CR
4492`COMP_TYPE'
4493 Set to an integer value corresponding to the type of completion
4494 attempted that caused a completion function to be called: TAB, for
4495 normal completion, `?', for listing completions after successive
4496 tabs, `!', for listing alternatives on partial word completion,
4497 `@', to list completions if the word is not unmodified, or `%',
4498 for menu completion. This variable is available only in shell
4499 functions and external commands invoked by the programmable
4500 completion facilities (*note Programmable Completion::).
4501
4502`COMP_KEY'
4503 The key (or final key of a key sequence) used to invoke the current
4504 completion function.
4505
d3a24ed2
CR
4506`COMP_WORDBREAKS'
4507 The set of characters that the Readline library treats as word
4508 separators when performing word completion. If `COMP_WORDBREAKS'
4509 is unset, it loses its special properties, even if it is
4510 subsequently reset.
4511
f73dda09
JA
4512`COMP_WORDS'
4513 An array variable consisting of the individual words in the
6932f7f5
CR
4514 current command line. The line is split into words as Readline
4515 would split it, using `COMP_WORDBREAKS' as described above. This
4516 variable is available only in shell functions invoked by the
4517 programmable completion facilities (*note Programmable
4518 Completion::).
f73dda09 4519
bb70624e
JA
4520`COMPREPLY'
4521 An array variable from which Bash reads the possible completions
4522 generated by a shell function invoked by the programmable
28ef6c31 4523 completion facility (*note Programmable Completion::).
ccc6cda3 4524
5cdaaf76
CR
4525`COPROC'
4526 An array variable created to hold the file descriptors for output
4527 from and input to an unnamed coprocess (*note Coprocesses::).
4528
bb70624e
JA
4529`DIRSTACK'
4530 An array variable containing the current contents of the directory
4531 stack. Directories appear in the stack in the order they are
4532 displayed by the `dirs' builtin. Assigning to members of this
4533 array variable may be used to modify directories already in the
4534 stack, but the `pushd' and `popd' builtins must be used to add and
4535 remove directories. Assignment to this variable will not change
4536 the current directory. If `DIRSTACK' is unset, it loses its
4537 special properties, even if it is subsequently reset.
cce855bc 4538
d3a24ed2
CR
4539`EMACS'
4540 If Bash finds this variable in the environment when the shell
4541 starts with value `t', it assumes that the shell is running in an
e05be32d 4542 Emacs shell buffer and disables line editing.
d3a24ed2 4543
5cdaaf76
CR
4544`ENV'
4545 Similar to `BASH_ENV'; used when the shell is invoked in POSIX
4546 Mode (*note Bash POSIX Mode::).
4547
bb70624e
JA
4548`EUID'
4549 The numeric effective user id of the current user. This variable
4550 is readonly.
cce855bc 4551
bb70624e
JA
4552`FCEDIT'
4553 The editor used as a default by the `-e' option to the `fc'
4554 builtin command.
ccc6cda3 4555
bb70624e
JA
4556`FIGNORE'
4557 A colon-separated list of suffixes to ignore when performing
122f603c
CR
4558 filename completion. A filename whose suffix matches one of the
4559 entries in `FIGNORE' is excluded from the list of matched
4560 filenames. A sample value is `.o:~'
ccc6cda3 4561
f73dda09 4562`FUNCNAME'
d3a24ed2
CR
4563 An array variable containing the names of all shell functions
4564 currently in the execution call stack. The element with index 0
4565 is the name of any currently-executing shell function. The
9ec5ed66
CR
4566 bottom-most element (the one with the highest index) is `"main"'.
4567 This variable exists only when a shell function is executing.
4568 Assignments to `FUNCNAME' have no effect and return an error
4569 status. If `FUNCNAME' is unset, it loses its special properties,
4570 even if it is subsequently reset.
4571
4572 This variable can be used with `BASH_LINENO' and `BASH_SOURCE'.
4573 Each element of `FUNCNAME' has corresponding elements in
4574 `BASH_LINENO' and `BASH_SOURCE' to describe the call stack. For
4575 instance, `${FUNCNAME[$i]}' was called from the file
4576 `${BASH_SOURCE[$i+1]}' at line number `${BASH_LINENO[$i]}'. The
4577 `caller' builtin displays the current call stack using this
4578 information.
f73dda09 4579
220537f2
CR
4580`FUNCNEST'
4581 If set to a numeric value greater than 0, defines a maximum
4582 function nesting level. Function invocations that exceed this
4583 nesting level will cause the current command to abort.
4584
bb70624e
JA
4585`GLOBIGNORE'
4586 A colon-separated list of patterns defining the set of filenames to
4587 be ignored by filename expansion. If a filename matched by a
4588 filename expansion pattern also matches one of the patterns in
4589 `GLOBIGNORE', it is removed from the list of matches.
ccc6cda3 4590
bb70624e
JA
4591`GROUPS'
4592 An array variable containing the list of groups of which the
4593 current user is a member. Assignments to `GROUPS' have no effect
28ef6c31 4594 and return an error status. If `GROUPS' is unset, it loses its
bb70624e 4595 special properties, even if it is subsequently reset.
ccc6cda3 4596
bb70624e
JA
4597`histchars'
4598 Up to three characters which control history expansion, quick
28ef6c31
JA
4599 substitution, and tokenization (*note History Interaction::). The
4600 first character is the HISTORY EXPANSION character, that is, the
4601 character which signifies the start of a history expansion,
bb70624e
JA
4602 normally `!'. The second character is the character which
4603 signifies `quick substitution' when seen as the first character on
4604 a line, normally `^'. The optional third character is the
4605 character which indicates that the remainder of the line is a
4606 comment when found as the first character of a word, usually `#'.
4607 The history comment character causes history substitution to be
4608 skipped for the remaining words on the line. It does not
4609 necessarily cause the shell parser to treat the rest of the line
4610 as a comment.
cce855bc 4611
bb70624e
JA
4612`HISTCMD'
4613 The history number, or index in the history list, of the current
4614 command. If `HISTCMD' is unset, it loses its special properties,
4615 even if it is subsequently reset.
ccc6cda3 4616
bb70624e 4617`HISTCONTROL'
d3a24ed2
CR
4618 A colon-separated list of values controlling how commands are
4619 saved on the history list. If the list of values includes
4620 `ignorespace', lines which begin with a space character are not
4621 saved in the history list. A value of `ignoredups' causes lines
4622 which match the previous history entry to not be saved. A value
4623 of `ignoreboth' is shorthand for `ignorespace' and `ignoredups'.
4624 A value of `erasedups' causes all previous lines matching the
4625 current line to be removed from the history list before that line
4626 is saved. Any value not in the above list is ignored. If
4627 `HISTCONTROL' is unset, or does not include a valid value, all
4628 lines read by the shell parser are saved on the history list,
4629 subject to the value of `HISTIGNORE'. The second and subsequent
4630 lines of a multi-line compound command are not tested, and are
4631 added to the history regardless of the value of `HISTCONTROL'.
ccc6cda3 4632
f73dda09
JA
4633`HISTFILE'
4634 The name of the file to which the command history is saved. The
4635 default value is `~/.bash_history'.
4636
4637`HISTFILESIZE'
4638 The maximum number of lines contained in the history file. When
4639 this variable is assigned a value, the history file is truncated,
d3ad40de
CR
4640 if necessary, by removing the oldest entries, to contain no more
4641 than that number of lines. The history file is also truncated to
4642 this size after writing it when an interactive shell exits. The
4643 default value is 500.
f73dda09 4644
bb70624e
JA
4645`HISTIGNORE'
4646 A colon-separated list of patterns used to decide which command
4647 lines should be saved on the history list. Each pattern is
4648 anchored at the beginning of the line and must match the complete
4649 line (no implicit `*' is appended). Each pattern is tested
4650 against the line after the checks specified by `HISTCONTROL' are
4651 applied. In addition to the normal shell pattern matching
4652 characters, `&' matches the previous history line. `&' may be
4653 escaped using a backslash; the backslash is removed before
4654 attempting a match. The second and subsequent lines of a
4655 multi-line compound command are not tested, and are added to the
4656 history regardless of the value of `HISTIGNORE'.
cce855bc 4657
bb70624e
JA
4658 `HISTIGNORE' subsumes the function of `HISTCONTROL'. A pattern of
4659 `&' is identical to `ignoredups', and a pattern of `[ ]*' is
4660 identical to `ignorespace'. Combining these two patterns,
4661 separating them with a colon, provides the functionality of
4662 `ignoreboth'.
ccc6cda3 4663
bb70624e
JA
4664`HISTSIZE'
4665 The maximum number of commands to remember on the history list.
4666 The default value is 500.
b72432fd 4667
d3a24ed2
CR
4668`HISTTIMEFORMAT'
4669 If this variable is set and not null, its value is used as a
4670 format string for STRFTIME to print the time stamp associated with
4671 each history entry displayed by the `history' builtin. If this
4672 variable is set, time stamps are written to the history file so
d3ad40de
CR
4673 they may be preserved across shell sessions. This uses the
4674 history comment character to distinguish timestamps from other
4675 history lines.
d3a24ed2 4676
bb70624e
JA
4677`HOSTFILE'
4678 Contains the name of a file in the same format as `/etc/hosts' that
4679 should be read when the shell needs to complete a hostname. The
4680 list of possible hostname completions may be changed while the
4681 shell is running; the next time hostname completion is attempted
4682 after the value is changed, Bash adds the contents of the new file
3eb2d94a
CR
4683 to the existing list. If `HOSTFILE' is set, but has no value, or
4684 does not name a readable file, Bash attempts to read `/etc/hosts'
4685 to obtain the list of possible hostname completions. When
4686 `HOSTFILE' is unset, the hostname list is cleared.
cce855bc 4687
bb70624e
JA
4688`HOSTNAME'
4689 The name of the current host.
cce855bc 4690
bb70624e
JA
4691`HOSTTYPE'
4692 A string describing the machine Bash is running on.
ccc6cda3 4693
bb70624e
JA
4694`IGNOREEOF'
4695 Controls the action of the shell on receipt of an `EOF' character
4696 as the sole input. If set, the value denotes the number of
4697 consecutive `EOF' characters that can be read as the first
4698 character on an input line before the shell will exit. If the
4699 variable exists but does not have a numeric value (or has no
4700 value) then the default is 10. If the variable does not exist,
4701 then `EOF' signifies the end of input to the shell. This is only
4702 in effect for interactive shells.
ccc6cda3 4703
bb70624e
JA
4704`INPUTRC'
4705 The name of the Readline initialization file, overriding the
4706 default of `~/.inputrc'.
ccc6cda3 4707
bb70624e
JA
4708`LANG'
4709 Used to determine the locale category for any category not
4710 specifically selected with a variable starting with `LC_'.
ccc6cda3 4711
bb70624e
JA
4712`LC_ALL'
4713 This variable overrides the value of `LANG' and any other `LC_'
4714 variable specifying a locale category.
cce855bc 4715
bb70624e
JA
4716`LC_COLLATE'
4717 This variable determines the collation order used when sorting the
4718 results of filename expansion, and determines the behavior of
4719 range expressions, equivalence classes, and collating sequences
4720 within filename expansion and pattern matching (*note Filename
28ef6c31 4721 Expansion::).
ccc6cda3 4722
bb70624e
JA
4723`LC_CTYPE'
4724 This variable determines the interpretation of characters and the
4725 behavior of character classes within filename expansion and pattern
28ef6c31 4726 matching (*note Filename Expansion::).
ccc6cda3 4727
bb70624e
JA
4728`LC_MESSAGES'
4729 This variable determines the locale used to translate double-quoted
28ef6c31 4730 strings preceded by a `$' (*note Locale Translation::).
ccc6cda3 4731
bb70624e
JA
4732`LC_NUMERIC'
4733 This variable determines the locale category used for number
4734 formatting.
ccc6cda3 4735
f73dda09
JA
4736`LINENO'
4737 The line number in the script or shell function currently
4738 executing.
4739
28ef6c31 4740`LINES'
54a1fa7c 4741 Used by the `select' command to determine the column length for
74d0116b
CR
4742 printing selection lists. Automatically set by an interactive
4743 shell upon receipt of a `SIGWINCH'.
28ef6c31 4744
bb70624e
JA
4745`MACHTYPE'
4746 A string that fully describes the system type on which Bash is
4747 executing, in the standard GNU CPU-COMPANY-SYSTEM format.
ccc6cda3 4748
bb70624e
JA
4749`MAILCHECK'
4750 How often (in seconds) that the shell should check for mail in the
28ef6c31
JA
4751 files specified in the `MAILPATH' or `MAIL' variables. The
4752 default is 60 seconds. When it is time to check for mail, the
4753 shell does so before displaying the primary prompt. If this
4754 variable is unset, or set to a value that is not a number greater
4755 than or equal to zero, the shell disables mail checking.
ccc6cda3 4756
5cdaaf76
CR
4757`MAPFILE'
4758 An array variable created to hold the text read by the `mapfile'
4759 builtin when no variable name is supplied.
4760
bb70624e
JA
4761`OLDPWD'
4762 The previous working directory as set by the `cd' builtin.
ccc6cda3 4763
bb70624e
JA
4764`OPTERR'
4765 If set to the value 1, Bash displays error messages generated by
4766 the `getopts' builtin command.
ccc6cda3 4767
bb70624e
JA
4768`OSTYPE'
4769 A string describing the operating system Bash is running on.
ccc6cda3 4770
bb70624e 4771`PIPESTATUS'
28ef6c31 4772 An array variable (*note Arrays::) containing a list of exit
bb70624e
JA
4773 status values from the processes in the most-recently-executed
4774 foreground pipeline (which may contain only a single command).
ccc6cda3 4775
f73dda09 4776`POSIXLY_CORRECT'
122f603c
CR
4777 If this variable is in the environment when Bash starts, the shell
4778 enters POSIX mode (*note Bash POSIX Mode::) before reading the
4779 startup files, as if the `--posix' invocation option had been
4780 supplied. If it is set while the shell is running, Bash enables
f73dda09
JA
4781 POSIX mode, as if the command
4782 `set -o posix'
f73dda09
JA
4783 had been executed.
4784
bb70624e
JA
4785`PPID'
4786 The process ID of the shell's parent process. This variable is
4787 readonly.
ccc6cda3 4788
bb70624e
JA
4789`PROMPT_COMMAND'
4790 If set, the value is interpreted as a command to execute before
4791 the printing of each primary prompt (`$PS1').
ccc6cda3 4792
09767ff0
CR
4793`PROMPT_DIRTRIM'
4794 If set to a number greater than zero, the value is used as the
4795 number of trailing directory components to retain when expanding
122f603c 4796 the `\w' and `\W' prompt string escapes (*note Controlling the
09767ff0
CR
4797 Prompt::). Characters removed are replaced with an ellipsis.
4798
bb70624e
JA
4799`PS3'
4800 The value of this variable is used as the prompt for the `select'
4801 command. If this variable is not set, the `select' command
4802 prompts with `#? '
ccc6cda3 4803
bb70624e
JA
4804`PS4'
4805 The value is the prompt printed before the command line is echoed
28ef6c31 4806 when the `-x' option is set (*note The Set Builtin::). The first
bb70624e
JA
4807 character of `PS4' is replicated multiple times, as necessary, to
4808 indicate multiple levels of indirection. The default is `+ '.
ccc6cda3 4809
bb70624e
JA
4810`PWD'
4811 The current working directory as set by the `cd' builtin.
ccc6cda3 4812
bb70624e
JA
4813`RANDOM'
4814 Each time this parameter is referenced, a random integer between 0
4815 and 32767 is generated. Assigning a value to this variable seeds
4816 the random number generator.
cce855bc 4817
5cdaaf76
CR
4818`READLINE_LINE'
4819 The contents of the Readline line buffer, for use with `bind -x'
4820 (*note Bash Builtins::).
4821
4822`READLINE_POINT'
4823 The position of the insertion point in the Readline line buffer,
4824 for use with `bind -x' (*note Bash Builtins::).
4825
bb70624e
JA
4826`REPLY'
4827 The default variable for the `read' builtin.
ccc6cda3 4828
bb70624e
JA
4829`SECONDS'
4830 This variable expands to the number of seconds since the shell was
4831 started. Assignment to this variable resets the count to the
4832 value assigned, and the expanded value becomes the value assigned
4833 plus the number of seconds since the assignment.
ccc6cda3 4834
9f422431
CR
4835`SHELL'
4836 The full pathname to the shell is kept in this environment
4837 variable. If it is not set when the shell starts, Bash assigns to
4838 it the full pathname of the current user's login shell.
4839
bb70624e
JA
4840`SHELLOPTS'
4841 A colon-separated list of enabled shell options. Each word in the
4842 list is a valid argument for the `-o' option to the `set' builtin
28ef6c31 4843 command (*note The Set Builtin::). The options appearing in
bb70624e
JA
4844 `SHELLOPTS' are those reported as `on' by `set -o'. If this
4845 variable is in the environment when Bash starts up, each shell
4846 option in the list will be enabled before reading any startup
4847 files. This variable is readonly.
ccc6cda3 4848
bb70624e
JA
4849`SHLVL'
4850 Incremented by one each time a new instance of Bash is started.
4851 This is intended to be a count of how deeply your Bash shells are
4852 nested.
cce855bc 4853
bb70624e
JA
4854`TIMEFORMAT'
4855 The value of this parameter is used as a format string specifying
4856 how the timing information for pipelines prefixed with the `time'
4857 reserved word should be displayed. The `%' character introduces an
4858 escape sequence that is expanded to a time value or other
4859 information. The escape sequences and their meanings are as
4860 follows; the braces denote optional portions.
cce855bc 4861
bb70624e
JA
4862 `%%'
4863 A literal `%'.
ccc6cda3 4864
bb70624e
JA
4865 `%[P][l]R'
4866 The elapsed time in seconds.
ccc6cda3 4867
bb70624e
JA
4868 `%[P][l]U'
4869 The number of CPU seconds spent in user mode.
ccc6cda3 4870
bb70624e
JA
4871 `%[P][l]S'
4872 The number of CPU seconds spent in system mode.
ccc6cda3 4873
bb70624e
JA
4874 `%P'
4875 The CPU percentage, computed as (%U + %S) / %R.
ccc6cda3 4876
bb70624e
JA
4877 The optional P is a digit specifying the precision, the number of
4878 fractional digits after a decimal point. A value of 0 causes no
4879 decimal point or fraction to be output. At most three places
4880 after the decimal point may be specified; values of P greater than
4881 3 are changed to 3. If P is not specified, the value 3 is used.
ccc6cda3 4882
bb70624e
JA
4883 The optional `l' specifies a longer format, including minutes, of
4884 the form MMmSS.FFs. The value of P determines whether or not the
4885 fraction is included.
ccc6cda3 4886
bb70624e
JA
4887 If this variable is not set, Bash acts as if it had the value
4888 `$'\nreal\t%3lR\nuser\t%3lU\nsys\t%3lS''
4889 If the value is null, no timing information is displayed. A
4890 trailing newline is added when the format string is displayed.
ccc6cda3 4891
bb70624e 4892`TMOUT'
7117c2d2
JA
4893 If set to a value greater than zero, `TMOUT' is treated as the
4894 default timeout for the `read' builtin (*note Bash Builtins::).
4895 The `select' command (*note Conditional Constructs::) terminates
4896 if input does not arrive after `TMOUT' seconds when input is coming
4897 from a terminal.
4898
d3ad40de 4899 In an interactive shell, the value is interpreted as the number of
7117c2d2
JA
4900 seconds to wait for input after issuing the primary prompt when
4901 the shell is interactive. Bash terminates after that number of
4902 seconds if input does not arrive.
ccc6cda3 4903
1c72c0cd
CR
4904`TMPDIR'
4905 If set, Bash uses its value as the name of a directory in which
4906 Bash creates temporary files for the shell's use.
4907
bb70624e
JA
4908`UID'
4909 The numeric real user id of the current user. This variable is
4910 readonly.
ccc6cda3 4911
761783bf 4912
bb70624e
JA
4913\1f
4914File: bashref.info, Node: Bash Features, Next: Job Control, Prev: Shell Variables, Up: Top
ccc6cda3 4915
37c41ab1
CR
49166 Bash Features
4917***************
ccc6cda3 4918
122f603c 4919This chapter describes features unique to Bash.
ccc6cda3 4920
bb70624e 4921* Menu:
ccc6cda3 4922
bb70624e
JA
4923* Invoking Bash:: Command line options that you can give
4924 to Bash.
4925* Bash Startup Files:: When and how Bash executes scripts.
4926* Interactive Shells:: What an interactive shell is.
4927* Bash Conditional Expressions:: Primitives used in composing expressions for
4928 the `test' builtin.
4929* Shell Arithmetic:: Arithmetic on shell variables.
4930* Aliases:: Substituting one command for another.
4931* Arrays:: Array Variables.
4932* The Directory Stack:: History of visited directories.
122f603c 4933* Controlling the Prompt:: Customizing the various prompt strings.
bb70624e
JA
4934* The Restricted Shell:: A more controlled mode of shell execution.
4935* Bash POSIX Mode:: Making Bash behave more closely to what
4936 the POSIX standard specifies.
ccc6cda3 4937
bb70624e
JA
4938\1f
4939File: bashref.info, Node: Invoking Bash, Next: Bash Startup Files, Up: Bash Features
ccc6cda3 4940
37c41ab1
CR
49416.1 Invoking Bash
4942=================
ccc6cda3 4943
f73dda09
JA
4944 bash [long-opt] [-ir] [-abefhkmnptuvxdBCDHP] [-o OPTION] [-O SHOPT_OPTION] [ARGUMENT ...]
4945 bash [long-opt] [-abefhkmnptuvxdBCDHP] [-o OPTION] [-O SHOPT_OPTION] -c STRING [ARGUMENT ...]
4946 bash [long-opt] -s [-abefhkmnptuvxdBCDHP] [-o OPTION] [-O SHOPT_OPTION] [ARGUMENT ...]
ccc6cda3 4947
eb0b2ad8
CR
4948 All of the single-character options used with the `set' builtin
4949(*note The Set Builtin::) can be used as options when the shell is
4950invoked. In addition, there are several multi-character options that
4951you can use. These options must appear on the command line before the
4952single-character options to be recognized.
ccc6cda3 4953
d3a24ed2
CR
4954`--debugger'
4955 Arrange for the debugger profile to be executed before the shell
6a8fd0ed 4956 starts. Turns on extended debugging mode (see *note The Shopt
d3ad40de 4957 Builtin:: for a description of the `extdebug' option to the `shopt'
eb0b2ad8 4958 builtin).
d3a24ed2 4959
bb70624e
JA
4960`--dump-po-strings'
4961 A list of all double-quoted strings preceded by `$' is printed on
eb2bb562 4962 the standard output in the GNU `gettext' PO (portable object) file
bb70624e 4963 format. Equivalent to `-D' except for the output format.
ccc6cda3 4964
bb70624e
JA
4965`--dump-strings'
4966 Equivalent to `-D'.
ccc6cda3 4967
bb70624e 4968`--help'
d3ad40de 4969 Display a usage message on standard output and exit successfully.
ccc6cda3 4970
28ef6c31
JA
4971`--init-file FILENAME'
4972`--rcfile FILENAME'
4973 Execute commands from FILENAME (instead of `~/.bashrc') in an
4974 interactive shell.
4975
bb70624e 4976`--login'
7117c2d2 4977 Equivalent to `-l'.
ccc6cda3 4978
bb70624e 4979`--noediting'
28ef6c31 4980 Do not use the GNU Readline library (*note Command Line Editing::)
bb70624e 4981 to read command lines when the shell is interactive.
ccc6cda3 4982
bb70624e
JA
4983`--noprofile'
4984 Don't load the system-wide startup file `/etc/profile' or any of
4985 the personal initialization files `~/.bash_profile',
4986 `~/.bash_login', or `~/.profile' when Bash is invoked as a login
4987 shell.
ccc6cda3 4988
bb70624e
JA
4989`--norc'
4990 Don't read the `~/.bashrc' initialization file in an interactive
4991 shell. This is on by default if the shell is invoked as `sh'.
ccc6cda3 4992
bb70624e
JA
4993`--posix'
4994 Change the behavior of Bash where the default operation differs
ac18b312
CR
4995 from the POSIX standard to match the standard. This is intended
4996 to make Bash behave as a strict superset of that standard. *Note
4997 Bash POSIX Mode::, for a description of the Bash POSIX mode.
ccc6cda3 4998
bb70624e 4999`--restricted'
28ef6c31 5000 Make the shell a restricted shell (*note The Restricted Shell::).
ccc6cda3 5001
bb70624e
JA
5002`--verbose'
5003 Equivalent to `-v'. Print shell input lines as they're read.
ccc6cda3 5004
bb70624e
JA
5005`--version'
5006 Show version information for this instance of Bash on the standard
5007 output and exit successfully.
ccc6cda3 5008
bb70624e
JA
5009 There are several single-character options that may be supplied at
5010invocation which are not available with the `set' builtin.
ccc6cda3 5011
bb70624e
JA
5012`-c STRING'
5013 Read and execute commands from STRING after processing the
5014 options, then exit. Any remaining arguments are assigned to the
5015 positional parameters, starting with `$0'.
ccc6cda3 5016
bb70624e
JA
5017`-i'
5018 Force the shell to run interactively. Interactive shells are
6a8fd0ed 5019 described in *note Interactive Shells::.
ccc6cda3 5020
7117c2d2
JA
5021`-l'
5022 Make this shell act as if it had been directly invoked by login.
5023 When the shell is interactive, this is equivalent to starting a
5024 login shell with `exec -l bash'. When the shell is not
5025 interactive, the login shell startup files will be executed.
5026 `exec bash -l' or `exec bash --login' will replace the current
5027 shell with a Bash login shell. *Note Bash Startup Files::, for a
5028 description of the special behavior of a login shell.
5029
bb70624e 5030`-r'
28ef6c31 5031 Make the shell a restricted shell (*note The Restricted Shell::).
ccc6cda3 5032
bb70624e
JA
5033`-s'
5034 If this option is present, or if no arguments remain after option
5035 processing, then commands are read from the standard input. This
5036 option allows the positional parameters to be set when invoking an
5037 interactive shell.
ccc6cda3 5038
bb70624e
JA
5039`-D'
5040 A list of all double-quoted strings preceded by `$' is printed on
eb2bb562 5041 the standard output. These are the strings that are subject to
bb70624e 5042 language translation when the current locale is not `C' or `POSIX'
28ef6c31 5043 (*note Locale Translation::). This implies the `-n' option; no
bb70624e 5044 commands will be executed.
ccc6cda3 5045
f73dda09
JA
5046`[-+]O [SHOPT_OPTION]'
5047 SHOPT_OPTION is one of the shell options accepted by the `shopt'
d3ad40de
CR
5048 builtin (*note The Shopt Builtin::). If SHOPT_OPTION is present,
5049 `-O' sets the value of that option; `+O' unsets it. If
f73dda09
JA
5050 SHOPT_OPTION is not supplied, the names and values of the shell
5051 options accepted by `shopt' are printed on the standard output.
5052 If the invocation option is `+O', the output is displayed in a
5053 format that may be reused as input.
5054
bb70624e
JA
5055`--'
5056 A `--' signals the end of options and disables further option
5057 processing. Any arguments after the `--' are treated as filenames
5058 and arguments.
ccc6cda3 5059
f73dda09
JA
5060 A _login_ shell is one whose first character of argument zero is
5061`-', or one invoked with the `--login' option.
5062
28ef6c31 5063 An _interactive_ shell is one started without non-option arguments,
bb70624e
JA
5064unless `-s' is specified, without specifying the `-c' option, and whose
5065input and output are both connected to terminals (as determined by
5066`isatty(3)'), or one started with the `-i' option. *Note Interactive
28ef6c31 5067Shells::, for more information.
ccc6cda3 5068
bb70624e
JA
5069 If arguments remain after option processing, and neither the `-c'
5070nor the `-s' option has been supplied, the first argument is assumed to
28ef6c31
JA
5071be the name of a file containing shell commands (*note Shell Scripts::).
5072When Bash is invoked in this fashion, `$0' is set to the name of the
5073file, and the positional parameters are set to the remaining arguments.
5074Bash reads and executes commands from this file, then exits. Bash's
5075exit status is the exit status of the last command executed in the
5076script. If no commands are executed, the exit status is 0.
ccc6cda3 5077
bb70624e
JA
5078\1f
5079File: bashref.info, Node: Bash Startup Files, Next: Interactive Shells, Prev: Invoking Bash, Up: Bash Features
ccc6cda3 5080
37c41ab1
CR
50816.2 Bash Startup Files
5082======================
ccc6cda3 5083
d3ad40de 5084This section describes how Bash executes its startup files. If any of
37c41ab1 5085the files exist but cannot be read, Bash reports an error. Tildes are
122f603c 5086expanded in filenames as described above under Tilde Expansion (*note
37c41ab1 5087Tilde Expansion::).
ccc6cda3 5088
6a8fd0ed 5089 Interactive shells are described in *note Interactive Shells::.
ccc6cda3 5090
bb70624e
JA
5091Invoked as an interactive login shell, or with `--login'
5092........................................................
cce855bc 5093
37c41ab1 5094When Bash is invoked as an interactive login shell, or as a
bb70624e
JA
5095non-interactive shell with the `--login' option, it first reads and
5096executes commands from the file `/etc/profile', if that file exists.
5097After reading that file, it looks for `~/.bash_profile',
5098`~/.bash_login', and `~/.profile', in that order, and reads and
5099executes commands from the first one that exists and is readable. The
5100`--noprofile' option may be used when the shell is started to inhibit
5101this behavior.
ccc6cda3 5102
bb70624e
JA
5103 When a login shell exits, Bash reads and executes commands from the
5104file `~/.bash_logout', if it exists.
ccc6cda3 5105
bb70624e
JA
5106Invoked as an interactive non-login shell
5107.........................................
ccc6cda3 5108
37c41ab1 5109When an interactive shell that is not a login shell is started, Bash
bb70624e
JA
5110reads and executes commands from `~/.bashrc', if that file exists.
5111This may be inhibited by using the `--norc' option. The `--rcfile
5112FILE' option will force Bash to read and execute commands from FILE
5113instead of `~/.bashrc'.
ccc6cda3 5114
bb70624e
JA
5115 So, typically, your `~/.bash_profile' contains the line
5116 `if [ -f ~/.bashrc ]; then . ~/.bashrc; fi'
37c41ab1 5117 after (or before) any login-specific initializations.
ccc6cda3 5118
bb70624e
JA
5119Invoked non-interactively
5120.........................
ccc6cda3 5121
37c41ab1 5122When Bash is started non-interactively, to run a shell script, for
bb70624e
JA
5123example, it looks for the variable `BASH_ENV' in the environment,
5124expands its value if it appears there, and uses the expanded value as
5125the name of a file to read and execute. Bash behaves as if the
5126following command were executed:
5127 `if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi'
37c41ab1 5128 but the value of the `PATH' variable is not used to search for the
122f603c 5129filename.
ccc6cda3 5130
28ef6c31
JA
5131 As noted above, if a non-interactive shell is invoked with the
5132`--login' option, Bash attempts to read and execute commands from the
5133login shell startup files.
5134
bb70624e
JA
5135Invoked with name `sh'
5136......................
ccc6cda3 5137
37c41ab1 5138If Bash is invoked with the name `sh', it tries to mimic the startup
bb70624e
JA
5139behavior of historical versions of `sh' as closely as possible, while
5140conforming to the POSIX standard as well.
ccc6cda3 5141
bb70624e
JA
5142 When invoked as an interactive login shell, or as a non-interactive
5143shell with the `--login' option, it first attempts to read and execute
5144commands from `/etc/profile' and `~/.profile', in that order. The
5145`--noprofile' option may be used to inhibit this behavior. When
5146invoked as an interactive shell with the name `sh', Bash looks for the
5147variable `ENV', expands its value if it is defined, and uses the
5148expanded value as the name of a file to read and execute. Since a
5149shell invoked as `sh' does not attempt to read and execute commands
5150from any other startup files, the `--rcfile' option has no effect. A
5151non-interactive shell invoked with the name `sh' does not attempt to
5152read any other startup files.
ccc6cda3 5153
bb70624e
JA
5154 When invoked as `sh', Bash enters POSIX mode after the startup files
5155are read.
b72432fd 5156
bb70624e
JA
5157Invoked in POSIX mode
5158.....................
ccc6cda3 5159
37c41ab1
CR
5160When Bash is started in POSIX mode, as with the `--posix' command line
5161option, it follows the POSIX standard for startup files. In this mode,
5162interactive shells expand the `ENV' variable and commands are read and
5163executed from the file whose name is the expanded value. No other
5164startup files are read.
ccc6cda3 5165
bb70624e
JA
5166Invoked by remote shell daemon
5167..............................
ccc6cda3 5168
c2a47ea9 5169Bash attempts to determine when it is being run with its standard input
e05be32d
CR
5170connected to a network connection, as when executed by the remote shell
5171daemon, usually `rshd', or the secure shell daemon `sshd'. If Bash
5172determines it is being run in this fashion, it reads and executes
5173commands from `~/.bashrc', if that file exists and is readable. It
5174will not do this if invoked as `sh'. The `--norc' option may be used
5175to inhibit this behavior, and the `--rcfile' option may be used to
5176force another file to be read, but `rshd' does not generally invoke the
5177shell with those options or allow them to be specified.
ccc6cda3 5178
bb70624e
JA
5179Invoked with unequal effective and real UID/GIDs
5180................................................
5181
37c41ab1
CR
5182If Bash is started with the effective user (group) id not equal to the
5183real user (group) id, and the `-p' option is not supplied, no startup
5184files are read, shell functions are not inherited from the environment,
8f714a7c
CR
5185the `SHELLOPTS', `BASHOPTS', `CDPATH', and `GLOBIGNORE' variables, if
5186they appear in the environment, are ignored, and the effective user id
5187is set to the real user id. If the `-p' option is supplied at
5188invocation, the startup behavior is the same, but the effective user id
5189is not reset.
bb70624e
JA
5190
5191\1f
5192File: bashref.info, Node: Interactive Shells, Next: Bash Conditional Expressions, Prev: Bash Startup Files, Up: Bash Features
5193
37c41ab1
CR
51946.3 Interactive Shells
5195======================
bb70624e
JA
5196
5197* Menu:
5198
5199* What is an Interactive Shell?:: What determines whether a shell is Interactive.
5200* Is this Shell Interactive?:: How to tell if a shell is interactive.
5201* Interactive Shell Behavior:: What changes in a interactive shell?
5202
5203\1f
5204File: bashref.info, Node: What is an Interactive Shell?, Next: Is this Shell Interactive?, Up: Interactive Shells
5205
37c41ab1
CR
52066.3.1 What is an Interactive Shell?
5207-----------------------------------
bb70624e 5208
37c41ab1 5209An interactive shell is one started without non-option arguments,
d3ad40de
CR
5210unless `-s' is specified, without specifying the `-c' option, and whose
5211input and error output are both connected to terminals (as determined
5212by `isatty(3)'), or one started with the `-i' option.
bb70624e
JA
5213
5214 An interactive shell generally reads from and writes to a user's
5215terminal.
5216
5217 The `-s' invocation option may be used to set the positional
5218parameters when an interactive shell is started.
5219
5220\1f
5221File: bashref.info, Node: Is this Shell Interactive?, Next: Interactive Shell Behavior, Prev: What is an Interactive Shell?, Up: Interactive Shells
5222
37c41ab1
CR
52236.3.2 Is this Shell Interactive?
5224--------------------------------
bb70624e 5225
37c41ab1 5226To determine within a startup script whether or not Bash is running
bb70624e
JA
5227interactively, test the value of the `-' special parameter. It
5228contains `i' when the shell is interactive. For example:
5229
5230 case "$-" in
5231 *i*) echo This shell is interactive ;;
5232 *) echo This shell is not interactive ;;
5233 esac
5234
28ef6c31
JA
5235 Alternatively, startup scripts may examine the variable `PS1'; it is
5236unset in non-interactive shells, and set in interactive shells. Thus:
bb70624e
JA
5237
5238 if [ -z "$PS1" ]; then
5239 echo This shell is not interactive
5240 else
5241 echo This shell is interactive
5242 fi
5243
5244\1f
5245File: bashref.info, Node: Interactive Shell Behavior, Prev: Is this Shell Interactive?, Up: Interactive Shells
5246
37c41ab1
CR
52476.3.3 Interactive Shell Behavior
5248--------------------------------
bb70624e 5249
37c41ab1 5250When the shell is running interactively, it changes its behavior in
bb70624e
JA
5251several ways.
5252
6a8fd0ed 5253 1. Startup files are read and executed as described in *note Bash
bb70624e
JA
5254 Startup Files::.
5255
28ef6c31 5256 2. Job Control (*note Job Control::) is enabled by default. When job
bb70624e
JA
5257 control is in effect, Bash ignores the keyboard-generated job
5258 control signals `SIGTTIN', `SIGTTOU', and `SIGTSTP'.
5259
28ef6c31
JA
5260 3. Bash expands and displays `PS1' before reading the first line of a
5261 command, and expands and displays `PS2' before reading the second
5262 and subsequent lines of a multi-line command.
bb70624e
JA
5263
5264 4. Bash executes the value of the `PROMPT_COMMAND' variable as a
5265 command before printing the primary prompt, `$PS1' (*note Bash
28ef6c31 5266 Variables::).
bb70624e 5267
28ef6c31 5268 5. Readline (*note Command Line Editing::) is used to read commands
bb70624e
JA
5269 from the user's terminal.
5270
5271 6. Bash inspects the value of the `ignoreeof' option to `set -o'
5272 instead of exiting immediately when it receives an `EOF' on its
28ef6c31 5273 standard input when reading a command (*note The Set Builtin::).
bb70624e 5274
28ef6c31
JA
5275 7. Command history (*note Bash History Facilities::) and history
5276 expansion (*note History Interaction::) are enabled by default.
bb70624e
JA
5277 Bash will save the command history to the file named by `$HISTFILE'
5278 when an interactive shell exits.
5279
28ef6c31 5280 8. Alias expansion (*note Aliases::) is performed by default.
bb70624e
JA
5281
5282 9. In the absence of any traps, Bash ignores `SIGTERM' (*note
28ef6c31 5283 Signals::).
bb70624e
JA
5284
5285 10. In the absence of any traps, `SIGINT' is caught and handled
28ef6c31 5286 ((*note Signals::). `SIGINT' will interrupt some shell builtins.
bb70624e
JA
5287
5288 11. An interactive login shell sends a `SIGHUP' to all jobs on exit if
d3ad40de 5289 the `huponexit' shell option has been enabled (*note Signals::).
bb70624e
JA
5290
5291 12. The `-n' invocation option is ignored, and `set -n' has no effect
28ef6c31 5292 (*note The Set Builtin::).
bb70624e
JA
5293
5294 13. Bash will check for mail periodically, depending on the values of
5295 the `MAIL', `MAILPATH', and `MAILCHECK' shell variables (*note
28ef6c31 5296 Bash Variables::).
bb70624e
JA
5297
5298 14. Expansion errors due to references to unbound shell variables after
5299 `set -u' has been enabled will not cause the shell to exit (*note
28ef6c31 5300 The Set Builtin::).
bb70624e
JA
5301
5302 15. The shell will not exit on expansion errors caused by VAR being
5303 unset or null in `${VAR:?WORD}' expansions (*note Shell Parameter
28ef6c31 5304 Expansion::).
bb70624e
JA
5305
5306 16. Redirection errors encountered by shell builtins will not cause the
5307 shell to exit.
5308
5309 17. When running in POSIX mode, a special builtin returning an error
28ef6c31 5310 status will not cause the shell to exit (*note Bash POSIX Mode::).
bb70624e
JA
5311
5312 18. A failed `exec' will not cause the shell to exit (*note Bourne
28ef6c31 5313 Shell Builtins::).
bb70624e
JA
5314
5315 19. Parser syntax errors will not cause the shell to exit.
5316
5317 20. Simple spelling correction for directory arguments to the `cd'
5318 builtin is enabled by default (see the description of the `cdspell'
6a8fd0ed 5319 option to the `shopt' builtin in *note The Shopt Builtin::).
bb70624e
JA
5320
5321 21. The shell will check the value of the `TMOUT' variable and exit if
5322 a command is not read within the specified number of seconds after
28ef6c31 5323 printing `$PS1' (*note Bash Variables::).
bb70624e
JA
5324
5325
5326\1f
5327File: bashref.info, Node: Bash Conditional Expressions, Next: Shell Arithmetic, Prev: Interactive Shells, Up: Bash Features
5328
37c41ab1
CR
53296.4 Bash Conditional Expressions
5330================================
bb70624e 5331
37c41ab1
CR
5332Conditional expressions are used by the `[[' compound command and the
5333`test' and `[' builtin commands.
bb70624e
JA
5334
5335 Expressions may be unary or binary. Unary expressions are often
5336used to examine the status of a file. There are string operators and
5337numeric comparison operators as well. If the FILE argument to one of
5338the primaries is of the form `/dev/fd/N', then file descriptor N is
5339checked. If the FILE argument to one of the primaries is one of
5340`/dev/stdin', `/dev/stdout', or `/dev/stderr', file descriptor 0, 1, or
53412, respectively, is checked.
5342
54a1fa7c
CR
5343 When used with `[[', the `<' and `>' operators sort
5344lexicographically using the current locale. The `test' command uses
5345ASCII ordering.
d6593885 5346
37c41ab1
CR
5347 Unless otherwise specified, primaries that operate on files follow
5348symbolic links and operate on the target of the link, rather than the
5349link itself.
5350
bb70624e
JA
5351`-a FILE'
5352 True if FILE exists.
5353
5354`-b FILE'
5355 True if FILE exists and is a block special file.
5356
5357`-c FILE'
5358 True if FILE exists and is a character special file.
5359
5360`-d FILE'
5361 True if FILE exists and is a directory.
5362
5363`-e FILE'
5364 True if FILE exists.
5365
5366`-f FILE'
5367 True if FILE exists and is a regular file.
5368
5369`-g FILE'
5370 True if FILE exists and its set-group-id bit is set.
5371
5372`-h FILE'
5373 True if FILE exists and is a symbolic link.
5374
5375`-k FILE'
5376 True if FILE exists and its "sticky" bit is set.
5377
5378`-p FILE'
5379 True if FILE exists and is a named pipe (FIFO).
5380
5381`-r FILE'
5382 True if FILE exists and is readable.
5383
5384`-s FILE'
5385 True if FILE exists and has a size greater than zero.
5386
5387`-t FD'
5388 True if file descriptor FD is open and refers to a terminal.
ccc6cda3
JA
5389
5390`-u FILE'
5391 True if FILE exists and its set-user-id bit is set.
5392
5393`-w FILE'
5394 True if FILE exists and is writable.
5395
5396`-x FILE'
5397 True if FILE exists and is executable.
5398
ccc6cda3
JA
5399`-G FILE'
5400 True if FILE exists and is owned by the effective group id.
5401
cce855bc
JA
5402`-L FILE'
5403 True if FILE exists and is a symbolic link.
5404
5cdaaf76
CR
5405`-N FILE'
5406 True if FILE exists and has been modified since it was last read.
5407
5408`-O FILE'
5409 True if FILE exists and is owned by the effective user id.
5410
cce855bc
JA
5411`-S FILE'
5412 True if FILE exists and is a socket.
5413
5cdaaf76
CR
5414`FILE1 -ef FILE2'
5415 True if FILE1 and FILE2 refer to the same device and inode numbers.
cce855bc 5416
ccc6cda3 5417`FILE1 -nt FILE2'
7117c2d2
JA
5418 True if FILE1 is newer (according to modification date) than
5419 FILE2, or if FILE1 exists and FILE2 does not.
ccc6cda3
JA
5420
5421`FILE1 -ot FILE2'
7117c2d2
JA
5422 True if FILE1 is older than FILE2, or if FILE2 exists and FILE1
5423 does not.
ccc6cda3 5424
ccc6cda3 5425`-o OPTNAME'
220537f2 5426 True if the shell option OPTNAME is enabled. The list of options
ccc6cda3 5427 appears in the description of the `-o' option to the `set' builtin
28ef6c31 5428 (*note The Set Builtin::).
ccc6cda3 5429
220537f2
CR
5430`-v VARNAME'
5431 True if the shell variable VARNAME is set (has been assigned a
5432 value).
5433
ccc6cda3
JA
5434`-z STRING'
5435 True if the length of STRING is zero.
5436
5437`-n STRING'
5438`STRING'
5439 True if the length of STRING is non-zero.
5440
cce855bc 5441`STRING1 == STRING2'
a3143574
CR
5442`STRING1 = STRING2'
5443 True if the strings are equal. `=' should be used with the `test'
5444 command for POSIX conformance.
ccc6cda3
JA
5445
5446`STRING1 != STRING2'
5447 True if the strings are not equal.
5448
5449`STRING1 < STRING2'
4a8bb13f 5450 True if STRING1 sorts before STRING2 lexicographically.
ccc6cda3
JA
5451
5452`STRING1 > STRING2'
4a8bb13f 5453 True if STRING1 sorts after STRING2 lexicographically.
ccc6cda3
JA
5454
5455`ARG1 OP ARG2'
5456 `OP' is one of `-eq', `-ne', `-lt', `-le', `-gt', or `-ge'. These
5457 arithmetic binary operators return true if ARG1 is equal to, not
5458 equal to, less than, less than or equal to, greater than, or
5459 greater than or equal to ARG2, respectively. ARG1 and ARG2 may be
5460 positive or negative integers.
5461
ccc6cda3 5462\1f
bb70624e 5463File: bashref.info, Node: Shell Arithmetic, Next: Aliases, Prev: Bash Conditional Expressions, Up: Bash Features
ccc6cda3 5464
37c41ab1
CR
54656.5 Shell Arithmetic
5466====================
ccc6cda3 5467
37c41ab1
CR
5468The shell allows arithmetic expressions to be evaluated, as one of the
5469shell expansions or by the `let' and the `-i' option to the `declare'
5470builtins.
ccc6cda3 5471
7117c2d2
JA
5472 Evaluation is done in fixed-width integers with no check for
5473overflow, though division by 0 is trapped and flagged as an error. The
d3a24ed2
CR
5474operators and their precedence, associativity, and values are the same
5475as in the C language. The following list of operators is grouped into
5476levels of equal-precedence operators. The levels are listed in order
5477of decreasing precedence.
cce855bc 5478
bb70624e
JA
5479`ID++ ID--'
5480 variable post-increment and post-decrement
d166f048 5481
bb70624e
JA
5482`++ID --ID'
5483 variable pre-increment and pre-decrement
ccc6cda3 5484
bb70624e
JA
5485`- +'
5486 unary minus and plus
ccc6cda3 5487
bb70624e
JA
5488`! ~'
5489 logical and bitwise negation
ccc6cda3 5490
bb70624e
JA
5491`**'
5492 exponentiation
ccc6cda3 5493
bb70624e
JA
5494`* / %'
5495 multiplication, division, remainder
ccc6cda3 5496
bb70624e
JA
5497`+ -'
5498 addition, subtraction
ccc6cda3 5499
bb70624e
JA
5500`<< >>'
5501 left and right bitwise shifts
cce855bc 5502
bb70624e
JA
5503`<= >= < >'
5504 comparison
cce855bc 5505
bb70624e
JA
5506`== !='
5507 equality and inequality
cce855bc 5508
bb70624e
JA
5509`&'
5510 bitwise AND
cce855bc 5511
bb70624e
JA
5512`^'
5513 bitwise exclusive OR
cce855bc 5514
bb70624e
JA
5515`|'
5516 bitwise OR
cce855bc 5517
bb70624e
JA
5518`&&'
5519 logical AND
ccc6cda3 5520
bb70624e
JA
5521`||'
5522 logical OR
ccc6cda3 5523
bb70624e 5524`expr ? expr : expr'
d3a24ed2 5525 conditional operator
cce855bc 5526
bb70624e
JA
5527`= *= /= %= += -= <<= >>= &= ^= |='
5528 assignment
ccc6cda3 5529
bb70624e
JA
5530`expr1 , expr2'
5531 comma
ccc6cda3 5532
bb70624e
JA
5533 Shell variables are allowed as operands; parameter expansion is
5534performed before the expression is evaluated. Within an expression,
5535shell variables may also be referenced by name without using the
d3a24ed2
CR
5536parameter expansion syntax. A shell variable that is null or unset
5537evaluates to 0 when referenced by name without using the parameter
5538expansion syntax. The value of a variable is evaluated as an
5539arithmetic expression when it is referenced, or when a variable which
5540has been given the INTEGER attribute using `declare -i' is assigned a
5541value. A null value evaluates to 0. A shell variable need not have
e05be32d 5542its INTEGER attribute turned on to be used in an expression.
ccc6cda3 5543
bb70624e
JA
5544 Constants with a leading 0 are interpreted as octal numbers. A
5545leading `0x' or `0X' denotes hexadecimal. Otherwise, numbers take the
eb0b2ad8
CR
5546form [BASE`#']N, where the optional BASE is a decimal number between 2
5547and 64 representing the arithmetic base, and N is a number in that
5548base. If BASE`#' is omitted, then base 10 is used. The digits greater
5549than 9 are represented by the lowercase letters, the uppercase letters,
5550`@', and `_', in that order. If BASE is less than or equal to 36,
5551lowercase and uppercase letters may be used interchangeably to
5552represent numbers between 10 and 35.
ccc6cda3 5553
bb70624e
JA
5554 Operators are evaluated in order of precedence. Sub-expressions in
5555parentheses are evaluated first and may override the precedence rules
5556above.
ccc6cda3 5557
bb70624e
JA
5558\1f
5559File: bashref.info, Node: Aliases, Next: Arrays, Prev: Shell Arithmetic, Up: Bash Features
ccc6cda3 5560
37c41ab1
CR
55616.6 Aliases
5562===========
ccc6cda3 5563
37c41ab1
CR
5564ALIASES allow a string to be substituted for a word when it is used as
5565the first word of a simple command. The shell maintains a list of
bb70624e 5566aliases that may be set and unset with the `alias' and `unalias'
cce855bc
JA
5567builtin commands.
5568
5569 The first word of each simple command, if unquoted, is checked to see
5570if it has an alias. If so, that word is replaced by the text of the
de8913bd
CR
5571alias. The characters `/', `$', ``', `=' and any of the shell
5572metacharacters or quoting characters listed above may not appear in an
5573alias name. The replacement text may contain any valid shell input,
5574including shell metacharacters. The first word of the replacement text
5575is tested for aliases, but a word that is identical to an alias being
5576expanded is not expanded a second time. This means that one may alias
5577`ls' to `"ls -F"', for instance, and Bash does not try to recursively
122f603c
CR
5578expand the replacement text. If the last character of the alias value
5579is a BLANK, then the next command word following the alias is also
5580checked for alias expansion.
cce855bc
JA
5581
5582 Aliases are created and listed with the `alias' command, and removed
5583with the `unalias' command.
5584
5585 There is no mechanism for using arguments in the replacement text,
5586as in `csh'. If arguments are needed, a shell function should be used
28ef6c31 5587(*note Shell Functions::).
cce855bc
JA
5588
5589 Aliases are not expanded when the shell is not interactive, unless
d3ad40de
CR
5590the `expand_aliases' shell option is set using `shopt' (*note The Shopt
5591Builtin::).
ccc6cda3 5592
cce855bc
JA
5593 The rules concerning the definition and use of aliases are somewhat
5594confusing. Bash always reads at least one complete line of input
5595before executing any of the commands on that line. Aliases are
5596expanded when a command is read, not when it is executed. Therefore, an
5597alias definition appearing on the same line as another command does not
5598take effect until the next line of input is read. The commands
5599following the alias definition on that line are not affected by the new
5600alias. This behavior is also an issue when functions are executed.
5601Aliases are expanded when a function definition is read, not when the
5602function is executed, because a function definition is itself a
5603compound command. As a consequence, aliases defined in a function are
5604not available until after that function is executed. To be safe,
5605always put alias definitions on a separate line, and do not use `alias'
5606in compound commands.
ccc6cda3 5607
bb70624e 5608 For almost every purpose, shell functions are preferred over aliases.
ccc6cda3
JA
5609
5610\1f
cce855bc 5611File: bashref.info, Node: Arrays, Next: The Directory Stack, Prev: Aliases, Up: Bash Features
ccc6cda3 5612
37c41ab1
CR
56136.7 Arrays
5614==========
ccc6cda3 5615
09767ff0
CR
5616Bash provides one-dimensional indexed and associative array variables.
5617Any variable may be used as an indexed array; the `declare' builtin
5618will explicitly declare an array. There is no maximum limit on the
5619size of an array, nor any requirement that members be indexed or
5620assigned contiguously. Indexed arrays are referenced using integers
d9e1f41e 5621(including arithmetic expressions (*note Shell Arithmetic::)) and are
09767ff0 5622zero-based; associative arrays use arbitrary strings.
ccc6cda3 5623
09767ff0
CR
5624 An indexed array is created automatically if any variable is
5625assigned to using the syntax
122f603c 5626 NAME[SUBSCRIPT]=VALUE
ccc6cda3
JA
5627
5628The SUBSCRIPT is treated as an arithmetic expression that must evaluate
f6da9f85 5629to a number. To explicitly declare an array, use
ccc6cda3 5630 declare -a NAME
37c41ab1 5631 The syntax
ccc6cda3 5632 declare -a NAME[SUBSCRIPT]
09767ff0
CR
5633 is also accepted; the SUBSCRIPT is ignored.
5634
122f603c 5635Associative arrays are created using
09767ff0
CR
5636 declare -A NAME.
5637
5638 Attributes may be specified for an array variable using the
5639`declare' and `readonly' builtins. Each attribute applies to all
5640members of an array.
ccc6cda3
JA
5641
5642 Arrays are assigned to using compound assignments of the form
122f603c 5643 NAME=(VALUE1 VALUE2 ... )
09767ff0 5644 where each VALUE is of the form `[SUBSCRIPT]='STRING. Indexed array
122f603c
CR
5645assignments do not require anything but STRING. When assigning to
5646indexed arrays, if the optional subscript is supplied, that index is
09767ff0
CR
5647assigned to; otherwise the index of the element assigned is the last
5648index assigned to by the statement plus one. Indexing starts at zero.
5649
5650 When assigning to an associative array, the subscript is required.
5651
5652 This syntax is also accepted by the `declare' builtin. Individual
122f603c 5653array elements may be assigned to using the `NAME[SUBSCRIPT]=VALUE'
09767ff0 5654syntax introduced above.
ccc6cda3 5655
122f603c
CR
5656 Any element of an array may be referenced using `${NAME[SUBSCRIPT]}'.
5657The braces are required to avoid conflicts with the shell's filename
5658expansion operators. If the SUBSCRIPT is `@' or `*', the word expands
5659to all members of the array NAME. These subscripts differ only when
5660the word appears within double quotes. If the word is double-quoted,
5661`${NAME[*]}' expands to a single word with the value of each array
5662member separated by the first character of the `IFS' variable, and
5663`${NAME[@]}' expands each element of NAME to a separate word. When
5664there are no array members, `${NAME[@]}' expands to nothing. If the
5665double-quoted expansion occurs within a word, the expansion of the
5666first parameter is joined with the beginning part of the original word,
5667and the expansion of the last parameter is joined with the last part of
5668the original word. This is analogous to the expansion of the special
5669parameters `@' and `*'. `${#NAME[SUBSCRIPT]}' expands to the length of
5670`${NAME[SUBSCRIPT]}'. If SUBSCRIPT is `@' or `*', the expansion is the
5671number of elements in the array. Referencing an array variable without
5672a subscript is equivalent to referencing with a subscript of 0. If the
5673SUBSCRIPT used to reference an element of an indexed array evaluates to
5674a number less than zero, it is used as an offset from one greater than
5675the array's maximum index (so a subcript of -1 refers to the last
5676element of the array).
ccc6cda3 5677
4a8bb13f
CR
5678 An array variable is considered set if a subscript has been assigned
5679a value. The null string is a valid value.
5680
122f603c
CR
5681 The `unset' builtin is used to destroy arrays. `unset
5682NAME[SUBSCRIPT]' destroys the array element at index SUBSCRIPT. Care
1c72c0cd 5683must be taken to avoid unwanted side effects caused by filename
122f603c
CR
5684expansion. `unset NAME', where NAME is an array, removes the entire
5685array. A subscript of `*' or `@' also removes the entire array.
ccc6cda3
JA
5686
5687 The `declare', `local', and `readonly' builtins each accept a `-a'
09767ff0 5688option to specify an indexed array and a `-A' option to specify an
d9e1f41e
CR
5689associative array. If both options are supplied, `-A' takes precedence.
5690The `read' builtin accepts a `-a' option to assign a list of words read
5691from the standard input to an array, and can read values from the
5692standard input into individual array elements. The `set' and `declare'
5693builtins display array values in a way that allows them to be reused as
5694input.
ccc6cda3
JA
5695
5696\1f
122f603c 5697File: bashref.info, Node: The Directory Stack, Next: Controlling the Prompt, Prev: Arrays, Up: Bash Features
cce855bc 5698
37c41ab1
CR
56996.8 The Directory Stack
5700=======================
cce855bc 5701
bb70624e
JA
5702* Menu:
5703
5704* Directory Stack Builtins:: Bash builtin commands to manipulate
5705 the directory stack.
5706
5707 The directory stack is a list of recently-visited directories. The
cce855bc
JA
5708`pushd' builtin adds directories to the stack as it changes the current
5709directory, and the `popd' builtin removes specified directories from
5710the stack and changes the current directory to the directory removed.
5711The `dirs' builtin displays the contents of the directory stack.
5712
5713 The contents of the directory stack are also visible as the value of
5714the `DIRSTACK' shell variable.
5715
bb70624e
JA
5716\1f
5717File: bashref.info, Node: Directory Stack Builtins, Up: The Directory Stack
5718
37c41ab1
CR
57196.8.1 Directory Stack Builtins
5720------------------------------
bb70624e 5721
cce855bc 5722`dirs'
122f603c
CR
5723 dirs [-clpv] [+N | -N]
5724
cce855bc
JA
5725 Display the list of currently remembered directories. Directories
5726 are added to the list with the `pushd' command; the `popd' command
5727 removes directories from the list.
cce855bc
JA
5728
5729 `-c'
5730 Clears the directory stack by deleting all of the elements.
5731
5732 `-l'
122f603c
CR
5733 Produces a listing using full pathnames; the default listing
5734 format uses a tilde to denote the home directory.
cce855bc
JA
5735
5736 `-p'
5737 Causes `dirs' to print the directory stack with one entry per
5738 line.
5739
5740 `-v'
5741 Causes `dirs' to print the directory stack with one entry per
5742 line, prefixing each entry with its index in the stack.
5743
122f603c
CR
5744 `+N'
5745 Displays the Nth directory (counting from the left of the
5746 list printed by `dirs' when invoked without options), starting
5747 with zero.
5748
5749 `-N'
5750 Displays the Nth directory (counting from the right of the
5751 list printed by `dirs' when invoked without options), starting
5752 with zero.
5753
cce855bc 5754`popd'
122f603c 5755 popd [-n] [+N | -N]
cce855bc
JA
5756
5757 Remove the top entry from the directory stack, and `cd' to the new
5758 top directory. When no arguments are given, `popd' removes the
5759 top directory from the stack and performs a `cd' to the new top
5760 directory. The elements are numbered from 0 starting at the first
122f603c
CR
5761 directory listed with `dirs'; that is, `popd' is equivalent to
5762 `popd +0'.
5763
5764 `-n'
5765 Suppresses the normal change of directory when removing
5766 directories from the stack, so that only the stack is
5767 manipulated.
5768
cce855bc
JA
5769 `+N'
5770 Removes the Nth directory (counting from the left of the list
5771 printed by `dirs'), starting with zero.
5772
5773 `-N'
5774 Removes the Nth directory (counting from the right of the
5775 list printed by `dirs'), starting with zero.
5776
cce855bc 5777`pushd'
122f603c 5778 pushd [-n] [+N | -N | DIR]
cce855bc
JA
5779
5780 Save the current directory on the top of the directory stack and
5781 then `cd' to DIR. With no arguments, `pushd' exchanges the top
5782 two directories.
5783
d3ad40de
CR
5784 `-n'
5785 Suppresses the normal change of directory when adding
5786 directories to the stack, so that only the stack is
5787 manipulated.
5788
cce855bc
JA
5789 `+N'
5790 Brings the Nth directory (counting from the left of the list
5791 printed by `dirs', starting with zero) to the top of the list
5792 by rotating the stack.
5793
5794 `-N'
5795 Brings the Nth directory (counting from the right of the list
5796 printed by `dirs', starting with zero) to the top of the list
5797 by rotating the stack.
5798
cce855bc
JA
5799 `DIR'
5800 Makes the current working directory be the top of the stack,
122f603c
CR
5801 making it the new current directory as if it had been
5802 supplied as an argument to the `cd' builtin.
761783bf 5803
cce855bc 5804\1f
122f603c 5805File: bashref.info, Node: Controlling the Prompt, Next: The Restricted Shell, Prev: The Directory Stack, Up: Bash Features
ccc6cda3 5806
37c41ab1
CR
58076.9 Controlling the Prompt
5808==========================
ccc6cda3 5809
37c41ab1
CR
5810The value of the variable `PROMPT_COMMAND' is examined just before Bash
5811prints each primary prompt. If `PROMPT_COMMAND' is set and has a
bb70624e
JA
5812non-null value, then the value is executed just as if it had been typed
5813on the command line.
ccc6cda3
JA
5814
5815 In addition, the following table describes the special characters
122f603c 5816which can appear in the prompt variables `PS1' to `PS4':
ccc6cda3
JA
5817
5818`\a'
cce855bc 5819 A bell character.
ccc6cda3
JA
5820
5821`\d'
cce855bc 5822 The date, in "Weekday Month Date" format (e.g., "Tue May 26").
ccc6cda3 5823
7117c2d2
JA
5824`\D{FORMAT}'
5825 The FORMAT is passed to `strftime'(3) and the result is inserted
5826 into the prompt string; an empty FORMAT results in a
5827 locale-specific time representation. The braces are required.
5828
ccc6cda3 5829`\e'
cce855bc 5830 An escape character.
ccc6cda3
JA
5831
5832`\h'
cce855bc 5833 The hostname, up to the first `.'.
ccc6cda3
JA
5834
5835`\H'
cce855bc 5836 The hostname.
ccc6cda3 5837
bb70624e
JA
5838`\j'
5839 The number of jobs currently managed by the shell.
5840
5841`\l'
5842 The basename of the shell's terminal device name.
5843
ccc6cda3 5844`\n'
cce855bc
JA
5845 A newline.
5846
5847`\r'
5848 A carriage return.
ccc6cda3
JA
5849
5850`\s'
cce855bc 5851 The name of the shell, the basename of `$0' (the portion following
ccc6cda3
JA
5852 the final slash).
5853
5854`\t'
cce855bc 5855 The time, in 24-hour HH:MM:SS format.
ccc6cda3
JA
5856
5857`\T'
cce855bc 5858 The time, in 12-hour HH:MM:SS format.
ccc6cda3
JA
5859
5860`\@'
cce855bc
JA
5861 The time, in 12-hour am/pm format.
5862
f73dda09
JA
5863`\A'
5864 The time, in 24-hour HH:MM format.
5865
cce855bc
JA
5866`\u'
5867 The username of the current user.
ccc6cda3
JA
5868
5869`\v'
cce855bc 5870 The version of Bash (e.g., 2.00)
ccc6cda3
JA
5871
5872`\V'
cce855bc 5873 The release of Bash, version + patchlevel (e.g., 2.00.0)
ccc6cda3
JA
5874
5875`\w'
12d937f9 5876 The current working directory, with `$HOME' abbreviated with a
09767ff0 5877 tilde (uses the `$PROMPT_DIRTRIM' variable).
ccc6cda3
JA
5878
5879`\W'
12d937f9 5880 The basename of `$PWD', with `$HOME' abbreviated with a tilde.
ccc6cda3
JA
5881
5882`\!'
cce855bc 5883 The history number of this command.
ccc6cda3
JA
5884
5885`\#'
cce855bc 5886 The command number of this command.
ccc6cda3
JA
5887
5888`\$'
cce855bc 5889 If the effective uid is 0, `#', otherwise `$'.
ccc6cda3 5890
cce855bc
JA
5891`\NNN'
5892 The character whose ASCII code is the octal value NNN.
ccc6cda3
JA
5893
5894`\\'
cce855bc 5895 A backslash.
ccc6cda3
JA
5896
5897`\['
cce855bc 5898 Begin a sequence of non-printing characters. This could be used to
ccc6cda3
JA
5899 embed a terminal control sequence into the prompt.
5900
5901`\]'
cce855bc 5902 End a sequence of non-printing characters.
ccc6cda3 5903
bb70624e
JA
5904 The command number and the history number are usually different: the
5905history number of a command is its position in the history list, which
5906may include commands restored from the history file (*note Bash History
28ef6c31
JA
5907Facilities::), while the command number is the position in the sequence
5908of commands executed during the current shell session.
bb70624e
JA
5909
5910 After the string is decoded, it is expanded via parameter expansion,
5911command substitution, arithmetic expansion, and quote removal, subject
28ef6c31 5912to the value of the `promptvars' shell option (*note Bash Builtins::).
bb70624e 5913
ccc6cda3 5914\1f
122f603c 5915File: bashref.info, Node: The Restricted Shell, Next: Bash POSIX Mode, Prev: Controlling the Prompt, Up: Bash Features
ccc6cda3 5916
37c41ab1
CR
59176.10 The Restricted Shell
5918=========================
ccc6cda3 5919
37c41ab1
CR
5920If Bash is started with the name `rbash', or the `--restricted' or `-r'
5921option is supplied at invocation, the shell becomes restricted. A
ccc6cda3
JA
5922restricted shell is used to set up an environment more controlled than
5923the standard shell. A restricted shell behaves identically to `bash'
7117c2d2
JA
5924with the exception that the following are disallowed or not performed:
5925
ccc6cda3
JA
5926 * Changing directories with the `cd' builtin.
5927
b72432fd
JA
5928 * Setting or unsetting the values of the `SHELL', `PATH', `ENV', or
5929 `BASH_ENV' variables.
ccc6cda3
JA
5930
5931 * Specifying command names containing slashes.
5932
5933 * Specifying a filename containing a slash as an argument to the `.'
5934 builtin command.
5935
bb70624e
JA
5936 * Specifying a filename containing a slash as an argument to the `-p'
5937 option to the `hash' builtin command.
5938
ccc6cda3
JA
5939 * Importing function definitions from the shell environment at
5940 startup.
5941
cce855bc
JA
5942 * Parsing the value of `SHELLOPTS' from the shell environment at
5943 startup.
5944
ccc6cda3
JA
5945 * Redirecting output using the `>', `>|', `<>', `>&', `&>', and `>>'
5946 redirection operators.
5947
5948 * Using the `exec' builtin to replace the shell with another command.
5949
5950 * Adding or deleting builtin commands with the `-f' and `-d' options
5951 to the `enable' builtin.
5952
7117c2d2
JA
5953 * Using the `enable' builtin command to enable disabled shell
5954 builtins.
5955
ccc6cda3
JA
5956 * Specifying the `-p' option to the `command' builtin.
5957
cce855bc 5958 * Turning off restricted mode with `set +r' or `set +o restricted'.
ccc6cda3 5959
7117c2d2
JA
5960 These restrictions are enforced after any startup files are read.
5961
5962 When a command that is found to be a shell script is executed (*note
5963Shell Scripts::), `rbash' turns off any restrictions in the shell
5964spawned to execute the script.
5965
ccc6cda3
JA
5966\1f
5967File: bashref.info, Node: Bash POSIX Mode, Prev: The Restricted Shell, Up: Bash Features
5968
37c41ab1
CR
59696.11 Bash POSIX Mode
5970====================
ccc6cda3 5971
37c41ab1
CR
5972Starting Bash with the `--posix' command-line option or executing `set
5973-o posix' while Bash is running will cause Bash to conform more closely
ac18b312
CR
5974to the POSIX standard by changing the behavior to match that specified
5975by POSIX in areas where the Bash default differs.
ccc6cda3 5976
7117c2d2
JA
5977 When invoked as `sh', Bash enters POSIX mode after reading the
5978startup files.
5979
ccc6cda3
JA
5980 The following list is what's changed when `POSIX mode' is in effect:
5981
5982 1. When a command in the hash table no longer exists, Bash will
5983 re-search `$PATH' to find the new location. This is also
5984 available with `shopt -s checkhash'.
5985
28ef6c31
JA
5986 2. The message printed by the job control code and builtins when a job
5987 exits with a non-zero status is `Done(status)'.
ccc6cda3
JA
5988
5989 3. The message printed by the job control code and builtins when a job
28ef6c31
JA
5990 is stopped is `Stopped(SIGNAME)', where SIGNAME is, for example,
5991 `SIGTSTP'.
ccc6cda3 5992
1c72c0cd
CR
5993 4. The `bg' builtin uses the required format to describe each job
5994 placed in the background, which does not include an indication of
5995 whether the job is the current or previous job.
5996
5997 5. Reserved words appearing in a context where reserved words are
3ee6b87d 5998 recognized do not undergo alias expansion.
ccc6cda3 5999
ac18b312
CR
6000 6. The POSIX `PS1' and `PS2' expansions of `!' to the history number
6001 and `!!' to `!' are enabled, and parameter expansion is performed
6002 on the values of `PS1' and `PS2' regardless of the setting of the
6003 `promptvars' option.
ccc6cda3 6004
ac18b312
CR
6005 7. The POSIX startup files are executed (`$ENV') rather than the
6006 normal Bash files.
ccc6cda3 6007
1c72c0cd 6008 8. Tilde expansion is only performed on assignments preceding a
ccc6cda3
JA
6009 command name, rather than on all assignment statements on the line.
6010
122f603c
CR
6011 9. The `command' builtin does not prevent builtins that take
6012 assignment statements as arguments from expanding them as
6013 assignment statements; when not in POSIX mode, assignment builtins
6014 lose their assignment statement expansion properties when preceded
6015 by `command'.
6016
6017 10. The default history file is `~/.sh_history' (this is the default
ccc6cda3
JA
6018 value of `$HISTFILE').
6019
122f603c 6020 11. The output of `kill -l' prints all the signal names on a single
d3a24ed2
CR
6021 line, separated by spaces, without the `SIG' prefix.
6022
122f603c 6023 12. The `kill' builtin does not accept signal names with a `SIG'
d3a24ed2 6024 prefix.
ccc6cda3 6025
122f603c 6026 13. Non-interactive shells exit if FILENAME in `.' FILENAME is not
ccc6cda3
JA
6027 found.
6028
122f603c 6029 14. Non-interactive shells exit if a syntax error in an arithmetic
cce855bc
JA
6030 expansion results in an invalid expression.
6031
122f603c 6032 15. Non-interactive shells exit if there is a syntax error in a script
220537f2
CR
6033 read with the `.' or `source' builtins, or in a string processed by
6034 the `eval' builtin.
6035
122f603c 6036 16. Redirection operators do not perform filename expansion on the word
ccc6cda3
JA
6037 in the redirection unless the shell is interactive.
6038
122f603c 6039 17. Redirection operators do not perform word splitting on the word in
bb70624e
JA
6040 the redirection.
6041
122f603c 6042 18. Function names must be valid shell `name's. That is, they may not
ccc6cda3 6043 contain characters other than letters, digits, and underscores, and
cce855bc 6044 may not start with a digit. Declaring a function with an invalid
ccc6cda3
JA
6045 name causes a fatal syntax error in non-interactive shells.
6046
122f603c
CR
6047 19. Function names may not be the same as one of the POSIX special
6048 builtins.
6049
6050 20. POSIX special builtins are found before shell functions during
ac18b312 6051 command lookup.
ccc6cda3 6052
122f603c 6053 21. The `time' reserved word may be used by itself as a command. When
220537f2
CR
6054 used in this way, it displays timing statistics for the shell and
6055 its completed children. The `TIMEFORMAT' variable controls the
6056 format of the timing information.
6057
122f603c 6058 22. When parsing and expanding a ${...} expansion that appears within
220537f2
CR
6059 double quotes, single quotes are no longer special and cannot be
6060 used to quote a closing brace or other special character, unless
6061 the operator is one of those defined to perform pattern removal.
6062 In this case, they do not have to appear as matched pairs.
6063
122f603c 6064 23. The parser does not recognize `time' as a reserved word if the next
9ec5ed66
CR
6065 token begins with a `-'.
6066
122f603c 6067 24. If a POSIX special builtin returns an error status, a
ccc6cda3 6068 non-interactive shell exits. The fatal errors are those listed in
ac18b312 6069 the POSIX standard, and include things like passing incorrect
ccc6cda3
JA
6070 options, redirection errors, variable assignment errors for
6071 assignments preceding the command name, and so on.
6072
122f603c 6073 25. A non-interactive shell exits with an error status if a variable
ccc6cda3
JA
6074 assignment error occurs when no command name follows the assignment
6075 statements. A variable assignment error occurs, for example, when
cce855bc 6076 trying to assign a value to a readonly variable.
ccc6cda3 6077
122f603c 6078 26. A non-interactive shell exists with an error status if a variable
e05be32d
CR
6079 assignment error occurs in an assignment statement preceding a
6080 special builtin, but not with any other simple command.
6081
122f603c 6082 27. A non-interactive shell exits with an error status if the iteration
ccc6cda3 6083 variable in a `for' statement or the selection variable in a
cce855bc 6084 `select' statement is a readonly variable.
ccc6cda3 6085
122f603c 6086 28. Process substitution is not available.
ccc6cda3 6087
122f603c 6088 29. While variable indirection is available, it may not be applied to
74d0116b
CR
6089 the `#' and `?' special parameters.
6090
122f603c 6091 30. Assignment statements preceding POSIX special builtins persist in
ac18b312 6092 the shell environment after the builtin completes.
ccc6cda3 6093
122f603c 6094 31. Assignment statements preceding shell function calls persist in the
28ef6c31
JA
6095 shell environment after the function returns, as if a POSIX
6096 special builtin command had been executed.
6097
122f603c 6098 32. The `export' and `readonly' builtin commands display their output
ac18b312 6099 in the format required by POSIX.
d166f048 6100
122f603c 6101 33. The `trap' builtin displays signal names without the leading `SIG'.
28ef6c31 6102
122f603c 6103 34. The `trap' builtin doesn't check the first argument for a possible
d3a24ed2 6104 signal specification and revert the signal handling to the original
8a9c66f6
CR
6105 disposition if it is, unless that argument consists solely of
6106 digits and is a valid signal number. If users want to reset the
6107 handler for a given signal to the original disposition, they
6108 should use `-' as the first argument.
d3a24ed2 6109
122f603c 6110 35. The `.' and `source' builtins do not search the current directory
28ef6c31
JA
6111 for the filename argument if it is not found by searching `PATH'.
6112
122f603c 6113 36. Subshells spawned to execute command substitutions inherit the
28ef6c31
JA
6114 value of the `-e' option from the parent shell. When not in POSIX
6115 mode, Bash clears the `-e' option in such subshells.
6116
122f603c 6117 37. Alias expansion is always enabled, even in non-interactive shells.
28ef6c31 6118
122f603c 6119 38. When the `alias' builtin displays alias definitions, it does not
d3a24ed2
CR
6120 display them with a leading `alias ' unless the `-p' option is
6121 supplied.
6122
122f603c 6123 39. When the `set' builtin is invoked without options, it does not
28ef6c31
JA
6124 display shell function names and definitions.
6125
122f603c 6126 40. When the `set' builtin is invoked without options, it displays
f73dda09
JA
6127 variable values without quotes, unless they contain shell
6128 metacharacters, even if the result contains nonprinting characters.
ccc6cda3 6129
122f603c 6130 41. When the `cd' builtin is invoked in LOGICAL mode, and the pathname
7117c2d2
JA
6131 constructed from `$PWD' and the directory name supplied as an
6132 argument does not refer to an existing directory, `cd' will fail
6133 instead of falling back to PHYSICAL mode.
6134
122f603c 6135 42. The `pwd' builtin verifies that the value it prints is the same as
1c72c0cd
CR
6136 the current directory, even if it is not asked to check the file
6137 system with the `-P' option.
6138
122f603c 6139 43. When listing the history, the `fc' builtin does not include an
8a9c66f6
CR
6140 indication of whether or not a history entry has been modified.
6141
122f603c 6142 44. The default editor used by `fc' is `ed'.
8a9c66f6 6143
122f603c 6144 45. The `type' and `command' builtins will not report a non-executable
37c41ab1
CR
6145 file as having been found, though the shell will attempt to
6146 execute such a file if it is the only so-named file found in
6147 `$PATH'.
6148
122f603c 6149 46. The `vi' editing mode will invoke the `vi' editor directly when
a9fac3b2 6150 the `v' command is run, instead of checking `$VISUAL' and
1c72c0cd
CR
6151 `$EDITOR'.
6152
122f603c 6153 47. When the `xpg_echo' option is enabled, Bash does not attempt to
37c41ab1
CR
6154 interpret any arguments to `echo' as options. Each argument is
6155 displayed, after escape characters are converted.
6156
122f603c 6157 48. The `ulimit' builtin uses a block size of 512 bytes for the `-c'
09767ff0
CR
6158 and `-f' options.
6159
122f603c 6160 49. The arrival of `SIGCHLD' when a trap is set on `SIGCHLD' does not
d5362af8
CR
6161 interrupt the `wait' builtin and cause it to return immediately.
6162 The trap command is run once for each child that exits.
6163
8a9c66f6 6164
ac18b312 6165 There is other POSIX behavior that Bash does not implement by
1c72c0cd 6166default even when in POSIX mode. Specifically:
ccc6cda3 6167
1c72c0cd
CR
6168 1. The `fc' builtin checks `$EDITOR' as a program to edit history
6169 entries if `FCEDIT' is unset, rather than defaulting directly to
6170 `ed'. `fc' uses `ed' if `EDITOR' is unset.
ccc6cda3 6171
1c72c0cd
CR
6172 2. As noted above, Bash requires the `xpg_echo' option to be enabled
6173 for the `echo' builtin to be fully conformant.
28ef6c31 6174
28ef6c31 6175
1c72c0cd
CR
6176 Bash can be configured to be POSIX-conformant by default, by
6177specifying the `--enable-strict-posix-default' to `configure' when
6178building (*note Optional Features::).
28ef6c31 6179
ccc6cda3 6180\1f
c2a47ea9 6181File: bashref.info, Node: Job Control, Next: Command Line Editing, Prev: Bash Features, Up: Top
ccc6cda3 6182
37c41ab1
CR
61837 Job Control
6184*************
ccc6cda3 6185
37c41ab1
CR
6186This chapter discusses what job control is, how it works, and how Bash
6187allows you to access its facilities.
ccc6cda3
JA
6188
6189* Menu:
6190
6191* Job Control Basics:: How job control works.
6192* Job Control Builtins:: Bash builtin commands used to interact
6193 with job control.
6194* Job Control Variables:: Variables Bash uses to customize job
6195 control.
6196
6197\1f
6198File: bashref.info, Node: Job Control Basics, Next: Job Control Builtins, Up: Job Control
6199
37c41ab1
CR
62007.1 Job Control Basics
6201======================
ccc6cda3 6202
37c41ab1 6203Job control refers to the ability to selectively stop (suspend) the
ccc6cda3
JA
6204execution of processes and continue (resume) their execution at a later
6205point. A user typically employs this facility via an interactive
602bb739
CR
6206interface supplied jointly by the operating system kernel's terminal
6207driver and Bash.
ccc6cda3
JA
6208
6209 The shell associates a JOB with each pipeline. It keeps a table of
6210currently executing jobs, which may be listed with the `jobs' command.
cce855bc 6211When Bash starts a job asynchronously, it prints a line that looks like:
ccc6cda3 6212 [1] 25647
37c41ab1
CR
6213 indicating that this job is job number 1 and that the process ID of
6214the last process in the pipeline associated with this job is 25647.
6215All of the processes in a single pipeline are members of the same job.
6216Bash uses the JOB abstraction as the basis for job control.
ccc6cda3
JA
6217
6218 To facilitate the implementation of the user interface to job
bb70624e
JA
6219control, the operating system maintains the notion of a current terminal
6220process group ID. Members of this process group (processes whose
6221process group ID is equal to the current terminal process group ID)
6222receive keyboard-generated signals such as `SIGINT'. These processes
6223are said to be in the foreground. Background processes are those whose
6224process group ID differs from the terminal's; such processes are immune
6225to keyboard-generated signals. Only foreground processes are allowed
602bb739
CR
6226to read from or, if the user so specifies with `stty tostop', write to
6227the terminal. Background processes which attempt to read from (write
6228to when `stty tostop' is in effect) the terminal are sent a `SIGTTIN'
6229(`SIGTTOU') signal by the kernel's terminal driver, which, unless
6230caught, suspends the process.
ccc6cda3
JA
6231
6232 If the operating system on which Bash is running supports job
cce855bc
JA
6233control, Bash contains facilities to use it. Typing the SUSPEND
6234character (typically `^Z', Control-Z) while a process is running causes
6235that process to be stopped and returns control to Bash. Typing the
6236DELAYED SUSPEND character (typically `^Y', Control-Y) causes the
6237process to be stopped when it attempts to read input from the terminal,
6238and control to be returned to Bash. The user then manipulates the
6239state of this job, using the `bg' command to continue it in the
6240background, the `fg' command to continue it in the foreground, or the
6241`kill' command to kill it. A `^Z' takes effect immediately, and has
6242the additional side effect of causing pending output and typeahead to
6243be discarded.
ccc6cda3
JA
6244
6245 There are a number of ways to refer to a job in the shell. The
a9fac3b2 6246character `%' introduces a job specification (JOBSPEC).
bb70624e
JA
6247
6248 Job number `n' may be referred to as `%n'. The symbols `%%' and
6249`%+' refer to the shell's notion of the current job, which is the last
eb2bb562
CR
6250job stopped while it was in the foreground or started in the background.
6251A single `%' (with no accompanying job specification) also refers to
09767ff0
CR
6252the current job. The previous job may be referenced using `%-'. If
6253there is only a single job, `%+' and `%-' can both be used to refer to
6254that job. In output pertaining to jobs (e.g., the output of the `jobs'
6255command), the current job is always flagged with a `+', and the
6256previous job with a `-'.
bb70624e
JA
6257
6258 A job may also be referred to using a prefix of the name used to
6259start it, or using a substring that appears in its command line. For
122f603c
CR
6260example, `%ce' refers to a stopped `ce' job. Using `%?ce', on the
6261other hand, refers to any job containing the string `ce' in its command
6262line. If the prefix or substring matches more than one job, Bash
6263reports an error.
ccc6cda3
JA
6264
6265 Simply naming a job can be used to bring it into the foreground:
6266`%1' is a synonym for `fg %1', bringing job 1 from the background into
6267the foreground. Similarly, `%1 &' resumes job 1 in the background,
6268equivalent to `bg %1'
6269
6270 The shell learns immediately whenever a job changes state.
6271Normally, Bash waits until it is about to print a prompt before
6272reporting changes in a job's status so as to not interrupt any other
f73dda09
JA
6273output. If the `-b' option to the `set' builtin is enabled, Bash
6274reports such changes immediately (*note The Set Builtin::). Any trap
6275on `SIGCHLD' is executed for each child process that exits.
ccc6cda3 6276
d3ad40de 6277 If an attempt to exit Bash is made while jobs are stopped, (or
6a8fd0ed 6278running, if the `checkjobs' option is enabled - see *note The Shopt
d3ad40de
CR
6279Builtin::), the shell prints a warning message, and if the `checkjobs'
6280option is enabled, lists the jobs and their statuses. The `jobs'
cce855bc
JA
6281command may then be used to inspect their status. If a second attempt
6282to exit is made without an intervening command, Bash does not print
d3ad40de 6283another warning, and any stopped jobs are terminated.
ccc6cda3
JA
6284
6285\1f
6286File: bashref.info, Node: Job Control Builtins, Next: Job Control Variables, Prev: Job Control Basics, Up: Job Control
6287
37c41ab1
CR
62887.2 Job Control Builtins
6289========================
ccc6cda3
JA
6290
6291`bg'
37c41ab1 6292 bg [JOBSPEC ...]
122f603c 6293
37c41ab1 6294 Resume each suspended job JOBSPEC in the background, as if it had
cce855bc
JA
6295 been started with `&'. If JOBSPEC is not supplied, the current
6296 job is used. The return status is zero unless it is run when job
1c72c0cd
CR
6297 control is not enabled, or, when run with job control enabled, any
6298 JOBSPEC was not found or specifies a job that was started without
6299 job control.
ccc6cda3
JA
6300
6301`fg'
6302 fg [JOBSPEC]
122f603c 6303
cce855bc
JA
6304 Resume the job JOBSPEC in the foreground and make it the current
6305 job. If JOBSPEC is not supplied, the current job is used. The
6306 return status is that of the command placed into the foreground,
6307 or non-zero if run when job control is disabled or, when run with
6308 job control enabled, JOBSPEC does not specify a valid job or
6309 JOBSPEC specifies a job that was started without job control.
ccc6cda3
JA
6310
6311`jobs'
bb70624e 6312 jobs [-lnprs] [JOBSPEC]
cce855bc 6313 jobs -x COMMAND [ARGUMENTS]
ccc6cda3
JA
6314
6315 The first form lists the active jobs. The options have the
6316 following meanings:
6317
6318 `-l'
cce855bc 6319 List process IDs in addition to the normal information.
ccc6cda3
JA
6320
6321 `-n'
6322 Display information only about jobs that have changed status
cce855bc 6323 since the user was last notified of their status.
ccc6cda3
JA
6324
6325 `-p'
6326 List only the process ID of the job's process group leader.
6327
6328 `-r'
122f603c 6329 Display only running jobs.
ccc6cda3
JA
6330
6331 `-s'
122f603c 6332 Display only stopped jobs.
ccc6cda3
JA
6333
6334 If JOBSPEC is given, output is restricted to information about
6335 that job. If JOBSPEC is not supplied, the status of all jobs is
6336 listed.
6337
6338 If the `-x' option is supplied, `jobs' replaces any JOBSPEC found
6339 in COMMAND or ARGUMENTS with the corresponding process group ID,
6340 and executes COMMAND, passing it ARGUMENTs, returning its exit
6341 status.
6342
6343`kill'
cce855bc
JA
6344 kill [-s SIGSPEC] [-n SIGNUM] [-SIGSPEC] JOBSPEC or PID
6345 kill -l [EXIT_STATUS]
122f603c 6346
ccc6cda3 6347 Send a signal specified by SIGSPEC or SIGNUM to the process named
cce855bc 6348 by job specification JOBSPEC or process ID PID. SIGSPEC is either
9f422431
CR
6349 a case-insensitive signal name such as `SIGINT' (with or without
6350 the `SIG' prefix) or a signal number; SIGNUM is a signal number.
6351 If SIGSPEC and SIGNUM are not present, `SIGTERM' is used. The
6352 `-l' option lists the signal names. If any arguments are supplied
6353 when `-l' is given, the names of the signals corresponding to the
6354 arguments are listed, and the return status is zero. EXIT_STATUS
6355 is a number specifying a signal number or the exit status of a
6356 process terminated by a signal. The return status is zero if at
6357 least one signal was successfully sent, or non-zero if an error
6358 occurs or an invalid option is encountered.
ccc6cda3
JA
6359
6360`wait'
eb2bb562 6361 wait [JOBSPEC or PID ...]
122f603c 6362
eb2bb562
CR
6363 Wait until the child process specified by each process ID PID or
6364 job specification JOBSPEC exits and return the exit status of the
6365 last command waited for. If a job spec is given, all processes in
6366 the job are waited for. If no arguments are given, all currently
cce855bc
JA
6367 active child processes are waited for, and the return status is
6368 zero. If neither JOBSPEC nor PID specifies an active child process
6369 of the shell, the return status is 127.
ccc6cda3
JA
6370
6371`disown'
cce855bc 6372 disown [-ar] [-h] [JOBSPEC ...]
122f603c
CR
6373
6374 Without options, remove each JOBSPEC from the table of active jobs.
6375 If the `-h' option is given, the job is not removed from the table,
6376 but is marked so that `SIGHUP' is not sent to the job if the shell
6377 receives a `SIGHUP'. If JOBSPEC is not present, and neither the
6378 `-a' nor `-r' option is supplied, the current job is used. If no
6379 JOBSPEC is supplied, the `-a' option means to remove or mark all
6380 jobs; the `-r' option without a JOBSPEC argument restricts
6381 operation to running jobs.
ccc6cda3
JA
6382
6383`suspend'
6384 suspend [-f]
122f603c 6385
ccc6cda3 6386 Suspend the execution of this shell until it receives a `SIGCONT'
09767ff0
CR
6387 signal. A login shell cannot be suspended; the `-f' option can be
6388 used to override this and force the suspension.
ccc6cda3
JA
6389
6390 When job control is not active, the `kill' and `wait' builtins do
6391not accept JOBSPEC arguments. They must be supplied process IDs.
6392
6393\1f
6394File: bashref.info, Node: Job Control Variables, Prev: Job Control Builtins, Up: Job Control
6395
37c41ab1
CR
63967.3 Job Control Variables
6397=========================
ccc6cda3
JA
6398
6399`auto_resume'
6400 This variable controls how the shell interacts with the user and
6401 job control. If this variable exists then single word simple
cce855bc
JA
6402 commands without redirections are treated as candidates for
6403 resumption of an existing job. There is no ambiguity allowed; if
6404 there is more than one job beginning with the string typed, then
6405 the most recently accessed job will be selected. The name of a
6406 stopped job, in this context, is the command line used to start
6407 it. If this variable is set to the value `exact', the string
6408 supplied must match the name of a stopped job exactly; if set to
ccc6cda3
JA
6409 `substring', the string supplied needs to match a substring of the
6410 name of a stopped job. The `substring' value provides
6411 functionality analogous to the `%?' job ID (*note Job Control
28ef6c31
JA
6412 Basics::). If set to any other value, the supplied string must be
6413 a prefix of a stopped job's name; this provides functionality
ccc6cda3
JA
6414 analogous to the `%' job ID.
6415
761783bf 6416
ccc6cda3 6417\1f
c2a47ea9 6418File: bashref.info, Node: Command Line Editing, Next: Using History Interactively, Prev: Job Control, Up: Top
ccc6cda3 6419
37c41ab1
CR
64208 Command Line Editing
6421**********************
ccc6cda3 6422
37c41ab1 6423This chapter describes the basic features of the GNU command line
bb70624e
JA
6424editing interface. Command line editing is provided by the Readline
6425library, which is used by several different programs, including Bash.
a9fac3b2
CR
6426Command line editing is enabled by default when using an interactive
6427shell, unless the `--noediting' option is supplied at shell invocation.
6428Line editing is also used when using the `-e' option to the `read'
6429builtin command (*note Bash Builtins::). By default, the line editing
e05be32d 6430commands are similar to those of Emacs. A vi-style line editing
a9fac3b2
CR
6431interface is also available. Line editing can be enabled at any time
6432using the `-o emacs' or `-o vi' options to the `set' builtin command
6433(*note The Set Builtin::), or disabled using the `+o emacs' or `+o vi'
6434options to `set'.
ccc6cda3
JA
6435
6436* Menu:
6437
bb70624e
JA
6438* Introduction and Notation:: Notation used in this text.
6439* Readline Interaction:: The minimum set of commands for editing a line.
6440* Readline Init File:: Customizing Readline from a user's view.
6441* Bindable Readline Commands:: A description of most of the Readline commands
6442 available for binding
6443* Readline vi Mode:: A short description of how to make Readline
6444 behave like the vi editor.
6445
6446* Programmable Completion:: How to specify the possible completions for
6447 a specific command.
6448* Programmable Completion Builtins:: Builtin commands to specify how to
6449 complete arguments for a particular command.
ccc6cda3
JA
6450
6451\1f
bb70624e 6452File: bashref.info, Node: Introduction and Notation, Next: Readline Interaction, Up: Command Line Editing
ccc6cda3 6453
37c41ab1
CR
64548.1 Introduction to Line Editing
6455================================
ccc6cda3 6456
37c41ab1 6457The following paragraphs describe the notation used to represent
bb70624e 6458keystrokes.
ccc6cda3 6459
28ef6c31 6460 The text `C-k' is read as `Control-K' and describes the character
bb70624e 6461produced when the <k> key is pressed while the Control key is depressed.
ccc6cda3 6462
28ef6c31 6463 The text `M-k' is read as `Meta-K' and describes the character
bb70624e
JA
6464produced when the Meta key (if you have one) is depressed, and the <k>
6465key is pressed. The Meta key is labeled <ALT> on many keyboards. On
6466keyboards with two keys labeled <ALT> (usually to either side of the
6467space bar), the <ALT> on the left side is generally set to work as a
6468Meta key. The <ALT> key on the right may also be configured to work as
6469a Meta key or may be configured as some other modifier, such as a
6470Compose key for typing accented characters.
6471
6472 If you do not have a Meta or <ALT> key, or another key working as a
6473Meta key, the identical keystroke can be generated by typing <ESC>
28ef6c31
JA
6474_first_, and then typing <k>. Either process is known as "metafying"
6475the <k> key.
bb70624e 6476
28ef6c31
JA
6477 The text `M-C-k' is read as `Meta-Control-k' and describes the
6478character produced by "metafying" `C-k'.
bb70624e
JA
6479
6480 In addition, several keys have their own names. Specifically,
6481<DEL>, <ESC>, <LFD>, <SPC>, <RET>, and <TAB> all stand for themselves
28ef6c31
JA
6482when seen in this text, or in an init file (*note Readline Init File::).
6483If your keyboard lacks a <LFD> key, typing <C-j> will produce the
6484desired character. The <RET> key may be labeled <Return> or <Enter> on
6485some keyboards.
ccc6cda3
JA
6486
6487\1f
bb70624e 6488File: bashref.info, Node: Readline Interaction, Next: Readline Init File, Prev: Introduction and Notation, Up: Command Line Editing
cce855bc 6489
37c41ab1
CR
64908.2 Readline Interaction
6491========================
cce855bc 6492
37c41ab1 6493Often during an interactive session you type in a long line of text,
bb70624e
JA
6494only to notice that the first word on the line is misspelled. The
6495Readline library gives you a set of commands for manipulating the text
6496as you type it in, allowing you to just fix your typo, and not forcing
6497you to retype the majority of the line. Using these editing commands,
6498you move the cursor to the place that needs correction, and delete or
6499insert the text of the corrections. Then, when you are satisfied with
28ef6c31
JA
6500the line, you simply press <RET>. You do not have to be at the end of
6501the line to press <RET>; the entire line is accepted regardless of the
6502location of the cursor within the line.
cce855bc 6503
bb70624e 6504* Menu:
cce855bc 6505
bb70624e
JA
6506* Readline Bare Essentials:: The least you need to know about Readline.
6507* Readline Movement Commands:: Moving about the input line.
6508* Readline Killing Commands:: How to delete text, and how to get it back!
6509* Readline Arguments:: Giving numeric arguments to commands.
6510* Searching:: Searching through previous lines.
cce855bc 6511
bb70624e
JA
6512\1f
6513File: bashref.info, Node: Readline Bare Essentials, Next: Readline Movement Commands, Up: Readline Interaction
cce855bc 6514
37c41ab1
CR
65158.2.1 Readline Bare Essentials
6516------------------------------
cce855bc 6517
37c41ab1
CR
6518In order to enter characters into the line, simply type them. The typed
6519character appears where the cursor was, and then the cursor moves one
6520space to the right. If you mistype a character, you can use your erase
6521character to back up and delete the mistyped character.
cce855bc 6522
bb70624e
JA
6523 Sometimes you may mistype a character, and not notice the error
6524until you have typed several other characters. In that case, you can
28ef6c31
JA
6525type `C-b' to move the cursor to the left, and then correct your
6526mistake. Afterwards, you can move the cursor to the right with `C-f'.
cce855bc 6527
bb70624e
JA
6528 When you add text in the middle of a line, you will notice that
6529characters to the right of the cursor are `pushed over' to make room
6530for the text that you have inserted. Likewise, when you delete text
6531behind the cursor, characters to the right of the cursor are `pulled
6532back' to fill in the blank space created by the removal of the text. A
6533list of the bare essentials for editing the text of an input line
6534follows.
cce855bc 6535
28ef6c31 6536`C-b'
bb70624e 6537 Move back one character.
cce855bc 6538
28ef6c31 6539`C-f'
bb70624e 6540 Move forward one character.
cce855bc 6541
bb70624e
JA
6542<DEL> or <Backspace>
6543 Delete the character to the left of the cursor.
cce855bc 6544
28ef6c31 6545`C-d'
bb70624e 6546 Delete the character underneath the cursor.
cce855bc 6547
bb70624e
JA
6548Printing characters
6549 Insert the character into the line at the cursor.
cce855bc 6550
28ef6c31 6551`C-_' or `C-x C-u'
bb70624e
JA
6552 Undo the last editing command. You can undo all the way back to an
6553 empty line.
cce855bc 6554
bb70624e
JA
6555(Depending on your configuration, the <Backspace> key be set to delete
6556the character to the left of the cursor and the <DEL> key set to delete
28ef6c31 6557the character underneath the cursor, like `C-d', rather than the
bb70624e 6558character to the left of the cursor.)
cce855bc
JA
6559
6560\1f
bb70624e 6561File: bashref.info, Node: Readline Movement Commands, Next: Readline Killing Commands, Prev: Readline Bare Essentials, Up: Readline Interaction
ccc6cda3 6562
37c41ab1
CR
65638.2.2 Readline Movement Commands
6564--------------------------------
ccc6cda3 6565
37c41ab1 6566The above table describes the most basic keystrokes that you need in
bb70624e 6567order to do editing of the input line. For your convenience, many
28ef6c31 6568other commands have been added in addition to `C-b', `C-f', `C-d', and
bb70624e 6569<DEL>. Here are some commands for moving more rapidly about the line.
ccc6cda3 6570
28ef6c31 6571`C-a'
bb70624e 6572 Move to the start of the line.
ccc6cda3 6573
28ef6c31 6574`C-e'
bb70624e 6575 Move to the end of the line.
ccc6cda3 6576
28ef6c31 6577`M-f'
bb70624e
JA
6578 Move forward a word, where a word is composed of letters and
6579 digits.
ccc6cda3 6580
28ef6c31 6581`M-b'
bb70624e 6582 Move backward a word.
ccc6cda3 6583
28ef6c31 6584`C-l'
bb70624e 6585 Clear the screen, reprinting the current line at the top.
ccc6cda3 6586
28ef6c31 6587 Notice how `C-f' moves forward a character, while `M-f' moves
bb70624e
JA
6588forward a word. It is a loose convention that control keystrokes
6589operate on characters while meta keystrokes operate on words.
ccc6cda3
JA
6590
6591\1f
bb70624e 6592File: bashref.info, Node: Readline Killing Commands, Next: Readline Arguments, Prev: Readline Movement Commands, Up: Readline Interaction
ccc6cda3 6593
37c41ab1
CR
65948.2.3 Readline Killing Commands
6595-------------------------------
ccc6cda3 6596
37c41ab1
CR
6597"Killing" text means to delete the text from the line, but to save it
6598away for later use, usually by "yanking" (re-inserting) it back into
bb70624e
JA
6599the line. (`Cut' and `paste' are more recent jargon for `kill' and
6600`yank'.)
ccc6cda3 6601
bb70624e
JA
6602 If the description for a command says that it `kills' text, then you
6603can be sure that you can get the text back in a different (or the same)
6604place later.
ccc6cda3 6605
bb70624e
JA
6606 When you use a kill command, the text is saved in a "kill-ring".
6607Any number of consecutive kills save all of the killed text together, so
6608that when you yank it back, you get it all. The kill ring is not line
6609specific; the text that you killed on a previously typed line is
37c41ab1 6610available to be yanked back later, when you are typing another line.
ccc6cda3 6611
bb70624e 6612 Here is the list of commands for killing text.
ccc6cda3 6613
28ef6c31 6614`C-k'
bb70624e
JA
6615 Kill the text from the current cursor position to the end of the
6616 line.
ccc6cda3 6617
28ef6c31 6618`M-d'
bb70624e
JA
6619 Kill from the cursor to the end of the current word, or, if between
6620 words, to the end of the next word. Word boundaries are the same
28ef6c31 6621 as those used by `M-f'.
ccc6cda3 6622
28ef6c31 6623`M-<DEL>'
f73dda09 6624 Kill from the cursor the start of the current word, or, if between
bb70624e 6625 words, to the start of the previous word. Word boundaries are the
28ef6c31 6626 same as those used by `M-b'.
ccc6cda3 6627
28ef6c31 6628`C-w'
ccc6cda3 6629 Kill from the cursor to the previous whitespace. This is
28ef6c31 6630 different than `M-<DEL>' because the word boundaries differ.
ccc6cda3 6631
761783bf 6632
cce855bc
JA
6633 Here is how to "yank" the text back into the line. Yanking means to
6634copy the most-recently-killed text from the kill buffer.
ccc6cda3 6635
28ef6c31 6636`C-y'
ccc6cda3
JA
6637 Yank the most recently killed text back into the buffer at the
6638 cursor.
6639
28ef6c31 6640`M-y'
ccc6cda3 6641 Rotate the kill-ring, and yank the new top. You can only do this
28ef6c31 6642 if the prior command is `C-y' or `M-y'.
ccc6cda3
JA
6643
6644\1f
6645File: bashref.info, Node: Readline Arguments, Next: Searching, Prev: Readline Killing Commands, Up: Readline Interaction
6646
37c41ab1
CR
66478.2.4 Readline Arguments
6648------------------------
ccc6cda3 6649
37c41ab1 6650You can pass numeric arguments to Readline commands. Sometimes the
ccc6cda3
JA
6651argument acts as a repeat count, other times it is the sign of the
6652argument that is significant. If you pass a negative argument to a
6653command which normally acts in a forward direction, that command will
6654act in a backward direction. For example, to kill text back to the
6655start of the line, you might type `M-- C-k'.
6656
6657 The general way to pass numeric arguments to a command is to type
cce855bc 6658meta digits before the command. If the first `digit' typed is a minus
bb70624e 6659sign (`-'), then the sign of the argument will be negative. Once you
cce855bc
JA
6660have typed one meta digit to get the argument started, you can type the
6661remainder of the digits, and then the command. For example, to give
28ef6c31
JA
6662the `C-d' command an argument of 10, you could type `M-1 0 C-d', which
6663will delete the next ten characters on the input line.
ccc6cda3
JA
6664
6665\1f
6666File: bashref.info, Node: Searching, Prev: Readline Arguments, Up: Readline Interaction
6667
37c41ab1
CR
66688.2.5 Searching for Commands in the History
6669-------------------------------------------
ccc6cda3 6670
37c41ab1 6671Readline provides commands for searching through the command history
28ef6c31
JA
6672(*note Bash History Facilities::) for lines containing a specified
6673string. There are two search modes: "incremental" and
6674"non-incremental".
ccc6cda3
JA
6675
6676 Incremental searches begin before the user has finished typing the
6677search string. As each character of the search string is typed,
cce855bc 6678Readline displays the next entry from the history matching the string
ccc6cda3 6679typed so far. An incremental search requires only as many characters
bb70624e 6680as needed to find the desired history entry. To search backward in the
28ef6c31 6681history for a particular string, type `C-r'. Typing `C-s' searches
bb70624e
JA
6682forward through the history. The characters present in the value of
6683the `isearch-terminators' variable are used to terminate an incremental
6684search. If that variable has not been assigned a value, the <ESC> and
28ef6c31 6685`C-J' characters will terminate an incremental search. `C-g' will
bb70624e
JA
6686abort an incremental search and restore the original line. When the
6687search is terminated, the history entry containing the search string
6688becomes the current line.
6689
28ef6c31
JA
6690 To find other matching entries in the history list, type `C-r' or
6691`C-s' as appropriate. This will search backward or forward in the
bb70624e
JA
6692history for the next entry matching the search string typed so far.
6693Any other key sequence bound to a Readline command will terminate the
6694search and execute that command. For instance, a <RET> will terminate
6695the search and accept the line, thereby executing the command from the
28ef6c31
JA
6696history list. A movement command will terminate the search, make the
6697last line found the current line, and begin editing.
ccc6cda3 6698
f73dda09
JA
6699 Readline remembers the last incremental search string. If two
6700`C-r's are typed without any intervening characters defining a new
6701search string, any remembered search string is used.
6702
ccc6cda3
JA
6703 Non-incremental searches read the entire search string before
6704starting to search for matching history lines. The search string may be
cce855bc 6705typed by the user or be part of the contents of the current line.
ccc6cda3
JA
6706
6707\1f
6708File: bashref.info, Node: Readline Init File, Next: Bindable Readline Commands, Prev: Readline Interaction, Up: Command Line Editing
6709
37c41ab1
CR
67108.3 Readline Init File
6711======================
ccc6cda3 6712
37c41ab1 6713Although the Readline library comes with a set of Emacs-like
cce855bc
JA
6714keybindings installed by default, it is possible to use a different set
6715of keybindings. Any user can customize programs that use Readline by
bb70624e
JA
6716putting commands in an "inputrc" file, conventionally in his home
6717directory. The name of this file is taken from the value of the shell
6718variable `INPUTRC'. If that variable is unset, the default is
d3ad40de
CR
6719`~/.inputrc'. If that file does not exist or cannot be read, the
6720ultimate default is `/etc/inputrc'.
ccc6cda3
JA
6721
6722 When a program which uses the Readline library starts up, the init
6723file is read, and the key bindings are set.
6724
6725 In addition, the `C-x C-r' command re-reads this init file, thus
6726incorporating any changes that you might have made to it.
6727
6728* Menu:
6729
6730* Readline Init File Syntax:: Syntax for the commands in the inputrc file.
6731
6732* Conditional Init Constructs:: Conditional key bindings in the inputrc file.
6733
6734* Sample Init File:: An example inputrc file.
6735
6736\1f
6737File: bashref.info, Node: Readline Init File Syntax, Next: Conditional Init Constructs, Up: Readline Init File
6738
37c41ab1
CR
67398.3.1 Readline Init File Syntax
6740-------------------------------
ccc6cda3 6741
37c41ab1 6742There are only a few basic constructs allowed in the Readline init
ccc6cda3
JA
6743file. Blank lines are ignored. Lines beginning with a `#' are
6744comments. Lines beginning with a `$' indicate conditional constructs
28ef6c31 6745(*note Conditional Init Constructs::). Other lines denote variable
ccc6cda3
JA
6746settings and key bindings.
6747
6748Variable Settings
cce855bc
JA
6749 You can modify the run-time behavior of Readline by altering the
6750 values of variables in Readline using the `set' command within the
28ef6c31
JA
6751 init file. The syntax is simple:
6752
6753 set VARIABLE VALUE
6754
6755 Here, for example, is how to change from the default Emacs-like
6756 key binding to use `vi' line editing commands:
ccc6cda3
JA
6757
6758 set editing-mode vi
6759
28ef6c31 6760 Variable names and values, where appropriate, are recognized
1c72c0cd
CR
6761 without regard to case. Unrecognized variable names are ignored.
6762
6763 Boolean variables (those that can be set to on or off) are set to
6764 on if the value is null or empty, ON (case-insensitive), or 1.
6765 Any other value results in the variable being set to off.
28ef6c31 6766
bb70624e
JA
6767 The `bind -V' command lists the current Readline variable names
6768 and values. *Note Bash Builtins::.
6769
cce855bc
JA
6770 A great deal of run-time behavior is changeable with the following
6771 variables.
ccc6cda3
JA
6772
6773 `bell-style'
6774 Controls what happens when Readline wants to ring the
6775 terminal bell. If set to `none', Readline never rings the
6776 bell. If set to `visible', Readline uses a visible bell if
6777 one is available. If set to `audible' (the default),
6778 Readline attempts to ring the terminal's bell.
6779
eb2bb562
CR
6780 `bind-tty-special-chars'
6781 If set to `on', Readline attempts to bind the control
6782 characters treated specially by the kernel's terminal driver
6783 to their Readline equivalents.
6784
ccc6cda3
JA
6785 `comment-begin'
6786 The string to insert at the beginning of the line when the
6787 `insert-comment' command is executed. The default value is
6788 `"#"'.
6789
eb0b2ad8
CR
6790 `completion-display-width'
6791 The number of screen columns used to display possible matches
6792 when performing completion. The value is ignored if it is
6793 less than 0 or greater than the terminal screen width. A
6794 value of 0 will cause matches to be displayed one per line.
6795 The default value is -1.
6796
cce855bc
JA
6797 `completion-ignore-case'
6798 If set to `on', Readline performs filename matching and
6799 completion in a case-insensitive fashion. The default value
6800 is `off'.
6801
220537f2
CR
6802 `completion-map-case'
6803 If set to `on', and COMPLETION-IGNORE-CASE is enabled,
6804 Readline treats hyphens (`-') and underscores (`_') as
6805 equivalent when performing case-insensitive filename matching
6806 and completion.
6807
ed35cb4a
CR
6808 `completion-prefix-display-length'
6809 The length in characters of the common prefix of a list of
6810 possible completions that is displayed without modification.
6811 When set to a value greater than zero, common prefixes longer
6812 than this value are replaced with an ellipsis when displaying
6813 possible completions.
6814
ccc6cda3
JA
6815 `completion-query-items'
6816 The number of possible completions that determines when the
d3a24ed2
CR
6817 user is asked whether the list of possibilities should be
6818 displayed. If the number of possible completions is greater
6819 than this value, Readline will ask the user whether or not he
6820 wishes to view them; otherwise, they are simply listed. This
6821 variable must be set to an integer value greater than or
1c72c0cd
CR
6822 equal to 0. A negative value means Readline should never ask.
6823 The default limit is `100'.
ccc6cda3
JA
6824
6825 `convert-meta'
6826 If set to `on', Readline will convert characters with the
cce855bc 6827 eighth bit set to an ASCII key sequence by stripping the
bb70624e 6828 eighth bit and prefixing an <ESC> character, converting them
cce855bc 6829 to a meta-prefixed key sequence. The default value is `on'.
ccc6cda3
JA
6830
6831 `disable-completion'
cce855bc 6832 If set to `On', Readline will inhibit word completion.
ccc6cda3
JA
6833 Completion characters will be inserted into the line as if
6834 they had been mapped to `self-insert'. The default is `off'.
6835
6836 `editing-mode'
cce855bc
JA
6837 The `editing-mode' variable controls which default set of key
6838 bindings is used. By default, Readline starts up in Emacs
6839 editing mode, where the keystrokes are most similar to Emacs.
6840 This variable can be set to either `emacs' or `vi'.
ccc6cda3 6841
a8fd3f3e
CR
6842 `echo-control-characters'
6843 When set to `on', on operating systems that indicate they
6844 support it, readline echoes a character corresponding to a
6845 signal generated from the keyboard. The default is `on'.
6846
ccc6cda3 6847 `enable-keypad'
cce855bc 6848 When set to `on', Readline will try to enable the application
ccc6cda3
JA
6849 keypad when it is called. Some systems need this to enable
6850 the arrow keys. The default is `off'.
6851
d5362af8
CR
6852 `enable-meta-key'
6853 When set to `on', Readline will try to enable any meta
6854 modifier key the terminal claims to support when it is
6855 called. On many terminals, the meta key is used to send
6856 eight-bit characters. The default is `on'.
6857
ccc6cda3
JA
6858 `expand-tilde'
6859 If set to `on', tilde expansion is performed when Readline
6860 attempts word completion. The default is `off'.
6861
1c72c0cd 6862 `history-preserve-point'
d7f49990
CR
6863 If set to `on', the history code attempts to place the point
6864 (the current cursor position) at the same location on each
6865 history line retrieved with `previous-history' or
6866 `next-history'. The default is `off'.
f73dda09 6867
6a8fd0ed
CR
6868 `history-size'
6869 Set the maximum number of history entries saved in the
6870 history list. If set to zero, the number of entries in the
6871 history list is not limited.
6872
ccc6cda3
JA
6873 `horizontal-scroll-mode'
6874 This variable can be set to either `on' or `off'. Setting it
cce855bc 6875 to `on' means that the text of the lines being edited will
ccc6cda3
JA
6876 scroll horizontally on a single screen line when they are
6877 longer than the width of the screen, instead of wrapping onto
6878 a new screen line. By default, this variable is set to `off'.
6879
b72432fd
JA
6880 `input-meta'
6881 If set to `on', Readline will enable eight-bit input (it will
28ef6c31 6882 not clear the eighth bit in the characters it reads),
b72432fd
JA
6883 regardless of what the terminal claims it can support. The
6884 default value is `off'. The name `meta-flag' is a synonym
6885 for this variable.
6886
6887 `isearch-terminators'
6888 The string of characters that should terminate an incremental
6889 search without subsequently executing the character as a
28ef6c31
JA
6890 command (*note Searching::). If this variable has not been
6891 given a value, the characters <ESC> and `C-J' will terminate
b72432fd
JA
6892 an incremental search.
6893
ccc6cda3
JA
6894 `keymap'
6895 Sets Readline's idea of the current keymap for key binding
6896 commands. Acceptable `keymap' names are `emacs',
28ef6c31 6897 `emacs-standard', `emacs-meta', `emacs-ctlx', `vi', `vi-move',
ccc6cda3
JA
6898 `vi-command', and `vi-insert'. `vi' is equivalent to
6899 `vi-command'; `emacs' is equivalent to `emacs-standard'. The
6900 default value is `emacs'. The value of the `editing-mode'
6901 variable also affects the default keymap.
6902
6903 `mark-directories'
6904 If set to `on', completed directory names have a slash
6905 appended. The default is `on'.
6906
6907 `mark-modified-lines'
cce855bc
JA
6908 This variable, when set to `on', causes Readline to display an
6909 asterisk (`*') at the start of history lines which have been
6910 modified. This variable is `off' by default.
ccc6cda3 6911
7117c2d2
JA
6912 `mark-symlinked-directories'
6913 If set to `on', completed names which are symbolic links to
6914 directories have a slash appended (subject to the value of
6915 `mark-directories'). The default is `off'.
6916
f73dda09
JA
6917 `match-hidden-files'
6918 This variable, when set to `on', causes Readline to match
6919 files whose names begin with a `.' (hidden files) when
eb0b2ad8
CR
6920 performing filename completion. If set to `off', the leading
6921 `.' must be supplied by the user in the filename to be
6922 completed. This variable is `on' by default.
f73dda09 6923
e05be32d
CR
6924 `menu-complete-display-prefix'
6925 If set to `on', menu completion displays the common prefix of
6926 the list of possible completions (which may be empty) before
6927 cycling through the list. The default is `off'.
6928
ccc6cda3
JA
6929 `output-meta'
6930 If set to `on', Readline will display characters with the
6931 eighth bit set directly rather than as a meta-prefixed escape
6932 sequence. The default is `off'.
6933
7117c2d2
JA
6934 `page-completions'
6935 If set to `on', Readline uses an internal `more'-like pager
6936 to display a screenful of possible completions at a time.
6937 This variable is `on' by default.
6938
cce855bc
JA
6939 `print-completions-horizontally'
6940 If set to `on', Readline will display completions with matches
6941 sorted horizontally in alphabetical order, rather than down
6942 the screen. The default is `off'.
6943
ed35cb4a
CR
6944 `revert-all-at-newline'
6945 If set to `on', Readline will undo all changes to history
6946 lines before returning when `accept-line' is executed. By
6947 default, history lines may be modified and retain individual
6948 undo lists across calls to `readline'. The default is `off'.
6949
ccc6cda3
JA
6950 `show-all-if-ambiguous'
6951 This alters the default behavior of the completion functions.
6952 If set to `on', words which have more than one possible
6953 completion cause the matches to be listed immediately instead
6954 of ringing the bell. The default value is `off'.
6955
d3a24ed2
CR
6956 `show-all-if-unmodified'
6957 This alters the default behavior of the completion functions
6958 in a fashion similar to SHOW-ALL-IF-AMBIGUOUS. If set to
6959 `on', words which have more than one possible completion
6960 without any possible partial completion (the possible
6961 completions don't share a common prefix) cause the matches to
6962 be listed immediately instead of ringing the bell. The
6963 default value is `off'.
6964
a8fd3f3e
CR
6965 `skip-completed-text'
6966 If set to `on', this alters the default completion behavior
6967 when inserting a single match into the line. It's only
6968 active when performing completion in the middle of a word.
6969 If enabled, readline does not insert characters from the
6970 completion that match characters after point in the word
6971 being completed, so portions of the word following the cursor
6972 are not duplicated. For instance, if this is enabled,
6973 attempting completion when the cursor is after the `e' in
6974 `Makefile' will result in `Makefile' rather than
6975 `Makefilefile', assuming there is a single possible
6976 completion. The default value is `off'.
6977
ccc6cda3
JA
6978 `visible-stats'
6979 If set to `on', a character denoting a file's type is
6980 appended to the filename when listing possible completions.
6981 The default is `off'.
6982
761783bf 6983
ccc6cda3
JA
6984Key Bindings
6985 The syntax for controlling key bindings in the init file is
bb70624e 6986 simple. First you need to find the name of the command that you
cce855bc
JA
6987 want to change. The following sections contain tables of the
6988 command name, the default keybinding, if any, and a short
6989 description of what the command does.
ccc6cda3 6990
28ef6c31
JA
6991 Once you know the name of the command, simply place on a line in
6992 the init file the name of the key you wish to bind the command to,
d3ad40de
CR
6993 a colon, and then the name of the command. There can be no space
6994 between the key name and the colon - that will be interpreted as
6995 part of the key name. The name of the key can be expressed in
6996 different ways, depending on what you find most comfortable.
28ef6c31
JA
6997
6998 In addition to command names, readline allows keys to be bound to
6999 a string that is inserted when the key is pressed (a MACRO).
ccc6cda3 7000
bb70624e
JA
7001 The `bind -p' command displays Readline function names and
7002 bindings in a format that can put directly into an initialization
7003 file. *Note Bash Builtins::.
7004
ccc6cda3
JA
7005 KEYNAME: FUNCTION-NAME or MACRO
7006 KEYNAME is the name of a key spelled out in English. For
7007 example:
7008 Control-u: universal-argument
7009 Meta-Rubout: backward-kill-word
7010 Control-o: "> output"
7011
28ef6c31
JA
7012 In the above example, `C-u' is bound to the function
7013 `universal-argument', `M-DEL' is bound to the function
7014 `backward-kill-word', and `C-o' is bound to run the macro
ccc6cda3
JA
7015 expressed on the right hand side (that is, to insert the text
7016 `> output' into the line).
7017
28ef6c31
JA
7018 A number of symbolic character names are recognized while
7019 processing this key binding syntax: DEL, ESC, ESCAPE, LFD,
7020 NEWLINE, RET, RETURN, RUBOUT, SPACE, SPC, and TAB.
7021
ccc6cda3
JA
7022 "KEYSEQ": FUNCTION-NAME or MACRO
7023 KEYSEQ differs from KEYNAME above in that strings denoting an
7024 entire key sequence can be specified, by placing the key
7025 sequence in double quotes. Some GNU Emacs style key escapes
7026 can be used, as in the following example, but the special
7027 character names are not recognized.
7028
7029 "\C-u": universal-argument
7030 "\C-x\C-r": re-read-init-file
7031 "\e[11~": "Function Key 1"
7032
28ef6c31 7033 In the above example, `C-u' is again bound to the function
ccc6cda3 7034 `universal-argument' (just as it was in the first example),
28ef6c31
JA
7035 `C-x C-r' is bound to the function `re-read-init-file', and
7036 `<ESC> <[> <1> <1> <~>' is bound to insert the text `Function
7037 Key 1'.
cce855bc 7038
761783bf 7039
cce855bc
JA
7040 The following GNU Emacs style escape sequences are available when
7041 specifying key sequences:
7042
7043 `\C-'
7044 control prefix
7045
7046 `\M-'
7047 meta prefix
7048
7049 `\e'
7050 an escape character
7051
7052 `\\'
7053 backslash
7054
7055 `\"'
bb70624e 7056 <">, a double quotation mark
cce855bc
JA
7057
7058 `\''
bb70624e 7059 <'>, a single quote or apostrophe
cce855bc
JA
7060
7061 In addition to the GNU Emacs style escape sequences, a second set
7062 of backslash escapes is available:
ccc6cda3 7063
cce855bc
JA
7064 `\a'
7065 alert (bell)
7066
7067 `\b'
7068 backspace
7069
7070 `\d'
7071 delete
7072
7073 `\f'
7074 form feed
7075
7076 `\n'
7077 newline
ccc6cda3 7078
cce855bc
JA
7079 `\r'
7080 carriage return
ccc6cda3 7081
cce855bc
JA
7082 `\t'
7083 horizontal tab
ccc6cda3 7084
cce855bc
JA
7085 `\v'
7086 vertical tab
ccc6cda3 7087
cce855bc 7088 `\NNN'
f73dda09 7089 the eight-bit character whose value is the octal value NNN
cce855bc 7090 (one to three digits)
ccc6cda3 7091
f73dda09
JA
7092 `\xHH'
7093 the eight-bit character whose value is the hexadecimal value
7094 HH (one or two hex digits)
7095
cce855bc
JA
7096 When entering the text of a macro, single or double quotes must be
7097 used to indicate a macro definition. Unquoted text is assumed to
7098 be a function name. In the macro body, the backslash escapes
7099 described above are expanded. Backslash will quote any other
7100 character in the macro text, including `"' and `''. For example,
7101 the following binding will make `C-x \' insert a single `\' into
7102 the line:
7103 "\C-x\\": "\\"
ccc6cda3 7104
761783bf 7105
ccc6cda3
JA
7106\1f
7107File: bashref.info, Node: Conditional Init Constructs, Next: Sample Init File, Prev: Readline Init File Syntax, Up: Readline Init File
7108
37c41ab1
CR
71098.3.2 Conditional Init Constructs
7110---------------------------------
ccc6cda3 7111
37c41ab1 7112Readline implements a facility similar in spirit to the conditional
ccc6cda3
JA
7113compilation features of the C preprocessor which allows key bindings
7114and variable settings to be performed as the result of tests. There
cce855bc 7115are four parser directives used.
ccc6cda3
JA
7116
7117`$if'
7118 The `$if' construct allows bindings to be made based on the
7119 editing mode, the terminal being used, or the application using
7120 Readline. The text of the test extends to the end of the line; no
7121 characters are required to isolate it.
7122
7123 `mode'
7124 The `mode=' form of the `$if' directive is used to test
7125 whether Readline is in `emacs' or `vi' mode. This may be
7126 used in conjunction with the `set keymap' command, for
7127 instance, to set bindings in the `emacs-standard' and
7128 `emacs-ctlx' keymaps only if Readline is starting out in
7129 `emacs' mode.
7130
7131 `term'
7132 The `term=' form may be used to include terminal-specific key
7133 bindings, perhaps to bind the key sequences output by the
7134 terminal's function keys. The word on the right side of the
cce855bc
JA
7135 `=' is tested against both the full name of the terminal and
7136 the portion of the terminal name before the first `-'. This
ccc6cda3
JA
7137 allows `sun' to match both `sun' and `sun-cmd', for instance.
7138
7139 `application'
7140 The APPLICATION construct is used to include
7141 application-specific settings. Each program using the
7142 Readline library sets the APPLICATION NAME, and you can test
28ef6c31
JA
7143 for a particular value. This could be used to bind key
7144 sequences to functions useful for a specific program. For
7145 instance, the following command adds a key sequence that
7146 quotes the current or previous word in Bash:
ccc6cda3
JA
7147 $if Bash
7148 # Quote the current or previous word
7149 "\C-xq": "\eb\"\ef\""
7150 $endif
7151
7152`$endif'
cce855bc
JA
7153 This command, as seen in the previous example, terminates an `$if'
7154 command.
ccc6cda3
JA
7155
7156`$else'
7157 Commands in this branch of the `$if' directive are executed if the
7158 test fails.
7159
cce855bc
JA
7160`$include'
7161 This directive takes a single filename as an argument and reads
28ef6c31
JA
7162 commands and bindings from that file. For example, the following
7163 directive reads from `/etc/inputrc':
cce855bc
JA
7164 $include /etc/inputrc
7165
ccc6cda3
JA
7166\1f
7167File: bashref.info, Node: Sample Init File, Prev: Conditional Init Constructs, Up: Readline Init File
7168
37c41ab1
CR
71698.3.3 Sample Init File
7170----------------------
ccc6cda3 7171
37c41ab1
CR
7172Here is an example of an INPUTRC file. This illustrates key binding,
7173variable assignment, and conditional syntax.
ccc6cda3
JA
7174
7175
7176 # This file controls the behaviour of line input editing for
7117c2d2
JA
7177 # programs that use the GNU Readline library. Existing
7178 # programs include FTP, Bash, and GDB.
ccc6cda3
JA
7179 #
7180 # You can re-read the inputrc file with C-x C-r.
7181 # Lines beginning with '#' are comments.
cce855bc 7182 #
7117c2d2
JA
7183 # First, include any systemwide bindings and variable
7184 # assignments from /etc/Inputrc
cce855bc 7185 $include /etc/Inputrc
37c41ab1 7186
ccc6cda3
JA
7187 #
7188 # Set various bindings for emacs mode.
37c41ab1 7189
ccc6cda3 7190 set editing-mode emacs
37c41ab1 7191
ccc6cda3 7192 $if mode=emacs
37c41ab1 7193
ccc6cda3 7194 Meta-Control-h: backward-kill-word Text after the function name is ignored
37c41ab1 7195
ccc6cda3
JA
7196 #
7197 # Arrow keys in keypad mode
7198 #
d166f048
JA
7199 #"\M-OD": backward-char
7200 #"\M-OC": forward-char
7201 #"\M-OA": previous-history
7202 #"\M-OB": next-history
ccc6cda3
JA
7203 #
7204 # Arrow keys in ANSI mode
7205 #
d166f048
JA
7206 "\M-[D": backward-char
7207 "\M-[C": forward-char
7208 "\M-[A": previous-history
7209 "\M-[B": next-history
ccc6cda3
JA
7210 #
7211 # Arrow keys in 8 bit keypad mode
7212 #
d166f048
JA
7213 #"\M-\C-OD": backward-char
7214 #"\M-\C-OC": forward-char
7215 #"\M-\C-OA": previous-history
7216 #"\M-\C-OB": next-history
ccc6cda3
JA
7217 #
7218 # Arrow keys in 8 bit ANSI mode
7219 #
d166f048
JA
7220 #"\M-\C-[D": backward-char
7221 #"\M-\C-[C": forward-char
7222 #"\M-\C-[A": previous-history
7223 #"\M-\C-[B": next-history
37c41ab1 7224
ccc6cda3 7225 C-q: quoted-insert
37c41ab1 7226
ccc6cda3 7227 $endif
37c41ab1 7228
ccc6cda3
JA
7229 # An old-style binding. This happens to be the default.
7230 TAB: complete
37c41ab1 7231
ccc6cda3
JA
7232 # Macros that are convenient for shell interaction
7233 $if Bash
7234 # edit the path
7235 "\C-xp": "PATH=${PATH}\e\C-e\C-a\ef\C-f"
7117c2d2
JA
7236 # prepare to type a quoted word --
7237 # insert open and close double quotes
ccc6cda3
JA
7238 # and move to just after the open quote
7239 "\C-x\"": "\"\"\C-b"
7117c2d2
JA
7240 # insert a backslash (testing backslash escapes
7241 # in sequences and macros)
ccc6cda3
JA
7242 "\C-x\\": "\\"
7243 # Quote the current or previous word
7244 "\C-xq": "\eb\"\ef\""
7245 # Add a binding to refresh the line, which is unbound
7246 "\C-xr": redraw-current-line
7247 # Edit variable on current line.
7248 "\M-\C-v": "\C-a\C-k$\C-y\M-\C-e\C-a\C-y="
7249 $endif
37c41ab1 7250
ccc6cda3
JA
7251 # use a visible bell if one is available
7252 set bell-style visible
37c41ab1 7253
ccc6cda3
JA
7254 # don't strip characters to 7 bits when reading
7255 set input-meta on
37c41ab1 7256
7117c2d2
JA
7257 # allow iso-latin1 characters to be inserted rather
7258 # than converted to prefix-meta sequences
ccc6cda3 7259 set convert-meta off
37c41ab1 7260
7117c2d2
JA
7261 # display characters with the eighth bit set directly
7262 # rather than as meta-prefixed characters
ccc6cda3 7263 set output-meta on
37c41ab1 7264
7117c2d2
JA
7265 # if there are more than 150 possible completions for
7266 # a word, ask the user if he wants to see all of them
ccc6cda3 7267 set completion-query-items 150
37c41ab1 7268
ccc6cda3
JA
7269 # For FTP
7270 $if Ftp
7271 "\C-xg": "get \M-?"
7272 "\C-xt": "put \M-?"
7273 "\M-.": yank-last-arg
7274 $endif
7275
7276\1f
bb70624e
JA
7277File: bashref.info, Node: Bindable Readline Commands, Next: Readline vi Mode, Prev: Readline Init File, Up: Command Line Editing
7278
37c41ab1
CR
72798.4 Bindable Readline Commands
7280==============================
bb70624e
JA
7281
7282* Menu:
7283
7284* Commands For Moving:: Moving about the line.
7285* Commands For History:: Getting at previous lines.
7286* Commands For Text:: Commands for changing text.
7287* Commands For Killing:: Commands for killing and yanking.
7288* Numeric Arguments:: Specifying numeric arguments, repeat counts.
7289* Commands For Completion:: Getting Readline to do the typing for you.
7290* Keyboard Macros:: Saving and re-executing typed characters
7291* Miscellaneous Commands:: Other miscellaneous commands.
7292
7293 This section describes Readline commands that may be bound to key
7294sequences. You can list your key bindings by executing `bind -P' or,
7295for a more terse format, suitable for an INPUTRC file, `bind -p'.
28ef6c31
JA
7296(*Note Bash Builtins::.) Command names without an accompanying key
7297sequence are unbound by default.
bb70624e 7298
28ef6c31
JA
7299 In the following descriptions, "point" refers to the current cursor
7300position, and "mark" refers to a cursor position saved by the
bb70624e 7301`set-mark' command. The text between the point and mark is referred to
28ef6c31 7302as the "region".
bb70624e
JA
7303
7304\1f
7305File: bashref.info, Node: Commands For Moving, Next: Commands For History, Up: Bindable Readline Commands
7306
37c41ab1
CR
73078.4.1 Commands For Moving
7308-------------------------
bb70624e
JA
7309
7310`beginning-of-line (C-a)'
7311 Move to the start of the current line.
7312
7313`end-of-line (C-e)'
7314 Move to the end of the line.
7315
7316`forward-char (C-f)'
7317 Move forward a character.
7318
7319`backward-char (C-b)'
7320 Move back a character.
7321
7322`forward-word (M-f)'
7323 Move forward to the end of the next word. Words are composed of
7324 letters and digits.
7325
7326`backward-word (M-b)'
7327 Move back to the start of the current or previous word. Words are
7328 composed of letters and digits.
7329
a9fac3b2
CR
7330`shell-forward-word ()'
7331 Move forward to the end of the next word. Words are delimited by
7332 non-quoted shell metacharacters.
7333
7334`shell-backward-word ()'
7335 Move back to the start of the current or previous word. Words are
7336 delimited by non-quoted shell metacharacters.
7337
bb70624e
JA
7338`clear-screen (C-l)'
7339 Clear the screen and redraw the current line, leaving the current
7340 line at the top of the screen.
7341
7342`redraw-current-line ()'
7343 Refresh the current line. By default, this is unbound.
7344
761783bf 7345
bb70624e
JA
7346\1f
7347File: bashref.info, Node: Commands For History, Next: Commands For Text, Prev: Commands For Moving, Up: Bindable Readline Commands
7348
37c41ab1
CR
73498.4.2 Commands For Manipulating The History
7350-------------------------------------------
bb70624e 7351
28ef6c31 7352`accept-line (Newline or Return)'
bb70624e
JA
7353 Accept the line regardless of where the cursor is. If this line is
7354 non-empty, add it to the history list according to the setting of
28ef6c31
JA
7355 the `HISTCONTROL' and `HISTIGNORE' variables. If this line is a
7356 modified history line, then restore the history line to its
7357 original state.
bb70624e
JA
7358
7359`previous-history (C-p)'
28ef6c31
JA
7360 Move `back' through the history list, fetching the previous
7361 command.
bb70624e
JA
7362
7363`next-history (C-n)'
28ef6c31 7364 Move `forward' through the history list, fetching the next command.
bb70624e
JA
7365
7366`beginning-of-history (M-<)'
7367 Move to the first line in the history.
7368
7369`end-of-history (M->)'
7370 Move to the end of the input history, i.e., the line currently
7371 being entered.
7372
7373`reverse-search-history (C-r)'
7374 Search backward starting at the current line and moving `up'
7375 through the history as necessary. This is an incremental search.
7376
7377`forward-search-history (C-s)'
7378 Search forward starting at the current line and moving `down'
7379 through the the history as necessary. This is an incremental
7380 search.
7381
7382`non-incremental-reverse-search-history (M-p)'
7383 Search backward starting at the current line and moving `up'
7384 through the history as necessary using a non-incremental search
7385 for a string supplied by the user.
7386
7387`non-incremental-forward-search-history (M-n)'
7388 Search forward starting at the current line and moving `down'
7389 through the the history as necessary using a non-incremental search
7390 for a string supplied by the user.
7391
7392`history-search-forward ()'
7393 Search forward through the history for the string of characters
74d0116b
CR
7394 between the start of the current line and the point. The search
7395 string must match at the beginning of a history line. This is a
bb70624e
JA
7396 non-incremental search. By default, this command is unbound.
7397
7398`history-search-backward ()'
7399 Search backward through the history for the string of characters
74d0116b
CR
7400 between the start of the current line and the point. The search
7401 string must match at the beginning of a history line. This is a
7402 non-incremental search. By default, this command is unbound.
7403
7404`history-substr-search-forward ()'
7405 Search forward through the history for the string of characters
7406 between the start of the current line and the point. The search
7407 string may match anywhere in a history line. This is a
7408 non-incremental search. By default, this command is unbound.
7409
7410`history-substr-search-backward ()'
7411 Search backward through the history for the string of characters
7412 between the start of the current line and the point. The search
7413 string may match anywhere in a history line. This is a
bb70624e
JA
7414 non-incremental search. By default, this command is unbound.
7415
7416`yank-nth-arg (M-C-y)'
7417 Insert the first argument to the previous command (usually the
28ef6c31
JA
7418 second word on the previous line) at point. With an argument N,
7419 insert the Nth word from the previous command (the words in the
7420 previous command begin with word 0). A negative argument inserts
eb2bb562
CR
7421 the Nth word from the end of the previous command. Once the
7422 argument N is computed, the argument is extracted as if the `!N'
7423 history expansion had been specified.
bb70624e 7424
28ef6c31 7425`yank-last-arg (M-. or M-_)'
bb70624e 7426 Insert last argument to the previous command (the last word of the
510e20a2
CR
7427 previous history entry). With a numeric argument, behave exactly
7428 like `yank-nth-arg'. Successive calls to `yank-last-arg' move
7429 back through the history list, inserting the last word (or the
7430 word specified by the argument to the first call) of each line in
7431 turn. Any numeric argument supplied to these successive calls
7432 determines the direction to move through the history. A negative
7433 argument switches the direction through the history (back or
7434 forward). The history expansion facilities are used to extract
7435 the last argument, as if the `!$' history expansion had been
7436 specified.
bb70624e 7437
761783bf 7438
bb70624e
JA
7439\1f
7440File: bashref.info, Node: Commands For Text, Next: Commands For Killing, Prev: Commands For History, Up: Bindable Readline Commands
7441
37c41ab1
CR
74428.4.3 Commands For Changing Text
7443--------------------------------
bb70624e
JA
7444
7445`delete-char (C-d)'
28ef6c31
JA
7446 Delete the character at point. If point is at the beginning of
7447 the line, there are no characters in the line, and the last
7448 character typed was not bound to `delete-char', then return EOF.
bb70624e
JA
7449
7450`backward-delete-char (Rubout)'
7451 Delete the character behind the cursor. A numeric argument means
7452 to kill the characters instead of deleting them.
7453
7454`forward-backward-delete-char ()'
7455 Delete the character under the cursor, unless the cursor is at the
7456 end of the line, in which case the character behind the cursor is
7457 deleted. By default, this is not bound to a key.
7458
28ef6c31 7459`quoted-insert (C-q or C-v)'
bb70624e 7460 Add the next character typed to the line verbatim. This is how to
28ef6c31 7461 insert key sequences like `C-q', for example.
bb70624e
JA
7462
7463`self-insert (a, b, A, 1, !, ...)'
7464 Insert yourself.
7465
7466`transpose-chars (C-t)'
7467 Drag the character before the cursor forward over the character at
7468 the cursor, moving the cursor forward as well. If the insertion
7469 point is at the end of the line, then this transposes the last two
7470 characters of the line. Negative arguments have no effect.
7471
7472`transpose-words (M-t)'
7473 Drag the word before point past the word after point, moving point
f73dda09
JA
7474 past that word as well. If the insertion point is at the end of
7475 the line, this transposes the last two words on the line.
bb70624e
JA
7476
7477`upcase-word (M-u)'
7478 Uppercase the current (or following) word. With a negative
7479 argument, uppercase the previous word, but do not move the cursor.
7480
7481`downcase-word (M-l)'
7482 Lowercase the current (or following) word. With a negative
7483 argument, lowercase the previous word, but do not move the cursor.
7484
7485`capitalize-word (M-c)'
7486 Capitalize the current (or following) word. With a negative
7487 argument, capitalize the previous word, but do not move the cursor.
7488
7117c2d2
JA
7489`overwrite-mode ()'
7490 Toggle overwrite mode. With an explicit positive numeric argument,
7491 switches to overwrite mode. With an explicit non-positive numeric
7492 argument, switches to insert mode. This command affects only
7493 `emacs' mode; `vi' mode does overwrite differently. Each call to
7494 `readline()' starts in insert mode.
7495
7496 In overwrite mode, characters bound to `self-insert' replace the
7497 text at point rather than pushing the text to the right.
7498 Characters bound to `backward-delete-char' replace the character
7499 before point with a space.
7500
7501 By default, this command is unbound.
7502
761783bf 7503
bb70624e
JA
7504\1f
7505File: bashref.info, Node: Commands For Killing, Next: Numeric Arguments, Prev: Commands For Text, Up: Bindable Readline Commands
7506
37c41ab1
CR
75078.4.4 Killing And Yanking
7508-------------------------
bb70624e
JA
7509
7510`kill-line (C-k)'
7511 Kill the text from point to the end of the line.
7512
7513`backward-kill-line (C-x Rubout)'
7514 Kill backward to the beginning of the line.
7515
7516`unix-line-discard (C-u)'
7517 Kill backward from the cursor to the beginning of the current line.
7518
7519`kill-whole-line ()'
28ef6c31
JA
7520 Kill all characters on the current line, no matter where point is.
7521 By default, this is unbound.
bb70624e
JA
7522
7523`kill-word (M-d)'
7524 Kill from point to the end of the current word, or if between
7525 words, to the end of the next word. Word boundaries are the same
7526 as `forward-word'.
7527
28ef6c31 7528`backward-kill-word (M-<DEL>)'
bb70624e
JA
7529 Kill the word behind point. Word boundaries are the same as
7530 `backward-word'.
7531
a9fac3b2
CR
7532`shell-kill-word ()'
7533 Kill from point to the end of the current word, or if between
7534 words, to the end of the next word. Word boundaries are the same
7535 as `shell-forward-word'.
7536
06dff54a 7537`shell-backward-kill-word ()'
a9fac3b2
CR
7538 Kill the word behind point. Word boundaries are the same as
7539 `shell-backward-word'.
7540
bb70624e
JA
7541`unix-word-rubout (C-w)'
7542 Kill the word behind point, using white space as a word boundary.
7543 The killed text is saved on the kill-ring.
7544
113d85a4
CR
7545`unix-filename-rubout ()'
7546 Kill the word behind point, using white space and the slash
7547 character as the word boundaries. The killed text is saved on the
7548 kill-ring.
7549
bb70624e
JA
7550`delete-horizontal-space ()'
7551 Delete all spaces and tabs around point. By default, this is
7552 unbound.
7553
7554`kill-region ()'
7555 Kill the text in the current region. By default, this command is
7556 unbound.
7557
7558`copy-region-as-kill ()'
7559 Copy the text in the region to the kill buffer, so it can be yanked
7560 right away. By default, this command is unbound.
7561
7562`copy-backward-word ()'
7563 Copy the word before point to the kill buffer. The word
7564 boundaries are the same as `backward-word'. By default, this
7565 command is unbound.
7566
7567`copy-forward-word ()'
7568 Copy the word following point to the kill buffer. The word
7569 boundaries are the same as `forward-word'. By default, this
7570 command is unbound.
7571
7572`yank (C-y)'
28ef6c31 7573 Yank the top of the kill ring into the buffer at point.
bb70624e
JA
7574
7575`yank-pop (M-y)'
7576 Rotate the kill-ring, and yank the new top. You can only do this
28ef6c31 7577 if the prior command is `yank' or `yank-pop'.
bb70624e
JA
7578
7579\1f
7580File: bashref.info, Node: Numeric Arguments, Next: Commands For Completion, Prev: Commands For Killing, Up: Bindable Readline Commands
7581
37c41ab1
CR
75828.4.5 Specifying Numeric Arguments
7583----------------------------------
bb70624e
JA
7584
7585`digit-argument (M-0, M-1, ... M--)'
7586 Add this digit to the argument already accumulating, or start a new
28ef6c31 7587 argument. `M--' starts a negative argument.
bb70624e
JA
7588
7589`universal-argument ()'
7590 This is another way to specify an argument. If this command is
7591 followed by one or more digits, optionally with a leading minus
7592 sign, those digits define the argument. If the command is
7593 followed by digits, executing `universal-argument' again ends the
7594 numeric argument, but is otherwise ignored. As a special case, if
7595 this command is immediately followed by a character that is
7596 neither a digit or minus sign, the argument count for the next
7597 command is multiplied by four. The argument count is initially
7598 one, so executing this function the first time makes the argument
7599 count four, a second time makes the argument count sixteen, and so
7600 on. By default, this is not bound to a key.
7601
7602\1f
7603File: bashref.info, Node: Commands For Completion, Next: Keyboard Macros, Prev: Numeric Arguments, Up: Bindable Readline Commands
7604
37c41ab1
CR
76058.4.6 Letting Readline Type For You
7606-----------------------------------
bb70624e 7607
28ef6c31
JA
7608`complete (<TAB>)'
7609 Attempt to perform completion on the text before point. The
7610 actual completion performed is application-specific. Bash
7611 attempts completion treating the text as a variable (if the text
7612 begins with `$'), username (if the text begins with `~'), hostname
7613 (if the text begins with `@'), or command (including aliases and
7614 functions) in turn. If none of these produces a match, filename
7615 completion is attempted.
bb70624e
JA
7616
7617`possible-completions (M-?)'
eb0b2ad8
CR
7618 List the possible completions of the text before point. When
7619 displaying completions, Readline sets the number of columns used
7620 for display to the value of `completion-display-width', the value
7621 of the environment variable `COLUMNS', or the screen width, in
7622 that order.
bb70624e
JA
7623
7624`insert-completions (M-*)'
7625 Insert all completions of the text before point that would have
7626 been generated by `possible-completions'.
7627
7628`menu-complete ()'
7629 Similar to `complete', but replaces the word to be completed with
7630 a single match from the list of possible completions. Repeated
7631 execution of `menu-complete' steps through the list of possible
7632 completions, inserting each match in turn. At the end of the list
28ef6c31
JA
7633 of completions, the bell is rung (subject to the setting of
7634 `bell-style') and the original text is restored. An argument of N
7635 moves N positions forward in the list of matches; a negative
7636 argument may be used to move backward through the list. This
7637 command is intended to be bound to <TAB>, but is unbound by
bb70624e
JA
7638 default.
7639
3eb2d94a
CR
7640`menu-complete-backward ()'
7641 Identical to `menu-complete', but moves backward through the list
7642 of possible completions, as if `menu-complete' had been given a
7643 negative argument.
7644
bb70624e
JA
7645`delete-char-or-list ()'
7646 Deletes the character under the cursor if not at the beginning or
7647 end of the line (like `delete-char'). If at the end of the line,
7648 behaves identically to `possible-completions'. This command is
7649 unbound by default.
7650
7651`complete-filename (M-/)'
7652 Attempt filename completion on the text before point.
7653
7654`possible-filename-completions (C-x /)'
7655 List the possible completions of the text before point, treating
7656 it as a filename.
7657
7658`complete-username (M-~)'
7659 Attempt completion on the text before point, treating it as a
7660 username.
7661
7662`possible-username-completions (C-x ~)'
7663 List the possible completions of the text before point, treating
7664 it as a username.
7665
7666`complete-variable (M-$)'
7667 Attempt completion on the text before point, treating it as a
7668 shell variable.
7669
7670`possible-variable-completions (C-x $)'
7671 List the possible completions of the text before point, treating
7672 it as a shell variable.
7673
7674`complete-hostname (M-@)'
7675 Attempt completion on the text before point, treating it as a
7676 hostname.
7677
7678`possible-hostname-completions (C-x @)'
7679 List the possible completions of the text before point, treating
7680 it as a hostname.
7681
7682`complete-command (M-!)'
7683 Attempt completion on the text before point, treating it as a
7684 command name. Command completion attempts to match the text
7685 against aliases, reserved words, shell functions, shell builtins,
7686 and finally executable filenames, in that order.
7687
7688`possible-command-completions (C-x !)'
7689 List the possible completions of the text before point, treating
7690 it as a command name.
7691
28ef6c31 7692`dynamic-complete-history (M-<TAB>)'
bb70624e
JA
7693 Attempt completion on the text before point, comparing the text
7694 against lines from the history list for possible completion
7695 matches.
7696
ed35cb4a
CR
7697`dabbrev-expand ()'
7698 Attempt menu completion on the text before point, comparing the
7699 text against lines from the history list for possible completion
7700 matches.
7701
bb70624e
JA
7702`complete-into-braces (M-{)'
7703 Perform filename completion and insert the list of possible
7704 completions enclosed within braces so the list is available to the
28ef6c31 7705 shell (*note Brace Expansion::).
bb70624e 7706
761783bf 7707
bb70624e
JA
7708\1f
7709File: bashref.info, Node: Keyboard Macros, Next: Miscellaneous Commands, Prev: Commands For Completion, Up: Bindable Readline Commands
7710
37c41ab1
CR
77118.4.7 Keyboard Macros
7712---------------------
bb70624e
JA
7713
7714`start-kbd-macro (C-x ()'
7715 Begin saving the characters typed into the current keyboard macro.
7716
7717`end-kbd-macro (C-x ))'
7718 Stop saving the characters typed into the current keyboard macro
7719 and save the definition.
7720
7721`call-last-kbd-macro (C-x e)'
7722 Re-execute the last keyboard macro defined, by making the
7723 characters in the macro appear as if typed at the keyboard.
7724
761783bf 7725
bb70624e
JA
7726\1f
7727File: bashref.info, Node: Miscellaneous Commands, Prev: Keyboard Macros, Up: Bindable Readline Commands
7728
37c41ab1
CR
77298.4.8 Some Miscellaneous Commands
7730---------------------------------
bb70624e
JA
7731
7732`re-read-init-file (C-x C-r)'
7733 Read in the contents of the INPUTRC file, and incorporate any
7734 bindings or variable assignments found there.
7735
7736`abort (C-g)'
7737 Abort the current editing command and ring the terminal's bell
7738 (subject to the setting of `bell-style').
7739
7740`do-uppercase-version (M-a, M-b, M-X, ...)'
7741 If the metafied character X is lowercase, run the command that is
7742 bound to the corresponding uppercase character.
7743
28ef6c31
JA
7744`prefix-meta (<ESC>)'
7745 Metafy the next character typed. This is for keyboards without a
7746 meta key. Typing `<ESC> f' is equivalent to typing `M-f'.
bb70624e 7747
28ef6c31 7748`undo (C-_ or C-x C-u)'
bb70624e
JA
7749 Incremental undo, separately remembered for each line.
7750
7751`revert-line (M-r)'
7752 Undo all changes made to this line. This is like executing the
7753 `undo' command enough times to get back to the beginning.
7754
7755`tilde-expand (M-&)'
7756 Perform tilde expansion on the current word.
7757
7758`set-mark (C-@)'
28ef6c31
JA
7759 Set the mark to the point. If a numeric argument is supplied, the
7760 mark is set to that position.
bb70624e
JA
7761
7762`exchange-point-and-mark (C-x C-x)'
7763 Swap the point with the mark. The current cursor position is set
7764 to the saved position, and the old cursor position is saved as the
7765 mark.
7766
7767`character-search (C-])'
7768 A character is read and point is moved to the next occurrence of
7769 that character. A negative count searches for previous
7770 occurrences.
7771
7772`character-search-backward (M-C-])'
7773 A character is read and point is moved to the previous occurrence
7774 of that character. A negative count searches for subsequent
7775 occurrences.
7776
8f714a7c
CR
7777`skip-csi-sequence ()'
7778 Read enough characters to consume a multi-key sequence such as
7779 those defined for keys like Home and End. Such sequences begin
7780 with a Control Sequence Indicator (CSI), usually ESC-[. If this
7781 sequence is bound to "\e[", keys producing such sequences will
7782 have no effect unless explicitly bound to a readline command,
7783 instead of inserting stray characters into the editing buffer.
7784 This is unbound by default, but usually bound to ESC-[.
7785
bb70624e 7786`insert-comment (M-#)'
7117c2d2
JA
7787 Without a numeric argument, the value of the `comment-begin'
7788 variable is inserted at the beginning of the current line. If a
7789 numeric argument is supplied, this command acts as a toggle: if
7790 the characters at the beginning of the line do not match the value
7791 of `comment-begin', the value is inserted, otherwise the
7792 characters in `comment-begin' are deleted from the beginning of
7793 the line. In either case, the line is accepted as if a newline
7794 had been typed. The default value of `comment-begin' causes this
7795 command to make the current line a shell comment. If a numeric
7796 argument causes the comment character to be removed, the line will
7797 be executed by the shell.
bb70624e
JA
7798
7799`dump-functions ()'
7800 Print all of the functions and their key bindings to the Readline
7801 output stream. If a numeric argument is supplied, the output is
7802 formatted in such a way that it can be made part of an INPUTRC
7803 file. This command is unbound by default.
7804
7805`dump-variables ()'
7806 Print all of the settable variables and their values to the
7807 Readline output stream. If a numeric argument is supplied, the
7808 output is formatted in such a way that it can be made part of an
7809 INPUTRC file. This command is unbound by default.
7810
7811`dump-macros ()'
7812 Print all of the Readline key sequences bound to macros and the
28ef6c31
JA
7813 strings they output. If a numeric argument is supplied, the
7814 output is formatted in such a way that it can be made part of an
7815 INPUTRC file. This command is unbound by default.
bb70624e 7816
7117c2d2
JA
7817`glob-complete-word (M-g)'
7818 The word before point is treated as a pattern for pathname
7819 expansion, with an asterisk implicitly appended. This pattern is
7820 used to generate a list of matching file names for possible
7821 completions.
7822
bb70624e
JA
7823`glob-expand-word (C-x *)'
7824 The word before point is treated as a pattern for pathname
7825 expansion, and the list of matching file names is inserted,
7117c2d2
JA
7826 replacing the word. If a numeric argument is supplied, a `*' is
7827 appended before pathname expansion.
bb70624e
JA
7828
7829`glob-list-expansions (C-x g)'
7830 The list of expansions that would have been generated by
7117c2d2
JA
7831 `glob-expand-word' is displayed, and the line is redrawn. If a
7832 numeric argument is supplied, a `*' is appended before pathname
7833 expansion.
bb70624e
JA
7834
7835`display-shell-version (C-x C-v)'
7836 Display version information about the current instance of Bash.
7837
7838`shell-expand-line (M-C-e)'
7839 Expand the line as the shell does. This performs alias and
7840 history expansion as well as all of the shell word expansions
28ef6c31 7841 (*note Shell Expansions::).
bb70624e
JA
7842
7843`history-expand-line (M-^)'
7844 Perform history expansion on the current line.
7845
7846`magic-space ()'
7847 Perform history expansion on the current line and insert a space
28ef6c31 7848 (*note History Interaction::).
bb70624e
JA
7849
7850`alias-expand-line ()'
28ef6c31 7851 Perform alias expansion on the current line (*note Aliases::).
bb70624e
JA
7852
7853`history-and-alias-expand-line ()'
7854 Perform history and alias expansion on the current line.
7855
28ef6c31 7856`insert-last-argument (M-. or M-_)'
bb70624e
JA
7857 A synonym for `yank-last-arg'.
7858
7859`operate-and-get-next (C-o)'
7860 Accept the current line for execution and fetch the next line
7861 relative to the current line from the history for editing. Any
7862 argument is ignored.
7863
7117c2d2
JA
7864`edit-and-execute-command (C-xC-e)'
7865 Invoke an editor on the current command line, and execute the
c2258e1c 7866 result as shell commands. Bash attempts to invoke `$VISUAL',
7117c2d2 7867 `$EDITOR', and `emacs' as the editor, in that order.
bb70624e 7868
761783bf 7869
bb70624e
JA
7870\1f
7871File: bashref.info, Node: Readline vi Mode, Next: Programmable Completion, Prev: Bindable Readline Commands, Up: Command Line Editing
7872
37c41ab1
CR
78738.5 Readline vi Mode
7874====================
bb70624e 7875
37c41ab1 7876While the Readline library does not have a full set of `vi' editing
bb70624e 7877functions, it does contain enough to allow simple editing of the line.
eb0b2ad8 7878The Readline `vi' mode behaves as specified in the POSIX standard.
bb70624e
JA
7879
7880 In order to switch interactively between `emacs' and `vi' editing
7881modes, use the `set -o emacs' and `set -o vi' commands (*note The Set
28ef6c31 7882Builtin::). The Readline default is `emacs' mode.
bb70624e
JA
7883
7884 When you enter a line in `vi' mode, you are already placed in
7885`insertion' mode, as if you had typed an `i'. Pressing <ESC> switches
7886you into `command' mode, where you can edit the text of the line with
7887the standard `vi' movement keys, move to previous history lines with
7888`k' and subsequent lines with `j', and so forth.
7889
7890\1f
7891File: bashref.info, Node: Programmable Completion, Next: Programmable Completion Builtins, Prev: Readline vi Mode, Up: Command Line Editing
7892
37c41ab1
CR
78938.6 Programmable Completion
7894===========================
bb70624e 7895
37c41ab1 7896When word completion is attempted for an argument to a command for
bb70624e 7897which a completion specification (a COMPSPEC) has been defined using
28ef6c31 7898the `complete' builtin (*note Programmable Completion Builtins::), the
bb70624e
JA
7899programmable completion facilities are invoked.
7900
7901 First, the command name is identified. If a compspec has been
7902defined for that command, the compspec is used to generate the list of
8f714a7c
CR
7903possible completions for the word. If the command word is the empty
7904string (completion attempted at the beginning of an empty line), any
7905compspec defined with the `-E' option to `complete' is used. If the
7906command word is a full pathname, a compspec for the full pathname is
7907searched for first. If no compspec is found for the full pathname, an
7908attempt is made to find a compspec for the portion following the final
7909slash. If those searches do not result in a compspec, any compspec
7910defined with the `-D' option to `complete' is used as the default.
bb70624e
JA
7911
7912 Once a compspec has been found, it is used to generate the list of
7913matching words. If a compspec is not found, the default Bash completion
28ef6c31 7914described above (*note Commands For Completion::) is performed.
bb70624e
JA
7915
7916 First, the actions specified by the compspec are used. Only matches
7917which are prefixed by the word being completed are returned. When the
7918`-f' or `-d' option is used for filename or directory name completion,
7919the shell variable `FIGNORE' is used to filter the matches. *Note Bash
7920Variables::, for a description of `FIGNORE'.
7921
7922 Any completions specified by a filename expansion pattern to the
7923`-G' option are generated next. The words generated by the pattern
7924need not match the word being completed. The `GLOBIGNORE' shell
7925variable is not used to filter the matches, but the `FIGNORE' shell
7926variable is used.
7927
7928 Next, the string specified as the argument to the `-W' option is
7929considered. The string is first split using the characters in the `IFS'
7930special variable as delimiters. Shell quoting is honored. Each word
7931is then expanded using brace expansion, tilde expansion, parameter and
2206f89a
CR
7932variable expansion, command substitution, and arithmetic expansion, as
7933described above (*note Shell Expansions::). The results are split
7934using the rules described above (*note Word Splitting::). The results
7935of the expansion are prefix-matched against the word being completed,
7936and the matching words become the possible completions.
bb70624e
JA
7937
7938 After these matches have been generated, any shell function or
7939command specified with the `-F' and `-C' options is invoked. When the
d3ad40de
CR
7940command or function is invoked, the `COMP_LINE', `COMP_POINT',
7941`COMP_KEY', and `COMP_TYPE' variables are assigned values as described
7942above (*note Bash Variables::). If a shell function is being invoked,
7943the `COMP_WORDS' and `COMP_CWORD' variables are also set. When the
7944function or command is invoked, the first argument is the name of the
7945command whose arguments are being completed, the second argument is the
7946word being completed, and the third argument is the word preceding the
7947word being completed on the current command line. No filtering of the
7948generated completions against the word being completed is performed;
7949the function or command has complete freedom in generating the matches.
bb70624e
JA
7950
7951 Any function specified with `-F' is invoked first. The function may
6a8fd0ed
CR
7952use any of the shell facilities, including the `compgen' and `compopt'
7953builtins described below (*note Programmable Completion Builtins::), to
7954generate the matches. It must put the possible completions in the
7955`COMPREPLY' array variable.
bb70624e
JA
7956
7957 Next, any command specified with the `-C' option is invoked in an
7958environment equivalent to command substitution. It should print a list
7959of completions, one per line, to the standard output. Backslash may be
7960used to escape a newline, if necessary.
7961
7962 After all of the possible completions are generated, any filter
7963specified with the `-X' option is applied to the list. The filter is a
7964pattern as used for pathname expansion; a `&' in the pattern is
7965replaced with the text of the word being completed. A literal `&' may
7966be escaped with a backslash; the backslash is removed before attempting
7967a match. Any completion that matches the pattern will be removed from
7968the list. A leading `!' negates the pattern; in this case any
7969completion not matching the pattern will be removed.
7970
7971 Finally, any prefix and suffix specified with the `-P' and `-S'
7972options are added to each member of the completion list, and the result
7973is returned to the Readline completion code as the list of possible
7974completions.
7975
28ef6c31
JA
7976 If the previously-applied actions do not generate any matches, and
7977the `-o dirnames' option was supplied to `complete' when the compspec
7978was defined, directory name completion is attempted.
7979
d3a24ed2
CR
7980 If the `-o plusdirs' option was supplied to `complete' when the
7981compspec was defined, directory name completion is attempted and any
7982matches are added to the results of the other actions.
7983
28ef6c31
JA
7984 By default, if a compspec is found, whatever it generates is
7985returned to the completion code as the full set of possible completions.
7986The default Bash completions are not attempted, and the Readline default
d3a24ed2
CR
7987of filename completion is disabled. If the `-o bashdefault' option was
7988supplied to `complete' when the compspec was defined, the default Bash
7989completions are attempted if the compspec generates no matches. If the
7990`-o default' option was supplied to `complete' when the compspec was
7991defined, Readline's default completion will be performed if the
7992compspec (and, if attempted, the default Bash completions) generate no
28ef6c31 7993matches.
bb70624e 7994
7117c2d2
JA
7995 When a compspec indicates that directory name completion is desired,
7996the programmable completion functions force Readline to append a slash
7997to completed names which are symbolic links to directories, subject to
7998the value of the MARK-DIRECTORIES Readline variable, regardless of the
7999setting of the MARK-SYMLINKED-DIRECTORIES Readline variable.
8000
8f714a7c
CR
8001 There is some support for dynamically modifying completions. This is
8002most useful when used in combination with a default completion specified
8003with `-D'. It's possible for shell functions executed as completion
8004handlers to indicate that completion should be retried by returning an
8005exit status of 124. If a shell function returns 124, and changes the
8006compspec associated with the command on which completion is being
8007attempted (supplied as the first argument when the function is
8008executed), programmable completion restarts from the beginning, with an
eb0b2ad8 8009attempt to find a new compspec for that command. This allows a set of
8f714a7c
CR
8010completions to be built dynamically as completion is attempted, rather
8011than being loaded all at once.
8012
8013 For instance, assuming that there is a library of compspecs, each
8014kept in a file corresponding to the name of the command, the following
8015default completion function would load completions dynamically:
8016
8017 _completion_loader()
8018 {
8019 . "/etc/bash_completion.d/$1.sh" >/dev/null 2>&1 && return 124
8020 }
8021 complete -D -F _completion_loader
8022
bb70624e
JA
8023\1f
8024File: bashref.info, Node: Programmable Completion Builtins, Prev: Programmable Completion, Up: Command Line Editing
8025
37c41ab1
CR
80268.7 Programmable Completion Builtins
8027====================================
bb70624e 8028
37c41ab1 8029Two builtin commands are available to manipulate the programmable
bb70624e
JA
8030completion facilities.
8031
8032`compgen'
8033 `compgen [OPTION] [WORD]'
8034
8035 Generate possible completion matches for WORD according to the
8036 OPTIONs, which may be any option accepted by the `complete'
8037 builtin with the exception of `-p' and `-r', and write the matches
8038 to the standard output. When using the `-F' or `-C' options, the
8039 various shell variables set by the programmable completion
8040 facilities, while available, will not have useful values.
8041
8042 The matches will be generated in the same way as if the
8043 programmable completion code had generated them directly from a
8044 completion specification with the same flags. If WORD is
8045 specified, only those completions matching WORD will be displayed.
8046
8047 The return value is true unless an invalid option is supplied, or
8048 no matches were generated.
8049
8050`complete'
3eb2d94a 8051 `complete [-abcdefgjksuv] [-o COMP-OPTION] [-DE] [-A ACTION] [-G GLOBPAT] [-W WORDLIST]
d3ad40de
CR
8052 [-F FUNCTION] [-C COMMAND] [-X FILTERPAT]
8053 [-P PREFIX] [-S SUFFIX] NAME [NAME ...]'
3eb2d94a 8054 `complete -pr [-DE] [NAME ...]'
bb70624e
JA
8055
8056 Specify how arguments to each NAME should be completed. If the
8057 `-p' option is supplied, or if no options are supplied, existing
8058 completion specifications are printed in a way that allows them to
8059 be reused as input. The `-r' option removes a completion
8060 specification for each NAME, or, if no NAMEs are supplied, all
3eb2d94a
CR
8061 completion specifications. The `-D' option indicates that the
8062 remaining options and actions should apply to the "default"
8063 command completion; that is, completion attempted on a command for
8064 which no completion has previously been defined. The `-E' option
8065 indicates that the remaining options and actions should apply to
8066 "empty" command completion; that is, completion attempted on a
8067 blank line.
bb70624e
JA
8068
8069 The process of applying these completion specifications when word
8070 completion is attempted is described above (*note Programmable
8f714a7c 8071 Completion::). The `-D' option takes precedence over `-E'.
bb70624e
JA
8072
8073 Other options, if specified, have the following meanings. The
8074 arguments to the `-G', `-W', and `-X' options (and, if necessary,
8075 the `-P' and `-S' options) should be quoted to protect them from
8076 expansion before the `complete' builtin is invoked.
8077
28ef6c31
JA
8078 `-o COMP-OPTION'
8079 The COMP-OPTION controls several aspects of the compspec's
8080 behavior beyond the simple generation of completions.
8081 COMP-OPTION may be one of:
8082
d3a24ed2
CR
8083 `bashdefault'
8084 Perform the rest of the default Bash completions if the
8085 compspec generates no matches.
8086
28ef6c31 8087 `default'
7117c2d2
JA
8088 Use Readline's default filename completion if the
8089 compspec generates no matches.
28ef6c31
JA
8090
8091 `dirnames'
8092 Perform directory name completion if the compspec
8093 generates no matches.
8094
8095 `filenames'
8096 Tell Readline that the compspec generates filenames, so
d3a24ed2 8097 it can perform any filename-specific processing (like
a9fac3b2
CR
8098 adding a slash to directory names quoting special
8099 characters, or suppressing trailing spaces). This
8100 option is intended to be used with shell functions
8101 specified with `-F'.
28ef6c31 8102
7117c2d2
JA
8103 `nospace'
8104 Tell Readline not to append a space (the default) to
8105 words completed at the end of the line.
8106
22e63b05
CR
8107 `plusdirs'
8108 After any matches defined by the compspec are generated,
8109 directory name completion is attempted and any matches
8110 are added to the results of the other actions.
8111
8112
bb70624e
JA
8113 `-A ACTION'
8114 The ACTION may be one of the following to generate a list of
8115 possible completions:
8116
8117 `alias'
8118 Alias names. May also be specified as `-a'.
8119
8120 `arrayvar'
8121 Array variable names.
8122
8123 `binding'
8124 Readline key binding names (*note Bindable Readline
28ef6c31 8125 Commands::).
bb70624e
JA
8126
8127 `builtin'
8128 Names of shell builtin commands. May also be specified
8129 as `-b'.
8130
8131 `command'
8132 Command names. May also be specified as `-c'.
8133
8134 `directory'
8135 Directory names. May also be specified as `-d'.
8136
8137 `disabled'
8138 Names of disabled shell builtins.
8139
8140 `enabled'
8141 Names of enabled shell builtins.
8142
8143 `export'
8144 Names of exported shell variables. May also be
8145 specified as `-e'.
8146
8147 `file'
8148 File names. May also be specified as `-f'.
8149
8150 `function'
8151 Names of shell functions.
8152
f73dda09
JA
8153 `group'
8154 Group names. May also be specified as `-g'.
8155
bb70624e
JA
8156 `helptopic'
8157 Help topics as accepted by the `help' builtin (*note
28ef6c31 8158 Bash Builtins::).
bb70624e
JA
8159
8160 `hostname'
8161 Hostnames, as taken from the file specified by the
28ef6c31 8162 `HOSTFILE' shell variable (*note Bash Variables::).
bb70624e
JA
8163
8164 `job'
8165 Job names, if job control is active. May also be
8166 specified as `-j'.
8167
8168 `keyword'
8169 Shell reserved words. May also be specified as `-k'.
8170
8171 `running'
8172 Names of running jobs, if job control is active.
8173
7117c2d2
JA
8174 `service'
8175 Service names. May also be specified as `-s'.
8176
bb70624e
JA
8177 `setopt'
8178 Valid arguments for the `-o' option to the `set' builtin
28ef6c31 8179 (*note The Set Builtin::).
bb70624e
JA
8180
8181 `shopt'
8182 Shell option names as accepted by the `shopt' builtin
28ef6c31 8183 (*note Bash Builtins::).
bb70624e
JA
8184
8185 `signal'
8186 Signal names.
8187
8188 `stopped'
8189 Names of stopped jobs, if job control is active.
8190
8191 `user'
8192 User names. May also be specified as `-u'.
8193
8194 `variable'
8195 Names of all shell variables. May also be specified as
8196 `-v'.
8197
bb70624e
JA
8198 `-C COMMAND'
8199 COMMAND is executed in a subshell environment, and its output
8200 is used as the possible completions.
8201
8202 `-F FUNCTION'
8203 The shell function FUNCTION is executed in the current shell
8204 environment. When it finishes, the possible completions are
8205 retrieved from the value of the `COMPREPLY' array variable.
8206
5cdaaf76
CR
8207 `-G GLOBPAT'
8208 The filename expansion pattern GLOBPAT is expanded to generate
8209 the possible completions.
bb70624e
JA
8210
8211 `-P PREFIX'
8212 PREFIX is added at the beginning of each possible completion
8213 after all other options have been applied.
8214
8215 `-S SUFFIX'
8216 SUFFIX is appended to each possible completion after all
8217 other options have been applied.
8218
5cdaaf76
CR
8219 `-W WORDLIST'
8220 The WORDLIST is split using the characters in the `IFS'
8221 special variable as delimiters, and each resultant word is
8222 expanded. The possible completions are the members of the
8223 resultant list which match the word being completed.
8224
8225 `-X FILTERPAT'
8226 FILTERPAT is a pattern as used for filename expansion. It is
8227 applied to the list of possible completions generated by the
8228 preceding options and arguments, and each completion matching
8229 FILTERPAT is removed from the list. A leading `!' in
8230 FILTERPAT negates the pattern; in this case, any completion
8231 not matching FILTERPAT is removed.
8232
bb70624e
JA
8233 The return value is true unless an invalid option is supplied, an
8234 option other than `-p' or `-r' is supplied without a NAME
8235 argument, an attempt is made to remove a completion specification
8236 for a NAME for which no specification exists, or an error occurs
8237 adding a completion specification.
8238
6a8fd0ed 8239`compopt'
3eb2d94a 8240 `compopt' [-o OPTION] [-DE] [+o OPTION] [NAME]
6a8fd0ed 8241 Modify completion options for each NAME according to the OPTIONs,
5cdaaf76 8242 or for the currently-executing completion if no NAMEs are supplied.
6a8fd0ed
CR
8243 If no OPTIONs are given, display the completion options for each
8244 NAME or the current completion. The possible values of OPTION are
3eb2d94a
CR
8245 those valid for the `complete' builtin described above. The `-D'
8246 option indicates that the remaining options should apply to the
8247 "default" command completion; that is, completion attempted on a
8248 command for which no completion has previously been defined. The
8249 `-E' option indicates that the remaining options should apply to
8250 "empty" command completion; that is, completion attempted on a
8251 blank line.
6a8fd0ed 8252
8f714a7c
CR
8253 The `-D' option takes precedence over `-E'.
8254
6a8fd0ed
CR
8255 The return value is true unless an invalid option is supplied, an
8256 attempt is made to modify the options for a NAME for which no
8257 completion specification exists, or an output error occurs.
8258
8259
bb70624e 8260\1f
c2a47ea9 8261File: bashref.info, Node: Using History Interactively, Next: Installing Bash, Prev: Command Line Editing, Up: Top
bb70624e 8262
37c41ab1
CR
82639 Using History Interactively
8264*****************************
bb70624e 8265
37c41ab1 8266This chapter describes how to use the GNU History Library
bb70624e
JA
8267interactively, from a user's standpoint. It should be considered a
8268user's guide. For information on using the GNU History Library in
8269other programs, see the GNU Readline Library Manual.
8270
8271* Menu:
8272
8273* Bash History Facilities:: How Bash lets you manipulate your command
8274 history.
8275* Bash History Builtins:: The Bash builtin commands that manipulate
8276 the command history.
8277* History Interaction:: What it feels like using History as a user.
8278
8279\1f
8280File: bashref.info, Node: Bash History Facilities, Next: Bash History Builtins, Up: Using History Interactively
8281
37c41ab1
CR
82829.1 Bash History Facilities
8283===========================
bb70624e 8284
37c41ab1
CR
8285When the `-o history' option to the `set' builtin is enabled (*note The
8286Set Builtin::), the shell provides access to the "command history", the
8287list of commands previously typed. The value of the `HISTSIZE' shell
8288variable is used as the number of commands to save in a history list.
8289The text of the last `$HISTSIZE' commands (default 500) is saved. The
8290shell stores each command in the history list prior to parameter and
8291variable expansion but after history expansion is performed, subject to
8292the values of the shell variables `HISTIGNORE' and `HISTCONTROL'.
bb70624e
JA
8293
8294 When the shell starts up, the history is initialized from the file
8295named by the `HISTFILE' variable (default `~/.bash_history'). The file
8296named by the value of `HISTFILE' is truncated, if necessary, to contain
8297no more than the number of lines specified by the value of the
8298`HISTFILESIZE' variable. When an interactive shell exits, the last
8299`$HISTSIZE' lines are copied from the history list to the file named by
8300`$HISTFILE'. If the `histappend' shell option is set (*note Bash
28ef6c31 8301Builtins::), the lines are appended to the history file, otherwise the
bb70624e
JA
8302history file is overwritten. If `HISTFILE' is unset, or if the history
8303file is unwritable, the history is not saved. After saving the
8304history, the history file is truncated to contain no more than
8305`$HISTFILESIZE' lines. If `HISTFILESIZE' is not set, no truncation is
8306performed.
8307
d3a24ed2 8308 If the `HISTTIMEFORMAT' is set, the time stamp information
d3ad40de
CR
8309associated with each history entry is written to the history file,
8310marked with the history comment character. When the history file is
8311read, lines beginning with the history comment character followed
8312immediately by a digit are interpreted as timestamps for the previous
8313history line.
d3a24ed2 8314
bb70624e
JA
8315 The builtin command `fc' may be used to list or edit and re-execute
8316a portion of the history list. The `history' builtin may be used to
8317display or modify the history list and manipulate the history file.
8318When using command-line editing, search commands are available in each
8319editing mode that provide access to the history list (*note Commands
28ef6c31 8320For History::).
bb70624e
JA
8321
8322 The shell allows control over which commands are saved on the history
8323list. The `HISTCONTROL' and `HISTIGNORE' variables may be set to cause
8324the shell to save only a subset of the commands entered. The `cmdhist'
8325shell option, if enabled, causes the shell to attempt to save each line
8326of a multi-line command in the same history entry, adding semicolons
8327where necessary to preserve syntactic correctness. The `lithist' shell
8328option causes the shell to save the command with embedded newlines
8329instead of semicolons. The `shopt' builtin is used to set these
8330options. *Note Bash Builtins::, for a description of `shopt'.
8331
8332\1f
8333File: bashref.info, Node: Bash History Builtins, Next: History Interaction, Prev: Bash History Facilities, Up: Using History Interactively
8334
37c41ab1
CR
83359.2 Bash History Builtins
8336=========================
bb70624e 8337
37c41ab1 8338Bash provides two builtin commands which manipulate the history list
bb70624e
JA
8339and history file.
8340
8341`fc'
d3ad40de 8342 `fc [-e ENAME] [-lnr] [FIRST] [LAST]'
bb70624e
JA
8343 `fc -s [PAT=REP] [COMMAND]'
8344
122f603c
CR
8345 The first form selects a range of commands from FIRST to LAST from
8346 the history list and displays or edits and re-executes them. Both
8347 FIRST and LAST may be specified as a string (to locate the most
8348 recent command beginning with that string) or as a number (an
8349 index into the history list, where a negative number is used as an
8350 offset from the current command number). If LAST is not specified
8351 it is set to FIRST. If FIRST is not specified it is set to the
8352 previous command for editing and -16 for listing. If the `-l'
8353 flag is given, the commands are listed on standard output. The
8354 `-n' flag suppresses the command numbers when listing. The `-r'
8355 flag reverses the order of the listing. Otherwise, the editor
8356 given by ENAME is invoked on a file containing those commands. If
8357 ENAME is not given, the value of the following variable expansion
8358 is used: `${FCEDIT:-${EDITOR:-vi}}'. This says to use the value
8359 of the `FCEDIT' variable if set, or the value of the `EDITOR'
8360 variable if that is set, or `vi' if neither is set. When editing
8361 is complete, the edited commands are echoed and executed.
bb70624e
JA
8362
8363 In the second form, COMMAND is re-executed after each instance of
122f603c
CR
8364 PAT in the selected command is replaced by REP. COMMAND is
8365 intepreted the same as FIRST above.
bb70624e
JA
8366
8367 A useful alias to use with the `fc' command is `r='fc -s'', so
8368 that typing `r cc' runs the last command beginning with `cc' and
28ef6c31 8369 typing `r' re-executes the last command (*note Aliases::).
bb70624e
JA
8370
8371`history'
8372 history [N]
8373 history -c
8374 history -d OFFSET
8375 history [-anrw] [FILENAME]
8376 history -ps ARG
8377
8378 With no options, display the history list with line numbers.
28ef6c31 8379 Lines prefixed with a `*' have been modified. An argument of N
d3a24ed2
CR
8380 lists only the last N lines. If the shell variable
8381 `HISTTIMEFORMAT' is set and not null, it is used as a format
8382 string for STRFTIME to display the time stamp associated with each
8383 displayed history entry. No intervening blank is printed between
8384 the formatted time stamp and the history line.
8385
8386 Options, if supplied, have the following meanings:
bb70624e
JA
8387
8388 `-c'
8389 Clear the history list. This may be combined with the other
8390 options to replace the history list completely.
8391
8392 `-d OFFSET'
8393 Delete the history entry at position OFFSET. OFFSET should
8394 be specified as it appears when the history is displayed.
8395
8396 `-a'
8397 Append the new history lines (history lines entered since the
8398 beginning of the current Bash session) to the history file.
8399
8400 `-n'
8401 Append the history lines not already read from the history
8402 file to the current history list. These are lines appended
8403 to the history file since the beginning of the current Bash
8404 session.
8405
8406 `-r'
122f603c
CR
8407 Read the history file and append its contents to the history
8408 list.
bb70624e
JA
8409
8410 `-w'
122f603c 8411 Write out the current history list to the history file.
bb70624e
JA
8412
8413 `-p'
8414 Perform history substitution on the ARGs and display the
8415 result on the standard output, without storing the results in
8416 the history list.
8417
8418 `-s'
8419 The ARGs are added to the end of the history list as a single
8420 entry.
8421
761783bf 8422
bb70624e
JA
8423 When any of the `-w', `-r', `-a', or `-n' options is used, if
8424 FILENAME is given, then it is used as the history file. If not,
8425 then the value of the `HISTFILE' variable is used.
8426
761783bf 8427
bb70624e
JA
8428\1f
8429File: bashref.info, Node: History Interaction, Prev: Bash History Builtins, Up: Using History Interactively
ccc6cda3 8430
37c41ab1
CR
84319.3 History Expansion
8432=====================
ccc6cda3 8433
37c41ab1
CR
8434The History library provides a history expansion feature that is similar
8435to the history expansion provided by `csh'. This section describes the
8436syntax used to manipulate the history information.
ccc6cda3 8437
bb70624e
JA
8438 History expansions introduce words from the history list into the
8439input stream, making it easy to repeat commands, insert the arguments
8440to a previous command into the current input line, or fix errors in
8441previous commands quickly.
ccc6cda3 8442
bb70624e
JA
8443 History expansion takes place in two parts. The first is to
8444determine which line from the history list should be used during
8445substitution. The second is to select portions of that line for
8446inclusion into the current one. The line selected from the history is
8447called the "event", and the portions of that line that are acted upon
8448are called "words". Various "modifiers" are available to manipulate
8449the selected words. The line is broken into words in the same fashion
8450that Bash does, so that several words surrounded by quotes are
8451considered one word. History expansions are introduced by the
8452appearance of the history expansion character, which is `!' by default.
8453Only `\' and `'' may be used to escape the history expansion character.
8454
8455 Several shell options settable with the `shopt' builtin (*note Bash
28ef6c31 8456Builtins::) may be used to tailor the behavior of history expansion.
bb70624e
JA
8457If the `histverify' shell option is enabled, and Readline is being
8458used, history substitutions are not immediately passed to the shell
8459parser. Instead, the expanded line is reloaded into the Readline
8460editing buffer for further modification. If Readline is being used,
8461and the `histreedit' shell option is enabled, a failed history
8462expansion will be reloaded into the Readline editing buffer for
8463correction. The `-p' option to the `history' builtin command may be
8464used to see what a history expansion will do before using it. The `-s'
8465option to the `history' builtin may be used to add commands to the end
8466of the history list without actually executing them, so that they are
8467available for subsequent recall. This is most useful in conjunction
8468with Readline.
8469
8470 The shell allows control of the various characters used by the
d3ad40de
CR
8471history expansion mechanism with the `histchars' variable, as explained
8472above (*note Bash Variables::). The shell uses the history comment
8473character to mark history timestamps when writing the history file.
bb70624e
JA
8474
8475* Menu:
8476
8477* Event Designators:: How to specify which history line to use.
8478* Word Designators:: Specifying which words are of interest.
8479* Modifiers:: Modifying the results of substitution.
ccc6cda3
JA
8480
8481\1f
bb70624e 8482File: bashref.info, Node: Event Designators, Next: Word Designators, Up: History Interaction
ccc6cda3 8483
37c41ab1
CR
84849.3.1 Event Designators
8485-----------------------
ccc6cda3 8486
37c41ab1 8487An event designator is a reference to a command line entry in the
e05be32d
CR
8488history list. Unless the reference is absolute, events are relative to
8489the current position in the history list.
ccc6cda3 8490
bb70624e
JA
8491`!'
8492 Start a history substitution, except when followed by a space, tab,
d3a24ed2
CR
8493 the end of the line, `=' or `(' (when the `extglob' shell option
8494 is enabled using the `shopt' builtin).
ccc6cda3 8495
bb70624e
JA
8496`!N'
8497 Refer to command line N.
ccc6cda3 8498
bb70624e
JA
8499`!-N'
8500 Refer to the command N lines back.
ccc6cda3 8501
bb70624e
JA
8502`!!'
8503 Refer to the previous command. This is a synonym for `!-1'.
ccc6cda3 8504
bb70624e 8505`!STRING'
e05be32d
CR
8506 Refer to the most recent command preceding the current position in
8507 the history list starting with STRING.
ccc6cda3 8508
bb70624e 8509`!?STRING[?]'
e05be32d
CR
8510 Refer to the most recent command preceding the current position in
8511 the history list containing STRING. The trailing `?' may be
8512 omitted if the STRING is followed immediately by a newline.
ccc6cda3 8513
bb70624e
JA
8514`^STRING1^STRING2^'
8515 Quick Substitution. Repeat the last command, replacing STRING1
8516 with STRING2. Equivalent to `!!:s/STRING1/STRING2/'.
8517
8518`!#'
8519 The entire command line typed so far.
ccc6cda3 8520
761783bf 8521
ccc6cda3 8522\1f
bb70624e 8523File: bashref.info, Node: Word Designators, Next: Modifiers, Prev: Event Designators, Up: History Interaction
ccc6cda3 8524
37c41ab1
CR
85259.3.2 Word Designators
8526----------------------
ccc6cda3 8527
37c41ab1 8528Word designators are used to select desired words from the event. A
bb70624e
JA
8529`:' separates the event specification from the word designator. It may
8530be omitted if the word designator begins with a `^', `$', `*', `-', or
8531`%'. Words are numbered from the beginning of the line, with the first
8532word being denoted by 0 (zero). Words are inserted into the current
8533line separated by single spaces.
ccc6cda3 8534
bb70624e 8535 For example,
ccc6cda3 8536
bb70624e
JA
8537`!!'
8538 designates the preceding command. When you type this, the
8539 preceding command is repeated in toto.
ccc6cda3 8540
bb70624e
JA
8541`!!:$'
8542 designates the last argument of the preceding command. This may be
8543 shortened to `!$'.
ccc6cda3 8544
bb70624e
JA
8545`!fi:2'
8546 designates the second argument of the most recent command starting
8547 with the letters `fi'.
ccc6cda3 8548
bb70624e 8549 Here are the word designators:
ccc6cda3 8550
bb70624e
JA
8551`0 (zero)'
8552 The `0'th word. For many applications, this is the command word.
ccc6cda3 8553
bb70624e
JA
8554`N'
8555 The Nth word.
ccc6cda3 8556
bb70624e
JA
8557`^'
8558 The first argument; that is, word 1.
ccc6cda3 8559
bb70624e
JA
8560`$'
8561 The last argument.
ccc6cda3 8562
bb70624e
JA
8563`%'
8564 The word matched by the most recent `?STRING?' search.
ccc6cda3 8565
bb70624e
JA
8566`X-Y'
8567 A range of words; `-Y' abbreviates `0-Y'.
ccc6cda3 8568
bb70624e
JA
8569`*'
8570 All of the words, except the `0'th. This is a synonym for `1-$'.
8571 It is not an error to use `*' if there is just one word in the
8572 event; the empty string is returned in that case.
8573
8574`X*'
8575 Abbreviates `X-$'
8576
8577`X-'
8578 Abbreviates `X-$' like `X*', but omits the last word.
8579
761783bf 8580
bb70624e
JA
8581 If a word designator is supplied without an event specification, the
8582previous command is used as the event.
ccc6cda3
JA
8583
8584\1f
bb70624e 8585File: bashref.info, Node: Modifiers, Prev: Word Designators, Up: History Interaction
ccc6cda3 8586
37c41ab1
CR
85879.3.3 Modifiers
8588---------------
ccc6cda3 8589
37c41ab1 8590After the optional word designator, you can add a sequence of one or
bb70624e 8591more of the following modifiers, each preceded by a `:'.
ccc6cda3 8592
bb70624e
JA
8593`h'
8594 Remove a trailing pathname component, leaving only the head.
ccc6cda3 8595
bb70624e 8596`t'
d3ad40de 8597 Remove all leading pathname components, leaving the tail.
bb70624e
JA
8598
8599`r'
8600 Remove a trailing suffix of the form `.SUFFIX', leaving the
8601 basename.
8602
8603`e'
8604 Remove all but the trailing suffix.
8605
8606`p'
8607 Print the new command but do not execute it.
8608
8609`q'
8610 Quote the substituted words, escaping further substitutions.
8611
8612`x'
8613 Quote the substituted words as with `q', but break into words at
8614 spaces, tabs, and newlines.
8615
8616`s/OLD/NEW/'
8617 Substitute NEW for the first occurrence of OLD in the event line.
8618 Any delimiter may be used in place of `/'. The delimiter may be
8619 quoted in OLD and NEW with a single backslash. If `&' appears in
8620 NEW, it is replaced by OLD. A single backslash will quote the
8621 `&'. The final delimiter is optional if it is the last character
8622 on the input line.
8623
8624`&'
8625 Repeat the previous substitution.
8626
8627`g'
d3a24ed2 8628`a'
bb70624e
JA
8629 Cause changes to be applied over the entire event line. Used in
8630 conjunction with `s', as in `gs/OLD/NEW/', or with `&'.
8631
d3a24ed2
CR
8632`G'
8633 Apply the following `s' modifier once to each word in the event.
8634
761783bf 8635
bb70624e 8636\1f
c2a47ea9 8637File: bashref.info, Node: Installing Bash, Next: Reporting Bugs, Prev: Using History Interactively, Up: Top
bb70624e 8638
37c41ab1
CR
863910 Installing Bash
8640******************
b72432fd 8641
37c41ab1 8642This chapter provides basic instructions for installing Bash on the
bb70624e
JA
8643various supported platforms. The distribution supports the GNU
8644operating systems, nearly every version of Unix, and several non-Unix
8645systems such as BeOS and Interix. Other independent ports exist for
d3a24ed2 8646MS-DOS, OS/2, and Windows platforms.
ccc6cda3 8647
bb70624e 8648* Menu:
ccc6cda3 8649
bb70624e 8650* Basic Installation:: Installation instructions.
bb70624e
JA
8651* Compilers and Options:: How to set special options for various
8652 systems.
bb70624e
JA
8653* Compiling For Multiple Architectures:: How to compile Bash for more
8654 than one kind of system from
8655 the same source tree.
bb70624e 8656* Installation Names:: How to set the various paths used by the installation.
bb70624e 8657* Specifying the System Type:: How to configure Bash for a particular system.
bb70624e
JA
8658* Sharing Defaults:: How to share default configuration values among GNU
8659 programs.
bb70624e 8660* Operation Controls:: Options recognized by the configuration program.
bb70624e
JA
8661* Optional Features:: How to enable and disable optional features when
8662 building Bash.
ccc6cda3 8663
bb70624e
JA
8664\1f
8665File: bashref.info, Node: Basic Installation, Next: Compilers and Options, Up: Installing Bash
ccc6cda3 8666
37c41ab1
CR
866710.1 Basic Installation
8668=======================
ccc6cda3 8669
37c41ab1 8670These are installation instructions for Bash.
ccc6cda3 8671
bb70624e 8672 The simplest way to compile Bash is:
ccc6cda3 8673
bb70624e
JA
8674 1. `cd' to the directory containing the source code and type
8675 `./configure' to configure Bash for your system. If you're using
8676 `csh' on an old version of System V, you might need to type `sh
8677 ./configure' instead to prevent `csh' from trying to execute
8678 `configure' itself.
ccc6cda3 8679
bb70624e
JA
8680 Running `configure' takes some time. While running, it prints
8681 messages telling which features it is checking for.
ccc6cda3 8682
bb70624e
JA
8683 2. Type `make' to compile Bash and build the `bashbug' bug reporting
8684 script.
ccc6cda3 8685
bb70624e 8686 3. Optionally, type `make tests' to run the Bash test suite.
ccc6cda3 8687
bb70624e
JA
8688 4. Type `make install' to install `bash' and `bashbug'. This will
8689 also install the manual pages and Info file.
ccc6cda3 8690
ccc6cda3 8691
bb70624e
JA
8692 The `configure' shell script attempts to guess correct values for
8693various system-dependent variables used during compilation. It uses
8694those values to create a `Makefile' in each directory of the package
8695(the top directory, the `builtins', `doc', and `support' directories,
8696each directory under `lib', and several others). It also creates a
8697`config.h' file containing system-dependent definitions. Finally, it
8698creates a shell script named `config.status' that you can run in the
8699future to recreate the current configuration, a file `config.cache'
8700that saves the results of its tests to speed up reconfiguring, and a
8701file `config.log' containing compiler output (useful mainly for
8702debugging `configure'). If at some point `config.cache' contains
8703results you don't want to keep, you may remove or edit it.
ccc6cda3 8704
bb70624e
JA
8705 To find out more about the options and arguments that the
8706`configure' script understands, type
ccc6cda3 8707
bb70624e 8708 bash-2.04$ ./configure --help
ccc6cda3 8709
bb70624e 8710at the Bash prompt in your Bash source directory.
ccc6cda3 8711
bb70624e
JA
8712 If you need to do unusual things to compile Bash, please try to
8713figure out how `configure' could check whether or not to do them, and
8714mail diffs or instructions to <bash-maintainers@gnu.org> so they can be
8715considered for the next release.
ccc6cda3 8716
bb70624e
JA
8717 The file `configure.in' is used to create `configure' by a program
8718called Autoconf. You only need `configure.in' if you want to change it
8719or regenerate `configure' using a newer version of Autoconf. If you do
f73dda09 8720this, make sure you are using Autoconf version 2.50 or newer.
ccc6cda3 8721
bb70624e
JA
8722 You can remove the program binaries and object files from the source
8723code directory by typing `make clean'. To also remove the files that
8724`configure' created (so you can compile Bash for a different kind of
8725computer), type `make distclean'.
ccc6cda3 8726
bb70624e
JA
8727\1f
8728File: bashref.info, Node: Compilers and Options, Next: Compiling For Multiple Architectures, Prev: Basic Installation, Up: Installing Bash
ccc6cda3 8729
37c41ab1
CR
873010.2 Compilers and Options
8731==========================
ccc6cda3 8732
37c41ab1 8733Some systems require unusual options for compilation or linking that
bb70624e
JA
8734the `configure' script does not know about. You can give `configure'
8735initial values for variables by setting them in the environment. Using
8736a Bourne-compatible shell, you can do that on the command line like
8737this:
ccc6cda3 8738
bb70624e 8739 CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure
ccc6cda3 8740
bb70624e 8741 On systems that have the `env' program, you can do it like this:
cce855bc 8742
bb70624e 8743 env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure
b72432fd 8744
bb70624e 8745 The configuration process uses GCC to build Bash if it is available.
ccc6cda3 8746
bb70624e
JA
8747\1f
8748File: bashref.info, Node: Compiling For Multiple Architectures, Next: Installation Names, Prev: Compilers and Options, Up: Installing Bash
ccc6cda3 8749
37c41ab1
CR
875010.3 Compiling For Multiple Architectures
8751=========================================
ccc6cda3 8752
37c41ab1 8753You can compile Bash for more than one kind of computer at the same
bb70624e
JA
8754time, by placing the object files for each architecture in their own
8755directory. To do this, you must use a version of `make' that supports
8756the `VPATH' variable, such as GNU `make'. `cd' to the directory where
8757you want the object files and executables to go and run the `configure'
8758script from the source directory. You may need to supply the
8759`--srcdir=PATH' argument to tell `configure' where the source files
8760are. `configure' automatically checks for the source code in the
8761directory that `configure' is in and in `..'.
ccc6cda3 8762
bb70624e
JA
8763 If you have to use a `make' that does not supports the `VPATH'
8764variable, you can compile Bash for one architecture at a time in the
8765source code directory. After you have installed Bash for one
8766architecture, use `make distclean' before reconfiguring for another
8767architecture.
ccc6cda3 8768
bb70624e
JA
8769 Alternatively, if your system supports symbolic links, you can use
8770the `support/mkclone' script to create a build tree which has symbolic
8771links back to each file in the source directory. Here's an example
8772that creates a build directory in the current directory from a source
8773directory `/usr/gnu/src/bash-2.0':
ccc6cda3 8774
bb70624e 8775 bash /usr/gnu/src/bash-2.0/support/mkclone -s /usr/gnu/src/bash-2.0 .
ccc6cda3 8776
bb70624e
JA
8777The `mkclone' script requires Bash, so you must have already built Bash
8778for at least one architecture before you can create build directories
8779for other architectures.
ccc6cda3 8780
bb70624e
JA
8781\1f
8782File: bashref.info, Node: Installation Names, Next: Specifying the System Type, Prev: Compiling For Multiple Architectures, Up: Installing Bash
ccc6cda3 8783
37c41ab1
CR
878410.4 Installation Names
8785=======================
ccc6cda3 8786
37c41ab1 8787By default, `make install' will install into `/usr/local/bin',
bb70624e 8788`/usr/local/man', etc. You can specify an installation prefix other
f73dda09
JA
8789than `/usr/local' by giving `configure' the option `--prefix=PATH', or
8790by specifying a value for the `DESTDIR' `make' variable when running
8791`make install'.
ccc6cda3 8792
bb70624e
JA
8793 You can specify separate installation prefixes for
8794architecture-specific files and architecture-independent files. If you
8795give `configure' the option `--exec-prefix=PATH', `make install' will
8796use PATH as the prefix for installing programs and libraries.
8797Documentation and other data files will still use the regular prefix.
ccc6cda3
JA
8798
8799\1f
bb70624e 8800File: bashref.info, Node: Specifying the System Type, Next: Sharing Defaults, Prev: Installation Names, Up: Installing Bash
ccc6cda3 8801
37c41ab1
CR
880210.5 Specifying the System Type
8803===============================
ccc6cda3 8804
37c41ab1 8805There may be some features `configure' can not figure out
f73dda09 8806automatically, but need to determine by the type of host Bash will run
bb70624e
JA
8807on. Usually `configure' can figure that out, but if it prints a
8808message saying it can not guess the host type, give it the
8809`--host=TYPE' option. `TYPE' can either be a short name for the system
8810type, such as `sun4', or a canonical name with three fields:
f73dda09 8811`CPU-COMPANY-SYSTEM' (e.g., `i386-unknown-freebsd4.2').
ccc6cda3 8812
bb70624e
JA
8813 See the file `support/config.sub' for the possible values of each
8814field.
ccc6cda3 8815
bb70624e
JA
8816\1f
8817File: bashref.info, Node: Sharing Defaults, Next: Operation Controls, Prev: Specifying the System Type, Up: Installing Bash
8818
37c41ab1
CR
881910.6 Sharing Defaults
8820=====================
bb70624e 8821
37c41ab1
CR
8822If you want to set default values for `configure' scripts to share, you
8823can create a site shell script called `config.site' that gives default
8824values for variables like `CC', `cache_file', and `prefix'. `configure'
8825looks for `PREFIX/share/config.site' if it exists, then
bb70624e
JA
8826`PREFIX/etc/config.site' if it exists. Or, you can set the
8827`CONFIG_SITE' environment variable to the location of the site script.
8828A warning: the Bash `configure' looks for a site script, but not all
8829`configure' scripts do.
ccc6cda3
JA
8830
8831\1f
bb70624e 8832File: bashref.info, Node: Operation Controls, Next: Optional Features, Prev: Sharing Defaults, Up: Installing Bash
ccc6cda3 8833
37c41ab1
CR
883410.7 Operation Controls
8835=======================
ccc6cda3 8836
37c41ab1 8837`configure' recognizes the following options to control how it operates.
ccc6cda3 8838
bb70624e
JA
8839`--cache-file=FILE'
8840 Use and save the results of the tests in FILE instead of
8841 `./config.cache'. Set FILE to `/dev/null' to disable caching, for
8842 debugging `configure'.
ccc6cda3 8843
bb70624e
JA
8844`--help'
8845 Print a summary of the options to `configure', and exit.
ccc6cda3 8846
bb70624e
JA
8847`--quiet'
8848`--silent'
8849`-q'
8850 Do not print messages saying which checks are being made.
ccc6cda3 8851
bb70624e
JA
8852`--srcdir=DIR'
8853 Look for the Bash source code in directory DIR. Usually
8854 `configure' can determine that directory automatically.
ccc6cda3 8855
bb70624e
JA
8856`--version'
8857 Print the version of Autoconf used to generate the `configure'
8858 script, and exit.
ccc6cda3 8859
bb70624e
JA
8860 `configure' also accepts some other, not widely used, boilerplate
8861options. `configure --help' prints the complete list.
ccc6cda3 8862
bb70624e
JA
8863\1f
8864File: bashref.info, Node: Optional Features, Prev: Operation Controls, Up: Installing Bash
ccc6cda3 8865
37c41ab1
CR
886610.8 Optional Features
8867======================
ccc6cda3 8868
37c41ab1
CR
8869The Bash `configure' has a number of `--enable-FEATURE' options, where
8870FEATURE indicates an optional part of Bash. There are also several
8871`--with-PACKAGE' options, where PACKAGE is something like `bash-malloc'
8872or `purify'. To turn off the default use of a package, use
8873`--without-PACKAGE'. To configure Bash without a feature that is
bb70624e 8874enabled by default, use `--disable-FEATURE'.
ccc6cda3 8875
bb70624e
JA
8876 Here is a complete list of the `--enable-' and `--with-' options
8877that the Bash `configure' recognizes.
ccc6cda3 8878
bb70624e
JA
8879`--with-afs'
8880 Define if you are using the Andrew File System from Transarc.
ccc6cda3 8881
bb70624e 8882`--with-bash-malloc'
1c72c0cd
CR
8883 Use the Bash version of `malloc' in the directory `lib/malloc'.
8884 This is not the same `malloc' that appears in GNU libc, but an
8885 older version originally derived from the 4.2 BSD `malloc'. This
8886 `malloc' is very fast, but wastes some space on each allocation.
8887 This option is enabled by default. The `NOTES' file contains a
8888 list of systems for which this should be turned off, and
8889 `configure' disables this option automatically for a number of
8890 systems.
ccc6cda3 8891
bb70624e
JA
8892`--with-curses'
8893 Use the curses library instead of the termcap library. This should
8894 be supplied if your system has an inadequate or incomplete termcap
8895 database.
ccc6cda3 8896
bb70624e
JA
8897`--with-gnu-malloc'
8898 A synonym for `--with-bash-malloc'.
ccc6cda3 8899
f73dda09 8900`--with-installed-readline[=PREFIX]'
bb70624e
JA
8901 Define this to make Bash link with a locally-installed version of
8902 Readline rather than the version in `lib/readline'. This works
01ed5ba4 8903 only with Readline 5.0 and later versions. If PREFIX is `yes' or
f73dda09
JA
8904 not supplied, `configure' uses the values of the make variables
8905 `includedir' and `libdir', which are subdirectories of `prefix' by
8906 default, to find the installed version of Readline if it is not in
8907 the standard system include and library directories. If PREFIX is
8908 `no', Bash links with the version in `lib/readline'. If PREFIX is
8909 set to any other value, `configure' treats it as a directory
8910 pathname and looks for the installed version of Readline in
8911 subdirectories of that directory (include files in
8912 PREFIX/`include' and the library in PREFIX/`lib').
ccc6cda3 8913
bb70624e
JA
8914`--with-purify'
8915 Define this to use the Purify memory allocation checker from
8916 Rational Software.
ccc6cda3 8917
bb70624e
JA
8918`--enable-minimal-config'
8919 This produces a shell with minimal features, close to the
8920 historical Bourne shell.
ccc6cda3 8921
bb70624e
JA
8922 There are several `--enable-' options that alter how Bash is
8923compiled and linked, rather than changing run-time features.
ccc6cda3 8924
f73dda09
JA
8925`--enable-largefile'
8926 Enable support for large files
8927 (http://www.sas.com/standards/large_file/x_open.20Mar96.html) if
8928 the operating system requires special compiler options to build
7117c2d2
JA
8929 programs which can access large files. This is enabled by
8930 default, if the operating system provides large file support.
f73dda09 8931
bb70624e
JA
8932`--enable-profiling'
8933 This builds a Bash binary that produces profiling information to be
8934 processed by `gprof' each time it is executed.
cce855bc 8935
bb70624e
JA
8936`--enable-static-link'
8937 This causes Bash to be linked statically, if `gcc' is being used.
8938 This could be used to build a version to use as root's shell.
d166f048 8939
bb70624e
JA
8940 The `minimal-config' option can be used to disable all of the
8941following options, but it is processed first, so individual options may
8942be enabled using `enable-FEATURE'.
d166f048 8943
bb70624e
JA
8944 All of the following options except for `disabled-builtins' and
8945`xpg-echo-default' are enabled by default, unless the operating system
8946does not provide the necessary support.
ccc6cda3 8947
bb70624e
JA
8948`--enable-alias'
8949 Allow alias expansion and include the `alias' and `unalias'
28ef6c31 8950 builtins (*note Aliases::).
ccc6cda3 8951
bb70624e
JA
8952`--enable-arith-for-command'
8953 Include support for the alternate form of the `for' command that
8954 behaves like the C language `for' statement (*note Looping
28ef6c31 8955 Constructs::).
ccc6cda3 8956
bb70624e
JA
8957`--enable-array-variables'
8958 Include support for one-dimensional array shell variables (*note
28ef6c31 8959 Arrays::).
ccc6cda3 8960
bb70624e
JA
8961`--enable-bang-history'
8962 Include support for `csh'-like history substitution (*note History
28ef6c31 8963 Interaction::).
ccc6cda3 8964
bb70624e
JA
8965`--enable-brace-expansion'
8966 Include `csh'-like brace expansion ( `b{a,b}c' ==> `bac bbc' ).
6a8fd0ed 8967 See *note Brace Expansion::, for a complete description.
ccc6cda3 8968
09767ff0
CR
8969`--enable-casemod-attributes'
8970 Include support for case-modifying attributes in the `declare'
8971 builtin and assignment statements. Variables with the UPPERCASE
8972 attribute, for example, will have their values converted to
8973 uppercase upon assignment.
8974
8975`--enable-casemod-expansion'
8976 Include support for case-modifying word expansions.
8977
bb70624e
JA
8978`--enable-command-timing'
8979 Include support for recognizing `time' as a reserved word and for
8980 displaying timing statistics for the pipeline following `time'
28ef6c31 8981 (*note Pipelines::). This allows pipelines as well as shell
bb70624e 8982 builtins and functions to be timed.
ccc6cda3 8983
bb70624e 8984`--enable-cond-command'
5e13499c
CR
8985 Include support for the `[[' conditional command. (*note
8986 Conditional Constructs::).
8987
8988`--enable-cond-regexp'
8989 Include support for matching POSIX regular expressions using the
8990 `=~' binary operator in the `[[' conditional command. (*note
28ef6c31 8991 Conditional Constructs::).
ccc6cda3 8992
8e1a6eaa
CR
8993`--enable-coprocesses'
8994 Include support for coprocesses and the `coproc' reserved word
8995 (*note Pipelines::).
8996
01ed5ba4
CR
8997`--enable-debugger'
8998 Include support for the bash debugger (distributed separately).
8999
bb70624e
JA
9000`--enable-directory-stack'
9001 Include support for a `csh'-like directory stack and the `pushd',
28ef6c31 9002 `popd', and `dirs' builtins (*note The Directory Stack::).
ccc6cda3 9003
bb70624e
JA
9004`--enable-disabled-builtins'
9005 Allow builtin commands to be invoked via `builtin xxx' even after
6a8fd0ed 9006 `xxx' has been disabled using `enable -n xxx'. See *note Bash
bb70624e
JA
9007 Builtins::, for details of the `builtin' and `enable' builtin
9008 commands.
ccc6cda3 9009
bb70624e
JA
9010`--enable-dparen-arithmetic'
9011 Include support for the `((...))' command (*note Conditional
28ef6c31 9012 Constructs::).
ccc6cda3 9013
bb70624e
JA
9014`--enable-extended-glob'
9015 Include support for the extended pattern matching features
6a8fd0ed 9016 described above under *note Pattern Matching::.
ccc6cda3 9017
8f714a7c
CR
9018`--enable-extended-glob-default'
9019 Set the default value of the EXTGLOB shell option described above
9020 under *note The Shopt Builtin:: to be enabled.
9021
bb70624e
JA
9022`--enable-help-builtin'
9023 Include the `help' builtin, which displays help on shell builtins
28ef6c31 9024 and variables (*note Bash Builtins::).
ccc6cda3 9025
bb70624e
JA
9026`--enable-history'
9027 Include command history and the `fc' and `history' builtin
28ef6c31 9028 commands (*note Bash History Facilities::).
ccc6cda3 9029
bb70624e 9030`--enable-job-control'
28ef6c31 9031 This enables the job control features (*note Job Control::), if
bb70624e 9032 the operating system supports them.
ccc6cda3 9033
d3a24ed2
CR
9034`--enable-multibyte'
9035 This enables support for multibyte characters if the operating
9036 system provides the necessary support.
9037
bb70624e
JA
9038`--enable-net-redirections'
9039 This enables the special handling of filenames of the form
9040 `/dev/tcp/HOST/PORT' and `/dev/udp/HOST/PORT' when used in
28ef6c31 9041 redirections (*note Redirections::).
ccc6cda3 9042
bb70624e 9043`--enable-process-substitution'
28ef6c31
JA
9044 This enables process substitution (*note Process Substitution::) if
9045 the operating system provides the necessary support.
ccc6cda3 9046
01ed5ba4
CR
9047`--enable-progcomp'
9048 Enable the programmable completion facilities (*note Programmable
9049 Completion::). If Readline is not enabled, this option has no
9050 effect.
9051
bb70624e
JA
9052`--enable-prompt-string-decoding'
9053 Turn on the interpretation of a number of backslash-escaped
9054 characters in the `$PS1', `$PS2', `$PS3', and `$PS4' prompt
122f603c
CR
9055 strings. See *note Controlling the Prompt::, for a complete list
9056 of prompt string escape sequences.
ccc6cda3 9057
bb70624e
JA
9058`--enable-readline'
9059 Include support for command-line editing and history with the Bash
28ef6c31 9060 version of the Readline library (*note Command Line Editing::).
ccc6cda3 9061
bb70624e
JA
9062`--enable-restricted'
9063 Include support for a "restricted shell". If this is enabled,
6a8fd0ed 9064 Bash, when called as `rbash', enters a restricted mode. See *note
bb70624e 9065 The Restricted Shell::, for a description of restricted mode.
ccc6cda3 9066
bb70624e 9067`--enable-select'
54a1fa7c
CR
9068 Include the `select' compound command, which allows the generation
9069 of simple menus (*note Conditional Constructs::).
ccc6cda3 9070
01ed5ba4
CR
9071`--enable-separate-helpfiles'
9072 Use external files for the documentation displayed by the `help'
9073 builtin instead of storing the text internally.
9074
9075`--enable-single-help-strings'
9076 Store the text displayed by the `help' builtin as a single string
9077 for each help topic. This aids in translating the text to
9078 different languages. You may need to disable this if your
9079 compiler cannot handle very long string literals.
9080
1c72c0cd
CR
9081`--enable-strict-posix-default'
9082 Make Bash POSIX-conformant by default (*note Bash POSIX Mode::).
9083
bb70624e
JA
9084`--enable-usg-echo-default'
9085 A synonym for `--enable-xpg-echo-default'.
ccc6cda3 9086
bb70624e
JA
9087`--enable-xpg-echo-default'
9088 Make the `echo' builtin expand backslash-escaped characters by
9089 default, without requiring the `-e' option. This sets the default
9090 value of the `xpg_echo' shell option to `on', which makes the Bash
9091 `echo' behave more like the version specified in the Single Unix
01ed5ba4 9092 Specification, version 3. *Note Bash Builtins::, for a
bb70624e 9093 description of the escape sequences that `echo' recognizes.
ccc6cda3 9094
bb70624e
JA
9095 The file `config-top.h' contains C Preprocessor `#define' statements
9096for options which are not settable from `configure'. Some of these are
9097not meant to be changed; beware of the consequences if you do. Read
9098the comments associated with each definition for more information about
9099its effect.
ccc6cda3 9100
bb70624e
JA
9101\1f
9102File: bashref.info, Node: Reporting Bugs, Next: Major Differences From The Bourne Shell, Prev: Installing Bash, Up: Top
d166f048 9103
37c41ab1
CR
9104Appendix A Reporting Bugs
9105*************************
ccc6cda3 9106
37c41ab1 9107Please report all bugs you find in Bash. But first, you should make
bb70624e 9108sure that it really is a bug, and that it appears in the latest version
d3a24ed2 9109of Bash. The latest version of Bash is always available for FTP from
4a8bb13f 9110`ftp://ftp.gnu.org/pub/gnu/bash/'.
ccc6cda3 9111
bb70624e
JA
9112 Once you have determined that a bug actually exists, use the
9113`bashbug' command to submit a bug report. If you have a fix, you are
9114encouraged to mail that as well! Suggestions and `philosophical' bug
9115reports may be mailed to <bug-bash@gnu.org> or posted to the Usenet
9116newsgroup `gnu.bash.bug'.
ccc6cda3 9117
bb70624e
JA
9118 All bug reports should include:
9119 * The version number of Bash.
ccc6cda3 9120
bb70624e 9121 * The hardware and operating system.
ccc6cda3 9122
bb70624e 9123 * The compiler used to compile Bash.
ccc6cda3 9124
bb70624e 9125 * A description of the bug behaviour.
ccc6cda3 9126
bb70624e
JA
9127 * A short script or `recipe' which exercises the bug and may be used
9128 to reproduce it.
ccc6cda3 9129
bb70624e
JA
9130`bashbug' inserts the first three items automatically into the template
9131it provides for filing a bug report.
9132
6932f7f5
CR
9133 Please send all reports concerning this manual to
9134<chet.ramey@case.edu>.
ccc6cda3
JA
9135
9136\1f
c2a47ea9 9137File: bashref.info, Node: Major Differences From The Bourne Shell, Next: GNU Free Documentation License, Prev: Reporting Bugs, Up: Top
ccc6cda3 9138
37c41ab1
CR
9139Appendix B Major Differences From The Bourne Shell
9140**************************************************
ccc6cda3 9141
37c41ab1 9142Bash implements essentially the same grammar, parameter and variable
bb70624e 9143expansion, redirection, and quoting as the Bourne Shell. Bash uses the
ac18b312
CR
9144POSIX standard as the specification of how these features are to be
9145implemented. There are some differences between the traditional Bourne
9146shell and Bash; this section quickly details the differences of
bb70624e
JA
9147significance. A number of these differences are explained in greater
9148depth in previous sections. This section uses the version of `sh'
1c72c0cd
CR
9149included in SVR4.2 (the last version of the historical Bourne shell) as
9150the baseline reference.
ccc6cda3 9151
bb70624e 9152 * Bash is POSIX-conformant, even where the POSIX specification
28ef6c31 9153 differs from traditional `sh' behavior (*note Bash POSIX Mode::).
ccc6cda3 9154
bb70624e 9155 * Bash has multi-character invocation options (*note Invoking
28ef6c31 9156 Bash::).
ccc6cda3 9157
28ef6c31 9158 * Bash has command-line editing (*note Command Line Editing::) and
bb70624e 9159 the `bind' builtin.
ccc6cda3 9160
bb70624e 9161 * Bash provides a programmable word completion mechanism (*note
6a8fd0ed
CR
9162 Programmable Completion::), and builtin commands `complete',
9163 `compgen', and `compopt', to manipulate it.
ccc6cda3 9164
28ef6c31 9165 * Bash has command history (*note Bash History Facilities::) and the
5e13499c
CR
9166 `history' and `fc' builtins to manipulate it. The Bash history
9167 list maintains timestamp information and uses the value of the
9168 `HISTTIMEFORMAT' variable to display it.
ccc6cda3 9169
bb70624e 9170 * Bash implements `csh'-like history expansion (*note History
28ef6c31 9171 Interaction::).
ccc6cda3 9172
28ef6c31 9173 * Bash has one-dimensional array variables (*note Arrays::), and the
bb70624e
JA
9174 appropriate variable expansions and assignment syntax to use them.
9175 Several of the Bash builtins take options to act on arrays. Bash
9176 provides a number of built-in array variables.
ccc6cda3 9177
bb70624e
JA
9178 * The `$'...'' quoting syntax, which expands ANSI-C
9179 backslash-escaped characters in the text between the single quotes,
28ef6c31 9180 is supported (*note ANSI-C Quoting::).
ccc6cda3 9181
bb70624e
JA
9182 * Bash supports the `$"..."' quoting syntax to do locale-specific
9183 translation of the characters between the double quotes. The
9184 `-D', `--dump-strings', and `--dump-po-strings' invocation options
9185 list the translatable strings found in a script (*note Locale
28ef6c31 9186 Translation::).
ccc6cda3 9187
bb70624e 9188 * Bash implements the `!' keyword to negate the return value of a
28ef6c31 9189 pipeline (*note Pipelines::). Very useful when an `if' statement
1c72c0cd
CR
9190 needs to act only if a test fails. The Bash `-o pipefail' option
9191 to `set' will cause a pipeline to return a failure status if any
9192 command fails.
ccc6cda3 9193
bb70624e 9194 * Bash has the `time' reserved word and command timing (*note
28ef6c31 9195 Pipelines::). The display of the timing statistics may be
bb70624e 9196 controlled with the `TIMEFORMAT' variable.
ccc6cda3 9197
bb70624e
JA
9198 * Bash implements the `for (( EXPR1 ; EXPR2 ; EXPR3 ))' arithmetic
9199 for command, similar to the C language (*note Looping
28ef6c31 9200 Constructs::).
ccc6cda3 9201
bb70624e 9202 * Bash includes the `select' compound command, which allows the
28ef6c31 9203 generation of simple menus (*note Conditional Constructs::).
ccc6cda3 9204
bb70624e 9205 * Bash includes the `[[' compound command, which makes conditional
1c72c0cd
CR
9206 testing part of the shell grammar (*note Conditional
9207 Constructs::), including optional regular expression matching.
9208
9209 * Bash provides optional case-insensitive matching for the `case' and
9210 `[[' constructs.
ccc6cda3 9211
28ef6c31
JA
9212 * Bash includes brace expansion (*note Brace Expansion::) and tilde
9213 expansion (*note Tilde Expansion::).
ccc6cda3 9214
bb70624e 9215 * Bash implements command aliases and the `alias' and `unalias'
28ef6c31 9216 builtins (*note Aliases::).
ccc6cda3 9217
bb70624e 9218 * Bash provides shell arithmetic, the `((' compound command (*note
28ef6c31
JA
9219 Conditional Constructs::), and arithmetic expansion (*note Shell
9220 Arithmetic::).
ccc6cda3 9221
bb70624e
JA
9222 * Variables present in the shell's initial environment are
9223 automatically exported to child processes. The Bourne shell does
9224 not normally do this unless the variables are explicitly marked
9225 using the `export' command.
ccc6cda3 9226
1c72c0cd
CR
9227 * Bash supports the `+=' assignment operator, which appends to the
9228 value of the variable named on the left hand side.
9229
bb70624e
JA
9230 * Bash includes the POSIX pattern removal `%', `#', `%%' and `##'
9231 expansions to remove leading or trailing substrings from variable
28ef6c31 9232 values (*note Shell Parameter Expansion::).
ccc6cda3 9233
bb70624e 9234 * The expansion `${#xx}', which returns the length of `${xx}', is
28ef6c31 9235 supported (*note Shell Parameter Expansion::).
ccc6cda3 9236
bb70624e
JA
9237 * The expansion `${var:'OFFSET`[:'LENGTH`]}', which expands to the
9238 substring of `var''s value of length LENGTH, beginning at OFFSET,
28ef6c31 9239 is present (*note Shell Parameter Expansion::).
ccc6cda3 9240
bb70624e
JA
9241 * The expansion `${var/[/]'PATTERN`[/'REPLACEMENT`]}', which matches
9242 PATTERN and replaces it with REPLACEMENT in the value of `var', is
28ef6c31 9243 available (*note Shell Parameter Expansion::).
ccc6cda3 9244
bb70624e
JA
9245 * The expansion `${!PREFIX}*' expansion, which expands to the names
9246 of all shell variables whose names begin with PREFIX, is available
28ef6c31 9247 (*note Shell Parameter Expansion::).
ccc6cda3 9248
bb70624e 9249 * Bash has INDIRECT variable expansion using `${!word}' (*note Shell
28ef6c31 9250 Parameter Expansion::).
ccc6cda3 9251
bb70624e 9252 * Bash can expand positional parameters beyond `$9' using `${NUM}'.
ccc6cda3 9253
bb70624e 9254 * The POSIX `$()' form of command substitution is implemented (*note
28ef6c31 9255 Command Substitution::), and preferred to the Bourne shell's ```'
bb70624e 9256 (which is also implemented for backwards compatibility).
ccc6cda3 9257
28ef6c31 9258 * Bash has process substitution (*note Process Substitution::).
ccc6cda3 9259
bb70624e
JA
9260 * Bash automatically assigns variables that provide information
9261 about the current user (`UID', `EUID', and `GROUPS'), the current
9262 host (`HOSTTYPE', `OSTYPE', `MACHTYPE', and `HOSTNAME'), and the
9263 instance of Bash that is running (`BASH', `BASH_VERSION', and
9264 `BASH_VERSINFO'). *Note Bash Variables::, for details.
ccc6cda3 9265
bb70624e 9266 * The `IFS' variable is used to split only the results of expansion,
28ef6c31 9267 not all words (*note Word Splitting::). This closes a
bb70624e 9268 longstanding shell security hole.
ccc6cda3 9269
ac18b312
CR
9270 * Bash implements the full set of POSIX filename expansion operators,
9271 including CHARACTER CLASSES, EQUIVALENCE CLASSES, and COLLATING
9272 SYMBOLS (*note Filename Expansion::).
ccc6cda3 9273
bb70624e 9274 * Bash implements extended pattern matching features when the
28ef6c31 9275 `extglob' shell option is enabled (*note Pattern Matching::).
ccc6cda3 9276
bb70624e
JA
9277 * It is possible to have a variable and a function with the same
9278 name; `sh' does not separate the two name spaces.
ccc6cda3 9279
bb70624e
JA
9280 * Bash functions are permitted to have local variables using the
9281 `local' builtin, and thus useful recursive functions may be written
28ef6c31 9282 (*note Bash Builtins::).
ccc6cda3 9283
bb70624e 9284 * Variable assignments preceding commands affect only that command,
28ef6c31 9285 even builtins and functions (*note Environment::). In `sh', all
bb70624e
JA
9286 variable assignments preceding commands are global unless the
9287 command is executed from the file system.
ccc6cda3 9288
bb70624e 9289 * Bash performs filename expansion on filenames specified as operands
28ef6c31 9290 to input and output redirection operators (*note Redirections::).
ccc6cda3 9291
bb70624e
JA
9292 * Bash contains the `<>' redirection operator, allowing a file to be
9293 opened for both reading and writing, and the `&>' redirection
9294 operator, for directing standard output and standard error to the
28ef6c31 9295 same file (*note Redirections::).
d166f048 9296
1c72c0cd
CR
9297 * Bash includes the `<<<' redirection operator, allowing a string to
9298 be used as the standard input to a command.
9299
9300 * Bash implements the `[n]<&WORD' and `[n]>&WORD' redirection
9301 operators, which move one file descriptor to another.
9302
bb70624e 9303 * Bash treats a number of filenames specially when they are used in
28ef6c31 9304 redirection operators (*note Redirections::).
ccc6cda3 9305
bb70624e 9306 * Bash can open network connections to arbitrary machines and
28ef6c31 9307 services with the redirection operators (*note Redirections::).
ccc6cda3 9308
bb70624e 9309 * The `noclobber' option is available to avoid overwriting existing
28ef6c31
JA
9310 files with output redirection (*note The Set Builtin::). The `>|'
9311 redirection operator may be used to override `noclobber'.
ccc6cda3 9312
28ef6c31
JA
9313 * The Bash `cd' and `pwd' builtins (*note Bourne Shell Builtins::)
9314 each take `-L' and `-P' options to switch between logical and
bb70624e 9315 physical modes.
b72432fd 9316
bb70624e
JA
9317 * Bash allows a function to override a builtin with the same name,
9318 and provides access to that builtin's functionality within the
9319 function via the `builtin' and `command' builtins (*note Bash
28ef6c31 9320 Builtins::).
ccc6cda3 9321
bb70624e 9322 * The `command' builtin allows selective disabling of functions when
28ef6c31 9323 command lookup is performed (*note Bash Builtins::).
ccc6cda3 9324
bb70624e 9325 * Individual builtins may be enabled or disabled using the `enable'
28ef6c31 9326 builtin (*note Bash Builtins::).
cce855bc 9327
bb70624e
JA
9328 * The Bash `exec' builtin takes additional options that allow users
9329 to control the contents of the environment passed to the executed
9330 command, and what the zeroth argument to the command is to be
28ef6c31 9331 (*note Bourne Shell Builtins::).
cce855bc 9332
bb70624e 9333 * Shell functions may be exported to children via the environment
28ef6c31 9334 using `export -f' (*note Shell Functions::).
cce855bc 9335
bb70624e
JA
9336 * The Bash `export', `readonly', and `declare' builtins can take a
9337 `-f' option to act on shell functions, a `-p' option to display
9338 variables with various attributes set in a format that can be used
9339 as shell input, a `-n' option to remove various variable
9340 attributes, and `name=value' arguments to set variable attributes
9341 and values simultaneously.
ccc6cda3 9342
bb70624e
JA
9343 * The Bash `hash' builtin allows a name to be associated with an
9344 arbitrary filename, even when that filename cannot be found by
9345 searching the `$PATH', using `hash -p' (*note Bourne Shell
28ef6c31 9346 Builtins::).
ccc6cda3 9347
bb70624e 9348 * Bash includes a `help' builtin for quick reference to shell
28ef6c31 9349 facilities (*note Bash Builtins::).
ccc6cda3 9350
bb70624e 9351 * The `printf' builtin is available to display formatted output
28ef6c31 9352 (*note Bash Builtins::).
ccc6cda3 9353
28ef6c31 9354 * The Bash `read' builtin (*note Bash Builtins::) will read a line
bb70624e
JA
9355 ending in `\' with the `-r' option, and will use the `REPLY'
9356 variable as a default if no non-option arguments are supplied.
9357 The Bash `read' builtin also accepts a prompt string with the `-p'
9358 option and will use Readline to obtain the line when given the
9359 `-e' option. The `read' builtin also has additional options to
9360 control input: the `-s' option will turn off echoing of input
9361 characters as they are read, the `-t' option will allow `read' to
9362 time out if input does not arrive within a specified number of
9363 seconds, the `-n' option will allow reading only a specified
9364 number of characters rather than a full line, and the `-d' option
9365 will read until a particular character rather than newline.
ccc6cda3 9366
bb70624e
JA
9367 * The `return' builtin may be used to abort execution of scripts
9368 executed with the `.' or `source' builtins (*note Bourne Shell
28ef6c31 9369 Builtins::).
d166f048 9370
bb70624e 9371 * Bash includes the `shopt' builtin, for finer control of shell
d3ad40de
CR
9372 optional capabilities (*note The Shopt Builtin::), and allows
9373 these options to be set and unset at shell invocation (*note
9374 Invoking Bash::).
d166f048 9375
bb70624e 9376 * Bash has much more optional behavior controllable with the `set'
28ef6c31 9377 builtin (*note The Set Builtin::).
cce855bc 9378
5e13499c
CR
9379 * The `-x' (`xtrace') option displays commands other than simple
9380 commands when performing an execution trace (*note The Set
9381 Builtin::).
9382
28ef6c31 9383 * The `test' builtin (*note Bourne Shell Builtins::) is slightly
bb70624e
JA
9384 different, as it implements the POSIX algorithm, which specifies
9385 the behavior based on the number of arguments.
ccc6cda3 9386
5e13499c
CR
9387 * Bash includes the `caller' builtin, which displays the context of
9388 any active subroutine call (a shell function or a script executed
9389 with the `.' or `source' builtins). This supports the bash
9390 debugger.
9391
28ef6c31 9392 * The `trap' builtin (*note Bourne Shell Builtins::) allows a
bb70624e 9393 `DEBUG' pseudo-signal specification, similar to `EXIT'. Commands
d3a24ed2
CR
9394 specified with a `DEBUG' trap are executed before every simple
9395 command, `for' command, `case' command, `select' command, every
9396 arithmetic `for' command, and before the first command executes in
9397 a shell function. The `DEBUG' trap is not inherited by shell
9398 functions unless the function has been given the `trace' attribute
9399 or the `functrace' option has been enabled using the `shopt'
9400 builtin. The `extdebug' shell option has additional effects on the
9401 `DEBUG' trap.
d166f048 9402
f73dda09
JA
9403 The `trap' builtin (*note Bourne Shell Builtins::) allows an `ERR'
9404 pseudo-signal specification, similar to `EXIT' and `DEBUG'.
9405 Commands specified with an `ERR' trap are executed after a simple
9406 command fails, with a few exceptions. The `ERR' trap is not
d3a24ed2
CR
9407 inherited by shell functions unless the `-o errtrace' option to
9408 the `set' builtin is enabled.
9409
9410 The `trap' builtin (*note Bourne Shell Builtins::) allows a
9411 `RETURN' pseudo-signal specification, similar to `EXIT' and
9412 `DEBUG'. Commands specified with an `RETURN' trap are executed
9413 before execution resumes after a shell function or a shell script
9414 executed with `.' or `source' returns. The `RETURN' trap is not
8fed3589
CR
9415 inherited by shell functions unless the function has been given
9416 the `trace' attribute or the `functrace' option has been enabled
9417 using the `shopt' builtin.
f73dda09 9418
bb70624e 9419 * The Bash `type' builtin is more extensive and gives more
28ef6c31 9420 information about the names it finds (*note Bash Builtins::).
cce855bc 9421
bb70624e
JA
9422 * The Bash `umask' builtin permits a `-p' option to cause the output
9423 to be displayed in the form of a `umask' command that may be
28ef6c31 9424 reused as input (*note Bourne Shell Builtins::).
d166f048 9425
bb70624e
JA
9426 * Bash implements a `csh'-like directory stack, and provides the
9427 `pushd', `popd', and `dirs' builtins to manipulate it (*note The
28ef6c31 9428 Directory Stack::). Bash also makes the directory stack visible
bb70624e 9429 as the value of the `DIRSTACK' shell variable.
d166f048 9430
bb70624e 9431 * Bash interprets special backslash-escaped characters in the prompt
122f603c 9432 strings when interactive (*note Controlling the Prompt::).
d166f048 9433
bb70624e 9434 * The Bash restricted mode is more useful (*note The Restricted
28ef6c31 9435 Shell::); the SVR4.2 shell restricted mode is too limited.
ccc6cda3 9436
bb70624e 9437 * The `disown' builtin can remove a job from the internal shell job
28ef6c31 9438 table (*note Job Control Builtins::) or suppress the sending of
bb70624e 9439 `SIGHUP' to a job when the shell exits as the result of a `SIGHUP'.
ccc6cda3 9440
1c72c0cd
CR
9441 * Bash includes a number of features to support a separate debugger
9442 for shell scripts.
9443
bb70624e
JA
9444 * The SVR4.2 shell has two privilege-related builtins (`mldmode' and
9445 `priv') not present in Bash.
ccc6cda3 9446
bb70624e 9447 * Bash does not have the `stop' or `newgrp' builtins.
d166f048 9448
bb70624e
JA
9449 * Bash does not use the `SHACCT' variable or perform shell
9450 accounting.
d166f048 9451
bb70624e 9452 * The SVR4.2 `sh' uses a `TIMEOUT' variable like Bash uses `TMOUT'.
ccc6cda3 9453
28ef6c31 9454
6a8fd0ed 9455More features unique to Bash may be found in *note Bash Features::.
ccc6cda3 9456
37c41ab1
CR
9457B.1 Implementation Differences From The SVR4.2 Shell
9458====================================================
ccc6cda3 9459
37c41ab1
CR
9460Since Bash is a completely new implementation, it does not suffer from
9461many of the limitations of the SVR4.2 shell. For instance:
ccc6cda3 9462
bb70624e
JA
9463 * Bash does not fork a subshell when redirecting into or out of a
9464 shell control structure such as an `if' or `while' statement.
ccc6cda3 9465
bb70624e
JA
9466 * Bash does not allow unbalanced quotes. The SVR4.2 shell will
9467 silently insert a needed closing quote at `EOF' under certain
9468 circumstances. This can be the cause of some hard-to-find errors.
ccc6cda3 9469
bb70624e
JA
9470 * The SVR4.2 shell uses a baroque memory management scheme based on
9471 trapping `SIGSEGV'. If the shell is started from a process with
9472 `SIGSEGV' blocked (e.g., by using the `system()' C library
9473 function call), it misbehaves badly.
ccc6cda3 9474
bb70624e
JA
9475 * In a questionable attempt at security, the SVR4.2 shell, when
9476 invoked without the `-p' option, will alter its real and effective
9477 UID and GID if they are less than some magic threshold value,
9478 commonly 100. This can lead to unexpected results.
ccc6cda3 9479
bb70624e
JA
9480 * The SVR4.2 shell does not allow users to trap `SIGSEGV',
9481 `SIGALRM', or `SIGCHLD'.
ccc6cda3 9482
bb70624e
JA
9483 * The SVR4.2 shell does not allow the `IFS', `MAILCHECK', `PATH',
9484 `PS1', or `PS2' variables to be unset.
ccc6cda3 9485
bb70624e 9486 * The SVR4.2 shell treats `^' as the undocumented equivalent of `|'.
ccc6cda3 9487
bb70624e
JA
9488 * Bash allows multiple option arguments when it is invoked (`-x -v');
9489 the SVR4.2 shell allows only one option argument (`-xv'). In
9490 fact, some versions of the shell dump core if the second argument
9491 begins with a `-'.
ccc6cda3 9492
bb70624e 9493 * The SVR4.2 shell exits a script if any builtin fails; Bash exits a
ac18b312
CR
9494 script only if one of the POSIX special builtins fails, and only
9495 for certain failures, as enumerated in the POSIX standard.
ccc6cda3 9496
bb70624e
JA
9497 * The SVR4.2 shell behaves differently when invoked as `jsh' (it
9498 turns on job control).
ccc6cda3
JA
9499
9500\1f
c2a47ea9 9501File: bashref.info, Node: GNU Free Documentation License, Next: Indexes, Prev: Major Differences From The Bourne Shell, Up: Top
d3a24ed2 9502
c2a47ea9
CR
9503Appendix C GNU Free Documentation License
9504*****************************************
d3a24ed2 9505
1231ac47 9506 Version 1.3, 3 November 2008
37c41ab1 9507
1231ac47
CR
9508 Copyright (C) 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
9509 `http://fsf.org/'
37c41ab1 9510
d3a24ed2
CR
9511 Everyone is permitted to copy and distribute verbatim copies
9512 of this license document, but changing it is not allowed.
9513
9514 0. PREAMBLE
9515
9516 The purpose of this License is to make a manual, textbook, or other
9517 functional and useful document "free" in the sense of freedom: to
9518 assure everyone the effective freedom to copy and redistribute it,
9519 with or without modifying it, either commercially or
9520 noncommercially. Secondarily, this License preserves for the
9521 author and publisher a way to get credit for their work, while not
9522 being considered responsible for modifications made by others.
9523
9524 This License is a kind of "copyleft", which means that derivative
9525 works of the document must themselves be free in the same sense.
9526 It complements the GNU General Public License, which is a copyleft
9527 license designed for free software.
9528
9529 We have designed this License in order to use it for manuals for
9530 free software, because free software needs free documentation: a
9531 free program should come with manuals providing the same freedoms
9532 that the software does. But this License is not limited to
9533 software manuals; it can be used for any textual work, regardless
9534 of subject matter or whether it is published as a printed book.
9535 We recommend this License principally for works whose purpose is
9536 instruction or reference.
9537
9538 1. APPLICABILITY AND DEFINITIONS
9539
9540 This License applies to any manual or other work, in any medium,
9541 that contains a notice placed by the copyright holder saying it
9542 can be distributed under the terms of this License. Such a notice
9543 grants a world-wide, royalty-free license, unlimited in duration,
9544 to use that work under the conditions stated herein. The
9545 "Document", below, refers to any such manual or work. Any member
9546 of the public is a licensee, and is addressed as "you". You
9547 accept the license if you copy, modify or distribute the work in a
9548 way requiring permission under copyright law.
9549
9550 A "Modified Version" of the Document means any work containing the
9551 Document or a portion of it, either copied verbatim, or with
9552 modifications and/or translated into another language.
9553
9554 A "Secondary Section" is a named appendix or a front-matter section
9555 of the Document that deals exclusively with the relationship of the
9556 publishers or authors of the Document to the Document's overall
9557 subject (or to related matters) and contains nothing that could
9558 fall directly within that overall subject. (Thus, if the Document
9559 is in part a textbook of mathematics, a Secondary Section may not
9560 explain any mathematics.) The relationship could be a matter of
9561 historical connection with the subject or with related matters, or
9562 of legal, commercial, philosophical, ethical or political position
9563 regarding them.
9564
9565 The "Invariant Sections" are certain Secondary Sections whose
9566 titles are designated, as being those of Invariant Sections, in
9567 the notice that says that the Document is released under this
9568 License. If a section does not fit the above definition of
9569 Secondary then it is not allowed to be designated as Invariant.
9570 The Document may contain zero Invariant Sections. If the Document
9571 does not identify any Invariant Sections then there are none.
9572
9573 The "Cover Texts" are certain short passages of text that are
9574 listed, as Front-Cover Texts or Back-Cover Texts, in the notice
9575 that says that the Document is released under this License. A
9576 Front-Cover Text may be at most 5 words, and a Back-Cover Text may
9577 be at most 25 words.
9578
9579 A "Transparent" copy of the Document means a machine-readable copy,
9580 represented in a format whose specification is available to the
9581 general public, that is suitable for revising the document
9582 straightforwardly with generic text editors or (for images
9583 composed of pixels) generic paint programs or (for drawings) some
9584 widely available drawing editor, and that is suitable for input to
9585 text formatters or for automatic translation to a variety of
9586 formats suitable for input to text formatters. A copy made in an
9587 otherwise Transparent file format whose markup, or absence of
9588 markup, has been arranged to thwart or discourage subsequent
9589 modification by readers is not Transparent. An image format is
9590 not Transparent if used for any substantial amount of text. A
9591 copy that is not "Transparent" is called "Opaque".
9592
9593 Examples of suitable formats for Transparent copies include plain
9594 ASCII without markup, Texinfo input format, LaTeX input format,
9595 SGML or XML using a publicly available DTD, and
9596 standard-conforming simple HTML, PostScript or PDF designed for
9597 human modification. Examples of transparent image formats include
9598 PNG, XCF and JPG. Opaque formats include proprietary formats that
9599 can be read and edited only by proprietary word processors, SGML or
9600 XML for which the DTD and/or processing tools are not generally
9601 available, and the machine-generated HTML, PostScript or PDF
9602 produced by some word processors for output purposes only.
9603
9604 The "Title Page" means, for a printed book, the title page itself,
9605 plus such following pages as are needed to hold, legibly, the
9606 material this License requires to appear in the title page. For
9607 works in formats which do not have any title page as such, "Title
9608 Page" means the text near the most prominent appearance of the
9609 work's title, preceding the beginning of the body of the text.
9610
1231ac47
CR
9611 The "publisher" means any person or entity that distributes copies
9612 of the Document to the public.
9613
d3a24ed2
CR
9614 A section "Entitled XYZ" means a named subunit of the Document
9615 whose title either is precisely XYZ or contains XYZ in parentheses
9616 following text that translates XYZ in another language. (Here XYZ
9617 stands for a specific section name mentioned below, such as
9618 "Acknowledgements", "Dedications", "Endorsements", or "History".)
9619 To "Preserve the Title" of such a section when you modify the
9620 Document means that it remains a section "Entitled XYZ" according
9621 to this definition.
9622
9623 The Document may include Warranty Disclaimers next to the notice
9624 which states that this License applies to the Document. These
9625 Warranty Disclaimers are considered to be included by reference in
9626 this License, but only as regards disclaiming warranties: any other
9627 implication that these Warranty Disclaimers may have is void and
9628 has no effect on the meaning of this License.
9629
9630 2. VERBATIM COPYING
9631
9632 You may copy and distribute the Document in any medium, either
9633 commercially or noncommercially, provided that this License, the
9634 copyright notices, and the license notice saying this License
9635 applies to the Document are reproduced in all copies, and that you
9636 add no other conditions whatsoever to those of this License. You
9637 may not use technical measures to obstruct or control the reading
9638 or further copying of the copies you make or distribute. However,
9639 you may accept compensation in exchange for copies. If you
9640 distribute a large enough number of copies you must also follow
9641 the conditions in section 3.
9642
9643 You may also lend copies, under the same conditions stated above,
9644 and you may publicly display copies.
9645
9646 3. COPYING IN QUANTITY
9647
9648 If you publish printed copies (or copies in media that commonly
9649 have printed covers) of the Document, numbering more than 100, and
9650 the Document's license notice requires Cover Texts, you must
9651 enclose the copies in covers that carry, clearly and legibly, all
9652 these Cover Texts: Front-Cover Texts on the front cover, and
9653 Back-Cover Texts on the back cover. Both covers must also clearly
9654 and legibly identify you as the publisher of these copies. The
9655 front cover must present the full title with all words of the
9656 title equally prominent and visible. You may add other material
9657 on the covers in addition. Copying with changes limited to the
9658 covers, as long as they preserve the title of the Document and
9659 satisfy these conditions, can be treated as verbatim copying in
9660 other respects.
9661
9662 If the required texts for either cover are too voluminous to fit
9663 legibly, you should put the first ones listed (as many as fit
9664 reasonably) on the actual cover, and continue the rest onto
9665 adjacent pages.
9666
9667 If you publish or distribute Opaque copies of the Document
9668 numbering more than 100, you must either include a
9669 machine-readable Transparent copy along with each Opaque copy, or
9670 state in or with each Opaque copy a computer-network location from
9671 which the general network-using public has access to download
9672 using public-standard network protocols a complete Transparent
9673 copy of the Document, free of added material. If you use the
9674 latter option, you must take reasonably prudent steps, when you
9675 begin distribution of Opaque copies in quantity, to ensure that
9676 this Transparent copy will remain thus accessible at the stated
9677 location until at least one year after the last time you
9678 distribute an Opaque copy (directly or through your agents or
9679 retailers) of that edition to the public.
9680
9681 It is requested, but not required, that you contact the authors of
9682 the Document well before redistributing any large number of
9683 copies, to give them a chance to provide you with an updated
9684 version of the Document.
9685
9686 4. MODIFICATIONS
9687
9688 You may copy and distribute a Modified Version of the Document
9689 under the conditions of sections 2 and 3 above, provided that you
9690 release the Modified Version under precisely this License, with
9691 the Modified Version filling the role of the Document, thus
9692 licensing distribution and modification of the Modified Version to
9693 whoever possesses a copy of it. In addition, you must do these
9694 things in the Modified Version:
9695
9696 A. Use in the Title Page (and on the covers, if any) a title
9697 distinct from that of the Document, and from those of
9698 previous versions (which should, if there were any, be listed
9699 in the History section of the Document). You may use the
9700 same title as a previous version if the original publisher of
9701 that version gives permission.
9702
9703 B. List on the Title Page, as authors, one or more persons or
9704 entities responsible for authorship of the modifications in
9705 the Modified Version, together with at least five of the
9706 principal authors of the Document (all of its principal
9707 authors, if it has fewer than five), unless they release you
9708 from this requirement.
9709
9710 C. State on the Title page the name of the publisher of the
9711 Modified Version, as the publisher.
9712
9713 D. Preserve all the copyright notices of the Document.
9714
9715 E. Add an appropriate copyright notice for your modifications
9716 adjacent to the other copyright notices.
9717
9718 F. Include, immediately after the copyright notices, a license
9719 notice giving the public permission to use the Modified
9720 Version under the terms of this License, in the form shown in
9721 the Addendum below.
9722
9723 G. Preserve in that license notice the full lists of Invariant
9724 Sections and required Cover Texts given in the Document's
9725 license notice.
9726
9727 H. Include an unaltered copy of this License.
9728
9729 I. Preserve the section Entitled "History", Preserve its Title,
9730 and add to it an item stating at least the title, year, new
9731 authors, and publisher of the Modified Version as given on
9732 the Title Page. If there is no section Entitled "History" in
9733 the Document, create one stating the title, year, authors,
9734 and publisher of the Document as given on its Title Page,
9735 then add an item describing the Modified Version as stated in
9736 the previous sentence.
9737
9738 J. Preserve the network location, if any, given in the Document
9739 for public access to a Transparent copy of the Document, and
9740 likewise the network locations given in the Document for
9741 previous versions it was based on. These may be placed in
9742 the "History" section. You may omit a network location for a
9743 work that was published at least four years before the
9744 Document itself, or if the original publisher of the version
9745 it refers to gives permission.
9746
9747 K. For any section Entitled "Acknowledgements" or "Dedications",
9748 Preserve the Title of the section, and preserve in the
9749 section all the substance and tone of each of the contributor
9750 acknowledgements and/or dedications given therein.
9751
9752 L. Preserve all the Invariant Sections of the Document,
9753 unaltered in their text and in their titles. Section numbers
9754 or the equivalent are not considered part of the section
9755 titles.
9756
9757 M. Delete any section Entitled "Endorsements". Such a section
9758 may not be included in the Modified Version.
9759
9760 N. Do not retitle any existing section to be Entitled
9761 "Endorsements" or to conflict in title with any Invariant
9762 Section.
9763
9764 O. Preserve any Warranty Disclaimers.
9765
9766 If the Modified Version includes new front-matter sections or
9767 appendices that qualify as Secondary Sections and contain no
9768 material copied from the Document, you may at your option
9769 designate some or all of these sections as invariant. To do this,
9770 add their titles to the list of Invariant Sections in the Modified
9771 Version's license notice. These titles must be distinct from any
9772 other section titles.
9773
9774 You may add a section Entitled "Endorsements", provided it contains
9775 nothing but endorsements of your Modified Version by various
9776 parties--for example, statements of peer review or that the text
9777 has been approved by an organization as the authoritative
9778 definition of a standard.
9779
9780 You may add a passage of up to five words as a Front-Cover Text,
9781 and a passage of up to 25 words as a Back-Cover Text, to the end
9782 of the list of Cover Texts in the Modified Version. Only one
9783 passage of Front-Cover Text and one of Back-Cover Text may be
9784 added by (or through arrangements made by) any one entity. If the
9785 Document already includes a cover text for the same cover,
9786 previously added by you or by arrangement made by the same entity
9787 you are acting on behalf of, you may not add another; but you may
9788 replace the old one, on explicit permission from the previous
9789 publisher that added the old one.
9790
9791 The author(s) and publisher(s) of the Document do not by this
9792 License give permission to use their names for publicity for or to
9793 assert or imply endorsement of any Modified Version.
9794
9795 5. COMBINING DOCUMENTS
9796
9797 You may combine the Document with other documents released under
9798 this License, under the terms defined in section 4 above for
9799 modified versions, provided that you include in the combination
9800 all of the Invariant Sections of all of the original documents,
9801 unmodified, and list them all as Invariant Sections of your
9802 combined work in its license notice, and that you preserve all
9803 their Warranty Disclaimers.
9804
9805 The combined work need only contain one copy of this License, and
9806 multiple identical Invariant Sections may be replaced with a single
9807 copy. If there are multiple Invariant Sections with the same name
9808 but different contents, make the title of each such section unique
9809 by adding at the end of it, in parentheses, the name of the
9810 original author or publisher of that section if known, or else a
9811 unique number. Make the same adjustment to the section titles in
9812 the list of Invariant Sections in the license notice of the
9813 combined work.
9814
9815 In the combination, you must combine any sections Entitled
9816 "History" in the various original documents, forming one section
9817 Entitled "History"; likewise combine any sections Entitled
9818 "Acknowledgements", and any sections Entitled "Dedications". You
9819 must delete all sections Entitled "Endorsements."
9820
9821 6. COLLECTIONS OF DOCUMENTS
9822
9823 You may make a collection consisting of the Document and other
9824 documents released under this License, and replace the individual
9825 copies of this License in the various documents with a single copy
9826 that is included in the collection, provided that you follow the
9827 rules of this License for verbatim copying of each of the
9828 documents in all other respects.
9829
9830 You may extract a single document from such a collection, and
9831 distribute it individually under this License, provided you insert
9832 a copy of this License into the extracted document, and follow
9833 this License in all other respects regarding verbatim copying of
9834 that document.
9835
9836 7. AGGREGATION WITH INDEPENDENT WORKS
9837
9838 A compilation of the Document or its derivatives with other
9839 separate and independent documents or works, in or on a volume of
9840 a storage or distribution medium, is called an "aggregate" if the
9841 copyright resulting from the compilation is not used to limit the
9842 legal rights of the compilation's users beyond what the individual
c2a47ea9 9843 works permit. When the Document is included in an aggregate, this
d3a24ed2
CR
9844 License does not apply to the other works in the aggregate which
9845 are not themselves derivative works of the Document.
9846
9847 If the Cover Text requirement of section 3 is applicable to these
9848 copies of the Document, then if the Document is less than one half
9849 of the entire aggregate, the Document's Cover Texts may be placed
9850 on covers that bracket the Document within the aggregate, or the
9851 electronic equivalent of covers if the Document is in electronic
9852 form. Otherwise they must appear on printed covers that bracket
9853 the whole aggregate.
9854
9855 8. TRANSLATION
9856
9857 Translation is considered a kind of modification, so you may
9858 distribute translations of the Document under the terms of section
9859 4. Replacing Invariant Sections with translations requires special
9860 permission from their copyright holders, but you may include
9861 translations of some or all Invariant Sections in addition to the
9862 original versions of these Invariant Sections. You may include a
9863 translation of this License, and all the license notices in the
9864 Document, and any Warranty Disclaimers, provided that you also
9865 include the original English version of this License and the
9866 original versions of those notices and disclaimers. In case of a
9867 disagreement between the translation and the original version of
9868 this License or a notice or disclaimer, the original version will
9869 prevail.
9870
9871 If a section in the Document is Entitled "Acknowledgements",
9872 "Dedications", or "History", the requirement (section 4) to
9873 Preserve its Title (section 1) will typically require changing the
9874 actual title.
9875
9876 9. TERMINATION
9877
9878 You may not copy, modify, sublicense, or distribute the Document
1231ac47
CR
9879 except as expressly provided under this License. Any attempt
9880 otherwise to copy, modify, sublicense, or distribute it is void,
9881 and will automatically terminate your rights under this License.
9882
9883 However, if you cease all violation of this License, then your
9884 license from a particular copyright holder is reinstated (a)
9885 provisionally, unless and until the copyright holder explicitly
9886 and finally terminates your license, and (b) permanently, if the
9887 copyright holder fails to notify you of the violation by some
9888 reasonable means prior to 60 days after the cessation.
9889
9890 Moreover, your license from a particular copyright holder is
9891 reinstated permanently if the copyright holder notifies you of the
9892 violation by some reasonable means, this is the first time you have
9893 received notice of violation of this License (for any work) from
9894 that copyright holder, and you cure the violation prior to 30 days
9895 after your receipt of the notice.
9896
9897 Termination of your rights under this section does not terminate
9898 the licenses of parties who have received copies or rights from
9899 you under this License. If your rights have been terminated and
9900 not permanently reinstated, receipt of a copy of some or all of
9901 the same material does not give you any rights to use it.
d3a24ed2
CR
9902
9903 10. FUTURE REVISIONS OF THIS LICENSE
9904
9905 The Free Software Foundation may publish new, revised versions of
9906 the GNU Free Documentation License from time to time. Such new
9907 versions will be similar in spirit to the present version, but may
9908 differ in detail to address new problems or concerns. See
9909 `http://www.gnu.org/copyleft/'.
9910
9911 Each version of the License is given a distinguishing version
9912 number. If the Document specifies that a particular numbered
9913 version of this License "or any later version" applies to it, you
9914 have the option of following the terms and conditions either of
9915 that specified version or of any later version that has been
9916 published (not as a draft) by the Free Software Foundation. If
9917 the Document does not specify a version number of this License,
9918 you may choose any version ever published (not as a draft) by the
1231ac47
CR
9919 Free Software Foundation. If the Document specifies that a proxy
9920 can decide which future versions of this License can be used, that
9921 proxy's public statement of acceptance of a version permanently
9922 authorizes you to choose that version for the Document.
9923
9924 11. RELICENSING
9925
9926 "Massive Multiauthor Collaboration Site" (or "MMC Site") means any
9927 World Wide Web server that publishes copyrightable works and also
9928 provides prominent facilities for anybody to edit those works. A
9929 public wiki that anybody can edit is an example of such a server.
9930 A "Massive Multiauthor Collaboration" (or "MMC") contained in the
9931 site means any set of copyrightable works thus published on the MMC
9932 site.
9933
9934 "CC-BY-SA" means the Creative Commons Attribution-Share Alike 3.0
9935 license published by Creative Commons Corporation, a not-for-profit
9936 corporation with a principal place of business in San Francisco,
9937 California, as well as future copyleft versions of that license
9938 published by that same organization.
9939
9940 "Incorporate" means to publish or republish a Document, in whole or
9941 in part, as part of another Document.
9942
9943 An MMC is "eligible for relicensing" if it is licensed under this
9944 License, and if all works that were first published under this
9945 License somewhere other than this MMC, and subsequently
9946 incorporated in whole or in part into the MMC, (1) had no cover
9947 texts or invariant sections, and (2) were thus incorporated prior
9948 to November 1, 2008.
9949
9950 The operator of an MMC Site may republish an MMC contained in the
9951 site under CC-BY-SA on the same site at any time before August 1,
9952 2009, provided the MMC is eligible for relicensing.
9953
d3a24ed2 9954
c2a47ea9
CR
9955ADDENDUM: How to use this License for your documents
9956====================================================
d3a24ed2 9957
37c41ab1 9958To use this License in a document you have written, include a copy of
d3a24ed2
CR
9959the License in the document and put the following copyright and license
9960notices just after the title page:
9961
9962 Copyright (C) YEAR YOUR NAME.
9963 Permission is granted to copy, distribute and/or modify this document
1231ac47 9964 under the terms of the GNU Free Documentation License, Version 1.3
d3a24ed2 9965 or any later version published by the Free Software Foundation;
c2a47ea9
CR
9966 with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
9967 Texts. A copy of the license is included in the section entitled ``GNU
d3a24ed2
CR
9968 Free Documentation License''.
9969
9970 If you have Invariant Sections, Front-Cover Texts and Back-Cover
9971Texts, replace the "with...Texts." line with this:
9972
9973 with the Invariant Sections being LIST THEIR TITLES, with
9974 the Front-Cover Texts being LIST, and with the Back-Cover Texts
9975 being LIST.
9976
9977 If you have Invariant Sections without Cover Texts, or some other
9978combination of the three, merge those two alternatives to suit the
9979situation.
9980
9981 If your document contains nontrivial examples of program code, we
9982recommend releasing these examples in parallel under your choice of
9983free software license, such as the GNU General Public License, to
9984permit their use in free software.
9985
9986\1f
c2a47ea9 9987File: bashref.info, Node: Indexes, Prev: GNU Free Documentation License, Up: Top
d3ad40de
CR
9988
9989Appendix D Indexes
9990******************
9991
9992* Menu:
9993
9994* Builtin Index:: Index of Bash builtin commands.
9995* Reserved Word Index:: Index of Bash reserved words.
9996* Variable Index:: Quick reference helps you find the
9997 variable you want.
9998* Function Index:: Index of bindable Readline functions.
9999* Concept Index:: General index for concepts described in
10000 this manual.
10001
10002\1f
10003File: bashref.info, Node: Builtin Index, Next: Reserved Word Index, Up: Indexes
5cfe250d 10004
d3ad40de
CR
10005D.1 Index of Shell Builtin Commands
10006===================================
ccc6cda3 10007
37c41ab1 10008\0\b[index\0\b]
ccc6cda3
JA
10009* Menu:
10010
e8ce775d 10011* .: Bourne Shell Builtins.
122f603c 10012 (line 17)
e8ce775d 10013* :: Bourne Shell Builtins.
37c41ab1 10014 (line 11)
e8ce775d 10015* [: Bourne Shell Builtins.
122f603c 10016 (line 240)
37c41ab1 10017* alias: Bash Builtins. (line 11)
e8ce775d 10018* bg: Job Control Builtins.
37c41ab1
CR
10019 (line 7)
10020* bind: Bash Builtins. (line 21)
e8ce775d 10021* break: Bourne Shell Builtins.
122f603c 10022 (line 31)
ed35cb4a 10023* builtin: Bash Builtins. (line 98)
122f603c 10024* caller: Bash Builtins. (line 107)
e8ce775d 10025* cd: Bourne Shell Builtins.
122f603c
CR
10026 (line 39)
10027* command: Bash Builtins. (line 125)
bb70624e 10028* compgen: Programmable Completion Builtins.
37c41ab1 10029 (line 10)
bb70624e 10030* complete: Programmable Completion Builtins.
37c41ab1 10031 (line 28)
6a8fd0ed 10032* compopt: Programmable Completion Builtins.
3eb2d94a 10033 (line 217)
e8ce775d 10034* continue: Bourne Shell Builtins.
122f603c
CR
10035 (line 63)
10036* declare: Bash Builtins. (line 145)
bb70624e 10037* dirs: Directory Stack Builtins.
37c41ab1 10038 (line 7)
e8ce775d 10039* disown: Job Control Builtins.
122f603c
CR
10040 (line 87)
10041* echo: Bash Builtins. (line 229)
10042* enable: Bash Builtins. (line 291)
e8ce775d 10043* eval: Bourne Shell Builtins.
122f603c 10044 (line 72)
e8ce775d 10045* exec: Bourne Shell Builtins.
122f603c 10046 (line 80)
e8ce775d 10047* exit: Bourne Shell Builtins.
122f603c 10048 (line 97)
e8ce775d 10049* export: Bourne Shell Builtins.
122f603c 10050 (line 104)
cce855bc 10051* fc: Bash History Builtins.
37c41ab1 10052 (line 10)
e8ce775d 10053* fg: Job Control Builtins.
122f603c 10054 (line 17)
e8ce775d 10055* getopts: Bourne Shell Builtins.
122f603c 10056 (line 120)
e8ce775d 10057* hash: Bourne Shell Builtins.
122f603c
CR
10058 (line 163)
10059* help: Bash Builtins. (line 320)
cce855bc 10060* history: Bash History Builtins.
122f603c 10061 (line 40)
e8ce775d 10062* jobs: Job Control Builtins.
122f603c 10063 (line 27)
e8ce775d 10064* kill: Job Control Builtins.
122f603c
CR
10065 (line 59)
10066* let: Bash Builtins. (line 341)
10067* local: Bash Builtins. (line 349)
10068* logout: Bash Builtins. (line 360)
10069* mapfile: Bash Builtins. (line 365)
bb70624e 10070* popd: Directory Stack Builtins.
122f603c
CR
10071 (line 39)
10072* printf: Bash Builtins. (line 413)
bb70624e 10073* pushd: Directory Stack Builtins.
122f603c 10074 (line 61)
e8ce775d 10075* pwd: Bourne Shell Builtins.
122f603c
CR
10076 (line 183)
10077* read: Bash Builtins. (line 459)
10078* readarray: Bash Builtins. (line 541)
e8ce775d 10079* readonly: Bourne Shell Builtins.
122f603c 10080 (line 193)
e8ce775d 10081* return: Bourne Shell Builtins.
122f603c 10082 (line 212)
d3ad40de 10083* set: The Set Builtin. (line 11)
e8ce775d 10084* shift: Bourne Shell Builtins.
122f603c 10085 (line 227)
d3ad40de 10086* shopt: The Shopt Builtin. (line 9)
122f603c 10087* source: Bash Builtins. (line 550)
e8ce775d 10088* suspend: Job Control Builtins.
122f603c 10089 (line 99)
e8ce775d 10090* test: Bourne Shell Builtins.
122f603c 10091 (line 240)
e8ce775d 10092* times: Bourne Shell Builtins.
122f603c 10093 (line 316)
e8ce775d 10094* trap: Bourne Shell Builtins.
122f603c
CR
10095 (line 322)
10096* type: Bash Builtins. (line 555)
10097* typeset: Bash Builtins. (line 587)
10098* ulimit: Bash Builtins. (line 593)
e8ce775d 10099* umask: Bourne Shell Builtins.
122f603c
CR
10100 (line 369)
10101* unalias: Bash Builtins. (line 684)
e8ce775d 10102* unset: Bourne Shell Builtins.
122f603c 10103 (line 387)
e8ce775d 10104* wait: Job Control Builtins.
122f603c 10105 (line 76)
ccc6cda3
JA
10106
10107\1f
d3ad40de 10108File: bashref.info, Node: Reserved Word Index, Next: Variable Index, Prev: Builtin Index, Up: Indexes
ccc6cda3 10109
d3ad40de
CR
10110D.2 Index of Shell Reserved Words
10111=================================
ccc6cda3 10112
37c41ab1 10113\0\b[index\0\b]
ccc6cda3
JA
10114* Menu:
10115
ed35cb4a 10116* !: Pipelines. (line 9)
cce855bc 10117* [[: Conditional Constructs.
ed35cb4a 10118 (line 117)
cce855bc 10119* ]]: Conditional Constructs.
ed35cb4a 10120 (line 117)
e8ce775d 10121* case: Conditional Constructs.
37c41ab1
CR
10122 (line 28)
10123* do: Looping Constructs. (line 12)
10124* done: Looping Constructs. (line 12)
e8ce775d 10125* elif: Conditional Constructs.
37c41ab1 10126 (line 7)
e8ce775d 10127* else: Conditional Constructs.
37c41ab1 10128 (line 7)
e8ce775d 10129* esac: Conditional Constructs.
37c41ab1 10130 (line 28)
e8ce775d 10131* fi: Conditional Constructs.
37c41ab1 10132 (line 7)
122f603c 10133* for: Looping Constructs. (line 32)
37c41ab1 10134* function: Shell Functions. (line 13)
e8ce775d 10135* if: Conditional Constructs.
37c41ab1 10136 (line 7)
e8ce775d 10137* in: Conditional Constructs.
37c41ab1 10138 (line 28)
cce855bc 10139* select: Conditional Constructs.
ed35cb4a 10140 (line 76)
e8ce775d 10141* then: Conditional Constructs.
37c41ab1 10142 (line 7)
ed35cb4a 10143* time: Pipelines. (line 9)
37c41ab1 10144* until: Looping Constructs. (line 12)
122f603c 10145* while: Looping Constructs. (line 22)
37c41ab1
CR
10146* {: Command Grouping. (line 21)
10147* }: Command Grouping. (line 21)
ccc6cda3
JA
10148
10149\1f
d3ad40de 10150File: bashref.info, Node: Variable Index, Next: Function Index, Prev: Reserved Word Index, Up: Indexes
ccc6cda3 10151
d3ad40de
CR
10152D.3 Parameter and Variable Index
10153================================
ccc6cda3 10154
37c41ab1 10155\0\b[index\0\b]
ccc6cda3
JA
10156* Menu:
10157
37c41ab1
CR
10158* !: Special Parameters. (line 46)
10159* #: Special Parameters. (line 30)
10160* $: Special Parameters. (line 42)
10161* *: Special Parameters. (line 9)
10162* -: Special Parameters. (line 37)
10163* 0: Special Parameters. (line 50)
10164* ?: Special Parameters. (line 33)
10165* @: Special Parameters. (line 19)
10166* _: Special Parameters. (line 59)
e8ce775d 10167* auto_resume: Job Control Variables.
37c41ab1
CR
10168 (line 6)
10169* BASH: Bash Variables. (line 13)
8f714a7c
CR
10170* BASH_ALIASES: Bash Variables. (line 30)
10171* BASH_ARGC: Bash Variables. (line 37)
10172* BASH_ARGV: Bash Variables. (line 47)
10173* BASH_CMDS: Bash Variables. (line 57)
10174* BASH_COMMAND: Bash Variables. (line 64)
10175* BASH_ENV: Bash Variables. (line 69)
10176* BASH_EXECUTION_STRING: Bash Variables. (line 75)
10177* BASH_LINENO: Bash Variables. (line 78)
9ec5ed66
CR
10178* BASH_REMATCH: Bash Variables. (line 86)
10179* BASH_SOURCE: Bash Variables. (line 94)
10180* BASH_SUBSHELL: Bash Variables. (line 101)
f6da9f85 10181* BASH_VERSINFO: Bash Variables. (line 106)
122f603c
CR
10182* BASH_VERSION: Bash Variables. (line 129)
10183* BASH_XTRACEFD: Bash Variables. (line 132)
8f714a7c
CR
10184* BASHOPTS: Bash Variables. (line 16)
10185* BASHPID: Bash Variables. (line 25)
e8ce775d 10186* bell-style: Readline Init File Syntax.
1c72c0cd 10187 (line 38)
eb2bb562 10188* bind-tty-special-chars: Readline Init File Syntax.
1c72c0cd 10189 (line 45)
e8ce775d 10190* CDPATH: Bourne Shell Variables.
37c41ab1 10191 (line 9)
122f603c 10192* COLUMNS: Bash Variables. (line 143)
e8ce775d 10193* comment-begin: Readline Init File Syntax.
1c72c0cd 10194 (line 50)
122f603c
CR
10195* COMP_CWORD: Bash Variables. (line 148)
10196* COMP_KEY: Bash Variables. (line 177)
10197* COMP_LINE: Bash Variables. (line 154)
10198* COMP_POINT: Bash Variables. (line 159)
10199* COMP_TYPE: Bash Variables. (line 167)
10200* COMP_WORDBREAKS: Bash Variables. (line 181)
10201* COMP_WORDS: Bash Variables. (line 187)
eb0b2ad8
CR
10202* completion-display-width: Readline Init File Syntax.
10203 (line 55)
10204* completion-ignore-case: Readline Init File Syntax.
10205 (line 62)
220537f2 10206* completion-map-case: Readline Init File Syntax.
ed35cb4a 10207 (line 67)
220537f2
CR
10208* completion-prefix-display-length: Readline Init File Syntax.
10209 (line 73)
eb0b2ad8 10210* completion-query-items: Readline Init File Syntax.
220537f2 10211 (line 80)
122f603c 10212* COMPREPLY: Bash Variables. (line 195)
e8ce775d 10213* convert-meta: Readline Init File Syntax.
220537f2 10214 (line 90)
122f603c
CR
10215* COPROC: Bash Variables. (line 200)
10216* DIRSTACK: Bash Variables. (line 204)
e8ce775d 10217* disable-completion: Readline Init File Syntax.
220537f2 10218 (line 96)
1c72c0cd 10219* editing-mode: Readline Init File Syntax.
220537f2 10220 (line 101)
122f603c 10221* EMACS: Bash Variables. (line 214)
e8ce775d 10222* enable-keypad: Readline Init File Syntax.
220537f2 10223 (line 112)
122f603c
CR
10224* ENV: Bash Variables. (line 219)
10225* EUID: Bash Variables. (line 223)
e8ce775d 10226* expand-tilde: Readline Init File Syntax.
220537f2 10227 (line 123)
122f603c
CR
10228* FCEDIT: Bash Variables. (line 227)
10229* FIGNORE: Bash Variables. (line 231)
10230* FUNCNAME: Bash Variables. (line 237)
10231* FUNCNEST: Bash Variables. (line 255)
10232* GLOBIGNORE: Bash Variables. (line 260)
10233* GROUPS: Bash Variables. (line 266)
10234* histchars: Bash Variables. (line 272)
10235* HISTCMD: Bash Variables. (line 287)
10236* HISTCONTROL: Bash Variables. (line 292)
10237* HISTFILE: Bash Variables. (line 308)
10238* HISTFILESIZE: Bash Variables. (line 312)
10239* HISTIGNORE: Bash Variables. (line 320)
f73dda09 10240* history-preserve-point: Readline Init File Syntax.
eb0b2ad8 10241 (line 127)
220537f2
CR
10242* history-size: Readline Init File Syntax.
10243 (line 133)
122f603c
CR
10244* HISTSIZE: Bash Variables. (line 339)
10245* HISTTIMEFORMAT: Bash Variables. (line 343)
e8ce775d 10246* HOME: Bourne Shell Variables.
37c41ab1 10247 (line 13)
e8ce775d 10248* horizontal-scroll-mode: Readline Init File Syntax.
220537f2 10249 (line 138)
122f603c
CR
10250* HOSTFILE: Bash Variables. (line 352)
10251* HOSTNAME: Bash Variables. (line 363)
10252* HOSTTYPE: Bash Variables. (line 366)
e8ce775d 10253* IFS: Bourne Shell Variables.
37c41ab1 10254 (line 18)
122f603c 10255* IGNOREEOF: Bash Variables. (line 369)
e8ce775d 10256* input-meta: Readline Init File Syntax.
220537f2 10257 (line 145)
122f603c 10258* INPUTRC: Bash Variables. (line 379)
b72432fd 10259* isearch-terminators: Readline Init File Syntax.
220537f2 10260 (line 152)
eb0b2ad8 10261* keymap: Readline Init File Syntax.
220537f2 10262 (line 159)
122f603c
CR
10263* LANG: Bash Variables. (line 383)
10264* LC_ALL: Bash Variables. (line 387)
10265* LC_COLLATE: Bash Variables. (line 391)
10266* LC_CTYPE: Bash Variables. (line 398)
37c41ab1 10267* LC_MESSAGES <1>: Locale Translation. (line 11)
122f603c
CR
10268* LC_MESSAGES: Bash Variables. (line 403)
10269* LC_NUMERIC: Bash Variables. (line 407)
10270* LINENO: Bash Variables. (line 411)
10271* LINES: Bash Variables. (line 415)
10272* MACHTYPE: Bash Variables. (line 420)
e8ce775d 10273* MAIL: Bourne Shell Variables.
37c41ab1 10274 (line 22)
122f603c 10275* MAILCHECK: Bash Variables. (line 424)
e8ce775d 10276* MAILPATH: Bourne Shell Variables.
37c41ab1 10277 (line 27)
122f603c 10278* MAPFILE: Bash Variables. (line 432)
e8ce775d 10279* mark-modified-lines: Readline Init File Syntax.
220537f2 10280 (line 172)
a8fd3f3e 10281* mark-symlinked-directories: Readline Init File Syntax.
220537f2 10282 (line 177)
a8fd3f3e 10283* match-hidden-files: Readline Init File Syntax.
220537f2 10284 (line 182)
e05be32d
CR
10285* menu-complete-display-prefix: Readline Init File Syntax.
10286 (line 189)
e8ce775d 10287* meta-flag: Readline Init File Syntax.
220537f2 10288 (line 145)
122f603c 10289* OLDPWD: Bash Variables. (line 436)
e8ce775d 10290* OPTARG: Bourne Shell Variables.
37c41ab1 10291 (line 34)
122f603c 10292* OPTERR: Bash Variables. (line 439)
e8ce775d 10293* OPTIND: Bourne Shell Variables.
37c41ab1 10294 (line 38)
122f603c 10295* OSTYPE: Bash Variables. (line 443)
e8ce775d 10296* output-meta: Readline Init File Syntax.
220537f2 10297 (line 194)
e05be32d
CR
10298* page-completions: Readline Init File Syntax.
10299 (line 199)
e8ce775d 10300* PATH: Bourne Shell Variables.
37c41ab1 10301 (line 42)
122f603c
CR
10302* PIPESTATUS: Bash Variables. (line 446)
10303* POSIXLY_CORRECT: Bash Variables. (line 451)
10304* PPID: Bash Variables. (line 460)
10305* PROMPT_COMMAND: Bash Variables. (line 464)
10306* PROMPT_DIRTRIM: Bash Variables. (line 468)
e8ce775d 10307* PS1: Bourne Shell Variables.
37c41ab1 10308 (line 48)
e8ce775d 10309* PS2: Bourne Shell Variables.
37c41ab1 10310 (line 53)
122f603c
CR
10311* PS3: Bash Variables. (line 474)
10312* PS4: Bash Variables. (line 479)
10313* PWD: Bash Variables. (line 485)
10314* RANDOM: Bash Variables. (line 488)
10315* READLINE_LINE: Bash Variables. (line 493)
10316* READLINE_POINT: Bash Variables. (line 497)
10317* REPLY: Bash Variables. (line 501)
ed35cb4a 10318* revert-all-at-newline: Readline Init File Syntax.
e05be32d 10319 (line 209)
122f603c
CR
10320* SECONDS: Bash Variables. (line 504)
10321* SHELL: Bash Variables. (line 510)
10322* SHELLOPTS: Bash Variables. (line 515)
10323* SHLVL: Bash Variables. (line 524)
220537f2 10324* show-all-if-ambiguous: Readline Init File Syntax.
e05be32d 10325 (line 215)
220537f2 10326* show-all-if-unmodified: Readline Init File Syntax.
e05be32d 10327 (line 221)
a8fd3f3e 10328* skip-completed-text: Readline Init File Syntax.
e05be32d 10329 (line 230)
37c41ab1
CR
10330* TEXTDOMAIN: Locale Translation. (line 11)
10331* TEXTDOMAINDIR: Locale Translation. (line 11)
122f603c
CR
10332* TIMEFORMAT: Bash Variables. (line 529)
10333* TMOUT: Bash Variables. (line 567)
10334* TMPDIR: Bash Variables. (line 579)
10335* UID: Bash Variables. (line 583)
e8ce775d 10336* visible-stats: Readline Init File Syntax.
e05be32d 10337 (line 243)
ccc6cda3
JA
10338
10339\1f
d3ad40de 10340File: bashref.info, Node: Function Index, Next: Concept Index, Prev: Variable Index, Up: Indexes
ccc6cda3 10341
d3ad40de
CR
10342D.4 Function Index
10343==================
ccc6cda3 10344
37c41ab1 10345\0\b[index\0\b]
ccc6cda3
JA
10346* Menu:
10347
e8ce775d 10348* abort (C-g): Miscellaneous Commands.
37c41ab1
CR
10349 (line 10)
10350* accept-line (Newline or Return): Commands For History. (line 6)
10351* backward-char (C-b): Commands For Moving. (line 15)
10352* backward-delete-char (Rubout): Commands For Text. (line 11)
10353* backward-kill-line (C-x Rubout): Commands For Killing. (line 9)
10354* backward-kill-word (M-<DEL>): Commands For Killing. (line 24)
10355* backward-word (M-b): Commands For Moving. (line 22)
10356* beginning-of-history (M-<): Commands For History. (line 20)
10357* beginning-of-line (C-a): Commands For Moving. (line 6)
10358* call-last-kbd-macro (C-x e): Keyboard Macros. (line 13)
10359* capitalize-word (M-c): Commands For Text. (line 46)
e8ce775d 10360* character-search (C-]): Miscellaneous Commands.
37c41ab1 10361 (line 41)
e8ce775d 10362* character-search-backward (M-C-]): Miscellaneous Commands.
37c41ab1 10363 (line 46)
a9fac3b2 10364* clear-screen (C-l): Commands For Moving. (line 34)
28ef6c31 10365* complete (<TAB>): Commands For Completion.
37c41ab1 10366 (line 6)
a9fac3b2
CR
10367* copy-backward-word (): Commands For Killing. (line 58)
10368* copy-forward-word (): Commands For Killing. (line 63)
10369* copy-region-as-kill (): Commands For Killing. (line 54)
37c41ab1 10370* delete-char (C-d): Commands For Text. (line 6)
b72432fd 10371* delete-char-or-list (): Commands For Completion.
eb0b2ad8 10372 (line 43)
a9fac3b2 10373* delete-horizontal-space (): Commands For Killing. (line 46)
37c41ab1 10374* digit-argument (M-0, M-1, ... M--): Numeric Arguments. (line 6)
ccc6cda3 10375* do-uppercase-version (M-a, M-b, M-X, ...): Miscellaneous Commands.
37c41ab1
CR
10376 (line 14)
10377* downcase-word (M-l): Commands For Text. (line 42)
e8ce775d 10378* dump-functions (): Miscellaneous Commands.
8f714a7c 10379 (line 73)
e8ce775d 10380* dump-macros (): Miscellaneous Commands.
8f714a7c 10381 (line 85)
e8ce775d 10382* dump-variables (): Miscellaneous Commands.
8f714a7c 10383 (line 79)
37c41ab1
CR
10384* end-kbd-macro (C-x )): Keyboard Macros. (line 9)
10385* end-of-history (M->): Commands For History. (line 23)
10386* end-of-line (C-e): Commands For Moving. (line 9)
e8ce775d 10387* exchange-point-and-mark (C-x C-x): Miscellaneous Commands.
37c41ab1
CR
10388 (line 36)
10389* forward-backward-delete-char (): Commands For Text. (line 15)
10390* forward-char (C-f): Commands For Moving. (line 12)
10391* forward-search-history (C-s): Commands For History. (line 31)
10392* forward-word (M-f): Commands For Moving. (line 18)
74d0116b 10393* history-search-backward (): Commands For History. (line 52)
37c41ab1 10394* history-search-forward (): Commands For History. (line 46)
74d0116b
CR
10395* history-substr-search-backward (): Commands For History. (line 64)
10396* history-substr-search-forward (): Commands For History. (line 58)
e8ce775d 10397* insert-comment (M-#): Miscellaneous Commands.
8f714a7c 10398 (line 60)
e8ce775d 10399* insert-completions (M-*): Commands For Completion.
eb0b2ad8 10400 (line 22)
37c41ab1 10401* kill-line (C-k): Commands For Killing. (line 6)
a9fac3b2 10402* kill-region (): Commands For Killing. (line 50)
37c41ab1
CR
10403* kill-whole-line (): Commands For Killing. (line 15)
10404* kill-word (M-d): Commands For Killing. (line 19)
cce855bc 10405* menu-complete (): Commands For Completion.
eb0b2ad8 10406 (line 26)
3eb2d94a 10407* menu-complete-backward (): Commands For Completion.
eb0b2ad8 10408 (line 38)
37c41ab1 10409* next-history (C-n): Commands For History. (line 17)
ccc6cda3 10410* non-incremental-forward-search-history (M-n): Commands For History.
37c41ab1 10411 (line 41)
ccc6cda3 10412* non-incremental-reverse-search-history (M-p): Commands For History.
37c41ab1
CR
10413 (line 36)
10414* overwrite-mode (): Commands For Text. (line 50)
e8ce775d 10415* possible-completions (M-?): Commands For Completion.
37c41ab1 10416 (line 15)
28ef6c31 10417* prefix-meta (<ESC>): Miscellaneous Commands.
37c41ab1
CR
10418 (line 18)
10419* previous-history (C-p): Commands For History. (line 13)
10420* quoted-insert (C-q or C-v): Commands For Text. (line 20)
e8ce775d 10421* re-read-init-file (C-x C-r): Miscellaneous Commands.
37c41ab1 10422 (line 6)
a9fac3b2 10423* redraw-current-line (): Commands For Moving. (line 38)
37c41ab1 10424* reverse-search-history (C-r): Commands For History. (line 27)
e8ce775d 10425* revert-line (M-r): Miscellaneous Commands.
37c41ab1
CR
10426 (line 25)
10427* self-insert (a, b, A, 1, !, ...): Commands For Text. (line 24)
e8ce775d 10428* set-mark (C-@): Miscellaneous Commands.
37c41ab1 10429 (line 32)
8f714a7c
CR
10430* skip-csi-sequence (): Miscellaneous Commands.
10431 (line 51)
37c41ab1
CR
10432* start-kbd-macro (C-x (): Keyboard Macros. (line 6)
10433* transpose-chars (C-t): Commands For Text. (line 27)
10434* transpose-words (M-t): Commands For Text. (line 33)
28ef6c31 10435* undo (C-_ or C-x C-u): Miscellaneous Commands.
37c41ab1
CR
10436 (line 22)
10437* universal-argument (): Numeric Arguments. (line 10)
a9fac3b2 10438* unix-filename-rubout (): Commands For Killing. (line 41)
37c41ab1 10439* unix-line-discard (C-u): Commands For Killing. (line 12)
a9fac3b2 10440* unix-word-rubout (C-w): Commands For Killing. (line 37)
37c41ab1 10441* upcase-word (M-u): Commands For Text. (line 38)
a9fac3b2 10442* yank (C-y): Commands For Killing. (line 68)
74d0116b
CR
10443* yank-last-arg (M-. or M-_): Commands For History. (line 79)
10444* yank-nth-arg (M-C-y): Commands For History. (line 70)
a9fac3b2 10445* yank-pop (M-y): Commands For Killing. (line 71)
ccc6cda3
JA
10446
10447\1f
d3ad40de 10448File: bashref.info, Node: Concept Index, Prev: Function Index, Up: Indexes
ccc6cda3 10449
d3ad40de
CR
10450D.5 Concept Index
10451=================
ccc6cda3 10452
37c41ab1 10453\0\b[index\0\b]
ccc6cda3
JA
10454* Menu:
10455
37c41ab1
CR
10456* alias expansion: Aliases. (line 6)
10457* arithmetic evaluation: Shell Arithmetic. (line 6)
e8ce775d 10458* arithmetic expansion: Arithmetic Expansion.
37c41ab1
CR
10459 (line 6)
10460* arithmetic, shell: Shell Arithmetic. (line 6)
10461* arrays: Arrays. (line 6)
10462* background: Job Control Basics. (line 6)
10463* Bash configuration: Basic Installation. (line 6)
10464* Bash installation: Basic Installation. (line 6)
e8ce775d 10465* Bourne shell: Basic Shell Features.
37c41ab1
CR
10466 (line 6)
10467* brace expansion: Brace Expansion. (line 6)
ac18b312 10468* builtin: Definitions. (line 17)
e8ce775d 10469* command editing: Readline Bare Essentials.
37c41ab1 10470 (line 6)
e8ce775d 10471* command execution: Command Search and Execution.
37c41ab1 10472 (line 6)
cce855bc 10473* command expansion: Simple Command Expansion.
37c41ab1 10474 (line 6)
e8ce775d 10475* command history: Bash History Facilities.
37c41ab1 10476 (line 6)
e8ce775d 10477* command search: Command Search and Execution.
37c41ab1 10478 (line 6)
e8ce775d 10479* command substitution: Command Substitution.
37c41ab1 10480 (line 6)
ed35cb4a 10481* command timing: Pipelines. (line 9)
37c41ab1 10482* commands, compound: Compound Commands. (line 6)
e8ce775d 10483* commands, conditional: Conditional Constructs.
37c41ab1
CR
10484 (line 6)
10485* commands, grouping: Command Grouping. (line 6)
10486* commands, lists: Lists. (line 6)
10487* commands, looping: Looping Constructs. (line 6)
10488* commands, pipelines: Pipelines. (line 6)
10489* commands, shell: Shell Commands. (line 6)
10490* commands, simple: Simple Commands. (line 6)
10491* comments, shell: Comments. (line 6)
bb70624e 10492* completion builtins: Programmable Completion Builtins.
37c41ab1
CR
10493 (line 6)
10494* configuration: Basic Installation. (line 6)
ac18b312 10495* control operator: Definitions. (line 21)
8e1a6eaa 10496* coprocess: Coprocesses. (line 6)
37c41ab1 10497* directory stack: The Directory Stack. (line 6)
e8ce775d 10498* editing command lines: Readline Bare Essentials.
37c41ab1
CR
10499 (line 6)
10500* environment: Environment. (line 6)
10501* evaluation, arithmetic: Shell Arithmetic. (line 6)
10502* event designators: Event Designators. (line 6)
cce855bc 10503* execution environment: Command Execution Environment.
37c41ab1
CR
10504 (line 6)
10505* exit status <1>: Exit Status. (line 6)
ed35cb4a 10506* exit status: Definitions. (line 26)
37c41ab1 10507* expansion: Shell Expansions. (line 6)
e8ce775d 10508* expansion, arithmetic: Arithmetic Expansion.
37c41ab1
CR
10509 (line 6)
10510* expansion, brace: Brace Expansion. (line 6)
10511* expansion, filename: Filename Expansion. (line 9)
e8ce775d 10512* expansion, parameter: Shell Parameter Expansion.
37c41ab1
CR
10513 (line 6)
10514* expansion, pathname: Filename Expansion. (line 9)
10515* expansion, tilde: Tilde Expansion. (line 6)
10516* expressions, arithmetic: Shell Arithmetic. (line 6)
e8ce775d 10517* expressions, conditional: Bash Conditional Expressions.
37c41ab1 10518 (line 6)
ed35cb4a
CR
10519* field: Definitions. (line 30)
10520* filename: Definitions. (line 35)
37c41ab1
CR
10521* filename expansion: Filename Expansion. (line 9)
10522* foreground: Job Control Basics. (line 6)
10523* functions, shell: Shell Functions. (line 6)
cce855bc 10524* history builtins: Bash History Builtins.
37c41ab1 10525 (line 6)
e05be32d 10526* history events: Event Designators. (line 8)
37c41ab1 10527* history expansion: History Interaction. (line 6)
e8ce775d 10528* history list: Bash History Facilities.
37c41ab1 10529 (line 6)
bb70624e 10530* History, how to use: Programmable Completion Builtins.
8f714a7c 10531 (line 237)
ed35cb4a 10532* identifier: Definitions. (line 51)
37c41ab1
CR
10533* initialization file, readline: Readline Init File. (line 6)
10534* installation: Basic Installation. (line 6)
e8ce775d 10535* interaction, readline: Readline Interaction.
37c41ab1
CR
10536 (line 6)
10537* interactive shell <1>: Interactive Shells. (line 6)
122f603c 10538* interactive shell: Invoking Bash. (line 125)
37c41ab1 10539* internationalization: Locale Translation. (line 6)
ed35cb4a 10540* job: Definitions. (line 38)
c2a47ea9 10541* job control <1>: Job Control Basics. (line 6)
ed35cb4a 10542* job control: Definitions. (line 42)
e8ce775d 10543* kill ring: Readline Killing Commands.
37c41ab1 10544 (line 19)
e8ce775d 10545* killing text: Readline Killing Commands.
37c41ab1
CR
10546 (line 6)
10547* localization: Locale Translation. (line 6)
122f603c 10548* login shell: Invoking Bash. (line 122)
37c41ab1 10549* matching, pattern: Pattern Matching. (line 6)
ed35cb4a
CR
10550* metacharacter: Definitions. (line 46)
10551* name: Definitions. (line 51)
37c41ab1 10552* native languages: Locale Translation. (line 6)
e8ce775d 10553* notation, readline: Readline Bare Essentials.
37c41ab1 10554 (line 6)
ed35cb4a 10555* operator, shell: Definitions. (line 57)
e8ce775d 10556* parameter expansion: Shell Parameter Expansion.
37c41ab1
CR
10557 (line 6)
10558* parameters: Shell Parameters. (line 6)
e8ce775d 10559* parameters, positional: Positional Parameters.
37c41ab1
CR
10560 (line 6)
10561* parameters, special: Special Parameters. (line 6)
10562* pathname expansion: Filename Expansion. (line 9)
10563* pattern matching: Pattern Matching. (line 6)
10564* pipeline: Pipelines. (line 6)
10565* POSIX: Definitions. (line 9)
10566* POSIX Mode: Bash POSIX Mode. (line 6)
a9fac3b2
CR
10567* process group: Definitions. (line 62)
10568* process group ID: Definitions. (line 66)
e8ce775d 10569* process substitution: Process Substitution.
37c41ab1 10570 (line 6)
bb70624e 10571* programmable completion: Programmable Completion.
37c41ab1 10572 (line 6)
122f603c
CR
10573* prompting: Controlling the Prompt.
10574 (line 6)
37c41ab1
CR
10575* quoting: Quoting. (line 6)
10576* quoting, ANSI: ANSI-C Quoting. (line 6)
bb70624e 10577* Readline, how to use: Job Control Variables.
37c41ab1
CR
10578 (line 24)
10579* redirection: Redirections. (line 6)
a9fac3b2 10580* reserved word: Definitions. (line 70)
e8ce775d 10581* restricted shell: The Restricted Shell.
37c41ab1 10582 (line 6)
a9fac3b2 10583* return status: Definitions. (line 75)
37c41ab1
CR
10584* shell arithmetic: Shell Arithmetic. (line 6)
10585* shell function: Shell Functions. (line 6)
10586* shell script: Shell Scripts. (line 6)
10587* shell variable: Shell Parameters. (line 6)
10588* shell, interactive: Interactive Shells. (line 6)
a9fac3b2 10589* signal: Definitions. (line 78)
37c41ab1 10590* signal handling: Signals. (line 6)
c2a47ea9 10591* special builtin <1>: Special Builtins. (line 6)
a9fac3b2 10592* special builtin: Definitions. (line 82)
37c41ab1
CR
10593* startup files: Bash Startup Files. (line 6)
10594* suspending jobs: Job Control Basics. (line 6)
10595* tilde expansion: Tilde Expansion. (line 6)
a9fac3b2 10596* token: Definitions. (line 86)
37c41ab1
CR
10597* translation, native languages: Locale Translation. (line 6)
10598* variable, shell: Shell Parameters. (line 6)
28ef6c31 10599* variables, readline: Readline Init File Syntax.
1c72c0cd 10600 (line 37)
a9fac3b2 10601* word: Definitions. (line 90)
37c41ab1 10602* word splitting: Word Splitting. (line 6)
e8ce775d 10603* yanking text: Readline Killing Commands.
37c41ab1 10604 (line 6)
ccc6cda3
JA
10605
10606
10607\1f
10608Tag Table:
122f603c
CR
10609Node: Top\7f1348
10610Node: Introduction\7f3190
10611Node: What is Bash?\7f3418
10612Node: What is a shell?\7f4531
10613Node: Definitions\7f7070
10614Node: Basic Shell Features\7f9988
10615Node: Shell Syntax\7f11207
10616Node: Shell Operation\7f12237
10617Node: Quoting\7f13531
10618Node: Escape Character\7f14834
10619Node: Single Quotes\7f15319
10620Node: Double Quotes\7f15667
10621Node: ANSI-C Quoting\7f16792
10622Node: Locale Translation\7f18036
10623Node: Comments\7f18932
10624Node: Shell Commands\7f19550
10625Node: Simple Commands\7f20422
10626Node: Pipelines\7f21053
10627Node: Lists\7f23752
10628Node: Compound Commands\7f25481
10629Node: Looping Constructs\7f26487
10630Node: Conditional Constructs\7f28950
10631Node: Command Grouping\7f37095
10632Node: Coprocesses\7f38574
10633Node: GNU Parallel\7f40248
10634Node: Shell Functions\7f42716
10635Node: Shell Parameters\7f47800
10636Node: Positional Parameters\7f50405
10637Node: Special Parameters\7f51305
10638Node: Shell Expansions\7f54269
10639Node: Brace Expansion\7f56195
10640Node: Tilde Expansion\7f58949
10641Node: Shell Parameter Expansion\7f61298
10642Node: Command Substitution\7f70432
10643Node: Arithmetic Expansion\7f71765
10644Node: Process Substitution\7f72615
10645Node: Word Splitting\7f73665
10646Node: Filename Expansion\7f75288
10647Node: Pattern Matching\7f77453
10648Node: Quote Removal\7f81153
10649Node: Redirections\7f81448
10650Node: Executing Commands\7f90285
10651Node: Simple Command Expansion\7f90955
10652Node: Command Search and Execution\7f92885
10653Node: Command Execution Environment\7f95222
10654Node: Environment\7f98208
10655Node: Exit Status\7f99867
10656Node: Signals\7f101489
10657Node: Shell Scripts\7f103457
10658Node: Shell Builtin Commands\7f105975
10659Node: Bourne Shell Builtins\7f108003
10660Node: Bash Builtins\7f126676
10661Node: Modifying Shell Behavior\7f153054
10662Node: The Set Builtin\7f153399
10663Node: The Shopt Builtin\7f163147
10664Node: Special Builtins\7f176848
10665Node: Shell Variables\7f177827
10666Node: Bourne Shell Variables\7f178267
10667Node: Bash Variables\7f180298
10668Node: Bash Features\7f205299
10669Node: Invoking Bash\7f206198
10670Node: Bash Startup Files\7f211960
10671Node: Interactive Shells\7f216979
10672Node: What is an Interactive Shell?\7f217389
10673Node: Is this Shell Interactive?\7f218038
10674Node: Interactive Shell Behavior\7f218853
10675Node: Bash Conditional Expressions\7f222133
10676Node: Shell Arithmetic\7f225921
10677Node: Aliases\7f228680
10678Node: Arrays\7f231236
10679Node: The Directory Stack\7f235444
10680Node: Directory Stack Builtins\7f236163
10681Node: Controlling the Prompt\7f239119
10682Node: The Restricted Shell\7f241891
10683Node: Bash POSIX Mode\7f243728
10684Node: Job Control\7f252876
10685Node: Job Control Basics\7f253336
10686Node: Job Control Builtins\7f258055
10687Node: Job Control Variables\7f262407
10688Node: Command Line Editing\7f263565
10689Node: Introduction and Notation\7f265132
10690Node: Readline Interaction\7f266754
10691Node: Readline Bare Essentials\7f267945
10692Node: Readline Movement Commands\7f269734
10693Node: Readline Killing Commands\7f270699
10694Node: Readline Arguments\7f272619
10695Node: Searching\7f273663
10696Node: Readline Init File\7f275849
10697Node: Readline Init File Syntax\7f276996
10698Node: Conditional Init Constructs\7f292338
10699Node: Sample Init File\7f294871
10700Node: Bindable Readline Commands\7f297988
10701Node: Commands For Moving\7f299195
10702Node: Commands For History\7f300339
10703Node: Commands For Text\7f304524
10704Node: Commands For Killing\7f307197
10705Node: Numeric Arguments\7f309654
10706Node: Commands For Completion\7f310793
10707Node: Keyboard Macros\7f314985
10708Node: Miscellaneous Commands\7f315556
10709Node: Readline vi Mode\7f321362
10710Node: Programmable Completion\7f322269
10711Node: Programmable Completion Builtins\7f329479
10712Node: Using History Interactively\7f338615
10713Node: Bash History Facilities\7f339299
10714Node: Bash History Builtins\7f342213
10715Node: History Interaction\7f346141
10716Node: Event Designators\7f348846
10717Node: Word Designators\7f350068
10718Node: Modifiers\7f351707
10719Node: Installing Bash\7f353111
10720Node: Basic Installation\7f354248
10721Node: Compilers and Options\7f356940
10722Node: Compiling For Multiple Architectures\7f357681
10723Node: Installation Names\7f359345
10724Node: Specifying the System Type\7f360163
10725Node: Sharing Defaults\7f360879
10726Node: Operation Controls\7f361552
10727Node: Optional Features\7f362510
10728Node: Reporting Bugs\7f372082
10729Node: Major Differences From The Bourne Shell\7f373283
10730Node: GNU Free Documentation License\7f389975
10731Node: Indexes\7f415171
10732Node: Builtin Index\7f415625
10733Node: Reserved Word Index\7f422452
10734Node: Variable Index\7f424900
10735Node: Function Index\7f437995
10736Node: Concept Index\7f445150
ccc6cda3
JA
10737\1f
10738End Tag Table