]> git.ipfire.org Git - thirdparty/bash.git/blame - doc/bashref.info
Bash-5.3 distribution sources and documentation
[thirdparty/bash.git] / doc / bashref.info
CommitLineData
b8c60bc9 1This is bashref.info, produced by makeinfo version 7.2 from
a0c0a00f 2bashref.texi.
e8ce775d 3
a0c0a00f 4This text is a brief description of the features that are present in the
b8c60bc9 5Bash shell (version 5.3, 18 May 2025).
ccc6cda3 6
b8c60bc9
CR
7 This is Edition 5.3, last updated 18 May 2025, of ‘The GNU Bash
8Reference Manual’, for ‘Bash’, Version 5.3.
ccc6cda3 9
b8c60bc9 10 Copyright © 1988-2025 Free Software Foundation, Inc.
ccc6cda3 11
b80f6443
JA
12 Permission is granted to copy, distribute and/or modify this
13 document under the terms of the GNU Free Documentation License,
0001803f 14 Version 1.3 or any later version published by the Free Software
ac50fbac
CR
15 Foundation; with no Invariant Sections, no Front-Cover Texts, and
16 no Back-Cover Texts. A copy of the license is included in the
17 section entitled "GNU Free Documentation License".
b80f6443
JA
18INFO-DIR-SECTION Basics
19START-INFO-DIR-ENTRY
20* Bash: (bash). The GNU Bourne-Again SHell.
21END-INFO-DIR-ENTRY
ccc6cda3
JA
22
23\1f
24File: bashref.info, Node: Top, Next: Introduction, Prev: (dir), Up: (dir)
25
26Bash Features
27*************
28
a0c0a00f 29This text is a brief description of the features that are present in the
b8c60bc9 30Bash shell (version 5.3, 18 May 2025). The Bash home page is
a0c0a00f 31<http://www.gnu.org/software/bash/>.
ccc6cda3 32
b8c60bc9
CR
33 This is Edition 5.3, last updated 18 May 2025, of ‘The GNU Bash
34Reference Manual’, for ‘Bash’, Version 5.3.
ccc6cda3
JA
35
36 Bash contains features that appear in other popular shells, and some
37features that only appear in Bash. Some of the shells that Bash has
b8c60bc9
CR
38borrowed concepts from are the Bourne Shell (‘sh’), the Korn Shell
39(‘ksh’), and the C-shell (‘csh’ and its successor, ‘tcsh’). The
ac50fbac
CR
40following menu breaks the features up into categories, noting which
41features were inspired by other shells and which are specific to Bash.
ccc6cda3
JA
42
43 This manual is meant as a brief introduction to features found in
44Bash. The Bash manual page should be used as the definitive reference
45on shell behavior.
46
47* Menu:
48
49* Introduction:: An introduction to the shell.
ccc6cda3
JA
50* Definitions:: Some definitions used in the rest of this
51 manual.
ccc6cda3 52* Basic Shell Features:: The shell "building blocks".
bb70624e 53* Shell Builtin Commands:: Commands that are a part of the shell.
bb70624e 54* Shell Variables:: Variables used or set by Bash.
ccc6cda3 55* Bash Features:: Features found only in Bash.
95732b49
JA
56* Job Control:: What job control is and how Bash allows you
57 to use it.
ccc6cda3
JA
58* Command Line Editing:: Chapter describing the command line
59 editing features.
3185942a 60* Using History Interactively:: Command History Expansion
ccc6cda3 61* Installing Bash:: How to build and install Bash on your system.
ccc6cda3 62* Reporting Bugs:: How to report bugs in Bash.
bb70624e
JA
63* Major Differences From The Bourne Shell:: A terse list of the differences
64 between Bash and historical
65 versions of /bin/sh.
3185942a
JA
66* GNU Free Documentation License:: Copying and sharing this documentation.
67* Indexes:: Various indexes for this manual.
ccc6cda3
JA
68
69\1f
a0c0a00f 70File: bashref.info, Node: Introduction, Next: Definitions, Up: Top
ccc6cda3 71
b80f6443
JA
721 Introduction
73**************
ccc6cda3
JA
74
75* Menu:
76
77* What is Bash?:: A short description of Bash.
ccc6cda3
JA
78* What is a shell?:: A brief introduction to shells.
79
80\1f
81File: bashref.info, Node: What is Bash?, Next: What is a shell?, Up: Introduction
82
b80f6443
JA
831.1 What is Bash?
84=================
ccc6cda3 85
b80f6443 86Bash is the shell, or command language interpreter, for the GNU
b8c60bc9 87operating system. The name is an acronym for the ‘Bourne-Again SHell’,
bb70624e 88a pun on Stephen Bourne, the author of the direct ancestor of the
b8c60bc9 89current Unix shell ‘sh’, which appeared in the Seventh Edition Bell Labs
a0c0a00f 90Research version of Unix.
ccc6cda3 91
b8c60bc9
CR
92 Bash is largely compatible with ‘sh’ and incorporates useful features
93from the Korn shell ‘ksh’ and the C shell ‘csh’. It is intended to be a
a0c0a00f
CR
94conformant implementation of the IEEE POSIX Shell and Tools portion of
95the IEEE POSIX specification (IEEE Standard 1003.1). It offers
b8c60bc9 96functional improvements over ‘sh’ for both interactive and programming
a0c0a00f 97use.
ccc6cda3 98
bb70624e 99 While the GNU operating system provides other shells, including a
b8c60bc9 100version of ‘csh’, Bash is the default shell. Like other GNU software,
bb70624e 101Bash is quite portable. It currently runs on nearly every version of
b8c60bc9
CR
102Unix and a few other operating systems − independently-supported ports
103exist for Windows and other platforms.
ccc6cda3
JA
104
105\1f
106File: bashref.info, Node: What is a shell?, Prev: What is Bash?, Up: Introduction
107
b80f6443
JA
1081.2 What is a shell?
109====================
110
a0c0a00f
CR
111At its base, a shell is simply a macro processor that executes commands.
112The term macro processor means functionality where text and symbols are
113expanded to create larger expressions.
ccc6cda3 114
b80f6443
JA
115 A Unix shell is both a command interpreter and a programming
116language. As a command interpreter, the shell provides the user
117interface to the rich set of GNU utilities. The programming language
b8c60bc9
CR
118features allow these utilities to be combined. Users can create files
119containing commands, and these become commands themselves. These new
bb70624e 120commands have the same status as system commands in directories such as
b8c60bc9 121‘/bin’, allowing users or groups to establish custom environments to
b80f6443
JA
122automate their common tasks.
123
124 Shells may be used interactively or non-interactively. In
125interactive mode, they accept input typed from the keyboard. When
b8c60bc9
CR
126executing non-interactively, shells execute commands read from a file or
127a string.
ccc6cda3 128
bb70624e 129 A shell allows execution of GNU commands, both synchronously and
cce855bc
JA
130asynchronously. The shell waits for synchronous commands to complete
131before accepting more input; asynchronous commands continue to execute
132in parallel with the shell while it reads and executes additional
b8c60bc9 133commands. The “redirection” constructs permit fine-grained control of
bb70624e 134the input and output of those commands. Moreover, the shell allows
b80f6443 135control over the contents of commands' environments.
bb70624e 136
b8c60bc9 137 Shells also provide a small set of built-in commands (“builtins”)
bb70624e 138implementing functionality impossible or inconvenient to obtain via
b8c60bc9 139separate utilities. For example, ‘cd’, ‘break’, ‘continue’, and ‘exec’
ac50fbac 140cannot be implemented outside of the shell because they directly
b8c60bc9 141manipulate the shell itself. The ‘history’, ‘getopts’, ‘kill’, or ‘pwd’
ac50fbac
CR
142builtins, among others, could be implemented in separate utilities, but
143they are more convenient to use as builtin commands. All of the shell
144builtins are described in subsequent sections.
ccc6cda3
JA
145
146 While executing commands is essential, most of the power (and
147complexity) of shells is due to their embedded programming languages.
a0c0a00f
CR
148Like any high-level language, the shell provides variables, flow control
149constructs, quoting, and functions.
ccc6cda3 150
bb70624e
JA
151 Shells offer features geared specifically for interactive use rather
152than to augment the programming language. These interactive features
b80f6443 153include job control, command line editing, command history and aliases.
b8c60bc9 154This manual describes how Bash provides all of these features.
ccc6cda3
JA
155
156\1f
157File: bashref.info, Node: Definitions, Next: Basic Shell Features, Prev: Introduction, Up: Top
158
b80f6443
JA
1592 Definitions
160*************
ccc6cda3 161
b80f6443 162These definitions are used throughout the remainder of this manual.
ccc6cda3 163
b8c60bc9 164‘POSIX’
a0c0a00f
CR
165 A family of open system standards based on Unix. Bash is primarily
166 concerned with the Shell and Utilities portion of the POSIX 1003.1
167 standard.
ccc6cda3 168
b8c60bc9 169‘blank’
ccc6cda3
JA
170 A space or tab character.
171
b8c60bc9
CR
172‘whitespace’
173 A character belonging to the ‘space’ character class in the current
174 locale, or for which ‘isspace()’ returns true.
175
176‘builtin’
ccc6cda3
JA
177 A command that is implemented internally by the shell itself,
178 rather than by an executable program somewhere in the file system.
179
b8c60bc9
CR
180‘control operator’
181 A ‘token’ that performs a control function. It is a ‘newline’ or
182 one of the following: ‘||’, ‘&&’, ‘&’, ‘;’, ‘;;’, ‘;&’, ‘;;&’, ‘|’,
183 ‘|&’, ‘(’, or ‘)’.
ccc6cda3 184
b8c60bc9 185‘exit status’
f73dda09
JA
186 The value returned by a command to its caller. The value is
187 restricted to eight bits, so the maximum value is 255.
ccc6cda3 188
b8c60bc9 189‘field’
ccc6cda3 190 A unit of text that is the result of one of the shell expansions.
a0c0a00f
CR
191 After expansion, when executing a command, the resulting fields are
192 used as the command name and arguments.
ccc6cda3 193
b8c60bc9 194‘filename’
ccc6cda3
JA
195 A string of characters used to identify a file.
196
b8c60bc9 197‘job’
ccc6cda3
JA
198 A set of processes comprising a pipeline, and any processes
199 descended from it, that are all in the same process group.
200
b8c60bc9 201‘job control’
d166f048
JA
202 A mechanism by which users can selectively stop (suspend) and
203 restart (resume) execution of processes.
ccc6cda3 204
b8c60bc9 205‘metacharacter’
ccc6cda3 206 A character that, when unquoted, separates words. A metacharacter
b8c60bc9
CR
207 is a ‘space’, ‘tab’, ‘newline’, or one of the following characters:
208 ‘|’, ‘&’, ‘;’, ‘(’, ‘)’, ‘<’, or ‘>’.
ccc6cda3 209
b8c60bc9
CR
210‘name’
211 A ‘word’ consisting solely of letters, numbers, and underscores,
212 and beginning with a letter or underscore. ‘Name’s are used as
ccc6cda3 213 shell variable and function names. Also referred to as an
b8c60bc9 214 ‘identifier’.
ccc6cda3 215
b8c60bc9
CR
216‘operator’
217 A ‘control operator’ or a ‘redirection operator’. *Note
3185942a 218 Redirections::, for a list of redirection operators. Operators
b8c60bc9 219 contain at least one unquoted ‘metacharacter’.
ccc6cda3 220
b8c60bc9 221‘process group’
ccc6cda3
JA
222 A collection of related processes each having the same process
223 group ID.
224
b8c60bc9
CR
225‘process group ID’
226 A unique identifier that represents a ‘process group’ during its
ccc6cda3
JA
227 lifetime.
228
b8c60bc9
CR
229‘reserved word’
230 A ‘word’ that has a special meaning to the shell. Most reserved
231 words introduce shell flow control constructs, such as ‘for’ and
232 ‘while’.
ccc6cda3 233
b8c60bc9
CR
234‘return status’
235 A synonym for ‘exit status’.
ccc6cda3 236
b8c60bc9 237‘signal’
bb70624e 238 A mechanism by which a process may be notified by the kernel of an
ccc6cda3
JA
239 event occurring in the system.
240
b8c60bc9 241‘special builtin’
ccc6cda3 242 A shell builtin command that has been classified as special by the
0628567a 243 POSIX standard.
ccc6cda3 244
b8c60bc9 245‘token’
a0c0a00f 246 A sequence of characters considered a single unit by the shell. It
b8c60bc9 247 is either a ‘word’ or an ‘operator’.
ccc6cda3 248
b8c60bc9 249‘word’
a0c0a00f 250 A sequence of characters treated as a unit by the shell. Words may
b8c60bc9 251 not include unquoted ‘metacharacters’.
ccc6cda3
JA
252
253\1f
bb70624e 254File: bashref.info, Node: Basic Shell Features, Next: Shell Builtin Commands, Prev: Definitions, Up: Top
ccc6cda3 255
b80f6443
JA
2563 Basic Shell Features
257**********************
ccc6cda3 258
b8c60bc9 259Bash is an acronym for ‘Bourne-Again SHell’. The Bourne shell is the
a0c0a00f 260traditional Unix shell originally written by Stephen Bourne. All of the
b8c60bc9 261Bourne shell builtin commands are available in Bash, and the rules for
b80f6443 262evaluation and quoting are taken from the POSIX specification for the
a0c0a00f 263'standard' Unix shell.
ccc6cda3 264
a0c0a00f 265 This chapter briefly summarizes the shell's 'building blocks':
ccc6cda3
JA
266commands, control structures, shell functions, shell parameters, shell
267expansions, redirections, which are a way to direct input and output
268from and to named files, and how the shell executes commands.
269
270* Menu:
271
272* Shell Syntax:: What your input means to the shell.
cce855bc 273* Shell Commands:: The types of commands you can use.
ccc6cda3 274* Shell Functions:: Grouping commands by name.
b80f6443
JA
275* Shell Parameters:: How the shell stores values.
276* Shell Expansions:: How Bash expands parameters and the various
ccc6cda3
JA
277 expansions available.
278* Redirections:: A way to control where input and output go.
279* Executing Commands:: What happens when you run a command.
280* Shell Scripts:: Executing files of shell commands.
281
282\1f
cce855bc 283File: bashref.info, Node: Shell Syntax, Next: Shell Commands, Up: Basic Shell Features
ccc6cda3 284
b80f6443
JA
2853.1 Shell Syntax
286================
ccc6cda3
JA
287
288* Menu:
289
290* Shell Operation:: The basic operation of the shell.
ccc6cda3 291* Quoting:: How to remove the special meaning from characters.
ccc6cda3
JA
292* Comments:: How to specify comments.
293
a0c0a00f 294When the shell reads input, it proceeds through a sequence of
bb70624e 295operations. If the input indicates the beginning of a comment, the
b8c60bc9 296shell ignores the comment symbol (‘#’), and the rest of that line.
bb70624e 297
a0c0a00f 298 Otherwise, roughly speaking, the shell reads its input and divides
bb70624e
JA
299the input into words and operators, employing the quoting rules to
300select which meanings to assign various words and characters.
301
302 The shell then parses these tokens into commands and other
303constructs, removes the special meaning of certain words or characters,
304expands others, redirects input and output as needed, executes the
305specified command, waits for the command's exit status, and makes that
306exit status available for further inspection or processing.
307
ccc6cda3
JA
308\1f
309File: bashref.info, Node: Shell Operation, Next: Quoting, Up: Shell Syntax
310
b80f6443
JA
3113.1.1 Shell Operation
312---------------------
ccc6cda3 313
b80f6443 314The following is a brief description of the shell's operation when it
ccc6cda3
JA
315reads and executes a command. Basically, the shell does the following:
316
28ef6c31 317 1. Reads its input from a file (*note Shell Scripts::), from a string
b8c60bc9 318 supplied as an argument to the ‘-c’ invocation option (*note
28ef6c31 319 Invoking Bash::), or from the user's terminal.
ccc6cda3
JA
320
321 2. Breaks the input into words and operators, obeying the quoting
3185942a 322 rules described in *note Quoting::. These tokens are separated by
b8c60bc9 323 ‘metacharacters’. This step performs alias expansion (*note
a0c0a00f 324 Aliases::).
ccc6cda3 325
cce855bc 326 3. Parses the tokens into simple and compound commands (*note Shell
28ef6c31 327 Commands::).
ccc6cda3 328
28ef6c31 329 4. Performs the various shell expansions (*note Shell Expansions::),
ccc6cda3 330 breaking the expanded tokens into lists of filenames (*note
28ef6c31 331 Filename Expansion::) and commands and arguments.
ccc6cda3 332
28ef6c31 333 5. Performs any necessary redirections (*note Redirections::) and
ccc6cda3
JA
334 removes the redirection operators and their operands from the
335 argument list.
336
28ef6c31 337 6. Executes the command (*note Executing Commands::).
ccc6cda3
JA
338
339 7. Optionally waits for the command to complete and collects its exit
28ef6c31 340 status (*note Exit Status::).
ccc6cda3 341
ccc6cda3
JA
342\1f
343File: bashref.info, Node: Quoting, Next: Comments, Prev: Shell Operation, Up: Shell Syntax
344
b80f6443
JA
3453.1.2 Quoting
346-------------
ccc6cda3
JA
347
348* Menu:
349
350* Escape Character:: How to remove the special meaning from a single
351 character.
352* Single Quotes:: How to inhibit all interpretation of a sequence
353 of characters.
354* Double Quotes:: How to suppress most of the interpretation of a
355 sequence of characters.
356* ANSI-C Quoting:: How to expand ANSI-C sequences in quoted strings.
ccc6cda3
JA
357* Locale Translation:: How to translate strings into different languages.
358
a0c0a00f
CR
359Quoting is used to remove the special meaning of certain characters or
360words to the shell. Quoting can be used to disable special treatment
361for special characters, to prevent reserved words from being recognized
362as such, and to prevent parameter expansion.
ccc6cda3 363
28ef6c31 364 Each of the shell metacharacters (*note Definitions::) has special
cce855bc 365meaning to the shell and must be quoted if it is to represent itself.
b8c60bc9
CR
366
367 When the command history expansion facilities are being used (*note
368History Interaction::), the “history expansion” character, usually ‘!’,
95732b49
JA
369must be quoted to prevent history expansion. *Note Bash History
370Facilities::, for more details concerning history expansion.
b80f6443 371
b8c60bc9
CR
372 There are four quoting mechanisms: the “escape character”, single
373quotes, double quotes, and dollar-single quotes.
ccc6cda3
JA
374
375\1f
376File: bashref.info, Node: Escape Character, Next: Single Quotes, Up: Quoting
377
b80f6443
JA
3783.1.2.1 Escape Character
379........................
ccc6cda3 380
b8c60bc9
CR
381A non-quoted backslash ‘\’ is the Bash escape character. It preserves
382the literal value of the next character that follows, removing any
383special meaning it has, with the exception of ‘newline’. If a
384‘\newline’ pair appears, and the backslash itself is not quoted, the
385‘\newline’ is treated as a line continuation (that is, it is removed
386from the input stream and effectively ignored).
ccc6cda3
JA
387
388\1f
389File: bashref.info, Node: Single Quotes, Next: Double Quotes, Prev: Escape Character, Up: Quoting
390
b80f6443
JA
3913.1.2.2 Single Quotes
392.....................
ccc6cda3 393
b8c60bc9 394Enclosing characters in single quotes (‘'’) preserves the literal value
b80f6443 395of each character within the quotes. A single quote may not occur
bb70624e 396between single quotes, even when preceded by a backslash.
ccc6cda3
JA
397
398\1f
399File: bashref.info, Node: Double Quotes, Next: ANSI-C Quoting, Prev: Single Quotes, Up: Quoting
400
b80f6443
JA
4013.1.2.3 Double Quotes
402.....................
ccc6cda3 403
b8c60bc9
CR
404Enclosing characters in double quotes (‘"’) preserves the literal value
405of all characters within the quotes, with the exception of ‘$’, ‘`’,
406‘\’, and, when history expansion is enabled, ‘!’. When the shell is in
407POSIX mode (*note Bash POSIX Mode::), the ‘!’ has no special meaning
a0c0a00f 408within double quotes, even when history expansion is enabled. The
b8c60bc9 409characters ‘$’ and ‘`’ retain their special meaning within double quotes
a0c0a00f 410(*note Shell Expansions::). The backslash retains its special meaning
b8c60bc9
CR
411only when followed by one of the following characters: ‘$’, ‘`’, ‘"’,
412‘\’, or ‘newline’. Within double quotes, backslashes that are followed
a0c0a00f 413by one of these characters are removed. Backslashes preceding
b8c60bc9 414characters without a special meaning are left unmodified.
a0c0a00f 415
b8c60bc9
CR
416 A double quote may be quoted within double quotes by preceding it
417with a backslash. If enabled, history expansion will be performed
418unless an ‘!’ appearing in double quotes is escaped using a backslash.
419The backslash preceding the ‘!’ is not removed.
420
421 The special parameters ‘*’ and ‘@’ have special meaning when in
28ef6c31 422double quotes (*note Shell Parameter Expansion::).
ccc6cda3
JA
423
424\1f
425File: bashref.info, Node: ANSI-C Quoting, Next: Locale Translation, Prev: Double Quotes, Up: Quoting
426
b80f6443
JA
4273.1.2.4 ANSI-C Quoting
428......................
ccc6cda3 429
b8c60bc9
CR
430Character sequences of the form ‘$'STRING'’ are treated as a special
431kind of single quotes. The sequence expands to STRING, with
74091dd4
CR
432backslash-escaped characters in STRING replaced as specified by the ANSI
433C standard. Backslash escape sequences, if present, are decoded as
434follows:
ccc6cda3 435
b8c60bc9 436‘\a’
ccc6cda3 437 alert (bell)
b8c60bc9 438‘\b’
ccc6cda3 439 backspace
b8c60bc9
CR
440‘\e’
441‘\E’
442 An escape character (not in ANSI C).
443‘\f’
ccc6cda3 444 form feed
b8c60bc9 445‘\n’
ccc6cda3 446 newline
b8c60bc9 447‘\r’
ccc6cda3 448 carriage return
b8c60bc9 449‘\t’
ccc6cda3 450 horizontal tab
b8c60bc9 451‘\v’
ccc6cda3 452 vertical tab
b8c60bc9 453‘\\’
ccc6cda3 454 backslash
b8c60bc9 455‘\'’
bb70624e 456 single quote
b8c60bc9 457‘\"’
0001803f 458 double quote
b8c60bc9 459‘\?’
a0c0a00f 460 question mark
b8c60bc9
CR
461‘\NNN’
462 The eight-bit character whose value is the octal value NNN (one to
463 three octal digits).
464‘\xHH’
465 The eight-bit character whose value is the hexadecimal value HH
466 (one or two hex digits).
467‘\uHHHH’
468 The Unicode (ISO/IEC 10646) character whose value is the
469 hexadecimal value HHHH (one to four hex digits).
470‘\UHHHHHHHH’
471 The Unicode (ISO/IEC 10646) character whose value is the
472 hexadecimal value HHHHHHHH (one to eight hex digits).
473‘\cX’
474 A control-X character.
7117c2d2 475
a0c0a00f
CR
476The expanded result is single-quoted, as if the dollar sign had not been
477present.
ccc6cda3
JA
478
479\1f
480File: bashref.info, Node: Locale Translation, Prev: ANSI-C Quoting, Up: Quoting
481
b80f6443
JA
4823.1.2.5 Locale-Specific Translation
483...................................
ccc6cda3 484
74091dd4 485* Menu:
ccc6cda3 486
74091dd4
CR
487* Creating Internationalized Scripts:: How to use translations and different
488 languages in your scripts.
489
b8c60bc9
CR
490Prefixing a double-quoted string with a dollar sign (‘$’), such as
491$"hello, world", causes the string to be translated according to the
492current locale. The ‘gettext’ infrastructure performs the lookup and
493translation, using the ‘LC_MESSAGES’, ‘TEXTDOMAINDIR’, and ‘TEXTDOMAIN’
74091dd4 494shell variables, as explained below. See the gettext documentation for
b8c60bc9
CR
495additional details not covered here. If the current locale is ‘C’ or
496‘POSIX’, if there are no translations available, or if the string is not
497translated, the dollar sign is ignored, and the string is treated as
498double-quoted as described above. Since this is a form of double
74091dd4 499quoting, the string remains double-quoted by default, whether or not it
b8c60bc9
CR
500is translated and replaced. If the ‘noexpand_translation’ option is
501enabled using the ‘shopt’ builtin (*note The Shopt Builtin::),
74091dd4
CR
502translated strings are single-quoted instead of double-quoted.
503
504 The rest of this section is a brief overview of how you use gettext
505to create translations for strings in a shell script named SCRIPTNAME.
506There are more details in the gettext documentation.
507
508\1f
509File: bashref.info, Node: Creating Internationalized Scripts, Up: Locale Translation
510
511Once you've marked the strings in your script that you want to translate
512using $"...", you create a gettext "template" file using the command
513
514 bash --dump-po-strings SCRIPTNAME > DOMAIN.pot
515
b8c60bc9 516The DOMAIN is your “message domain”. It's just an arbitrary string
74091dd4
CR
517that's used to identify the files gettext needs, like a package or
518script name. It needs to be unique among all the message domains on
519systems where you install the translations, so gettext knows which
520translations correspond to your script. You'll use the template file to
521create translations for each target language. The template file
b8c60bc9 522conventionally has the suffix ‘.pot’.
74091dd4
CR
523
524 You copy this template file to a separate file for each target
525language you want to support (called "PO" files, which use the suffix
b8c60bc9 526‘.po’). PO files use various naming conventions, but when you are
74091dd4
CR
527working to translate a template file into a particular language, you
528first copy the template file to a file whose name is the language you
b8c60bc9
CR
529want to target, with the ‘.po’ suffix. For instance, the Spanish
530translations of your strings would be in a file named ‘es.po’, and to
74091dd4
CR
531get started using a message domain named "example," you would run
532
533 cp example.pot es.po
534
535Ultimately, PO files are often named DOMAIN.po and installed in
536directories that contain multiple translation files for a particular
537language.
538
539 Whichever naming convention you choose, you will need to translate
540the strings in the PO files into the appropriate languages. This has to
541be done manually.
542
543 When you have the translations and PO files complete, you'll use the
544gettext tools to produce what are called "MO" files, which are compiled
545versions of the PO files the gettext tools use to look up translations
546efficiently. MO files are also called "message catalog" files. You use
b8c60bc9 547the ‘msgfmt’ program to do this. For instance, if you had a file with
74091dd4
CR
548Spanish translations, you could run
549
550 msgfmt -o es.mo es.po
551
552to produce the corresponding MO file.
553
554 Once you have the MO files, you decide where to install them and use
b8c60bc9 555the ‘TEXTDOMAINDIR’ shell variable to tell the gettext tools where they
74091dd4
CR
556are. Make sure to use the same message domain to name the MO files as
557you did for the PO files when you install them.
558
b8c60bc9 559 Your users will use the ‘LANG’ or ‘LC_MESSAGES’ shell variables to
74091dd4
CR
560select the desired language.
561
b8c60bc9 562 You set the ‘TEXTDOMAIN’ variable to the script's message domain. As
74091dd4
CR
563above, you use the message domain to name your translation files.
564
b8c60bc9 565 You, or possibly your users, set the ‘TEXTDOMAINDIR’ variable to the
74091dd4
CR
566name of a directory where the message catalog files are stored. If you
567install the message files into the system's standard message catalog
568directory, you don't need to worry about this variable.
569
570 The directory where the message catalog files are stored varies
571between systems. Some use the message catalog selected by the
b8c60bc9
CR
572‘LC_MESSAGES’ shell variable. Others create the name of the message
573catalog from the value of the ‘TEXTDOMAIN’ shell variable, possibly
574adding the ‘.mo’ suffix. If you use the ‘TEXTDOMAIN’ variable, you may
575need to set the ‘TEXTDOMAINDIR’ variable to the location of the message
74091dd4 576catalog files, as above. It's common to use both variables in this
b8c60bc9 577fashion: ‘$TEXTDOMAINDIR’/‘$LC_MESSAGES’/LC_MESSAGES/‘$TEXTDOMAIN’.mo.
74091dd4
CR
578
579 If you used that last convention, and you wanted to store the message
580catalog files with Spanish (es) and Esperanto (eo) translations into a
581local directory you use for custom translation files, you could run
582
583 TEXTDOMAIN=example
584 TEXTDOMAINDIR=/usr/local/share/locale
585
586 cp es.mo ${TEXTDOMAINDIR}/es/LC_MESSAGES/${TEXTDOMAIN}.mo
587 cp eo.mo ${TEXTDOMAINDIR}/eo/LC_MESSAGES/${TEXTDOMAIN}.mo
588
589 When all of this is done, and the message catalog files containing
590the compiled translations are installed in the correct location, your
591users will be able to see translated strings in any of the supported
b8c60bc9 592languages by setting the ‘LANG’ or ‘LC_MESSAGES’ environment variables
74091dd4 593before running your script.
28ef6c31 594
ccc6cda3
JA
595\1f
596File: bashref.info, Node: Comments, Prev: Quoting, Up: Shell Syntax
597
b80f6443
JA
5983.1.3 Comments
599--------------
ccc6cda3 600
b80f6443 601In a non-interactive shell, or an interactive shell in which the
b8c60bc9
CR
602‘interactive_comments’ option to the ‘shopt’ builtin is enabled (*note
603The Shopt Builtin::), a word beginning with ‘#’ introduces a comment. A
604word begins at the beginning of a line, after unquoted whitespace, or
605after an operator. The comment causes that word and all remaining
606characters on that line to be ignored. An interactive shell without the
607‘interactive_comments’ option enabled does not allow comments. The
608‘interactive_comments’ option is enabled by default in interactive
609shells. *Note Interactive Shells::, for a description of what makes a
610shell interactive.
cce855bc
JA
611
612\1f
613File: bashref.info, Node: Shell Commands, Next: Shell Functions, Prev: Shell Syntax, Up: Basic Shell Features
614
b80f6443
JA
6153.2 Shell Commands
616==================
cce855bc 617
b8c60bc9 618A simple shell command such as ‘echo a b c’ consists of the command
bb70624e
JA
619itself followed by arguments, separated by spaces.
620
621 More complex shell commands are composed of simple commands arranged
622together in a variety of ways: in a pipeline in which the output of one
623command becomes the input of a second, in a loop or conditional
624construct, or in some other grouping.
625
cce855bc
JA
626* Menu:
627
8868edaf 628* Reserved Words:: Words that have special meaning to the shell.
cce855bc
JA
629* Simple Commands:: The most common type of command.
630* Pipelines:: Connecting the input and output of several
631 commands.
632* Lists:: How to execute commands sequentially.
b80f6443 633* Compound Commands:: Shell commands for control flow.
3185942a 634* Coprocesses:: Two-way communication between commands.
495aee44 635* GNU Parallel:: Running commands in parallel.
ccc6cda3
JA
636
637\1f
8868edaf 638File: bashref.info, Node: Reserved Words, Next: Simple Commands, Up: Shell Commands
ccc6cda3 639
8868edaf
CR
6403.2.1 Reserved Words
641--------------------
642
643Reserved words are words that have special meaning to the shell. They
644are used to begin and end the shell's compound commands.
645
646 The following words are recognized as reserved when unquoted and the
647first word of a command (see below for exceptions):
648
b8c60bc9
CR
649‘if’ ‘then’ ‘elif’ ‘else’ ‘fi’ ‘time’
650‘for’ ‘in’ ‘until’ ‘while’ ‘do’ ‘done’
651‘case’ ‘esac’ ‘coproc’‘select’‘function’
652‘{’ ‘}’ ‘[[’ ‘]]’ ‘!’
8868edaf 653
b8c60bc9
CR
654‘in’ is recognized as a reserved word if it is the third word of a
655‘case’ or ‘select’ command. ‘in’ and ‘do’ are recognized as reserved
656words if they are the third word in a ‘for’ command.
8868edaf
CR
657
658\1f
659File: bashref.info, Node: Simple Commands, Next: Pipelines, Prev: Reserved Words, Up: Shell Commands
660
6613.2.2 Simple Commands
b80f6443 662---------------------
ccc6cda3 663
b8c60bc9
CR
664A simple command is the kind of command that's executed most often.
665It's just a sequence of words separated by ‘blank’s, terminated by one
666of the shell's control operators (*note Definitions::). The first word
a0c0a00f
CR
667generally specifies a command to be executed, with the rest of the words
668being that command's arguments.
ccc6cda3 669
28ef6c31 670 The return status (*note Exit Status::) of a simple command is its
b8c60bc9 671exit status as provided by the POSIX 1003.1 ‘waitpid’ function, or 128+N
a0c0a00f 672if the command was terminated by signal N.
ccc6cda3
JA
673
674\1f
cce855bc 675File: bashref.info, Node: Pipelines, Next: Lists, Prev: Simple Commands, Up: Shell Commands
ccc6cda3 676
8868edaf 6773.2.3 Pipelines
b80f6443 678---------------
ccc6cda3 679
b8c60bc9
CR
680A ‘pipeline’ is a sequence of one or more commands separated by one of
681the control operators ‘|’ or ‘|&’.
ccc6cda3
JA
682
683 The format for a pipeline is
ac50fbac 684 [time [-p]] [!] COMMAND1 [ | or |& COMMAND2 ] ...
ccc6cda3 685
f73dda09 686The output of each command in the pipeline is connected via a pipe to
a0c0a00f
CR
687the input of the next command. That is, each command reads the previous
688command's output. This connection is performed before any redirections
74091dd4 689specified by COMMAND1.
3185942a 690
b8c60bc9
CR
691 If ‘|&’ is the pipeline operator, COMMAND1's standard error, in
692addition to its standard output, is connected to COMMAND2's standard
693input through the pipe; it is shorthand for ‘2>&1 |’. This implicit
694redirection of the standard error to the standard output is performed
695after any redirections specified by COMMAND1, consistent with that
696shorthand.
697
698 If the reserved word ‘time’ precedes the pipeline, Bash prints timing
699statistics for the pipeline once it finishes. The statistics currently
700consist of elapsed (wall-clock) time and user and system time consumed
701by the command's execution. The ‘-p’ option changes the output format
702to that specified by POSIX. When the shell is in POSIX mode (*note Bash
703POSIX Mode::), it does not recognize ‘time’ as a reserved word if the
704next token begins with a ‘-’. The value of the ‘TIMEFORMAT’ variable is
705a format string that specifies how the timing information should be
495aee44 706displayed. *Note Bash Variables::, for a description of the available
b8c60bc9
CR
707formats. Providing ‘time’ as a reserved word permits the timing of
708shell builtins, shell functions, and pipelines. An external ‘time’
495aee44
CR
709command cannot time these easily.
710
b8c60bc9
CR
711 When the shell is in POSIX mode (*note Bash POSIX Mode::), you can
712use ‘time’ by itself as a simple command. In this case, the shell
713displays the total user and system time consumed by the shell and its
714children. The ‘TIMEFORMAT’ variable specifies the format of the time
495aee44 715information.
cce855bc 716
b8c60bc9 717 If a pipeline is not executed asynchronously (*note Lists::), the
cce855bc 718shell waits for all commands in the pipeline to complete.
ccc6cda3 719
74091dd4 720 Each command in a multi-command pipeline, where pipes are created, is
b8c60bc9
CR
721executed in its own “subshell”, which is a separate process (*note
722Command Execution Environment::). If the ‘lastpipe’ option is enabled
723using the ‘shopt’ builtin (*note The Shopt Builtin::), and job control
724is not active, the last element of a pipeline may be run by the shell
725process.
d233b485
CR
726
727 The exit status of a pipeline is the exit status of the last command
b8c60bc9
CR
728in the pipeline, unless the ‘pipefail’ option is enabled (*note The Set
729Builtin::). If ‘pipefail’ is enabled, the pipeline's return status is
d233b485
CR
730the value of the last (rightmost) command to exit with a non-zero
731status, or zero if all commands exit successfully. If the reserved word
b8c60bc9
CR
732‘!’ precedes the pipeline, the exit status is the logical negation of
733the exit status as described above. If a pipeline is not executed
734asynchronously (*note Lists::), the shell waits for all commands in the
735pipeline to terminate before returning a value. The return status of an
736asynchronous pipeline is 0.
ccc6cda3
JA
737
738\1f
b80f6443 739File: bashref.info, Node: Lists, Next: Compound Commands, Prev: Pipelines, Up: Shell Commands
ccc6cda3 740
8868edaf 7413.2.4 Lists of Commands
b80f6443 742-----------------------
ccc6cda3 743
b8c60bc9
CR
744A ‘list’ is a sequence of one or more pipelines separated by one of the
745operators ‘;’, ‘&’, ‘&&’, or ‘||’, and optionally terminated by one of
746‘;’, ‘&’, or a ‘newline’.
ccc6cda3 747
b8c60bc9
CR
748 Of these list operators, ‘&&’ and ‘||’ have equal precedence,
749followed by ‘;’ and ‘&’, which have equal precedence.
ccc6cda3 750
b8c60bc9 751 A sequence of one or more newlines may appear in a ‘list’ to delimit
7117c2d2
JA
752commands, equivalent to a semicolon.
753
b8c60bc9 754 If a command is terminated by the control operator ‘&’, the shell
cce855bc 755executes the command asynchronously in a subshell. This is known as
b8c60bc9
CR
756executing the command in the “background”, and these are referred to as
757“asynchronous” commands. The shell does not wait for the command to
d233b485
CR
758finish, and the return status is 0 (true). When job control is not
759active (*note Job Control::), the standard input for asynchronous
760commands, in the absence of any explicit redirections, is redirected
b8c60bc9 761from ‘/dev/null’.
cce855bc 762
b8c60bc9 763 Commands separated by a ‘;’ are executed sequentially; the shell
cce855bc
JA
764waits for each command to terminate in turn. The return status is the
765exit status of the last command executed.
ccc6cda3 766
3185942a 767 AND and OR lists are sequences of one or more pipelines separated by
b8c60bc9 768the control operators ‘&&’ and ‘||’, respectively. AND and OR lists are
a0c0a00f 769executed with left associativity.
3185942a
JA
770
771 An AND list has the form
bb70624e 772 COMMAND1 && COMMAND2
ccc6cda3 773
a0c0a00f 774COMMAND2 is executed if, and only if, COMMAND1 returns an exit status of
d233b485 775zero (success).
ccc6cda3
JA
776
777 An OR list has the form
bb70624e 778 COMMAND1 || COMMAND2
ccc6cda3 779
bb70624e 780COMMAND2 is executed if, and only if, COMMAND1 returns a non-zero exit
ccc6cda3
JA
781status.
782
783 The return status of AND and OR lists is the exit status of the last
784command executed in the list.
785
786\1f
3185942a 787File: bashref.info, Node: Compound Commands, Next: Coprocesses, Prev: Lists, Up: Shell Commands
ccc6cda3 788
8868edaf 7893.2.5 Compound Commands
b80f6443 790-----------------------
ccc6cda3 791
b80f6443
JA
792* Menu:
793
794* Looping Constructs:: Shell commands for iterative action.
795* Conditional Constructs:: Shell commands for conditional execution.
796* Command Grouping:: Ways to group commands.
797
d233b485
CR
798Compound commands are the shell programming language constructs. Each
799construct begins with a reserved word or control operator and is
800terminated by a corresponding reserved word or operator. Any
801redirections (*note Redirections::) associated with a compound command
802apply to all commands within that compound command unless explicitly
803overridden.
b80f6443 804
ac50fbac
CR
805 In most cases a list of commands in a compound command's description
806may be separated from the rest of the command by one or more newlines,
807and may be followed by a newline in place of a semicolon.
808
b80f6443
JA
809 Bash provides looping constructs, conditional commands, and
810mechanisms to group commands and execute them as a unit.
811
812\1f
813File: bashref.info, Node: Looping Constructs, Next: Conditional Constructs, Up: Compound Commands
814
8868edaf 8153.2.5.1 Looping Constructs
b80f6443
JA
816..........................
817
818Bash supports the following looping constructs.
ccc6cda3 819
b8c60bc9 820 Note that wherever a ‘;’ appears in the description of a command's
cce855bc
JA
821syntax, it may be replaced with one or more newlines.
822
b8c60bc9
CR
823‘until’
824 The syntax of the ‘until’ command is:
ac50fbac 825
ccc6cda3 826 until TEST-COMMANDS; do CONSEQUENT-COMMANDS; done
ac50fbac 827
cce855bc
JA
828 Execute CONSEQUENT-COMMANDS as long as TEST-COMMANDS has an exit
829 status which is not zero. The return status is the exit status of
830 the last command executed in CONSEQUENT-COMMANDS, or zero if none
831 was executed.
ccc6cda3 832
b8c60bc9
CR
833‘while’
834 The syntax of the ‘while’ command is:
ac50fbac 835
ccc6cda3
JA
836 while TEST-COMMANDS; do CONSEQUENT-COMMANDS; done
837
cce855bc
JA
838 Execute CONSEQUENT-COMMANDS as long as TEST-COMMANDS has an exit
839 status of zero. The return status is the exit status of the last
840 command executed in CONSEQUENT-COMMANDS, or zero if none was
841 executed.
ccc6cda3 842
b8c60bc9
CR
843‘for’
844 The syntax of the ‘for’ command is:
ccc6cda3 845
b8c60bc9 846 for NAME [ [in WORDS ...] ; ] do COMMANDS; done
ac50fbac 847
b8c60bc9
CR
848 Expand WORDS (*note Shell Expansions::), and then execute COMMANDS
849 once for each word in the resultant list, with NAME bound to the
850 current word. If ‘in WORDS’ is not present, the ‘for’ command
d233b485 851 executes the COMMANDS once for each positional parameter that is
b8c60bc9 852 set, as if ‘in "$@"’ had been specified (*note Special
d233b485
CR
853 Parameters::).
854
855 The return status is the exit status of the last command that
856 executes. If there are no items in the expansion of WORDS, no
857 commands are executed, and the return status is zero.
bb70624e 858
b8c60bc9
CR
859 There is an alternate form of the ‘for’ command which is similar to
860 the C language:
bb70624e 861
b8c60bc9 862 for (( EXPR1 ; EXPR2 ; EXPR3 )) [;] do COMMANDS ; done
ac50fbac 863
b8c60bc9
CR
864 First, evaluate the arithmetic expression EXPR1 according to the
865 rules described below (*note Shell Arithmetic::). Then, repeatedly
866 evaluate the arithmetic expression EXPR2 until it evaluates to
867 zero. Each time EXPR2 evaluates to a non-zero value, execute
868 COMMANDS and evaluate the arithmetic expression EXPR3. If any
869 expression is omitted, it behaves as if it evaluates to 1. The
870 return value is the exit status of the last command in COMMANDS
871 that is executed, or non-zero if any of the expressions is invalid.
ccc6cda3 872
b8c60bc9
CR
873 Use the ‘break’ and ‘continue’ builtins (*note Bourne Shell
874Builtins::) to control loop execution.
ccc6cda3
JA
875
876\1f
b80f6443 877File: bashref.info, Node: Conditional Constructs, Next: Command Grouping, Prev: Looping Constructs, Up: Compound Commands
ccc6cda3 878
8868edaf 8793.2.5.2 Conditional Constructs
b80f6443 880..............................
ccc6cda3 881
b8c60bc9
CR
882‘if’
883 The syntax of the ‘if’ command is:
ccc6cda3
JA
884
885 if TEST-COMMANDS; then
886 CONSEQUENT-COMMANDS;
887 [elif MORE-TEST-COMMANDS; then
888 MORE-CONSEQUENTS;]
889 [else ALTERNATE-CONSEQUENTS;]
890 fi
891
cce855bc
JA
892 The TEST-COMMANDS list is executed, and if its return status is
893 zero, the CONSEQUENT-COMMANDS list is executed. If TEST-COMMANDS
b8c60bc9 894 returns a non-zero status, each ‘elif’ list is executed in turn,
cce855bc 895 and if its exit status is zero, the corresponding MORE-CONSEQUENTS
b8c60bc9
CR
896 is executed and the command completes. If ‘else
897 ALTERNATE-CONSEQUENTS’ is present, and the final command in the
898 final ‘if’ or ‘elif’ clause has a non-zero exit status, then
cce855bc 899 ALTERNATE-CONSEQUENTS is executed. The return status is the exit
a0c0a00f
CR
900 status of the last command executed, or zero if no condition tested
901 true.
ccc6cda3 902
b8c60bc9
CR
903‘case’
904 The syntax of the ‘case’ command is:
ccc6cda3 905
d233b485
CR
906 case WORD in
907 [ [(] PATTERN [| PATTERN]...) COMMAND-LIST ;;]...
908 esac
ccc6cda3 909
b8c60bc9
CR
910 ‘case’ will selectively execute the COMMAND-LIST corresponding to
911 the first PATTERN that matches WORD, proceeding from the first
912 pattern to the last. The match is performed according to the rules
913 described below in *note Pattern Matching::. If the ‘nocasematch’
914 shell option (see the description of ‘shopt’ in *note The Shopt
915 Builtin::) is enabled, the match is performed without regard to the
916 case of alphabetic characters. The ‘|’ is used to separate
917 multiple patterns in a pattern list, and the ‘)’ operator
918 terminates the pattern list. A pattern list and an associated
919 COMMAND-LIST is known as a CLAUSE.
3185942a 920
b8c60bc9 921 Each clause must be terminated with ‘;;’, ‘;&’, or ‘;;&’. The WORD
d233b485 922 undergoes tilde expansion, parameter expansion, command
b8c60bc9
CR
923 substitution, process substitution, arithmetic expansion, and quote
924 removal (*note Shell Parameter Expansion::) before the shell
925 attempts to match the pattern. Each PATTERN undergoes tilde
926 expansion, parameter expansion, command substitution, arithmetic
927 expansion, process substitution, and quote removal.
cce855bc 928
b8c60bc9
CR
929 There may be an arbitrary number of ‘case’ clauses, each terminated
930 by a ‘;;’, ‘;&’, or ‘;;&’. The first pattern that matches
ac50fbac 931 determines the command-list that is executed. It's a common idiom
b8c60bc9 932 to use ‘*’ as the final pattern to define the default case, since
ac50fbac 933 that pattern will always match.
ccc6cda3 934
b8c60bc9 935 Here is an example using ‘case’ in a script that could be used to
ccc6cda3
JA
936 describe one interesting feature of an animal:
937
938 echo -n "Enter the name of an animal: "
939 read ANIMAL
940 echo -n "The $ANIMAL has "
941 case $ANIMAL in
942 horse | dog | cat) echo -n "four";;
943 man | kangaroo ) echo -n "two";;
944 *) echo -n "an unknown number of";;
945 esac
946 echo " legs."
947
b8c60bc9
CR
948 If the ‘;;’ operator is used, the ‘case’ command completes after
949 the first pattern match. Using ‘;&’ in place of ‘;;’ causes
a0c0a00f 950 execution to continue with the COMMAND-LIST associated with the
b8c60bc9 951 next clause, if any. Using ‘;;&’ in place of ‘;;’ causes the shell
a0c0a00f 952 to test the patterns in the next clause, if any, and execute any
b8c60bc9 953 associated COMMAND-LIST if the match succeeds, continuing the case
8868edaf 954 statement execution as if the pattern list had not matched.
3185942a 955
b8c60bc9
CR
956 The return status is zero if no PATTERN matches. Otherwise, the
957 return status is the exit status of the last COMMAND-LIST executed.
cce855bc 958
b8c60bc9 959‘select’
a0c0a00f 960
b8c60bc9
CR
961 The ‘select’ construct allows the easy generation of menus. It has
962 almost the same syntax as the ‘for’ command:
cce855bc
JA
963
964 select NAME [in WORDS ...]; do COMMANDS; done
965
b8c60bc9
CR
966 First, expand the list of words following ‘in’, generating a list
967 of items, and print the set of expanded words on the standard error
968 stream, each preceded by a number. If the ‘in WORDS’ is omitted,
969 print the positional parameters, as if ‘in "$@"’ had been
970 specified. ‘select’ then displays the ‘PS3’ prompt and reads a
971 line from the standard input. If the line consists of a number
972 corresponding to one of the displayed words, then ‘select’ sets the
973 value of NAME to that word. If the line is empty, ‘select’
974 displays the words and prompt again. If ‘EOF’ is read, ‘select’
74091dd4 975 completes and returns 1. Any other value read causes NAME to be
b8c60bc9 976 set to null. The line read is saved in the variable ‘REPLY’.
a0c0a00f 977
b8c60bc9
CR
978 The COMMANDS are executed after each selection until a ‘break’
979 command is executed, at which point the ‘select’ command completes.
cce855bc
JA
980
981 Here is an example that allows the user to pick a filename from the
982 current directory, and displays the name and index of the file
983 selected.
984
985 select fname in *;
986 do
987 echo you picked $fname \($REPLY\)
988 break;
989 done
990
b8c60bc9 991‘((...))’
ccc6cda3
JA
992 (( EXPRESSION ))
993
cce855bc 994 The arithmetic EXPRESSION is evaluated according to the rules
74091dd4
CR
995 described below (*note Shell Arithmetic::). The EXPRESSION
996 undergoes the same expansions as if it were within double quotes,
b8c60bc9
CR
997 but unescaped double quote characters in EXPRESSION are not treated
998 specially and are removed. Since this can potentially result in
999 empty strings, this command treats those as expressions that
1000 evaluate to 0. If the value of the expression is non-zero, the
74091dd4 1001 return status is 0; otherwise the return status is 1.
cce855bc 1002
b8c60bc9 1003‘[[...]]’
cce855bc
JA
1004 [[ EXPRESSION ]]
1005
b8c60bc9
CR
1006 Evaluate the conditional expression EXPRESSION and return a status
1007 of zero (true) or non-zero (false). Expressions are composed of
1008 the primaries described below in *note Bash Conditional
1009 Expressions::. The words between the ‘[[’ and ‘]]’ do not undergo
1010 word splitting and filename expansion. The shell performs tilde
1011 expansion, parameter and variable expansion, arithmetic expansion,
1012 command substitution, process substitution, and quote removal on
1013 those words. Conditional operators such as ‘-f’ must be unquoted
1014 to be recognized as primaries.
1015
1016 When used with ‘[[’, the ‘<’ and ‘>’ operators sort
0001803f
CR
1017 lexicographically using the current locale.
1018
b8c60bc9 1019 When the ‘==’ and ‘!=’ operators are used, the string to the right
cce855bc 1020 of the operator is considered a pattern and matched according to
ac50fbac 1021 the rules described below in *note Pattern Matching::, as if the
b8c60bc9
CR
1022 ‘extglob’ shell option were enabled. The ‘=’ operator is identical
1023 to ‘==’. If the ‘nocasematch’ shell option (see the description of
1024 ‘shopt’ in *note The Shopt Builtin::) is enabled, the match is
a0c0a00f 1025 performed without regard to the case of alphabetic characters. The
b8c60bc9
CR
1026 return value is 0 if the string matches (‘==’) or does not match
1027 (‘!=’) the pattern, and 1 otherwise.
74091dd4
CR
1028
1029 If you quote any part of the pattern, using any of the shell's
1030 quoting mechanisms, the quoted portion is matched literally. This
1031 means every character in the quoted portion matches itself, instead
1032 of having any special pattern matching meaning.
a0c0a00f 1033
b8c60bc9
CR
1034 An additional binary operator, ‘=~’, is available, with the same
1035 precedence as ‘==’ and ‘!=’. When you use ‘=~’, the string to the
d233b485 1036 right of the operator is considered a POSIX extended regular
74091dd4 1037 expression pattern and matched accordingly (using the POSIX
b8c60bc9 1038 ‘regcomp’ and ‘regexec’ interfaces usually described in regex(3)).
74091dd4
CR
1039 The return value is 0 if the string matches the pattern, and 1 if
1040 it does not. If the regular expression is syntactically incorrect,
b8c60bc9
CR
1041 the conditional expression returns 2. If the ‘nocasematch’ shell
1042 option (see the description of ‘shopt’ in *note The Shopt
74091dd4
CR
1043 Builtin::) is enabled, the match is performed without regard to the
1044 case of alphabetic characters.
1045
1046 You can quote any part of the pattern to force the quoted portion
1047 to be matched literally instead of as a regular expression (see
1048 above). If the pattern is stored in a shell variable, quoting the
1049 variable expansion forces the entire pattern to be matched
1050 literally.
1051
b8c60bc9
CR
1052 The match succeeds if the pattern matches any part of the string.
1053 If you want to force the pattern to match the entire string, anchor
1054 the pattern using the ‘^’ and ‘$’ regular expression operators.
ac50fbac
CR
1055
1056 For example, the following will match a line (stored in the shell
b8c60bc9 1057 variable ‘line’) if there is a sequence of characters anywhere in
74091dd4 1058 the value consisting of any number, including zero, of characters
b8c60bc9
CR
1059 in the ‘space’ character class, immediately followed by zero or one
1060 instances of ‘a’, then a ‘b’:
74091dd4 1061
8868edaf 1062 [[ $line =~ [[:space:]]*(a)?b ]]
ac50fbac 1063
b8c60bc9
CR
1064 That means values for ‘line’ like ‘aab’, ‘ aaaaaab’, ‘xaby’, and ‘
1065 ab’ will all match, as will a line containing a ‘b’ anywhere in its
74091dd4
CR
1066 value.
1067
1068 If you want to match a character that's special to the regular
b8c60bc9
CR
1069 expression grammar (‘^$|[]()\.*+?’), it has to be quoted to remove
1070 its special meaning. This means that in the pattern ‘xxx.txt’, the
1071 ‘.’ matches any character in the string (its usual regular
1072 expression meaning), but in the pattern ‘"xxx.txt"’, it can only
1073 match a literal ‘.’.
74091dd4
CR
1074
1075 Likewise, if you want to include a character in your pattern that
1076 has a special meaning to the regular expression grammar, you must
1077 make sure it's not quoted. If you want to anchor a pattern at the
1078 beginning or end of the string, for instance, you cannot quote the
b8c60bc9 1079 ‘^’ or ‘$’ characters using any form of shell quoting.
74091dd4 1080
b8c60bc9 1081 If you want to match ‘initial string’ at the start of a line, the
74091dd4
CR
1082 following will work:
1083 [[ $line =~ ^"initial string" ]]
1084 but this will not:
1085 [[ $line =~ "^initial string" ]]
b8c60bc9 1086 because in the second example the ‘^’ is quoted and doesn't have
74091dd4
CR
1087 its usual special meaning.
1088
1089 It is sometimes difficult to specify a regular expression properly
1090 without using quotes, or to keep track of the quoting used by
1091 regular expressions while paying attention to shell quoting and the
1092 shell's quote removal. Storing the regular expression in a shell
1093 variable is often a useful way to avoid problems with quoting
1094 characters that are special to the shell. For example, the
1095 following is equivalent to the pattern used above:
1096
8868edaf 1097 pattern='[[:space:]]*(a)?b'
ac50fbac
CR
1098 [[ $line =~ $pattern ]]
1099
a0c0a00f 1100 Shell programmers should take special care with backslashes, since
74091dd4
CR
1101 backslashes are used by both the shell and regular expressions to
1102 remove the special meaning from the following character. This
1103 means that after the shell's word expansions complete (*note Shell
1104 Expansions::), any backslashes remaining in parts of the pattern
1105 that were originally not quoted can remove the special meaning of
1106 pattern characters. If any part of the pattern is quoted, the
1107 shell does its best to ensure that the regular expression treats
1108 those remaining backslashes as literal, if they appeared in a
1109 quoted portion.
1110
1111 The following two sets of commands are _not_ equivalent:
1112
ac50fbac
CR
1113 pattern='\.'
1114
1115 [[ . =~ $pattern ]]
1116 [[ . =~ \. ]]
1117
1118 [[ . =~ "$pattern" ]]
1119 [[ . =~ '\.' ]]
1120
1121 The first two matches will succeed, but the second two will not,
a0c0a00f 1122 because in the second two the backslash will be part of the pattern
74091dd4 1123 to be matched. In the first two examples, the pattern passed to
b8c60bc9
CR
1124 the regular expression parser is ‘\.’. The backslash removes the
1125 special meaning from ‘.’, so the literal ‘.’ matches. In the
74091dd4 1126 second two examples, the pattern passed to the regular expression
b8c60bc9 1127 parser has the backslash quoted (e.g., ‘\\\.’), which will not
74091dd4 1128 match the string, since it does not contain a backslash. If the
b8c60bc9
CR
1129 string in the first examples were anything other than ‘.’, say ‘a’,
1130 the pattern would not match, because the quoted ‘.’ in the pattern
a0c0a00f 1131 loses its special meaning of matching any single character.
b80f6443 1132
74091dd4
CR
1133 Bracket expressions in regular expressions can be sources of errors
1134 as well, since characters that are normally special in regular
1135 expressions lose their special meanings between brackets. However,
1136 you can use bracket expressions to match special pattern characters
1137 without quoting them, so they are sometimes useful for this
1138 purpose.
1139
1140 Though it might seem like a strange way to write it, the following
b8c60bc9 1141 pattern will match a ‘.’ in the string:
74091dd4
CR
1142
1143 [[ . =~ [.] ]]
1144
1145 The shell performs any word expansions before passing the pattern
1146 to the regular expression functions, so you can assume that the
1147 shell's quoting takes precedence. As noted above, the regular
1148 expression parser will interpret any unquoted backslashes remaining
1149 in the pattern after shell expansion according to its own rules.
1150 The intention is to avoid making shell programmers quote things
1151 twice as much as possible, so shell quoting should be sufficient to
1152 quote special pattern characters where that's necessary.
1153
b8c60bc9
CR
1154 The array variable ‘BASH_REMATCH’ records which parts of the string
1155 matched the pattern. The element of ‘BASH_REMATCH’ with index 0
74091dd4
CR
1156 contains the portion of the string matching the entire regular
1157 expression. Substrings matched by parenthesized subexpressions
1158 within the regular expression are saved in the remaining
b8c60bc9 1159 ‘BASH_REMATCH’ indices. The element of ‘BASH_REMATCH’ with index N
74091dd4
CR
1160 is the portion of the string matching the Nth parenthesized
1161 subexpression.
1162
b8c60bc9 1163 Bash sets ‘BASH_REMATCH’ in the global scope; declaring it as a
74091dd4
CR
1164 local variable will lead to unexpected results.
1165
cce855bc
JA
1166 Expressions may be combined using the following operators, listed
1167 in decreasing order of precedence:
1168
b8c60bc9 1169 ‘( EXPRESSION )’
a0c0a00f
CR
1170 Returns the value of EXPRESSION. This may be used to override
1171 the normal precedence of operators.
cce855bc 1172
b8c60bc9 1173 ‘! EXPRESSION’
cce855bc
JA
1174 True if EXPRESSION is false.
1175
b8c60bc9 1176 ‘EXPRESSION1 && EXPRESSION2’
cce855bc
JA
1177 True if both EXPRESSION1 and EXPRESSION2 are true.
1178
b8c60bc9 1179 ‘EXPRESSION1 || EXPRESSION2’
cce855bc 1180 True if either EXPRESSION1 or EXPRESSION2 is true.
ac50fbac 1181
b8c60bc9 1182 The ‘&&’ and ‘||’ operators do not evaluate EXPRESSION2 if the
a0c0a00f
CR
1183 value of EXPRESSION1 is sufficient to determine the return value of
1184 the entire conditional expression.
ccc6cda3
JA
1185
1186\1f
b80f6443 1187File: bashref.info, Node: Command Grouping, Prev: Conditional Constructs, Up: Compound Commands
ccc6cda3 1188
8868edaf 11893.2.5.3 Grouping Commands
b80f6443 1190.........................
ccc6cda3 1191
b80f6443
JA
1192Bash provides two ways to group a list of commands to be executed as a
1193unit. When commands are grouped, redirections may be applied to the
a0c0a00f
CR
1194entire command list. For example, the output of all the commands in the
1195list may be redirected to a single stream.
ccc6cda3 1196
b8c60bc9 1197‘()’
ccc6cda3
JA
1198 ( LIST )
1199
74091dd4
CR
1200 Placing a list of commands between parentheses forces the shell to
1201 create a subshell (*note Command Execution Environment::), and each
1202 of the commands in LIST is executed in that subshell environment.
b80f6443
JA
1203 Since the LIST is executed in a subshell, variable assignments do
1204 not remain in effect after the subshell completes.
ccc6cda3 1205
b8c60bc9 1206‘{}’
ccc6cda3
JA
1207 { LIST; }
1208
1209 Placing a list of commands between curly braces causes the list to
b8c60bc9
CR
1210 be executed in the current shell environment. No subshell is
1211 created. The semicolon (or newline) following LIST is required.
ccc6cda3
JA
1212
1213 In addition to the creation of a subshell, there is a subtle
1214difference between these two constructs due to historical reasons. The
74091dd4 1215braces are reserved words, so they must be separated from the LIST by
b8c60bc9 1216‘blank’s or other shell metacharacters. The parentheses are operators,
74091dd4
CR
1217and are recognized as separate tokens by the shell even if they are not
1218separated from the LIST by whitespace.
ccc6cda3
JA
1219
1220 The exit status of both of these constructs is the exit status of
1221LIST.
1222
3185942a 1223\1f
495aee44 1224File: bashref.info, Node: Coprocesses, Next: GNU Parallel, Prev: Compound Commands, Up: Shell Commands
3185942a 1225
8868edaf 12263.2.6 Coprocesses
3185942a
JA
1227-----------------
1228
b8c60bc9 1229A ‘coprocess’ is a shell command preceded by the ‘coproc’ reserved word.
3185942a 1230A coprocess is executed asynchronously in a subshell, as if the command
b8c60bc9 1231had been terminated with the ‘&’ control operator, with a two-way pipe
3185942a
JA
1232established between the executing shell and the coprocess.
1233
74091dd4
CR
1234 The syntax for a coprocess is:
1235
ac50fbac 1236 coproc [NAME] COMMAND [REDIRECTIONS]
3185942a 1237
74091dd4
CR
1238This creates a coprocess named NAME. COMMAND may be either a simple
1239command (*note Simple Commands::) or a compound command (*note Compound
1240Commands::). NAME is a shell variable name. If NAME is not supplied,
b8c60bc9 1241the default name is ‘COPROC’.
74091dd4
CR
1242
1243 The recommended form to use for a coprocess is
1244
1245 coproc NAME { COMMAND; }
1246
b8c60bc9
CR
1247This form is preferred because simple commands result in the coprocess
1248always being named ‘COPROC’, and it is simpler to use and more complete
74091dd4
CR
1249than the other compound commands.
1250
1251 There are other forms of coprocesses:
1252
1253 coproc NAME COMPOUND-COMMAND
1254 coproc COMPOUND-COMMAND
1255 coproc SIMPLE-COMMAND
1256
1257If COMMAND is a compound command, NAME is optional. The word following
b8c60bc9 1258‘coproc’ determines whether that word is interpreted as a variable name:
74091dd4
CR
1259it is interpreted as NAME if it is not a reserved word that introduces a
1260compound command. If COMMAND is a simple command, NAME is not allowed;
1261this is to avoid confusion between NAME and the first word of the simple
1262command.
3185942a 1263
ac50fbac 1264 When the coprocess is executed, the shell creates an array variable
74091dd4
CR
1265(*note Arrays::) named NAME in the context of the executing shell. The
1266standard output of COMMAND is connected via a pipe to a file descriptor
1267in the executing shell, and that file descriptor is assigned to NAME[0].
1268The standard input of COMMAND is connected via a pipe to a file
3185942a 1269descriptor in the executing shell, and that file descriptor is assigned
74091dd4
CR
1270to NAME[1]. This pipe is established before any redirections specified
1271by the command (*note Redirections::). The file descriptors can be
1272utilized as arguments to shell commands and redirections using standard
1273word expansions. Other than those created to execute command and
1274process substitutions, the file descriptors are not available in
a0c0a00f 1275subshells.
3185942a 1276
495aee44 1277 The process ID of the shell spawned to execute the coprocess is
b8c60bc9
CR
1278available as the value of the variable ‘NAME_PID’. The ‘wait’ builtin
1279may be used to wait for the coprocess to terminate.
3185942a 1280
ac50fbac 1281 Since the coprocess is created as an asynchronous command, the
b8c60bc9 1282‘coproc’ command always returns success. The return status of a
ac50fbac 1283coprocess is the exit status of COMMAND.
3185942a 1284
495aee44
CR
1285\1f
1286File: bashref.info, Node: GNU Parallel, Prev: Coprocesses, Up: Shell Commands
1287
8868edaf 12883.2.7 GNU Parallel
495aee44
CR
1289------------------
1290
ac50fbac
CR
1291There are ways to run commands in parallel that are not built into Bash.
1292GNU Parallel is a tool to do just that.
1293
1294 GNU Parallel, as its name suggests, can be used to build and run
495aee44
CR
1295commands in parallel. You may run the same command with different
1296arguments, whether they are filenames, usernames, hostnames, or lines
ac50fbac
CR
1297read from files. GNU Parallel provides shorthand references to many of
1298the most common operations (input lines, various portions of the input
1299line, different ways to specify the input source, and so on). Parallel
b8c60bc9 1300can replace ‘xargs’ or feed commands from its input sources to several
ac50fbac 1301different instances of Bash.
495aee44 1302
74091dd4
CR
1303 For a complete description, refer to the GNU Parallel documentation,
1304which is available at
1305<https://www.gnu.org/software/parallel/parallel_tutorial.html>.
ac50fbac 1306
ccc6cda3 1307\1f
cce855bc 1308File: bashref.info, Node: Shell Functions, Next: Shell Parameters, Prev: Shell Commands, Up: Basic Shell Features
ccc6cda3 1309
b80f6443
JA
13103.3 Shell Functions
1311===================
ccc6cda3 1312
b80f6443
JA
1313Shell functions are a way to group commands for later execution using a
1314single name for the group. They are executed just like a "regular"
b8c60bc9
CR
1315simple command. When the name of a shell function is used as a simple
1316command name, the shell executes the list of commands associated with
1317that function name. Shell functions are executed in the current shell
1318context; there is no new process created to interpret them.
ccc6cda3 1319
a0c0a00f 1320 Functions are declared using this syntax:
8868edaf 1321 FNAME () COMPOUND-COMMAND [ REDIRECTIONS ]
495aee44 1322
ac50fbac
CR
1323 or
1324
8868edaf 1325 function FNAME [()] COMPOUND-COMMAND [ REDIRECTIONS ]
ccc6cda3 1326
8868edaf 1327 This defines a shell function named FNAME. The reserved word
b8c60bc9
CR
1328‘function’ is optional. If the ‘function’ reserved word is supplied,
1329the parentheses are optional. The “body” of the function is the
74091dd4
CR
1330compound command COMPOUND-COMMAND (*note Compound Commands::). That
1331command is usually a LIST enclosed between { and }, but may be any
b8c60bc9
CR
1332compound command listed above. If the ‘function’ reserved word is used,
1333but the parentheses are not supplied, the braces are recommended. When
1334the shell is in POSIX mode (*note Bash POSIX Mode::), FNAME must be a
1335valid shell name and may not be the same as one of the special builtins
1336(*note Special Builtins::). When not in POSIX mode, a function name can
1337be any unquoted shell word that does not contain ‘$’.
1338
1339 Any redirections (*note Redirections::) associated with the shell
1340function are performed when the function is executed. Function
1341definitions are deleted using the ‘-f’ option to the ‘unset’ builtin
8868edaf 1342(*note Bourne Shell Builtins::).
0628567a 1343
b80f6443
JA
1344 The exit status of a function definition is zero unless a syntax
1345error occurs or a readonly function with the same name already exists.
1346When executed, the exit status of a function is the exit status of the
1347last command executed in the body.
1348
1349 Note that for historical reasons, in the most common usage the curly
a0c0a00f 1350braces that surround the body of the function must be separated from the
b8c60bc9 1351body by ‘blank’s or newlines. This is because the braces are reserved
a0c0a00f 1352words and are only recognized as such when they are separated from the
b8c60bc9
CR
1353command list by whitespace or another shell metacharacter. When using
1354the braces, the LIST must be terminated by a semicolon, a ‘&’, or a
1355newline.
1356
1357 COMPOUND-COMMAND is executed whenever FNAME is specified as the name
1358of a simple command. Functions are executed in the context of the
1359calling shell; there is no new process created to interpret them
1360(contrast this with the execution of a shell script).
a0c0a00f
CR
1361
1362 When a function is executed, the arguments to the function become the
1363positional parameters during its execution (*note Positional
b8c60bc9
CR
1364Parameters::). The special parameter ‘#’ that expands to the number of
1365positional parameters is updated to reflect the new set of positional
1366parameters. Special parameter ‘0’ is unchanged. The first element of
1367the ‘FUNCNAME’ variable is set to the name of the function while the
1368function is executing.
0001803f
CR
1369
1370 All other aspects of the shell execution environment are identical
b8c60bc9
CR
1371between a function and its caller with these exceptions: the ‘DEBUG’ and
1372‘RETURN’ traps are not inherited unless the function has been given the
1373‘trace’ attribute using the ‘declare’ builtin or the ‘-o functrace’
1374option has been enabled with the ‘set’ builtin, (in which case all
1375functions inherit the ‘DEBUG’ and ‘RETURN’ traps), and the ‘ERR’ trap is
1376not inherited unless the ‘-o errtrace’ shell option has been enabled.
1377*Note Bourne Shell Builtins::, for the description of the ‘trap’
0001803f 1378builtin.
ccc6cda3 1379
b8c60bc9 1380 The ‘FUNCNEST’ variable, if set to a numeric value greater than 0,
495aee44
CR
1381defines a maximum function nesting level. Function invocations that
1382exceed the limit cause the entire command to abort.
1383
b8c60bc9 1384 If the builtin command ‘return’ is executed in a function, the
a0c0a00f 1385function completes and execution resumes with the next command after the
b8c60bc9 1386function call. Any command associated with the ‘RETURN’ trap is
b80f6443 1387executed before execution resumes. When a function completes, the
b8c60bc9
CR
1388values of the positional parameters and the special parameter ‘#’ are
1389restored to the values they had prior to the function's execution. If
1390‘return’ is supplied a numeric argument, that is the function's return
a0c0a00f 1391status; otherwise the function's return status is the exit status of the
b8c60bc9 1392last command executed before the ‘return’.
ccc6cda3 1393
b8c60bc9
CR
1394 Variables local to the function are declared with the ‘local’ builtin
1395(“local variables”). Ordinarily, variables and their values are shared
1396between a function and its caller. These variables are visible only to
1397the function and the commands it invokes. This is particularly
74091dd4
CR
1398important when a shell function calls other functions.
1399
b8c60bc9 1400 In the following description, the “current scope” is a currently-
74091dd4
CR
1401executing function. Previous scopes consist of that function's caller
1402and so on, back to the "global" scope, where the shell is not executing
b8c60bc9
CR
1403any shell function. A local variable at the current local scope is a
1404variable declared using the ‘local’ or ‘declare’ builtins in the
1405function that is currently executing.
d233b485
CR
1406
1407 Local variables "shadow" variables with the same name declared at
1408previous scopes. For instance, a local variable declared in a function
b8c60bc9
CR
1409hides variables with the same name declared at previous scopes,
1410including global variables: references and assignments refer to the
1411local variable, leaving the variables at previous scopes unmodified.
d233b485
CR
1412When the function returns, the global variable is once again visible.
1413
b8c60bc9 1414 The shell uses “dynamic scoping” to control a variable's visibility
d233b485
CR
1415within functions. With dynamic scoping, visible variables and their
1416values are a result of the sequence of function calls that caused
1417execution to reach the current function. The value of a variable that a
1418function sees depends on its value within its caller, if any, whether
b8c60bc9
CR
1419that caller is the global scope or another shell function. This is also
1420the value that a local variable declaration shadows, and the value that
1421is restored when the function returns.
d233b485 1422
b8c60bc9
CR
1423 For example, if a variable ‘var’ is declared as local in function
1424‘func1’, and ‘func1’ calls another function ‘func2’, references to ‘var’
1425made from within ‘func2’ resolve to the local variable ‘var’ from
1426‘func1’, shadowing any global variable named ‘var’.
d233b485
CR
1427
1428 The following script demonstrates this behavior. When executed, the
1429script displays
1430
1431 In func2, var = func1 local
1432
1433 func1()
1434 {
1435 local var='func1 local'
1436 func2
1437 }
1438
1439 func2()
1440 {
1441 echo "In func2, var = $var"
1442 }
1443
1444 var=global
1445 func1
1446
b8c60bc9
CR
1447 The ‘unset’ builtin also acts using the same dynamic scope: if a
1448variable is local to the current scope, ‘unset’ unsets it; otherwise the
1449unset will refer to the variable found in any calling scope as described
1450above. If a variable at the current local scope is unset, it remains so
1451(appearing as unset) until it is reset in that scope or until the
1452function returns. Once the function returns, any instance of the
1453variable at a previous scope becomes visible. If the unset acts on a
1454variable at a previous scope, any instance of a variable with that name
1455that had been shadowed becomes visible (see below how the
1456‘localvar_unset’ shell option changes this behavior).
1457
1458 The ‘-f’ option to the ‘declare’ (‘typeset’) builtin command (*note
1459Bash Builtins::) lists function names and definitions. The ‘-F’ option
1460to ‘declare’ or ‘typeset’ lists the function names only (and optionally
1461the source file and line number, if the ‘extdebug’ shell option is
1462enabled). Functions may be exported so that child shell processes
1463(those created when executing a separate shell invocation) automatically
1464have them defined with the ‘-f’ option to the ‘export’ builtin (*note
1465Bourne Shell Builtins::). The ‘-f’ option to the ‘unset’ builtin (*note
1466Bourne Shell Builtins::) deletes a function definition.
1467
1468 Functions may be recursive. The ‘FUNCNEST’ variable may be used to
495aee44 1469limit the depth of the function call stack and restrict the number of
b8c60bc9 1470function invocations. By default, Bash places no limit on the number of
a0c0a00f 1471recursive calls.
ccc6cda3
JA
1472
1473\1f
1474File: bashref.info, Node: Shell Parameters, Next: Shell Expansions, Prev: Shell Functions, Up: Basic Shell Features
1475
b80f6443
JA
14763.4 Shell Parameters
1477====================
ccc6cda3
JA
1478
1479* Menu:
1480
1481* Positional Parameters:: The shell's command-line arguments.
b80f6443 1482* Special Parameters:: Parameters denoted by special characters.
ccc6cda3 1483
b8c60bc9
CR
1484A “parameter” is an entity that stores values. It can be a ‘name’, a
1485number, or one of the special characters listed below. A “variable” is
1486a parameter denoted by a ‘name’. A variable has a ‘value’ and zero or
1487more ‘attributes’. Attributes are assigned using the ‘declare’ builtin
1488command (see the description of the ‘declare’ builtin in *note Bash
1489Builtins::). The ‘export’ and ‘readonly’ builtins assign specific
1490attributes.
ccc6cda3
JA
1491
1492 A parameter is set if it has been assigned a value. The null string
1493is a valid value. Once a variable is set, it may be unset only by using
b8c60bc9 1494the ‘unset’ builtin command.
ccc6cda3 1495
b8c60bc9 1496 A variable is assigned to using a statement of the form
ccc6cda3 1497 NAME=[VALUE]
a0c0a00f 1498If VALUE is not given, the variable is assigned the null string. All
ccc6cda3 1499VALUEs undergo tilde expansion, parameter and variable expansion,
74091dd4 1500command substitution, arithmetic expansion, and quote removal (*note
b8c60bc9 1501Shell Parameter Expansion::). If the variable has its ‘integer’
74091dd4 1502attribute set, then VALUE is evaluated as an arithmetic expression even
b8c60bc9 1503if the ‘$((...))’ expansion is not used (*note Arithmetic Expansion::).
74091dd4 1504Word splitting and filename expansion are not performed. Assignment
b8c60bc9
CR
1505statements may also appear as arguments to the ‘alias’, ‘declare’,
1506‘typeset’, ‘export’, ‘readonly’, and ‘local’ builtin commands
1507(“declaration commands”). When in POSIX mode (*note Bash POSIX Mode::),
74091dd4 1508these builtins may appear in a command after one or more instances of
b8c60bc9
CR
1509the ‘command’ builtin and retain these assignment statement properties.
1510For example,
1511 command export var=value
ccc6cda3 1512
95732b49 1513 In the context where an assignment statement is assigning a value to
b8c60bc9
CR
1514a shell variable or array index (*note Arrays::), the ‘+=’ operator
1515appends to or adds to the variable's previous value. This includes
1516arguments to declaration commands such as ‘declare’ that accept
1517assignment statements. When ‘+=’ is applied to a variable for which the
1518‘integer’ attribute has been set, the variable's current value and VALUE
1519are each evaluated as arithmetic expressions, and the sum of the results
1520is assigned as the variable's value. The current value is usually an
1521integer constant, but may be an expression. When ‘+=’ is applied to an
a0c0a00f 1522array variable using compound assignment (*note Arrays::), the
b8c60bc9 1523variable's value is not unset (as it is when using ‘=’), and new values
a0c0a00f
CR
1524are appended to the array beginning at one greater than the array's
1525maximum index (for indexed arrays), or added as additional key-value
1526pairs in an associative array. When applied to a string-valued
1527variable, VALUE is expanded and appended to the variable's value.
1528
b8c60bc9
CR
1529 A variable can be assigned the ‘nameref’ attribute using the ‘-n’
1530option to the ‘declare’ or ‘local’ builtin commands (*note Bash
1531Builtins::) to create a “nameref”, or a reference to another variable.
ac50fbac 1532This allows variables to be manipulated indirectly. Whenever the
a0c0a00f
CR
1533nameref variable is referenced, assigned to, unset, or has its
1534attributes modified (other than using or changing the nameref attribute
1535itself), the operation is actually performed on the variable specified
1536by the nameref variable's value. A nameref is commonly used within
1537shell functions to refer to a variable whose name is passed as an
1538argument to the function. For instance, if a variable name is passed to
1539a shell function as its first argument, running
ac50fbac 1540 declare -n ref=$1
b8c60bc9
CR
1541inside the function creates a local nameref variable ‘ref’ whose value
1542is the variable name passed as the first argument. References and
1543assignments to ‘ref’, and changes to its attributes, are treated as
1544references, assignments, and attribute modifications to the variable
1545whose name was passed as ‘$1’.
ac50fbac 1546
b8c60bc9 1547 If the control variable in a ‘for’ loop has the nameref attribute,
ac50fbac 1548the list of words can be a list of shell variables, and a name reference
b8c60bc9 1549is established for each word in the list, in turn, when the loop is
a0c0a00f 1550executed. Array variables cannot be given the nameref attribute.
ac50fbac 1551However, nameref variables can reference array variables and subscripted
b8c60bc9
CR
1552array variables. Namerefs can be unset using the ‘-n’ option to the
1553‘unset’ builtin (*note Bourne Shell Builtins::). Otherwise, if ‘unset’
ac50fbac 1554is executed with the name of a nameref variable as an argument, the
b8c60bc9
CR
1555variable referenced by the nameref variable is unset.
1556
1557 When the shell starts, it reads its environment and creates a shell
1558variable from each environment variable that has a valid name, as
1559described below (*note Environment::).
ac50fbac 1560
ccc6cda3
JA
1561\1f
1562File: bashref.info, Node: Positional Parameters, Next: Special Parameters, Up: Shell Parameters
1563
b80f6443
JA
15643.4.1 Positional Parameters
1565---------------------------
ccc6cda3 1566
b8c60bc9
CR
1567A “positional parameter” is a parameter denoted by one or more digits,
1568other than the single digit ‘0’. Positional parameters are assigned
ccc6cda3 1569from the shell's arguments when it is invoked, and may be reassigned
b8c60bc9
CR
1570using the ‘set’ builtin command. Positional parameter ‘N’ may be
1571referenced as ‘${N}’, or as ‘$N’ when ‘N’ consists of a single digit.
bb70624e 1572Positional parameters may not be assigned to with assignment statements.
b8c60bc9 1573The ‘set’ and ‘shift’ builtins are used to set and unset them (*note
28ef6c31
JA
1574Shell Builtin Commands::). The positional parameters are temporarily
1575replaced when a shell function is executed (*note Shell Functions::).
ccc6cda3 1576
a0c0a00f 1577 When a positional parameter consisting of more than a single digit is
b8c60bc9
CR
1578expanded, it must be enclosed in braces. Without braces, a digit
1579following ‘$’ can only refer to one of the first nine positional
1580parameters ($1\-$9) or the special parameter $0 (see below).
ccc6cda3
JA
1581
1582\1f
1583File: bashref.info, Node: Special Parameters, Prev: Positional Parameters, Up: Shell Parameters
1584
b80f6443
JA
15853.4.2 Special Parameters
1586------------------------
ccc6cda3 1587
b80f6443 1588The shell treats several parameters specially. These parameters may
b8c60bc9
CR
1589only be referenced; assignment to them is not allowed. Special
1590parameters are denoted by one of the following characters.
ccc6cda3 1591
b8c60bc9 1592‘*’
a0c0a00f
CR
1593 ($*) Expands to the positional parameters, starting from one. When
1594 the expansion is not within double quotes, each positional
b8c60bc9
CR
1595 parameter expands to a separate word. In contexts where word
1596 expansions are performed, those words are subject to further word
1597 splitting and filename expansion. When the expansion occurs within
1598 double quotes, it expands to a single word with the value of each
1599 parameter separated by the first character of the ‘IFS’ variable.
1600 That is, ‘"$*"’ is equivalent to ‘"$1C$2C..."’, where C is the
1601 first character of the value of the ‘IFS’ variable. If ‘IFS’ is
1602 unset, the parameters are separated by spaces. If ‘IFS’ is null,
1603 the parameters are joined without intervening separators.
1604
1605‘@’
d233b485
CR
1606 ($@) Expands to the positional parameters, starting from one. In
1607 contexts where word splitting is performed, this expands each
1608 positional parameter to a separate word; if not within double
1609 quotes, these words are subject to word splitting. In contexts
b8c60bc9
CR
1610 where word splitting is not performed, such as the value portion of
1611 an assignment statement, this expands to a single word with each
1612 positional parameter separated by a space. When the expansion
1613 occurs within double quotes, and word splitting is performed, each
1614 parameter expands to a separate word. That is, ‘"$@"’ is
1615 equivalent to ‘"$1" "$2" ...’. If the double-quoted expansion
1616 occurs within a word, the expansion of the first parameter is
1617 joined with the expansion of the beginning part of the original
1618 word, and the expansion of the last parameter is joined with the
1619 expansion of the last part of the original word. When there are no
1620 positional parameters, ‘"$@"’ and ‘$@’ expand to nothing (i.e.,
1621 they are removed).
1622
1623‘#’
ac50fbac 1624 ($#) Expands to the number of positional parameters in decimal.
ccc6cda3 1625
b8c60bc9 1626‘?’
a0c0a00f 1627 ($?) Expands to the exit status of the most recently executed
b8c60bc9 1628 command.
ccc6cda3 1629
b8c60bc9 1630‘-’
ac50fbac 1631 ($-, a hyphen.) Expands to the current option flags as specified
b8c60bc9
CR
1632 upon invocation, by the ‘set’ builtin command, or those set by the
1633 shell itself (such as the ‘-i’ option).
ccc6cda3 1634
b8c60bc9 1635‘$’
74091dd4
CR
1636 ($$) Expands to the process ID of the shell. In a subshell, it
1637 expands to the process ID of the invoking shell, not the subshell.
ccc6cda3 1638
b8c60bc9 1639‘!’
a0c0a00f
CR
1640 ($!) Expands to the process ID of the job most recently placed
1641 into the background, whether executed as an asynchronous command or
b8c60bc9 1642 using the ‘bg’ builtin (*note Job Control Builtins::).
a0c0a00f 1643
b8c60bc9 1644‘0’
a0c0a00f
CR
1645 ($0) Expands to the name of the shell or shell script. This is set
1646 at shell initialization. If Bash is invoked with a file of
b8c60bc9
CR
1647 commands (*note Shell Scripts::), ‘$0’ is set to the name of that
1648 file. If Bash is started with the ‘-c’ option (*note Invoking
1649 Bash::), then ‘$0’ is set to the first argument after the string to
a0c0a00f 1650 be executed, if one is present. Otherwise, it is set to the
ac50fbac 1651 filename used to invoke Bash, as given by argument zero.
ccc6cda3 1652
ccc6cda3
JA
1653\1f
1654File: bashref.info, Node: Shell Expansions, Next: Redirections, Prev: Shell Parameters, Up: Basic Shell Features
1655
b80f6443
JA
16563.5 Shell Expansions
1657====================
ccc6cda3 1658
b80f6443 1659Expansion is performed on the command line after it has been split into
b8c60bc9 1660‘token’s. Bash performs these expansions:
ac50fbac 1661
b8c60bc9
CR
1662 • brace expansion
1663 • tilde expansion
1664 • parameter and variable expansion
1665 • command substitution
1666 • arithmetic expansion
1667 • word splitting
1668 • filename expansion
1669 • quote removal
ccc6cda3
JA
1670
1671* Menu:
1672
cce855bc
JA
1673* Brace Expansion:: Expansion of expressions within braces.
1674* Tilde Expansion:: Expansion of the ~ character.
ccc6cda3
JA
1675* Shell Parameter Expansion:: How Bash expands variables to their values.
1676* Command Substitution:: Using the output of a command as an argument.
cce855bc 1677* Arithmetic Expansion:: How to use arithmetic in shell expansions.
ccc6cda3
JA
1678* Process Substitution:: A way to write and read to and from a
1679 command.
1680* Word Splitting:: How the results of expansion are split into separate
1681 arguments.
1682* Filename Expansion:: A shorthand for specifying filenames matching patterns.
1683* Quote Removal:: How and when quote characters are removed from
1684 words.
1685
ac50fbac
CR
1686 The order of expansions is: brace expansion; tilde expansion,
1687parameter and variable expansion, arithmetic expansion, and command
b8c60bc9
CR
1688substitution (done in a left-to-right fashion); word splitting; filename
1689expansion; and quote removal.
ccc6cda3
JA
1690
1691 On systems that can support it, there is an additional expansion
b8c60bc9 1692available: “process substitution”. This is performed at the same time
74091dd4 1693as tilde, parameter, variable, and arithmetic expansion and command
ac50fbac 1694substitution.
ccc6cda3 1695
b8c60bc9
CR
1696 “Quote removal” is always performed last. It removes quote
1697characters present in the original word, not ones resulting from one of
1698the other expansions, unless they have been quoted themselves. *Note
1699Quote Removal:: for more details.
a0c0a00f 1700
ccc6cda3 1701 Only brace expansion, word splitting, and filename expansion can
d233b485 1702increase the number of words of the expansion; other expansions expand a
ccc6cda3 1703single word to a single word. The only exceptions to this are the
b8c60bc9
CR
1704expansions of ‘"$@"’ and ‘$*’ (*note Special Parameters::), and
1705‘"${NAME[@]}"’ and ‘${NAME[*]}’ (*note Arrays::).
ccc6cda3
JA
1706
1707\1f
cce855bc
JA
1708File: bashref.info, Node: Brace Expansion, Next: Tilde Expansion, Up: Shell Expansions
1709
b80f6443
JA
17103.5.1 Brace Expansion
1711---------------------
cce855bc 1712
b8c60bc9
CR
1713Brace expansion is a mechanism to generate arbitrary strings sharing a
1714common prefix and suffix, either of which can be empty. This mechanism
1715is similar to “filename expansion” (*note Filename Expansion::), but the
1716filenames generated need not exist. Patterns to be brace expanded are
1717formed from an optional PREAMBLE, followed by either a series of
1718comma-separated strings or a sequence expression between a pair of
1719braces, followed by an optional POSTSCRIPT. The preamble is prefixed to
1720each string contained within the braces, and the postscript is then
1721appended to each resulting string, expanding left to right.
cce855bc
JA
1722
1723 Brace expansions may be nested. The results of each expanded string
b8c60bc9
CR
1724are not sorted; brace expansion preserves left to right order. For
1725example,
cce855bc
JA
1726 bash$ echo a{d,c,b}e
1727 ade ace abe
1728
b8c60bc9 1729 A sequence expression takes the form ‘X..Y[..INCR]’, where X and Y
74091dd4
CR
1730are either integers or letters, and INCR, an optional increment, is an
1731integer. When integers are supplied, the expression expands to each
b8c60bc9
CR
1732number between X and Y, inclusive. If either X or Y begins with a zero,
1733each generated term will contain the same number of digits, zero-padding
1734where necessary. When letters are supplied, the expression expands to
1735each character lexicographically between X and Y, inclusive, using the C
74091dd4
CR
1736locale. Note that both X and Y must be of the same type (integer or
1737letter). When the increment is supplied, it is used as the difference
1738between each term. The default increment is 1 or -1 as appropriate.
b80f6443 1739
cce855bc
JA
1740 Brace expansion is performed before any other expansions, and any
1741characters special to other expansions are preserved in the result. It
1742is strictly textual. Bash does not apply any syntactic interpretation
d233b485 1743to the context of the expansion or the text between the braces.
cce855bc
JA
1744
1745 A correctly-formed brace expansion must contain unquoted opening and
b80f6443
JA
1746closing braces, and at least one unquoted comma or a valid sequence
1747expression. Any incorrectly formed brace expansion is left unchanged.
1748
b8c60bc9 1749 A ‘{’ or ‘,’ may be quoted with a backslash to prevent its being
b80f6443 1750considered part of a brace expression. To avoid conflicts with
b8c60bc9
CR
1751parameter expansion, the string ‘${’ is not considered eligible for
1752brace expansion, and inhibits brace expansion until the closing ‘}’.
cce855bc
JA
1753
1754 This construct is typically used as shorthand when the common prefix
1755of the strings to be generated is longer than in the above example:
1756 mkdir /usr/local/src/bash/{old,new,dist,bugs}
1757 or
1758 chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}
1759
b8c60bc9
CR
1760 Brace expansion introduces a slight incompatibility with historical
1761versions of ‘sh’. ‘sh’ does not treat opening or closing braces
1762specially when they appear as part of a word, and preserves them in the
1763output. Bash removes braces from words as a consequence of brace
1764expansion. For example, a word entered to ‘sh’ as ‘file{1,2}’ appears
1765identically in the output. Bash outputs that word as ‘file1 file2’
1766after brace expansion. Start Bash with the ‘+B’ option or disable brace
1767expansion with the ‘+B’ option to the ‘set’ command (*note Shell Builtin
1768Commands::) for strict ‘sh’ compatibility.
1769
cce855bc
JA
1770\1f
1771File: bashref.info, Node: Tilde Expansion, Next: Shell Parameter Expansion, Prev: Brace Expansion, Up: Shell Expansions
1772
b80f6443
JA
17733.5.2 Tilde Expansion
1774---------------------
cce855bc 1775
b8c60bc9 1776If a word begins with an unquoted tilde character (‘~’), all of the
cce855bc 1777characters up to the first unquoted slash (or all characters, if there
b8c60bc9 1778is no unquoted slash) are considered a “tilde-prefix”. If none of the
cce855bc 1779characters in the tilde-prefix are quoted, the characters in the
b8c60bc9 1780tilde-prefix following the tilde are treated as a possible “login name”.
cce855bc 1781If this login name is the null string, the tilde is replaced with the
b8c60bc9
CR
1782value of the ‘HOME’ shell variable. If ‘HOME’ is unset, the tilde
1783expands to the home directory of the user executing the shell instead.
cce855bc
JA
1784Otherwise, the tilde-prefix is replaced with the home directory
1785associated with the specified login name.
1786
b8c60bc9
CR
1787 If the tilde-prefix is ‘~+’, the value of the shell variable ‘PWD’
1788replaces the tilde-prefix. If the tilde-prefix is ‘~-’, the shell
1789substitutes the value of the shell variable ‘OLDPWD’, if it is set.
cce855bc
JA
1790
1791 If the characters following the tilde in the tilde-prefix consist of
b8c60bc9 1792a number N, optionally prefixed by a ‘+’ or a ‘-’, the tilde-prefix is
cce855bc 1793replaced with the corresponding element from the directory stack, as it
b8c60bc9 1794would be displayed by the ‘dirs’ builtin invoked with the characters
cce855bc 1795following tilde in the tilde-prefix as an argument (*note The Directory
28ef6c31 1796Stack::). If the tilde-prefix, sans the tilde, consists of a number
b8c60bc9
CR
1797without a leading ‘+’ or ‘-’, tilde expansion assumes ‘+’.
1798
1799 The results of tilde expansion are treated as if they were quoted, so
1800the replacement is not subject to word splitting and filename expansion.
cce855bc 1801
b8c60bc9
CR
1802 If the login name is invalid, or the tilde expansion fails, the
1803tilde-prefix is left unchanged.
cce855bc 1804
b8c60bc9
CR
1805 Bash checks each variable assignment for unquoted tilde-prefixes
1806immediately following a ‘:’ or the first ‘=’, and performs tilde
1807expansion in these cases. Consequently, one may use filenames with
1808tildes in assignments to ‘PATH’, ‘MAILPATH’, and ‘CDPATH’, and the shell
a0c0a00f 1809assigns the expanded value.
cce855bc
JA
1810
1811 The following table shows how Bash treats unquoted tilde-prefixes:
1812
b8c60bc9
CR
1813‘~’
1814 The value of ‘$HOME’.
1815‘~/foo’
1816 ‘$HOME/foo’
cce855bc 1817
b8c60bc9
CR
1818‘~fred/foo’
1819 The directory or file ‘foo’ in the home directory of the user
1820 ‘fred’.
cce855bc 1821
b8c60bc9
CR
1822‘~+/foo’
1823 ‘$PWD/foo’
cce855bc 1824
b8c60bc9
CR
1825‘~-/foo’
1826 ‘${OLDPWD-'~-'}/foo’
cce855bc 1827
b8c60bc9
CR
1828‘~N’
1829 The string that would be displayed by ‘dirs +N’.
cce855bc 1830
b8c60bc9
CR
1831‘~+N’
1832 The string that would be displayed by ‘dirs +N’.
cce855bc 1833
b8c60bc9
CR
1834‘~-N’
1835 The string that would be displayed by ‘dirs -N’.
cce855bc 1836
d233b485
CR
1837 Bash also performs tilde expansion on words satisfying the conditions
1838of variable assignments (*note Shell Parameters::) when they appear as
1839arguments to simple commands. Bash does not do this, except for the
74091dd4 1840declaration commands listed above, when in POSIX mode.
d233b485 1841
cce855bc
JA
1842\1f
1843File: bashref.info, Node: Shell Parameter Expansion, Next: Command Substitution, Prev: Tilde Expansion, Up: Shell Expansions
ccc6cda3 1844
b80f6443
JA
18453.5.3 Shell Parameter Expansion
1846-------------------------------
ccc6cda3 1847
b8c60bc9 1848The ‘$’ character introduces parameter expansion, command substitution,
b80f6443
JA
1849or arithmetic expansion. The parameter name or symbol to be expanded
1850may be enclosed in braces, which are optional but serve to protect the
1851variable to be expanded from characters immediately following it which
b8c60bc9
CR
1852could be interpreted as part of the name. For example, if the first
1853positional parameter has the value ‘a’, then ‘${11}’ expands to the
1854value of the eleventh positional parameter, while ‘$11’ expands to ‘a1’.
ccc6cda3 1855
b8c60bc9 1856 When braces are used, the matching ending brace is the first ‘}’ not
cce855bc
JA
1857escaped by a backslash or within a quoted string, and not within an
1858embedded arithmetic expansion, command substitution, or parameter
1859expansion.
1860
b8c60bc9
CR
1861 The basic form of parameter expansion is ${PARAMETER}, which
1862substitutes the value of PARAMETER. The PARAMETER is a shell parameter
1863as described above (*note Shell Parameters::) or an array reference
1864(*note Arrays::). The braces are required when PARAMETER is a
1865positional parameter with more than one digit, or when PARAMETER is
1866followed by a character that is not to be interpreted as part of its
1867name.
ac50fbac 1868
a0c0a00f 1869 If the first character of PARAMETER is an exclamation point (!), and
74091dd4 1870PARAMETER is not a nameref, it introduces a level of indirection. Bash
d233b485 1871uses the value formed by expanding the rest of PARAMETER as the new
b8c60bc9
CR
1872PARAMETER; this new parameter is then expanded and that value is used in
1873the rest of the expansion, rather than the expansion of the original
1874PARAMETER. This is known as ‘indirect expansion’. The value is subject
1875to tilde expansion, parameter expansion, command substitution, and
1876arithmetic expansion. If PARAMETER is a nameref, this expands to the
1877name of the variable referenced by PARAMETER instead of performing the
1878complete indirect expansion, for compatibility. The exceptions to this
1879are the expansions of ${!PREFIX*} and ${!NAME[@]} described below. The
1880exclamation point must immediately follow the left brace in order to
1881introduce indirection.
ccc6cda3
JA
1882
1883 In each of the cases below, WORD is subject to tilde expansion,
1884parameter expansion, command substitution, and arithmetic expansion.
bb70624e 1885
b8c60bc9
CR
1886 When not performing substring expansion, using the forms described
1887below (e.g., ‘:-’), Bash tests for a parameter that is unset or null.
ac50fbac
CR
1888Omitting the colon results in a test only for a parameter that is unset.
1889Put another way, if the colon is included, the operator tests for both
17345e5a
JA
1890PARAMETER's existence and that its value is not null; if the colon is
1891omitted, the operator tests only for existence.
ccc6cda3 1892
b8c60bc9 1893‘${PARAMETER:−WORD}’
ccc6cda3
JA
1894 If PARAMETER is unset or null, the expansion of WORD is
1895 substituted. Otherwise, the value of PARAMETER is substituted.
1896
74091dd4
CR
1897 $ v=123
1898 $ echo ${v-unset}
1899 123
b8c60bc9
CR
1900 $ echo ${v:-unset-or-null}
1901 123
1902 $ unset v
1903 $ echo ${v-unset}
1904 unset
1905 $ v=
1906 $ echo ${v-unset}
1907
1908 $ echo ${v:-unset-or-null}
1909 unset-or-null
74091dd4 1910
b8c60bc9 1911‘${PARAMETER:=WORD}’
a0c0a00f 1912 If PARAMETER is unset or null, the expansion of WORD is assigned to
b8c60bc9
CR
1913 PARAMETER, and the result of the expansion is the final value of
1914 PARAMETER. Positional parameters and special parameters may not be
1915 assigned in this way.
1916
1917 $ unset var
1918 $ : ${var=DEFAULT}
1919 $ echo $var
1920 DEFAULT
1921 $ var=
1922 $ : ${var=DEFAULT}
1923 $ echo $var
ccc6cda3 1924
74091dd4
CR
1925 $ var=
1926 $ : ${var:=DEFAULT}
1927 $ echo $var
1928 DEFAULT
b8c60bc9
CR
1929 $ unset var
1930 $ : ${var:=DEFAULT}
1931 $ echo $var
1932 DEFAULT
74091dd4 1933
b8c60bc9
CR
1934‘${PARAMETER:?WORD}’
1935 If PARAMETER is null or unset, the shell writes the expansion of
1936 WORD (or a message to that effect if WORD is not present) to the
1937 standard error and, if it is not interactive, exits with a non-zero
1938 status. An interactive shell does not exit, but does not execute
1939 the command associated with the expansion. Otherwise, the value of
1940 PARAMETER is substituted.
ccc6cda3 1941
74091dd4
CR
1942 $ var=
1943 $ : ${var:?var is unset or null}
1944 bash: var: var is unset or null
b8c60bc9
CR
1945 $ echo ${var?var is unset}
1946
1947 $ unset var
1948 $ : ${var?var is unset}
1949 bash: var: var is unset
1950 $ : ${var:?var is unset or null}
1951 bash: var: var is unset or null
1952 $ var=123
1953 $ echo ${var:?var is unset or null}
1954 123
74091dd4 1955
b8c60bc9 1956‘${PARAMETER:+WORD}’
ccc6cda3 1957 If PARAMETER is null or unset, nothing is substituted, otherwise
b8c60bc9
CR
1958 the expansion of WORD is substituted. The value of PARAMETER is
1959 not used.
ccc6cda3 1960
74091dd4
CR
1961 $ var=123
1962 $ echo ${var:+var is set and not null}
1963 var is set and not null
b8c60bc9
CR
1964 $ echo ${var+var is set}
1965 var is set
1966 $ var=
1967 $ echo ${var:+var is set and not null}
1968
1969 $ echo ${var+var is set}
1970 var is set
1971 $ unset var
1972 $ echo ${var+var is set}
74091dd4 1973
b8c60bc9
CR
1974 $ echo ${var:+var is set and not null}
1975
1976 $
1977
1978‘${PARAMETER:OFFSET}’
1979‘${PARAMETER:OFFSET:LENGTH}’
ac50fbac
CR
1980 This is referred to as Substring Expansion. It expands to up to
1981 LENGTH characters of the value of PARAMETER starting at the
b8c60bc9
CR
1982 character specified by OFFSET. If PARAMETER is ‘@’ or ‘*’, an
1983 indexed array subscripted by ‘@’ or ‘*’, or an associative array
1984 name, the results differ as described below. If :LENGTH is omitted
1985 (the first form above), this expands to the substring of the value
1986 of PARAMETER starting at the character specified by OFFSET and
1987 extending to the end of the value. If OFFSET is omitted, it is
1988 treated as 0. If LENGTH is omitted, but the colon after OFFSET is
1989 present, it is treated as 0. LENGTH and OFFSET are arithmetic
1990 expressions (*note Shell Arithmetic::).
ccc6cda3 1991
ccc6cda3 1992 If OFFSET evaluates to a number less than zero, the value is used
ac50fbac
CR
1993 as an offset in characters from the end of the value of PARAMETER.
1994 If LENGTH evaluates to a number less than zero, it is interpreted
1995 as an offset in characters from the end of the value of PARAMETER
1996 rather than a number of characters, and the expansion is the
b8c60bc9
CR
1997 characters between OFFSET and that result.
1998
1999 Note that a negative offset must be separated from the colon by at
2000 least one space to avoid being confused with the ‘:-’ expansion.
ac50fbac
CR
2001
2002 Here are some examples illustrating substring expansion on
2003 parameters and subscripted arrays:
2004
2005 $ string=01234567890abcdefgh
2006 $ echo ${string:7}
2007 7890abcdefgh
2008 $ echo ${string:7:0}
d233b485 2009
ac50fbac
CR
2010 $ echo ${string:7:2}
2011 78
2012 $ echo ${string:7:-2}
2013 7890abcdef
2014 $ echo ${string: -7}
2015 bcdefgh
2016 $ echo ${string: -7:0}
d233b485 2017
ac50fbac
CR
2018 $ echo ${string: -7:2}
2019 bc
2020 $ echo ${string: -7:-2}
2021 bcdef
2022 $ set -- 01234567890abcdefgh
2023 $ echo ${1:7}
2024 7890abcdefgh
2025 $ echo ${1:7:0}
d233b485 2026
ac50fbac
CR
2027 $ echo ${1:7:2}
2028 78
2029 $ echo ${1:7:-2}
2030 7890abcdef
2031 $ echo ${1: -7}
2032 bcdefgh
2033 $ echo ${1: -7:0}
d233b485 2034
ac50fbac
CR
2035 $ echo ${1: -7:2}
2036 bc
2037 $ echo ${1: -7:-2}
2038 bcdef
2039 $ array[0]=01234567890abcdefgh
2040 $ echo ${array[0]:7}
2041 7890abcdefgh
2042 $ echo ${array[0]:7:0}
d233b485 2043
ac50fbac
CR
2044 $ echo ${array[0]:7:2}
2045 78
2046 $ echo ${array[0]:7:-2}
2047 7890abcdef
2048 $ echo ${array[0]: -7}
2049 bcdefgh
2050 $ echo ${array[0]: -7:0}
d233b485 2051
ac50fbac
CR
2052 $ echo ${array[0]: -7:2}
2053 bc
2054 $ echo ${array[0]: -7:-2}
2055 bcdef
2056
b8c60bc9 2057 If PARAMETER is ‘@’ or ‘*’, the result is LENGTH positional
74091dd4
CR
2058 parameters beginning at OFFSET. A negative OFFSET is taken
2059 relative to one greater than the greatest positional parameter, so
b8c60bc9
CR
2060 an offset of -1 evaluates to the last positional parameter (or 0 if
2061 there are no positional parameters). It is an expansion error if
2062 LENGTH evaluates to a number less than zero.
ac50fbac
CR
2063
2064 The following examples illustrate substring expansion using
2065 positional parameters:
2066
2067 $ set -- 1 2 3 4 5 6 7 8 9 0 a b c d e f g h
2068 $ echo ${@:7}
2069 7 8 9 0 a b c d e f g h
2070 $ echo ${@:7:0}
d233b485 2071
ac50fbac
CR
2072 $ echo ${@:7:2}
2073 7 8
2074 $ echo ${@:7:-2}
2075 bash: -2: substring expression < 0
2076 $ echo ${@: -7:2}
2077 b c
2078 $ echo ${@:0}
2079 ./bash 1 2 3 4 5 6 7 8 9 0 a b c d e f g h
2080 $ echo ${@:0:2}
2081 ./bash 1
2082 $ echo ${@: -7:0}
d233b485 2083
a0c0a00f 2084
b8c60bc9 2085 If PARAMETER is an indexed array name subscripted by ‘@’ or ‘*’,
ac50fbac 2086 the result is the LENGTH members of the array beginning with
b8c60bc9 2087 ‘${PARAMETER[OFFSET]}’. A negative OFFSET is taken relative to one
a0c0a00f
CR
2088 greater than the maximum index of the specified array. It is an
2089 expansion error if LENGTH evaluates to a number less than zero.
ac50fbac
CR
2090
2091 These examples show how you can use substring expansion with
2092 indexed arrays:
2093
2094 $ array=(0 1 2 3 4 5 6 7 8 9 0 a b c d e f g h)
2095 $ echo ${array[@]:7}
2096 7 8 9 0 a b c d e f g h
2097 $ echo ${array[@]:7:2}
2098 7 8
2099 $ echo ${array[@]: -7:2}
2100 b c
2101 $ echo ${array[@]: -7:-2}
2102 bash: -2: substring expression < 0
2103 $ echo ${array[@]:0}
2104 0 1 2 3 4 5 6 7 8 9 0 a b c d e f g h
2105 $ echo ${array[@]:0:2}
2106 0 1
2107 $ echo ${array[@]: -7:0}
d233b485 2108
a0c0a00f 2109
ac50fbac
CR
2110 Substring expansion applied to an associative array produces
2111 undefined results.
2112
95732b49 2113 Substring indexing is zero-based unless the positional parameters
3185942a 2114 are used, in which case the indexing starts at 1 by default. If
b8c60bc9 2115 OFFSET is 0, and the positional parameters are used, ‘$0’ is
3185942a 2116 prefixed to the list.
ccc6cda3 2117
b8c60bc9
CR
2118‘${!PREFIX*}’
2119‘${!PREFIX@}’
bb70624e 2120 Expands to the names of variables whose names begin with PREFIX,
b8c60bc9
CR
2121 separated by the first character of the ‘IFS’ special variable.
2122 When ‘@’ is used and the expansion appears within double quotes,
3185942a 2123 each variable name expands to a separate word.
bb70624e 2124
b8c60bc9
CR
2125‘${!NAME[@]}’
2126‘${!NAME[*]}’
b80f6443
JA
2127 If NAME is an array variable, expands to the list of array indices
2128 (keys) assigned in NAME. If NAME is not an array, expands to 0 if
b8c60bc9 2129 NAME is set and null otherwise. When ‘@’ is used and the expansion
a0c0a00f 2130 appears within double quotes, each key expands to a separate word.
b80f6443 2131
b8c60bc9
CR
2132‘${#PARAMETER}’
2133 Substitutes the length in characters of the value of PARAMETER. If
2134 PARAMETER is ‘*’ or ‘@’, the value substituted is the number of
2135 positional parameters. If PARAMETER is an array name subscripted
2136 by ‘*’ or ‘@’, the value substituted is the number of elements in
2137 the array. If PARAMETER is an indexed array name subscripted by a
2138 negative number, that number is interpreted as relative to one
2139 greater than the maximum index of PARAMETER, so negative indices
2140 count back from the end of the array, and an index of -1 references
2141 the last element.
2142
2143‘${PARAMETER#WORD}’
2144‘${PARAMETER##WORD}’
2145 The WORD is expanded to produce a pattern and matched against the
2146 expanded value of PARAMETER according to the rules described below
2147 (*note Pattern Matching::). If the pattern matches the beginning
2148 of the expanded value of PARAMETER, then the result of the
2149 expansion is the expanded value of PARAMETER with the shortest
2150 matching pattern (the ‘#’ case) or the longest matching pattern
2151 (the ‘##’ case) deleted. If PARAMETER is ‘@’ or ‘*’, the pattern
2152 removal operation is applied to each positional parameter in turn,
2153 and the expansion is the resultant list. If PARAMETER is an array
2154 variable subscripted with ‘@’ or ‘*’, the pattern removal operation
2155 is applied to each member of the array in turn, and the expansion
2156 is the resultant list.
2157
2158‘${PARAMETER%WORD}’
2159‘${PARAMETER%%WORD}’
2160 The WORD is expanded to produce a pattern and matched against the
2161 expanded value of PARAMETER according to the rules described below
2162 (*note Pattern Matching::). If the pattern matches a trailing
2163 portion of the expanded value of PARAMETER, then the result of the
2164 expansion is the value of PARAMETER with the shortest matching
2165 pattern (the ‘%’ case) or the longest matching pattern (the ‘%%’
2166 case) deleted. If PARAMETER is ‘@’ or ‘*’, the pattern removal
2167 operation is applied to each positional parameter in turn, and the
2168 expansion is the resultant list. If PARAMETER is an array variable
2169 subscripted with ‘@’ or ‘*’, the pattern removal operation is
2170 applied to each member of the array in turn, and the expansion is
2171 the resultant list.
2172
2173‘${PARAMETER/PATTERN/STRING}’
2174‘${PARAMETER//PATTERN/STRING}’
2175‘${PARAMETER/#PATTERN/STRING}’
2176‘${PARAMETER/%PATTERN/STRING}’
2177 The PATTERN is expanded to produce a pattern and matched against
2178 the expanded value of PARAMETER as described below (*note Pattern
2179 Matching::). The longest match of PATTERN in the expanded value is
2180 replaced with STRING. STRING undergoes tilde expansion, parameter
2181 and variable expansion, arithmetic expansion, command and process
2182 substitution, and quote removal.
74091dd4
CR
2183
2184 In the first form above, only the first match is replaced. If
2185 there are two slashes separating PARAMETER and PATTERN (the second
2186 form above), all matches of PATTERN are replaced with STRING. If
b8c60bc9 2187 PATTERN is preceded by ‘#’ (the third form above), it must match at
74091dd4 2188 the beginning of the expanded value of PARAMETER. If PATTERN is
b8c60bc9
CR
2189 preceded by ‘%’ (the fourth form above), it must match at the end
2190 of the expanded value of PARAMETER.
74091dd4 2191
b8c60bc9
CR
2192 If the expansion of STRING is null, matches of PATTERN are deleted
2193 and the ‘/’ following PATTERN may be omitted.
2194
2195 If the ‘patsub_replacement’ shell option is enabled using ‘shopt’
2196 (*note The Shopt Builtin::), any unquoted instances of ‘&’ in
2197 STRING are replaced with the matching portion of PATTERN. This is
2198 intended to duplicate a common ‘sed’ idiom.
74091dd4
CR
2199
2200 Quoting any part of STRING inhibits replacement in the expansion of
2201 the quoted portion, including replacement strings stored in shell
b8c60bc9
CR
2202 variables. Backslash escapes ‘&’ in STRING; the backslash is
2203 removed in order to permit a literal ‘&’ in the replacement string.
74091dd4
CR
2204 Users should take care if STRING is double-quoted to avoid unwanted
2205 interactions between the backslash and double-quoting, since
2206 backslash has special meaning within double quotes. Pattern
b8c60bc9 2207 substitution performs the check for unquoted ‘&’ after expanding
74091dd4 2208 STRING, so users should ensure to properly quote any occurrences of
b8c60bc9
CR
2209 ‘&’ they want to be taken literally in the replacement and ensure
2210 any instances of ‘&’ they want to be replaced are unquoted.
74091dd4
CR
2211
2212 For instance,
2213
2214 var=abcdef
2215 rep='& '
2216 echo ${var/abc/& }
2217 echo "${var/abc/& }"
2218 echo ${var/abc/$rep}
2219 echo "${var/abc/$rep}"
2220
2221 will display four lines of "abc def", while
2222
2223 var=abcdef
2224 rep='& '
2225 echo ${var/abc/\& }
2226 echo "${var/abc/\& }"
2227 echo ${var/abc/"& "}
2228 echo ${var/abc/"$rep"}
2229
2230 will display four lines of "& def". Like the pattern removal
2231 operators, double quotes surrounding the replacement string quote
2232 the expanded characters, while double quotes enclosing the entire
2233 parameter substitution do not, since the expansion is performed in
2234 a context that doesn't take any enclosing double quotes into
2235 account.
2236
b8c60bc9
CR
2237 Since backslash can escape ‘&’, it can also escape a backslash in
2238 the replacement string. This means that ‘\\’ will insert a literal
2239 backslash into the replacement, so these two ‘echo’ commands
74091dd4
CR
2240
2241 var=abcdef
2242 rep='\\&xyz'
2243 echo ${var/abc/\\&xyz}
2244 echo ${var/abc/$rep}
2245
b8c60bc9 2246 will both output ‘\abcxyzdef’.
74091dd4
CR
2247
2248 It should rarely be necessary to enclose only STRING in double
2249 quotes.
2250
b8c60bc9 2251 If the ‘nocasematch’ shell option (see the description of ‘shopt’
74091dd4 2252 in *note The Shopt Builtin::) is enabled, the match is performed
b8c60bc9
CR
2253 without regard to the case of alphabetic characters.
2254
2255 If PARAMETER is ‘@’ or ‘*’, the substitution operation is applied
2256 to each positional parameter in turn, and the expansion is the
2257 resultant list. If PARAMETER is an array variable subscripted with
2258 ‘@’ or ‘*’, the substitution operation is applied to each member of
2259 the array in turn, and the expansion is the resultant list.
2260
2261‘${PARAMETER^PATTERN}’
2262‘${PARAMETER^^PATTERN}’
2263‘${PARAMETER,PATTERN}’
2264‘${PARAMETER,,PATTERN}’
3185942a 2265 This expansion modifies the case of alphabetic characters in
b8c60bc9
CR
2266 PARAMETER. First, the PATTERN is expanded to produce a pattern as
2267 described below in *note Pattern Matching::.
2268
2269 ‘Bash’ then examines characters in the expanded value of PARAMETER
2270 against PATTERN as described below. If a character matches the
ac50fbac 2271 pattern, its case is converted. The pattern should not attempt to
74091dd4
CR
2272 match more than one character.
2273
b8c60bc9
CR
2274 Using ‘^’ converts lowercase letters matching PATTERN to uppercase;
2275 ‘,’ converts matching uppercase letters to lowercase. The ‘^’ and
2276 ‘,’ variants examine the first character in the expanded value and
2277 convert its case if it matches PATTERN; the ‘^^’ and ‘,,’ variants
2278 examine all characters in the expanded value and convert each one
2279 that matches PATTERN. If PATTERN is omitted, it is treated like a
2280 ‘?’, which matches every character.
74091dd4 2281
b8c60bc9 2282 If PARAMETER is ‘@’ or ‘*’, the case modification operation is
74091dd4
CR
2283 applied to each positional parameter in turn, and the expansion is
2284 the resultant list. If PARAMETER is an array variable subscripted
b8c60bc9 2285 with ‘@’ or ‘*’, the case modification operation is applied to each
74091dd4
CR
2286 member of the array in turn, and the expansion is the resultant
2287 list.
b80f6443 2288
b8c60bc9 2289‘${PARAMETER@OPERATOR}’
a0c0a00f
CR
2290 The expansion is either a transformation of the value of PARAMETER
2291 or information about PARAMETER itself, depending on the value of
2292 OPERATOR. Each OPERATOR is a single letter:
2293
b8c60bc9 2294 ‘U’
8868edaf
CR
2295 The expansion is a string that is the value of PARAMETER with
2296 lowercase alphabetic characters converted to uppercase.
b8c60bc9 2297 ‘u’
8868edaf
CR
2298 The expansion is a string that is the value of PARAMETER with
2299 the first character converted to uppercase, if it is
2300 alphabetic.
b8c60bc9 2301 ‘L’
8868edaf
CR
2302 The expansion is a string that is the value of PARAMETER with
2303 uppercase alphabetic characters converted to lowercase.
b8c60bc9 2304 ‘Q’
a0c0a00f
CR
2305 The expansion is a string that is the value of PARAMETER
2306 quoted in a format that can be reused as input.
b8c60bc9 2307 ‘E’
a0c0a00f 2308 The expansion is a string that is the value of PARAMETER with
b8c60bc9 2309 backslash escape sequences expanded as with the ‘$'...'’
d233b485 2310 quoting mechanism.
b8c60bc9 2311 ‘P’
a0c0a00f
CR
2312 The expansion is a string that is the result of expanding the
2313 value of PARAMETER as if it were a prompt string (*note
2314 Controlling the Prompt::).
b8c60bc9 2315 ‘A’
a0c0a00f 2316 The expansion is a string in the form of an assignment
b8c60bc9
CR
2317 statement or ‘declare’ command that, if evaluated, recreates
2318 PARAMETER with its attributes and value.
2319 ‘K’
8868edaf
CR
2320 Produces a possibly-quoted version of the value of PARAMETER,
2321 except that it prints the values of indexed and associative
2322 arrays as a sequence of quoted key-value pairs (*note
b8c60bc9
CR
2323 Arrays::). The keys and values are quoted in a format that
2324 can be reused as input.
2325 ‘a’
a0c0a00f
CR
2326 The expansion is a string consisting of flag values
2327 representing PARAMETER's attributes.
b8c60bc9
CR
2328 ‘k’
2329 Like the ‘K’ transformation, but expands the keys and values
74091dd4
CR
2330 of indexed and associative arrays to separate words after word
2331 splitting.
a0c0a00f 2332
b8c60bc9 2333 If PARAMETER is ‘@’ or ‘*’, the operation is applied to each
a0c0a00f 2334 positional parameter in turn, and the expansion is the resultant
b8c60bc9
CR
2335 list. If PARAMETER is an array variable subscripted with ‘@’ or
2336 ‘*’, the operation is applied to each member of the array in turn,
a0c0a00f
CR
2337 and the expansion is the resultant list.
2338
2339 The result of the expansion is subject to word splitting and
8868edaf 2340 filename expansion as described below.
a0c0a00f 2341
ccc6cda3 2342\1f
cce855bc 2343File: bashref.info, Node: Command Substitution, Next: Arithmetic Expansion, Prev: Shell Parameter Expansion, Up: Shell Expansions
ccc6cda3 2344
b80f6443
JA
23453.5.4 Command Substitution
2346--------------------------
ccc6cda3 2347
b80f6443 2348Command substitution allows the output of a command to replace the
b8c60bc9
CR
2349command itself. The standard form of command substitution occurs when a
2350command is enclosed as follows:
ccc6cda3 2351 $(COMMAND)
b8c60bc9
CR
2352or (deprecated)
2353 `COMMAND`.
ccc6cda3 2354
b8c60bc9 2355Bash performs command substitution by executing COMMAND in a subshell
a0c0a00f
CR
2356environment and replacing the command substitution with the standard
2357output of the command, with any trailing newlines deleted. Embedded
2358newlines are not deleted, but they may be removed during word splitting.
b8c60bc9
CR
2359The command substitution ‘$(cat FILE)’ can be replaced by the equivalent
2360but faster ‘$(< FILE)’.
ccc6cda3 2361
b8c60bc9
CR
2362 With the old-style backquote form of substitution, backslash retains
2363its literal meaning except when followed by ‘$’, ‘`’, or ‘\’. The first
2364backquote not preceded by a backslash terminates the command
2365substitution. When using the ‘$(COMMAND)’ form, all characters between
cce855bc 2366the parentheses make up the command; none are treated specially.
ccc6cda3 2367
b8c60bc9
CR
2368 There is an alternate form of command substitution:
2369
2370 ${C COMMAND; }
2371
2372which executes COMMAND in the current execution environment and captures
2373its output, again with trailing newlines removed.
2374
2375 The character C following the open brace must be a space, tab,
2376newline, or ‘|’, and the close brace must be in a position where a
2377reserved word may appear (i.e., preceded by a command terminator such as
2378semicolon). Bash allows the close brace to be joined to the remaining
2379characters in the word without being followed by a shell metacharacter
2380as a reserved word would usually require.
2381
2382 Any side effects of COMMAND take effect immediately in the current
2383execution environment and persist in the current environment after the
2384command completes (e.g., the ‘exit’ builtin exits the shell).
2385
2386 This type of command substitution superficially resembles executing
2387an unnamed shell function: local variables are created as when a shell
2388function is executing, and the ‘return’ builtin forces COMMAND to
2389complete; however, the rest of the execution environment, including the
2390positional parameters, is shared with the caller.
2391
2392 If the first character following the open brace is a ‘|’, the
2393construct expands to the value of the ‘REPLY’ shell variable after
2394COMMAND executes, without removing any trailing newlines, and the
2395standard output of COMMAND remains the same as in the calling shell.
2396Bash creates ‘REPLY’ as an initially-unset local variable when COMMAND
2397executes, and restores ‘REPLY’ to the value it had before the command
2398substitution after COMMAND completes, as with any local variable.
2399
2400 For example, this construct expands to ‘12345’, and leaves the shell
2401variable ‘X’ unchanged in the current execution environment:
2402
2403
2404 ${ local X=12345 ; echo $X; }
2405
2406(not declaring ‘X’ as local would modify its value in the current
2407environment, as with normal shell function execution), while this
2408construct does not require any output to expand to ‘12345’:
2409
2410 ${| REPLY=12345; }
2411
2412and restores ‘REPLY’ to the value it had before the command
2413substitution.
2414
cce855bc
JA
2415 Command substitutions may be nested. To nest when using the
2416backquoted form, escape the inner backquotes with backslashes.
ccc6cda3 2417
b8c60bc9
CR
2418 If the substitution appears within double quotes, Bash does not
2419perform word splitting and filename expansion on the results.
ccc6cda3
JA
2420
2421\1f
cce855bc
JA
2422File: bashref.info, Node: Arithmetic Expansion, Next: Process Substitution, Prev: Command Substitution, Up: Shell Expansions
2423
b80f6443
JA
24243.5.5 Arithmetic Expansion
2425--------------------------
cce855bc 2426
b8c60bc9
CR
2427Arithmetic expansion evaluates an arithmetic expression and substitutes
2428the result. The format for arithmetic expansion is:
cce855bc
JA
2429
2430 $(( EXPRESSION ))
2431
74091dd4 2432 The EXPRESSION undergoes the same expansions as if it were within
b8c60bc9
CR
2433double quotes, but unescaped double quote characters in EXPRESSION are
2434not treated specially and are removed. All tokens in the expression
2435undergo parameter and variable expansion, command substitution, and
2436quote removal. The result is treated as the arithmetic expression to be
2437evaluated. Since the way Bash handles double quotes can potentially
2438result in empty strings, arithmetic expansion treats those as
2439expressions that evaluate to 0. Arithmetic expansions may be nested.
cce855bc
JA
2440
2441 The evaluation is performed according to the rules listed below
a0c0a00f 2442(*note Shell Arithmetic::). If the expression is invalid, Bash prints a
b8c60bc9
CR
2443message indicating failure to the standard error, does not perform the
2444substitution, and does not execute the command associated with the
2445expansion.
cce855bc
JA
2446
2447\1f
2448File: bashref.info, Node: Process Substitution, Next: Word Splitting, Prev: Arithmetic Expansion, Up: Shell Expansions
ccc6cda3 2449
b80f6443
JA
24503.5.6 Process Substitution
2451--------------------------
ccc6cda3 2452
a0c0a00f
CR
2453Process substitution allows a process's input or output to be referred
2454to using a filename. It takes the form of
ccc6cda3 2455 <(LIST)
a0c0a00f 2456or
ccc6cda3 2457 >(LIST)
a0c0a00f
CR
2458The process LIST is run asynchronously, and its input or output appears
2459as a filename. This filename is passed as an argument to the current
b8c60bc9
CR
2460command as the result of the expansion.
2461
2462 If the ‘>(LIST)’ form is used, writing to the file provides input for
2463LIST. If the ‘<(LIST)’ form is used, reading the file obtains the
2464output of LIST. Note that no space may appear between the ‘<’ or ‘>’
a0c0a00f 2465and the left parenthesis, otherwise the construct would be interpreted
b8c60bc9
CR
2466as a redirection.
2467
2468 Process substitution is supported on systems that support named pipes
2469(FIFOs) or the ‘/dev/fd’ method of naming open files.
ccc6cda3 2470
cce855bc
JA
2471 When available, process substitution is performed simultaneously with
2472parameter and variable expansion, command substitution, and arithmetic
2473expansion.
ccc6cda3
JA
2474
2475\1f
2476File: bashref.info, Node: Word Splitting, Next: Filename Expansion, Prev: Process Substitution, Up: Shell Expansions
2477
b80f6443
JA
24783.5.7 Word Splitting
2479--------------------
ccc6cda3 2480
b80f6443 2481The shell scans the results of parameter expansion, command
ccc6cda3 2482substitution, and arithmetic expansion that did not occur within double
b8c60bc9
CR
2483quotes for word splitting. Words that were not expanded are not split.
2484
2485 The shell treats each character of ‘$IFS’ as a delimiter, and splits
2486the results of the other expansions into fields using these characters
2487as field terminators.
2488
2489 An “IFS whitespace” character is whitespace as defined above (*note
2490Definitions::) that appears in the value of ‘IFS’. Space, tab, and
2491newline are always considered IFS whitespace, even if they don't appear
2492in the locale's ‘space’ category.
2493
2494 If ‘IFS’ is unset, word splitting behaves as if its value were
2495‘<space><tab><newline>’, and treats these characters as IFS whitespace.
2496If the value of ‘IFS’ is null, no word splitting occurs, but implicit
2497null arguments (see below) are still removed.
2498
2499 Word splitting begins by removing sequences of IFS whitespace
2500characters from the beginning and end of the results of the previous
2501expansions, then splits the remaining words.
2502
2503 If the value of ‘IFS’ consists solely of IFS whitespace, any sequence
2504of IFS whitespace characters delimits a field, so a field consists of
2505characters that are not unquoted IFS whitespace, and null fields result
2506only from quoting.
2507
2508 If ‘IFS’ contains a non-whitespace character, then any character in
2509the value of ‘IFS’ that is not IFS whitespace, along with any adjacent
2510IFS whitespace characters, delimits a field. This means that adjacent
2511non-IFS-whitespace delimiters produce a null field. A sequence of IFS
2512whitespace characters also delimits a field.
2513
2514 Explicit null arguments (‘""’ or ‘''’) are retained and passed to
a0c0a00f 2515commands as empty strings. Unquoted implicit null arguments, resulting
b8c60bc9
CR
2516from the expansion of parameters that have no values, are removed.
2517Expanding a parameter with no value within double quotes produces a null
2518field, which is retained and passed to a command as an empty string.
ccc6cda3 2519
b8c60bc9
CR
2520 When a quoted null argument appears as part of a word whose expansion
2521is non-null, word splitting removes the null argument portion, leaving
2522the non-null expansion. That is, the word ‘-d''’ becomes ‘-d’ after
2523word splitting and null argument removal.
ccc6cda3
JA
2524
2525\1f
2526File: bashref.info, Node: Filename Expansion, Next: Quote Removal, Prev: Word Splitting, Up: Shell Expansions
2527
b80f6443
JA
25283.5.8 Filename Expansion
2529------------------------
ccc6cda3 2530
cce855bc
JA
2531* Menu:
2532
2533* Pattern Matching:: How the shell matches patterns.
2534
b8c60bc9
CR
2535After word splitting, unless the ‘-f’ option has been set (*note The Set
2536Builtin::), Bash scans each word for the characters ‘*’, ‘?’, and ‘[’.
8868edaf 2537If one of these characters appears, and is not quoted, then the word is
b8c60bc9
CR
2538regarded as a PATTERN, and replaced with a sorted list of filenames
2539matching the pattern (*note Pattern Matching::), subject to the value of
2540the ‘GLOBSORT’ shell variable (*note Bash Variables::).
2541
2542 If no matching filenames are found, and the shell option ‘nullglob’
2543is disabled, the word is left unchanged. If the ‘nullglob’ option is
2544set, and no matches are found, the word is removed. If the ‘failglob’
2545shell option is set, and no matches are found, Bash prints an error
2546message and does not execute the command. If the shell option
2547‘nocaseglob’ is enabled, the match is performed without regard to the
2548case of alphabetic characters.
2549
2550 When a pattern is used for filename expansion, the character ‘.’ at
a0c0a00f 2551the start of a filename or immediately following a slash must be matched
b8c60bc9
CR
2552explicitly, unless the shell option ‘dotglob’ is set. In order to match
2553the filenames ‘.’ and ‘..’, the pattern must begin with ‘.’ (for
2554example, ‘.?’), even if ‘dotglob’ is set. If the ‘globskipdots’ shell
2555option is enabled, the filenames ‘.’ and ‘..’ never match, even if the
2556pattern begins with a ‘.’. When not matching filenames, the ‘.’
74091dd4 2557character is not treated specially.
d233b485
CR
2558
2559 When matching a filename, the slash character must always be matched
2560explicitly by a slash in the pattern, but in other matching contexts it
2561can be matched by a special pattern character as described below (*note
2562Pattern Matching::).
a0c0a00f 2563
b8c60bc9
CR
2564 See the description of ‘shopt’ in *note The Shopt Builtin::, for a
2565description of the ‘nocaseglob’, ‘nullglob’, ‘globskipdots’, ‘failglob’,
2566and ‘dotglob’ options.
2567
2568 The ‘GLOBIGNORE’ shell variable may be used to restrict the set of
2569file names matching a pattern. If ‘GLOBIGNORE’ is set, each matching
2570file name that also matches one of the patterns in ‘GLOBIGNORE’ is
2571removed from the list of matches. If the ‘nocaseglob’ option is set,
2572the matching against the patterns in ‘GLOBIGNORE’ is performed without
2573regard to case. The filenames ‘.’ and ‘..’ are always ignored when
2574‘GLOBIGNORE’ is set and not null. However, setting ‘GLOBIGNORE’ to a
2575non-null value has the effect of enabling the ‘dotglob’ shell option, so
2576all other filenames beginning with a ‘.’ match. To get the old behavior
2577of ignoring filenames beginning with a ‘.’, make ‘.*’ one of the
2578patterns in ‘GLOBIGNORE’. The ‘dotglob’ option is disabled when
2579‘GLOBIGNORE’ is unset. The ‘GLOBIGNORE’ pattern matching honors the
2580setting of the ‘extglob’ shell option.
2581
2582 The value of the ‘GLOBSORT’ shell variable controls how the results
2583of pathname expansion are sorted, as described below (*note Bash
2584Variables::).
ccc6cda3 2585
cce855bc
JA
2586\1f
2587File: bashref.info, Node: Pattern Matching, Up: Filename Expansion
2588
b80f6443
JA
25893.5.8.1 Pattern Matching
2590........................
cce855bc 2591
b80f6443
JA
2592Any character that appears in a pattern, other than the special pattern
2593characters described below, matches itself. The NUL character may not
2594occur in a pattern. A backslash escapes the following character; the
2595escaping backslash is discarded when matching. The special pattern
2596characters must be quoted if they are to be matched literally.
cce855bc 2597
ccc6cda3 2598 The special pattern characters have the following meanings:
b8c60bc9
CR
2599‘*’
2600 Matches any string, including the null string. When the ‘globstar’
2601 shell option is enabled, and ‘*’ is used in a filename expansion
2602 context, two adjacent ‘*’s used as a single pattern match all files
2603 and zero or more directories and subdirectories. If followed by a
2604 ‘/’, two adjacent ‘*’s match only directories and subdirectories.
2605‘?’
ccc6cda3 2606 Matches any single character.
b8c60bc9
CR
2607‘[...]’
2608 Matches any one of the characters enclosed between the brackets.
2609 This is known as a “bracket expression” and matches a single
2610 character. A pair of characters separated by a hyphen denotes a
2611 “range expression”; any character that falls between those two
2612 characters, inclusive, using the current locale's collating
2613 sequence and character set, matches. If the first character
2614 following the ‘[’ is a ‘!’ or a ‘^’ then any character not within
2615 the range matches. To match a ‘−’, include it as the first or last
2616 character in the set. To match a ‘]’, include it as the first
2617 character in the set.
2618
2619 The sorting order of characters in range expressions, and the
74091dd4 2620 characters included in the range, are determined by the current
b8c60bc9 2621 locale and the values of the ‘LC_COLLATE’ and ‘LC_ALL’ shell
74091dd4 2622 variables, if set.
28ef6c31 2623
b8c60bc9
CR
2624 For example, in the default C locale, ‘[a-dx-z]’ is equivalent to
2625 ‘[abcdxyz]’. Many locales sort characters in dictionary order, and
2626 in these locales ‘[a-dx-z]’ is typically not equivalent to
2627 ‘[abcdxyz]’; it might be equivalent to ‘[aBbCcDdxYyZz]’, for
28ef6c31
JA
2628 example. To obtain the traditional interpretation of ranges in
2629 bracket expressions, you can force the use of the C locale by
b8c60bc9
CR
2630 setting the ‘LC_COLLATE’ or ‘LC_ALL’ environment variable to the
2631 value ‘C’, or enable the ‘globasciiranges’ shell option.
ccc6cda3 2632
b8c60bc9
CR
2633 Within a bracket expression, “character classes” can be specified
2634 using the syntax ‘[:’CLASS‘:]’, where CLASS is one of the following
2635 classes defined in the POSIX standard:
cce855bc 2636 alnum alpha ascii blank cntrl digit graph lower
7117c2d2 2637 print punct space upper word xdigit
cce855bc 2638 A character class matches any character belonging to that class.
b8c60bc9
CR
2639 The ‘word’ character class matches letters, digits, and the
2640 character ‘_’.
2641
2642 For instance, the following pattern will match any character
2643 belonging to the ‘space’ character class in the current locale,
2644 then any upper case letter or ‘!’, a dot, and finally any lower
2645 case letter or a hyphen.
cce855bc 2646
b8c60bc9 2647 [[:space:]][[:upper:]!].[-[:lower:]]
cce855bc 2648
b8c60bc9
CR
2649 Within a bracket expression, an “equivalence class” can be
2650 specified using the syntax ‘[=’C‘=]’, which matches all characters
2651 with the same collation weight (as defined by the current locale)
2652 as the character C.
cce855bc 2653
b8c60bc9
CR
2654 Within a bracket expression, the syntax ‘[.’SYMBOL‘.]’ matches the
2655 collating symbol SYMBOL.
2656
2657 If the ‘extglob’ shell option is enabled using the ‘shopt’ builtin,
74091dd4
CR
2658the shell recognizes several extended pattern matching operators. In
2659the following description, a PATTERN-LIST is a list of one or more
b8c60bc9 2660patterns separated by a ‘|’. When matching filenames, the ‘dotglob’
74091dd4
CR
2661shell option determines the set of filenames that are tested, as
2662described above. Composite patterns may be formed using one or more of
2663the following sub-patterns:
cce855bc 2664
b8c60bc9 2665‘?(PATTERN-LIST)’
cce855bc
JA
2666 Matches zero or one occurrence of the given patterns.
2667
b8c60bc9 2668‘*(PATTERN-LIST)’
cce855bc
JA
2669 Matches zero or more occurrences of the given patterns.
2670
b8c60bc9 2671‘+(PATTERN-LIST)’
cce855bc
JA
2672 Matches one or more occurrences of the given patterns.
2673
b8c60bc9 2674‘@(PATTERN-LIST)’
95732b49 2675 Matches one of the given patterns.
cce855bc 2676
b8c60bc9 2677‘!(PATTERN-LIST)’
cce855bc
JA
2678 Matches anything except one of the given patterns.
2679
b8c60bc9 2680 The ‘extglob’ option changes the behavior of the parser, since the
74091dd4
CR
2681parentheses are normally treated as operators with syntactic meaning.
2682To ensure that extended matching patterns are parsed correctly, make
b8c60bc9 2683sure that ‘extglob’ is enabled before parsing constructs containing the
74091dd4
CR
2684patterns, including shell functions and command substitutions.
2685
b8c60bc9
CR
2686 When matching filenames, the ‘dotglob’ shell option determines the
2687set of filenames that are tested: when ‘dotglob’ is enabled, the set of
2688filenames includes all files beginning with ‘.’, but the filenames ‘.’
2689and ‘..’ must be matched by a pattern or sub-pattern that begins with a
74091dd4 2690dot; when it is disabled, the set does not include any filenames
b8c60bc9
CR
2691beginning with ‘.’ unless the pattern or sub-pattern begins with a ‘.’.
2692If the ‘globskipdots’ shell option is enabled, the filenames ‘.’ and
2693‘..’ never appear in the set. As above, ‘.’ only has a special meaning
2694when matching filenames.
74091dd4 2695
d233b485
CR
2696 Complicated extended pattern matching against long strings is slow,
2697especially when the patterns contain alternations and the strings
2698contain multiple matches. Using separate matches against shorter
2699strings, or using arrays of strings instead of a single long string, may
2700be faster.
2701
ccc6cda3
JA
2702\1f
2703File: bashref.info, Node: Quote Removal, Prev: Filename Expansion, Up: Shell Expansions
2704
b80f6443
JA
27053.5.9 Quote Removal
2706-------------------
ccc6cda3 2707
b80f6443 2708After the preceding expansions, all unquoted occurrences of the
b8c60bc9 2709characters ‘\’, ‘'’, and ‘"’ that did not result from one of the above
ccc6cda3
JA
2710expansions are removed.
2711
2712\1f
2713File: bashref.info, Node: Redirections, Next: Executing Commands, Prev: Shell Expansions, Up: Basic Shell Features
2714
b80f6443
JA
27153.6 Redirections
2716================
ccc6cda3 2717
b8c60bc9
CR
2718Before a command is executed, its input and output may be “redirected”
2719using a special notation interpreted by the shell. “Redirection” allows
ac50fbac
CR
2720commands' file handles to be duplicated, opened, closed, made to refer
2721to different files, and can change the files the command reads from and
b8c60bc9
CR
2722writes to. When used with the ‘exec’ builtin, redirections modify file
2723handles in the current shell execution environment. The following
2724redirection operators may precede or appear anywhere within a simple
2725command or may follow a command. Redirections are processed in the
2726order they appear, from left to right.
ccc6cda3 2727
a0c0a00f
CR
2728 Each redirection that may be preceded by a file descriptor number may
2729instead be preceded by a word of the form {VARNAME}. In this case, for
b8c60bc9
CR
2730each redirection operator except ‘>&-’ and ‘<&-’, the shell allocates a
2731file descriptor greater than or equal to 10 and assigns it to {VARNAME}.
2732If {VARNAME} precedes ‘>&-’ or ‘<&-’, the value of VARNAME defines the
2733file descriptor to close. If {VARNAME} is supplied, the redirection
2734persists beyond the scope of the command, which allows the shell
2735programmer to manage the file descriptor's lifetime manually without
2736using the ‘exec’ builtin. The ‘varredir_close’ shell option manages
2737this behavior (*note The Shopt Builtin::).
0001803f 2738
ccc6cda3 2739 In the following descriptions, if the file descriptor number is
b8c60bc9 2740omitted, and the first character of the redirection operator is ‘<’, the
a0c0a00f 2741redirection refers to the standard input (file descriptor 0). If the
b8c60bc9 2742first character of the redirection operator is ‘>’, the redirection
ccc6cda3
JA
2743refers to the standard output (file descriptor 1).
2744
b8c60bc9 2745 The WORD following the redirection operator in the following
cce855bc 2746descriptions, unless otherwise noted, is subjected to brace expansion,
b8c60bc9
CR
2747tilde expansion, parameter and variable expansion, command substitution,
2748arithmetic expansion, quote removal, filename expansion, and word
2749splitting. If it expands to more than one word, Bash reports an error.
ccc6cda3 2750
b8c60bc9 2751 The order of redirections is significant. For example, the command
ccc6cda3 2752 ls > DIRLIST 2>&1
a0c0a00f 2753directs both standard output (file descriptor 1) and standard error
bb70624e 2754(file descriptor 2) to the file DIRLIST, while the command
ccc6cda3 2755 ls 2>&1 > DIRLIST
a0c0a00f
CR
2756directs only the standard output to file DIRLIST, because the standard
2757error was made a copy of the standard output before the standard output
2758was redirected to DIRLIST.
ccc6cda3 2759
bb70624e 2760 Bash handles several filenames specially when they are used in
a0c0a00f 2761redirections, as described in the following table. If the operating
b8c60bc9
CR
2762system on which Bash is running provides these special files, Bash uses
2763them; otherwise it emulates them internally with the behavior described
2764below.
bb70624e 2765
b8c60bc9
CR
2766‘/dev/fd/FD’
2767 If FD is a valid integer, duplicate file descriptor FD.
bb70624e 2768
b8c60bc9 2769‘/dev/stdin’
bb70624e
JA
2770 File descriptor 0 is duplicated.
2771
b8c60bc9 2772‘/dev/stdout’
bb70624e
JA
2773 File descriptor 1 is duplicated.
2774
b8c60bc9 2775‘/dev/stderr’
bb70624e
JA
2776 File descriptor 2 is duplicated.
2777
b8c60bc9 2778‘/dev/tcp/HOST/PORT’
bb70624e 2779 If HOST is a valid hostname or Internet address, and PORT is an
ac50fbac
CR
2780 integer port number or service name, Bash attempts to open the
2781 corresponding TCP socket.
bb70624e 2782
b8c60bc9 2783‘/dev/udp/HOST/PORT’
bb70624e 2784 If HOST is a valid hostname or Internet address, and PORT is an
ac50fbac
CR
2785 integer port number or service name, Bash attempts to open the
2786 corresponding UDP socket.
b80f6443 2787
cce855bc
JA
2788 A failure to open or create a file causes the redirection to fail.
2789
95732b49
JA
2790 Redirections using file descriptors greater than 9 should be used
2791with care, as they may conflict with file descriptors the shell uses
2792internally.
2793
b80f6443
JA
27943.6.1 Redirecting Input
2795-----------------------
ccc6cda3 2796
b8c60bc9
CR
2797Redirecting input opens the file whose name results from the expansion
2798of WORD for reading on file descriptor ‘n’, or the standard input (file
2799descriptor 0) if ‘n’ is not specified.
ccc6cda3
JA
2800
2801 The general format for redirecting input is:
7117c2d2 2802 [N]<WORD
ccc6cda3 2803
b80f6443
JA
28043.6.2 Redirecting Output
2805------------------------
ccc6cda3 2806
b8c60bc9
CR
2807Redirecting output opens the file whose name results from the expansion
2808of WORD for writing on file descriptor N, or the standard output (file
2809descriptor 1) if N is not specified. If the file does not exist it is
2810created; if it does exist it is truncated to zero size.
ccc6cda3
JA
2811
2812 The general format for redirecting output is:
7117c2d2 2813 [N]>[|]WORD
ccc6cda3 2814
b8c60bc9
CR
2815 If the redirection operator is ‘>’, and the ‘noclobber’ option to the
2816‘set’ builtin command has been enabled, the redirection fails if the
2817file whose name results from the expansion of WORD exists and is a
2818regular file. If the redirection operator is ‘>|’, or the redirection
2819operator is ‘>’ and the ‘noclobber’ option to the ‘set’ builtin is not
2820enabled, Bash attempts the redirection even if the file named by WORD
2821exists.
ccc6cda3 2822
b80f6443
JA
28233.6.3 Appending Redirected Output
2824---------------------------------
ccc6cda3 2825
b8c60bc9
CR
2826Redirecting output in this fashion opens the file whose name results
2827from the expansion of WORD for appending on file descriptor N, or the
2828standard output (file descriptor 1) if N is not specified. If the file
2829does not exist it is created.
ccc6cda3
JA
2830
2831 The general format for appending output is:
7117c2d2 2832 [N]>>WORD
ccc6cda3 2833
b80f6443
JA
28343.6.4 Redirecting Standard Output and Standard Error
2835----------------------------------------------------
ccc6cda3 2836
b8c60bc9
CR
2837This construct redirects both the standard output (file descriptor 1)
2838and the standard error output (file descriptor 2) to the file whose name
2839is the expansion of WORD.
ccc6cda3
JA
2840
2841 There are two formats for redirecting standard output and standard
2842error:
2843 &>WORD
a0c0a00f 2844and
ccc6cda3 2845 >&WORD
a0c0a00f 2846Of the two forms, the first is preferred. This is semantically
ccc6cda3
JA
2847equivalent to
2848 >WORD 2>&1
b8c60bc9 2849 When using the second form, WORD may not expand to a number or ‘-’.
ac50fbac
CR
2850If it does, other redirection operators apply (see Duplicating File
2851Descriptors below) for compatibility reasons.
ccc6cda3 2852
3185942a
JA
28533.6.5 Appending Standard Output and Standard Error
2854--------------------------------------------------
2855
b8c60bc9
CR
2856This construct appends both the standard output (file descriptor 1) and
2857the standard error output (file descriptor 2) to the file whose name is
2858the expansion of WORD.
3185942a
JA
2859
2860 The format for appending standard output and standard error is:
2861 &>>WORD
a0c0a00f 2862This is semantically equivalent to
3185942a 2863 >>WORD 2>&1
ac50fbac 2864 (see Duplicating File Descriptors below).
3185942a
JA
2865
28663.6.6 Here Documents
b80f6443 2867--------------------
ccc6cda3 2868
b80f6443 2869This type of redirection instructs the shell to read input from the
b8c60bc9
CR
2870current source until it reads a line containing only DELIMITER (with no
2871trailing blanks). All of the lines read up to that point then become
2872the standard input (or file descriptor N if N is specified) for a
a0c0a00f 2873command.
ccc6cda3 2874
7117c2d2 2875 The format of here-documents is:
b8c60bc9 2876 [N]<<[−]WORD
ccc6cda3
JA
2877 HERE-DOCUMENT
2878 DELIMITER
2879
b8c60bc9
CR
2880 The shell does not perform parameter and variable expansion, command
2881substitution, arithmetic expansion, or filename expansion on WORD.
2882
2883 If any part of WORD is quoted, the DELIMITER is the result of quote
2884removal on WORD, and the lines in the here-document are not expanded.
2885If WORD is unquoted, DELIMITER is WORD itself, and the here-document
2886text is treated similarly to a double-quoted string: all lines of the
2887here-document are subjected to parameter expansion, command
2888substitution, and arithmetic expansion, the character sequence
2889‘\newline’ is treated literally, and ‘\’ must be used to quote the
2890characters ‘\’, ‘$’, and ‘`’; however, double quote characters have no
2891special meaning.
2892
2893 If the redirection operator is ‘<<-’, the shell strips leading tab
2894characters are stripped from input lines and the line containing
2895DELIMITER. This allows here-documents within shell scripts to be
2896indented in a natural fashion.
2897
2898 If the delimiter is not quoted, the ‘\<newline>’ sequence is treated
2899as a line continuation: the two lines are joined and the
2900backslash-newline is removed. This happens while reading the
2901here-document, before the check for the ending delimiter, so joined
2902lines can form the end delimiter.
ccc6cda3 2903
3185942a 29043.6.7 Here Strings
b80f6443 2905------------------
7117c2d2 2906
b80f6443 2907A variant of here documents, the format is:
a0c0a00f 2908 [N]<<< WORD
7117c2d2 2909
d233b485 2910 The WORD undergoes tilde expansion, parameter and variable expansion,
8868edaf 2911command substitution, arithmetic expansion, and quote removal. Filename
d233b485
CR
2912expansion and word splitting are not performed. The result is supplied
2913as a single string, with a newline appended, to the command on its
2914standard input (or file descriptor N if N is specified).
7117c2d2 2915
3185942a 29163.6.8 Duplicating File Descriptors
b80f6443 2917----------------------------------
ccc6cda3 2918
b80f6443 2919The redirection operator
7117c2d2 2920 [N]<&WORD
a0c0a00f 2921is used to duplicate input file descriptors. If WORD expands to one or
b8c60bc9
CR
2922more digits, file descriptor N is made to be a copy of that file
2923descriptor. It is a redirection error if the digits in WORD do not
2924specify a file descriptor open for input. If WORD evaluates to ‘-’,
2925file descriptor N is closed. If N is not specified, this uses the
2926standard input (file descriptor 0).
ccc6cda3
JA
2927
2928 The operator
7117c2d2 2929 [N]>&WORD
a0c0a00f 2930is used similarly to duplicate output file descriptors. If N is not
b8c60bc9
CR
2931specified, this uses the standard output (file descriptor 1). It is a
2932redirection error if the digits in WORD do not specify a file descriptor
2933open for output. If WORD evaluates to ‘-’, file descriptor N is closed.
2934As a special case, if N is omitted, and WORD does not expand to one or
2935more digits or ‘-’, this redirects the standard output and standard
2936error as described previously.
7117c2d2 2937
3185942a 29383.6.9 Moving File Descriptors
b80f6443 2939-----------------------------
7117c2d2 2940
b80f6443 2941The redirection operator
7117c2d2 2942 [N]<&DIGIT-
a0c0a00f
CR
2943moves the file descriptor DIGIT to file descriptor N, or the standard
2944input (file descriptor 0) if N is not specified. DIGIT is closed after
2945being duplicated to N.
7117c2d2
JA
2946
2947 Similarly, the redirection operator
2948 [N]>&DIGIT-
a0c0a00f
CR
2949moves the file descriptor DIGIT to file descriptor N, or the standard
2950output (file descriptor 1) if N is not specified.
7117c2d2 2951
3185942a
JA
29523.6.10 Opening File Descriptors for Reading and Writing
2953-------------------------------------------------------
ccc6cda3 2954
b80f6443 2955The redirection operator
7117c2d2 2956 [N]<>WORD
b8c60bc9
CR
2957opens the file whose name is the expansion of WORD for both reading and
2958writing on file descriptor N, or on file descriptor 0 if N is not
2959specified. If the file does not exist, it is created.
ccc6cda3
JA
2960
2961\1f
2962File: bashref.info, Node: Executing Commands, Next: Shell Scripts, Prev: Redirections, Up: Basic Shell Features
2963
b80f6443
JA
29643.7 Executing Commands
2965======================
ccc6cda3
JA
2966
2967* Menu:
2968
cce855bc
JA
2969* Simple Command Expansion:: How Bash expands simple commands before
2970 executing them.
ccc6cda3 2971* Command Search and Execution:: How Bash finds commands and runs them.
cce855bc
JA
2972* Command Execution Environment:: The environment in which Bash
2973 executes commands that are not
2974 shell builtins.
ccc6cda3 2975* Environment:: The environment given to a command.
ccc6cda3
JA
2976* Exit Status:: The status returned by commands and how Bash
2977 interprets it.
ccc6cda3
JA
2978* Signals:: What happens when Bash or a command it runs
2979 receives a signal.
2980
2981\1f
cce855bc
JA
2982File: bashref.info, Node: Simple Command Expansion, Next: Command Search and Execution, Up: Executing Commands
2983
b80f6443
JA
29843.7.1 Simple Command Expansion
2985------------------------------
cce855bc 2986
b8c60bc9 2987When the shell executes a simple command, it performs the following
8868edaf
CR
2988expansions, assignments, and redirections, from left to right, in the
2989following order.
cce855bc
JA
2990
2991 1. The words that the parser has marked as variable assignments (those
2992 preceding the command name) and redirections are saved for later
2993 processing.
2994
2995 2. The words that are not variable assignments or redirections are
28ef6c31 2996 expanded (*note Shell Expansions::). If any words remain after
cce855bc
JA
2997 expansion, the first word is taken to be the name of the command
2998 and the remaining words are the arguments.
2999
3000 3. Redirections are performed as described above (*note
28ef6c31 3001 Redirections::).
cce855bc 3002
b8c60bc9 3003 4. The text after the ‘=’ in each variable assignment undergoes tilde
cce855bc
JA
3004 expansion, parameter expansion, command substitution, arithmetic
3005 expansion, and quote removal before being assigned to the variable.
3006
3007 If no command name results, the variable assignments affect the
74091dd4
CR
3008current shell environment. In the case of such a command (one that
3009consists only of assignment statements and redirections), assignment
3010statements are performed before redirections. Otherwise, the variables
3011are added to the environment of the executed command and do not affect
3012the current shell environment. If any of the assignments attempts to
3013assign a value to a readonly variable, an error occurs, and the command
3014exits with a non-zero status.
cce855bc
JA
3015
3016 If no command name results, redirections are performed, but do not
3017affect the current shell environment. A redirection error causes the
3018command to exit with a non-zero status.
3019
3020 If there is a command name left after expansion, execution proceeds
3021as described below. Otherwise, the command exits. If one of the
3022expansions contained a command substitution, the exit status of the
3023command is the exit status of the last command substitution performed.
b8c60bc9
CR
3024If there were no command substitutions, the command exits with a zero
3025status.
cce855bc
JA
3026
3027\1f
3028File: bashref.info, Node: Command Search and Execution, Next: Command Execution Environment, Prev: Simple Command Expansion, Up: Executing Commands
ccc6cda3 3029
b80f6443
JA
30303.7.2 Command Search and Execution
3031----------------------------------
ccc6cda3 3032
b80f6443 3033After a command has been split into words, if it results in a simple
b8c60bc9
CR
3034command and an optional list of arguments, the shell performs the
3035following actions.
ccc6cda3
JA
3036
3037 1. If the command name contains no slashes, the shell attempts to
3038 locate it. If there exists a shell function by that name, that
3185942a 3039 function is invoked as described in *note Shell Functions::.
ccc6cda3 3040
a0c0a00f
CR
3041 2. If the name does not match a function, the shell searches for it in
3042 the list of shell builtins. If a match is found, that builtin is
3043 invoked.
3044
3045 3. If the name is neither a shell function nor a builtin, and contains
b8c60bc9 3046 no slashes, Bash searches each element of ‘$PATH’ for a directory
a0c0a00f
CR
3047 containing an executable file by that name. Bash uses a hash table
3048 to remember the full pathnames of executable files to avoid
b8c60bc9
CR
3049 multiple ‘PATH’ searches (see the description of ‘hash’ in *note
3050 Bourne Shell Builtins::). Bash performs a full search of the
3051 directories in ‘$PATH’ only if the command is not found in the hash
a0c0a00f 3052 table. If the search is unsuccessful, the shell searches for a
b8c60bc9 3053 defined shell function named ‘command_not_found_handle’. If that
d233b485
CR
3054 function exists, it is invoked in a separate execution environment
3055 with the original command and the original command's arguments as
3056 its arguments, and the function's exit status becomes the exit
3057 status of that subshell. If that function is not defined, the
3058 shell prints an error message and returns an exit status of 127.
a0c0a00f
CR
3059
3060 4. If the search is successful, or if the command name contains one or
3061 more slashes, the shell executes the named program in a separate
3062 execution environment. Argument 0 is set to the name given, and
3063 the remaining arguments to the command are set to the arguments
3064 supplied, if any.
ccc6cda3
JA
3065
3066 5. If this execution fails because the file is not in executable
cce855bc 3067 format, and the file is not a directory, it is assumed to be a
b8c60bc9
CR
3068 “shell script”, a file containing shell commands, and the shell
3069 executes it as described in *note Shell Scripts::.
cce855bc
JA
3070
3071 6. If the command was not begun asynchronously, the shell waits for
3072 the command to complete and collects its exit status.
3073
cce855bc
JA
3074\1f
3075File: bashref.info, Node: Command Execution Environment, Next: Environment, Prev: Command Search and Execution, Up: Executing Commands
3076
b80f6443
JA
30773.7.3 Command Execution Environment
3078-----------------------------------
cce855bc 3079
b8c60bc9 3080The shell has an “execution environment”, which consists of the
74091dd4 3081following:
cce855bc 3082
b8c60bc9
CR
3083 • Open files inherited by the shell at invocation, as modified by
3084 redirections supplied to the ‘exec’ builtin.
cce855bc 3085
b8c60bc9
CR
3086 • The current working directory as set by ‘cd’, ‘pushd’, or ‘popd’,
3087 or inherited by the shell at invocation.
cce855bc 3088
b8c60bc9
CR
3089 • The file creation mode mask as set by ‘umask’ or inherited from the
3090 shell's parent.
cce855bc 3091
b8c60bc9 3092 • Current traps set by ‘trap’.
cce855bc 3093
b8c60bc9
CR
3094 • Shell parameters that are set by variable assignment or with ‘set’
3095 or inherited from the shell's parent in the environment.
cce855bc 3096
b8c60bc9
CR
3097 • Shell functions defined during execution or inherited from the
3098 shell's parent in the environment.
cce855bc 3099
b8c60bc9
CR
3100 • Options enabled at invocation (either by default or with
3101 command-line arguments) or by ‘set’.
cce855bc 3102
b8c60bc9 3103 • Options enabled by ‘shopt’ (*note The Shopt Builtin::).
cce855bc 3104
b8c60bc9 3105 • Shell aliases defined with ‘alias’ (*note Aliases::).
cce855bc 3106
b8c60bc9
CR
3107 • Various process IDs, including those of background jobs (*note
3108 Lists::), the value of ‘$$’, and the value of ‘$PPID’.
28ef6c31 3109
a0c0a00f
CR
3110 When a simple command other than a builtin or shell function is to be
3111executed, it is invoked in a separate execution environment that
cce855bc
JA
3112consists of the following. Unless otherwise noted, the values are
3113inherited from the shell.
3114
b8c60bc9
CR
3115 • The shell's open files, plus any modifications and additions
3116 specified by redirections to the command.
cce855bc 3117
b8c60bc9 3118 • The current working directory.
cce855bc 3119
b8c60bc9 3120 • The file creation mode mask.
cce855bc 3121
b8c60bc9 3122 • Shell variables and functions marked for export, along with
b80f6443 3123 variables exported for the command, passed in the environment
b8c60bc9 3124 (*note Environment::).
cce855bc 3125
b8c60bc9
CR
3126 • Traps caught by the shell are reset to the values inherited from
3127 the shell's parent, and traps ignored by the shell are ignored.
cce855bc
JA
3128
3129 A command invoked in this separate environment cannot affect the
3130shell's execution environment.
3131
b8c60bc9 3132 A “subshell” is a copy of the shell process.
74091dd4 3133
b80f6443
JA
3134 Command substitution, commands grouped with parentheses, and
3135asynchronous commands are invoked in a subshell environment that is a
3136duplicate of the shell environment, except that traps caught by the
3137shell are reset to the values that the shell inherited from its parent
b8c60bc9
CR
3138at invocation. Builtin commands that are invoked as part of a pipeline,
3139except possibly in the last element depending on the value of the
3140‘lastpipe’ shell option (*note The Shopt Builtin::), are also executed
3141in a subshell environment. Changes made to the subshell environment
3142cannot affect the shell's execution environment.
3143
3144 When the shell is in POSIX mode, subshells spawned to execute command
3145substitutions inherit the value of the ‘-e’ option from the parent
3146shell. When not in POSIX mode, Bash clears the ‘-e’ option in such
3147subshells See the description of the ‘inherit_errexit’ shell option
3148(*note Bash Builtins::) for how to control this behavior when not in
3149POSIX mode.
3150
3151 If a command is followed by a ‘&’ and job control is not active, the
3152default standard input for the command is the empty file ‘/dev/null’.
f73dda09
JA
3153Otherwise, the invoked command inherits the file descriptors of the
3154calling shell as modified by redirections.
3155
ccc6cda3 3156\1f
cce855bc 3157File: bashref.info, Node: Environment, Next: Exit Status, Prev: Command Execution Environment, Up: Executing Commands
ccc6cda3 3158
b80f6443
JA
31593.7.4 Environment
3160-----------------
ccc6cda3 3161
b80f6443 3162When a program is invoked it is given an array of strings called the
b8c60bc9
CR
3163“environment”. This is a list of name-value pairs, of the form
3164‘name=value’.
ccc6cda3 3165
bb70624e 3166 Bash provides several ways to manipulate the environment. On
ccc6cda3 3167invocation, the shell scans its own environment and creates a parameter
b8c60bc9
CR
3168for each name found, automatically marking it for ‘export’ to child
3169processes. Executed commands inherit the environment. The ‘export’,
3170‘declare -x’, and ‘unset’ commands modify the environment by adding and
3171deleting parameters and functions. If the value of a parameter in the
3172environment is modified, the new value automatically becomes part of the
3173environment, replacing the old. The environment inherited by any
3174executed command consists of the shell's initial environment, whose
3175values may be modified in the shell, less any pairs removed by the
3176‘unset’ and ‘export -n’ commands, plus any additions via the ‘export’
3177and ‘declare -x’ commands.
3178
3179 If any parameter assignment statements, as described in *note Shell
3180Parameters::, appear before a simple command, the variable assignments
3181are part of that command's environment for as long as it executes.
3182These assignment statements affect only the environment seen by that
3183command. If these assignments precede a call to a shell function, the
3184variables are local to the function and exported to that function's
3185children.
3186
3187 If the ‘-k’ option is set (*note The Set Builtin::), then all
ccc6cda3
JA
3188parameter assignments are placed in the environment for a command, not
3189just those that precede the command name.
3190
b8c60bc9 3191 When Bash invokes an external command, the variable ‘$_’ is set to
ac50fbac 3192the full pathname of the command and passed to that command in its
ccc6cda3
JA
3193environment.
3194
3195\1f
3196File: bashref.info, Node: Exit Status, Next: Signals, Prev: Environment, Up: Executing Commands
3197
b80f6443
JA
31983.7.5 Exit Status
3199-----------------
ccc6cda3 3200
3185942a 3201The exit status of an executed command is the value returned by the
b8c60bc9 3202‘waitpid’ system call or equivalent function. Exit statuses fall
74091dd4
CR
3203between 0 and 255, though, as explained below, the shell may use values
3204above 125 specially. Exit statuses from shell builtins and compound
3205commands are also limited to this range. Under certain circumstances,
3206the shell will use special values to indicate specific failure modes.
3185942a
JA
3207
3208 For the shell's purposes, a command which exits with a zero exit
b8c60bc9
CR
3209status has succeeded. So while an exit status of zero indicates
3210success, a non-zero exit status indicates failure. This seemingly
3211counter-intuitive scheme is used so there is one well-defined way to
3212indicate success and a variety of ways to indicate various failure
3213modes.
3214
3215 When a command terminates on a fatal signal whose number is N, Bash
3216uses the value 128+N as the exit status.
ccc6cda3
JA
3217
3218 If a command is not found, the child process created to execute it
3219returns a status of 127. If a command is found but is not executable,
3220the return status is 126.
3221
cce855bc
JA
3222 If a command fails because of an error during expansion or
3223redirection, the exit status is greater than zero.
3224
ccc6cda3 3225 The exit status is used by the Bash conditional commands (*note
28ef6c31
JA
3226Conditional Constructs::) and some of the list constructs (*note
3227Lists::).
ccc6cda3
JA
3228
3229 All of the Bash builtins return an exit status of zero if they
3230succeed and a non-zero status on failure, so they may be used by the
cce855bc 3231conditional and list constructs. All builtins return an exit status of
a0c0a00f
CR
32322 to indicate incorrect usage, generally invalid options or missing
3233arguments.
ccc6cda3 3234
74091dd4
CR
3235 The exit status of the last command is available in the special
3236parameter $? (*note Special Parameters::).
3237
b8c60bc9
CR
3238 Bash itself returns the exit status of the last command executed,
3239unless a syntax error occurs, in which case it exits with a non-zero
3240value. See also the ‘exit’ builtin command (*note Bourne Shell
3241Builtins::.
3242
ccc6cda3
JA
3243\1f
3244File: bashref.info, Node: Signals, Prev: Exit Status, Up: Executing Commands
3245
b80f6443
JA
32463.7.6 Signals
3247-------------
ccc6cda3 3248
b80f6443 3249When Bash is interactive, in the absence of any traps, it ignores
b8c60bc9
CR
3250‘SIGTERM’ (so that ‘kill 0’ does not kill an interactive shell), and
3251catches and handles ‘SIGINT’ (so that the ‘wait’ builtin is
3252interruptible). When Bash receives a ‘SIGINT’, it breaks out of any
3253executing loops. In all cases, Bash ignores ‘SIGQUIT’. If job control
3254is in effect (*note Job Control::), Bash ignores ‘SIGTTIN’, ‘SIGTTOU’,
3255and ‘SIGTSTP’.
3256
3257 The ‘trap’ builtin modifies the shell's signal handling, as described
3258below (*note Bourne Shell Builtins::.
3259
3260 Non-builtin commands Bash executes have signal handlers set to the
3261values inherited by the shell from its parent, unless ‘trap’ sets them
3262to be ignored, in which case the child process will ignore them as well.
3263When job control is not in effect, asynchronous commands ignore ‘SIGINT’
3264and ‘SIGQUIT’ in addition to these inherited handlers. Commands run as
3265a result of command substitution ignore the keyboard-generated job
3266control signals ‘SIGTTIN’, ‘SIGTTOU’, and ‘SIGTSTP’.
3267
3268 The shell exits by default upon receipt of a ‘SIGHUP’. Before
3269exiting, an interactive shell resends the ‘SIGHUP’ to all jobs, running
3270or stopped. The shell sends ‘SIGCONT’ to stopped jobs to ensure that
3271they receive the ‘SIGHUP’ (*Note Job Control::, for more information
3272about running and stopped jobs). To prevent the shell from sending the
3273‘SIGHUP’ signal to a particular job, remove it from the jobs table with
3274the ‘disown’ builtin (*note Job Control Builtins::) or mark it not to
3275receive ‘SIGHUP’ using ‘disown -h’.
3276
3277 If the ‘huponexit’ shell option has been set using ‘shopt’ (*note The
3278Shopt Builtin::), Bash sends a ‘SIGHUP’ to all jobs when an interactive
a0c0a00f 3279login shell exits.
cce855bc 3280
b80f6443 3281 If Bash is waiting for a command to complete and receives a signal
b8c60bc9
CR
3282for which a trap has been set, it will not execute the trap until the
3283command completes. If Bash is waiting for an asynchronous command via
3284the ‘wait’ builtin, and it receives a signal for which a trap has been
3285set, the ‘wait’ builtin will return immediately with an exit status
3286greater than 128, immediately after which the shell executes the trap.
ccc6cda3 3287
74091dd4
CR
3288 When job control is not enabled, and Bash is waiting for a foreground
3289command to complete, the shell receives keyboard-generated signals such
b8c60bc9 3290as ‘SIGINT’ (usually generated by ‘^C’) that users commonly intend to
74091dd4 3291send to that command. This happens because the shell and the command
b8c60bc9
CR
3292are in the same process group as the terminal, and ‘^C’ sends ‘SIGINT’
3293to all processes in that process group. Since Bash does not enable job
3294control by default when the shell is not interactive, this scenario is
3295most common in non-interactive shells.
3296
3297 When job control is enabled, and Bash is waiting for a foreground
3298command to complete, the shell does not receive keyboard-generated
3299signals, because it is not in the same process group as the terminal.
3300This scenario is most common in interactive shells, where Bash attempts
3301to enable job control by default. See *note Job Control::, for a more
3302in-depth discussion of process groups.
3303
3304 When job control is not enabled, and Bash receives ‘SIGINT’ while
3305waiting for a foreground command, it waits until that foreground command
3306terminates and then decides what to do about the ‘SIGINT’:
3307
3308 1. If the command terminates due to the ‘SIGINT’, Bash concludes that
3309 the user meant to send the ‘SIGINT’ to the shell as well, and acts
3310 on the ‘SIGINT’ (e.g., by running a ‘SIGINT’ trap, exiting a
3311 non-interactive shell, or returning to the top level to read a new
3312 command).
3313
3314 2. If the command does not terminate due to ‘SIGINT’, the program
3315 handled the ‘SIGINT’ itself and did not treat it as a fatal signal.
3316 In that case, Bash does not treat ‘SIGINT’ as a fatal signal,
3317 either, instead assuming that the ‘SIGINT’ was used as part of the
3318 program's normal operation (e.g., ‘emacs’ uses it to abort editing
74091dd4 3319 commands) or deliberately discarded. However, Bash will run any
b8c60bc9 3320 trap set on ‘SIGINT’, as it does with any other trapped signal it
74091dd4
CR
3321 receives while it is waiting for the foreground command to
3322 complete, for compatibility.
3323
b8c60bc9
CR
3324 When job control is enabled, Bash does not receive keyboard-generated
3325signals such as ‘SIGINT’ while it is waiting for a foreground command.
3326An interactive shell does not pay attention to the ‘SIGINT’, even if the
3327foreground command terminates as a result, other than noting its exit
3328status. If the shell is not interactive, and the foreground command
3329terminates due to the ‘SIGINT’, Bash pretends it received the ‘SIGINT’
3330itself (scenario 1 above), for compatibility.
3331
ccc6cda3
JA
3332\1f
3333File: bashref.info, Node: Shell Scripts, Prev: Executing Commands, Up: Basic Shell Features
3334
b80f6443
JA
33353.8 Shell Scripts
3336=================
ccc6cda3 3337
b80f6443
JA
3338A shell script is a text file containing shell commands. When such a
3339file is used as the first non-option argument when invoking Bash, and
b8c60bc9 3340neither the ‘-c’ nor ‘-s’ option is supplied (*note Invoking Bash::),
ccc6cda3 3341Bash reads and executes commands from the file, then exits. This mode
b8c60bc9
CR
3342of operation creates a non-interactive shell. If the filename does not
3343contain any slashes, the shell first searches for the file in the
3344current directory, and looks in the directories in ‘$PATH’ if not found
3345there.
3346
3347 Bash tries to determine whether the file is a text file or a binary,
3348and will not execute files it determines to be binaries.
f73dda09 3349
b8c60bc9 3350 When Bash runs a shell script, it sets the special parameter ‘0’ to
f73dda09
JA
3351the name of the file, rather than the name of the shell, and the
3352positional parameters are set to the remaining arguments, if any are
3353given. If no additional arguments are supplied, the positional
3354parameters are unset.
ccc6cda3 3355
b8c60bc9 3356 A shell script may be made executable by using the ‘chmod’ command to
a0c0a00f 3357turn on the execute bit. When Bash finds such a file while searching
b8c60bc9 3358the ‘$PATH’ for a command, it creates a new instance of itself to
74091dd4 3359execute it. In other words, executing
ccc6cda3 3360 filename ARGUMENTS
a0c0a00f 3361is equivalent to executing
ccc6cda3
JA
3362 bash filename ARGUMENTS
3363
b8c60bc9 3364if ‘filename’ is an executable shell script. This subshell
ccc6cda3 3365reinitializes itself, so that the effect is as if a new shell had been
cce855bc 3366invoked to interpret the script, with the exception that the locations
b8c60bc9 3367of commands remembered by the parent (see the description of ‘hash’ in
3185942a 3368*note Bourne Shell Builtins::) are retained by the child.
ccc6cda3 3369
b8c60bc9
CR
3370 The GNU operating system, and most versions of Unix, make this a part
3371of the operating system's command execution mechanism. If the first
3372line of a script begins with the two characters ‘#!’, the remainder of
3373the line specifies an interpreter for the program and, depending on the
3374operating system, one or more optional arguments for that interpreter.
3375Thus, you can specify Bash, ‘awk’, Perl, or some other interpreter and
3376write the rest of the script file in that language.
bb70624e 3377
8868edaf
CR
3378 The arguments to the interpreter consist of one or more optional
3379arguments following the interpreter name on the first line of the script
bb70624e 3380file, followed by the name of the script file, followed by the rest of
8868edaf
CR
3381the arguments supplied to the script. The details of how the
3382interpreter line is split into an interpreter name and a set of
3383arguments vary across systems. Bash will perform this action on
3384operating systems that do not handle it themselves. Note that some
3385older versions of Unix limit the interpreter name and a single argument
3386to a maximum of 32 characters, so it's not portable to assume that using
3387more than one argument will work.
bb70624e 3388
b8c60bc9
CR
3389 Bash scripts often begin with ‘#! /bin/bash’ (assuming that Bash has
3390been installed in ‘/bin’), since this ensures that Bash will be used to
8868edaf 3391interpret the script, even if it is executed under another shell. It's
b8c60bc9
CR
3392a common idiom to use ‘env’ to find ‘bash’ even if it's been installed
3393in another directory: ‘#!/usr/bin/env bash’ will find the first
3394occurrence of ‘bash’ in ‘$PATH’.
ccc6cda3
JA
3395
3396\1f
bb70624e 3397File: bashref.info, Node: Shell Builtin Commands, Next: Shell Variables, Prev: Basic Shell Features, Up: Top
ccc6cda3 3398
b80f6443
JA
33994 Shell Builtin Commands
3400************************
ccc6cda3
JA
3401
3402* Menu:
3403
3404* Bourne Shell Builtins:: Builtin commands inherited from the Bourne
3405 Shell.
bb70624e 3406* Bash Builtins:: Table of builtins specific to Bash.
3185942a
JA
3407* Modifying Shell Behavior:: Builtins to modify shell attributes and
3408 optional behavior.
bb70624e 3409* Special Builtins:: Builtin commands classified specially by
0628567a 3410 POSIX.
bb70624e 3411
a0c0a00f
CR
3412Builtin commands are contained within the shell itself. When the name
3413of a builtin command is used as the first word of a simple command
28ef6c31 3414(*note Simple Commands::), the shell executes the command directly,
bb70624e
JA
3415without invoking another program. Builtin commands are necessary to
3416implement functionality impossible or inconvenient to obtain with
3417separate utilities.
ccc6cda3 3418
0628567a 3419 This section briefly describes the builtins which Bash inherits from
a0c0a00f
CR
3420the Bourne Shell, as well as the builtin commands which are unique to or
3421have been extended in Bash.
bb70624e 3422
a0c0a00f 3423 Several builtin commands are described in other chapters: builtin
bb70624e 3424commands which provide the Bash interface to the job control facilities
28ef6c31
JA
3425(*note Job Control Builtins::), the directory stack (*note Directory
3426Stack Builtins::), the command history (*note Bash History Builtins::),
3427and the programmable completion facilities (*note Programmable
3428Completion Builtins::).
bb70624e
JA
3429
3430 Many of the builtins have been extended by POSIX or Bash.
ccc6cda3 3431
b80f6443 3432 Unless otherwise noted, each builtin command documented as accepting
b8c60bc9
CR
3433options preceded by ‘-’ accepts ‘--’ to signify the end of the options.
3434The ‘:’, ‘true’, ‘false’, and ‘test’/‘[’ builtins do not accept options
3435and do not treat ‘--’ specially. The ‘exit’, ‘logout’, ‘return’,
3436‘break’, ‘continue’, ‘let’, and ‘shift’ builtins accept and process
3437arguments beginning with ‘-’ without requiring ‘--’. Other builtins
d233b485 3438that accept arguments but are not specified as accepting options
b8c60bc9
CR
3439interpret arguments beginning with ‘-’ as invalid options and require
3440‘--’ to prevent this interpretation.
b80f6443 3441
ccc6cda3 3442\1f
bb70624e 3443File: bashref.info, Node: Bourne Shell Builtins, Next: Bash Builtins, Up: Shell Builtin Commands
ccc6cda3 3444
b80f6443
JA
34454.1 Bourne Shell Builtins
3446=========================
ccc6cda3 3447
b80f6443 3448The following shell builtin commands are inherited from the Bourne
0628567a 3449Shell. These commands are implemented as specified by the POSIX
ccc6cda3
JA
3450standard.
3451
b8c60bc9 3452‘: (a colon)’
ccc6cda3 3453 : [ARGUMENTS]
ac50fbac 3454
ccc6cda3 3455 Do nothing beyond expanding ARGUMENTS and performing redirections.
cce855bc 3456 The return status is zero.
ccc6cda3 3457
b8c60bc9
CR
3458‘. (a period)’
3459 . [-p PATH] FILENAME [ARGUMENTS]
3460
3461 The ‘.’ command reads and execute commands from the FILENAME
3462 argument in the current shell context.
3463
3464 If FILENAME does not contain a slash, ‘.’ searches for it. If ‘-p’
3465 is supplied, ‘.’ treats PATH as a colon-separated list of
3466 directories in which to find FILENAME; otherwise, ‘.’ uses the
3467 directories in ‘PATH’ to find FILENAME. FILENAME does not need to
3468 be executable. When Bash is not in POSIX mode, it searches the
3469 current directory if FILENAME is not found in ‘$PATH’, but does not
3470 search the current directory if ‘-p’ is supplied. If the
3471 ‘sourcepath’ option (*note The Shopt Builtin::) is turned off, ‘.’
3472 does not search ‘PATH’.
3473
3474 If any ARGUMENTS are supplied, they become the positional
3475 parameters when FILENAME is executed. Otherwise the positional
3476 parameters are unchanged.
3477
3478 If the ‘-T’ option is enabled, ‘.’ inherits any trap on ‘DEBUG’; if
3479 it is not, any ‘DEBUG’ trap string is saved and restored around the
3480 call to ‘.’, and ‘.’ unsets the ‘DEBUG’ trap while it executes. If
3481 ‘-T’ is not set, and the sourced file changes the ‘DEBUG’ trap, the
3482 new value persists after ‘.’ completes. The return status is the
3483 exit status of the last command executed from FILENAME, or zero if
3484 no commands are executed. If FILENAME is not found, or cannot be
3485 read, the return status is non-zero. This builtin is equivalent to
3486 ‘source’.
3487
3488‘break’
ccc6cda3 3489 break [N]
ac50fbac 3490
b8c60bc9
CR
3491 Exit from a ‘for’, ‘while’, ‘until’, or ‘select’ loop. If N is
3492 supplied, ‘break’ exits the Nth enclosing loop. N must be greater
3493 than or equal to 1. The return status is zero unless N is not
3494 greater than or equal to 1.
ccc6cda3 3495
b8c60bc9
CR
3496‘cd’
3497 cd [-L] [-@] [DIRECTORY]
3498 cd -P [-e] [-@] [DIRECTORY]
ac50fbac 3499
a0c0a00f 3500 Change the current working directory to DIRECTORY. If DIRECTORY is
b8c60bc9
CR
3501 not supplied, the value of the ‘HOME’ shell variable is used as
3502 DIRECTORY. If the shell variable ‘CDPATH’ exists, and DIRECTORY
3503 does not begin with a slash, ‘cd’ uses it as a search path: ‘cd’
3504 searches each directory name in ‘CDPATH’ for DIRECTORY, with
3505 alternative directory names in ‘CDPATH’ separated by a colon (‘:’).
3506 A null directory name in ‘CDPATH’ means the same thing as the
3507 current directory.
3508
3509 The ‘-P’ option means not to follow symbolic links: symbolic links
3510 are resolved while ‘cd’ is traversing DIRECTORY and before
3511 processing an instance of ‘..’ in DIRECTORY.
3512
3513 By default, or when the ‘-L’ option is supplied, symbolic links in
3514 DIRECTORY are resolved after ‘cd’ processes an instance of ‘..’ in
ac50fbac
CR
3515 DIRECTORY.
3516
b8c60bc9 3517 If ‘..’ appears in DIRECTORY, ‘cd’ processes it by removing the
ac50fbac 3518 immediately preceding pathname component, back to a slash or the
b8c60bc9
CR
3519 beginning of DIRECTORY, and verifying that the portion of DIRECTORY
3520 it has processed to that point is still a valid directory name
3521 after removing the pathname component. If it is not a valid
3522 directory name, ‘cd’ returns a non-zero status.
ac50fbac 3523
b8c60bc9
CR
3524 If the ‘-e’ option is supplied with ‘-P’ and ‘cd’ cannot
3525 successfully determine the current working directory after a
3526 successful directory change, it returns a non-zero status.
ac50fbac 3527
b8c60bc9 3528 On systems that support it, the ‘-@’ option presents the extended
ac50fbac
CR
3529 attributes associated with a file as a directory.
3530
b8c60bc9
CR
3531 If DIRECTORY is ‘-’, it is converted to ‘$OLDPWD’ before attempting
3532 the directory change.
b80f6443 3533
b8c60bc9
CR
3534 If ‘cd’ uses a non-empty directory name from ‘CDPATH’, or if ‘-’ is
3535 the first argument, and the directory change is successful, ‘cd’
3536 writes the absolute pathname of the new working directory to the
b80f6443
JA
3537 standard output.
3538
b8c60bc9
CR
3539 If the directory change is successful, ‘cd’ sets the value of the
3540 ‘PWD’ environment variable to the new directory name, and sets the
3541 ‘OLDPWD’ environment variable to the value of the current working
74091dd4
CR
3542 directory before the change.
3543
b80f6443
JA
3544 The return status is zero if the directory is successfully changed,
3545 non-zero otherwise.
ccc6cda3 3546
b8c60bc9 3547‘continue’
ccc6cda3 3548 continue [N]
ac50fbac 3549
b8c60bc9
CR
3550 ‘continue’ resumes the next iteration of an enclosing ‘for’,
3551 ‘while’, ‘until’, or ‘select’ loop. If N is supplied, Bash resumes
3552 the execution of the Nth enclosing loop. N must be greater than or
3553 equal to 1. The return status is zero unless N is not greater than
3554 or equal to 1.
ccc6cda3 3555
b8c60bc9 3556‘eval’
ccc6cda3 3557 eval [ARGUMENTS]
ac50fbac 3558
b8c60bc9
CR
3559 The ARGUMENTS are concatenated together into a single command,
3560 separated by spaces. Bash then reads and executes this command and
3561 returns its exit status as the exit status of ‘eval’. If there are
3562 no arguments or only empty arguments, the return status is zero.
ccc6cda3 3563
b8c60bc9 3564‘exec’
cce855bc 3565 exec [-cl] [-a NAME] [COMMAND [ARGUMENTS]]
ac50fbac 3566
cce855bc 3567 If COMMAND is supplied, it replaces the shell without creating a
b8c60bc9
CR
3568 new process. COMMAND cannot be a shell builtin or function. The
3569 ARGUMENTS become the arguments to COMMAND If the ‘-l’ option is
3570 supplied, the shell places a dash at the beginning of the zeroth
3571 argument passed to COMMAND. This is what the ‘login’ program does.
3572 The ‘-c’ option causes COMMAND to be executed with an empty
3573 environment. If ‘-a’ is supplied, the shell passes NAME as the
3574 zeroth argument to COMMAND.
3575
ac50fbac 3576 If COMMAND cannot be executed for some reason, a non-interactive
b8c60bc9
CR
3577 shell exits, unless the ‘execfail’ shell option is enabled. In
3578 that case, it returns a non-zero status. An interactive shell
3579 returns a non-zero status if the file cannot be executed. A
3580 subshell exits unconditionally if ‘exec’ fails.
3581
3582 If COMMAND is not specified, redirections may be used to affect the
3583 current shell environment. If there are no redirection errors, the
3584 return status is zero; otherwise the return status is non-zero.
3585
3586‘exit’
ccc6cda3 3587 exit [N]
ac50fbac 3588
bb70624e
JA
3589 Exit the shell, returning a status of N to the shell's parent. If
3590 N is omitted, the exit status is that of the last command executed.
b8c60bc9 3591 Any trap on ‘EXIT’ is executed before the shell terminates.
ccc6cda3 3592
b8c60bc9 3593‘export’
ccc6cda3 3594 export [-fn] [-p] [NAME[=VALUE]]
ac50fbac 3595
b8c60bc9
CR
3596 Mark each NAME to be passed to subsequently executed commands in
3597 the environment. If the ‘-f’ option is supplied, the NAMEs refer
3598 to shell functions; otherwise the names refer to shell variables.
3599
3600 The ‘-n’ option means to unexport each name: no longer mark it for
3601 export. If no NAMEs are supplied, or if only the ‘-p’ option is
3602 given, ‘export’ displays a list of names of all exported variables
3603 on the standard output. Using ‘-p’ and ‘-f’ together displays
3604 exported functions. The ‘-p’ option displays output in a form that
3605 may be reused as input.
3606
3607 ‘export’ allows the value of a variable to be set at the same time
3608 it is exported or unexported by following the variable name with
3609 =VALUE. This sets the value of the variable is to VALUE while
3610 modifying the export attribute.
a0c0a00f
CR
3611
3612 The return status is zero unless an invalid option is supplied, one
b8c60bc9 3613 of the names is not a valid shell variable name, or ‘-f’ is
b80f6443 3614 supplied with a name that is not a shell function.
ccc6cda3 3615
b8c60bc9
CR
3616‘false’
3617 false
3618
3619 Does nothing; returns a non-zero status.
3620
3621‘getopts’
8868edaf 3622 getopts OPTSTRING NAME [ARG ...]
ac50fbac 3623
b8c60bc9
CR
3624 ‘getopts’ is used by shell scripts or functions to parse positional
3625 parameters and obtain options and their arguments. OPTSTRING
3626 contains the option characters to be recognized; if a character is
3627 followed by a colon, the option is expected to have an argument,
3628 which should be separated from it by whitespace. The colon (‘:’)
3629 and question mark (‘?’) may not be used as option characters.
3630
3631 Each time it is invoked, ‘getopts’ places the next option in the
3632 shell variable NAME, initializing NAME if it does not exist, and
3633 the index of the next argument to be processed into the variable
3634 ‘OPTIND’. ‘OPTIND’ is initialized to 1 each time the shell or a
3635 shell script is invoked. When an option requires an argument,
3636 ‘getopts’ places that argument into the variable ‘OPTARG’.
3637
3638 The shell does not reset ‘OPTIND’ automatically; it must be
3639 manually reset between multiple calls to ‘getopts’ within the same
3640 shell invocation to use a new set of parameters.
3641
3642 When it reaches the end of options, ‘getopts’ exits with a return
3643 value greater than zero. ‘OPTIND’ is set to the index of the first
3644 non-option argument, and NAME is set to ‘?’.
3645
3646 ‘getopts’ normally parses the positional parameters, but if more
3647 arguments are supplied as ARG values, ‘getopts’ parses those
8868edaf 3648 instead.
cce855bc 3649
b8c60bc9
CR
3650 ‘getopts’ can report errors in two ways. If the first character of
3651 OPTSTRING is a colon, ‘getopts’ uses _silent_ error reporting. In
3652 normal operation, ‘getopts’ prints diagnostic messages when it
3653 encounters invalid options or missing option arguments. If the
3654 variable ‘OPTERR’ is set to 0, ‘getopts’ does not display any error
3655 messages, even if the first character of ‘optstring’ is not a
3656 colon.
3657
3658 If ‘getopts’ detects an invalid option, it places ‘?’ into NAME
3659 and, if not silent, prints an error message and unsets ‘OPTARG’.
3660 If ‘getopts’ is silent, it assigns the option character found to
3661 ‘OPTARG’ and does not print a diagnostic message.
3662
3663 If a required argument is not found, and ‘getopts’ is not silent,
3664 it sets the value of NAME to a question mark (‘?’), unsets
3665 ‘OPTARG’, and prints a diagnostic message. If ‘getopts’ is silent,
3666 it sets the value of NAME to a colon (‘:’), and sets ‘OPTARG’ to
3667 the option character found.
3668
3669 ‘getopts’ returns true if an option, specified or unspecified, is
3670 found. It returns false when it encounters the end of options or
3671 if an error occurs.
3672
3673‘hash’
0628567a 3674 hash [-r] [-p FILENAME] [-dt] [NAME]
ac50fbac 3675
b8c60bc9 3676 Each time ‘hash’ is invoked, it remembers the full filenames of the
495aee44 3677 commands specified as NAME arguments, so they need not be searched
a0c0a00f 3678 for on subsequent invocations. The commands are found by searching
b8c60bc9
CR
3679 through the directories listed in ‘$PATH’. Any
3680 previously-remembered filename associated with NAME is discarded.
3681 The ‘-p’ option inhibits the path search, and ‘hash’ uses FILENAME
3682 as the location of NAME.
3683
3684 The ‘-r’ option causes the shell to forget all remembered
3685 locations. Assigning to the ‘PATH’ variable also clears all hashed
3686 filenames. The ‘-d’ option causes the shell to forget the
3687 remembered location of each NAME.
3688
3689 If the ‘-t’ option is supplied, ‘hash’ prints the full pathname
3690 corresponding to each NAME. If multiple NAME arguments are
3691 supplied with ‘-t’, ‘hash’ prints each NAME before the
3692 corresponding hashed full path. The ‘-l’ option displays output in
3693 a format that may be reused as input.
3694
3695 If no arguments are given, or if only ‘-l’ is supplied, ‘hash’
3696 prints information about remembered commands. The ‘-t’, ‘-d’, and
3697 ‘-p’ options (the options that act on the NAME arguments) are
3698 mutually exclusive. Only one will be active. If more than one is
3699 supplied, ‘-t’ has higher priority than ‘-p’, and both have higher
3700 priority than ‘-d’.
3701
3702 The return status is zero unless a NAME is not found or an invalid
3703 option is supplied.
3704
3705‘pwd’
ccc6cda3 3706 pwd [-LP]
ac50fbac 3707
bb70624e 3708 Print the absolute pathname of the current working directory. If
b8c60bc9
CR
3709 the ‘-P’ option is supplied, or the ‘-o physical’ option to the
3710 ‘set’ builtin (*note The Set Builtin::) is enabled, the pathname
3711 printed will not contain symbolic links. If the ‘-L’ option is
3712 supplied, the pathname printed may contain symbolic links. The
3713 return status is zero unless an error is encountered while
3714 determining the name of the current directory or an invalid option
3715 is supplied.
3716
3717‘readonly’
ac50fbac
CR
3718 readonly [-aAf] [-p] [NAME[=VALUE]] ...
3719
cce855bc 3720 Mark each NAME as readonly. The values of these names may not be
b8c60bc9
CR
3721 changed by subsequent assignment or unset. If the ‘-f’ option is
3722 supplied, each NAME refers to a shell function. The ‘-a’ option
3723 means each NAME refers to an indexed array variable; the ‘-A’
3724 option means each NAME refers to an associative array variable. If
3725 both options are supplied, ‘-A’ takes precedence. If no NAME
3726 arguments are supplied, or if the ‘-p’ option is supplied, print a
3727 list of all readonly names. The other options may be used to
3728 restrict the output to a subset of the set of readonly names. The
3729 ‘-p’ option displays output in a format that may be reused as
3730 input.
3731
3732 ‘readonly’ allows the value of a variable to be set at the same
3733 time the readonly attribute is changed by following the variable
3734 name with =VALUE. This sets the value of the variable is to VALUE
3735 while modifying the readonly attribute.
3736
3737 The return status is zero unless an invalid option is supplied, one
3738 of the NAME arguments is not a valid shell variable or function
3739 name, or the ‘-f’ option is supplied with a name that is not a
3740 shell function.
ccc6cda3 3741
b8c60bc9 3742‘return’
ccc6cda3 3743 return [N]
ac50fbac 3744
b8c60bc9
CR
3745 Stop executing a shell function or sourced file and return the
3746 value N to its caller. If N is not supplied, the return value is
3747 the exit status of the last command executed. If ‘return’ is
3748 executed by a trap handler, the last command used to determine the
3749 status is the last command executed before the trap handler. If
3750 ‘return’ is executed during a ‘DEBUG’ trap, the last command used
3751 to determine the status is the last command executed by the trap
3752 handler before ‘return’ was invoked.
3753
3754 When ‘return’ is used to terminate execution of a script being
3755 executed with the ‘.’ (‘source’) builtin, it returns either N or
3756 the exit status of the last command executed within the script as
3757 the exit status of the script. If N is supplied, the return value
3758 is its least significant 8 bits.
3759
3760 Any command associated with the ‘RETURN’ trap is executed before
3761 execution resumes after the function or script.
3762
3763 The return status is non-zero if ‘return’ is supplied a non-numeric
a0c0a00f 3764 argument or is used outside a function and not during the execution
b8c60bc9 3765 of a script by ‘.’ or ‘source’.
a0c0a00f 3766
b8c60bc9 3767‘shift’
ccc6cda3 3768 shift [N]
ac50fbac 3769
b8c60bc9
CR
3770 Shift the positional parameters to the left by N: the positional
3771 parameters from N+1 ... ‘$#’ are renamed to ‘$1’ ... ‘$#’-N.
3772 Parameters represented by the numbers ‘$#’ down to ‘$#’-N+1 are
3773 unset. N must be a non-negative number less than or equal to ‘$#’.
3774 If N is not supplied, it is assumed to be 1. If N is zero or
3775 greater than ‘$#’, the positional parameters are not changed. The
3776 return status is zero unless N is greater than ‘$#’ or less than
8868edaf 3777 zero, non-zero otherwise.
ccc6cda3 3778
b8c60bc9
CR
3779‘test’
3780‘[’
ac50fbac
CR
3781 test EXPR
3782
a0c0a00f 3783 Evaluate a conditional expression EXPR and return a status of 0
ac50fbac
CR
3784 (true) or 1 (false). Each operator and operand must be a separate
3785 argument. Expressions are composed of the primaries described
b8c60bc9 3786 below in *note Bash Conditional Expressions::. ‘test’ does not
ac50fbac 3787 accept any options, nor does it accept and ignore an argument of
b8c60bc9
CR
3788 ‘--’ as signifying the end of options. When using the ‘[’ form,
3789 the last argument to the command must be a ‘]’.
bb70624e 3790
cce855bc 3791 Expressions may be combined using the following operators, listed
3185942a 3792 in decreasing order of precedence. The evaluation depends on the
b8c60bc9
CR
3793 number of arguments; see below. ‘test’ uses operator precedence
3794 when there are five or more arguments.
cce855bc 3795
b8c60bc9 3796 ‘! EXPR’
cce855bc
JA
3797 True if EXPR is false.
3798
b8c60bc9
CR
3799 ‘( EXPR )’
3800 Returns the value of EXPR. This may be used to override
3801 normal operator precedence.
cce855bc 3802
b8c60bc9 3803 ‘EXPR1 -a EXPR2’
cce855bc
JA
3804 True if both EXPR1 and EXPR2 are true.
3805
b8c60bc9 3806 ‘EXPR1 -o EXPR2’
cce855bc
JA
3807 True if either EXPR1 or EXPR2 is true.
3808
b8c60bc9 3809 The ‘test’ and ‘[’ builtins evaluate conditional expressions using
cce855bc
JA
3810 a set of rules based on the number of arguments.
3811
a0c0a00f 3812 0 arguments
cce855bc
JA
3813 The expression is false.
3814
a0c0a00f 3815 1 argument
d233b485 3816 The expression is true if, and only if, the argument is not
cce855bc
JA
3817 null.
3818
a0c0a00f 3819 2 arguments
b8c60bc9 3820 If the first argument is ‘!’, the expression is true if and
a0c0a00f
CR
3821 only if the second argument is null. If the first argument is
3822 one of the unary conditional operators (*note Bash Conditional
3823 Expressions::), the expression is true if the unary test is
3824 true. If the first argument is not a valid unary operator,
3825 the expression is false.
cce855bc 3826
a0c0a00f 3827 3 arguments
d233b485
CR
3828 The following conditions are applied in the order listed.
3829
3830 1. If the second argument is one of the binary conditional
3831 operators (*note Bash Conditional Expressions::), the
3832 result of the expression is the result of the binary test
3833 using the first and third arguments as operands. The
b8c60bc9 3834 ‘-a’ and ‘-o’ operators are considered binary operators
d233b485 3835 when there are three arguments.
b8c60bc9 3836 2. If the first argument is ‘!’, the value is the negation
d233b485
CR
3837 of the two-argument test using the second and third
3838 arguments.
b8c60bc9
CR
3839 3. If the first argument is exactly ‘(’ and the third
3840 argument is exactly ‘)’, the result is the one-argument
d233b485
CR
3841 test of the second argument.
3842 4. Otherwise, the expression is false.
a0c0a00f
CR
3843
3844 4 arguments
74091dd4
CR
3845 The following conditions are applied in the order listed.
3846
b8c60bc9 3847 1. If the first argument is ‘!’, the result is the negation
74091dd4
CR
3848 of the three-argument expression composed of the
3849 remaining arguments.
b8c60bc9
CR
3850 2. If the first argument is exactly ‘(’ and the fourth
3851 argument is exactly ‘)’, the result is the two-argument
74091dd4
CR
3852 test of the second and third arguments.
3853 3. Otherwise, the expression is parsed and evaluated
3854 according to precedence using the rules listed above.
cce855bc 3855
a0c0a00f 3856 5 or more arguments
cce855bc
JA
3857 The expression is parsed and evaluated according to precedence
3858 using the rules listed above.
ccc6cda3 3859
b8c60bc9
CR
3860 If the shell is in POSIX mode, or if the expression is part of the
3861 ‘[[’ command, the ‘<’ and ‘>’ operators sort using the current
3862 locale. If the shell is not in POSIX mode, the ‘test’ and ‘[’
3863 commands sort lexicographically using ASCII ordering.
3864
3865 The historical operator-precedence parsing with 4 or more arguments
3866 can lead to ambiguities when it encounters strings that look like
3867 primaries. The POSIX standard has deprecated the ‘-a’ and ‘-o’
3868 primaries and enclosing expressions within parentheses. Scripts
3869 should no longer use them. It's much more reliable to restrict
3870 test invocations to a single primary, and to replace uses of ‘-a’
3871 and ‘-o’ with the shell's ‘&&’ and ‘||’ list operators. For
3872 example, use
3873
3874 test -n string1 && test -n string2
495aee44 3875
b8c60bc9
CR
3876 instead of
3877
3878 test -n string1 -a -n string2
3879
3880‘times’
ccc6cda3 3881 times
ac50fbac 3882
ccc6cda3 3883 Print out the user and system times used by the shell and its
cce855bc 3884 children. The return status is zero.
ccc6cda3 3885
b8c60bc9
CR
3886‘trap’
3887 trap [-lpP] [ACTION] [SIGSPEC ...]
3888
3889 The ACTION is a command that is read and executed when the shell
3890 receives any of the signals SIGSPEC. If ACTION is absent (and
3891 there is a single SIGSPEC) or equal to ‘-’, each specified
3892 SIGSPEC's disposition is reset to the value it had when the shell
3893 was started. If ACTION is the null string, then the signal
3894 specified by each SIGSPEC is ignored by the shell and commands it
3895 invokes.
3896
3897 If no arguments are supplied, ‘trap’ prints the actions associated
3898 with each trapped signal as a set of ‘trap’ commands that can be
3899 reused as shell input to restore the current signal dispositions.
3900
3901 If ACTION is not present and ‘-p’ has been supplied, ‘trap’
3902 displays the trap commands associated with each SIGSPEC, or, if no
3903 SIGSPECs are supplied, for all trapped signals, as a set of ‘trap’
3904 commands that can be reused as shell input to restore the current
3905 signal dispositions. The ‘-P’ option behaves similarly, but
3906 displays only the actions associated with each SIGSPEC argument.
3907 ‘-P’ requires at least one SIGSPEC argument. The ‘-P’ or ‘-p’
3908 options may be used in a subshell environment (e.g., command
3909 substitution) and, as long as they are used before ‘trap’ is used
3910 to change a signal's handling, will display the state of its
3911 parent's traps.
3912
3913 The ‘-l’ option prints a list of signal names and their
3914 corresponding numbers. Each SIGSPEC is either a signal name or a
3915 signal number. Signal names are case insensitive and the ‘SIG’
3916 prefix is optional. If ‘-l’ is supplied with no SIGSPEC arguments,
3917 it prints a list of valid signal names.
3918
3919 If a SIGSPEC is ‘0’ or ‘EXIT’, ACTION is executed when the shell
3920 exits. If a SIGSPEC is ‘DEBUG’, ACTION is executed before every
3921 simple command, ‘for’ command, ‘case’ command, ‘select’ command, ((
3922 arithmetic command, [[ conditional command, arithmetic ‘for’
3923 command, and before the first command executes in a shell function.
3924 Refer to the description of the ‘extdebug’ shell option (*note The
3925 Shopt Builtin::) for details of its effect on the ‘DEBUG’ trap. If
3926 a SIGSPEC is ‘RETURN’, ACTION is executed each time a shell
3927 function or a script executed with the ‘.’ or ‘source’ builtins
a0c0a00f
CR
3928 finishes executing.
3929
b8c60bc9
CR
3930 If a SIGSPEC is ‘ERR’, ACTION is executed whenever a pipeline
3931 (which may consist of a single simple command), a list, or a
3932 compound command returns a non-zero exit status, subject to the
3933 following conditions. The ‘ERR’ trap is not executed if the failed
a0c0a00f 3934 command is part of the command list immediately following an
b8c60bc9
CR
3935 ‘until’ or ‘while’ reserved word, part of the test following the
3936 ‘if’ or ‘elif’ reserved words, part of a command executed in a ‘&&’
3937 or ‘||’ list except the command following the final ‘&&’ or ‘||’,
3938 any command in a pipeline but the last, (subject to the state of
3939 the ‘pipefail’ shell option), or if the command's return status is
3940 being inverted using ‘!’. These are the same conditions obeyed by
3941 the ‘errexit’ (‘-e’) option.
3942
3943 When the shell is not interactive, signals ignored upon entry to a
3944 non-interactive shell cannot be trapped or reset. Interactive
3945 shells permit trapping signals ignored on entry. Trapped signals
3946 that are not being ignored are reset to their original values in a
3947 subshell or subshell environment when one is created.
ccc6cda3 3948
a0c0a00f 3949 The return status is zero unless a SIGSPEC does not specify a valid
b8c60bc9
CR
3950 signal; non-zero otherwise.
3951
3952‘true’
3953 true
cce855bc 3954
b8c60bc9
CR
3955 Does nothing, returns a 0 status.
3956
3957‘umask’
cce855bc 3958 umask [-p] [-S] [MODE]
ac50fbac 3959
a0c0a00f
CR
3960 Set the shell process's file creation mask to MODE. If MODE begins
3961 with a digit, it is interpreted as an octal number; if not, it is
3962 interpreted as a symbolic mode mask similar to that accepted by the
b8c60bc9
CR
3963 ‘chmod’ command. If MODE is omitted, ‘umask’ prints the current
3964 value of the mask. If the ‘-S’ option is supplied without a MODE
3965 argument, ‘umask’ prints the mask in a symbolic format; the default
3966 output is an octal number. If the ‘-p’ option is supplied, and
3967 MODE is omitted, the output is in a form that may be reused as
3968 input. The return status is zero if the mode is successfully
3969 changed or if no MODE argument is supplied, and non-zero otherwise.
ccc6cda3 3970
bb70624e 3971 Note that when the mode is interpreted as an octal number, each
b8c60bc9
CR
3972 number of the umask is subtracted from ‘7’. Thus, a umask of ‘022’
3973 results in permissions of ‘755’.
bb70624e 3974
b8c60bc9 3975‘unset’
ac50fbac
CR
3976 unset [-fnv] [NAME]
3977
b8c60bc9 3978 Remove each variable or function NAME. If the ‘-v’ option is
ac50fbac 3979 given, each NAME refers to a shell variable and that variable is
b8c60bc9
CR
3980 removed. If the ‘-f’ option is given, the NAMEs refer to shell
3981 functions, and the function definition is removed. If the ‘-n’
3982 option is supplied, and NAME is a variable with the ‘nameref’
ac50fbac 3983 attribute, NAME will be unset rather than the variable it
b8c60bc9 3984 references. ‘-n’ has no effect if the ‘-f’ option is supplied. If
a0c0a00f 3985 no options are supplied, each NAME refers to a variable; if there
8868edaf 3986 is no variable by that name, a function with that name, if any, is
b8c60bc9
CR
3987 unset. Readonly variables and functions may not be unset. When
3988 variables or functions are removed, they are also removed from the
3989 environment passed to subsequent commands. Some shell variables
3990 may not be unset. Some shell variables lose their special behavior
3991 if they are unset; such behavior is noted in the description of the
3992 individual variables. The return status is zero unless a NAME is
3993 readonly or may not be unset.
ccc6cda3
JA
3994
3995\1f
3185942a 3996File: bashref.info, Node: Bash Builtins, Next: Modifying Shell Behavior, Prev: Bourne Shell Builtins, Up: Shell Builtin Commands
ccc6cda3 3997
b80f6443
JA
39984.2 Bash Builtin Commands
3999=========================
ccc6cda3 4000
a0c0a00f
CR
4001This section describes builtin commands which are unique to or have been
4002extended in Bash. Some of these commands are specified in the POSIX
4003standard.
ccc6cda3 4004
b8c60bc9 4005‘alias’
ac50fbac 4006 alias [-p] [NAME[=VALUE] ...]
ccc6cda3 4007
b8c60bc9 4008 Without arguments or with the ‘-p’ option, ‘alias’ prints the list
bb70624e 4009 of aliases on the standard output in a form that allows them to be
b8c60bc9
CR
4010 reused as input. If arguments are supplied, define an alias for
4011 each NAME whose VALUE is given. If no VALUE is given, print the
4012 name and value of the alias NAME. A trailing space in VALUE causes
4013 the next word to be checked for alias substitution when the alias
4014 is expanded during command parsing. ‘alias’ returns true unless a
4015 NAME is given (without a corresponding =VALUE) for which no alias
4016 has been defined. Aliases are described in *note Aliases::.
4017
4018‘bind’
4019 bind [-m KEYMAP] [-lsvSVX]
bb70624e
JA
4020 bind [-m KEYMAP] [-q FUNCTION] [-u FUNCTION] [-r KEYSEQ]
4021 bind [-m KEYMAP] -f FILENAME
b8c60bc9 4022 bind [-m KEYMAP] -x KEYSEQ[: ]SHELL-COMMAND
bb70624e 4023 bind [-m KEYMAP] KEYSEQ:FUNCTION-NAME
a0c0a00f 4024 bind [-m KEYMAP] KEYSEQ:READLINE-COMMAND
b8c60bc9 4025 bind [-m KEYMAP] -p|-P [READLINE-COMMAND]
74091dd4 4026 bind READLINE-COMMAND-LINE
ccc6cda3 4027
28ef6c31 4028 Display current Readline (*note Command Line Editing::) key and
7117c2d2 4029 function bindings, bind a key sequence to a Readline function or
b8c60bc9
CR
4030 macro or to a shell command, or set a Readline variable. Each
4031 non-option argument is a key binding or command as it would appear
4032 in a Readline initialization file (*note Readline Init File::), but
4033 each binding or command must be passed as a separate argument;
4034 e.g., ‘"\C-x\C-r":re-read-init-file’.
4035
4036 In the following descriptions, options that display output in a
4037 form available to be re-read format their output as commands that
4038 would appear in a Readline initialization file or that would be
4039 supplied as individual arguments to a ‘bind’ command.
3185942a
JA
4040
4041 Options, if supplied, have the following meanings:
ccc6cda3 4042
b8c60bc9 4043 ‘-m KEYMAP’
bb70624e 4044 Use KEYMAP as the keymap to be affected by the subsequent
b8c60bc9
CR
4045 bindings. Acceptable KEYMAP names are ‘emacs’,
4046 ‘emacs-standard’, ‘emacs-meta’, ‘emacs-ctlx’, ‘vi’, ‘vi-move’,
4047 ‘vi-command’, and ‘vi-insert’. ‘vi’ is equivalent to
4048 ‘vi-command’ (‘vi-move’ is also a synonym); ‘emacs’ is
4049 equivalent to ‘emacs-standard’.
cce855bc 4050
b8c60bc9 4051 ‘-l’
bb70624e 4052 List the names of all Readline functions.
cce855bc 4053
b8c60bc9 4054 ‘-p’
bb70624e 4055 Display Readline function names and bindings in such a way
b8c60bc9
CR
4056 that they can be used as an argument to a subsequent ‘bind’
4057 command or in a Readline initialization file. If arguments
4058 remain after option processing, ‘bind’ treats them as readline
4059 command names and restricts output to those names.
cce855bc 4060
b8c60bc9
CR
4061 ‘-P’
4062 List current Readline function names and bindings. If
4063 arguments remain after option processing, ‘bind’ treats them
4064 as readline command names and restricts output to those names.
ccc6cda3 4065
b8c60bc9 4066 ‘-s’
a0c0a00f 4067 Display Readline key sequences bound to macros and the strings
b8c60bc9
CR
4068 they output in such a way that they can be used as an argument
4069 to a subsequent ‘bind’ command or in a Readline initialization
4070 file.
ccc6cda3 4071
b8c60bc9 4072 ‘-S’
a0c0a00f
CR
4073 Display Readline key sequences bound to macros and the strings
4074 they output.
ccc6cda3 4075
b8c60bc9
CR
4076 ‘-v’
4077 Display Readline variable names and values in such a way that
4078 they can be used as an argument to a subsequent ‘bind’ command
4079 or in a Readline initialization file.
4080
4081 ‘-V’
4082 List current Readline variable names and values.
4083
4084 ‘-f FILENAME’
bb70624e 4085 Read key bindings from FILENAME.
ccc6cda3 4086
b8c60bc9
CR
4087 ‘-q FUNCTION’
4088 Display key sequences that invoke the named Readline FUNCTION.
ccc6cda3 4089
b8c60bc9
CR
4090 ‘-u FUNCTION’
4091 Unbind all key sequences bound to the named Readline FUNCTION.
ccc6cda3 4092
b8c60bc9 4093 ‘-r KEYSEQ’
bb70624e 4094 Remove any current binding for KEYSEQ.
ccc6cda3 4095
b8c60bc9 4096 ‘-x KEYSEQ:SHELL-COMMAND’
bb70624e 4097 Cause SHELL-COMMAND to be executed whenever KEYSEQ is entered.
b8c60bc9
CR
4098 The separator between KEYSEQ and SHELL-COMMAND is either
4099 whitespace or a colon optionally followed by whitespace. If
4100 the separator is whitespace, SHELL-COMMAND must be enclosed in
4101 double quotes and Readline expands any of its special
4102 backslash-escapes in SHELL-COMMAND before saving it. If the
4103 separator is a colon, any enclosing double quotes are
4104 optional, and Readline does not expand the command string
4105 before saving it. Since the entire key binding expression
4106 must be a single argument, it should be enclosed in single
4107 quotes. When SHELL-COMMAND is executed, the shell sets the
4108 ‘READLINE_LINE’ variable to the contents of the Readline line
4109 buffer and the ‘READLINE_POINT’ and ‘READLINE_MARK’ variables
8868edaf 4110 to the current location of the insertion point and the saved
74091dd4
CR
4111 insertion point (the MARK), respectively. The shell assigns
4112 any numeric argument the user supplied to the
b8c60bc9 4113 ‘READLINE_ARGUMENT’ variable. If there was no argument, that
74091dd4 4114 variable is not set. If the executed command changes the
b8c60bc9
CR
4115 value of any of ‘READLINE_LINE’, ‘READLINE_POINT’, or
4116 ‘READLINE_MARK’, those new values will be reflected in the
74091dd4 4117 editing state.
b80f6443 4118
b8c60bc9 4119 ‘-X’
ac50fbac 4120 List all key sequences bound to shell commands and the
b8c60bc9
CR
4121 associated commands in a format that can be reused as an
4122 argument to a subsequent ‘bind’ command.
ac50fbac 4123
bb70624e
JA
4124 The return status is zero unless an invalid option is supplied or
4125 an error occurs.
ccc6cda3 4126
b8c60bc9 4127‘builtin’
bb70624e 4128 builtin [SHELL-BUILTIN [ARGS]]
ac50fbac 4129
b8c60bc9
CR
4130 Execute the specified shell builtin SHELL-BUILTIN, passing it ARGS,
4131 and return its exit status. This is useful when defining a shell
4132 function with the same name as a shell builtin, retaining the
4133 functionality of the builtin within the function. The return
4134 status is non-zero if SHELL-BUILTIN is not a shell builtin command.
ccc6cda3 4135
b8c60bc9 4136‘caller’
b80f6443 4137 caller [EXPR]
ac50fbac 4138
a0c0a00f 4139 Returns the context of any active subroutine call (a shell function
b8c60bc9 4140 or a script executed with the ‘.’ or ‘source’ builtins).
b80f6443 4141
b8c60bc9 4142 Without EXPR, ‘caller’ displays the line number and source filename
a0c0a00f 4143 of the current subroutine call. If a non-negative integer is
b8c60bc9 4144 supplied as EXPR, ‘caller’ displays the line number, subroutine
a0c0a00f
CR
4145 name, and source file corresponding to that position in the current
4146 execution call stack. This extra information may be used, for
4147 example, to print a stack trace. The current frame is frame 0.
b80f6443
JA
4148
4149 The return value is 0 unless the shell is not executing a
4150 subroutine call or EXPR does not correspond to a valid position in
4151 the call stack.
4152
b8c60bc9 4153‘command’
bb70624e 4154 command [-pVv] COMMAND [ARGUMENTS ...]
ac50fbac 4155
b8c60bc9
CR
4156 The ‘command’ builtin runs COMMAND with ARGUMENTS ignoring any
4157 shell function named COMMAND. Only shell builtin commands or
4158 commands found by searching the ‘PATH’ are executed. If there is a
4159 shell function named ‘ls’, running ‘command ls’ within the function
4160 will execute the external command ‘ls’ instead of calling the
4161 function recursively. The ‘-p’ option means to use a default value
4162 for ‘PATH’ that is guaranteed to find all of the standard
4163 utilities. The return status in this case is 127 if COMMAND cannot
4164 be found or an error occurred, and the exit status of COMMAND
4165 otherwise.
4166
4167 If either the ‘-V’ or ‘-v’ option is supplied, ‘command’ prints a
4168 description of COMMAND. The ‘-v’ option displays a single word
4169 indicating the command or file name used to invoke COMMAND; the
4170 ‘-V’ option produces a more verbose description. In this case, the
4171 return status is zero if COMMAND is found, and non-zero if not.
4172
4173‘declare’
8868edaf 4174 declare [-aAfFgiIlnrtux] [-p] [NAME[=VALUE] ...]
ccc6cda3 4175
a0c0a00f 4176 Declare variables and give them attributes. If no NAMEs are given,
b8c60bc9 4177 then display the values of variables or shell functions instead.
ccc6cda3 4178
b8c60bc9
CR
4179 The ‘-p’ option will display the attributes and values of each
4180 NAME. When ‘-p’ is used with NAME arguments, additional options,
4181 other than ‘-f’ and ‘-F’, are ignored.
3185942a 4182
b8c60bc9 4183 When ‘-p’ is supplied without NAME arguments, ‘declare’ will
3185942a
JA
4184 display the attributes and values of all variables having the
4185 attributes specified by the additional options. If no other
b8c60bc9
CR
4186 options are supplied with ‘-p’, ‘declare’ will display the
4187 attributes and values of all shell variables. The ‘-f’ option
4188 restricts the display to shell functions.
a0c0a00f 4189
b8c60bc9
CR
4190 The ‘-F’ option inhibits the display of function definitions; only
4191 the function name and attributes are printed. If the ‘extdebug’
4192 shell option is enabled using ‘shopt’ (*note The Shopt Builtin::),
a0c0a00f 4193 the source file name and line number where each NAME is defined are
b8c60bc9 4194 displayed as well. ‘-F’ implies ‘-f’.
a0c0a00f 4195
b8c60bc9
CR
4196 The ‘-g’ option forces variables to be created or modified at the
4197 global scope, even when ‘declare’ is executed in a shell function.
4198 It is ignored in when ‘declare’ is not executed in a shell
4199 function.
495aee44 4200
b8c60bc9
CR
4201 The ‘-I’ option causes local variables to inherit the attributes
4202 (except the ‘nameref’ attribute) and value of any existing variable
8868edaf
CR
4203 with the same NAME at a surrounding scope. If there is no existing
4204 variable, the local variable is initially unset.
4205
495aee44
CR
4206 The following options can be used to restrict output to variables
4207 with the specified attributes or to give variables attributes:
ccc6cda3 4208
b8c60bc9 4209 ‘-a’
3185942a
JA
4210 Each NAME is an indexed array variable (*note Arrays::).
4211
b8c60bc9 4212 ‘-A’
3185942a 4213 Each NAME is an associative array variable (*note Arrays::).
ccc6cda3 4214
b8c60bc9
CR
4215 ‘-f’
4216 Each NAME refers to a shell function.
ccc6cda3 4217
b8c60bc9 4218 ‘-i’
bb70624e 4219 The variable is to be treated as an integer; arithmetic
28ef6c31 4220 evaluation (*note Shell Arithmetic::) is performed when the
bb70624e 4221 variable is assigned a value.
ccc6cda3 4222
b8c60bc9 4223 ‘-l’
3185942a
JA
4224 When the variable is assigned a value, all upper-case
4225 characters are converted to lower-case. The upper-case
4226 attribute is disabled.
4227
b8c60bc9
CR
4228 ‘-n’
4229 Give each NAME the ‘nameref’ attribute, making it a name
a0c0a00f
CR
4230 reference to another variable. That other variable is defined
4231 by the value of NAME. All references, assignments, and
4232 attribute modifications to NAME, except for those using or
b8c60bc9 4233 changing the ‘-n’ attribute itself, are performed on the
a0c0a00f
CR
4234 variable referenced by NAME's value. The nameref attribute
4235 cannot be applied to array variables.
4236
b8c60bc9 4237 ‘-r’
bb70624e
JA
4238 Make NAMEs readonly. These names cannot then be assigned
4239 values by subsequent assignment statements or unset.
ccc6cda3 4240
b8c60bc9
CR
4241 ‘-t’
4242 Give each NAME the ‘trace’ attribute. Traced functions
4243 inherit the ‘DEBUG’ and ‘RETURN’ traps from the calling shell.
95732b49 4244 The trace attribute has no special meaning for variables.
7117c2d2 4245
b8c60bc9 4246 ‘-u’
3185942a
JA
4247 When the variable is assigned a value, all lower-case
4248 characters are converted to upper-case. The lower-case
4249 attribute is disabled.
4250
b8c60bc9 4251 ‘-x’
bb70624e
JA
4252 Mark each NAME for export to subsequent commands via the
4253 environment.
ccc6cda3 4254
b8c60bc9
CR
4255 Using ‘+’ instead of ‘-’ turns off the specified attribute instead,
4256 with the exceptions that ‘+a’ and ‘+A’ may not be used to destroy
4257 array variables and ‘+r’ will not remove the readonly attribute.
4258
4259 When used in a function, ‘declare’ makes each NAME local, as with
4260 the ‘local’ command, unless the ‘-g’ option is supplied. If a
4261 variable name is followed by =VALUE, the value of the variable is
4262 set to VALUE.
ccc6cda3 4263
b8c60bc9 4264 When using ‘-a’ or ‘-A’ and the compound assignment syntax to
ac50fbac
CR
4265 create array variables, additional attributes do not take effect
4266 until subsequent assignments.
4267
bb70624e 4268 The return status is zero unless an invalid option is encountered,
b8c60bc9 4269 an attempt is made to define a function using ‘-f foo=bar’, an
bb70624e
JA
4270 attempt is made to assign a value to a readonly variable, an
4271 attempt is made to assign a value to an array variable without
28ef6c31 4272 using the compound assignment syntax (*note Arrays::), one of the
74091dd4 4273 NAMEs is not a valid shell variable name, an attempt is made to
bb70624e
JA
4274 turn off readonly status for a readonly variable, an attempt is
4275 made to turn off array status for an array variable, or an attempt
b8c60bc9 4276 is made to display a non-existent function with ‘-f’.
ccc6cda3 4277
b8c60bc9 4278‘echo’
bb70624e 4279 echo [-neE] [ARG ...]
ac50fbac 4280
bb70624e 4281 Output the ARGs, separated by spaces, terminated with a newline.
b8c60bc9
CR
4282 The return status is 0 unless a write error occurs. If ‘-n’ is
4283 specified, the trailing newline is not printed.
4284
4285 If the ‘-e’ option is given, ‘echo’ interprets the following
4286 backslash-escaped characters. The ‘-E’ option disables
4287 interpretation of these escape characters, even on systems where
4288 they are interpreted by default. The ‘xpg_echo’ shell option
4289 determines whether or not ‘echo’ interprets any options and expands
4290 these escape characters. ‘echo’ does not interpret ‘--’ to mean
4291 the end of options.
4292
4293 ‘echo’ interprets the following escape sequences:
4294 ‘\a’
bb70624e 4295 alert (bell)
b8c60bc9 4296 ‘\b’
bb70624e 4297 backspace
b8c60bc9 4298 ‘\c’
3185942a 4299 suppress further output
b8c60bc9
CR
4300 ‘\e’
4301 ‘\E’
bb70624e 4302 escape
b8c60bc9 4303 ‘\f’
bb70624e 4304 form feed
b8c60bc9 4305 ‘\n’
bb70624e 4306 new line
b8c60bc9 4307 ‘\r’
bb70624e 4308 carriage return
b8c60bc9 4309 ‘\t’
bb70624e 4310 horizontal tab
b8c60bc9 4311 ‘\v’
bb70624e 4312 vertical tab
b8c60bc9 4313 ‘\\’
bb70624e 4314 backslash
b8c60bc9
CR
4315 ‘\0NNN’
4316 The eight-bit character whose value is the octal value NNN
4317 (zero to three octal digits).
4318 ‘\xHH’
4319 The eight-bit character whose value is the hexadecimal value
4320 HH (one or two hex digits).
4321 ‘\uHHHH’
4322 The Unicode (ISO/IEC 10646) character whose value is the
4323 hexadecimal value HHHH (one to four hex digits).
4324 ‘\UHHHHHHHH’
4325 The Unicode (ISO/IEC 10646) character whose value is the
4326 hexadecimal value HHHHHHHH (one to eight hex digits).
4327
4328 ‘echo’ writes any unrecognized backslash-escaped characters
4329 unchanged.
4330
4331‘enable’
3185942a 4332 enable [-a] [-dnps] [-f FILENAME] [NAME ...]
ac50fbac 4333
bb70624e 4334 Enable and disable builtin shell commands. Disabling a builtin
b8c60bc9
CR
4335 allows an executable file which has the same name as a shell
4336 builtin to be executed without specifying a full pathname, even
4337 though the shell normally searches for builtins before files.
4338
4339 If ‘-n’ is supplied, the NAMEs are disabled. Otherwise NAMEs are
4340 enabled. For example, to use the ‘test’ binary found using ‘$PATH’
4341 instead of the shell builtin version, type ‘enable -n test’.
4342
4343 If the ‘-p’ option is supplied, or no NAME arguments are supplied,
4344 print a list of shell builtins. With no other arguments, the list
4345 consists of all enabled shell builtins. The ‘-n’ option means to
4346 print only disabled builtins. The ‘-a’ option means to list each
4347 builtin with an indication of whether or not it is enabled. The
4348 ‘-s’ option means to restrict ‘enable’ to the POSIX special
4349 builtins.
ccc6cda3 4350
b8c60bc9
CR
4351 The ‘-f’ option means to load the new builtin command NAME from
4352 shared object FILENAME, on systems that support dynamic loading.
4353 If FILENAME does not contain a slash. Bash will use the value of
4354 the ‘BASH_LOADABLES_PATH’ variable as a colon-separated list of
4355 directories in which to search for FILENAME. The default for
4356 ‘BASH_LOADABLES_PATH’ is system-dependent, and may include "." to
4357 force a search of the current directory. The ‘-d’ option will
4358 delete a builtin loaded with ‘-f’. If ‘-s’ is used with ‘-f’, the
4359 new builtin becomes a POSIX special builtin (*note Special
4360 Builtins::).
ccc6cda3 4361
74091dd4 4362 If no options are supplied and a NAME is not a shell builtin,
b8c60bc9
CR
4363 ‘enable’ will attempt to load NAME from a shared object named NAME,
4364 as if the command were ‘enable -f NAME NAME’.
74091dd4 4365
bb70624e
JA
4366 The return status is zero unless a NAME is not a shell builtin or
4367 there is an error loading a new builtin from a shared object.
ccc6cda3 4368
b8c60bc9 4369‘help’
3185942a 4370 help [-dms] [PATTERN]
ac50fbac 4371
bb70624e 4372 Display helpful information about builtin commands. If PATTERN is
b8c60bc9
CR
4373 specified, ‘help’ gives detailed help on all commands matching
4374 PATTERN as described below; otherwise it displays a list of all
4375 builtins and shell compound commands.
3185942a
JA
4376
4377 Options, if supplied, have the following meanings:
4378
b8c60bc9 4379 ‘-d’
3185942a 4380 Display a short description of each PATTERN
b8c60bc9 4381 ‘-m’
3185942a
JA
4382 Display the description of each PATTERN in a manpage-like
4383 format
b8c60bc9 4384 ‘-s’
3185942a
JA
4385 Display only a short usage synopsis for each PATTERN
4386
b8c60bc9
CR
4387 If PATTERN contains pattern matching characters (*note Pattern
4388 Matching::) it's treated as a shell pattern and ‘help’ prints the
4389 description of each help topic matching PATTERN.
4390
4391 If not, and PATTERN exactly matches the name of a help topic,
4392 ‘help’ prints the description associated with that topic.
4393 Otherwise, ‘help’ performs prefix matching and prints the
4394 descriptions of all matching help topics.
4395
3185942a 4396 The return status is zero unless no command matches PATTERN.
ccc6cda3 4397
b8c60bc9 4398‘let’
ac50fbac
CR
4399 let EXPRESSION [EXPRESSION ...]
4400
b8c60bc9
CR
4401 The ‘let’ builtin allows arithmetic to be performed on shell
4402 variables. Each EXPRESSION is evaluated as an arithmetic
4403 expression according to the rules given below in *note Shell
4404 Arithmetic::. If the last EXPRESSION evaluates to 0, ‘let’ returns
4405 1; otherwise ‘let’ returns 0.
ccc6cda3 4406
b8c60bc9 4407‘local’
b80f6443 4408 local [OPTION] NAME[=VALUE] ...
ac50fbac 4409
b8c60bc9
CR
4410 For each argument, create a local variable named NAME, and assign
4411 it VALUE. The OPTION can be any of the options accepted by
4412 ‘declare’. ‘local’ can only be used within a function; it makes
bb70624e 4413 the variable NAME have a visible scope restricted to that function
b8c60bc9
CR
4414 and its children. It is an error to use ‘local’ when not within a
4415 function.
4416
4417 If NAME is ‘-’, it makes the set of shell options local to the
4418 function in which ‘local’ is invoked: any shell options changed
4419 using the ‘set’ builtin inside the function after the call to
4420 ‘local’ are restored to their original values when the function
4421 returns. The restore is performed as if a series of ‘set’ commands
4422 were executed to restore the values that were in place before the
4423 function.
4424
4425 With no operands, ‘local’ writes a list of local variables to the
4426 standard output.
4427
4428 The return status is zero unless ‘local’ is used outside a
4429 function, an invalid NAME is supplied, or NAME is a readonly
4430 variable.
4431
4432‘logout’
bb70624e 4433 logout [N]
ac50fbac 4434
bb70624e 4435 Exit a login shell, returning a status of N to the shell's parent.
ccc6cda3 4436
b8c60bc9 4437‘mapfile’
d233b485
CR
4438 mapfile [-d DELIM] [-n COUNT] [-O ORIGIN] [-s COUNT]
4439 [-t] [-u FD] [-C CALLBACK] [-c QUANTUM] [ARRAY]
ac50fbac 4440
b8c60bc9
CR
4441 Read lines from the standard input, or from file descriptor FD if
4442 the ‘-u’ option is supplied, into the indexed array variable ARRAY.
4443 The variable ‘MAPFILE’ is the default ARRAY. Options, if supplied,
a0c0a00f 4444 have the following meanings:
ac50fbac 4445
b8c60bc9
CR
4446 ‘-d’
4447 Use the first character of DELIM to terminate each input line,
4448 rather than newline. If DELIM is the empty string, ‘mapfile’
4449 will terminate a line when it reads a NUL character.
4450 ‘-n’
4451 Copy at most COUNT lines. If COUNT is 0, copy all lines.
4452 ‘-O’
3185942a
JA
4453 Begin assigning to ARRAY at index ORIGIN. The default index
4454 is 0.
b8c60bc9 4455 ‘-s’
3185942a 4456 Discard the first COUNT lines read.
b8c60bc9 4457 ‘-t’
a0c0a00f 4458 Remove a trailing DELIM (default newline) from each line read.
b8c60bc9 4459 ‘-u’
3185942a
JA
4460 Read lines from file descriptor FD instead of the standard
4461 input.
b8c60bc9
CR
4462 ‘-C’
4463 Evaluate CALLBACK each time QUANTUM lines are read. The ‘-c’
a0c0a00f 4464 option specifies QUANTUM.
b8c60bc9 4465 ‘-c’
3185942a
JA
4466 Specify the number of lines read between each call to
4467 CALLBACK.
4468
b8c60bc9 4469 If ‘-C’ is specified without ‘-c’, the default quantum is 5000.
a0c0a00f 4470 When CALLBACK is evaluated, it is supplied the index of the next
495aee44
CR
4471 array element to be assigned and the line to be assigned to that
4472 element as additional arguments. CALLBACK is evaluated after the
4473 line is read but before the array element is assigned.
3185942a 4474
b8c60bc9 4475 If not supplied with an explicit origin, ‘mapfile’ will clear ARRAY
3185942a
JA
4476 before assigning to it.
4477
b8c60bc9
CR
4478 ‘mapfile’ returns zero unless an invalid option or option argument
4479 is supplied, ARRAY is invalid or unassignable, or if ARRAY is not
4480 an indexed array.
3185942a 4481
b8c60bc9 4482‘printf’
3185942a 4483 printf [-v VAR] FORMAT [ARGUMENTS]
ac50fbac 4484
bb70624e 4485 Write the formatted ARGUMENTS to the standard output under the
b8c60bc9
CR
4486 control of the FORMAT. The ‘-v’ option assigns the output to the
4487 variable VAR rather than printing it to the standard output.
495aee44
CR
4488
4489 The FORMAT is a character string which contains three types of
4490 objects: plain characters, which are simply copied to standard
4491 output, character escape sequences, which are converted and copied
4492 to the standard output, and format specifications, each of which
4493 causes printing of the next successive ARGUMENT. In addition to
b8c60bc9
CR
4494 the standard ‘printf(3)’ format characters ‘cCsSndiouxXeEfFgGaA’,
4495 ‘printf’ interprets the following additional format specifiers:
a0c0a00f 4496
b8c60bc9
CR
4497 ‘%b’
4498 Causes ‘printf’ to expand backslash escape sequences in the
4499 corresponding ARGUMENT in the same way as ‘echo -e’ (*note
a0c0a00f 4500 Bash Builtins::).
b8c60bc9
CR
4501 ‘%q’
4502 Causes ‘printf’ to output the corresponding ARGUMENT in a
4503 format that can be reused as shell input. ‘%q’ and ‘%Q’P use
4504 the ANSI-C quoting style (*note ANSI-C Quoting::) if any
4505 characters in the argument string require it, and backslash
4506 quoting otherwise. If the format string uses the ‘printf’
4507 _alternate form_, these two formats quote the argument string
4508 using single quotes.
4509
4510 ‘%Q’
4511 like ‘%q’, but applies any supplied precision to the ARGUMENT
74091dd4 4512 before quoting it.
495aee44 4513
b8c60bc9
CR
4514 ‘%(DATEFMT)T’
4515 Causes ‘printf’ to output the date-time string resulting from
4516 using DATEFMT as a format string for ‘strftime’(3). The
4517 corresponding ARGUMENT is an integer representing the number
4518 of seconds since the epoch. This format specifier recognizes
4519 Two special argument values: -1 represents the current time,
4520 and -2 represents the time the shell was invoked. If no
4521 argument is specified, conversion behaves as if -1 had been
4522 supplied. This is an exception to the usual ‘printf’
4523 behavior.
4524
4525 The %b, %q, and %T format specifiers all use the field width and
4526 precision arguments from the format specification and write that
4527 many bytes from (or use that wide a field for) the expanded
4528 argument, which usually contains more characters than the original.
4529
4530 The %n format specifier accepts a corresponding argument that is
4531 treated as a shell variable name.
4532
4533 The %s and %c format specifiers accept an l (long) modifier, which
4534 forces them to convert the argument string to a wide-character
4535 string and apply any supplied field width and precision in terms of
4536 characters, not bytes. The %S and %C format specifiers are
4537 equivalent to %ls and %lc, respectively.
8868edaf 4538
a0c0a00f
CR
4539 Arguments to non-string format specifiers are treated as C language
4540 constants, except that a leading plus or minus sign is allowed, and
4541 if the leading character is a single or double quote, the value is
b8c60bc9
CR
4542 the numeric value of the following character, using the current
4543 locale.
95732b49 4544
bb70624e
JA
4545 The FORMAT is reused as necessary to consume all of the ARGUMENTS.
4546 If the FORMAT requires more ARGUMENTS than are supplied, the extra
4547 format specifications behave as if a zero value or null string, as
4548 appropriate, had been supplied. The return value is zero on
b8c60bc9
CR
4549 success, non-zero if an invalid option is supplied or a write or
4550 assignment error occurs.
ccc6cda3 4551
b8c60bc9
CR
4552‘read’
4553 read [-Eers] [-a ANAME] [-d DELIM] [-i TEXT] [-n NCHARS]
ac50fbac
CR
4554 [-N NCHARS] [-p PROMPT] [-t TIMEOUT] [-u FD] [NAME ...]
4555
b8c60bc9
CR
4556 Read one line from the standard input, or from the file descriptor
4557 FD supplied as an argument to the ‘-u’ option, split it into words
4558 as described above in *note Word Splitting::, and assign the first
4559 word to the first NAME, the second word to the second NAME, and so
4560 on. If there are more words than names, the remaining words and
4561 their intervening delimiters are assigned to the last NAME. If
4562 there are fewer words read from the input stream than names, the
4563 remaining names are assigned empty values. The characters in the
4564 value of the ‘IFS’ variable are used to split the line into words
4565 using the same rules the shell uses for expansion (described above
4566 in *note Word Splitting::). The backslash character ‘\’ removes
4567 any special meaning for the next character read and is used for
4568 line continuation.
3185942a
JA
4569
4570 Options, if supplied, have the following meanings:
ccc6cda3 4571
b8c60bc9 4572 ‘-a ANAME’
bb70624e
JA
4573 The words are assigned to sequential indices of the array
4574 variable ANAME, starting at 0. All elements are removed from
4575 ANAME before the assignment. Other NAME arguments are
4576 ignored.
ccc6cda3 4577
b8c60bc9
CR
4578 ‘-d DELIM’
4579 The first character of DELIM terminates the input line, rather
4580 than newline. If DELIM is the empty string, ‘read’ will
4581 terminate a line when it reads a NUL character.
4582
4583 ‘-e’
4584 If the standard input is coming from a terminal, ‘read’ uses
4585 Readline (*note Command Line Editing::) to obtain the line.
4586 Readline uses the current (or default, if line editing was not
4587 previously active) editing settings, but uses Readline's
4588 default filename completion.
4589
4590 ‘-E’
4591 If the standard input is coming from a terminal, ‘read’ uses
4592 Readline (*note Command Line Editing::) to obtain the line.
4593 Readline uses the current (or default, if line editing was not
4594 previously active) editing settings, but uses Bash's default
4595 completion, including programmable completion.
4596
4597 ‘-i TEXT’
4598 If Readline is being used to read the line, ‘read’ places TEXT
3185942a 4599 into the editing buffer before editing begins.
ccc6cda3 4600
b8c60bc9
CR
4601 ‘-n NCHARS’
4602 ‘read’ returns after reading NCHARS characters rather than
4603 waiting for a complete line of input, unless it encounters EOF
4604 or ‘read’ times out, but honors a delimiter if it reads fewer
4605 than NCHARS characters before the delimiter.
4606
4607 ‘-N NCHARS’
4608 ‘read’ returns after reading exactly NCHARS characters rather
4609 than waiting for a complete line of input, unless it
4610 encounters EOF or ‘read’ times out. Delimiter characters in
4611 the input are not treated specially and do not cause ‘read’ to
4612 return until it has read NCHARS characters. The result is not
4613 split on the characters in ‘IFS’; the intent is that the
4614 variable is assigned exactly the characters read (with the
4615 exception of backslash; see the ‘-r’ option below).
4616
4617 ‘-p PROMPT’
bb70624e 4618 Display PROMPT, without a trailing newline, before attempting
b8c60bc9
CR
4619 to read any input, but only if input is coming from a
4620 terminal.
ccc6cda3 4621
b8c60bc9 4622 ‘-r’
bb70624e
JA
4623 If this option is given, backslash does not act as an escape
4624 character. The backslash is considered to be part of the
d233b485
CR
4625 line. In particular, a backslash-newline pair may not then be
4626 used as a line continuation.
ccc6cda3 4627
b8c60bc9 4628 ‘-s’
bb70624e
JA
4629 Silent mode. If input is coming from a terminal, characters
4630 are not echoed.
cce855bc 4631
b8c60bc9
CR
4632 ‘-t TIMEOUT’
4633 Cause ‘read’ to time out and return failure if it does not
4634 read a complete line of input (or a specified number of
4635 characters) within TIMEOUT seconds. TIMEOUT may be a decimal
4636 number with a fractional portion following the decimal point.
4637 This option is only effective if ‘read’ is reading input from
4638 a terminal, pipe, or other special file; it has no effect when
4639 reading from regular files. If ‘read’ times out, it saves any
4640 partial input read into the specified variable NAME, and
4641 returns a status greater than 128. If TIMEOUT is 0, ‘read’
4642 returns immediately, without trying to read any data. In this
4643 case, the exit status is 0 if input is available on the
4644 specified file descriptor, or the read will return EOF,
4645 non-zero otherwise.
4646
4647 ‘-u FD’
4648 Read input from file descriptor FD instead of the standard
4649 input.
4650
4651 Other than the case where DELIM is the empty string, ‘read’ ignores
4652 any NUL characters in the input.
4653
4654 If no NAMEs are supplied, ‘read’ assigns the line read, without the
4655 ending delimiter but otherwise unmodified, to the variable ‘REPLY’.
4656
4657 The exit status is zero, unless end-of-file is encountered, ‘read’
4658 times out (in which case the status is greater than 128), a
4659 variable assignment error (such as assigning to a readonly
4660 variable) occurs, or an invalid file descriptor is supplied as the
4661 argument to ‘-u’.
4662
4663‘readarray’
d233b485
CR
4664 readarray [-d DELIM] [-n COUNT] [-O ORIGIN] [-s COUNT]
4665 [-t] [-u FD] [-C CALLBACK] [-c QUANTUM] [ARRAY]
ac50fbac 4666
0001803f 4667 Read lines from the standard input into the indexed array variable
b8c60bc9 4668 ARRAY, or from file descriptor FD if the ‘-u’ option is supplied.
17345e5a 4669
b8c60bc9 4670 A synonym for ‘mapfile’.
17345e5a 4671
b8c60bc9
CR
4672‘source’
4673 source [-p PATH] FILENAME [ARGUMENTS]
ac50fbac 4674
b8c60bc9 4675 A synonym for ‘.’ (*note Bourne Shell Builtins::).
cce855bc 4676
b8c60bc9 4677‘type’
3185942a 4678 type [-afptP] [NAME ...]
ac50fbac 4679
b8c60bc9
CR
4680 Indicate how each NAME would be interpreted if used as a command
4681 name.
ccc6cda3 4682
b8c60bc9
CR
4683 If the ‘-t’ option is used, ‘type’ prints a single word which is
4684 one of ‘alias’, ‘keyword’, ‘function’, ‘builtin’, or ‘file’, if
4685 NAME is an alias, shell reserved word, shell function, shell
4686 builtin, or executable file, respectively. If the NAME is not
4687 found, ‘type’ prints nothing and returns a failure status.
ccc6cda3 4688
b8c60bc9
CR
4689 If the ‘-p’ option is used, ‘type’ either returns the name of the
4690 executable file that would be found by searching ‘$PATH’ for
4691 ‘name’, or nothing if ‘-t’ would not return ‘file’.
ccc6cda3 4692
b8c60bc9
CR
4693 The ‘-P’ option forces a path search for each NAME, even if ‘-t’
4694 would not return ‘file’.
ccc6cda3 4695
b8c60bc9
CR
4696 If a NAME is present in the table of hashed commands, options ‘-p’
4697 and ‘-P’ print the hashed value, which is not necessarily the file
4698 that appears first in ‘$PATH’.
ccc6cda3 4699
b8c60bc9
CR
4700 If the ‘-a’ option is used, ‘type’ returns all of the places that
4701 contain a command named NAME. This includes aliases, reserved
4702 words, functions, and builtins, but the path search options (‘-p’
4703 and ‘-P’) can be supplied to restrict the output to executable
4704 files. If ‘-a’ is supplied with ‘-p’, ‘type’ does not look in the
4705 table of hashed commands, and only performs a ‘PATH’ search for
4706 NAME.
ccc6cda3 4707
b8c60bc9
CR
4708 If the ‘-f’ option is used, ‘type’ does not attempt to find shell
4709 functions, as with the ‘command’ builtin.
ccc6cda3 4710
74091dd4 4711 The return status is zero if all of the NAMEs are found, non-zero
3185942a 4712 if any are not found.
ccc6cda3 4713
b8c60bc9 4714‘typeset’
ac50fbac
CR
4715 typeset [-afFgrxilnrtux] [-p] [NAME[=VALUE] ...]
4716
b8c60bc9
CR
4717 The ‘typeset’ command is supplied for compatibility with the Korn
4718 shell. It is a synonym for the ‘declare’ builtin command.
ccc6cda3 4719
b8c60bc9 4720‘ulimit’
8868edaf
CR
4721 ulimit [-HS] -a
4722 ulimit [-HS] [-bcdefiklmnpqrstuvxPRT] [LIMIT]
ac50fbac 4723
b8c60bc9
CR
4724 ‘ulimit’ provides control over the resources available to the shell
4725 and to processes it starts, on systems that allow such control. If
4726 an option is given, it is interpreted as follows:
ac50fbac 4727
b8c60bc9 4728 ‘-S’
3185942a 4729 Change and report the soft limit associated with a resource.
ccc6cda3 4730
b8c60bc9 4731 ‘-H’
3185942a 4732 Change and report the hard limit associated with a resource.
ccc6cda3 4733
b8c60bc9
CR
4734 ‘-a’
4735 Report all current limits; no limits are set.
cce855bc 4736
b8c60bc9 4737 ‘-b’
3185942a 4738 The maximum socket buffer size.
cce855bc 4739
b8c60bc9 4740 ‘-c’
3185942a 4741 The maximum size of core files created.
ccc6cda3 4742
b8c60bc9 4743 ‘-d’
3185942a 4744 The maximum size of a process's data segment.
ccc6cda3 4745
b8c60bc9 4746 ‘-e’
3185942a 4747 The maximum scheduling priority ("nice").
b80f6443 4748
b8c60bc9 4749 ‘-f’
3185942a
JA
4750 The maximum size of files written by the shell and its
4751 children.
b80f6443 4752
b8c60bc9 4753 ‘-i’
3185942a 4754 The maximum number of pending signals.
b80f6443 4755
b8c60bc9 4756 ‘-k’
a0c0a00f
CR
4757 The maximum number of kqueues that may be allocated.
4758
b8c60bc9 4759 ‘-l’
3185942a 4760 The maximum size that may be locked into memory.
b80f6443 4761
b8c60bc9 4762 ‘-m’
0001803f
CR
4763 The maximum resident set size (many systems do not honor this
4764 limit).
95732b49 4765
b8c60bc9 4766 ‘-n’
0001803f
CR
4767 The maximum number of open file descriptors (most systems do
4768 not allow this value to be set).
95732b49 4769
b8c60bc9 4770 ‘-p’
3185942a 4771 The pipe buffer size.
95732b49 4772
b8c60bc9 4773 ‘-q’
3185942a 4774 The maximum number of bytes in POSIX message queues.
ccc6cda3 4775
b8c60bc9 4776 ‘-r’
3185942a 4777 The maximum real-time scheduling priority.
b80f6443 4778
b8c60bc9 4779 ‘-s’
3185942a 4780 The maximum stack size.
b80f6443 4781
b8c60bc9 4782 ‘-t’
3185942a 4783 The maximum amount of cpu time in seconds.
b80f6443 4784
b8c60bc9 4785 ‘-u’
3185942a 4786 The maximum number of processes available to a single user.
b80f6443 4787
b8c60bc9 4788 ‘-v’
495aee44
CR
4789 The maximum amount of virtual memory available to the shell,
4790 and, on some systems, to its children.
ccc6cda3 4791
b8c60bc9 4792 ‘-x’
3185942a 4793 The maximum number of file locks.
ccc6cda3 4794
b8c60bc9 4795 ‘-P’
a0c0a00f
CR
4796 The maximum number of pseudoterminals.
4797
b8c60bc9 4798 ‘-R’
8868edaf
CR
4799 The maximum time a real-time process can run before blocking,
4800 in microseconds.
4801
b8c60bc9 4802 ‘-T’
3185942a 4803 The maximum number of threads.
0628567a 4804
b8c60bc9 4805 If LIMIT is supplied, and the ‘-a’ option is not used, LIMIT is the
ac50fbac 4806 new value of the specified resource. The special LIMIT values
b8c60bc9 4807 ‘hard’, ‘soft’, and ‘unlimited’ stand for the current hard limit,
ac50fbac 4808 the current soft limit, and no limit, respectively. A hard limit
a0c0a00f 4809 cannot be increased by a non-root user once it is set; a soft limit
b8c60bc9
CR
4810 may be increased up to the value of the hard limit. Otherwise,
4811 ‘ulimit’ prints the current value of the soft limit for the
4812 specified resource, unless the ‘-H’ option is supplied. When more
4813 than one resource is specified, the limit name and unit, if
4814 appropriate, are printed before the value. When setting new
4815 limits, if neither ‘-H’ nor ‘-S’ is supplied, ‘ulimit’ sets both
4816 the hard and soft limits. If no option is supplied, then ‘-f’ is
4817 assumed.
4818
4819 Values are in 1024-byte increments, except for ‘-t’, which is in
4820 seconds; ‘-R’, which is in microseconds; ‘-p’, which is in units of
4821 512-byte blocks; ‘-P’, ‘-T’, ‘-b’, ‘-k’, ‘-n’ and ‘-u’, which are
4822 unscaled values; and, when in POSIX mode (*note Bash POSIX Mode::),
4823 ‘-c’ and ‘-f’, which are in 512-byte increments.
ccc6cda3 4824
f73dda09
JA
4825 The return status is zero unless an invalid option or argument is
4826 supplied, or an error occurs while setting a new limit.
ccc6cda3 4827
b8c60bc9 4828‘unalias’
bb70624e 4829 unalias [-a] [NAME ... ]
ccc6cda3 4830
b8c60bc9
CR
4831 Remove each NAME from the list of aliases. If ‘-a’ is supplied,
4832 remove all aliases. The return value is true unless a supplied
4833 NAME is not a defined alias. Aliases are described in *note
4834 Aliases::.
ccc6cda3 4835
bb70624e 4836\1f
3185942a 4837File: bashref.info, Node: Modifying Shell Behavior, Next: Special Builtins, Prev: Bash Builtins, Up: Shell Builtin Commands
ccc6cda3 4838
3185942a
JA
48394.3 Modifying Shell Behavior
4840============================
4841
4842* Menu:
ccc6cda3 4843
3185942a
JA
4844* The Set Builtin:: Change the values of shell attributes and
4845 positional parameters.
4846* The Shopt Builtin:: Modify shell optional behavior.
4847
4848\1f
4849File: bashref.info, Node: The Set Builtin, Next: The Shopt Builtin, Up: Modifying Shell Behavior
4850
48514.3.1 The Set Builtin
4852---------------------
4853
b8c60bc9 4854This builtin is so complicated that it deserves its own section. ‘set’
3185942a
JA
4855allows you to change the values of shell options and set the positional
4856parameters, or to display the names and values of shell variables.
ccc6cda3 4857
b8c60bc9 4858‘set’
74091dd4
CR
4859 set [-abefhkmnptuvxBCEHPT] [-o OPTION-NAME] [--] [-] [ARGUMENT ...]
4860 set [+abefhkmnptuvxBCEHPT] [+o OPTION-NAME] [--] [-] [ARGUMENT ...]
b8c60bc9
CR
4861 set -o
4862 set +o
ccc6cda3 4863
b8c60bc9 4864 If no options or arguments are supplied, ‘set’ displays the names
bb70624e 4865 and values of all shell variables and functions, sorted according
95732b49
JA
4866 to the current locale, in a format that may be reused as input for
4867 setting or resetting the currently-set variables. Read-only
a0c0a00f
CR
4868 variables cannot be reset. In POSIX mode, only shell variables are
4869 listed.
ccc6cda3 4870
b8c60bc9
CR
4871 When options are supplied, they set or unset shell attributes. Any
4872 arguments remaining after option processing replace the positional
4873 parameters.
4874
bb70624e 4875 Options, if specified, have the following meanings:
ccc6cda3 4876
b8c60bc9 4877 ‘-a’
a0c0a00f
CR
4878 Each variable or function that is created or modified is given
4879 the export attribute and marked for export to the environment
4880 of subsequent commands.
ccc6cda3 4881
b8c60bc9 4882 ‘-b’
bb70624e
JA
4883 Cause the status of terminated background jobs to be reported
4884 immediately, rather than before printing the next primary
b8c60bc9
CR
4885 prompt or, under some circumstances, when a foreground command
4886 exits. This is effective only when job control is enabled.
ccc6cda3 4887
b8c60bc9 4888 ‘-e’
0001803f
CR
4889 Exit immediately if a pipeline (*note Pipelines::), which may
4890 consist of a single simple command (*note Simple Commands::),
ac50fbac
CR
4891 a list (*note Lists::), or a compound command (*note Compound
4892 Commands::) returns a non-zero status. The shell does not
4893 exit if the command that fails is part of the command list
b8c60bc9
CR
4894 immediately following a ‘while’ or ‘until’ reserved word, part
4895 of the test in an ‘if’ statement, part of any command executed
4896 in a ‘&&’ or ‘||’ list except the command following the final
4897 ‘&&’ or ‘||’, any command in a pipeline but the last (subject
4898 to the state of the ‘pipefail’ shell option), or if the
4899 command's return status is being inverted with ‘!’. If a
ac50fbac 4900 compound command other than a subshell returns a non-zero
b8c60bc9
CR
4901 status because a command failed while ‘-e’ was being ignored,
4902 the shell does not exit. A trap on ‘ERR’, if set, is executed
a0c0a00f 4903 before the shell exits.
ccc6cda3 4904
a0c0a00f
CR
4905 This option applies to the shell environment and each subshell
4906 environment separately (*note Command Execution
0001803f
CR
4907 Environment::), and may cause subshells to exit before
4908 executing all the commands in the subshell.
4909
ac50fbac 4910 If a compound command or shell function executes in a context
b8c60bc9 4911 where ‘-e’ is being ignored, none of the commands executed
ac50fbac 4912 within the compound command or function body will be affected
b8c60bc9 4913 by the ‘-e’ setting, even if ‘-e’ is set and a command returns
a0c0a00f 4914 a failure status. If a compound command or shell function
b8c60bc9 4915 sets ‘-e’ while executing in a context where ‘-e’ is ignored,
a0c0a00f
CR
4916 that setting will not have any effect until the compound
4917 command or the command containing the function call completes.
4918
b8c60bc9 4919 ‘-f’
0001803f 4920 Disable filename expansion (globbing).
ccc6cda3 4921
b8c60bc9 4922 ‘-h’
bb70624e
JA
4923 Locate and remember (hash) commands as they are looked up for
4924 execution. This option is enabled by default.
ccc6cda3 4925
b8c60bc9 4926 ‘-k’
bb70624e
JA
4927 All arguments in the form of assignment statements are placed
4928 in the environment for a command, not just those that precede
4929 the command name.
ccc6cda3 4930
b8c60bc9 4931 ‘-m’
ac50fbac
CR
4932 Job control is enabled (*note Job Control::). All processes
4933 run in a separate process group. When a background job
4934 completes, the shell prints a line containing its exit status.
b72432fd 4935
b8c60bc9 4936 ‘-n’
a0c0a00f 4937 Read commands but do not execute them. This may be used to
bb70624e
JA
4938 check a script for syntax errors. This option is ignored by
4939 interactive shells.
ccc6cda3 4940
b8c60bc9 4941 ‘-o OPTION-NAME’
a0c0a00f 4942
b8c60bc9
CR
4943 Set the option corresponding to OPTION-NAME. If ‘-o’ is
4944 supplied with no OPTION-NAME, ‘set’ prints the current shell
4945 options settings. If ‘+o’ is supplied with no OPTION-NAME,
4946 ‘set’ prints a series of ‘set’ commands to recreate the
4947 current option settings on the standard output. Valid option
4948 names are:
ccc6cda3 4949
b8c60bc9
CR
4950 ‘allexport’
4951 Same as ‘-a’.
ccc6cda3 4952
b8c60bc9
CR
4953 ‘braceexpand’
4954 Same as ‘-B’.
ccc6cda3 4955
b8c60bc9
CR
4956 ‘emacs’
4957 Use an ‘emacs’-style line editing interface (*note
3185942a 4958 Command Line Editing::). This also affects the editing
b8c60bc9 4959 interface used for ‘read -e’.
ccc6cda3 4960
b8c60bc9
CR
4961 ‘errexit’
4962 Same as ‘-e’.
d166f048 4963
b8c60bc9
CR
4964 ‘errtrace’
4965 Same as ‘-E’.
b80f6443 4966
b8c60bc9
CR
4967 ‘functrace’
4968 Same as ‘-T’.
b80f6443 4969
b8c60bc9
CR
4970 ‘hashall’
4971 Same as ‘-h’.
d166f048 4972
b8c60bc9
CR
4973 ‘histexpand’
4974 Same as ‘-H’.
ccc6cda3 4975
b8c60bc9 4976 ‘history’
3185942a 4977 Enable command history, as described in *note Bash
bb70624e
JA
4978 History Facilities::. This option is on by default in
4979 interactive shells.
ccc6cda3 4980
b8c60bc9 4981 ‘ignoreeof’
bb70624e 4982 An interactive shell will not exit upon reading EOF.
ccc6cda3 4983
b8c60bc9
CR
4984 ‘keyword’
4985 Same as ‘-k’.
ccc6cda3 4986
b8c60bc9
CR
4987 ‘monitor’
4988 Same as ‘-m’.
ccc6cda3 4989
b8c60bc9
CR
4990 ‘noclobber’
4991 Same as ‘-C’.
ccc6cda3 4992
b8c60bc9
CR
4993 ‘noexec’
4994 Same as ‘-n’.
ccc6cda3 4995
b8c60bc9
CR
4996 ‘noglob’
4997 Same as ‘-f’.
ccc6cda3 4998
b8c60bc9 4999 ‘nolog’
f73dda09
JA
5000 Currently ignored.
5001
b8c60bc9
CR
5002 ‘notify’
5003 Same as ‘-b’.
ccc6cda3 5004
b8c60bc9
CR
5005 ‘nounset’
5006 Same as ‘-u’.
ccc6cda3 5007
b8c60bc9
CR
5008 ‘onecmd’
5009 Same as ‘-t’.
ccc6cda3 5010
b8c60bc9
CR
5011 ‘physical’
5012 Same as ‘-P’.
ccc6cda3 5013
b8c60bc9 5014 ‘pipefail’
b80f6443
JA
5015 If set, the return value of a pipeline is the value of
5016 the last (rightmost) command to exit with a non-zero
5017 status, or zero if all commands in the pipeline exit
5018 successfully. This option is disabled by default.
5019
b8c60bc9
CR
5020 ‘posix’
5021 Enable POSIX mode; change the behavior of Bash where the
5022 default operation differs from the POSIX standard to
5023 match the standard (*note Bash POSIX Mode::). This is
5024 intended to make Bash behave as a strict superset of that
5025 standard.
3185942a 5026
b8c60bc9
CR
5027 ‘privileged’
5028 Same as ‘-p’.
3185942a 5029
b8c60bc9
CR
5030 ‘verbose’
5031 Same as ‘-v’.
3185942a 5032
b8c60bc9
CR
5033 ‘vi’
5034 Use a ‘vi’-style line editing interface. This also
5035 affects the editing interface used for ‘read -e’.
3185942a 5036
b8c60bc9
CR
5037 ‘xtrace’
5038 Same as ‘-x’.
3185942a 5039
b8c60bc9
CR
5040 ‘-p’
5041 Turn on privileged mode. In this mode, the ‘$BASH_ENV’ and
5042 ‘$ENV’ files are not processed, shell functions are not
5043 inherited from the environment, and the ‘SHELLOPTS’,
5044 ‘BASHOPTS’, ‘CDPATH’ and ‘GLOBIGNORE’ variables, if they
0001803f
CR
5045 appear in the environment, are ignored. If the shell is
5046 started with the effective user (group) id not equal to the
b8c60bc9 5047 real user (group) id, and the ‘-p’ option is not supplied,
0001803f 5048 these actions are taken and the effective user id is set to
b8c60bc9 5049 the real user id. If the ‘-p’ option is supplied at startup,
0001803f
CR
5050 the effective user id is not reset. Turning this option off
5051 causes the effective user and group ids to be set to the real
5052 user and group ids.
3185942a 5053
b8c60bc9
CR
5054 ‘-r’
5055 Enable restricted shell mode (*note The Restricted Shell::).
5056 This option cannot be unset once it has been set.
74091dd4 5057
b8c60bc9 5058 ‘-t’
3185942a
JA
5059 Exit after reading and executing one command.
5060
b8c60bc9 5061 ‘-u’
0001803f 5062 Treat unset variables and parameters other than the special
b8c60bc9
CR
5063 parameters ‘@’ or ‘*’, or array variables subscripted with ‘@’
5064 or ‘*’, as an error when performing parameter expansion. An
74091dd4
CR
5065 error message will be written to the standard error, and a
5066 non-interactive shell will exit.
3185942a 5067
b8c60bc9
CR
5068 ‘-v’
5069 Print shell input lines to standard error as they are read.
3185942a 5070
b8c60bc9
CR
5071 ‘-x’
5072 Print a trace of simple commands, ‘for’ commands, ‘case’
5073 commands, ‘select’ commands, and arithmetic ‘for’ commands and
5074 their arguments or associated word lists to the standard error
5075 after they are expanded and before they are executed. The
5076 shell prints the expanded value of the ‘PS4’ variable before
3185942a
JA
5077 the command and its expanded arguments.
5078
b8c60bc9 5079 ‘-B’
3185942a
JA
5080 The shell will perform brace expansion (*note Brace
5081 Expansion::). This option is on by default.
5082
b8c60bc9
CR
5083 ‘-C’
5084 Prevent output redirection using ‘>’, ‘>&’, and ‘<>’ from
5085 overwriting existing files. Using the redirection operator
5086 ‘>|’ instead of ‘>’ will override this and force the creation
5087 of an output file.
3185942a 5088
b8c60bc9
CR
5089 ‘-E’
5090 If set, any trap on ‘ERR’ is inherited by shell functions,
3185942a 5091 command substitutions, and commands executed in a subshell
b8c60bc9 5092 environment. The ‘ERR’ trap is normally not inherited in such
a0c0a00f 5093 cases.
3185942a 5094
b8c60bc9
CR
5095 ‘-H’
5096 Enable ‘!’ style history substitution (*note History
3185942a
JA
5097 Interaction::). This option is on by default for interactive
5098 shells.
5099
b8c60bc9
CR
5100 ‘-P’
5101 If set, Bash does not resolve symbolic links when executing
5102 commands such as ‘cd’ which change the current directory. It
5103 uses the physical directory structure instead. By default,
5104 Bash follows the logical chain of directories when performing
5105 commands which change the current directory.
3185942a 5106
b8c60bc9
CR
5107 For example, if ‘/usr/sys’ is a symbolic link to
5108 ‘/usr/local/sys’ then:
3185942a
JA
5109 $ cd /usr/sys; echo $PWD
5110 /usr/sys
5111 $ cd ..; pwd
5112 /usr
5113
b8c60bc9 5114 If ‘set -P’ is on, then:
3185942a
JA
5115 $ cd /usr/sys; echo $PWD
5116 /usr/local/sys
5117 $ cd ..; pwd
5118 /usr/local
5119
b8c60bc9
CR
5120 ‘-T’
5121 If set, any traps on ‘DEBUG’ and ‘RETURN’ are inherited by
3185942a 5122 shell functions, command substitutions, and commands executed
b8c60bc9 5123 in a subshell environment. The ‘DEBUG’ and ‘RETURN’ traps are
a0c0a00f 5124 normally not inherited in such cases.
3185942a 5125
b8c60bc9
CR
5126 ‘--’
5127 If no arguments follow this option, unset the positional
5128 parameters. Otherwise, the positional parameters are set to
5129 the ARGUMENTS, even if some of them begin with a ‘-’.
3185942a 5130
b8c60bc9
CR
5131 ‘-’
5132 Signal the end of options, and assign all remaining ARGUMENTS
5133 to the positional parameters. The ‘-x’ and ‘-v’ options are
5134 turned off. If there are no arguments, the positional
5135 parameters remain unchanged.
3185942a 5136
b8c60bc9 5137 Using ‘+’ rather than ‘-’ causes these options to be turned off.
3185942a 5138 The options can also be used upon invocation of the shell. The
b8c60bc9 5139 current set of options may be found in ‘$-’.
3185942a
JA
5140
5141 The remaining N ARGUMENTS are positional parameters and are
b8c60bc9
CR
5142 assigned, in order, to ‘$1’, ‘$2’, ... ‘$N’. The special parameter
5143 ‘#’ is set to N.
3185942a
JA
5144
5145 The return status is always zero unless an invalid option is
5146 supplied.
5147
5148\1f
5149File: bashref.info, Node: The Shopt Builtin, Prev: The Set Builtin, Up: Modifying Shell Behavior
5150
51514.3.2 The Shopt Builtin
5152-----------------------
5153
b8c60bc9 5154This builtin allows you to change additional optional shell behavior.
3185942a 5155
b8c60bc9 5156‘shopt’
3185942a 5157 shopt [-pqsu] [-o] [OPTNAME ...]
ac50fbac
CR
5158
5159 Toggle the values of settings controlling optional shell behavior.
b8c60bc9
CR
5160 The settings can be either those listed below, or, if the ‘-o’
5161 option is used, those available with the ‘-o’ option to the ‘set’
5162 builtin command (*note The Set Builtin::).
5163
5164 With no options, or with the ‘-p’ option, display a list of all
5165 settable options, with an indication of whether or not each is set;
5166 if any OPTNAMEs are supplied, the output is restricted to those
5167 options. The ‘-p’ option displays output in a form that may be
5168 reused as input.
5169
5170 Other options have the following meanings:
5171
5172 ‘-s’
3185942a
JA
5173 Enable (set) each OPTNAME.
5174
b8c60bc9 5175 ‘-u’
3185942a
JA
5176 Disable (unset) each OPTNAME.
5177
b8c60bc9 5178 ‘-q’
3185942a
JA
5179 Suppresses normal output; the return status indicates whether
5180 the OPTNAME is set or unset. If multiple OPTNAME arguments
b8c60bc9
CR
5181 are supplied with ‘-q’, the return status is zero if all
5182 OPTNAMEs are enabled; non-zero otherwise.
3185942a 5183
b8c60bc9 5184 ‘-o’
3185942a 5185 Restricts the values of OPTNAME to be those defined for the
b8c60bc9 5186 ‘-o’ option to the ‘set’ builtin (*note The Set Builtin::).
3185942a 5187
b8c60bc9 5188 If either ‘-s’ or ‘-u’ is used with no OPTNAME arguments, ‘shopt’
ac50fbac 5189 shows only those options which are set or unset, respectively.
3185942a 5190
b8c60bc9 5191 Unless otherwise noted, the ‘shopt’ options are disabled (off) by
3185942a
JA
5192 default.
5193
74091dd4 5194 The return status when listing options is zero if all OPTNAMEs are
3185942a
JA
5195 enabled, non-zero otherwise. When setting or unsetting options,
5196 the return status is zero unless an OPTNAME is not a valid shell
5197 option.
5198
b8c60bc9 5199 The list of ‘shopt’ options is:
a0c0a00f 5200
b8c60bc9 5201 ‘array_expand_once’
d233b485 5202 If set, the shell suppresses multiple evaluation of
b8c60bc9
CR
5203 associative and indexed array subscripts during arithmetic
5204 expression evaluation, while executing builtins that can
5205 perform variable assignments, and while executing builtins
5206 that perform array dereferencing.
d233b485 5207
b8c60bc9
CR
5208 ‘assoc_expand_once’
5209 Deprecated; a synonym for ‘array_expand_once’.
5210
5211 ‘autocd’
3185942a 5212 If set, a command name that is the name of a directory is
b8c60bc9 5213 executed as if it were the argument to the ‘cd’ command. This
a0c0a00f 5214 option is only used by interactive shells.
3185942a 5215
b8c60bc9
CR
5216 ‘bash_source_fullpath’
5217 If set, filenames added to the ‘BASH_SOURCE’ array variable
5218 are converted to full pathnames (*note Bash Variables::).
5219
5220 ‘cdable_vars’
5221 If this is set, an argument to the ‘cd’ builtin command that
3185942a
JA
5222 is not a directory is assumed to be the name of a variable
5223 whose value is the directory to change to.
5224
b8c60bc9
CR
5225 ‘cdspell’
5226 If set, the ‘cd’ command attempts to correct minor errors in
5227 the spelling of a directory component. Minor errors include
5228 transposed characters, a missing character, and one extra
5229 character. If ‘cd’ corrects the directory name, it prints the
5230 corrected filename, and the command proceeds. This option is
3185942a
JA
5231 only used by interactive shells.
5232
b8c60bc9 5233 ‘checkhash’
3185942a 5234 If this is set, Bash checks that a command found in the hash
a0c0a00f 5235 table exists before trying to execute it. If a hashed command
b8c60bc9 5236 no longer exists, Bash performs a normal path search.
3185942a 5237
b8c60bc9 5238 ‘checkjobs’
3185942a 5239 If set, Bash lists the status of any stopped and running jobs
a0c0a00f 5240 before exiting an interactive shell. If any jobs are running,
b8c60bc9
CR
5241 Bash defers the exit until a second exit is attempted without
5242 an intervening command (*note Job Control::). The shell
5243 always postpones exiting if any jobs are stopped.
3185942a 5244
b8c60bc9 5245 ‘checkwinsize’
d233b485
CR
5246 If set, Bash checks the window size after each external
5247 (non-builtin) command and, if necessary, updates the values of
b8c60bc9
CR
5248 ‘LINES’ and ‘COLUMNS’, using the file descriptor associated
5249 with stderr if it is a terminal. This option is enabled by
5250 default.
3185942a 5251
b8c60bc9 5252 ‘cmdhist’
3185942a
JA
5253 If set, Bash attempts to save all lines of a multiple-line
5254 command in the same history entry. This allows easy
d233b485
CR
5255 re-editing of multi-line commands. This option is enabled by
5256 default, but only has an effect if command history is enabled
5257 (*note Bash History Facilities::).
3185942a 5258
b8c60bc9
CR
5259 ‘compat31’
5260 ‘compat32’
5261 ‘compat40’
5262 ‘compat41’
5263 ‘compat42’
5264 ‘compat43’
5265 ‘compat44’
8868edaf
CR
5266 These control aspects of the shell's compatibility mode (*note
5267 Shell Compatibility Mode::).
d233b485 5268
b8c60bc9 5269 ‘complete_fullquote’
ac50fbac
CR
5270 If set, Bash quotes all shell metacharacters in filenames and
5271 directory names when performing completion. If not set, Bash
5272 removes metacharacters such as the dollar sign from the set of
5273 characters that will be quoted in completed filenames when
5274 these metacharacters appear in shell variable references in
5275 words to be completed. This means that dollar signs in
5276 variable names that expand to directories will not be quoted;
5277 however, any dollar signs appearing in filenames will not be
b8c60bc9 5278 quoted, either. This is active only when Bash is using
ac50fbac 5279 backslashes to quote completed filenames. This variable is
a0c0a00f
CR
5280 set by default, which is the default Bash behavior in versions
5281 through 4.2.
ac50fbac 5282
b8c60bc9 5283 ‘direxpand’
a0c0a00f
CR
5284 If set, Bash replaces directory names with the results of word
5285 expansion when performing filename completion. This changes
74091dd4 5286 the contents of the Readline editing buffer. If not set, Bash
a0c0a00f 5287 attempts to preserve what the user typed.
ac50fbac 5288
b8c60bc9 5289 ‘dirspell’
3185942a
JA
5290 If set, Bash attempts spelling correction on directory names
5291 during word completion if the directory name initially
5292 supplied does not exist.
5293
b8c60bc9
CR
5294 ‘dotglob’
5295 If set, Bash includes filenames beginning with a ‘.’ in the
5296 results of filename expansion. The filenames ‘.’ and ‘..’
5297 must always be matched explicitly, even if ‘dotglob’ is set.
3185942a 5298
b8c60bc9 5299 ‘execfail’
3185942a 5300 If this is set, a non-interactive shell will not exit if it
b8c60bc9
CR
5301 cannot execute the file specified as an argument to the ‘exec’
5302 builtin. An interactive shell does not exit if ‘exec’ fails.
3185942a 5303
b8c60bc9 5304 ‘expand_aliases’
3185942a
JA
5305 If set, aliases are expanded as described below under Aliases,
5306 *note Aliases::. This option is enabled by default for
5307 interactive shells.
5308
b8c60bc9 5309 ‘extdebug’
8868edaf
CR
5310 If set at shell invocation, or in a shell startup file,
5311 arrange to execute the debugger profile before the shell
b8c60bc9 5312 starts, identical to the ‘--debugger’ option. If set after
8868edaf 5313 invocation, behavior intended for use by debuggers is enabled:
3185942a 5314
b8c60bc9 5315 1. The ‘-F’ option to the ‘declare’ builtin (*note Bash
a0c0a00f
CR
5316 Builtins::) displays the source file name and line number
5317 corresponding to each function name supplied as an
5318 argument.
3185942a 5319
b8c60bc9 5320 2. If the command run by the ‘DEBUG’ trap returns a non-zero
a0c0a00f 5321 value, the next command is skipped and not executed.
3185942a 5322
b8c60bc9 5323 3. If the command run by the ‘DEBUG’ trap returns a value of
a0c0a00f 5324 2, and the shell is executing in a subroutine (a shell
b8c60bc9
CR
5325 function or a shell script executed by the ‘.’ or
5326 ‘source’ builtins), the shell simulates a call to
5327 ‘return’.
3185942a 5328
b8c60bc9 5329 4. ‘BASH_ARGC’ and ‘BASH_ARGV’ are updated as described in
3185942a
JA
5330 their descriptions (*note Bash Variables::).
5331
a0c0a00f 5332 5. Function tracing is enabled: command substitution, shell
b8c60bc9
CR
5333 functions, and subshells invoked with ‘( COMMAND )’
5334 inherit the ‘DEBUG’ and ‘RETURN’ traps.
3185942a 5335
a0c0a00f 5336 6. Error tracing is enabled: command substitution, shell
b8c60bc9
CR
5337 functions, and subshells invoked with ‘( COMMAND )’
5338 inherit the ‘ERR’ trap.
3185942a 5339
b8c60bc9
CR
5340 ‘extglob’
5341 If set, enable the extended pattern matching features
5342 described above (*note Pattern Matching::).
3185942a 5343
b8c60bc9
CR
5344 ‘extquote’
5345 If set, ‘$'STRING'’ and ‘$"STRING"’ quoting is performed
5346 within ‘${PARAMETER}’ expansions enclosed in double quotes.
3185942a
JA
5347 This option is enabled by default.
5348
b8c60bc9 5349 ‘failglob’
a0c0a00f
CR
5350 If set, patterns which fail to match filenames during filename
5351 expansion result in an expansion error.
3185942a 5352
b8c60bc9
CR
5353 ‘force_fignore’
5354 If set, the suffixes specified by the ‘FIGNORE’ shell variable
a0c0a00f
CR
5355 cause words to be ignored when performing word completion even
5356 if the ignored words are the only possible completions. *Note
b8c60bc9 5357 Bash Variables::, for a description of ‘FIGNORE’. This option
a0c0a00f 5358 is enabled by default.
3185942a 5359
b8c60bc9 5360 ‘globasciiranges’
ac50fbac
CR
5361 If set, range expressions used in pattern matching bracket
5362 expressions (*note Pattern Matching::) behave as if in the
5363 traditional C locale when performing comparisons. That is,
b8c60bc9
CR
5364 pattern matching does not take the current locale's collating
5365 sequence into account, so ‘b’ will not collate between ‘A’ and
5366 ‘B’, and upper-case and lower-case ASCII characters will
5367 collate together.
5368
5369 ‘globskipdots’
5370 If set, filename expansion will never match the filenames ‘.’
5371 and ‘..’, even if the pattern begins with a ‘.’. This option
74091dd4
CR
5372 is enabled by default.
5373
b8c60bc9
CR
5374 ‘globstar’
5375 If set, the pattern ‘**’ used in a filename expansion context
ac50fbac 5376 will match all files and zero or more directories and
b8c60bc9 5377 subdirectories. If the pattern is followed by a ‘/’, only
3185942a 5378 directories and subdirectories match.
ccc6cda3 5379
b8c60bc9 5380 ‘gnu_errfmt’
3185942a
JA
5381 If set, shell error messages are written in the standard GNU
5382 error message format.
ccc6cda3 5383
b8c60bc9 5384 ‘histappend’
3185942a 5385 If set, the history list is appended to the file named by the
b8c60bc9 5386 value of the ‘HISTFILE’ variable when the shell exits, rather
3185942a 5387 than overwriting the file.
cce855bc 5388
b8c60bc9
CR
5389 ‘histreedit’
5390 If set, and Readline is being used, the user is given the
3185942a 5391 opportunity to re-edit a failed history substitution.
ccc6cda3 5392
b8c60bc9 5393 ‘histverify’
3185942a
JA
5394 If set, and Readline is being used, the results of history
5395 substitution are not immediately passed to the shell parser.
5396 Instead, the resulting line is loaded into the Readline
5397 editing buffer, allowing further modification.
cce855bc 5398
b8c60bc9 5399 ‘hostcomplete’
3185942a 5400 If set, and Readline is being used, Bash will attempt to
b8c60bc9 5401 perform hostname completion when a word containing a ‘@’ is
3185942a
JA
5402 being completed (*note Commands For Completion::). This
5403 option is enabled by default.
ccc6cda3 5404
b8c60bc9
CR
5405 ‘huponexit’
5406 If set, Bash will send ‘SIGHUP’ to all jobs when an
3185942a 5407 interactive login shell exits (*note Signals::).
ccc6cda3 5408
b8c60bc9 5409 ‘inherit_errexit’
a0c0a00f 5410 If set, command substitution inherits the value of the
b8c60bc9 5411 ‘errexit’ option, instead of unsetting it in the subshell
a0c0a00f
CR
5412 environment. This option is enabled when POSIX mode is
5413 enabled.
5414
b8c60bc9
CR
5415 ‘interactive_comments’
5416 In an interactive shell, a word beginning with ‘#’ causes that
5417 word and all remaining characters on that line to be ignored,
5418 as in a non-interactive shell. This option is enabled by
5419 default.
ccc6cda3 5420
b8c60bc9 5421 ‘lastpipe’
a0c0a00f
CR
5422 If set, and job control is not active, the shell runs the last
5423 command of a pipeline not executed in the background in the
5424 current shell environment.
495aee44 5425
b8c60bc9
CR
5426 ‘lithist’
5427 If enabled, and the ‘cmdhist’ option is enabled, multi-line
3185942a
JA
5428 commands are saved to the history with embedded newlines
5429 rather than using semicolon separators where possible.
ccc6cda3 5430
b8c60bc9 5431 ‘localvar_inherit’
d233b485
CR
5432 If set, local variables inherit the value and attributes of a
5433 variable of the same name that exists at a previous scope
b8c60bc9 5434 before any new value is assigned. The ‘nameref’ attribute is
d233b485
CR
5435 not inherited.
5436
b8c60bc9
CR
5437 ‘localvar_unset’
5438 If set, calling ‘unset’ on local variables in previous
d233b485
CR
5439 function scopes marks them so subsequent lookups find them
5440 unset until that function returns. This is identical to the
5441 behavior of unsetting local variables at the current function
5442 scope.
5443
b8c60bc9 5444 ‘login_shell’
3185942a
JA
5445 The shell sets this option if it is started as a login shell
5446 (*note Invoking Bash::). The value may not be changed.
ccc6cda3 5447
b8c60bc9 5448 ‘mailwarn’
3185942a 5449 If set, and a file that Bash is checking for mail has been
b8c60bc9
CR
5450 accessed since the last time it was checked, Bash displays the
5451 message ‘"The mail in MAILFILE has been read"’.
ccc6cda3 5452
b8c60bc9
CR
5453 ‘no_empty_cmd_completion’
5454 If set, and Readline is being used, Bash does not search the
5455 ‘PATH’ for possible completions when completion is attempted
5456 on an empty line.
ccc6cda3 5457
b8c60bc9 5458 ‘nocaseglob’
3185942a
JA
5459 If set, Bash matches filenames in a case-insensitive fashion
5460 when performing filename expansion.
b80f6443 5461
b8c60bc9 5462 ‘nocasematch’
3185942a 5463 If set, Bash matches patterns in a case-insensitive fashion
b8c60bc9 5464 when performing matching while executing ‘case’ or ‘[[’
74091dd4
CR
5465 conditional commands (*note Conditional Constructs::, when
5466 performing pattern substitution word expansions, or when
5467 filtering possible completions as part of programmable
5468 completion.
5469
b8c60bc9
CR
5470 ‘noexpand_translation’
5471 If set, Bash encloses the translated results of $"..." quoting
5472 in single quotes instead of double quotes. If the string is
5473 not translated, this has no effect.
ccc6cda3 5474
b8c60bc9
CR
5475 ‘nullglob’
5476 If set, filename expansion patterns which match no files
5477 (*note Filename Expansion::) expand to nothing and are
5478 removed, rather than expanding to themselves.
ccc6cda3 5479
b8c60bc9
CR
5480 ‘patsub_replacement’
5481 If set, Bash expands occurrences of ‘&’ in the replacement
74091dd4
CR
5482 string of pattern substitution to the text matched by the
5483 pattern, as described above (*note Shell Parameter
5484 Expansion::). This option is enabled by default.
5485
b8c60bc9
CR
5486 ‘progcomp’
5487 If set, enable the programmable completion facilities (*note
5488 Programmable Completion::). This option is enabled by
5489 default.
ccc6cda3 5490
b8c60bc9 5491 ‘progcomp_alias’
d233b485
CR
5492 If set, and programmable completion is enabled, Bash treats a
5493 command name that doesn't have any completions as a possible
5494 alias and attempts alias expansion. If it has an alias, Bash
5495 attempts programmable completion using the command word
5496 resulting from the expanded alias.
5497
b8c60bc9 5498 ‘promptvars’
3185942a
JA
5499 If set, prompt strings undergo parameter expansion, command
5500 substitution, arithmetic expansion, and quote removal after
ac50fbac
CR
5501 being expanded as described below (*note Controlling the
5502 Prompt::). This option is enabled by default.
ccc6cda3 5503
b8c60bc9 5504 ‘restricted_shell’
3185942a
JA
5505 The shell sets this option if it is started in restricted mode
5506 (*note The Restricted Shell::). The value may not be changed.
5507 This is not reset when the startup files are executed,
5508 allowing the startup files to discover whether or not a shell
5509 is restricted.
b80f6443 5510
b8c60bc9
CR
5511 ‘shift_verbose’
5512 If this is set, the ‘shift’ builtin prints an error message
3185942a
JA
5513 when the shift count exceeds the number of positional
5514 parameters.
ccc6cda3 5515
b8c60bc9
CR
5516 ‘sourcepath’
5517 If set, the ‘.’ (‘source’) builtin uses the value of ‘PATH’ to
5518 find the directory containing the file supplied as an argument
5519 when the ‘-p’ option is not supplied. This option is enabled
5520 by default.
74091dd4 5521
b8c60bc9 5522 ‘varredir_close’
74091dd4 5523 If set, the shell automatically closes file descriptors
b8c60bc9 5524 assigned using the ‘{varname}’ redirection syntax (*note
74091dd4
CR
5525 Redirections::) instead of leaving them open when the command
5526 completes.
ccc6cda3 5527
b8c60bc9
CR
5528 ‘xpg_echo’
5529 If set, the ‘echo’ builtin expands backslash-escape sequences
5530 by default. If the ‘posix’ shell option (*note The Set
5531 Builtin::) is also enabled, ‘echo’ does not interpret any
5532 options.
cce855bc 5533
bb70624e 5534\1f
3185942a 5535File: bashref.info, Node: Special Builtins, Prev: Modifying Shell Behavior, Up: Shell Builtin Commands
ccc6cda3 5536
b80f6443
JA
55374.4 Special Builtins
5538====================
ccc6cda3 5539
0628567a
JA
5540For historical reasons, the POSIX standard has classified several
5541builtin commands as _special_. When Bash is executing in POSIX mode,
5542the special builtins differ from other builtin commands in three
bb70624e 5543respects:
ccc6cda3 5544
bb70624e
JA
5545 1. Special builtins are found before shell functions during command
5546 lookup.
ccc6cda3 5547
bb70624e
JA
5548 2. If a special builtin returns an error status, a non-interactive
5549 shell exits.
ccc6cda3 5550
bb70624e
JA
5551 3. Assignment statements preceding the command stay in effect in the
5552 shell environment after the command completes.
ccc6cda3 5553
bb70624e
JA
5554 When Bash is not executing in POSIX mode, these builtins behave no
5555differently than the rest of the Bash builtin commands. The Bash POSIX
3185942a 5556mode is described in *note Bash POSIX Mode::.
ccc6cda3 5557
bb70624e 5558 These are the POSIX special builtins:
b8c60bc9
CR
5559 break : . source continue eval exec exit export readonly return set
5560 shift times trap unset
ccc6cda3 5561
bb70624e
JA
5562\1f
5563File: bashref.info, Node: Shell Variables, Next: Bash Features, Prev: Shell Builtin Commands, Up: Top
cce855bc 5564
b80f6443
JA
55655 Shell Variables
5566*****************
ccc6cda3 5567
bb70624e 5568* Menu:
ccc6cda3 5569
bb70624e
JA
5570* Bourne Shell Variables:: Variables which Bash uses in the same way
5571 as the Bourne Shell.
5572* Bash Variables:: List of variables that exist in Bash.
ccc6cda3 5573
a0c0a00f 5574This chapter describes the shell variables that Bash uses. Bash
bb70624e 5575automatically assigns default values to a number of variables.
cce855bc 5576
bb70624e
JA
5577\1f
5578File: bashref.info, Node: Bourne Shell Variables, Next: Bash Variables, Up: Shell Variables
ccc6cda3 5579
b80f6443
JA
55805.1 Bourne Shell Variables
5581==========================
cce855bc 5582
b80f6443
JA
5583Bash uses certain shell variables in the same way as the Bourne shell.
5584In some cases, Bash assigns a default value to the variable.
cce855bc 5585
b8c60bc9 5586‘CDPATH’
a0c0a00f 5587 A colon-separated list of directories used as a search path for the
b8c60bc9 5588 ‘cd’ builtin command.
ccc6cda3 5589
b8c60bc9
CR
5590‘HOME’
5591 The current user's home directory; the default for the ‘cd’ builtin
bb70624e 5592 command. The value of this variable is also used by tilde
28ef6c31 5593 expansion (*note Tilde Expansion::).
ccc6cda3 5594
b8c60bc9 5595‘IFS’
bb70624e 5596 A list of characters that separate fields; used when the shell
b8c60bc9
CR
5597 splits words as part of expansion and by the ‘read’ builtin to
5598 split lines into words. *Note Word Splitting::, for a description
5599 of word splitting.
ccc6cda3 5600
b8c60bc9
CR
5601‘MAIL’
5602 If the value is set to a filename or directory name and the
5603 ‘MAILPATH’ variable is not set, Bash informs the user of the
495aee44 5604 arrival of mail in the specified file or Maildir-format directory.
cce855bc 5605
b8c60bc9 5606‘MAILPATH’
bb70624e
JA
5607 A colon-separated list of filenames which the shell periodically
5608 checks for new mail. Each list entry can specify the message that
a0c0a00f 5609 is printed when new mail arrives in the mail file by separating the
b8c60bc9
CR
5610 filename from the message with a ‘?’. When used in the text of the
5611 message, ‘$_’ expands to the name of the current mail file.
cce855bc 5612
b8c60bc9
CR
5613‘OPTARG’
5614 The value of the last option argument processed by the ‘getopts’
bb70624e 5615 builtin.
ccc6cda3 5616
b8c60bc9
CR
5617‘OPTIND’
5618 The index of the next argument to be processed by the ‘getopts’
bb70624e 5619 builtin.
ccc6cda3 5620
b8c60bc9 5621‘PATH’
bb70624e 5622 A colon-separated list of directories in which the shell looks for
b80f6443 5623 commands. A zero-length (null) directory name in the value of
b8c60bc9 5624 ‘PATH’ indicates the current directory. A null directory name may
b80f6443 5625 appear as two adjacent colons, or as an initial or trailing colon.
b8c60bc9
CR
5626 The default path is system-dependent, and is set by the
5627 administrator who installs ‘bash’. A common value is
5628 "/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin".
ccc6cda3 5629
b8c60bc9
CR
5630‘PS1’
5631 The primary prompt string. The default value is ‘\s-\v\$ ’. *Note
a0c0a00f 5632 Controlling the Prompt::, for the complete list of escape sequences
b8c60bc9 5633 that are expanded before ‘PS1’ is displayed.
ccc6cda3 5634
b8c60bc9
CR
5635‘PS2’
5636 The secondary prompt string. The default value is ‘> ’. ‘PS2’ is
5637 expanded in the same way as ‘PS1’ before being displayed.
b80f6443 5638
bb70624e
JA
5639\1f
5640File: bashref.info, Node: Bash Variables, Prev: Bourne Shell Variables, Up: Shell Variables
ccc6cda3 5641
b80f6443
JA
56425.2 Bash Variables
5643==================
ccc6cda3 5644
b80f6443 5645These variables are set or used by Bash, but other shells do not
bb70624e 5646normally treat them specially.
ccc6cda3 5647
bb70624e
JA
5648 A few variables used by Bash are described in different chapters:
5649variables for controlling the job control facilities (*note Job Control
28ef6c31 5650Variables::).
ccc6cda3 5651
b8c60bc9
CR
5652‘_’
5653 ($_, an underscore.) This has a number of meanings depending on
5654 context. At shell startup, $_ set to the pathname used to invoke
5655 the shell or shell script being executed as passed in the
5656 environment or argument list. Subsequently, it expands to the last
8868edaf 5657 argument to the previous simple command executed in the foreground,
b8c60bc9
CR
5658 after expansion. It is also set to the full pathname used to
5659 invoke each command executed and placed in the environment exported
5660 to that command. When checking mail, $_ expands to the name of the
8868edaf
CR
5661 mail file.
5662
b8c60bc9 5663‘BASH’
bb70624e 5664 The full pathname used to execute the current instance of Bash.
ccc6cda3 5665
b8c60bc9 5666‘BASHOPTS’
0001803f 5667 A colon-separated list of enabled shell options. Each word in the
b8c60bc9 5668 list is a valid argument for the ‘-s’ option to the ‘shopt’ builtin
a0c0a00f 5669 command (*note The Shopt Builtin::). The options appearing in
b8c60bc9
CR
5670 ‘BASHOPTS’ are those reported as ‘on’ by ‘shopt’. If this variable
5671 is in the environment when Bash starts up, the shell enables each
5672 option in the list before reading any startup files. If this
5673 variable is exported, child shells will enable each option in the
5674 list. This variable is readonly.
a0c0a00f 5675
b8c60bc9 5676‘BASHPID’
495aee44 5677 Expands to the process ID of the current Bash process. This
b8c60bc9 5678 differs from ‘$$’ under certain circumstances, such as subshells
d233b485 5679 that do not require Bash to be re-initialized. Assignments to
b8c60bc9 5680 ‘BASHPID’ have no effect. If ‘BASHPID’ is unset, it loses its
d233b485 5681 special properties, even if it is subsequently reset.
3185942a 5682
b8c60bc9 5683‘BASH_ALIASES’
3185942a 5684 An associative array variable whose members correspond to the
b8c60bc9 5685 internal list of aliases as maintained by the ‘alias’ builtin.
3185942a 5686 (*note Bourne Shell Builtins::). Elements added to this array
a0c0a00f
CR
5687 appear in the alias list; however, unsetting array elements
5688 currently does not cause aliases to be removed from the alias list.
b8c60bc9 5689 If ‘BASH_ALIASES’ is unset, it loses its special properties, even
a0c0a00f 5690 if it is subsequently reset.
3185942a 5691
b8c60bc9 5692‘BASH_ARGC’
b80f6443 5693 An array variable whose values are the number of parameters in each
b8c60bc9 5694 frame of the current Bash execution call stack. The number of
b80f6443 5695 parameters to the current subroutine (shell function or script
b8c60bc9 5696 executed with ‘.’ or ‘source’) is at the top of the stack. When a
b80f6443 5697 subroutine is executed, the number of parameters passed is pushed
b8c60bc9 5698 onto ‘BASH_ARGC’. The shell sets ‘BASH_ARGC’ only when in extended
a0c0a00f 5699 debugging mode (see *note The Shopt Builtin:: for a description of
b8c60bc9
CR
5700 the ‘extdebug’ option to the ‘shopt’ builtin). Setting ‘extdebug’
5701 after the shell has started to execute a subroutine, or referencing
5702 this variable when ‘extdebug’ is not set, may result in
5703 inconsistent values. Assignments to ‘BASH_ARGC’ have no effect,
5704 and it may not be unset.
b80f6443 5705
b8c60bc9 5706‘BASH_ARGV’
b80f6443 5707 An array variable containing all of the parameters in the current
b8c60bc9 5708 Bash execution call stack. The final parameter of the last
b80f6443
JA
5709 subroutine call is at the top of the stack; the first parameter of
5710 the initial call is at the bottom. When a subroutine is executed,
b8c60bc9
CR
5711 the shell pushes the supplied parameters onto ‘BASH_ARGV’. The
5712 shell sets ‘BASH_ARGV’ only when in extended debugging mode (see
5713 *note The Shopt Builtin:: for a description of the ‘extdebug’
5714 option to the ‘shopt’ builtin). Setting ‘extdebug’ after the shell
5715 has started to execute a script, or referencing this variable when
5716 ‘extdebug’ is not set, may result in inconsistent values.
5717 Assignments to ‘BASH_ARGV’ have no effect, and it may not be unset.
5718
5719‘BASH_ARGV0’
d233b485 5720 When referenced, this variable expands to the name of the shell or
b8c60bc9
CR
5721 shell script (identical to ‘$0’; *Note Special Parameters::, for
5722 the description of special parameter 0). Assigning a value to
5723 ‘BASH_ARGV0’ sets ‘$0’ to the same value. If ‘BASH_ARGV0’ is
5724 unset, it loses its special properties, even if it is subsequently
5725 reset.
3185942a 5726
b8c60bc9 5727‘BASH_CMDS’
3185942a 5728 An associative array variable whose members correspond to the
b8c60bc9
CR
5729 internal hash table of commands as maintained by the ‘hash’ builtin
5730 (*note Bourne Shell Builtins::). Adding elements to this array
5731 makes them appear in the hash table; however, unsetting array
5732 elements currently does not remove command names from the hash
5733 table. If ‘BASH_CMDS’ is unset, it loses its special properties,
a0c0a00f 5734 even if it is subsequently reset.
b80f6443 5735
b8c60bc9
CR
5736‘BASH_COMMAND’
5737 Expands to the command currently being executed or about to be
5738 executed, unless the shell is executing a command as the result of
5739 a trap, in which case it is the command executing at the time of
5740 the trap. If ‘BASH_COMMAND’ is unset, it loses its special
5741 properties, even if it is subsequently reset.
b80f6443 5742
b8c60bc9 5743‘BASH_COMPAT’
ac50fbac 5744 The value is used to set the shell's compatibility level. *Note
8868edaf
CR
5745 Shell Compatibility Mode::, for a description of the various
5746 compatibility levels and their effects. The value may be a decimal
5747 number (e.g., 4.2) or an integer (e.g., 42) corresponding to the
b8c60bc9 5748 desired compatibility level. If ‘BASH_COMPAT’ is unset or set to
8868edaf 5749 the empty string, the compatibility level is set to the default for
b8c60bc9 5750 the current version. If ‘BASH_COMPAT’ is set to a value that is
8868edaf
CR
5751 not one of the valid compatibility levels, the shell prints an
5752 error message and sets the compatibility level to the default for
b8c60bc9
CR
5753 the current version. A subset of the valid values correspond to
5754 the compatibility levels described below (*note Shell Compatibility
8868edaf 5755 Mode::). For example, 4.2 and 42 are valid values that correspond
b8c60bc9 5756 to the ‘compat42’ ‘shopt’ option and set the compatibility level to
8868edaf 5757 42. The current version is also a valid value.
a0c0a00f 5758
b8c60bc9 5759‘BASH_ENV’
bb70624e
JA
5760 If this variable is set when Bash is invoked to execute a shell
5761 script, its value is expanded and used as the name of a startup
b8c60bc9
CR
5762 file to read before executing the script. Bash does not use ‘PATH’
5763 to search for the resultant filename. *Note Bash Startup Files::.
ccc6cda3 5764
b8c60bc9
CR
5765‘BASH_EXECUTION_STRING’
5766 The command argument to the ‘-c’ invocation option.
b80f6443 5767
b8c60bc9 5768‘BASH_LINENO’
b80f6443 5769 An array variable whose members are the line numbers in source
b8c60bc9
CR
5770 files where each corresponding member of ‘FUNCNAME’ was invoked.
5771 ‘${BASH_LINENO[$i]}’ is the line number in the source file
5772 (‘${BASH_SOURCE[$i+1]}’) where ‘${FUNCNAME[$i]}’ was called (or
5773 ‘${BASH_LINENO[$i-1]}’ if referenced within another shell
5774 function). Use ‘LINENO’ to obtain the current line number.
5775 Assignments to ‘BASH_LINENO’ have no effect, and it may not be
5776 unset.
a0c0a00f 5777
b8c60bc9
CR
5778‘BASH_LOADABLES_PATH’
5779 A colon-separated list of directories in which the ‘enable’ command
5780 looks for dynamically loadable builtins.
5781
5782‘BASH_MONOSECONDS’
5783 Each time this variable is referenced, it expands to the value
5784 returned by the system's monotonic clock, if one is available. If
5785 there is no monotonic clock, this is equivalent to ‘EPOCHSECONDS’.
5786 If ‘BASH_MONOSECONDS’ is unset, it loses its special properties,
5787 even if it is subsequently reset.
a0c0a00f 5788
b8c60bc9
CR
5789‘BASH_REMATCH’
5790 An array variable whose members are assigned by the ‘=~’ binary
5791 operator to the ‘[[’ conditional command (*note Conditional
b80f6443
JA
5792 Constructs::). The element with index 0 is the portion of the
5793 string matching the entire regular expression. The element with
a0c0a00f 5794 index N is the portion of the string matching the Nth parenthesized
8868edaf 5795 subexpression.
b80f6443 5796
b8c60bc9 5797‘BASH_SOURCE’
495aee44 5798 An array variable whose members are the source filenames where the
b8c60bc9
CR
5799 corresponding shell function names in the ‘FUNCNAME’ array variable
5800 are defined. The shell function ‘${FUNCNAME[$i]}’ is defined in
5801 the file ‘${BASH_SOURCE[$i]}’ and called from
5802 ‘${BASH_SOURCE[$i+1]}’ Assignments to ‘BASH_SOURCE’ have no effect,
5803 and it may not be unset.
b80f6443 5804
b8c60bc9 5805‘BASH_SUBSHELL’
ac50fbac
CR
5806 Incremented by one within each subshell or subshell environment
5807 when the shell begins executing in that environment. The initial
b8c60bc9 5808 value is 0. If ‘BASH_SUBSHELL’ is unset, it loses its special
8868edaf 5809 properties, even if it is subsequently reset.
ccc6cda3 5810
b8c60bc9
CR
5811‘BASH_TRAPSIG’
5812 Set to the signal number corresponding to the trap action being
5813 executed during its execution. See the description of ‘trap’
5814 (*note Bourne Shell Builtins::) for information about signal
5815 numbers and trap execution.
5816
5817‘BASH_VERSINFO’
28ef6c31 5818 A readonly array variable (*note Arrays::) whose members hold
a0c0a00f
CR
5819 version information for this instance of Bash. The values assigned
5820 to the array members are as follows:
ccc6cda3 5821
b8c60bc9
CR
5822 ‘BASH_VERSINFO[0]’
5823 The major version number (the “release”).
ccc6cda3 5824
b8c60bc9
CR
5825 ‘BASH_VERSINFO[1]’
5826 The minor version number (the “version”).
ccc6cda3 5827
b8c60bc9 5828 ‘BASH_VERSINFO[2]’
bb70624e 5829 The patch level.
ccc6cda3 5830
b8c60bc9 5831 ‘BASH_VERSINFO[3]’
bb70624e 5832 The build version.
ccc6cda3 5833
b8c60bc9
CR
5834 ‘BASH_VERSINFO[4]’
5835 The release status (e.g., ‘beta’).
ccc6cda3 5836
b8c60bc9
CR
5837 ‘BASH_VERSINFO[5]’
5838 The value of ‘MACHTYPE’.
ccc6cda3 5839
b8c60bc9
CR
5840‘BASH_VERSION’
5841 Expands to a string describing the version of this instance of Bash
5842 (e.g., 5.2.37(3)-release).
b80f6443 5843
b8c60bc9 5844‘BASH_XTRACEFD’
0001803f 5845 If set to an integer corresponding to a valid file descriptor, Bash
b8c60bc9
CR
5846 writes the trace output generated when ‘set -x’ is enabled to that
5847 file descriptor, instead of the standard error. This allows
5848 tracing output to be separated from diagnostic and error messages.
5849 The file descriptor is closed when ‘BASH_XTRACEFD’ is unset or
5850 assigned a new value. Unsetting ‘BASH_XTRACEFD’ or assigning it
5851 the empty string causes the trace output to be sent to the standard
5852 error. Note that setting ‘BASH_XTRACEFD’ to 2 (the standard error
5853 file descriptor) and then unsetting it will result in the standard
5854 error being closed.
5855
5856‘CHILD_MAX’
ac50fbac
CR
5857 Set the number of exited child status values for the shell to
5858 remember. Bash will not allow this value to be decreased below a
5859 POSIX-mandated minimum, and there is a maximum value (currently
5860 8192) that this may not exceed. The minimum value is
5861 system-dependent.
5862
b8c60bc9
CR
5863‘COLUMNS’
5864 Used by the ‘select’ command to determine the terminal width when
5865 printing selection lists. Automatically set if the ‘checkwinsize’
a0c0a00f 5866 option is enabled (*note The Shopt Builtin::), or in an interactive
b8c60bc9 5867 shell upon receipt of a ‘SIGWINCH’.
bb70624e 5868
b8c60bc9
CR
5869‘COMP_CWORD’
5870 An index into ‘${COMP_WORDS}’ of the word containing the current
bb70624e
JA
5871 cursor position. This variable is available only in shell
5872 functions invoked by the programmable completion facilities (*note
28ef6c31 5873 Programmable Completion::).
bb70624e 5874
b8c60bc9
CR
5875‘COMP_KEY’
5876 The key (or final key of a key sequence) used to invoke the current
5877 completion function. This variable is available only in shell
5878 functions and external commands invoked by the programmable
5879 completion facilities (*note Programmable Completion::).
5880
5881‘COMP_LINE’
a0c0a00f
CR
5882 The current command line. This variable is available only in shell
5883 functions and external commands invoked by the programmable
28ef6c31 5884 completion facilities (*note Programmable Completion::).
bb70624e 5885
b8c60bc9 5886‘COMP_POINT’
bb70624e
JA
5887 The index of the current cursor position relative to the beginning
5888 of the current command. If the current cursor position is at the
5889 end of the current command, the value of this variable is equal to
b8c60bc9 5890 ‘${#COMP_LINE}’. This variable is available only in shell
bb70624e 5891 functions and external commands invoked by the programmable
28ef6c31 5892 completion facilities (*note Programmable Completion::).
bb70624e 5893
b8c60bc9
CR
5894‘COMP_TYPE’
5895 Set to an integer value corresponding to the type of attempted
5896 completion that caused a completion function to be called: <TAB>,
5897 for normal completion, ‘?’, for listing completions after
5898 successive tabs, ‘!’, for listing alternatives on partial word
5899 completion, ‘@’, to list completions if the word is not unmodified,
5900 or ‘%’, for menu completion. This variable is available only in
74091dd4 5901 shell functions and external commands invoked by the programmable
3185942a
JA
5902 completion facilities (*note Programmable Completion::).
5903
b8c60bc9 5904‘COMP_WORDBREAKS’
b80f6443 5905 The set of characters that the Readline library treats as word
b8c60bc9 5906 separators when performing word completion. If ‘COMP_WORDBREAKS’
b80f6443
JA
5907 is unset, it loses its special properties, even if it is
5908 subsequently reset.
5909
b8c60bc9 5910‘COMP_WORDS’
a0c0a00f
CR
5911 An array variable consisting of the individual words in the current
5912 command line. The line is split into words as Readline would split
b8c60bc9 5913 it, using ‘COMP_WORDBREAKS’ as described above. This variable is
a0c0a00f
CR
5914 available only in shell functions invoked by the programmable
5915 completion facilities (*note Programmable Completion::).
f73dda09 5916
b8c60bc9 5917‘COMPREPLY’
bb70624e
JA
5918 An array variable from which Bash reads the possible completions
5919 generated by a shell function invoked by the programmable
ac50fbac
CR
5920 completion facility (*note Programmable Completion::). Each array
5921 element contains one possible completion.
ccc6cda3 5922
b8c60bc9 5923‘COPROC’
495aee44
CR
5924 An array variable created to hold the file descriptors for output
5925 from and input to an unnamed coprocess (*note Coprocesses::).
5926
b8c60bc9 5927‘DIRSTACK’
bb70624e
JA
5928 An array variable containing the current contents of the directory
5929 stack. Directories appear in the stack in the order they are
b8c60bc9 5930 displayed by the ‘dirs’ builtin. Assigning to members of this
bb70624e 5931 array variable may be used to modify directories already in the
b8c60bc9
CR
5932 stack, but the ‘pushd’ and ‘popd’ builtins must be used to add and
5933 remove directories. Assigning to this variable does not change the
5934 current directory. If ‘DIRSTACK’ is unset, it loses its special
5935 properties, even if it is subsequently reset.
cce855bc 5936
b8c60bc9 5937‘EMACS’
b80f6443 5938 If Bash finds this variable in the environment when the shell
b8c60bc9
CR
5939 starts, and its value is ‘t’, Bash assumes that the shell is
5940 running in an Emacs shell buffer and disables line editing.
495aee44 5941
b8c60bc9
CR
5942‘ENV’
5943 Expanded and executed similarly to ‘BASH_ENV’ (*note Bash Startup
5944 Files::) when an interactive shell is invoked in POSIX mode (*note
8868edaf 5945 Bash POSIX Mode::).
b80f6443 5946
b8c60bc9 5947‘EPOCHREALTIME’
d233b485 5948 Each time this parameter is referenced, it expands to the number of
b8c60bc9 5949 seconds since the Unix Epoch as a floating-point value with
d233b485 5950 micro-second granularity (see the documentation for the C library
b8c60bc9
CR
5951 function ‘time’ for the definition of Epoch). Assignments to
5952 ‘EPOCHREALTIME’ are ignored. If ‘EPOCHREALTIME’ is unset, it loses
d233b485
CR
5953 its special properties, even if it is subsequently reset.
5954
b8c60bc9 5955‘EPOCHSECONDS’
d233b485
CR
5956 Each time this parameter is referenced, it expands to the number of
5957 seconds since the Unix Epoch (see the documentation for the C
b8c60bc9
CR
5958 library function ‘time’ for the definition of Epoch). Assignments
5959 to ‘EPOCHSECONDS’ are ignored. If ‘EPOCHSECONDS’ is unset, it
74091dd4 5960 loses its special properties, even if it is subsequently reset.
d233b485 5961
b8c60bc9 5962‘EUID’
bb70624e
JA
5963 The numeric effective user id of the current user. This variable
5964 is readonly.
cce855bc 5965
b8c60bc9 5966‘EXECIGNORE’
a0c0a00f 5967 A colon-separated list of shell patterns (*note Pattern Matching::)
b8c60bc9
CR
5968 defining the set of filenames to be ignored by command search using
5969 ‘PATH’. Files whose full pathnames match one of these patterns are
5970 not considered executable files for the purposes of completion and
5971 command execution via ‘PATH’ lookup. This does not affect the
5972 behavior of the ‘[’, ‘test’, and ‘[[’ commands. Full pathnames in
5973 the command hash table are not subject to ‘EXECIGNORE’. Use this
5974 variable to ignore shared library files that have the executable
5975 bit set, but are not executable files. The pattern matching honors
5976 the setting of the ‘extglob’ shell option.
5977
5978‘FCEDIT’
5979 The editor used as a default by the ‘fc’ builtin command.
5980
5981‘FIGNORE’
bb70624e 5982 A colon-separated list of suffixes to ignore when performing
ac50fbac 5983 filename completion. A filename whose suffix matches one of the
b8c60bc9
CR
5984 entries in ‘FIGNORE’ is excluded from the list of matched
5985 filenames. A sample value is ‘.o:~’
ccc6cda3 5986
b8c60bc9 5987‘FUNCNAME’
b80f6443 5988 An array variable containing the names of all shell functions
a0c0a00f
CR
5989 currently in the execution call stack. The element with index 0 is
5990 the name of any currently-executing shell function. The
b8c60bc9 5991 bottom-most element (the one with the highest index) is ‘"main"’.
495aee44 5992 This variable exists only when a shell function is executing.
b8c60bc9 5993 Assignments to ‘FUNCNAME’ have no effect. If ‘FUNCNAME’ is unset,
a0c0a00f
CR
5994 it loses its special properties, even if it is subsequently reset.
5995
b8c60bc9
CR
5996 This variable can be used with ‘BASH_LINENO’ and ‘BASH_SOURCE’.
5997 Each element of ‘FUNCNAME’ has corresponding elements in
5998 ‘BASH_LINENO’ and ‘BASH_SOURCE’ to describe the call stack. For
5999 instance, ‘${FUNCNAME[$i]}’ was called from the file
6000 ‘${BASH_SOURCE[$i+1]}’ at line number ‘${BASH_LINENO[$i]}’. The
6001 ‘caller’ builtin displays the current call stack using this
495aee44
CR
6002 information.
6003
b8c60bc9
CR
6004‘FUNCNEST’
6005 A numeric value greater than 0 defines a maximum function nesting
6006 level. Function invocations that exceed this nesting level cause
6007 the current command to abort.
f73dda09 6008
b8c60bc9 6009‘GLOBIGNORE’
d233b485
CR
6010 A colon-separated list of patterns defining the set of file names
6011 to be ignored by filename expansion. If a file name matched by a
bb70624e 6012 filename expansion pattern also matches one of the patterns in
b8c60bc9
CR
6013 ‘GLOBIGNORE’, it is removed from the list of matches. The pattern
6014 matching honors the setting of the ‘extglob’ shell option.
6015
6016‘GLOBSORT’
6017 Controls how the results of filename expansion are sorted. The
6018 value of this variable specifies the sort criteria and sort order
6019 for the results of filename expansion. If this variable is unset
6020 or set to the null string, filename expansion uses the historical
6021 behavior of sorting by name, in ascending lexicographic order as
6022 determined by the ‘LC_COLLATE’ shell variable.
6023
6024 If set, a valid value begins with an optional ‘+’, which is
6025 ignored, or ‘-’, which reverses the sort order from ascending to
6026 descending, followed by a sort specifier. The valid sort
6027 specifiers are ‘name’, ‘numeric’, ‘size’, ‘mtime’, ‘atime’,
6028 ‘ctime’, and ‘blocks’, which sort the files on name, names in
6029 numeric rather than lexicographic order, file size, modification
6030 time, access time, inode change time, and number of blocks,
6031 respectively. If any of the non-name keys compare as equal (e.g.,
6032 if two files are the same size), sorting uses the name as a
6033 secondary sort key.
6034
6035 For example, a value of ‘-mtime’ sorts the results in descending
6036 order by modification time (newest first).
6037
6038 The ‘numeric’ specifier treats names consisting solely of digits as
6039 numbers and sorts them using their numeric value (so "2" sorts
6040 before "10", for example). When using ‘numeric’, names containing
6041 non-digits sort after all the all-digit names and are sorted by
6042 name using the traditional behavior.
6043
6044 A sort specifier of ‘nosort’ disables sorting completely; Bash
6045 returns the results in the order they are read from the file
6046 system, ignoring any leading ‘-’.
6047
6048 If the sort specifier is missing, it defaults to NAME, so a value
6049 of ‘+’ is equivalent to the null string, and a value of ‘-’ sorts
6050 by name in descending order.
6051
6052 Any invalid value restores the historical sorting behavior.
6053
6054‘GROUPS’
bb70624e 6055 An array variable containing the list of groups of which the
b8c60bc9
CR
6056 current user is a member. Assignments to ‘GROUPS’ have no effect.
6057 If ‘GROUPS’ is unset, it loses its special properties, even if it
a0c0a00f 6058 is subsequently reset.
ccc6cda3 6059
b8c60bc9
CR
6060‘histchars’
6061 The two or three characters which control history expansion, quick
28ef6c31 6062 substitution, and tokenization (*note History Interaction::). The
b8c60bc9
CR
6063 first character is the “history expansion” character, the character
6064 which begins a history expansion, normally ‘!’. The second
6065 character is the “quick substitution” character, normally ‘^’.
6066 When it appears as the first character on the line, history
6067 substitution repeats the previous command, replacing one string
6068 with another. The optional third character is the “history
6069 comment” character, normally ‘#’, which indicates that the
6070 remainder of the line is a comment when it appears as the first
6071 character of a word. The history comment character disables
6072 history substitution for the remaining words on the line. It does
6073 not necessarily cause the shell parser to treat the rest of the
6074 line as a comment.
6075
6076‘HISTCMD’
bb70624e 6077 The history number, or index in the history list, of the current
b8c60bc9 6078 command. Assignments to ‘HISTCMD’ have no effect. If ‘HISTCMD’ is
8868edaf
CR
6079 unset, it loses its special properties, even if it is subsequently
6080 reset.
ccc6cda3 6081
b8c60bc9 6082‘HISTCONTROL’
a0c0a00f 6083 A colon-separated list of values controlling how commands are saved
b8c60bc9 6084 on the history list. If the list of values includes ‘ignorespace’,
a0c0a00f 6085 lines which begin with a space character are not saved in the
b8c60bc9
CR
6086 history list. A value of ‘ignoredups’ causes lines which match the
6087 previous history entry not to be saved. A value of ‘ignoreboth’ is
6088 shorthand for ‘ignorespace’ and ‘ignoredups’. A value of
6089 ‘erasedups’ causes all previous lines matching the current line to
a0c0a00f 6090 be removed from the history list before that line is saved. Any
b8c60bc9
CR
6091 value not in the above list is ignored. If ‘HISTCONTROL’ is unset,
6092 or does not include a valid value, Bash saves all lines read by the
6093 shell parser on the history list, subject to the value of
6094 ‘HISTIGNORE’. If the first line of a multi-line compound command
6095 was saved, the second and subsequent lines are not tested, and are
6096 added to the history regardless of the value of ‘HISTCONTROL’. If
6097 the first line was not saved, the second and subsequent lines of
6098 the command are not saved either.
6099
6100‘HISTFILE’
6101 The name of the file to which the command history is saved. Bash
6102 assigns a default value of ‘~/.bash_history’. If ‘HISTFILE’ is
6103 unset or null, the shell does not save the command history when it
6104 exits.
6105
6106‘HISTFILESIZE’
f73dda09
JA
6107 The maximum number of lines contained in the history file. When
6108 this variable is assigned a value, the history file is truncated,
b8c60bc9
CR
6109 if necessary, to contain no more than the number of history entries
6110 that total no more than that number of lines by removing the oldest
6111 entries. If the history list contains multi-line entries, the
6112 history file may contain more lines than this maximum to avoid
6113 leaving partial history entries. The history file is also
6114 truncated to this size after writing it when a shell exits or by
6115 the ‘history’ builtin. If the value is 0, the history file is
6116 truncated to zero size. Non-numeric values and numeric values less
6117 than zero inhibit truncation. The shell sets the default value to
6118 the value of ‘HISTSIZE’ after reading any startup files.
6119
6120‘HISTIGNORE’
bb70624e 6121 A colon-separated list of patterns used to decide which command
b8c60bc9
CR
6122 lines should be saved on the history list. If a command line
6123 matches one of the patterns in the value of ‘HISTIGNORE’, it is not
6124 saved on the history list. Each pattern is anchored at the
6125 beginning of the line and must match the complete line (Bash does
6126 not implicitly append a ‘*’). Each pattern is tested against the
6127 line after the checks specified by ‘HISTCONTROL’ are applied. In
6128 addition to the normal shell pattern matching characters, ‘&’
6129 matches the previous history line. A backslash escapes the ‘&’;
6130 the backslash is removed before attempting a match. If the first
6131 line of a multi-line compound command was saved, the second and
6132 subsequent lines are not tested, and are added to the history
6133 regardless of the value of ‘HISTIGNORE’. If the first line was not
6134 saved, the second and subsequent lines of the command are not saved
6135 either. The pattern matching honors the setting of the ‘extglob’
6136 shell option.
6137
6138 ‘HISTIGNORE’ subsumes some of the function of ‘HISTCONTROL’. A
6139 pattern of ‘&’ is identical to ‘ignoredups’, and a pattern of ‘[
6140 ]*’ is identical to ‘ignorespace’. Combining these two patterns,
bb70624e 6141 separating them with a colon, provides the functionality of
b8c60bc9 6142 ‘ignoreboth’.
ccc6cda3 6143
b8c60bc9 6144‘HISTSIZE’
a0c0a00f
CR
6145 The maximum number of commands to remember on the history list. If
6146 the value is 0, commands are not saved in the history list.
ac50fbac
CR
6147 Numeric values less than zero result in every command being saved
6148 on the history list (there is no limit). The shell sets the
6149 default value to 500 after reading any startup files.
b72432fd 6150
b8c60bc9 6151‘HISTTIMEFORMAT’
a0c0a00f 6152 If this variable is set and not null, its value is used as a format
b8c60bc9
CR
6153 string for ‘strftime’(3) to print the time stamp associated with
6154 each history entry displayed by the ‘history’ builtin. If this
6155 variable is set, the shell writes time stamps to the history file
6156 so they may be preserved across shell sessions. This uses the
6157 history comment character to distinguish timestamps from other
6158 history lines.
6159
6160‘HOSTFILE’
6161 Contains the name of a file in the same format as ‘/etc/hosts’ that
bb70624e
JA
6162 should be read when the shell needs to complete a hostname. The
6163 list of possible hostname completions may be changed while the
6164 shell is running; the next time hostname completion is attempted
6165 after the value is changed, Bash adds the contents of the new file
b8c60bc9
CR
6166 to the existing list. If ‘HOSTFILE’ is set, but has no value, or
6167 does not name a readable file, Bash attempts to read ‘/etc/hosts’
0001803f 6168 to obtain the list of possible hostname completions. When
b8c60bc9 6169 ‘HOSTFILE’ is unset, Bash clears the hostname list.
cce855bc 6170
b8c60bc9 6171‘HOSTNAME’
bb70624e 6172 The name of the current host.
cce855bc 6173
b8c60bc9 6174‘HOSTTYPE’
bb70624e 6175 A string describing the machine Bash is running on.
ccc6cda3 6176
b8c60bc9
CR
6177‘IGNOREEOF’
6178 Controls the action of the shell on receipt of an ‘EOF’ character
6179 as the sole input. If set, the value is the number of consecutive
6180 ‘EOF’ characters that can be read as the first character on an
6181 input line before Bash exits. If the variable is set but does not
6182 have a numeric value, or the value is null, then the default is 10.
6183 If the variable is unset, then ‘EOF’ signifies the end of input to
6184 the shell. This is only in effect for interactive shells.
6185
6186‘INPUTRC’
bb70624e 6187 The name of the Readline initialization file, overriding the
b8c60bc9 6188 default of ‘~/.inputrc’.
ccc6cda3 6189
b8c60bc9 6190‘INSIDE_EMACS’
d233b485
CR
6191 If Bash finds this variable in the environment when the shell
6192 starts, it assumes that the shell is running in an Emacs shell
6193 buffer and may disable line editing depending on the value of
b8c60bc9 6194 ‘TERM’.
d233b485 6195
b8c60bc9 6196‘LANG’
bb70624e 6197 Used to determine the locale category for any category not
b8c60bc9 6198 specifically selected with a variable starting with ‘LC_’.
ccc6cda3 6199
b8c60bc9
CR
6200‘LC_ALL’
6201 This variable overrides the value of ‘LANG’ and any other ‘LC_’
bb70624e 6202 variable specifying a locale category.
cce855bc 6203
b8c60bc9 6204‘LC_COLLATE’
bb70624e 6205 This variable determines the collation order used when sorting the
a0c0a00f
CR
6206 results of filename expansion, and determines the behavior of range
6207 expressions, equivalence classes, and collating sequences within
6208 filename expansion and pattern matching (*note Filename
28ef6c31 6209 Expansion::).
ccc6cda3 6210
b8c60bc9 6211‘LC_CTYPE’
bb70624e
JA
6212 This variable determines the interpretation of characters and the
6213 behavior of character classes within filename expansion and pattern
28ef6c31 6214 matching (*note Filename Expansion::).
ccc6cda3 6215
b8c60bc9 6216‘LC_MESSAGES’
bb70624e 6217 This variable determines the locale used to translate double-quoted
b8c60bc9 6218 strings preceded by a ‘$’ (*note Locale Translation::).
ccc6cda3 6219
b8c60bc9 6220‘LC_NUMERIC’
bb70624e
JA
6221 This variable determines the locale category used for number
6222 formatting.
ccc6cda3 6223
b8c60bc9 6224‘LC_TIME’
a0c0a00f
CR
6225 This variable determines the locale category used for data and time
6226 formatting.
6227
b8c60bc9 6228‘LINENO’
f73dda09 6229 The line number in the script or shell function currently
b8c60bc9
CR
6230 executing. Line numbers start with 1. When not in a script or
6231 function, the value is not guaranteed to be meaningful. If
6232 ‘LINENO’ is unset, it loses its special properties, even if it is
6233 subsequently reset.
f73dda09 6234
b8c60bc9
CR
6235‘LINES’
6236 Used by the ‘select’ command to determine the column length for
6237 printing selection lists. Automatically set if the ‘checkwinsize’
a0c0a00f 6238 option is enabled (*note The Shopt Builtin::), or in an interactive
b8c60bc9 6239 shell upon receipt of a ‘SIGWINCH’.
28ef6c31 6240
b8c60bc9 6241‘MACHTYPE’
bb70624e
JA
6242 A string that fully describes the system type on which Bash is
6243 executing, in the standard GNU CPU-COMPANY-SYSTEM format.
ccc6cda3 6244
b8c60bc9 6245‘MAILCHECK’
bb70624e 6246 How often (in seconds) that the shell should check for mail in the
b8c60bc9 6247 files specified in the ‘MAILPATH’ or ‘MAIL’ variables. The default
a0c0a00f
CR
6248 is 60 seconds. When it is time to check for mail, the shell does
6249 so before displaying the primary prompt. If this variable is
6250 unset, or set to a value that is not a number greater than or equal
6251 to zero, the shell disables mail checking.
6252
b8c60bc9
CR
6253‘MAPFILE’
6254 An array variable created to hold the text read by the ‘mapfile’
495aee44
CR
6255 builtin when no variable name is supplied.
6256
b8c60bc9
CR
6257‘OLDPWD’
6258 The previous working directory as set by the ‘cd’ builtin.
ccc6cda3 6259
b8c60bc9 6260‘OPTERR’
bb70624e 6261 If set to the value 1, Bash displays error messages generated by
b8c60bc9
CR
6262 the ‘getopts’ builtin command. ‘OPTERR’ is initialized to 1 each
6263 time the shell is invoked.
ccc6cda3 6264
b8c60bc9 6265‘OSTYPE’
bb70624e 6266 A string describing the operating system Bash is running on.
ccc6cda3 6267
b8c60bc9 6268‘PIPESTATUS’
a0c0a00f 6269 An array variable (*note Arrays::) containing a list of exit status
b8c60bc9
CR
6270 values from the commands in the most-recently-executed foreground
6271 pipeline, which may consist of only a simple command (*note Shell
6272 Commands::). Bash sets ‘PIPESTATUS’ after executing multi-element
6273 pipelines, timed and negated pipelines, simple commands, subshells
6274 created with the ‘(’ operator, the ‘[[’ and ‘((’ compound commands,
6275 and after error conditions that result in the shell aborting
6276 command execution.
6277
6278‘POSIXLY_CORRECT’
ac50fbac
CR
6279 If this variable is in the environment when Bash starts, the shell
6280 enters POSIX mode (*note Bash POSIX Mode::) before reading the
b8c60bc9 6281 startup files, as if the ‘--posix’ invocation option had been
ac50fbac 6282 supplied. If it is set while the shell is running, Bash enables
f73dda09 6283 POSIX mode, as if the command
a0c0a00f 6284 set -o posix
d233b485
CR
6285 had been executed. When the shell enters POSIX mode, it sets this
6286 variable if it was not already set.
f73dda09 6287
b8c60bc9 6288‘PPID’
bb70624e
JA
6289 The process ID of the shell's parent process. This variable is
6290 readonly.
ccc6cda3 6291
b8c60bc9 6292‘PROMPT_COMMAND’
8868edaf
CR
6293 If this variable is set, and is an array, the value of each set
6294 element is interpreted as a command to execute before printing the
b8c60bc9 6295 primary prompt (‘$PS1’). If this is set but not an array variable,
8868edaf 6296 its value is used as a command to execute instead.
ccc6cda3 6297
b8c60bc9 6298‘PROMPT_DIRTRIM’
3185942a
JA
6299 If set to a number greater than zero, the value is used as the
6300 number of trailing directory components to retain when expanding
b8c60bc9 6301 the ‘\w’ and ‘\W’ prompt string escapes (*note Controlling the
3185942a
JA
6302 Prompt::). Characters removed are replaced with an ellipsis.
6303
b8c60bc9
CR
6304‘PS0’
6305 The value of this parameter is expanded like ‘PS1’ and displayed by
a0c0a00f
CR
6306 interactive shells after reading a command and before the command
6307 is executed.
6308
b8c60bc9
CR
6309‘PS3’
6310 The value of this variable is used as the prompt for the ‘select’
6311 command. If this variable is not set, the ‘select’ command prompts
6312 with ‘#? ’
ccc6cda3 6313
b8c60bc9
CR
6314‘PS4’
6315 The value of this parameter is expanded like ‘PS1’ and the expanded
d233b485 6316 value is the prompt printed before the command line is echoed when
b8c60bc9 6317 the ‘-x’ option is set (*note The Set Builtin::). The first
d233b485
CR
6318 character of the expanded value is replicated multiple times, as
6319 necessary, to indicate multiple levels of indirection. The default
b8c60bc9 6320 is ‘+ ’.
ccc6cda3 6321
b8c60bc9
CR
6322‘PWD’
6323 The current working directory as set by the ‘cd’ builtin.
ccc6cda3 6324
b8c60bc9 6325‘RANDOM’
8868edaf 6326 Each time this parameter is referenced, it expands to a random
b8c60bc9
CR
6327 integer between 0 and 32767. Assigning a value to ‘RANDOM’
6328 initializes (seeds) the sequence of random numbers. Seeding the
6329 random number generator with the same constant value produces the
6330 same sequence of values. If ‘RANDOM’ is unset, it loses its
6331 special properties, even if it is subsequently reset.
cce855bc 6332
b8c60bc9 6333‘READLINE_ARGUMENT’
74091dd4 6334 Any numeric argument given to a Readline command that was defined
b8c60bc9 6335 using ‘bind -x’ (*note Bash Builtins:: when it was invoked.
74091dd4 6336
b8c60bc9
CR
6337‘READLINE_LINE’
6338 The contents of the Readline line buffer, for use with ‘bind -x’
495aee44
CR
6339 (*note Bash Builtins::).
6340
b8c60bc9
CR
6341‘READLINE_MARK’
6342 The position of the “mark” (saved insertion point) in the Readline
6343 line buffer, for use with ‘bind -x’ (*note Bash Builtins::). The
8868edaf 6344 characters between the insertion point and the mark are often
b8c60bc9 6345 called the “region”.
8868edaf 6346
b8c60bc9 6347‘READLINE_POINT’
495aee44 6348 The position of the insertion point in the Readline line buffer,
b8c60bc9 6349 for use with ‘bind -x’ (*note Bash Builtins::).
495aee44 6350
b8c60bc9
CR
6351‘REPLY’
6352 The default variable for the ‘read’ builtin; set to the line read
6353 when ‘read’ is not supplied a variable name argument.
ccc6cda3 6354
b8c60bc9 6355‘SECONDS’
bb70624e 6356 This variable expands to the number of seconds since the shell was
a0c0a00f
CR
6357 started. Assignment to this variable resets the count to the value
6358 assigned, and the expanded value becomes the value assigned plus
8868edaf 6359 the number of seconds since the assignment. The number of seconds
74091dd4 6360 at shell invocation and the current time are always determined by
b8c60bc9
CR
6361 querying the system clock at one-second resolution. If ‘SECONDS’
6362 is unset, it loses its special properties, even if it is
6363 subsequently reset.
ccc6cda3 6364
b8c60bc9 6365‘SHELL’
8868edaf
CR
6366 This environment variable expands to the full pathname to the
6367 shell. If it is not set when the shell starts, Bash assigns to it
6368 the full pathname of the current user's login shell.
b80f6443 6369
b8c60bc9 6370‘SHELLOPTS’
bb70624e 6371 A colon-separated list of enabled shell options. Each word in the
b8c60bc9 6372 list is a valid argument for the ‘-o’ option to the ‘set’ builtin
28ef6c31 6373 command (*note The Set Builtin::). The options appearing in
b8c60bc9
CR
6374 ‘SHELLOPTS’ are those reported as ‘on’ by ‘set -o’. If this
6375 variable is in the environment when Bash starts up, the shell
6376 enables each option in the list before reading any startup files.
6377 If this variable is exported, child shells will enable each option
6378 in the list. This variable is readonly.
ccc6cda3 6379
b8c60bc9 6380‘SHLVL’
bb70624e
JA
6381 Incremented by one each time a new instance of Bash is started.
6382 This is intended to be a count of how deeply your Bash shells are
6383 nested.
cce855bc 6384
b8c60bc9 6385‘SRANDOM’
8868edaf
CR
6386 This variable expands to a 32-bit pseudo-random number each time it
6387 is referenced. The random number generator is not linear on
b8c60bc9 6388 systems that support ‘/dev/urandom’ or ‘arc4random’, so each
8868edaf
CR
6389 returned number has no relationship to the numbers preceding it.
6390 The random number generator cannot be seeded, so assignments to
b8c60bc9 6391 this variable have no effect. If ‘SRANDOM’ is unset, it loses its
8868edaf
CR
6392 special properties, even if it is subsequently reset.
6393
b8c60bc9 6394‘TIMEFORMAT’
bb70624e 6395 The value of this parameter is used as a format string specifying
b8c60bc9
CR
6396 how the timing information for pipelines prefixed with the ‘time’
6397 reserved word should be displayed. The ‘%’ character introduces an
bb70624e
JA
6398 escape sequence that is expanded to a time value or other
6399 information. The escape sequences and their meanings are as
b8c60bc9 6400 follows; the brackets denote optional portions.
cce855bc 6401
b8c60bc9
CR
6402 ‘%%’
6403 A literal ‘%’.
ccc6cda3 6404
b8c60bc9 6405 ‘%[P][l]R’
bb70624e 6406 The elapsed time in seconds.
ccc6cda3 6407
b8c60bc9 6408 ‘%[P][l]U’
bb70624e 6409 The number of CPU seconds spent in user mode.
ccc6cda3 6410
b8c60bc9 6411 ‘%[P][l]S’
bb70624e 6412 The number of CPU seconds spent in system mode.
ccc6cda3 6413
b8c60bc9 6414 ‘%P’
bb70624e 6415 The CPU percentage, computed as (%U + %S) / %R.
ccc6cda3 6416
bb70624e
JA
6417 The optional P is a digit specifying the precision, the number of
6418 fractional digits after a decimal point. A value of 0 causes no
b8c60bc9
CR
6419 decimal point or fraction to be output. ‘time’ prints at most six
6420 digits after the decimal point; values of P greater than 6 are
6421 changed to 6. If P is not specified, ‘time’ prints three digits
6422 after the decimal point.
ccc6cda3 6423
b8c60bc9 6424 The optional ‘l’ specifies a longer format, including minutes, of
bb70624e
JA
6425 the form MMmSS.FFs. The value of P determines whether or not the
6426 fraction is included.
ccc6cda3 6427
bb70624e 6428 If this variable is not set, Bash acts as if it had the value
a0c0a00f 6429 $'\nreal\t%3lR\nuser\t%3lU\nsys\t%3lS'
b8c60bc9
CR
6430 If the value is null, Bash does not display any timing information.
6431 A trailing newline is added when the format string is displayed.
ccc6cda3 6432
b8c60bc9
CR
6433‘TMOUT’
6434 If set to a value greater than zero, the ‘read’ builtin uses the
6435 value as its default timeout (*note Bash Builtins::). The ‘select’
6436 command (*note Conditional Constructs::) terminates if input does
6437 not arrive after ‘TMOUT’ seconds when input is coming from a
6438 terminal.
7117c2d2 6439
3185942a 6440 In an interactive shell, the value is interpreted as the number of
ac50fbac
CR
6441 seconds to wait for a line of input after issuing the primary
6442 prompt. Bash terminates after waiting for that number of seconds
6443 if a complete line of input does not arrive.
ccc6cda3 6444
b8c60bc9 6445‘TMPDIR’
95732b49
JA
6446 If set, Bash uses its value as the name of a directory in which
6447 Bash creates temporary files for the shell's use.
6448
b8c60bc9 6449‘UID’
bb70624e
JA
6450 The numeric real user id of the current user. This variable is
6451 readonly.
ccc6cda3 6452
bb70624e
JA
6453\1f
6454File: bashref.info, Node: Bash Features, Next: Job Control, Prev: Shell Variables, Up: Top
ccc6cda3 6455
b80f6443
JA
64566 Bash Features
6457***************
ccc6cda3 6458
ac50fbac 6459This chapter describes features unique to Bash.
ccc6cda3 6460
bb70624e 6461* Menu:
ccc6cda3 6462
bb70624e
JA
6463* Invoking Bash:: Command line options that you can give
6464 to Bash.
6465* Bash Startup Files:: When and how Bash executes scripts.
6466* Interactive Shells:: What an interactive shell is.
6467* Bash Conditional Expressions:: Primitives used in composing expressions for
b8c60bc9 6468 the ‘test’ builtin.
bb70624e
JA
6469* Shell Arithmetic:: Arithmetic on shell variables.
6470* Aliases:: Substituting one command for another.
6471* Arrays:: Array Variables.
6472* The Directory Stack:: History of visited directories.
ac50fbac 6473* Controlling the Prompt:: Customizing the various prompt strings.
bb70624e
JA
6474* The Restricted Shell:: A more controlled mode of shell execution.
6475* Bash POSIX Mode:: Making Bash behave more closely to what
6476 the POSIX standard specifies.
8868edaf
CR
6477* Shell Compatibility Mode:: How Bash supports behavior that was present
6478 in earlier versions and has changed.
ccc6cda3 6479
bb70624e
JA
6480\1f
6481File: bashref.info, Node: Invoking Bash, Next: Bash Startup Files, Up: Bash Features
ccc6cda3 6482
b80f6443
JA
64836.1 Invoking Bash
6484=================
ccc6cda3 6485
d233b485
CR
6486 bash [long-opt] [-ir] [-abefhkmnptuvxdBCDHP] [-o OPTION]
6487 [-O SHOPT_OPTION] [ARGUMENT ...]
6488 bash [long-opt] [-abefhkmnptuvxdBCDHP] [-o OPTION]
6489 [-O SHOPT_OPTION] -c STRING [ARGUMENT ...]
6490 bash [long-opt] -s [-abefhkmnptuvxdBCDHP] [-o OPTION]
6491 [-O SHOPT_OPTION] [ARGUMENT ...]
ccc6cda3 6492
b8c60bc9 6493 All of the single-character options used with the ‘set’ builtin
495aee44
CR
6494(*note The Set Builtin::) can be used as options when the shell is
6495invoked. In addition, there are several multi-character options that
6496you can use. These options must appear on the command line before the
6497single-character options to be recognized.
ccc6cda3 6498
b8c60bc9 6499‘--debugger’
b80f6443 6500 Arrange for the debugger profile to be executed before the shell
3185942a 6501 starts. Turns on extended debugging mode (see *note The Shopt
b8c60bc9 6502 Builtin:: for a description of the ‘extdebug’ option to the ‘shopt’
495aee44 6503 builtin).
b80f6443 6504
b8c60bc9
CR
6505‘--dump-po-strings’
6506 Print a list of all double-quoted strings preceded by ‘$’ on the
6507 standard output in the GNU ‘gettext’ PO (portable object) file
6508 format. Equivalent to ‘-D’ except for the output format.
ccc6cda3 6509
b8c60bc9
CR
6510‘--dump-strings’
6511 Equivalent to ‘-D’.
ccc6cda3 6512
b8c60bc9 6513‘--help’
3185942a 6514 Display a usage message on standard output and exit successfully.
ccc6cda3 6515
b8c60bc9
CR
6516‘--init-file FILENAME’
6517‘--rcfile FILENAME’
6518 Execute commands from FILENAME (instead of ‘~/.bashrc’) in an
28ef6c31
JA
6519 interactive shell.
6520
b8c60bc9
CR
6521‘--login’
6522 Equivalent to ‘-l’.
ccc6cda3 6523
b8c60bc9 6524‘--noediting’
28ef6c31 6525 Do not use the GNU Readline library (*note Command Line Editing::)
a0c0a00f 6526 to read command lines when the shell is interactive.
ccc6cda3 6527
b8c60bc9
CR
6528‘--noprofile’
6529 Don't load the system-wide startup file ‘/etc/profile’ or any of
6530 the personal initialization files ‘~/.bash_profile’,
6531 ‘~/.bash_login’, or ‘~/.profile’ when Bash is invoked as a login
bb70624e 6532 shell.
ccc6cda3 6533
b8c60bc9
CR
6534‘--norc’
6535 Don't read the ‘~/.bashrc’ initialization file in an interactive
6536 shell. This is on by default if the shell is invoked as ‘sh’.
ccc6cda3 6537
b8c60bc9
CR
6538‘--posix’
6539 Enable POSIX mode; change the behavior of Bash where the default
6540 operation differs from the POSIX standard to match the standard.
6541 This is intended to make Bash behave as a strict superset of that
6542 standard. *Note Bash POSIX Mode::, for a description of the Bash
6543 POSIX mode.
ccc6cda3 6544
b8c60bc9
CR
6545‘--restricted’
6546 Equivalent to ‘-r’. Make the shell a restricted shell (*note The
6547 Restricted Shell::).
ccc6cda3 6548
b8c60bc9
CR
6549‘--verbose’
6550 Equivalent to ‘-v’. Print shell input lines as they're read.
ccc6cda3 6551
b8c60bc9 6552‘--version’
bb70624e
JA
6553 Show version information for this instance of Bash on the standard
6554 output and exit successfully.
ccc6cda3 6555
bb70624e 6556 There are several single-character options that may be supplied at
b8c60bc9 6557invocation which are not available with the ‘set’ builtin.
ccc6cda3 6558
b8c60bc9 6559‘-c’
a0c0a00f
CR
6560 Read and execute commands from the first non-option argument
6561 COMMAND_STRING, then exit. If there are arguments after the
b8c60bc9 6562 COMMAND_STRING, the first argument is assigned to ‘$0’ and any
a0c0a00f 6563 remaining arguments are assigned to the positional parameters. The
b8c60bc9 6564 assignment to ‘$0’ sets the name of the shell, which is used in
a0c0a00f 6565 warning and error messages.
ccc6cda3 6566
b8c60bc9 6567‘-i’
bb70624e 6568 Force the shell to run interactively. Interactive shells are
3185942a 6569 described in *note Interactive Shells::.
ccc6cda3 6570
b8c60bc9 6571‘-l’
7117c2d2
JA
6572 Make this shell act as if it had been directly invoked by login.
6573 When the shell is interactive, this is equivalent to starting a
b8c60bc9
CR
6574 login shell with ‘exec -l bash’. When the shell is not
6575 interactive, it will read and execute the login shell startup
6576 files. ‘exec bash -l’ or ‘exec bash --login’ will replace the
6577 current shell with a Bash login shell. *Note Bash Startup Files::,
6578 for a description of the special behavior of a login shell.
7117c2d2 6579
b8c60bc9 6580‘-r’
28ef6c31 6581 Make the shell a restricted shell (*note The Restricted Shell::).
ccc6cda3 6582
b8c60bc9 6583‘-s’
bb70624e 6584 If this option is present, or if no arguments remain after option
b8c60bc9 6585 processing, then Bash reads commands from the standard input. This
bb70624e 6586 option allows the positional parameters to be set when invoking an
d233b485 6587 interactive shell or when reading input through a pipe.
ccc6cda3 6588
b8c60bc9
CR
6589‘-D’
6590 Print a list of all double-quoted strings preceded by ‘$’ on the
6591 standard output. These are the strings that are subject to
6592 language translation when the current locale is not ‘C’ or ‘POSIX’
6593 (*note Locale Translation::). This implies the ‘-n’ option; no
bb70624e 6594 commands will be executed.
ccc6cda3 6595
b8c60bc9
CR
6596‘[-+]O [SHOPT_OPTION]’
6597 SHOPT_OPTION is one of the shell options accepted by the ‘shopt’
3185942a 6598 builtin (*note The Shopt Builtin::). If SHOPT_OPTION is present,
b8c60bc9
CR
6599 ‘-O’ sets the value of that option; ‘+O’ unsets it. If
6600 SHOPT_OPTION is not supplied, Bash prints the names and values of
6601 the shell options accepted by ‘shopt’ on the standard output. If
6602 the invocation option is ‘+O’, the output is displayed in a format
a0c0a00f 6603 that may be reused as input.
f73dda09 6604
b8c60bc9
CR
6605‘--’
6606 A ‘--’ signals the end of options and disables further option
6607 processing. Any arguments after the ‘--’ are treated as a shell
6608 script filename (*note Shell Scripts::) and arguments passed to
6609 that script.
ccc6cda3 6610
b8c60bc9
CR
6611‘-’
6612 Equivalent to ‘--’.
f73dda09 6613
b8c60bc9
CR
6614 A “login shell” is one whose first character of argument zero is ‘-’,
6615or one invoked with the ‘--login’ option.
ccc6cda3 6616
b8c60bc9
CR
6617 An “interactive shell” is one started without non-option arguments,
6618unless ‘-s’ is specified, without specifying the ‘-c’ option, and whose
6619standard input and standard error are both connected to terminals (as
6620determined by isatty(3)), or one started with the ‘-i’ option. *Note
6621Interactive Shells::, for more information.
6622
6623 If arguments remain after option processing, and neither the ‘-c’ nor
6624the ‘-s’ option has been supplied, the first argument is treated as the
6625name of a file containing shell commands (*note Shell Scripts::). When
6626Bash is invoked in this fashion, ‘$0’ is set to the name of the file,
6627and the positional parameters are set to the remaining arguments. Bash
6628reads and executes commands from this file, then exits. Bash's exit
6629status is the exit status of the last command executed in the script.
6630If no commands are executed, the exit status is 0. Bash first attempts
6631to open the file in the current directory, and, if no file is found,
6632searches the directories in ‘PATH’ for the script.
ccc6cda3 6633
bb70624e
JA
6634\1f
6635File: bashref.info, Node: Bash Startup Files, Next: Interactive Shells, Prev: Invoking Bash, Up: Bash Features
ccc6cda3 6636
b80f6443
JA
66376.2 Bash Startup Files
6638======================
ccc6cda3 6639
3185942a 6640This section describes how Bash executes its startup files. If any of
b80f6443 6641the files exist but cannot be read, Bash reports an error. Tildes are
ac50fbac 6642expanded in filenames as described above under Tilde Expansion (*note
b80f6443 6643Tilde Expansion::).
ccc6cda3 6644
3185942a 6645 Interactive shells are described in *note Interactive Shells::.
ccc6cda3 6646
b8c60bc9 6647Invoked as an interactive login shell, or with ‘--login’
bb70624e 6648........................................................
cce855bc 6649
b80f6443 6650When Bash is invoked as an interactive login shell, or as a
b8c60bc9
CR
6651non-interactive shell with the ‘--login’ option, it first reads and
6652executes commands from the file ‘/etc/profile’, if that file exists.
6653After reading that file, it looks for ‘~/.bash_profile’,
6654‘~/.bash_login’, and ‘~/.profile’, in that order, and reads and executes
a0c0a00f 6655commands from the first one that exists and is readable. The
b8c60bc9 6656‘--noprofile’ option inhibits this behavior.
ccc6cda3 6657
a0c0a00f 6658 When an interactive login shell exits, or a non-interactive login
b8c60bc9
CR
6659shell executes the ‘exit’ builtin command, Bash reads and executes
6660commands from the file ‘~/.bash_logout’, if it exists.
ccc6cda3 6661
bb70624e
JA
6662Invoked as an interactive non-login shell
6663.........................................
ccc6cda3 6664
b8c60bc9
CR
6665When Bash runs as an interactive shell that is not a login shell, it
6666reads and executes commands from ‘~/.bashrc’, if that file exists. The
6667‘--norc’ option inhibits this behavior. The ‘--rcfile FILE’ option
6668causes Bash to use FILE instead of ‘~/.bashrc’.
ccc6cda3 6669
b8c60bc9 6670 So, typically, your ‘~/.bash_profile’ contains the line
a0c0a00f
CR
6671 if [ -f ~/.bashrc ]; then . ~/.bashrc; fi
6672after (or before) any login-specific initializations.
ccc6cda3 6673
bb70624e
JA
6674Invoked non-interactively
6675.........................
ccc6cda3 6676
b80f6443 6677When Bash is started non-interactively, to run a shell script, for
b8c60bc9 6678example, it looks for the variable ‘BASH_ENV’ in the environment,
bb70624e
JA
6679expands its value if it appears there, and uses the expanded value as
6680the name of a file to read and execute. Bash behaves as if the
6681following command were executed:
a0c0a00f 6682 if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi
b8c60bc9 6683but does not the value of the ‘PATH’ variable to search for the
ac50fbac 6684filename.
ccc6cda3 6685
28ef6c31 6686 As noted above, if a non-interactive shell is invoked with the
b8c60bc9 6687‘--login’ option, Bash attempts to read and execute commands from the
28ef6c31
JA
6688login shell startup files.
6689
b8c60bc9 6690Invoked with name ‘sh’
bb70624e 6691......................
ccc6cda3 6692
b8c60bc9
CR
6693If Bash is invoked with the name ‘sh’, it tries to mimic the startup
6694behavior of historical versions of ‘sh’ as closely as possible, while
bb70624e 6695conforming to the POSIX standard as well.
ccc6cda3 6696
bb70624e 6697 When invoked as an interactive login shell, or as a non-interactive
b8c60bc9
CR
6698shell with the ‘--login’ option, it first attempts to read and execute
6699commands from ‘/etc/profile’ and ‘~/.profile’, in that order. The
6700‘--noprofile’ option inhibits this behavior.
6701
6702 When invoked as an interactive shell with the name ‘sh’, Bash looks
6703for the variable ‘ENV’, expands its value if it is defined, and uses the
6704expanded value as the name of a file to read and execute. Since a shell
6705invoked as ‘sh’ does not attempt to read and execute commands from any
6706other startup files, the ‘--rcfile’ option has no effect.
6707
6708 A non-interactive shell invoked with the name ‘sh’ does not attempt
6709to read any other startup files.
a0c0a00f 6710
b8c60bc9
CR
6711 When invoked as ‘sh’, Bash enters POSIX mode after reading the
6712startup files.
b72432fd 6713
bb70624e
JA
6714Invoked in POSIX mode
6715.....................
ccc6cda3 6716
b8c60bc9 6717When Bash is started in POSIX mode, as with the ‘--posix’ command line
b80f6443 6718option, it follows the POSIX standard for startup files. In this mode,
b8c60bc9
CR
6719interactive shells expand the ‘ENV’ variable and read and execute
6720commands from the file whose name is the expanded value. No other
b80f6443 6721startup files are read.
ccc6cda3 6722
bb70624e
JA
6723Invoked by remote shell daemon
6724..............................
ccc6cda3 6725
3185942a 6726Bash attempts to determine when it is being run with its standard input
74091dd4 6727connected to a network connection, as when executed by the historical
b8c60bc9
CR
6728and rarely-seen remote shell daemon, usually ‘rshd’, or the secure shell
6729daemon ‘sshd’. If Bash determines it is being run non-interactively in
6730this fashion, it reads and executes commands from ‘~/.bashrc’, if that
6731file exists and is readable. Bash does not read this file if invoked as
6732‘sh’. The ‘--norc’ option inhibits this behavior, and the ‘--rcfile’
6733option makes Bash use a different file instead of ‘~/.bashrc’, but
6734neither ‘rshd’ nor ‘sshd’ generally invoke the shell with those options
6735or allow them to be specified.
ccc6cda3 6736
bb70624e
JA
6737Invoked with unequal effective and real UID/GIDs
6738................................................
6739
b80f6443 6740If Bash is started with the effective user (group) id not equal to the
b8c60bc9 6741real user (group) id, and the ‘-p’ option is not supplied, no startup
b80f6443 6742files are read, shell functions are not inherited from the environment,
b8c60bc9 6743the ‘SHELLOPTS’, ‘BASHOPTS’, ‘CDPATH’, and ‘GLOBIGNORE’ variables, if
0001803f 6744they appear in the environment, are ignored, and the effective user id
b8c60bc9 6745is set to the real user id. If the ‘-p’ option is supplied at
0001803f
CR
6746invocation, the startup behavior is the same, but the effective user id
6747is not reset.
bb70624e
JA
6748
6749\1f
6750File: bashref.info, Node: Interactive Shells, Next: Bash Conditional Expressions, Prev: Bash Startup Files, Up: Bash Features
6751
b80f6443
JA
67526.3 Interactive Shells
6753======================
bb70624e
JA
6754
6755* Menu:
6756
6757* What is an Interactive Shell?:: What determines whether a shell is Interactive.
6758* Is this Shell Interactive?:: How to tell if a shell is interactive.
74091dd4 6759* Interactive Shell Behavior:: What changes in an interactive shell?
bb70624e
JA
6760
6761\1f
6762File: bashref.info, Node: What is an Interactive Shell?, Next: Is this Shell Interactive?, Up: Interactive Shells
6763
b80f6443
JA
67646.3.1 What is an Interactive Shell?
6765-----------------------------------
bb70624e 6766
74091dd4 6767An interactive shell is one started without non-option arguments (unless
b8c60bc9 6768‘-s’ is specified) and without specifying the ‘-c’ option, whose input
a0c0a00f 6769and error output are both connected to terminals (as determined by
b8c60bc9 6770‘isatty(3)’), or one started with the ‘-i’ option.
bb70624e
JA
6771
6772 An interactive shell generally reads from and writes to a user's
6773terminal.
6774
b8c60bc9
CR
6775 The ‘-s’ invocation option may be used to set the positional
6776parameters when an interactive shell starts.
bb70624e
JA
6777
6778\1f
6779File: bashref.info, Node: Is this Shell Interactive?, Next: Interactive Shell Behavior, Prev: What is an Interactive Shell?, Up: Interactive Shells
6780
b80f6443
JA
67816.3.2 Is this Shell Interactive?
6782--------------------------------
bb70624e 6783
b80f6443 6784To determine within a startup script whether or not Bash is running
b8c60bc9
CR
6785interactively, test the value of the ‘-’ special parameter. It contains
6786‘i’ when the shell is interactive. For example:
bb70624e
JA
6787
6788 case "$-" in
6789 *i*) echo This shell is interactive ;;
6790 *) echo This shell is not interactive ;;
6791 esac
6792
b8c60bc9 6793 Alternatively, startup scripts may examine the variable ‘PS1’; it is
28ef6c31 6794unset in non-interactive shells, and set in interactive shells. Thus:
bb70624e
JA
6795
6796 if [ -z "$PS1" ]; then
6797 echo This shell is not interactive
6798 else
6799 echo This shell is interactive
6800 fi
6801
6802\1f
6803File: bashref.info, Node: Interactive Shell Behavior, Prev: Is this Shell Interactive?, Up: Interactive Shells
6804
b80f6443
JA
68056.3.3 Interactive Shell Behavior
6806--------------------------------
bb70624e 6807
b80f6443 6808When the shell is running interactively, it changes its behavior in
bb70624e
JA
6809several ways.
6810
b8c60bc9 6811 1. Bash reads and executes startup files as described in *note Bash
bb70624e
JA
6812 Startup Files::.
6813
28ef6c31 6814 2. Job Control (*note Job Control::) is enabled by default. When job
bb70624e 6815 control is in effect, Bash ignores the keyboard-generated job
b8c60bc9
CR
6816 control signals ‘SIGTTIN’, ‘SIGTTOU’, and ‘SIGTSTP’.
6817
6818 3. Bash executes the values of the set elements of the
6819 ‘PROMPT_COMMAND’ array variable as commands before printing the
6820 primary prompt, ‘$PS1’ (*note Bash Variables::).
bb70624e 6821
b8c60bc9
CR
6822 4. Bash expands and displays ‘PS1’ before reading the first line of a
6823 command, and expands and displays ‘PS2’ before reading the second
d233b485 6824 and subsequent lines of a multi-line command. Bash expands and
b8c60bc9 6825 displays ‘PS0’ after it reads a command but before executing it.
d233b485
CR
6826 See *note Controlling the Prompt::, for a complete list of prompt
6827 string escape sequences.
bb70624e 6828
b8c60bc9 6829 5. Bash uses Readline (*note Command Line Editing::) to read commands
bb70624e
JA
6830 from the user's terminal.
6831
b8c60bc9
CR
6832 6. Bash inspects the value of the ‘ignoreeof’ option to ‘set -o’
6833 instead of exiting immediately when it receives an ‘EOF’ on its
28ef6c31 6834 standard input when reading a command (*note The Set Builtin::).
bb70624e 6835
b8c60bc9
CR
6836 7. Bash enables Command history (*note Bash History Facilities::) and
6837 history expansion (*note History Interaction::) by default. When a
6838 shell with history enabled exits, Bash saves the command history to
6839 the file named by ‘$HISTFILE’.
bb70624e 6840
28ef6c31 6841 8. Alias expansion (*note Aliases::) is performed by default.
bb70624e 6842
b8c60bc9 6843 9. In the absence of any traps, Bash ignores ‘SIGTERM’ (*note
28ef6c31 6844 Signals::).
bb70624e 6845
b8c60bc9
CR
6846 10. In the absence of any traps, ‘SIGINT’ is caught and handled (*note
6847 Signals::). ‘SIGINT’ will interrupt some shell builtins.
bb70624e 6848
b8c60bc9
CR
6849 11. An interactive login shell sends a ‘SIGHUP’ to all jobs on exit if
6850 the ‘huponexit’ shell option has been enabled (*note Signals::).
bb70624e 6851
b8c60bc9
CR
6852 12. The ‘-n’ option has no effect, whether at invocation or when using
6853 ‘set -n’ (*note The Set Builtin::).
bb70624e 6854
a0c0a00f 6855 13. Bash will check for mail periodically, depending on the values of
b8c60bc9 6856 the ‘MAIL’, ‘MAILPATH’, and ‘MAILCHECK’ shell variables (*note Bash
a0c0a00f 6857 Variables::).
bb70624e 6858
b8c60bc9
CR
6859 14. The shell will not exit on expansion errors due to references to
6860 unbound shell variables after ‘set -u’ has been enabled (*note The
6861 Set Builtin::).
bb70624e 6862
a0c0a00f 6863 15. The shell will not exit on expansion errors caused by VAR being
b8c60bc9 6864 unset or null in ‘${VAR:?WORD}’ expansions (*note Shell Parameter
28ef6c31 6865 Expansion::).
bb70624e 6866
a0c0a00f
CR
6867 16. Redirection errors encountered by shell builtins will not cause
6868 the shell to exit.
bb70624e 6869
a0c0a00f 6870 17. When running in POSIX mode, a special builtin returning an error
28ef6c31 6871 status will not cause the shell to exit (*note Bash POSIX Mode::).
bb70624e 6872
b8c60bc9 6873 18. A failed ‘exec’ will not cause the shell to exit (*note Bourne
28ef6c31 6874 Shell Builtins::).
bb70624e 6875
a0c0a00f 6876 19. Parser syntax errors will not cause the shell to exit.
bb70624e 6877
b8c60bc9
CR
6878 20. If the ‘cdspell’ shell option is enabled, the shell will attempt
6879 simple spelling correction for directory arguments to the ‘cd’
6880 builtin (see the description of the ‘cdspell’ option to the ‘shopt’
6881 builtin in *note The Shopt Builtin::). The ‘cdspell’ option is
74091dd4 6882 only effective in interactive shells.
bb70624e 6883
b8c60bc9 6884 21. The shell will check the value of the ‘TMOUT’ variable and exit if
bb70624e 6885 a command is not read within the specified number of seconds after
b8c60bc9 6886 printing ‘$PS1’ (*note Bash Variables::).
bb70624e
JA
6887
6888\1f
6889File: bashref.info, Node: Bash Conditional Expressions, Next: Shell Arithmetic, Prev: Interactive Shells, Up: Bash Features
6890
b80f6443
JA
68916.4 Bash Conditional Expressions
6892================================
bb70624e 6893
b8c60bc9
CR
6894Conditional expressions are used by the ‘[[’ compound command (*note
6895Conditional Constructs::) and the ‘test’ and ‘[’ builtin commands (*note
6896Bourne Shell Builtins::). The ‘test’ and ‘[’ commands determine their
74091dd4
CR
6897behavior based on the number of arguments; see the descriptions of those
6898commands for any other command-specific actions.
d233b485 6899
b8c60bc9
CR
6900 Expressions may be unary or binary, and are formed from the primaries
6901listed below. Unary expressions are often used to examine the status of
6902a file or shell variable. Binary operators are used for string,
6903numeric, and file attribute comparisons.
6904
6905 Bash handles several filenames specially when they are used in
d233b485 6906expressions. If the operating system on which Bash is running provides
b8c60bc9 6907these special files, Bash uses them; otherwise it emulates them
d233b485 6908internally with this behavior: If the FILE argument to one of the
b8c60bc9
CR
6909primaries is of the form ‘/dev/fd/N’, then Bash checks file descriptor
6910N. If the FILE argument to one of the primaries is one of ‘/dev/stdin’,
6911‘/dev/stdout’, or ‘/dev/stderr’, Bash checks file descriptor 0, 1, or 2,
6912respectively.
bb70624e 6913
b8c60bc9
CR
6914 When used with ‘[[’, the ‘<’ and ‘>’ operators sort lexicographically
6915using the current locale. The ‘test’ command uses ASCII ordering.
0001803f 6916
95732b49
JA
6917 Unless otherwise specified, primaries that operate on files follow
6918symbolic links and operate on the target of the link, rather than the
6919link itself.
6920
b8c60bc9 6921‘-a FILE’
bb70624e
JA
6922 True if FILE exists.
6923
b8c60bc9 6924‘-b FILE’
bb70624e
JA
6925 True if FILE exists and is a block special file.
6926
b8c60bc9 6927‘-c FILE’
bb70624e
JA
6928 True if FILE exists and is a character special file.
6929
b8c60bc9 6930‘-d FILE’
bb70624e
JA
6931 True if FILE exists and is a directory.
6932
b8c60bc9 6933‘-e FILE’
bb70624e
JA
6934 True if FILE exists.
6935
b8c60bc9 6936‘-f FILE’
bb70624e
JA
6937 True if FILE exists and is a regular file.
6938
b8c60bc9 6939‘-g FILE’
bb70624e
JA
6940 True if FILE exists and its set-group-id bit is set.
6941
b8c60bc9 6942‘-h FILE’
bb70624e
JA
6943 True if FILE exists and is a symbolic link.
6944
b8c60bc9 6945‘-k FILE’
bb70624e
JA
6946 True if FILE exists and its "sticky" bit is set.
6947
b8c60bc9 6948‘-p FILE’
bb70624e
JA
6949 True if FILE exists and is a named pipe (FIFO).
6950
b8c60bc9 6951‘-r FILE’
bb70624e
JA
6952 True if FILE exists and is readable.
6953
b8c60bc9 6954‘-s FILE’
bb70624e
JA
6955 True if FILE exists and has a size greater than zero.
6956
b8c60bc9 6957‘-t FD’
bb70624e 6958 True if file descriptor FD is open and refers to a terminal.
ccc6cda3 6959
b8c60bc9 6960‘-u FILE’
ccc6cda3
JA
6961 True if FILE exists and its set-user-id bit is set.
6962
b8c60bc9 6963‘-w FILE’
ccc6cda3
JA
6964 True if FILE exists and is writable.
6965
b8c60bc9 6966‘-x FILE’
ccc6cda3
JA
6967 True if FILE exists and is executable.
6968
b8c60bc9 6969‘-G FILE’
ccc6cda3
JA
6970 True if FILE exists and is owned by the effective group id.
6971
b8c60bc9 6972‘-L FILE’
cce855bc
JA
6973 True if FILE exists and is a symbolic link.
6974
b8c60bc9
CR
6975‘-N FILE’
6976 True if FILE exists and has been modified since it was last
6977 accessed.
495aee44 6978
b8c60bc9 6979‘-O FILE’
495aee44
CR
6980 True if FILE exists and is owned by the effective user id.
6981
b8c60bc9 6982‘-S FILE’
cce855bc
JA
6983 True if FILE exists and is a socket.
6984
b8c60bc9 6985‘FILE1 -ef FILE2’
495aee44 6986 True if FILE1 and FILE2 refer to the same device and inode numbers.
cce855bc 6987
b8c60bc9 6988‘FILE1 -nt FILE2’
a0c0a00f
CR
6989 True if FILE1 is newer (according to modification date) than FILE2,
6990 or if FILE1 exists and FILE2 does not.
ccc6cda3 6991
b8c60bc9 6992‘FILE1 -ot FILE2’
7117c2d2
JA
6993 True if FILE1 is older than FILE2, or if FILE2 exists and FILE1
6994 does not.
ccc6cda3 6995
b8c60bc9 6996‘-o OPTNAME’
495aee44 6997 True if the shell option OPTNAME is enabled. The list of options
b8c60bc9 6998 appears in the description of the ‘-o’ option to the ‘set’ builtin
28ef6c31 6999 (*note The Set Builtin::).
ccc6cda3 7000
b8c60bc9 7001‘-v VARNAME’
495aee44 7002 True if the shell variable VARNAME is set (has been assigned a
b8c60bc9
CR
7003 value). If VARNAME is an indexed array variable name subscripted
7004 by ‘@’ or ‘*’, this returns true if the array has any set elements.
7005 If VARNAME is an associative array variable name subscripted by ‘@’
7006 or ‘*’, this returns true if an element with that key is set.
495aee44 7007
b8c60bc9 7008‘-R VARNAME’
ac50fbac
CR
7009 True if the shell variable VARNAME is set and is a name reference.
7010
b8c60bc9 7011‘-z STRING’
ccc6cda3
JA
7012 True if the length of STRING is zero.
7013
b8c60bc9
CR
7014‘-n STRING’
7015‘STRING’
ccc6cda3
JA
7016 True if the length of STRING is non-zero.
7017
b8c60bc9
CR
7018‘STRING1 == STRING2’
7019‘STRING1 = STRING2’
7020 True if the strings are equal. When used with the ‘[[’ command,
ac50fbac
CR
7021 this performs pattern matching as described above (*note
7022 Conditional Constructs::).
7023
b8c60bc9 7024 ‘=’ should be used with the ‘test’ command for POSIX conformance.
ccc6cda3 7025
b8c60bc9 7026‘STRING1 != STRING2’
ccc6cda3
JA
7027 True if the strings are not equal.
7028
b8c60bc9 7029‘STRING1 < STRING2’
0001803f 7030 True if STRING1 sorts before STRING2 lexicographically.
ccc6cda3 7031
b8c60bc9 7032‘STRING1 > STRING2’
0001803f 7033 True if STRING1 sorts after STRING2 lexicographically.
ccc6cda3 7034
b8c60bc9
CR
7035‘ARG1 OP ARG2’
7036 ‘OP’ is one of ‘-eq’, ‘-ne’, ‘-lt’, ‘-le’, ‘-gt’, or ‘-ge’. These
ccc6cda3
JA
7037 arithmetic binary operators return true if ARG1 is equal to, not
7038 equal to, less than, less than or equal to, greater than, or
7039 greater than or equal to ARG2, respectively. ARG1 and ARG2 may be
b8c60bc9 7040 positive or negative integers. When used with the ‘[[’ command,
d233b485 7041 ARG1 and ARG2 are evaluated as arithmetic expressions (*note Shell
b8c60bc9
CR
7042 Arithmetic::). Since the expansions the ‘[[’ command performs on
7043 ARG1 and ARG2 can potentially result in empty strings, arithmetic
7044 expression evaluation treats those as expressions that evaluate to
7045 0.
ccc6cda3 7046
ccc6cda3 7047\1f
bb70624e 7048File: bashref.info, Node: Shell Arithmetic, Next: Aliases, Prev: Bash Conditional Expressions, Up: Bash Features
ccc6cda3 7049
b80f6443
JA
70506.5 Shell Arithmetic
7051====================
ccc6cda3 7052
b80f6443 7053The shell allows arithmetic expressions to be evaluated, as one of the
b8c60bc9
CR
7054shell expansions or by using the ‘((’ compound command, the ‘let’ and
7055‘declare’ builtins, the arithmetic ‘for’ command, the ‘[[’ conditional
7056command, or the ‘-i’ option to the ‘declare’ builtin.
7057
7058 Evaluation is done in the largest fixed-width integers available,
7059with no check for overflow, though division by 0 is trapped and flagged
7060as an error. The operators and their precedence, associativity, and
7061values are the same as in the C language. The following list of
7062operators is grouped into levels of equal-precedence operators. The
7063levels are listed in order of decreasing precedence.
7064
7065‘ID++ ID--’
bb70624e 7066 variable post-increment and post-decrement
d166f048 7067
b8c60bc9 7068‘++ID --ID’
bb70624e 7069 variable pre-increment and pre-decrement
ccc6cda3 7070
b8c60bc9 7071‘- +’
bb70624e 7072 unary minus and plus
ccc6cda3 7073
b8c60bc9 7074‘! ~’
bb70624e 7075 logical and bitwise negation
ccc6cda3 7076
b8c60bc9 7077‘**’
bb70624e 7078 exponentiation
ccc6cda3 7079
b8c60bc9 7080‘* / %’
bb70624e 7081 multiplication, division, remainder
ccc6cda3 7082
b8c60bc9 7083‘+ -’
bb70624e 7084 addition, subtraction
ccc6cda3 7085
b8c60bc9 7086‘<< >>’
bb70624e 7087 left and right bitwise shifts
cce855bc 7088
b8c60bc9 7089‘<= >= < >’
bb70624e 7090 comparison
cce855bc 7091
b8c60bc9 7092‘== !=’
bb70624e 7093 equality and inequality
cce855bc 7094
b8c60bc9 7095‘&’
bb70624e 7096 bitwise AND
cce855bc 7097
b8c60bc9 7098‘^’
bb70624e 7099 bitwise exclusive OR
cce855bc 7100
b8c60bc9 7101‘|’
bb70624e 7102 bitwise OR
cce855bc 7103
b8c60bc9 7104‘&&’
bb70624e 7105 logical AND
ccc6cda3 7106
b8c60bc9 7107‘||’
bb70624e 7108 logical OR
ccc6cda3 7109
b8c60bc9 7110‘expr ? if-true-expr : if-false-expr’
b80f6443 7111 conditional operator
cce855bc 7112
b8c60bc9 7113‘= *= /= %= += -= <<= >>= &= ^= |=’
bb70624e 7114 assignment
ccc6cda3 7115
b8c60bc9 7116‘expr1 , expr2’
bb70624e 7117 comma
ccc6cda3 7118
bb70624e
JA
7119 Shell variables are allowed as operands; parameter expansion is
7120performed before the expression is evaluated. Within an expression,
7121shell variables may also be referenced by name without using the
b8c60bc9
CR
7122parameter expansion syntax. This means you can use X, where X is a
7123shell variable name, in an arithmetic expression, and the shell will
7124evaluate its value as an expression and use the result. A shell
7125variable that is null or unset evaluates to 0 when referenced by name in
7126an expression.
7127
7128 The value of a variable is evaluated as an arithmetic expression when
7129it is referenced, or when a variable which has been given the ‘integer’
7130attribute using ‘declare -i’ is assigned a value. A null value
7131evaluates to 0. A shell variable need not have its ‘integer’ attribute
7132turned on to be used in an expression.
ccc6cda3 7133
8868edaf
CR
7134 Integer constants follow the C language definition, without suffixes
7135or character constants. Constants with a leading 0 are interpreted as
b8c60bc9
CR
7136octal numbers. A leading ‘0x’ or ‘0X’ denotes hexadecimal. Otherwise,
7137numbers take the form [BASE‘#’]N, where the optional BASE is a decimal
8868edaf 7138number between 2 and 64 representing the arithmetic base, and N is a
b8c60bc9 7139number in that base. If BASE‘#’ is omitted, then base 10 is used. When
8868edaf 7140specifying N, if a non-digit is required, the digits greater than 9 are
b8c60bc9
CR
7141represented by the lowercase letters, the uppercase letters, ‘@’, and
7142‘_’, in that order. If BASE is less than or equal to 36, lowercase and
8868edaf
CR
7143uppercase letters may be used interchangeably to represent numbers
7144between 10 and 35.
ccc6cda3 7145
b8c60bc9 7146 Operators are evaluated in precedence order. Sub-expressions in
bb70624e
JA
7147parentheses are evaluated first and may override the precedence rules
7148above.
ccc6cda3 7149
bb70624e
JA
7150\1f
7151File: bashref.info, Node: Aliases, Next: Arrays, Prev: Shell Arithmetic, Up: Bash Features
ccc6cda3 7152
b80f6443
JA
71536.6 Aliases
7154===========
ccc6cda3 7155
b8c60bc9
CR
7156“Aliases” allow a string to be substituted for a word that is in a
7157position in the input where it can be the first word of a simple
7158command. Aliases have names and corresponding values that are set and
7159unset using the ‘alias’ and ‘unalias’ builtin commands (*note Shell
7160Builtin Commands::).
7161
7162 If the shell reads an unquoted word in the right position, it checks
7163the word to see if it matches an alias name. If it matches, the shell
7164replaces the word with the alias value, and reads that value as if it
7165had been read instead of the word. The shell doesn't look at any
7166characters following the word before attempting alias substitution.
7167
7168 The characters ‘/’, ‘$’, ‘`’, ‘=’ and any of the shell metacharacters
7169or quoting characters listed above may not appear in an alias name. The
7170replacement text may contain any valid shell input, including shell
7171metacharacters. The first word of the replacement text is tested for
7172aliases, but a word that is identical to an alias being expanded is not
7173expanded a second time. This means that one may alias ‘ls’ to ‘"ls
7174-F"’, for instance, and Bash does not try to recursively expand the
7175replacement text.
7176
7177 If the last character of the alias value is a ‘blank’, then the shell
7178checks the next command word following the alias for alias expansion.
7179
7180 Aliases are created and listed with the ‘alias’ command, and removed
7181with the ‘unalias’ command.
cce855bc 7182
a0c0a00f 7183 There is no mechanism for using arguments in the replacement text, as
b8c60bc9
CR
7184in ‘csh’. If arguments are needed, use a shell function (*note Shell
7185Functions::) instead.
cce855bc
JA
7186
7187 Aliases are not expanded when the shell is not interactive, unless
b8c60bc9 7188the ‘expand_aliases’ shell option is set using ‘shopt’ (*note The Shopt
3185942a 7189Builtin::).
ccc6cda3 7190
cce855bc 7191 The rules concerning the definition and use of aliases are somewhat
d233b485
CR
7192confusing. Bash always reads at least one complete line of input, and
7193all lines that make up a compound command, before executing any of the
7194commands on that line or the compound command. Aliases are expanded
7195when a command is read, not when it is executed. Therefore, an alias
a0c0a00f 7196definition appearing on the same line as another command does not take
b8c60bc9
CR
7197effect until the shell reads the next line of input, and an alias
7198definition in a compound command does not take effect until the shell
7199parses and executes the entire compound command. The commands following
7200the alias definition on that line, or in the rest of a compound command,
7201are not affected by the new alias. This behavior is also an issue when
7202functions are executed. Aliases are expanded when a function definition
7203is read, not when the function is executed, because a function
7204definition is itself a command. As a consequence, aliases defined in a
7205function are not available until after that function is executed. To be
7206safe, always put alias definitions on a separate line, and do not use
7207‘alias’ in compound commands.
ccc6cda3 7208
b8c60bc9 7209 For almost every purpose, shell functions are preferable to aliases.
ccc6cda3
JA
7210
7211\1f
cce855bc 7212File: bashref.info, Node: Arrays, Next: The Directory Stack, Prev: Aliases, Up: Bash Features
ccc6cda3 7213
b80f6443
JA
72146.7 Arrays
7215==========
ccc6cda3 7216
3185942a 7217Bash provides one-dimensional indexed and associative array variables.
b8c60bc9
CR
7218Any variable may be used as an indexed array; the ‘declare’ builtin
7219explicitly declares an array. There is no maximum limit on the size of
a0c0a00f 7220an array, nor any requirement that members be indexed or assigned
b8c60bc9
CR
7221contiguously. Indexed arrays are referenced using arithmetic
7222expressions that must expand to an integer (*note Shell Arithmetic::))
7223and are zero-based; associative arrays use arbitrary strings. Unless
7224otherwise noted, indexed array indices must be non-negative integers.
7225
7226 The shell performs parameter and variable expansion, arithmetic
7227expansion, command substitution, and quote removal on indexed array
7228subscripts. Since this can potentially result in empty strings,
7229subscript indexing treats those as expressions that evaluate to 0.
7230
7231 The shell performs tilde expansion, parameter and variable expansion,
7232arithmetic expansion, command substitution, and quote removal on
7233associative array subscripts. Empty strings cannot be used as
7234associative array keys.
7235
7236 Bash automatically creates an indexed array if any variable is
7237assigned to using the syntax
ac50fbac 7238 NAME[SUBSCRIPT]=VALUE
ccc6cda3
JA
7239
7240The SUBSCRIPT is treated as an arithmetic expression that must evaluate
b8c60bc9
CR
7241to a number greater than or equal to zero. To explicitly declare an
7242indexed array, use
ccc6cda3 7243 declare -a NAME
b8c60bc9 7244(*note Bash Builtins::). The syntax
ccc6cda3 7245 declare -a NAME[SUBSCRIPT]
a0c0a00f 7246is also accepted; the SUBSCRIPT is ignored.
3185942a 7247
ac50fbac 7248Associative arrays are created using
8868edaf 7249 declare -A NAME
3185942a 7250
b8c60bc9
CR
7251 Attributes may be specified for an array variable using the ‘declare’
7252and ‘readonly’ builtins. Each attribute applies to all members of an
a0c0a00f 7253array.
ccc6cda3 7254
b8c60bc9 7255 Arrays are assigned using compound assignments of the form
ac50fbac 7256 NAME=(VALUE1 VALUE2 ... )
b8c60bc9
CR
7257where each VALUE may be of the form ‘[SUBSCRIPT]=’STRING. Indexed array
7258assignments do not require anything but STRING.
3185942a 7259
b8c60bc9
CR
7260 Each VALUE in the list undergoes the shell expansions described above
7261(*note Shell Expansions::), but VALUEs that are valid variable
7262assignments including the brackets and subscript do not undergo brace
7263expansion and word splitting, as with individual variable assignments.
7264
7265 When assigning to indexed arrays, if the optional subscript is
7266supplied, that index is assigned to; otherwise the index of the element
7267assigned is the last index assigned to by the statement plus one.
7268Indexing starts at zero.
8868edaf
CR
7269
7270 When assigning to an associative array, the words in a compound
7271assignment may be either assignment statements, for which the subscript
7272is required, or a list of words that is interpreted as a sequence of
7273alternating keys and values: NAME=(KEY1 VALUE1 KEY2 VALUE2 ... ). These
7274are treated identically to NAME=( [KEY1]=VALUE1 [KEY2]=VALUE2 ... ).
7275The first word in the list determines how the remaining words are
7276interpreted; all assignments in a list must be of the same type. When
7277using key/value pairs, the keys may not be missing or empty; a final
7278missing value is treated like the empty string.
3185942a 7279
b8c60bc9
CR
7280 This syntax is also accepted by the ‘declare’ builtin. Individual
7281array elements may be assigned to using the ‘NAME[SUBSCRIPT]=VALUE’
3185942a 7282syntax introduced above.
ccc6cda3 7283
ac50fbac
CR
7284 When assigning to an indexed array, if NAME is subscripted by a
7285negative number, that number is interpreted as relative to one greater
7286than the maximum index of NAME, so negative indices count back from the
7287end of the array, and an index of -1 references the last element.
7288
b8c60bc9
CR
7289 The ‘+=’ operator appends to an array variable when assigning using
7290the compound assignment syntax; see *note Shell Parameters:: above.
7291
7292 An array element is referenced using ‘${NAME[SUBSCRIPT]}’. The
7293braces are required to avoid conflicts with the shell's filename
7294expansion operators. If the SUBSCRIPT is ‘@’ or ‘*’, the word expands
7295to all members of the array NAME, unless otherwise noted in the
7296description of a builtin or word expansion. These subscripts differ
7297only when the word appears within double quotes. If the word is
7298double-quoted, ‘${NAME[*]}’ expands to a single word with the value of
7299each array member separated by the first character of the ‘IFS’
7300variable, and ‘${NAME[@]}’ expands each element of NAME to a separate
7301word. When there are no array members, ‘${NAME[@]}’ expands to nothing.
7302If the double-quoted expansion occurs within a word, the expansion of
7303the first parameter is joined with the beginning part of the expansion
7304of the original word, and the expansion of the last parameter is joined
7305with the last part of the expansion of the original word. This is
7306analogous to the expansion of the special parameters ‘@’ and ‘*’.
7307
7308 ‘${#NAME[SUBSCRIPT]}’ expands to the length of ‘${NAME[SUBSCRIPT]}’.
7309If SUBSCRIPT is ‘@’ or ‘*’, the expansion is the number of elements in
7310the array.
7311
7312 If the SUBSCRIPT used to reference an element of an indexed array
7313evaluates to a number less than zero, it is interpreted as relative to
7314one greater than the maximum index of the array, so negative indices
7315count back from the end of the array, and an index of -1 refers to the
7316last element.
a0c0a00f
CR
7317
7318 Referencing an array variable without a subscript is equivalent to
7319referencing with a subscript of 0. Any reference to a variable using a
b8c60bc9 7320valid subscript is valid; Bash creates an array if necessary.
ccc6cda3 7321
0001803f
CR
7322 An array variable is considered set if a subscript has been assigned
7323a value. The null string is a valid value.
7324
ac50fbac
CR
7325 It is possible to obtain the keys (indices) of an array as well as
7326the values. ${!NAME[@]} and ${!NAME[*]} expand to the indices assigned
7327in array variable NAME. The treatment when in double quotes is similar
b8c60bc9 7328to the expansion of the special parameters ‘@’ and ‘*’ within double
ac50fbac
CR
7329quotes.
7330
b8c60bc9
CR
7331 The ‘unset’ builtin is used to destroy arrays. ‘unset
7332NAME[SUBSCRIPT]’ unsets the array element at index SUBSCRIPT. Negative
7333subscripts to indexed arrays are interpreted as described above.
7334Unsetting the last element of an array variable does not unset the
7335variable. ‘unset NAME’, where NAME is an array, removes the entire
7336array. ‘unset NAME[SUBSCRIPT]’ behaves differently depending on the
7337array type when SUBSCRIPT is ‘*’ or ‘@’. When NAME is an associative
7338array, it removes the element with key ‘*’ or ‘@’. If NAME is an
7339indexed array, ‘unset’ removes all of the elements, but does not remove
7340the array itself.
d233b485
CR
7341
7342 When using a variable name with a subscript as an argument to a
b8c60bc9
CR
7343command, such as with ‘unset’, without using the word expansion syntax
7344described above (e.g., unset a[4]), the argument is subject to the
7345shell's filename expansion. Quote the argument if pathname expansion is
7346not desired (e.g., unset 'a[4]').
7347
7348 The ‘declare’, ‘local’, and ‘readonly’ builtins each accept a ‘-a’
7349option to specify an indexed array and a ‘-A’ option to specify an
7350associative array. If both options are supplied, ‘-A’ takes precedence.
7351The ‘read’ builtin accepts a ‘-a’ option to assign a list of words read
ac50fbac 7352from the standard input to an array, and can read values from the
b8c60bc9 7353standard input into individual array elements. The ‘set’ and ‘declare’
ac50fbac 7354builtins display array values in a way that allows them to be reused as
b8c60bc9
CR
7355input. Other builtins accept array name arguments as well (e.g.,
7356‘mapfile’); see the descriptions of individual builtins for details.
7357The shell provides a number of builtin array variables.
ccc6cda3
JA
7358
7359\1f
ac50fbac 7360File: bashref.info, Node: The Directory Stack, Next: Controlling the Prompt, Prev: Arrays, Up: Bash Features
cce855bc 7361
b80f6443
JA
73626.8 The Directory Stack
7363=======================
cce855bc 7364
bb70624e
JA
7365* Menu:
7366
7367* Directory Stack Builtins:: Bash builtin commands to manipulate
7368 the directory stack.
7369
a0c0a00f 7370The directory stack is a list of recently-visited directories. The
b8c60bc9
CR
7371‘pushd’ builtin adds directories to the stack as it changes the current
7372directory, and the ‘popd’ builtin removes specified directories from the
a0c0a00f 7373stack and changes the current directory to the directory removed. The
b8c60bc9 7374‘dirs’ builtin displays the contents of the directory stack. The
a0c0a00f 7375current directory is always the "top" of the directory stack.
cce855bc
JA
7376
7377 The contents of the directory stack are also visible as the value of
b8c60bc9 7378the ‘DIRSTACK’ shell variable.
cce855bc 7379
bb70624e
JA
7380\1f
7381File: bashref.info, Node: Directory Stack Builtins, Up: The Directory Stack
7382
b80f6443
JA
73836.8.1 Directory Stack Builtins
7384------------------------------
bb70624e 7385
b8c60bc9 7386‘dirs’
ac50fbac
CR
7387 dirs [-clpv] [+N | -N]
7388
b8c60bc9
CR
7389 Without options, display the list of currently remembered
7390 directories. Directories are added to the list with the ‘pushd’
7391 command; the ‘popd’ command removes directories from the list. The
7392 current directory is always the first directory in the stack.
7393
7394 Options, if supplied, have the following meanings:
cce855bc 7395
b8c60bc9 7396 ‘-c’
cce855bc 7397 Clears the directory stack by deleting all of the elements.
b8c60bc9 7398 ‘-l’
ac50fbac
CR
7399 Produces a listing using full pathnames; the default listing
7400 format uses a tilde to denote the home directory.
b8c60bc9
CR
7401 ‘-p’
7402 Causes ‘dirs’ to print the directory stack with one entry per
cce855bc 7403 line.
b8c60bc9
CR
7404 ‘-v’
7405 Causes ‘dirs’ to print the directory stack with one entry per
cce855bc 7406 line, prefixing each entry with its index in the stack.
b8c60bc9 7407 ‘+N’
a0c0a00f 7408 Displays the Nth directory (counting from the left of the list
b8c60bc9 7409 printed by ‘dirs’ when invoked without options), starting with
a0c0a00f 7410 zero.
b8c60bc9 7411 ‘-N’
ac50fbac 7412 Displays the Nth directory (counting from the right of the
b8c60bc9 7413 list printed by ‘dirs’ when invoked without options), starting
ac50fbac
CR
7414 with zero.
7415
b8c60bc9 7416‘popd’
ac50fbac 7417 popd [-n] [+N | -N]
cce855bc 7418
b8c60bc9
CR
7419 Remove elements from the directory stack. The elements are
7420 numbered from 0 starting at the first directory listed by ‘dirs’;
7421 that is, ‘popd’ is equivalent to ‘popd +0’.
74091dd4 7422
b8c60bc9 7423 When no arguments are given, ‘popd’ removes the top directory from
74091dd4
CR
7424 the stack and changes to the new top directory.
7425
7426 Arguments, if supplied, have the following meanings:
ac50fbac 7427
b8c60bc9
CR
7428 ‘-n’
7429 Suppress the normal change of directory when removing
7430 directories from the stack, only manipulate the stack.
7431 ‘+N’
7432 Remove the Nth directory (counting from the left of the list
7433 printed by ‘dirs’), starting with zero, from the stack.
7434 ‘-N’
7435 Remove the Nth directory (counting from the right of the list
7436 printed by ‘dirs’), starting with zero, from the stack.
7437
7438 If the top element of the directory stack is modified, and the ‘-n’
7439 option was not supplied, ‘popd’ uses the ‘cd’ builtin to change to
7440 the directory at the top of the stack. If the ‘cd’ fails, ‘popd’
74091dd4
CR
7441 returns a non-zero value.
7442
b8c60bc9
CR
7443 Otherwise, ‘popd’ returns an unsuccessful status if an invalid
7444 option is specified, the directory stack is empty, or N specifies a
7445 non-existent directory stack entry.
74091dd4 7446
b8c60bc9 7447 If the ‘popd’ command is successful, Bash runs ‘dirs’ to show the
74091dd4 7448 final contents of the directory stack, and the return status is 0.
cce855bc 7449
b8c60bc9 7450‘pushd’
ac50fbac 7451 pushd [-n] [+N | -N | DIR]
cce855bc 7452
b8c60bc9 7453 Add a directory to the top of the directory stack, or rotate the
74091dd4 7454 stack, making the new top of the stack the current working
b8c60bc9 7455 directory. With no arguments, ‘pushd’ exchanges the top two
74091dd4
CR
7456 elements of the directory stack.
7457
7458 Arguments, if supplied, have the following meanings:
cce855bc 7459
b8c60bc9
CR
7460 ‘-n’
7461 Suppress the normal change of directory when rotating or
7462 adding directories to the stack, only manipulate the stack.
7463 ‘+N’
7464 Rotate the stack so that the Nth directory (counting from the
7465 left of the list printed by ‘dirs’, starting with zero) is at
7466 the top.
7467 ‘-N’
7468 Rotate the stack so that the Nth directory (counting from the
7469 right of the list printed by ‘dirs’, starting with zero) is at
7470 the top.
7471 ‘DIR’
7472 Make DIR be the top of the stack.
7473
7474 After the stack has been modified, if the ‘-n’ option was not
7475 supplied, ‘pushd’ uses the ‘cd’ builtin to change to the directory
7476 at the top of the stack. If the ‘cd’ fails, ‘pushd’ returns a
74091dd4
CR
7477 non-zero value.
7478
b8c60bc9
CR
7479 Otherwise, if no arguments are supplied, ‘pushd’ returns zero
7480 unless the directory stack is empty. When rotating the directory
7481 stack, ‘pushd’ returns zero unless the directory stack is empty or
7482 N specifies a non-existent directory stack element.
74091dd4 7483
b8c60bc9 7484 If the ‘pushd’ command is successful, Bash runs ‘dirs’ to show the
74091dd4 7485 final contents of the directory stack.
b80f6443 7486
cce855bc 7487\1f
ac50fbac 7488File: bashref.info, Node: Controlling the Prompt, Next: The Restricted Shell, Prev: The Directory Stack, Up: Bash Features
ccc6cda3 7489
b80f6443
JA
74906.9 Controlling the Prompt
7491==========================
ccc6cda3 7492
b8c60bc9
CR
7493In addition, the following table describes the special characters which
7494can appear in the prompt variables ‘PS0’, ‘PS1’, ‘PS2’, and ‘PS4’:
ccc6cda3 7495
b8c60bc9 7496‘\a’
cce855bc 7497 A bell character.
b8c60bc9 7498‘\d’
cce855bc 7499 The date, in "Weekday Month Date" format (e.g., "Tue May 26").
b8c60bc9
CR
7500‘\D{FORMAT}’
7501 The FORMAT is passed to ‘strftime’(3) and the result is inserted
7117c2d2
JA
7502 into the prompt string; an empty FORMAT results in a
7503 locale-specific time representation. The braces are required.
b8c60bc9 7504‘\e’
cce855bc 7505 An escape character.
b8c60bc9
CR
7506‘\h’
7507 The hostname, up to the first ‘.’.
7508‘\H’
cce855bc 7509 The hostname.
b8c60bc9 7510‘\j’
bb70624e 7511 The number of jobs currently managed by the shell.
b8c60bc9
CR
7512‘\l’
7513 The basename of the shell's terminal device name (e.g., "ttys0").
7514‘\n’
cce855bc 7515 A newline.
b8c60bc9 7516‘\r’
cce855bc 7517 A carriage return.
b8c60bc9
CR
7518‘\s’
7519 The name of the shell: the basename of ‘$0’ (the portion following
ccc6cda3 7520 the final slash).
b8c60bc9 7521‘\t’
cce855bc 7522 The time, in 24-hour HH:MM:SS format.
b8c60bc9 7523‘\T’
cce855bc 7524 The time, in 12-hour HH:MM:SS format.
b8c60bc9 7525‘\@’
cce855bc 7526 The time, in 12-hour am/pm format.
b8c60bc9 7527‘\A’
f73dda09 7528 The time, in 24-hour HH:MM format.
b8c60bc9 7529‘\u’
cce855bc 7530 The username of the current user.
b8c60bc9
CR
7531‘\v’
7532 The Bash version (e.g., 2.00).
7533‘\V’
7534 The Bash release, version + patchlevel (e.g., 2.00.0).
7535‘\w’
7536 The value of the ‘PWD’ shell variable (‘$PWD’), with ‘$HOME’
7537 abbreviated with a tilde (uses the ‘$PROMPT_DIRTRIM’ variable).
7538‘\W’
7539 The basename of ‘$PWD’, with ‘$HOME’ abbreviated with a tilde.
7540‘\!’
cce855bc 7541 The history number of this command.
b8c60bc9 7542‘\#’
cce855bc 7543 The command number of this command.
b8c60bc9
CR
7544‘\$’
7545 If the effective uid is 0, ‘#’, otherwise ‘$’.
7546‘\NNN’
cce855bc 7547 The character whose ASCII code is the octal value NNN.
b8c60bc9 7548‘\\’
cce855bc 7549 A backslash.
b8c60bc9
CR
7550‘\[’
7551 Begin a sequence of non-printing characters. Thiss could be used
7552 to embed a terminal control sequence into the prompt.
7553‘\]’
cce855bc 7554 End a sequence of non-printing characters.
ccc6cda3 7555
bb70624e
JA
7556 The command number and the history number are usually different: the
7557history number of a command is its position in the history list, which
7558may include commands restored from the history file (*note Bash History
28ef6c31
JA
7559Facilities::), while the command number is the position in the sequence
7560of commands executed during the current shell session.
bb70624e
JA
7561
7562 After the string is decoded, it is expanded via parameter expansion,
7563command substitution, arithmetic expansion, and quote removal, subject
b8c60bc9 7564to the value of the ‘promptvars’ shell option (*note The Shopt
8868edaf
CR
7565Builtin::). This can have unwanted side effects if escaped portions of
7566the string appear within command substitution or contain characters
7567special to word expansion.
bb70624e 7568
ccc6cda3 7569\1f
ac50fbac 7570File: bashref.info, Node: The Restricted Shell, Next: Bash POSIX Mode, Prev: Controlling the Prompt, Up: Bash Features
ccc6cda3 7571
b80f6443
JA
75726.10 The Restricted Shell
7573=========================
ccc6cda3 7574
b8c60bc9
CR
7575If Bash is started with the name ‘rbash’, or the ‘--restricted’ or ‘-r’
7576option is supplied at invocation, the shell becomes RESTRICTED. A
ccc6cda3 7577restricted shell is used to set up an environment more controlled than
b8c60bc9 7578the standard shell. A restricted shell behaves identically to ‘bash’
7117c2d2
JA
7579with the exception that the following are disallowed or not performed:
7580
b8c60bc9
CR
7581 • Changing directories with the ‘cd’ builtin.
7582 • Setting or unsetting the values of the ‘SHELL’, ‘PATH’, ‘HISTFILE’,
7583 ‘ENV’, or ‘BASH_ENV’ variables.
7584 • Specifying command names containing slashes.
7585 • Specifying a filename containing a slash as an argument to the ‘.’
ccc6cda3 7586 builtin command.
b8c60bc9
CR
7587 • Using the ‘-p’ option to the ‘.’ builtin command to specify a
7588 search path.
7589 • Specifying a filename containing a slash as an argument to the
7590 ‘history’ builtin command.
7591 • Specifying a filename containing a slash as an argument to the ‘-p’
7592 option to the ‘hash’ builtin command.
7593 • Importing function definitions from the shell environment at
ccc6cda3 7594 startup.
b8c60bc9 7595 • Parsing the value of ‘SHELLOPTS’ from the shell environment at
cce855bc 7596 startup.
b8c60bc9 7597 • Redirecting output using the ‘>’, ‘>|’, ‘<>’, ‘>&’, ‘&>’, and ‘>>’
ccc6cda3 7598 redirection operators.
b8c60bc9
CR
7599 • Using the ‘exec’ builtin to replace the shell with another command.
7600 • Adding or deleting builtin commands with the ‘-f’ and ‘-d’ options
7601 to the ‘enable’ builtin.
7602 • Using the ‘enable’ builtin command to enable disabled shell
7117c2d2 7603 builtins.
b8c60bc9
CR
7604 • Specifying the ‘-p’ option to the ‘command’ builtin.
7605 • Turning off restricted mode with ‘set +r’ or ‘shopt -u
7606 restricted_shell’.
ccc6cda3 7607
7117c2d2
JA
7608 These restrictions are enforced after any startup files are read.
7609
7610 When a command that is found to be a shell script is executed (*note
b8c60bc9 7611Shell Scripts::), ‘rbash’ turns off any restrictions in the shell
7117c2d2
JA
7612spawned to execute the script.
7613
8868edaf 7614 The restricted shell mode is only one component of a useful
b8c60bc9 7615restricted environment. It should be accompanied by setting ‘PATH’ to a
8868edaf 7616value that allows execution of only a few verified commands (commands
74091dd4 7617that allow shell escapes are particularly vulnerable), changing the
b8c60bc9 7618current directory to a non-writable directory other than ‘$HOME’ after
74091dd4
CR
7619login, not allowing the restricted shell to execute shell scripts, and
7620cleaning the environment of variables that cause some commands to modify
b8c60bc9 7621their behavior (e.g., ‘VISUAL’ or ‘PAGER’).
8868edaf
CR
7622
7623 Modern systems provide more secure ways to implement a restricted
b8c60bc9 7624environment, such as ‘jails’, ‘zones’, or ‘containers’.
8868edaf 7625
ccc6cda3 7626\1f
8868edaf 7627File: bashref.info, Node: Bash POSIX Mode, Next: Shell Compatibility Mode, Prev: The Restricted Shell, Up: Bash Features
ccc6cda3 7628
b8c60bc9
CR
76296.11 Bash and POSIX
7630===================
ccc6cda3 7631
b8c60bc9
CR
76326.11.1 What is POSIX?
7633---------------------
ccc6cda3 7634
b8c60bc9
CR
7635POSIX is the name for a family of standards based on Unix. A number of
7636Unix services, tools, and functions are part of the standard, ranging
7637from the basic system calls and C library functions to common
7638applications and tools to system administration and management.
7639
7640 The POSIX Shell and Utilities standard was originally developed by
7641IEEE Working Group 1003.2 (POSIX.2). The first edition of the 1003.2
7642standard was published in 1992. It was merged with the original IEEE
76431003.1 Working Group and is currently maintained by the Austin Group (a
7644joint working group of the IEEE, The Open Group and ISO/IEC SC22/WG15).
7645Today the Shell and Utilities are a volume within the set of documents
7646that make up IEEE Std 1003.1-2024, and thus the former POSIX.2 (from
76471992) is now part of the current unified POSIX standard.
7648
7649 The Shell and Utilities volume concentrates on the command
7650interpreter interface and utility programs commonly executed from the
7651command line or by other programs. The standard is freely available on
7652the web at
7653<https://pubs.opengroup.org/onlinepubs/9799919799/utilities/contents.html>.
7654
7655 Bash is concerned with the aspects of the shell's behavior defined by
7656the POSIX Shell and Utilities volume. The shell command language has of
7657course been standardized, including the basic flow control and program
7658execution constructs, I/O redirection and pipelines, argument handling,
7659variable expansion, and quoting.
7660
7661 The special builtins, which must be implemented as part of the shell
7662to provide the desired functionality, are specified as being part of the
7663shell; examples of these are ‘eval’ and ‘export’. Other utilities
7664appear in the sections of POSIX not devoted to the shell which are
7665commonly (and in some cases must be) implemented as builtin commands,
7666such as ‘read’ and ‘test’. POSIX also specifies aspects of the shell's
7667interactive behavior, including job control and command line editing.
7668Only vi-style line editing commands have been standardized; emacs
7669editing commands were left out due to objections.
7670
76716.11.2 Bash POSIX Mode
7672----------------------
7117c2d2 7673
b8c60bc9
CR
7674Although Bash is an implementation of the POSIX shell specification,
7675there are areas where the Bash default behavior differs from the
7676specification. The Bash “posix mode” changes the Bash behavior in these
7677areas so that it conforms more strictly to the standard.
ccc6cda3 7678
b8c60bc9
CR
7679 Starting Bash with the ‘--posix’ command-line option or executing
7680‘set -o posix’ while Bash is running will cause Bash to conform more
7681closely to the POSIX standard by changing the behavior to match that
7682specified by POSIX in areas where the Bash default differs.
d233b485 7683
b8c60bc9
CR
7684 When invoked as ‘sh’, Bash enters POSIX mode after reading the
7685startup files.
ccc6cda3 7686
b8c60bc9 7687 The following list is what's changed when POSIX mode is in effect:
ccc6cda3 7688
b8c60bc9 7689 1. Bash ensures that the ‘POSIXLY_CORRECT’ variable is set.
8868edaf 7690
b8c60bc9
CR
7691 2. Bash reads and executes the POSIX startup files (‘$ENV’) rather
7692 than the normal Bash files (*note Bash Startup Files::.
ccc6cda3 7693
b8c60bc9 7694 3. Alias expansion is always enabled, even in non-interactive shells.
95732b49 7695
b8c60bc9 7696 4. Reserved words appearing in a context where reserved words are
95732b49 7697 recognized do not undergo alias expansion.
ccc6cda3 7698
b8c60bc9
CR
7699 5. Alias expansion is performed when initially parsing a command
7700 substitution. The default (non-posix) mode generally defers it,
7701 when enabled, until the command substitution is executed. This
7702 means that command substitution will not expand aliases that are
7703 defined after the command substitution is initially parsed (e.g.,
7704 as part of a function definition).
74091dd4 7705
b8c60bc9
CR
7706 6. The ‘time’ reserved word may be used by itself as a simple command.
7707 When used in this way, it displays timing statistics for the shell
7708 and its completed children. The ‘TIMEFORMAT’ variable controls the
7709 format of the timing information.
ccc6cda3 7710
b8c60bc9
CR
7711 7. The parser does not recognize ‘time’ as a reserved word if the next
7712 token begins with a ‘-’.
ccc6cda3 7713
b8c60bc9
CR
7714 8. When parsing and expanding a ${...} expansion that appears within
7715 double quotes, single quotes are no longer special and cannot be
7716 used to quote a closing brace or other special character, unless
7717 the operator is one of those defined to perform pattern removal.
7718 In this case, they do not have to appear as matched pairs.
ccc6cda3 7719
b8c60bc9
CR
7720 9. Redirection operators do not perform filename expansion on the word
7721 in a redirection unless the shell is interactive.
b80f6443 7722
b8c60bc9
CR
7723 10. Redirection operators do not perform word splitting on the word in
7724 a redirection.
495aee44 7725
b8c60bc9
CR
7726 11. Function names may not be the same as one of the POSIX special
7727 builtins.
7728
7729 12. Tilde expansion is only performed on assignments preceding a
7730 command name, rather than on all assignment statements on the line.
7731
7732 13. While variable indirection is available, it may not be applied to
7733 the ‘#’ and ‘?’ special parameters.
bb70624e 7734
b8c60bc9
CR
7735 14. Expanding the ‘*’ special parameter in a pattern context where the
7736 expansion is double-quoted does not treat the ‘$*’ as if it were
7737 double-quoted.
7738
7739 15. A double quote character (‘"’) is treated specially when it
7740 appears in a backquoted command substitution in the body of a
7741 here-document that undergoes expansion. That means, for example,
7742 that a backslash preceding a double quote character will escape it
7743 and the backslash will be removed.
7744
7745 16. Command substitutions don't set the ‘?’ special parameter. The
7746 exit status of a simple command without a command word is still the
7747 exit status of the last command substitution that occurred while
7748 evaluating the variable assignments and redirections in that
7749 command, but that does not happen until after all of the
7750 assignments and redirections.
7751
7752 17. Literal tildes that appear as the first character in elements of
7753 the ‘PATH’ variable are not expanded as described above under *note
7754 Tilde Expansion::.
ccc6cda3 7755
b8c60bc9
CR
7756 18. Command lookup finds POSIX special builtins before shell
7757 functions, including output printed by the ‘type’ and ‘command’
ac50fbac
CR
7758 builtins.
7759
b8c60bc9
CR
7760 19. Even if a shell function whose name contains a slash was defined
7761 before entering POSIX mode, the shell will not execute a function
7762 whose name contains one or more slashes.
ccc6cda3 7763
b8c60bc9
CR
7764 20. When a command in the hash table no longer exists, Bash will
7765 re-search ‘$PATH’ to find the new location. This is also available
7766 with ‘shopt -s checkhash’.
a0c0a00f 7767
b8c60bc9
CR
7768 21. Bash will not insert a command without the execute bit set into
7769 the command hash table, even if it returns it as a (last-ditch)
7770 result from a ‘$PATH’ search.
a0c0a00f 7771
b8c60bc9
CR
7772 22. The message printed by the job control code and builtins when a
7773 job exits with a non-zero status is 'Done(status)'.
495aee44 7774
b8c60bc9
CR
7775 23. The message printed by the job control code and builtins when a
7776 job is stopped is 'Stopped(SIGNAME)', where SIGNAME is, for
7777 example, ‘SIGTSTP’.
7778
7779 24. If the shell is interactive, Bash does not perform job
7780 notifications between executing commands in lists separated by ‘;’
7781 or newline. Non-interactive shells print status messages after a
7782 foreground job in a list completes.
7783
7784 25. If the shell is interactive, Bash waits until the next prompt
7785 before printing the status of a background job that changes status
7786 or a foreground job that terminates due to a signal.
7787 Non-interactive shells print status messages after a foreground job
7788 completes.
7789
7790 26. Bash permanently removes jobs from the jobs table after notifying
7791 the user of their termination via the ‘wait’ or ‘jobs’ builtins.
7792 It removes the job from the jobs list after notifying the user of
7793 its termination, but the status is still available via ‘wait’, as
7794 long as ‘wait’ is supplied a PID argument.
495aee44 7795
b8c60bc9
CR
7796 27. The ‘vi’ editing mode will invoke the ‘vi’ editor directly when
7797 the ‘v’ command is run, instead of checking ‘$VISUAL’ and
7798 ‘$EDITOR’.
495aee44 7799
b8c60bc9
CR
7800 28. Prompt expansion enables the POSIX ‘PS1’ and ‘PS2’ expansions of
7801 ‘!’ to the history number and ‘!!’ to ‘!’, and Bash performs
7802 parameter expansion on the values of ‘PS1’ and ‘PS2’ regardless of
7803 the setting of the ‘promptvars’ option.
a0c0a00f 7804
b8c60bc9
CR
7805 29. The default history file is ‘~/.sh_history’ (this is the default
7806 value the shell assigns to ‘$HISTFILE’).
7807
7808 30. The ‘!’ character does not introduce history expansion within a
7809 double-quoted string, even if the ‘histexpand’ option is enabled.
7810
7811 31. When printing shell function definitions (e.g., by ‘type’), Bash
7812 does not print the ‘function’ reserved word unless necessary.
7813
7814 32. Non-interactive shells exit if a syntax error in an arithmetic
7815 expansion results in an invalid expression.
7816
7817 33. Non-interactive shells exit if a parameter expansion error occurs.
7818
7819 34. If a POSIX special builtin returns an error status, a
ccc6cda3 7820 non-interactive shell exits. The fatal errors are those listed in
0628567a 7821 the POSIX standard, and include things like passing incorrect
ccc6cda3
JA
7822 options, redirection errors, variable assignment errors for
7823 assignments preceding the command name, and so on.
7824
b8c60bc9 7825 35. A non-interactive shell exits with an error status if a variable
ccc6cda3
JA
7826 assignment error occurs when no command name follows the assignment
7827 statements. A variable assignment error occurs, for example, when
cce855bc 7828 trying to assign a value to a readonly variable.
ccc6cda3 7829
b8c60bc9 7830 36. A non-interactive shell exits with an error status if a variable
495aee44 7831 assignment error occurs in an assignment statement preceding a
74091dd4
CR
7832 special builtin, but not with any other simple command. For any
7833 other simple command, the shell aborts execution of that command,
7834 and execution continues at the top level ("the shell shall not
7835 perform any further processing of the command in which the error
7836 occurred").
495aee44 7837
b8c60bc9
CR
7838 37. A non-interactive shell exits with an error status if the
7839 iteration variable in a ‘for’ statement or the selection variable
7840 in a ‘select’ statement is a readonly variable or has an invalid
7841 name.
ccc6cda3 7842
b8c60bc9 7843 38. Non-interactive shells exit if FILENAME in ‘.’ FILENAME is not
a0c0a00f 7844 found.
ccc6cda3 7845
b8c60bc9
CR
7846 39. Non-interactive shells exit if there is a syntax error in a script
7847 read with the ‘.’ or ‘source’ builtins, or in a string processed by
7848 the ‘eval’ builtin.
a0c0a00f 7849
b8c60bc9
CR
7850 40. Non-interactive shells exit if the ‘export’, ‘readonly’ or ‘unset’
7851 builtin commands get an argument that is not a valid identifier,
7852 and they are not operating on shell functions. These errors force
7853 an exit because these are special builtins.
a0c0a00f 7854
b8c60bc9 7855 41. Assignment statements preceding POSIX special builtins persist in
0628567a 7856 the shell environment after the builtin completes.
ccc6cda3 7857
b8c60bc9 7858 42. The ‘command’ builtin does not prevent builtins that take
a0c0a00f 7859 assignment statements as arguments from expanding them as
b8c60bc9 7860 assignment statements; when not in POSIX mode, declaration commands
a0c0a00f 7861 lose their assignment statement expansion properties when preceded
b8c60bc9 7862 by ‘command’.
a0c0a00f 7863
b8c60bc9
CR
7864 43. Enabling POSIX mode has the effect of setting the
7865 ‘inherit_errexit’ option, so subshells spawned to execute command
7866 substitutions inherit the value of the ‘-e’ option from the parent
7867 shell. When the ‘inherit_errexit’ option is not enabled, Bash
7868 clears the ‘-e’ option in such subshells.
a0c0a00f 7869
b8c60bc9
CR
7870 44. Enabling POSIX mode has the effect of setting the ‘shift_verbose’
7871 option, so numeric arguments to ‘shift’ that exceed the number of
7872 positional parameters will result in an error message.
a0c0a00f 7873
b8c60bc9
CR
7874 45. Enabling POSIX mode has the effect of setting the
7875 ‘interactive_comments’ option (*note Comments::).
a0c0a00f 7876
b8c60bc9
CR
7877 46. The ‘.’ and ‘source’ builtins do not search the current directory
7878 for the filename argument if it is not found by searching ‘PATH’.
d166f048 7879
b8c60bc9
CR
7880 47. When the ‘alias’ builtin displays alias definitions, it does not
7881 display them with a leading ‘alias ’ unless the ‘-p’ option is
7882 supplied.
28ef6c31 7883
b8c60bc9
CR
7884 48. The ‘bg’ builtin uses the required format to describe each job
7885 placed in the background, which does not include an indication of
7886 whether the job is the current or previous job.
28ef6c31 7887
b8c60bc9
CR
7888 49. When the ‘cd’ builtin is invoked in logical mode, and the pathname
7889 constructed from ‘$PWD’ and the directory name supplied as an
7890 argument does not refer to an existing directory, ‘cd’ will fail
7891 instead of falling back to physical mode.
8868edaf 7892
b8c60bc9
CR
7893 50. When the ‘cd’ builtin cannot change a directory because the length
7894 of the pathname constructed from ‘$PWD’ and the directory name
7895 supplied as an argument exceeds ‘PATH_MAX’ when canonicalized, ‘cd’
7896 will attempt to use the supplied directory name.
28ef6c31 7897
b8c60bc9
CR
7898 51. When the ‘xpg_echo’ option is enabled, Bash does not attempt to
7899 interpret any arguments to ‘echo’ as options. ‘echo’ displays each
7900 argument after converting escape sequences.
28ef6c31 7901
b8c60bc9
CR
7902 52. The ‘export’ and ‘readonly’ builtin commands display their output
7903 in the format required by POSIX.
d233b485 7904
b8c60bc9
CR
7905 53. When listing the history, the ‘fc’ builtin does not include an
7906 indication of whether or not a history entry has been modified.
b80f6443 7907
b8c60bc9 7908 54. The default editor used by ‘fc’ is ‘ed’.
28ef6c31 7909
b8c60bc9 7910 55. ‘fc’ treats extra arguments as an error instead of ignoring them.
ccc6cda3 7911
b8c60bc9
CR
7912 56. If there are too many arguments supplied to ‘fc -s’, ‘fc’ prints
7913 an error message and returns failure.
7117c2d2 7914
b8c60bc9
CR
7915 57. The output of ‘kill -l’ prints all the signal names on a single
7916 line, separated by spaces, without the ‘SIG’ prefix.
d233b485 7917
b8c60bc9
CR
7918 58. The ‘kill’ builtin does not accept signal names with a ‘SIG’
7919 prefix.
7920
7921 59. The ‘kill’ builtin returns a failure status if any of the pid or
7922 job arguments are invalid or if sending the specified signal to any
7923 of them fails. In default mode, ‘kill’ returns success if the
7924 signal was successfully sent to any of the specified processes.
7925
7926 60. The ‘printf’ builtin uses ‘double’ (via ‘strtod’) to convert
7927 arguments corresponding to floating point conversion specifiers,
7928 instead of ‘long double’ if it's available. The ‘L’ length
7929 modifier forces ‘printf’ to use ‘long double’ if it's available.
7930
7931 61. The ‘pwd’ builtin verifies that the value it prints is the same as
95732b49 7932 the current directory, even if it is not asked to check the file
b8c60bc9 7933 system with the ‘-P’ option.
95732b49 7934
b8c60bc9
CR
7935 62. The ‘read’ builtin may be interrupted by a signal for which a trap
7936 has been set. If Bash receives a trapped signal while executing
7937 ‘read’, the trap handler executes and ‘read’ returns an exit status
7938 greater than 128.
7939
7940 63. When the ‘set’ builtin is invoked without options, it does not
7941 display shell function names and definitions.
7942
7943 64. When the ‘set’ builtin is invoked without options, it displays
7944 variable values without quotes, unless they contain shell
7945 metacharacters, even if the result contains nonprinting characters.
7946
7947 65. The ‘test’ builtin compares strings using the current locale when
7948 evaluating the ‘<’ and ‘>’ binary operators.
95732b49 7949
b8c60bc9
CR
7950 66. The ‘test’ builtin's ‘-t’ unary primary requires an argument.
7951 Historical versions of ‘test’ made the argument optional in certain
7952 cases, and Bash attempts to accommodate those for backwards
7953 compatibility.
95732b49 7954
b8c60bc9
CR
7955 67. The ‘trap’ builtin displays signal names without the leading
7956 ‘SIG’.
7957
7958 68. The ‘trap’ builtin doesn't check the first argument for a possible
7959 signal specification and revert the signal handling to the original
7960 disposition if it is, unless that argument consists solely of
7961 digits and is a valid signal number. If users want to reset the
7962 handler for a given signal to the original disposition, they should
7963 use ‘-’ as the first argument.
7964
7965 69. ‘trap -p’ without arguments displays signals whose dispositions
7966 are set to SIG_DFL and those that were ignored when the shell
7967 started, not just trapped signals.
7968
7969 70. The ‘type’ and ‘command’ builtins will not report a non-executable
a0c0a00f 7970 file as having been found, though the shell will attempt to execute
b8c60bc9 7971 such a file if it is the only so-named file found in ‘$PATH’.
ccc6cda3 7972
b8c60bc9
CR
7973 71. The ‘ulimit’ builtin uses a block size of 512 bytes for the ‘-c’
7974 and ‘-f’ options.
ccc6cda3 7975
b8c60bc9
CR
7976 72. The ‘unset’ builtin with the ‘-v’ option specified returns a fatal
7977 error if it attempts to unset a ‘readonly’ or ‘non-unsettable’
7978 variable, which causes a non-interactive shell to exit.
28ef6c31 7979
b8c60bc9
CR
7980 73. When asked to unset a variable that appears in an assignment
7981 statement preceding the command, the ‘unset’ builtin attempts to
7982 unset a variable of the same name in the current or previous scope
7983 as well. This implements the required "if an assigned variable is
7984 further modified by the utility, the modifications made by the
7985 utility shall persist" behavior.
3185942a 7986
b8c60bc9
CR
7987 74. The arrival of ‘SIGCHLD’ when a trap is set on ‘SIGCHLD’ does not
7988 interrupt the ‘wait’ builtin and cause it to return immediately.
0001803f
CR
7989 The trap command is run once for each child that exits.
7990
b8c60bc9
CR
7991 75. Bash removes an exited background process's status from the list
7992 of such statuses after the ‘wait’ builtin returns it.
28ef6c31 7993
b8c60bc9
CR
7994 There is additional POSIX behavior that Bash does not implement by
7995default even when in POSIX mode. Specifically:
95732b49 7996
b8c60bc9
CR
7997 1. POSIX requires that word splitting be byte-oriented. That is, each
7998 _byte_ in the value of ‘IFS’ potentially splits a word, even if
7999 that byte is part of a multibyte character in ‘IFS’ or part of
8000 multibyte character in the word. Bash allows multibyte characters
8001 in the value of ‘IFS’, treating a valid multibyte character as a
8002 single delimiter, and will not split a valid multibyte character
8003 even if one of the bytes composing that character appears in ‘IFS’.
8004 This is POSIX interpretation 1560, further modified by issue 1924.
95732b49 8005
b8c60bc9
CR
8006 2. The ‘fc’ builtin checks ‘$EDITOR’ as a program to edit history
8007 entries if ‘FCEDIT’ is unset, rather than defaulting directly to
8008 ‘ed’. ‘fc’ uses ‘ed’ if ‘EDITOR’ is unset.
95732b49 8009
b8c60bc9
CR
8010 3. As noted above, Bash requires the ‘xpg_echo’ option to be enabled
8011 for the ‘echo’ builtin to be fully conformant.
95732b49
JA
8012
8013 Bash can be configured to be POSIX-conformant by default, by
b8c60bc9 8014specifying the ‘--enable-strict-posix-default’ to ‘configure’ when
95732b49 8015building (*note Optional Features::).
28ef6c31 8016
8868edaf
CR
8017\1f
8018File: bashref.info, Node: Shell Compatibility Mode, Prev: Bash POSIX Mode, Up: Bash Features
8019
80206.12 Shell Compatibility Mode
8021=============================
8022
b8c60bc9
CR
8023Bash-4.0 introduced the concept of a “shell compatibility level”,
8024specified as a set of options to the shopt builtin (‘compat31’,
8025‘compat32’, ‘compat40’, ‘compat41’, and so on). There is only one
8868edaf
CR
8026current compatibility level - each option is mutually exclusive. The
8027compatibility level is intended to allow users to select behavior from
8028previous versions that is incompatible with newer versions while they
8029migrate scripts to use current features and behavior. It's intended to
8030be a temporary solution.
8031
8032 This section does not mention behavior that is standard for a
b8c60bc9
CR
8033particular version (e.g., setting ‘compat32’ means that quoting the
8034right hand side of the regexp matching operator quotes special regexp
8035characters in the word, which is default behavior in bash-3.2 and
8036subsequent versions).
8868edaf 8037
b8c60bc9 8038 If a user enables, say, ‘compat32’, it may affect the behavior of
8868edaf
CR
8039other compatibility levels up to and including the current compatibility
8040level. The idea is that each compatibility level controls behavior that
8041changed in that version of Bash, but that behavior may have been present
8042in earlier versions. For instance, the change to use locale-based
b8c60bc9
CR
8043comparisons with the ‘[[’ command came in bash-4.1, and earlier versions
8044used ASCII-based comparisons, so enabling ‘compat32’ will enable
8868edaf
CR
8045ASCII-based comparisons as well. That granularity may not be sufficient
8046for all uses, and as a result users should employ compatibility levels
8047carefully. Read the documentation for a particular feature to find out
8048the current behavior.
8049
b8c60bc9 8050 Bash-4.3 introduced a new shell variable: ‘BASH_COMPAT’. The value
8868edaf 8051assigned to this variable (a decimal version number like 4.2, or an
b8c60bc9 8052integer corresponding to the ‘compat’NN option, like 42) determines the
8868edaf
CR
8053compatibility level.
8054
b8c60bc9
CR
8055 Starting with bash-4.4, Bash began deprecating older compatibility
8056levels. Eventually, the options will be removed in favor of
8057‘BASH_COMPAT’.
8868edaf 8058
b8c60bc9
CR
8059 Bash-5.0 was the final version for which there was an individual
8060shopt option for the previous version. ‘BASH_COMPAT’ is the only
8061mechanism to control the compatibility level in versions newer than
8062bash-5.0.
8868edaf
CR
8063
8064 The following table describes the behavior changes controlled by each
b8c60bc9 8065compatibility level setting. The ‘compat’NN tag is used as shorthand
8868edaf
CR
8066for setting the compatibility level to NN using one of the following
8067mechanisms. For versions prior to bash-5.0, the compatibility level may
b8c60bc9
CR
8068be set using the corresponding ‘compat’NN shopt option. For bash-4.3
8069and later versions, the ‘BASH_COMPAT’ variable is preferred, and it is
8868edaf
CR
8070required for bash-5.1 and later versions.
8071
b8c60bc9
CR
8072‘compat31’
8073 • Quoting the rhs of the ‘[[’ command's regexp matching operator
8868edaf
CR
8074 (=~) has no special effect
8075
b8c60bc9
CR
8076‘compat40’
8077 • The ‘<’ and ‘>’ operators to the ‘[[’ command do not consider
8868edaf
CR
8078 the current locale when comparing strings; they use ASCII
8079 ordering. Bash versions prior to bash-4.1 use ASCII collation
8080 and strcmp(3); bash-4.1 and later use the current locale's
8081 collation sequence and strcoll(3).
8082
b8c60bc9
CR
8083‘compat41’
8084 • In POSIX mode, ‘time’ may be followed by options and still be
8868edaf 8085 recognized as a reserved word (this is POSIX interpretation
b8c60bc9
CR
8086 267).
8087 • In POSIX mode, the parser requires that an even number of
8868edaf
CR
8088 single quotes occur in the WORD portion of a double-quoted
8089 ${...} parameter expansion and treats them specially, so that
8090 characters within the single quotes are considered quoted
b8c60bc9 8091 (this is POSIX interpretation 221).
8868edaf 8092
b8c60bc9
CR
8093‘compat42’
8094 • The replacement string in double-quoted pattern substitution
8868edaf 8095 does not undergo quote removal, as it does in versions after
b8c60bc9
CR
8096 bash-4.2.
8097 • In POSIX mode, single quotes are considered special when
8868edaf
CR
8098 expanding the WORD portion of a double-quoted ${...} parameter
8099 expansion and can be used to quote a closing brace or other
8100 special character (this is part of POSIX interpretation 221);
8101 in later versions, single quotes are not special within
b8c60bc9
CR
8102 double-quoted word expansions.
8103
8104‘compat43’
8105 • Word expansion errors are considered non-fatal errors that
8106 cause the current command to fail, even in POSIX mode (the
8868edaf 8107 default behavior is to make them fatal errors that cause the
b8c60bc9
CR
8108 shell to exit).
8109 • When executing a shell function, the loop state
8110 (while/until/etc.) is not reset, so ‘break’ or ‘continue’ in
8868edaf
CR
8111 that function will break or continue loops in the calling
8112 context. Bash-4.4 and later reset the loop state to prevent
b8c60bc9
CR
8113 this.
8114
8115‘compat44’
8116 • The shell sets up the values used by ‘BASH_ARGV’ and
8117 ‘BASH_ARGC’ so they can expand to the shell's positional
8118 parameters even if extended debugging mode is not enabled.
8119 • A subshell inherits loops from its parent context, so ‘break’
8120 or ‘continue’ will cause the subshell to exit. Bash-5.0 and
8121 later reset the loop state to prevent the exit.
8122 • Variable assignments preceding builtins like ‘export’ and
8123 ‘readonly’ that set attributes continue to affect variables
8868edaf 8124 with the same name in the calling environment even if the
b8c60bc9 8125 shell is not in POSIX mode.
8868edaf 8126
b8c60bc9
CR
8127‘compat50 (set using BASH_COMPAT)’
8128 • Bash-5.1 changed the way ‘$RANDOM’ is generated to introduce
8868edaf
CR
8129 slightly more randomness. If the shell compatibility level is
8130 set to 50 or lower, it reverts to the method from bash-5.0 and
8131 previous versions, so seeding the random number generator by
b8c60bc9
CR
8132 assigning a value to ‘RANDOM’ will produce the same sequence
8133 as in bash-5.0.
8134 • If the command hash table is empty, Bash versions prior to
8868edaf
CR
8135 bash-5.1 printed an informational message to that effect, even
8136 when producing output that can be reused as input. Bash-5.1
b8c60bc9 8137 suppresses that message when the ‘-l’ option is supplied.
8868edaf 8138
b8c60bc9
CR
8139‘compat51 (set using BASH_COMPAT)’
8140 • The ‘unset’ builtin will unset the array ‘a’ given an argument
8141 like ‘a[@]’. Bash-5.2 will unset an element with key ‘@’
74091dd4 8142 (associative arrays) or remove all the elements without
b8c60bc9
CR
8143 unsetting the array (indexed arrays).
8144 • Arithmetic commands ( ((...)) ) and the expressions in an
8145 arithmetic for statement can be expanded more than once.
8146 • Expressions used as arguments to arithmetic operators in the
8147 ‘[[’ conditional command can be expanded more than once.
8148 • The expressions in substring parameter brace expansion can be
8149 expanded more than once.
8150 • The expressions in the $(( ... )) word expansion can be
8151 expanded more than once.
8152 • Arithmetic expressions used as indexed array subscripts can be
8153 expanded more than once.
8154 • ‘test -v’, when given an argument of ‘A[@]’, where A is an
74091dd4
CR
8155 existing associative array, will return true if the array has
8156 any set elements. Bash-5.2 will look for and report on a key
b8c60bc9
CR
8157 named ‘@’.
8158 • the ${PARAMETER[:]=VALUE} word expansion will return VALUE,
74091dd4
CR
8159 before any variable-specific transformations have been
8160 performed (e.g., converting to lowercase). Bash-5.2 will
8161 return the final value assigned to the variable.
b8c60bc9
CR
8162 • Parsing command substitutions will behave as if extended
8163 globbing (*note The Shopt Builtin::) is enabled, so that
8164 parsing a command substitution containing an extglob pattern
8165 (say, as part of a shell function) will not fail. This
8166 assumes the intent is to enable extglob before the command is
8167 executed and word expansions are performed. It will fail at
8168 word expansion time if extglob hasn't been enabled by the time
8169 the command is executed.
8170
8171‘compat52 (set using BASH_COMPAT)’
8172 • The ‘test’ builtin uses its historical algorithm to parse
8173 parenthesized subexpressions when given five or more
8174 arguments.
8175 • If the ‘-p’ or ‘-P’ option is supplied to the ‘bind’ builtin,
8176 ‘bind’ treats any arguments remaining after option processing
8177 as bindable command names, and displays any key sequences
8178 bound to those commands, instead of treating the arguments as
8179 key sequences to bind.
8180 • Interactive shells will notify the user of completed jobs
8181 while sourcing a script. Newer versions defer notification
8182 until script execution completes.
74091dd4 8183
ccc6cda3 8184\1f
3185942a 8185File: bashref.info, Node: Job Control, Next: Command Line Editing, Prev: Bash Features, Up: Top
ccc6cda3 8186
b80f6443
JA
81877 Job Control
8188*************
ccc6cda3 8189
b80f6443
JA
8190This chapter discusses what job control is, how it works, and how Bash
8191allows you to access its facilities.
ccc6cda3
JA
8192
8193* Menu:
8194
8195* Job Control Basics:: How job control works.
8196* Job Control Builtins:: Bash builtin commands used to interact
8197 with job control.
8198* Job Control Variables:: Variables Bash uses to customize job
8199 control.
8200
8201\1f
8202File: bashref.info, Node: Job Control Basics, Next: Job Control Builtins, Up: Job Control
8203
b80f6443
JA
82047.1 Job Control Basics
8205======================
ccc6cda3 8206
b80f6443 8207Job control refers to the ability to selectively stop (suspend) the
ccc6cda3
JA
8208execution of processes and continue (resume) their execution at a later
8209point. A user typically employs this facility via an interactive
0001803f
CR
8210interface supplied jointly by the operating system kernel's terminal
8211driver and Bash.
ccc6cda3
JA
8212
8213 The shell associates a JOB with each pipeline. It keeps a table of
b8c60bc9
CR
8214currently executing jobs, which the ‘jobs’ command will display. Each
8215job has a “job number”, which ‘jobs’ displays between brackets. Job
8216numbers start at 1. When Bash starts a job asynchronously, it prints a
8217line that looks like:
ccc6cda3 8218 [1] 25647
a0c0a00f
CR
8219indicating that this job is job number 1 and that the process ID of the
8220last process in the pipeline associated with this job is 25647. All of
8221the processes in a single pipeline are members of the same job. Bash
8222uses the JOB abstraction as the basis for job control.
ccc6cda3
JA
8223
8224 To facilitate the implementation of the user interface to job
b8c60bc9
CR
8225control, each process has a “process group ID”, and the operating system
8226maintains the notion of a current terminal process group ID. This
8227terminal process group ID is associated with the “controlling terminal”.
8228
8229 Processes that have the same process group ID are said to be part of
8230the same “process group”. Members of the foreground process group
8231(processes whose process group ID is equal to the current terminal
8232process group ID) receive keyboard-generated signals such as ‘SIGINT’.
8233Processes in the foreground process group are said to be foreground
8234processes. Background processes are those whose process group ID
8235differs from the controlling terminal's; such processes are immune to
8236keyboard-generated signals. Only foreground processes are allowed to
8237read from or, if the user so specifies with ‘stty tostop’, write to the
8238controlling terminal. The system sends a ‘SIGTTIN’ (‘SIGTTOU’) signal
8239to background processes which attempt to read from (write to when
8240‘tostop’ is in effect) the terminal, which, unless caught, suspends the
8241process.
ccc6cda3
JA
8242
8243 If the operating system on which Bash is running supports job
b8c60bc9
CR
8244control, Bash contains facilities to use it. Typing the “suspend”
8245character (typically ‘^Z’, Control-Z) while a process is running stops
8246that process and returns control to Bash. Typing the “delayed suspend”
8247character (typically ‘^Y’, Control-Y) causes the process to stop when it
8248attempts to read input from the terminal, and returns control to Bash.
8249The user then manipulates the state of this job, using the ‘bg’ command
8250to continue it in the background, the ‘fg’ command to continue it in the
8251foreground, or the ‘kill’ command to kill it. The suspend character
8252takes effect immediately, and has the additional side effect of
8253discarding any pending output and typeahead. If you want to force a
8254background process to stop, or stop a process that's not associated with
8255your terminal session, send it the ‘SIGSTOP’ signal using ‘kill’.
8256
8257 There are a number of ways to refer to a job in the shell. The ‘%’
8258character introduces a “job specification” (jobspec).
8259
8260 Job number ‘n’ may be referred to as ‘%n’. A job may also be
8261referred to using a prefix of the name used to start it, or using a
8262substring that appears in its command line. For example, ‘%ce’ refers
8263to a job whose command name begins with ‘ce’. Using ‘%?ce’, on the
8264other hand, refers to any job containing the string ‘ce’ in its command
8265line. If the prefix or substring matches more than one job, Bash
8266reports an error.
8267
8268 The symbols ‘%%’ and ‘%+’ refer to the shell's notion of the “current
8269job”. A single ‘%’ (with no accompanying job specification) also refers
8270to the current job. ‘%-’ refers to the “previous job”. When a job
8271starts in the background, a job stops while in the foreground, or a job
8272is resumed in the background, it becomes the current job. The job that
8273was the current job becomes the previous job. When the current job
8274terminates, the previous job becomes the current job. If there is only
8275a single job, ‘%+’ and ‘%-’ can both be used to refer to that job. In
8276output pertaining to jobs (e.g., the output of the ‘jobs’ command), the
8277current job is always marked with a ‘+’, and the previous job with a
8278‘-’.
8279
8280 Simply naming a job can be used to bring it into the foreground: ‘%1’
8281is a synonym for ‘fg %1’, bringing job 1 from the background into the
8282foreground. Similarly, ‘%1 &’ resumes job 1 in the background,
8283equivalent to ‘bg %1’.
a0c0a00f
CR
8284
8285 The shell learns immediately whenever a job changes state. Normally,
b8c60bc9
CR
8286Bash waits until it is about to print a prompt before notifying the user
8287about changes in a job's status so as to not interrupt any other output,
8288though it will notify of changes in a job's status after a foreground
8289command in a list completes, before executing the next command in the
8290list. If the ‘-b’ option to the ‘set’ builtin is enabled, Bash reports
8291status changes immediately (*note The Set Builtin::). Bash executes any
8292trap on ‘SIGCHLD’ for each child process that terminates.
8293
8294 When a job terminates and Bash notifies the user about it, Bash
8295removes the job from the jobs table. It will not appear in ‘jobs’
8296output, but ‘wait’ will report its exit status, as long as it's supplied
8297the process ID associated with the job as an argument. When the table
8298is empty, job numbers start over at 1.
8299
8300 If a user attempts to exit Bash while jobs are stopped, (or running,
8301if the ‘checkjobs’ option is enabled - see *note The Shopt Builtin::),
8302the shell prints a warning message, and if the ‘checkjobs’ option is
8303enabled, lists the jobs and their statuses. The ‘jobs’ command may then
8304be used to inspect their status. If the user immediately attempts to
8305exit again, without an intervening command, Bash does not print another
8306warning, and terminates any stopped jobs.
8307
8308 When the shell is waiting for a job or process using the ‘wait’
8309builtin, and job control is enabled, ‘wait’ will return when the job
8310changes state. The ‘-f’ option causes ‘wait’ to wait until the job or
8868edaf 8311process terminates before returning.
d233b485 8312
ccc6cda3
JA
8313\1f
8314File: bashref.info, Node: Job Control Builtins, Next: Job Control Variables, Prev: Job Control Basics, Up: Job Control
8315
b80f6443
JA
83167.2 Job Control Builtins
8317========================
ccc6cda3 8318
b8c60bc9 8319‘bg’
95732b49 8320 bg [JOBSPEC ...]
ac50fbac 8321
95732b49 8322 Resume each suspended job JOBSPEC in the background, as if it had
b8c60bc9
CR
8323 been started with ‘&’. If JOBSPEC is not supplied, the shell uses
8324 its notion of the current job. ‘bg’ returns zero unless it is run
8325 when job control is not enabled, or, when run with job control
8326 enabled, any JOBSPEC was not found or specifies a job that was
8327 started without job control.
ccc6cda3 8328
b8c60bc9 8329‘fg’
ccc6cda3 8330 fg [JOBSPEC]
ac50fbac 8331
cce855bc 8332 Resume the job JOBSPEC in the foreground and make it the current
b8c60bc9
CR
8333 job. If JOBSPEC is not supplied, ‘fg’ resumes the current job.
8334 The return status is that of the command placed into the
8335 foreground, or non-zero if run when job control is disabled or,
8336 when run with job control enabled, JOBSPEC does not specify a valid
8337 job or JOBSPEC specifies a job that was started without job
8338 control.
8339
8340‘jobs’
bb70624e 8341 jobs [-lnprs] [JOBSPEC]
cce855bc 8342 jobs -x COMMAND [ARGUMENTS]
ccc6cda3
JA
8343
8344 The first form lists the active jobs. The options have the
8345 following meanings:
8346
b8c60bc9 8347 ‘-l’
cce855bc 8348 List process IDs in addition to the normal information.
ccc6cda3 8349
b8c60bc9 8350 ‘-n’
ccc6cda3 8351 Display information only about jobs that have changed status
cce855bc 8352 since the user was last notified of their status.
ccc6cda3 8353
b8c60bc9 8354 ‘-p’
ccc6cda3
JA
8355 List only the process ID of the job's process group leader.
8356
b8c60bc9 8357 ‘-r’
ac50fbac 8358 Display only running jobs.
ccc6cda3 8359
b8c60bc9 8360 ‘-s’
ac50fbac 8361 Display only stopped jobs.
ccc6cda3 8362
b8c60bc9
CR
8363 If JOBSPEC is supplied, ‘jobs’ restricts output to information
8364 about that job. If JOBSPEC is not supplied, ‘jobs’ lists the
8365 status of all jobs. The return status is zero unless an invalid
8366 option is encountered or an invalid JOBSPEC is supplied.
ccc6cda3 8367
b8c60bc9 8368 If the ‘-x’ option is supplied, ‘jobs’ replaces any JOBSPEC found
ccc6cda3
JA
8369 in COMMAND or ARGUMENTS with the corresponding process group ID,
8370 and executes COMMAND, passing it ARGUMENTs, returning its exit
8371 status.
8372
b8c60bc9
CR
8373‘kill’
8374 kill [-s SIGSPEC] [-n SIGNUM] [-SIGSPEC] ID [...]
a0c0a00f 8375 kill -l|-L [EXIT_STATUS]
ac50fbac 8376
b8c60bc9
CR
8377 Send a signal specified by SIGSPEC or SIGNUM to the processes named
8378 by each ID. Each ID may be a job specification JOBSPEC or process
8379 ID PID. SIGSPEC is either a case-insensitive signal name such as
8380 ‘SIGINT’ (with or without the ‘SIG’ prefix) or a signal number;
8381 SIGNUM is a signal number. If SIGSPEC and SIGNUM are not present,
8382 ‘kill’ sends ‘SIGTERM’.
8383
8384 The ‘-l’ option lists the signal names. If any arguments are
8385 supplied when ‘-l’ is supplied, ‘kill’ lists the names of the
8386 signals corresponding to the arguments, and the return status is
8387 zero. EXIT_STATUS is a number specifying a signal number or the
8388 exit status of a process terminated by a signal; if it is supplied,
8389 ‘kill’ prints the name of the signal that caused the process to
8390 terminate. ‘kill’ assumes that process exit statuses are greater
8391 than 128; anything less than that is a signal number. The ‘-L’
8392 option is equivalent to ‘-l’.
8393
8394 The return status is zero if at least one signal was successfully
8395 sent, or non-zero if an error occurs or an invalid option is
8396 encountered.
8397
8398‘wait’
8399 wait [-fn] [-p VARNAME] [ID ...]
8400
8401 Wait until the child process specified by each ID exits and return
8402 the exit status of the last ID. Each ID may be a process ID PID or
8403 a job specification JOBSPEC; if a jobspec is supplied, ‘wait’ waits
8404 for all processes in the job.
8405
8406 If no options or IDs are supplied, ‘wait’ waits for all running
8407 background jobs and the last-executed process substitution, if its
8408 process id is the same as $!, and the return status is zero.
8409
8410 If the ‘-n’ option is supplied, ‘wait’ waits for any one of the IDs
8411 or, if no IDs are supplied, any job or process substitution, to
8412 complete and returns its exit status. If none of the supplied IDs
8413 is a child of the shell, or if no arguments are supplied and the
8414 shell has no unwaited-for children, the exit status is 127.
8415
8416 If the ‘-p’ option is supplied, ‘wait’ assigns the process or job
8417 identifier of the job for which the exit status is returned to the
8418 variable VARNAME named by the option argument. The variable, which
8419 cannot be readonly, will be unset initially, before any assignment.
8420 This is useful only when used with the ‘-n’ option.
8421
8422 Supplying the ‘-f’ option, when job control is enabled, forces
8423 ‘wait’ to wait for each ID to terminate before returning its
8424 status, instead of returning when it changes status.
8425
8426 If none of the IDs specify one of the shell's an active child
8427 processes, the return status is 127. If ‘wait’ is interrupted by a
8428 signal, any VARNAME will remain unset, and the return status will
8429 be greater than 128, as described above (*note Signals::).
8430 Otherwise, the return status is the exit status of the last ID.
8431
8432‘disown’
8433 disown [-ar] [-h] [ID ...]
8434
8435 Without options, remove each ID from the table of active jobs.
8436 Each ID may be a job specification JOBSPEC or a process ID PID; if
8437 ID is a PID, ‘disown’ uses the job containing PID as JOBSPEC.
8438
8439 If the ‘-h’ option is supplied, ‘disown’ does not remove the jobs
8440 corresponding to each ‘id’ from the jobs table, but rather marks
8441 them so the shell does not send ‘SIGHUP’ to the job if the shell
8442 receives a ‘SIGHUP’.
8443
8444 If no ID is supplied, the ‘-a’ option means to remove or mark all
8445 jobs; the ‘-r’ option without an ID argument removes or marks
8446 running jobs. If no ID is supplied, and neither the ‘-a’ nor the
8447 ‘-r’ option is supplied, ‘disown’ removes or marks the current job.
8448
8449 The return value is 0 unless an ID does not specify a valid job.
8450
8451‘suspend’
ccc6cda3 8452 suspend [-f]
ac50fbac 8453
b8c60bc9 8454 Suspend the execution of this shell until it receives a ‘SIGCONT’
74091dd4 8455 signal. A login shell, or a shell without job control enabled,
b8c60bc9
CR
8456 cannot be suspended; the ‘-f’ option will override this and force
8457 the suspension. The return status is 0 unless the shell is a login
8458 shell or job control is not enabled and ‘-f’ is not supplied.
ccc6cda3 8459
b8c60bc9 8460 When job control is not active, the ‘kill’ and ‘wait’ builtins do not
a0c0a00f 8461accept JOBSPEC arguments. They must be supplied process IDs.
ccc6cda3
JA
8462
8463\1f
8464File: bashref.info, Node: Job Control Variables, Prev: Job Control Builtins, Up: Job Control
8465
b80f6443
JA
84667.3 Job Control Variables
8467=========================
ccc6cda3 8468
b8c60bc9 8469‘auto_resume’
ccc6cda3 8470 This variable controls how the shell interacts with the user and
b8c60bc9
CR
8471 job control. If this variable exists then simple commands
8472 consisting of only a single word, without redirections, are treated
8473 as candidates for resumption of an existing job. There is no
8474 ambiguity allowed; if there is more than one job beginning with or
8475 containing the word, then this selects the most recently accessed
8476 job. The name of a stopped job, in this context, is the command
8477 line used to start it, as displayed by ‘jobs’. If this variable is
8478 set to the value ‘exact’, the word must match the name of a stopped
8479 job exactly; if set to ‘substring’, the word needs to match a
8480 substring of the name of a stopped job. The ‘substring’ value
8481 provides functionality analogous to the ‘%?string’ job ID (*note
8482 Job Control Basics::). If set to any other value (e.g., ‘prefix’),
8483 the word must be a prefix of a stopped job's name; this provides
8484 functionality analogous to the ‘%string’ job ID.
b80f6443 8485
ccc6cda3 8486\1f
3185942a 8487File: bashref.info, Node: Command Line Editing, Next: Using History Interactively, Prev: Job Control, Up: Top
ccc6cda3 8488
b80f6443
JA
84898 Command Line Editing
8490**********************
ccc6cda3 8491
b80f6443 8492This chapter describes the basic features of the GNU command line
bb70624e
JA
8493editing interface. Command line editing is provided by the Readline
8494library, which is used by several different programs, including Bash.
3185942a 8495Command line editing is enabled by default when using an interactive
b8c60bc9
CR
8496shell, unless the ‘--noediting’ option is supplied at shell invocation.
8497Line editing is also used when using the ‘-e’ option to the ‘read’
3185942a 8498builtin command (*note Bash Builtins::). By default, the line editing
b8c60bc9 8499commands are similar to those of Emacs; a vi-style line editing
3185942a 8500interface is also available. Line editing can be enabled at any time
b8c60bc9
CR
8501using the ‘-o emacs’ or ‘-o vi’ options to the ‘set’ builtin command
8502(*note The Set Builtin::), or disabled using the ‘+o emacs’ or ‘+o vi’
8503options to ‘set’.
ccc6cda3
JA
8504
8505* Menu:
8506
bb70624e
JA
8507* Introduction and Notation:: Notation used in this text.
8508* Readline Interaction:: The minimum set of commands for editing a line.
8509* Readline Init File:: Customizing Readline from a user's view.
8510* Bindable Readline Commands:: A description of most of the Readline commands
8511 available for binding
8512* Readline vi Mode:: A short description of how to make Readline
8513 behave like the vi editor.
bb70624e
JA
8514* Programmable Completion:: How to specify the possible completions for
8515 a specific command.
8516* Programmable Completion Builtins:: Builtin commands to specify how to
8517 complete arguments for a particular command.
ac50fbac
CR
8518* A Programmable Completion Example:: An example shell function for
8519 generating possible completions.
ccc6cda3
JA
8520
8521\1f
bb70624e 8522File: bashref.info, Node: Introduction and Notation, Next: Readline Interaction, Up: Command Line Editing
ccc6cda3 8523
b80f6443
JA
85248.1 Introduction to Line Editing
8525================================
ccc6cda3 8526
b8c60bc9
CR
8527The following paragraphs use Emacs style to describe the notation used
8528to represent keystrokes.
ccc6cda3 8529
b8c60bc9 8530 The text ‘C-k’ is read as 'Control-K' and describes the character
bb70624e 8531produced when the <k> key is pressed while the Control key is depressed.
ccc6cda3 8532
b8c60bc9 8533 The text ‘M-k’ is read as 'Meta-K' and describes the character
bb70624e 8534produced when the Meta key (if you have one) is depressed, and the <k>
b8c60bc9
CR
8535key is pressed (a “meta character”), then both are released. The Meta
8536key is labeled <ALT> or <Option> on many keyboards. On keyboards with
8537two keys labeled <ALT> (usually to either side of the space bar), the
8538<ALT> on the left side is generally set to work as a Meta key. One of
8539the <ALT> keys may also be configured as some other modifier, such as a
bb70624e
JA
8540Compose key for typing accented characters.
8541
b8c60bc9
CR
8542 On some keyboards, the Meta key modifier produces characters with the
8543eighth bit (0200) set. You can use the ‘enable-meta-key’ variable to
8544control whether or not it does this, if the keyboard allows it. On many
8545others, the terminal or terminal emulator converts the metafied key to a
8546key sequence beginning with <ESC> as described in the next paragraph.
8547
bb70624e 8548 If you do not have a Meta or <ALT> key, or another key working as a
b8c60bc9
CR
8549Meta key, you can generally achieve the latter effect by typing <ESC>
8550_first_, and then typing <k>. The <ESC> character is known as the “meta
8551prefix”).
8552
8553 Either process is known as “metafying” the <k> key.
bb70624e 8554
b8c60bc9
CR
8555 If your Meta key produces a key sequence with the <ESC> meta prefix,
8556you can make ‘M-key’ key bindings you specify (see ‘Key Bindings’ in
8557*note Readline Init File Syntax::) do the same thing by setting the
8558‘force-meta-prefix’ variable.
8559
8560 The text ‘M-C-k’ is read as 'Meta-Control-k' and describes the
8561character produced by metafying ‘C-k’.
bb70624e 8562
a0c0a00f
CR
8563 In addition, several keys have their own names. Specifically, <DEL>,
8564<ESC>, <LFD>, <SPC>, <RET>, and <TAB> all stand for themselves when seen
8565in this text, or in an init file (*note Readline Init File::). If your
b8c60bc9 8566keyboard lacks a <LFD> key, typing <C-j> will output the appropriate
a0c0a00f
CR
8567character. The <RET> key may be labeled <Return> or <Enter> on some
8568keyboards.
ccc6cda3
JA
8569
8570\1f
bb70624e 8571File: bashref.info, Node: Readline Interaction, Next: Readline Init File, Prev: Introduction and Notation, Up: Command Line Editing
cce855bc 8572
b80f6443
JA
85738.2 Readline Interaction
8574========================
cce855bc 8575
b80f6443 8576Often during an interactive session you type in a long line of text,
bb70624e
JA
8577only to notice that the first word on the line is misspelled. The
8578Readline library gives you a set of commands for manipulating the text
8579as you type it in, allowing you to just fix your typo, and not forcing
8580you to retype the majority of the line. Using these editing commands,
8581you move the cursor to the place that needs correction, and delete or
8582insert the text of the corrections. Then, when you are satisfied with
28ef6c31
JA
8583the line, you simply press <RET>. You do not have to be at the end of
8584the line to press <RET>; the entire line is accepted regardless of the
8585location of the cursor within the line.
cce855bc 8586
bb70624e 8587* Menu:
cce855bc 8588
bb70624e
JA
8589* Readline Bare Essentials:: The least you need to know about Readline.
8590* Readline Movement Commands:: Moving about the input line.
8591* Readline Killing Commands:: How to delete text, and how to get it back!
8592* Readline Arguments:: Giving numeric arguments to commands.
8593* Searching:: Searching through previous lines.
cce855bc 8594
bb70624e
JA
8595\1f
8596File: bashref.info, Node: Readline Bare Essentials, Next: Readline Movement Commands, Up: Readline Interaction
cce855bc 8597
b80f6443
JA
85988.2.1 Readline Bare Essentials
8599------------------------------
cce855bc 8600
b80f6443
JA
8601In order to enter characters into the line, simply type them. The typed
8602character appears where the cursor was, and then the cursor moves one
8603space to the right. If you mistype a character, you can use your erase
8604character to back up and delete the mistyped character.
cce855bc 8605
a0c0a00f
CR
8606 Sometimes you may mistype a character, and not notice the error until
8607you have typed several other characters. In that case, you can type
b8c60bc9
CR
8608‘C-b’ to move the cursor to the left, and then correct your mistake.
8609Afterwards, you can move the cursor to the right with ‘C-f’.
cce855bc 8610
bb70624e 8611 When you add text in the middle of a line, you will notice that
a0c0a00f
CR
8612characters to the right of the cursor are 'pushed over' to make room for
8613the text that you have inserted. Likewise, when you delete text behind
8614the cursor, characters to the right of the cursor are 'pulled back' to
b8c60bc9
CR
8615fill in the blank space created by the removal of the text. These are
8616the bare essentials for editing the text of an input line:
cce855bc 8617
b8c60bc9 8618‘C-b’
a0c0a00f 8619 Move back one character.
b8c60bc9 8620‘C-f’
bb70624e 8621 Move forward one character.
bb70624e
JA
8622<DEL> or <Backspace>
8623 Delete the character to the left of the cursor.
b8c60bc9 8624‘C-d’
bb70624e 8625 Delete the character underneath the cursor.
bb70624e
JA
8626Printing characters
8627 Insert the character into the line at the cursor.
b8c60bc9 8628‘C-_’ or ‘C-x C-u’
bb70624e
JA
8629 Undo the last editing command. You can undo all the way back to an
8630 empty line.
cce855bc 8631
b8c60bc9 8632Depending on your configuration, the <Backspace> key might be set to
74091dd4 8633delete the character to the left of the cursor and the <DEL> key set to
b8c60bc9
CR
8634delete the character underneath the cursor, like ‘C-d’, rather than the
8635character to the left of the cursor.
cce855bc
JA
8636
8637\1f
bb70624e 8638File: bashref.info, Node: Readline Movement Commands, Next: Readline Killing Commands, Prev: Readline Bare Essentials, Up: Readline Interaction
ccc6cda3 8639
b80f6443
JA
86408.2.2 Readline Movement Commands
8641--------------------------------
ccc6cda3 8642
b80f6443 8643The above table describes the most basic keystrokes that you need in
a0c0a00f 8644order to do editing of the input line. For your convenience, many other
b8c60bc9
CR
8645commands are available in addition to ‘C-b’, ‘C-f’, ‘C-d’, and <DEL>.
8646Here are some commands for moving more rapidly within the line.
ccc6cda3 8647
b8c60bc9 8648‘C-a’
bb70624e 8649 Move to the start of the line.
b8c60bc9 8650‘C-e’
bb70624e 8651 Move to the end of the line.
b8c60bc9 8652‘M-f’
bb70624e
JA
8653 Move forward a word, where a word is composed of letters and
8654 digits.
b8c60bc9 8655‘M-b’
bb70624e 8656 Move backward a word.
b8c60bc9 8657‘C-l’
bb70624e 8658 Clear the screen, reprinting the current line at the top.
ccc6cda3 8659
b8c60bc9 8660 Notice how ‘C-f’ moves forward a character, while ‘M-f’ moves forward
a0c0a00f
CR
8661a word. It is a loose convention that control keystrokes operate on
8662characters while meta keystrokes operate on words.
ccc6cda3
JA
8663
8664\1f
bb70624e 8665File: bashref.info, Node: Readline Killing Commands, Next: Readline Arguments, Prev: Readline Movement Commands, Up: Readline Interaction
ccc6cda3 8666
b80f6443
JA
86678.2.3 Readline Killing Commands
8668-------------------------------
ccc6cda3 8669
b8c60bc9
CR
8670“Killing” text means to delete the text from the line, but to save it
8671away for later use, usually by “yanking” (re-inserting) it back into the
a0c0a00f 8672line. ('Cut' and 'paste' are more recent jargon for 'kill' and 'yank'.)
ccc6cda3 8673
a0c0a00f 8674 If the description for a command says that it 'kills' text, then you
bb70624e
JA
8675can be sure that you can get the text back in a different (or the same)
8676place later.
ccc6cda3 8677
b8c60bc9 8678 When you use a kill command, the text is saved in a “kill-ring”. Any
a0c0a00f 8679number of consecutive kills save all of the killed text together, so
bb70624e
JA
8680that when you yank it back, you get it all. The kill ring is not line
8681specific; the text that you killed on a previously typed line is
a0c0a00f 8682available to be yanked back later, when you are typing another line.
ccc6cda3 8683
bb70624e 8684 Here is the list of commands for killing text.
ccc6cda3 8685
b8c60bc9 8686‘C-k’
bb70624e
JA
8687 Kill the text from the current cursor position to the end of the
8688 line.
ccc6cda3 8689
b8c60bc9 8690‘M-d’
bb70624e
JA
8691 Kill from the cursor to the end of the current word, or, if between
8692 words, to the end of the next word. Word boundaries are the same
b8c60bc9 8693 as those used by ‘M-f’.
ccc6cda3 8694
b8c60bc9 8695‘M-<DEL>’
74091dd4
CR
8696 Kill from the cursor to the start of the current word, or, if
8697 between words, to the start of the previous word. Word boundaries
b8c60bc9 8698 are the same as those used by ‘M-b’.
ccc6cda3 8699
b8c60bc9 8700‘C-w’
a0c0a00f 8701 Kill from the cursor to the previous whitespace. This is different
b8c60bc9 8702 than ‘M-<DEL>’ because the word boundaries differ.
b80f6443 8703
b8c60bc9
CR
8704 Here is how to “yank” the text back into the line. Yanking means to
8705copy the most-recently-killed text from the kill buffer into the line at
8706the current cursor position.
ccc6cda3 8707
b8c60bc9 8708‘C-y’
ccc6cda3
JA
8709 Yank the most recently killed text back into the buffer at the
8710 cursor.
8711
b8c60bc9 8712‘M-y’
ccc6cda3 8713 Rotate the kill-ring, and yank the new top. You can only do this
b8c60bc9 8714 if the prior command is ‘C-y’ or ‘M-y’.
ccc6cda3
JA
8715
8716\1f
8717File: bashref.info, Node: Readline Arguments, Next: Searching, Prev: Readline Killing Commands, Up: Readline Interaction
8718
b80f6443
JA
87198.2.4 Readline Arguments
8720------------------------
ccc6cda3 8721
b80f6443 8722You can pass numeric arguments to Readline commands. Sometimes the
ccc6cda3
JA
8723argument acts as a repeat count, other times it is the sign of the
8724argument that is significant. If you pass a negative argument to a
8725command which normally acts in a forward direction, that command will
8726act in a backward direction. For example, to kill text back to the
b8c60bc9 8727start of the line, you might type ‘M-- C-k’.
ccc6cda3
JA
8728
8729 The general way to pass numeric arguments to a command is to type
a0c0a00f 8730meta digits before the command. If the first 'digit' typed is a minus
b8c60bc9 8731sign (‘-’), then the sign of the argument will be negative. Once you
cce855bc 8732have typed one meta digit to get the argument started, you can type the
a0c0a00f 8733remainder of the digits, and then the command. For example, to give the
b8c60bc9 8734‘C-d’ command an argument of 10, you could type ‘M-1 0 C-d’, which will
a0c0a00f 8735delete the next ten characters on the input line.
ccc6cda3
JA
8736
8737\1f
8738File: bashref.info, Node: Searching, Prev: Readline Arguments, Up: Readline Interaction
8739
b80f6443
JA
87408.2.5 Searching for Commands in the History
8741-------------------------------------------
ccc6cda3 8742
b80f6443 8743Readline provides commands for searching through the command history
28ef6c31 8744(*note Bash History Facilities::) for lines containing a specified
b8c60bc9
CR
8745string. There are two search modes: “incremental” and
8746“non-incremental”.
ccc6cda3
JA
8747
8748 Incremental searches begin before the user has finished typing the
8749search string. As each character of the search string is typed,
cce855bc 8750Readline displays the next entry from the history matching the string
a0c0a00f 8751typed so far. An incremental search requires only as many characters as
b8c60bc9
CR
8752needed to find the desired history entry. When using emacs editing
8753mode, type ‘C-r’ to search backward in the history for a particular
8754string. Typing ‘C-s’ searches forward through the history. The
8755characters present in the value of the ‘isearch-terminators’ variable
8756are used to terminate an incremental search. If that variable has not
8757been assigned a value, the <ESC> and ‘C-j’ characters terminate an
8758incremental search. ‘C-g’ aborts an incremental search and restores the
8759original line. When the search is terminated, the history entry
8760containing the search string becomes the current line.
8761
8762 To find other matching entries in the history list, type ‘C-r’ or
8763‘C-s’ as appropriate. This searches backward or forward in the history
8764for the next entry matching the search string typed so far. Any other
8765key sequence bound to a Readline command terminates the search and
8766executes that command. For instance, a <RET> terminates the search and
8767accepts the line, thereby executing the command from the history list.
8768A movement command will terminate the search, make the last line found
8769the current line, and begin editing.
8770
8771 Readline remembers the last incremental search string. If two ‘C-r’s
a0c0a00f 8772are typed without any intervening characters defining a new search
b8c60bc9 8773string, Readline uses any remembered search string.
f73dda09 8774
ccc6cda3 8775 Non-incremental searches read the entire search string before
b8c60bc9
CR
8776starting to search for matching history entries. The search string may
8777be typed by the user or be part of the contents of the current line.
ccc6cda3
JA
8778
8779\1f
8780File: bashref.info, Node: Readline Init File, Next: Bindable Readline Commands, Prev: Readline Interaction, Up: Command Line Editing
8781
b80f6443
JA
87828.3 Readline Init File
8783======================
ccc6cda3 8784
a0c0a00f
CR
8785Although the Readline library comes with a set of Emacs-like keybindings
8786installed by default, it is possible to use a different set of
8787keybindings. Any user can customize programs that use Readline by
b8c60bc9 8788putting commands in an “inputrc” file, conventionally in their home
bb70624e 8789directory. The name of this file is taken from the value of the shell
b8c60bc9
CR
8790variable ‘INPUTRC’. If that variable is unset, the default is
8791‘~/.inputrc’. If that file does not exist or cannot be read, Readline
8792looks for ‘/etc/inputrc’. The ‘bind’ builtin command can also be used
8793to set Readline keybindings and variables. *Note Bash Builtins::.
ccc6cda3 8794
b8c60bc9
CR
8795 When a program that uses the Readline library starts up, Readline
8796reads the init file and sets any variables and key bindings it contains.
ccc6cda3 8797
b8c60bc9 8798 In addition, the ‘C-x C-r’ command re-reads this init file, thus
ccc6cda3
JA
8799incorporating any changes that you might have made to it.
8800
8801* Menu:
8802
8803* Readline Init File Syntax:: Syntax for the commands in the inputrc file.
ccc6cda3 8804* Conditional Init Constructs:: Conditional key bindings in the inputrc file.
ccc6cda3
JA
8805* Sample Init File:: An example inputrc file.
8806
8807\1f
8808File: bashref.info, Node: Readline Init File Syntax, Next: Conditional Init Constructs, Up: Readline Init File
8809
b80f6443
JA
88108.3.1 Readline Init File Syntax
8811-------------------------------
ccc6cda3 8812
a0c0a00f 8813There are only a few basic constructs allowed in the Readline init file.
b8c60bc9
CR
8814Blank lines are ignored. Lines beginning with a ‘#’ are comments.
8815Lines beginning with a ‘$’ indicate conditional constructs (*note
a0c0a00f
CR
8816Conditional Init Constructs::). Other lines denote variable settings
8817and key bindings.
ccc6cda3
JA
8818
8819Variable Settings
cce855bc 8820 You can modify the run-time behavior of Readline by altering the
b8c60bc9 8821 values of variables in Readline using the ‘set’ command within the
28ef6c31
JA
8822 init file. The syntax is simple:
8823
8824 set VARIABLE VALUE
8825
a0c0a00f 8826 Here, for example, is how to change from the default Emacs-like key
b8c60bc9 8827 binding to use ‘vi’ line editing commands:
ccc6cda3
JA
8828
8829 set editing-mode vi
8830
28ef6c31 8831 Variable names and values, where appropriate, are recognized
95732b49
JA
8832 without regard to case. Unrecognized variable names are ignored.
8833
8834 Boolean variables (those that can be set to on or off) are set to
a0c0a00f
CR
8835 on if the value is null or empty, ON (case-insensitive), or 1. Any
8836 other value results in the variable being set to off.
28ef6c31 8837
b8c60bc9 8838 The ‘bind -V’ command lists the current Readline variable names and
a0c0a00f 8839 values. *Note Bash Builtins::.
bb70624e 8840
cce855bc
JA
8841 A great deal of run-time behavior is changeable with the following
8842 variables.
ccc6cda3 8843
b8c60bc9 8844 ‘active-region-start-color’
74091dd4
CR
8845 A string variable that controls the text color and background
8846 when displaying the text in the active region (see the
b8c60bc9 8847 description of ‘enable-active-region’ below). This string
74091dd4
CR
8848 must not take up any physical character positions on the
8849 display, so it should consist only of terminal escape
8850 sequences. It is output to the terminal before displaying the
8851 text in the active region. This variable is reset to the
8852 default value whenever the terminal type changes. The default
8853 value is the string that puts the terminal in standout mode,
8854 as obtained from the terminal's terminfo description. A
b8c60bc9 8855 sample value might be ‘\e[01;33m’.
74091dd4 8856
b8c60bc9 8857 ‘active-region-end-color’
74091dd4 8858 A string variable that "undoes" the effects of
b8c60bc9 8859 ‘active-region-start-color’ and restores "normal" terminal
74091dd4
CR
8860 display appearance after displaying text in the active region.
8861 This string must not take up any physical character positions
8862 on the display, so it should consist only of terminal escape
8863 sequences. It is output to the terminal after displaying the
8864 text in the active region. This variable is reset to the
8865 default value whenever the terminal type changes. The default
8866 value is the string that restores the terminal from standout
8867 mode, as obtained from the terminal's terminfo description. A
b8c60bc9 8868 sample value might be ‘\e[0m’.
74091dd4 8869
b8c60bc9 8870 ‘bell-style’
a0c0a00f 8871 Controls what happens when Readline wants to ring the terminal
b8c60bc9
CR
8872 bell. If set to ‘none’, Readline never rings the bell. If
8873 set to ‘visible’, Readline uses a visible bell if one is
8874 available. If set to ‘audible’ (the default), Readline
a0c0a00f
CR
8875 attempts to ring the terminal's bell.
8876
b8c60bc9
CR
8877 ‘bind-tty-special-chars’
8878 If set to ‘on’ (the default), Readline attempts to bind the
8879 control characters that are treated specially by the kernel's
8880 terminal driver to their Readline equivalents. These override
8881 the default Readline bindings described here. Type ‘stty -a’
8882 at a Bash prompt to see your current terminal settings,
8883 including the special control characters (usually ‘cchars’).
a0c0a00f 8884
b8c60bc9
CR
8885 ‘blink-matching-paren’
8886 If set to ‘on’, Readline attempts to briefly move the cursor
a0c0a00f 8887 to an opening parenthesis when a closing parenthesis is
b8c60bc9 8888 inserted. The default is ‘off’.
a0c0a00f 8889
b8c60bc9
CR
8890 ‘colored-completion-prefix’
8891 If set to ‘on’, when listing completions, Readline displays
a0c0a00f
CR
8892 the common prefix of the set of possible completions using a
8893 different color. The color definitions are taken from the
b8c60bc9
CR
8894 value of the ‘LS_COLORS’ environment variable. If there is a
8895 color definition in ‘LS_COLORS’ for the custom suffix
8896 ‘readline-colored-completion-prefix’, Readline uses this color
74091dd4 8897 for the common prefix instead of its default. The default is
b8c60bc9 8898 ‘off’.
a0c0a00f 8899
b8c60bc9
CR
8900 ‘colored-stats’
8901 If set to ‘on’, Readline displays possible completions using
ac50fbac 8902 different colors to indicate their file type. The color
b8c60bc9
CR
8903 definitions are taken from the value of the ‘LS_COLORS’
8904 environment variable. The default is ‘off’.
ac50fbac 8905
b8c60bc9
CR
8906 ‘comment-begin’
8907 The string to insert at the beginning of the line by the
8908 ‘insert-comment’ command. The default value is ‘"#"’.
ccc6cda3 8909
b8c60bc9 8910 ‘completion-display-width’
495aee44
CR
8911 The number of screen columns used to display possible matches
8912 when performing completion. The value is ignored if it is
8913 less than 0 or greater than the terminal screen width. A
b8c60bc9
CR
8914 value of 0 causes matches to be displayed one per line. The
8915 default value is -1.
495aee44 8916
b8c60bc9
CR
8917 ‘completion-ignore-case’
8918 If set to ‘on’, Readline performs filename matching and
cce855bc 8919 completion in a case-insensitive fashion. The default value
b8c60bc9 8920 is ‘off’.
cce855bc 8921
b8c60bc9
CR
8922 ‘completion-map-case’
8923 If set to ‘on’, and COMPLETION-IGNORE-CASE is enabled,
8924 Readline treats hyphens (‘-’) and underscores (‘_’) as
495aee44 8925 equivalent when performing case-insensitive filename matching
b8c60bc9
CR
8926 and completion. The default value is ‘off’.
8927
8928 ‘completion-prefix-display-length’
8929 The maximum length in characters of the common prefix of a
8930 list of possible completions that is displayed without
8931 modification. When set to a value greater than zero, Readline
8932 replaces common prefixes longer than this value with an
8933 ellipsis when displaying possible completions. If a
8934 completion begins with a period, and Readline is completing
8935 filenames, it uses three underscores instead of an ellipsis.
8936
8937 ‘completion-query-items’
ccc6cda3 8938 The number of possible completions that determines when the
b80f6443
JA
8939 user is asked whether the list of possibilities should be
8940 displayed. If the number of possible completions is greater
b8c60bc9
CR
8941 than or equal to this value, Readline asks whether or not the
8942 user wishes to view them; otherwise, Readline simply lists the
8943 completions. This variable must be set to an integer value
8944 greater than or equal to zero. A zero value means Readline
8945 should never ask; negative values are treated as zero. The
8946 default limit is ‘100’.
8947
8948 ‘convert-meta’
8949 If set to ‘on’, Readline converts characters it reads that
8950 have the eighth bit set to an ASCII key sequence by clearing
8951 the eighth bit and prefixing an <ESC> character, converting
8952 them to a meta-prefixed key sequence. The default value is
8953 ‘on’, but Readline sets it to ‘off’ if the locale contains
8954 characters whose encodings may include bytes with the eighth
8955 bit set. This variable is dependent on the ‘LC_CTYPE’ locale
8956 category, and may change if the locale changes. This variable
8957 also affects key bindings; see the description of
8958 ‘force-meta-prefix’ below.
8959
8960 ‘disable-completion’
8961 If set to ‘On’, Readline inhibits word completion. Completion
8962 characters are inserted into the line as if they had been
8963 mapped to ‘self-insert’. The default is ‘off’.
8964
8965 ‘echo-control-characters’
8966 When set to ‘on’, on operating systems that indicate they
74091dd4 8967 support it, Readline echoes a character corresponding to a
b8c60bc9 8968 signal generated from the keyboard. The default is ‘on’.
0001803f 8969
b8c60bc9
CR
8970 ‘editing-mode’
8971 The ‘editing-mode’ variable controls the default set of key
8972 bindings. By default, Readline starts up in emacs editing
8973 mode, where the keystrokes are most similar to Emacs. This
8974 variable can be set to either ‘emacs’ or ‘vi’.
a0c0a00f 8975
b8c60bc9 8976 ‘emacs-mode-string’
d233b485
CR
8977 If the SHOW-MODE-IN-PROMPT variable is enabled, this string is
8978 displayed immediately before the last line of the primary
8979 prompt when emacs editing mode is active. The value is
8980 expanded like a key binding, so the standard set of meta- and
b8c60bc9
CR
8981 control- prefixes and backslash escape sequences is available.
8982 The ‘\1’ and ‘\2’ escapes begin and end sequences of
d233b485 8983 non-printing characters, which can be used to embed a terminal
b8c60bc9
CR
8984 control sequence into the mode string. The default is ‘@’.
8985
8986 ‘enable-active-region’
8987 “point” is the current cursor position, and “mark” refers to a
8988 saved cursor position (*note Commands For Moving::). The text
8989 between the point and mark is referred to as the “region”.
8990 When this variable is set to ‘On’, Readline allows certain
8991 commands to designate the region as “active”. When the region
8992 is active, Readline highlights the text in the region using
8993 the value of the ‘active-region-start-color’, which defaults
8994 to the string that enables the terminal's standout mode. The
8995 active region shows the text inserted by bracketed-paste and
8996 any matching text found by incremental and non-incremental
8997 history searches. The default is ‘On’.
8998
8999 ‘enable-bracketed-paste’
9000 When set to ‘On’, Readline configures the terminal to insert
74091dd4
CR
9001 each paste into the editing buffer as a single string of
9002 characters, instead of treating each character as if it had
9003 been read from the keyboard. This is called putting the
b8c60bc9 9004 terminal into “bracketed paste mode”; it prevents Readline
74091dd4 9005 from executing any editing commands bound to key sequences
b8c60bc9 9006 appearing in the pasted text. The default is ‘On’.
a0c0a00f 9007
b8c60bc9
CR
9008 ‘enable-keypad’
9009 When set to ‘on’, Readline tries to enable the application
ccc6cda3 9010 keypad when it is called. Some systems need this to enable
b8c60bc9
CR
9011 the arrow keys. The default is ‘off’.
9012
9013 ‘enable-meta-key’
9014 When set to ‘on’, Readline tries to enable any meta modifier
9015 key the terminal claims to support when it is called. On many
9016 terminals, the Meta key is used to send eight-bit characters;
9017 this variable checks for the terminal capability that
9018 indicates the terminal can enable and disable a mode that sets
9019 the eighth bit of a character (0200) if the Meta key is held
9020 down when the character is typed (a meta character). The
9021 default is ‘on’.
9022
9023 ‘expand-tilde’
9024 If set to ‘on’, Readline attempts tilde expansion when it
9025 attempts word completion. The default is ‘off’.
9026
9027 ‘force-meta-prefix’
9028 If set to ‘on’, Readline modifies its behavior when binding
9029 key sequences containing ‘\M-’ or ‘Meta-’ (see ‘Key Bindings’
9030 in *note Readline Init File Syntax::) by converting a key
9031 sequence of the form ‘\M-’C or ‘Meta-’C to the two-character
9032 sequence ‘ESC’ C (adding the meta prefix). If
9033 ‘force-meta-prefix’ is set to ‘off’ (the default), Readline
9034 uses the value of the ‘convert-meta’ variable to determine
9035 whether to perform this conversion: if ‘convert-meta’ is ‘on’,
9036 Readline performs the conversion described above; if it is
9037 ‘off’, Readline converts C to a meta character by setting the
9038 eighth bit (0200). The default is ‘off’.
9039
9040 ‘history-preserve-point’
9041 If set to ‘on’, the history code attempts to place the point
3185942a 9042 (the current cursor position) at the same location on each
b8c60bc9
CR
9043 history line retrieved with ‘previous-history’ or
9044 ‘next-history’. The default is ‘off’.
a0c0a00f 9045
b8c60bc9 9046 ‘history-size’
a0c0a00f
CR
9047 Set the maximum number of history entries saved in the history
9048 list. If set to zero, any existing history entries are
9049 deleted and no new entries are saved. If set to a value less
9050 than zero, the number of history entries is not limited. By
b8c60bc9
CR
9051 default, Bash sets the maximum number of history entries to
9052 the value of the ‘HISTSIZE’ shell variable. If you try to set
9053 HISTORY-SIZE to a non-numeric value, the maximum number of
9054 history entries will be set to 500.
9055
9056 ‘horizontal-scroll-mode’
9057 Setting this variable to ‘on’ means that the text of the lines
9058 being edited will scroll horizontally on a single screen line
9059 when the lines are longer than the width of the screen,
9060 instead of wrapping onto a new screen line. This variable is
9061 automatically set to ‘on’ for terminals of height 1. By
9062 default, this variable is set to ‘off’.
9063
9064 ‘input-meta’
9065 If set to ‘on’, Readline enables eight-bit input (that is, it
9066 does not clear the eighth bit in the characters it reads),
b72432fd 9067 regardless of what the terminal claims it can support. The
b8c60bc9
CR
9068 default value is ‘off’, but Readline sets it to ‘on’ if the
9069 locale contains characters whose encodings may include bytes
9070 with the eighth bit set. This variable is dependent on the
9071 ‘LC_CTYPE’ locale category, and its value may change if the
9072 locale changes. The name ‘meta-flag’ is a synonym for
9073 ‘input-meta’.
9074
9075 ‘isearch-terminators’
b72432fd
JA
9076 The string of characters that should terminate an incremental
9077 search without subsequently executing the character as a
28ef6c31 9078 command (*note Searching::). If this variable has not been
b8c60bc9
CR
9079 given a value, the characters <ESC> and ‘C-j’ terminate an
9080 incremental search.
b72432fd 9081
b8c60bc9 9082 ‘keymap’
ccc6cda3 9083 Sets Readline's idea of the current keymap for key binding
b8c60bc9
CR
9084 commands. Built-in ‘keymap’ names are ‘emacs’,
9085 ‘emacs-standard’, ‘emacs-meta’, ‘emacs-ctlx’, ‘vi’, ‘vi-move’,
9086 ‘vi-command’, and ‘vi-insert’. ‘vi’ is equivalent to
9087 ‘vi-command’ (‘vi-move’ is also a synonym); ‘emacs’ is
9088 equivalent to ‘emacs-standard’. Applications may add
9089 additional names. The default value is ‘emacs’; the value of
9090 the ‘editing-mode’ variable also affects the default keymap.
9091
9092 ‘keyseq-timeout’
a0c0a00f
CR
9093 Specifies the duration Readline will wait for a character when
9094 reading an ambiguous key sequence (one that can form a
9095 complete key sequence using the input read so far, or can take
b8c60bc9
CR
9096 additional input to complete a longer key sequence). If
9097 Readline doesn't receive any input within the timeout, it uses
9098 the shorter but complete key sequence. Readline uses this
9099 value to determine whether or not input is available on the
9100 current input source (‘rl_instream’ by default). The value is
a0c0a00f 9101 specified in milliseconds, so a value of 1000 means that
ac50fbac
CR
9102 Readline will wait one second for additional input. If this
9103 variable is set to a value less than or equal to zero, or to a
b8c60bc9
CR
9104 non-numeric value, Readline waits until another key is pressed
9105 to decide which key sequence to complete. The default value
9106 is ‘500’.
9107
9108 ‘mark-directories’
9109 If set to ‘on’, completed directory names have a slash
9110 appended. The default is ‘on’.
9111
9112 ‘mark-modified-lines’
9113 When this variable is set to ‘on’, Readline displays an
9114 asterisk (‘*’) at the start of history lines which have been
9115 modified. This variable is ‘off’ by default.
9116
9117 ‘mark-symlinked-directories’
9118 If set to ‘on’, completed names which are symbolic links to
9119 directories have a slash appended, subject to the value of
9120 ‘mark-directories’. The default is ‘off’.
9121
9122 ‘match-hidden-files’
9123 This variable, when set to ‘on’, forces Readline to match
9124 files whose names begin with a ‘.’ (hidden files) when
9125 performing filename completion. If set to ‘off’, the user
9126 must include the leading ‘.’ in the filename to be completed.
9127 This variable is ‘on’ by default.
9128
9129 ‘menu-complete-display-prefix’
9130 If set to ‘on’, menu completion displays the common prefix of
495aee44 9131 the list of possible completions (which may be empty) before
b8c60bc9
CR
9132 cycling through the list. The default is ‘off’.
9133
9134 ‘output-meta’
9135 If set to ‘on’, Readline displays characters with the eighth
9136 bit set directly rather than as a meta-prefixed escape
9137 sequence. The default is ‘off’, but Readline sets it to ‘on’
9138 if the locale contains characters whose encodings may include
9139 bytes with the eighth bit set. This variable is dependent on
9140 the ‘LC_CTYPE’ locale category, and its value may change if
9141 the locale changes.
9142
9143 ‘page-completions’
9144 If set to ‘on’, Readline uses an internal pager resembling
9145 more(1) to display a screenful of possible completions at a
9146 time. This variable is ‘on’ by default.
9147
9148 ‘prefer-visible-bell’
9149 See ‘bell-style’.
9150
9151 ‘print-completions-horizontally’
9152 If set to ‘on’, Readline displays completions with matches
cce855bc 9153 sorted horizontally in alphabetical order, rather than down
b8c60bc9 9154 the screen. The default is ‘off’.
cce855bc 9155
b8c60bc9
CR
9156 ‘revert-all-at-newline’
9157 If set to ‘on’, Readline will undo all changes to history
9158 lines before returning when executing ‘accept-line’. By
3185942a 9159 default, history lines may be modified and retain individual
b8c60bc9
CR
9160 undo lists across calls to ‘readline()’. The default is
9161 ‘off’.
3185942a 9162
b8c60bc9
CR
9163 ‘search-ignore-case’
9164 If set to ‘on’, Readline performs incremental and
9165 non-incremental history list searches in a case-insensitive
9166 fashion. The default value is ‘off’.
9167
9168 ‘show-all-if-ambiguous’
ccc6cda3 9169 This alters the default behavior of the completion functions.
b8c60bc9 9170 If set to ‘on’, words which have more than one possible
ccc6cda3 9171 completion cause the matches to be listed immediately instead
b8c60bc9 9172 of ringing the bell. The default value is ‘off’.
ccc6cda3 9173
b8c60bc9 9174 ‘show-all-if-unmodified’
b80f6443
JA
9175 This alters the default behavior of the completion functions
9176 in a fashion similar to SHOW-ALL-IF-AMBIGUOUS. If set to
b8c60bc9 9177 ‘on’, words which have more than one possible completion
b80f6443
JA
9178 without any possible partial completion (the possible
9179 completions don't share a common prefix) cause the matches to
9180 be listed immediately instead of ringing the bell. The
b8c60bc9 9181 default value is ‘off’.
a0c0a00f 9182
b8c60bc9
CR
9183 ‘show-mode-in-prompt’
9184 If set to ‘on’, add a string to the beginning of the prompt
a0c0a00f 9185 indicating the editing mode: emacs, vi command, or vi
d233b485 9186 insertion. The mode strings are user-settable (e.g.,
b8c60bc9 9187 EMACS-MODE-STRING). The default value is ‘off’.
a0c0a00f 9188
b8c60bc9
CR
9189 ‘skip-completed-text’
9190 If set to ‘on’, this alters the default completion behavior
a0c0a00f
CR
9191 when inserting a single match into the line. It's only active
9192 when performing completion in the middle of a word. If
74091dd4 9193 enabled, Readline does not insert characters from the
a0c0a00f
CR
9194 completion that match characters after point in the word being
9195 completed, so portions of the word following the cursor are
9196 not duplicated. For instance, if this is enabled, attempting
b8c60bc9
CR
9197 completion when the cursor is after the first ‘e’ in
9198 ‘Makefile’ will result in ‘Makefile’ rather than
9199 ‘Makefilefile’, assuming there is a single possible
9200 completion. The default value is ‘off’.
a0c0a00f 9201
b8c60bc9 9202 ‘vi-cmd-mode-string’
d233b485
CR
9203 If the SHOW-MODE-IN-PROMPT variable is enabled, this string is
9204 displayed immediately before the last line of the primary
9205 prompt when vi editing mode is active and in command mode.
9206 The value is expanded like a key binding, so the standard set
b8c60bc9
CR
9207 of meta- and control- prefixes and backslash escape sequences
9208 is available. The ‘\1’ and ‘\2’ escapes begin and end
d233b485
CR
9209 sequences of non-printing characters, which can be used to
9210 embed a terminal control sequence into the mode string. The
b8c60bc9 9211 default is ‘(cmd)’.
a0c0a00f 9212
b8c60bc9 9213 ‘vi-ins-mode-string’
d233b485
CR
9214 If the SHOW-MODE-IN-PROMPT variable is enabled, this string is
9215 displayed immediately before the last line of the primary
9216 prompt when vi editing mode is active and in insertion mode.
9217 The value is expanded like a key binding, so the standard set
b8c60bc9
CR
9218 of meta- and control- prefixes and backslash escape sequences
9219 is available. The ‘\1’ and ‘\2’ escapes begin and end
d233b485
CR
9220 sequences of non-printing characters, which can be used to
9221 embed a terminal control sequence into the mode string. The
b8c60bc9 9222 default is ‘(ins)’.
a0c0a00f 9223
b8c60bc9
CR
9224 ‘visible-stats’
9225 If set to ‘on’, a character denoting a file's type is appended
a0c0a00f 9226 to the filename when listing possible completions. The
b8c60bc9 9227 default is ‘off’.
b80f6443 9228
ccc6cda3 9229Key Bindings
a0c0a00f
CR
9230 The syntax for controlling key bindings in the init file is simple.
9231 First you need to find the name of the command that you want to
9232 change. The following sections contain tables of the command name,
9233 the default keybinding, if any, and a short description of what the
9234 command does.
ccc6cda3 9235
28ef6c31
JA
9236 Once you know the name of the command, simply place on a line in
9237 the init file the name of the key you wish to bind the command to,
0628567a
JA
9238 a colon, and then the name of the command. There can be no space
9239 between the key name and the colon - that will be interpreted as
9240 part of the key name. The name of the key can be expressed in
9241 different ways, depending on what you find most comfortable.
28ef6c31 9242
74091dd4 9243 In addition to command names, Readline allows keys to be bound to a
b8c60bc9
CR
9244 string that is inserted when the key is pressed (a MACRO). The
9245 difference between a macro and a command is that a macro is
9246 enclosed in single or double quotes.
ccc6cda3 9247
b8c60bc9 9248 The ‘bind -p’ command displays Readline function names and bindings
74091dd4 9249 in a format that can be put directly into an initialization file.
a0c0a00f 9250 *Note Bash Builtins::.
bb70624e 9251
a0c0a00f 9252 KEYNAME: FUNCTION-NAME or MACRO
ccc6cda3
JA
9253 KEYNAME is the name of a key spelled out in English. For
9254 example:
9255 Control-u: universal-argument
9256 Meta-Rubout: backward-kill-word
9257 Control-o: "> output"
9258
b8c60bc9
CR
9259 In the example above, ‘C-u’ is bound to the function
9260 ‘universal-argument’, ‘M-DEL’ is bound to the function
9261 ‘backward-kill-word’, and ‘C-o’ is bound to run the macro
ccc6cda3 9262 expressed on the right hand side (that is, to insert the text
b8c60bc9 9263 ‘> output’ into the line).
ccc6cda3 9264
b8c60bc9
CR
9265 This key binding syntax recognizes a number of symbolic
9266 character names: DEL, ESC, ESCAPE, LFD, NEWLINE, RET, RETURN,
9267 RUBOUT (a destructive backspace), SPACE, SPC, and TAB.
28ef6c31 9268
a0c0a00f 9269 "KEYSEQ": FUNCTION-NAME or MACRO
ccc6cda3
JA
9270 KEYSEQ differs from KEYNAME above in that strings denoting an
9271 entire key sequence can be specified, by placing the key
9272 sequence in double quotes. Some GNU Emacs style key escapes
b8c60bc9
CR
9273 can be used, as in the following example, but none of the
9274 special character names are recognized.
ccc6cda3
JA
9275
9276 "\C-u": universal-argument
9277 "\C-x\C-r": re-read-init-file
9278 "\e[11~": "Function Key 1"
9279
b8c60bc9
CR
9280 In the above example, ‘C-u’ is again bound to the function
9281 ‘universal-argument’ (just as it was in the first example),
9282 ‘‘C-x’ ‘C-r’’ is bound to the function ‘re-read-init-file’,
9283 and ‘<ESC> <[> <1> <1> <~>’ is bound to insert the text
9284 ‘Function Key 1’.
b80f6443 9285
cce855bc
JA
9286 The following GNU Emacs style escape sequences are available when
9287 specifying key sequences:
9288
b8c60bc9
CR
9289 ‘\C-’
9290 A control prefix.
9291 ‘\M-’
9292 Adding the meta prefix or converting the following character
9293 to a meta character, as described above under
9294 ‘force-meta-prefix’ (see ‘Variable Settings’ in *note Readline
9295 Init File Syntax::).
9296 ‘\e’
9297 An escape character.
9298 ‘\\’
9299 Backslash.
9300 ‘\"’
9301 <">, a double quotation mark.
9302 ‘\'’
9303 <'>, a single quote or apostrophe.
cce855bc
JA
9304
9305 In addition to the GNU Emacs style escape sequences, a second set
9306 of backslash escapes is available:
ccc6cda3 9307
b8c60bc9 9308 ‘\a’
cce855bc 9309 alert (bell)
b8c60bc9 9310 ‘\b’
cce855bc 9311 backspace
b8c60bc9 9312 ‘\d’
cce855bc 9313 delete
b8c60bc9 9314 ‘\f’
cce855bc 9315 form feed
b8c60bc9 9316 ‘\n’
cce855bc 9317 newline
b8c60bc9 9318 ‘\r’
cce855bc 9319 carriage return
b8c60bc9 9320 ‘\t’
cce855bc 9321 horizontal tab
b8c60bc9 9322 ‘\v’
cce855bc 9323 vertical tab
b8c60bc9
CR
9324 ‘\NNN’
9325 The eight-bit character whose value is the octal value NNN
9326 (one to three digits).
9327 ‘\xHH’
9328 The eight-bit character whose value is the hexadecimal value
9329 HH (one or two hex digits).
f73dda09 9330
cce855bc
JA
9331 When entering the text of a macro, single or double quotes must be
9332 used to indicate a macro definition. Unquoted text is assumed to
b8c60bc9
CR
9333 be a function name. The backslash escapes described above are
9334 expanded in the macro body. Backslash will quote any other
9335 character in the macro text, including ‘"’ and ‘'’. For example,
9336 the following binding will make ‘‘C-x’ \’ insert a single ‘\’ into
cce855bc
JA
9337 the line:
9338 "\C-x\\": "\\"
ccc6cda3
JA
9339
9340\1f
9341File: bashref.info, Node: Conditional Init Constructs, Next: Sample Init File, Prev: Readline Init File Syntax, Up: Readline Init File
9342
b80f6443
JA
93438.3.2 Conditional Init Constructs
9344---------------------------------
ccc6cda3 9345
b80f6443 9346Readline implements a facility similar in spirit to the conditional
a0c0a00f
CR
9347compilation features of the C preprocessor which allows key bindings and
9348variable settings to be performed as the result of tests. There are
b8c60bc9 9349four parser directives available.
a0c0a00f 9350
b8c60bc9
CR
9351‘$if’
9352 The ‘$if’ construct allows bindings to be made based on the editing
a0c0a00f 9353 mode, the terminal being used, or the application using Readline.
d233b485
CR
9354 The text of the test, after any comparison operator, extends to the
9355 end of the line; unless otherwise noted, no characters are required
9356 to isolate it.
a0c0a00f 9357
b8c60bc9
CR
9358 ‘mode’
9359 The ‘mode=’ form of the ‘$if’ directive is used to test
9360 whether Readline is in ‘emacs’ or ‘vi’ mode. This may be used
9361 in conjunction with the ‘set keymap’ command, for instance, to
9362 set bindings in the ‘emacs-standard’ and ‘emacs-ctlx’ keymaps
9363 only if Readline is starting out in ‘emacs’ mode.
a0c0a00f 9364
b8c60bc9
CR
9365 ‘term’
9366 The ‘term=’ form may be used to include terminal-specific key
ccc6cda3
JA
9367 bindings, perhaps to bind the key sequences output by the
9368 terminal's function keys. The word on the right side of the
b8c60bc9
CR
9369 ‘=’ is tested against both the full name of the terminal and
9370 the portion of the terminal name before the first ‘-’. This
9371 allows ‘xterm’ to match both ‘xterm’ and ‘xterm-256color’, for
9372 instance.
9373
9374 ‘version’
9375 The ‘version’ test may be used to perform comparisons against
9376 specific Readline versions. The ‘version’ expands to the
d233b485 9377 current Readline version. The set of comparison operators
b8c60bc9 9378 includes ‘=’ (and ‘==’), ‘!=’, ‘<=’, ‘>=’, ‘<’, and ‘>’. The
d233b485
CR
9379 version number supplied on the right side of the operator
9380 consists of a major version number, an optional decimal point,
b8c60bc9
CR
9381 and an optional minor version (e.g., ‘7.1’). If the minor
9382 version is omitted, it defaults to ‘0’. The operator may be
9383 separated from the string ‘version’ and from the version
d233b485
CR
9384 number argument by whitespace. The following example sets a
9385 variable if the Readline version being used is 7.0 or newer:
9386 $if version >= 7.0
9387 set show-mode-in-prompt on
9388 $endif
9389
b8c60bc9 9390 ‘application’
ccc6cda3
JA
9391 The APPLICATION construct is used to include
9392 application-specific settings. Each program using the
9393 Readline library sets the APPLICATION NAME, and you can test
28ef6c31
JA
9394 for a particular value. This could be used to bind key
9395 sequences to functions useful for a specific program. For
9396 instance, the following command adds a key sequence that
9397 quotes the current or previous word in Bash:
ccc6cda3
JA
9398 $if Bash
9399 # Quote the current or previous word
9400 "\C-xq": "\eb\"\ef\""
9401 $endif
9402
b8c60bc9 9403 ‘variable’
d233b485
CR
9404 The VARIABLE construct provides simple equality tests for
9405 Readline variables and values. The permitted comparison
b8c60bc9 9406 operators are ‘=’, ‘==’, and ‘!=’. The variable name must be
d233b485
CR
9407 separated from the comparison operator by whitespace; the
9408 operator may be separated from the value on the right hand
b8c60bc9 9409 side by whitespace. String and boolean variables may be
d233b485
CR
9410 tested. Boolean variables must be tested against the values
9411 ON and OFF. The following example is equivalent to the
b8c60bc9 9412 ‘mode=emacs’ test described above:
d233b485
CR
9413 $if editing-mode == emacs
9414 set show-mode-in-prompt on
9415 $endif
9416
b8c60bc9
CR
9417‘$else’
9418 Commands in this branch of the ‘$if’ directive are executed if the
ccc6cda3
JA
9419 test fails.
9420
b8c60bc9
CR
9421‘$endif’
9422 This command, as seen in the previous example, terminates an ‘$if’
9423 command.
9424
9425‘$include’
cce855bc 9426 This directive takes a single filename as an argument and reads
b8c60bc9
CR
9427 commands and key bindings from that file. For example, the
9428 following directive reads from ‘/etc/inputrc’:
cce855bc
JA
9429 $include /etc/inputrc
9430
ccc6cda3
JA
9431\1f
9432File: bashref.info, Node: Sample Init File, Prev: Conditional Init Constructs, Up: Readline Init File
9433
b80f6443
JA
94348.3.3 Sample Init File
9435----------------------
ccc6cda3 9436
b80f6443
JA
9437Here is an example of an INPUTRC file. This illustrates key binding,
9438variable assignment, and conditional syntax.
ccc6cda3 9439
b8c60bc9 9440 # This file controls the behavior of line input editing for
7117c2d2
JA
9441 # programs that use the GNU Readline library. Existing
9442 # programs include FTP, Bash, and GDB.
ccc6cda3
JA
9443 #
9444 # You can re-read the inputrc file with C-x C-r.
9445 # Lines beginning with '#' are comments.
cce855bc 9446 #
ac50fbac 9447 # First, include any system-wide bindings and variable
7117c2d2 9448 # assignments from /etc/Inputrc
cce855bc 9449 $include /etc/Inputrc
b80f6443 9450
ccc6cda3
JA
9451 #
9452 # Set various bindings for emacs mode.
b80f6443 9453
ccc6cda3 9454 set editing-mode emacs
b80f6443 9455
ccc6cda3 9456 $if mode=emacs
b80f6443 9457
ccc6cda3 9458 Meta-Control-h: backward-kill-word Text after the function name is ignored
b80f6443 9459
ccc6cda3
JA
9460 #
9461 # Arrow keys in keypad mode
9462 #
d166f048
JA
9463 #"\M-OD": backward-char
9464 #"\M-OC": forward-char
9465 #"\M-OA": previous-history
9466 #"\M-OB": next-history
ccc6cda3
JA
9467 #
9468 # Arrow keys in ANSI mode
9469 #
d166f048
JA
9470 "\M-[D": backward-char
9471 "\M-[C": forward-char
9472 "\M-[A": previous-history
9473 "\M-[B": next-history
ccc6cda3
JA
9474 #
9475 # Arrow keys in 8 bit keypad mode
9476 #
d166f048
JA
9477 #"\M-\C-OD": backward-char
9478 #"\M-\C-OC": forward-char
9479 #"\M-\C-OA": previous-history
9480 #"\M-\C-OB": next-history
ccc6cda3
JA
9481 #
9482 # Arrow keys in 8 bit ANSI mode
9483 #
d166f048
JA
9484 #"\M-\C-[D": backward-char
9485 #"\M-\C-[C": forward-char
9486 #"\M-\C-[A": previous-history
9487 #"\M-\C-[B": next-history
b80f6443 9488
ccc6cda3 9489 C-q: quoted-insert
b80f6443 9490
ccc6cda3 9491 $endif
b80f6443 9492
ccc6cda3
JA
9493 # An old-style binding. This happens to be the default.
9494 TAB: complete
b80f6443 9495
ccc6cda3
JA
9496 # Macros that are convenient for shell interaction
9497 $if Bash
9498 # edit the path
9499 "\C-xp": "PATH=${PATH}\e\C-e\C-a\ef\C-f"
7117c2d2
JA
9500 # prepare to type a quoted word --
9501 # insert open and close double quotes
ccc6cda3
JA
9502 # and move to just after the open quote
9503 "\C-x\"": "\"\"\C-b"
7117c2d2
JA
9504 # insert a backslash (testing backslash escapes
9505 # in sequences and macros)
ccc6cda3
JA
9506 "\C-x\\": "\\"
9507 # Quote the current or previous word
9508 "\C-xq": "\eb\"\ef\""
9509 # Add a binding to refresh the line, which is unbound
9510 "\C-xr": redraw-current-line
9511 # Edit variable on current line.
9512 "\M-\C-v": "\C-a\C-k$\C-y\M-\C-e\C-a\C-y="
9513 $endif
b80f6443 9514
ccc6cda3
JA
9515 # use a visible bell if one is available
9516 set bell-style visible
b80f6443 9517
ccc6cda3
JA
9518 # don't strip characters to 7 bits when reading
9519 set input-meta on
b80f6443 9520
7117c2d2
JA
9521 # allow iso-latin1 characters to be inserted rather
9522 # than converted to prefix-meta sequences
ccc6cda3 9523 set convert-meta off
b80f6443 9524
7117c2d2
JA
9525 # display characters with the eighth bit set directly
9526 # rather than as meta-prefixed characters
ccc6cda3 9527 set output-meta on
b80f6443 9528
8868edaf
CR
9529 # if there are 150 or more possible completions for a word,
9530 # ask whether or not the user wants to see all of them
ccc6cda3 9531 set completion-query-items 150
b80f6443 9532
ccc6cda3
JA
9533 # For FTP
9534 $if Ftp
9535 "\C-xg": "get \M-?"
9536 "\C-xt": "put \M-?"
9537 "\M-.": yank-last-arg
9538 $endif
9539
9540\1f
bb70624e
JA
9541File: bashref.info, Node: Bindable Readline Commands, Next: Readline vi Mode, Prev: Readline Init File, Up: Command Line Editing
9542
b80f6443
JA
95438.4 Bindable Readline Commands
9544==============================
bb70624e
JA
9545
9546* Menu:
9547
9548* Commands For Moving:: Moving about the line.
9549* Commands For History:: Getting at previous lines.
9550* Commands For Text:: Commands for changing text.
9551* Commands For Killing:: Commands for killing and yanking.
9552* Numeric Arguments:: Specifying numeric arguments, repeat counts.
9553* Commands For Completion:: Getting Readline to do the typing for you.
9554* Keyboard Macros:: Saving and re-executing typed characters
9555* Miscellaneous Commands:: Other miscellaneous commands.
9556
a0c0a00f 9557This section describes Readline commands that may be bound to key
b8c60bc9
CR
9558sequences. You can list your key bindings by executing ‘bind -P’ or,
9559for a more terse format, suitable for an INPUTRC file, ‘bind -p’.
28ef6c31
JA
9560(*Note Bash Builtins::.) Command names without an accompanying key
9561sequence are unbound by default.
bb70624e 9562
b8c60bc9
CR
9563 In the following descriptions, “point” refers to the current cursor
9564position, and “mark” refers to a cursor position saved by the ‘set-mark’
a0c0a00f 9565command. The text between the point and mark is referred to as the
b8c60bc9
CR
9566“region”. Readline has the concept of an _active region_: when the
9567region is active, Readline redisplay highlights the region using the
9568value of the ‘active-region-start-color’ variable. The
9569‘enable-active-region’ variable turns this on and off. Several commands
9570set the region to active; those are noted below.
bb70624e
JA
9571
9572\1f
9573File: bashref.info, Node: Commands For Moving, Next: Commands For History, Up: Bindable Readline Commands
9574
b80f6443
JA
95758.4.1 Commands For Moving
9576-------------------------
bb70624e 9577
b8c60bc9
CR
9578‘beginning-of-line (C-a)’
9579 Move to the start of the current line. This may also be bound to
9580 the Home key on some keyboards.
bb70624e 9581
b8c60bc9
CR
9582‘end-of-line (C-e)’
9583 Move to the end of the line. This may also be bound to the End key
9584 on some keyboards.
bb70624e 9585
b8c60bc9
CR
9586‘forward-char (C-f)’
9587 Move forward a character. This may also be bound to the right
9588 arrow key on some keyboards.
bb70624e 9589
b8c60bc9
CR
9590‘backward-char (C-b)’
9591 Move back a character. This may also be bound to the left arrow
9592 key on some keyboards.
bb70624e 9593
b8c60bc9 9594‘forward-word (M-f)’
bb70624e
JA
9595 Move forward to the end of the next word. Words are composed of
9596 letters and digits.
9597
b8c60bc9 9598‘backward-word (M-b)’
bb70624e
JA
9599 Move back to the start of the current or previous word. Words are
9600 composed of letters and digits.
9601
b8c60bc9 9602‘shell-forward-word (M-C-f)’
3185942a
JA
9603 Move forward to the end of the next word. Words are delimited by
9604 non-quoted shell metacharacters.
9605
b8c60bc9 9606‘shell-backward-word (M-C-b)’
3185942a
JA
9607 Move back to the start of the current or previous word. Words are
9608 delimited by non-quoted shell metacharacters.
9609
b8c60bc9 9610‘previous-screen-line ()’
d233b485
CR
9611 Attempt to move point to the same physical screen column on the
9612 previous physical screen line. This will not have the desired
9613 effect if the current Readline line does not take up more than one
9614 physical line or if point is not greater than the length of the
9615 prompt plus the screen width.
9616
b8c60bc9 9617‘next-screen-line ()’
d233b485
CR
9618 Attempt to move point to the same physical screen column on the
9619 next physical screen line. This will not have the desired effect
9620 if the current Readline line does not take up more than one
9621 physical line or if the length of the current Readline line is not
9622 greater than the length of the prompt plus the screen width.
9623
b8c60bc9 9624‘clear-display (M-C-l)’
8868edaf
CR
9625 Clear the screen and, if possible, the terminal's scrollback
9626 buffer, then redraw the current line, leaving the current line at
9627 the top of the screen.
9628
b8c60bc9 9629‘clear-screen (C-l)’
8868edaf 9630 Clear the screen, then redraw the current line, leaving the current
b8c60bc9
CR
9631 line at the top of the screen. If given a numeric argument, this
9632 refreshes the current line without clearing the screen.
bb70624e 9633
b8c60bc9 9634‘redraw-current-line ()’
bb70624e
JA
9635 Refresh the current line. By default, this is unbound.
9636
9637\1f
9638File: bashref.info, Node: Commands For History, Next: Commands For Text, Prev: Commands For Moving, Up: Bindable Readline Commands
9639
b80f6443
JA
96408.4.2 Commands For Manipulating The History
9641-------------------------------------------
bb70624e 9642
b8c60bc9 9643‘accept-line (Newline or Return)’
bb70624e
JA
9644 Accept the line regardless of where the cursor is. If this line is
9645 non-empty, add it to the history list according to the setting of
b8c60bc9 9646 the ‘HISTCONTROL’ and ‘HISTIGNORE’ variables. If this line is a
28ef6c31
JA
9647 modified history line, then restore the history line to its
9648 original state.
bb70624e 9649
b8c60bc9 9650‘previous-history (C-p)’
a0c0a00f 9651 Move 'back' through the history list, fetching the previous
b8c60bc9
CR
9652 command. This may also be bound to the up arrow key on some
9653 keyboards.
bb70624e 9654
b8c60bc9 9655‘next-history (C-n)’
a0c0a00f 9656 Move 'forward' through the history list, fetching the next command.
b8c60bc9 9657 This may also be bound to the down arrow key on some keyboards.
bb70624e 9658
b8c60bc9 9659‘beginning-of-history (M-<)’
bb70624e
JA
9660 Move to the first line in the history.
9661
b8c60bc9 9662‘end-of-history (M->)’
bb70624e
JA
9663 Move to the end of the input history, i.e., the line currently
9664 being entered.
9665
b8c60bc9 9666‘reverse-search-history (C-r)’
a0c0a00f 9667 Search backward starting at the current line and moving 'up'
bb70624e 9668 through the history as necessary. This is an incremental search.
8868edaf 9669 This command sets the region to the matched text and activates the
b8c60bc9 9670 region.
bb70624e 9671
b8c60bc9 9672‘forward-search-history (C-s)’
a0c0a00f
CR
9673 Search forward starting at the current line and moving 'down'
9674 through the history as necessary. This is an incremental search.
8868edaf 9675 This command sets the region to the matched text and activates the
b8c60bc9 9676 region.
bb70624e 9677
b8c60bc9 9678‘non-incremental-reverse-search-history (M-p)’
a0c0a00f
CR
9679 Search backward starting at the current line and moving 'up'
9680 through the history as necessary using a non-incremental search for
9681 a string supplied by the user. The search string may match
9682 anywhere in a history line.
bb70624e 9683
b8c60bc9 9684‘non-incremental-forward-search-history (M-n)’
a0c0a00f
CR
9685 Search forward starting at the current line and moving 'down'
9686 through the history as necessary using a non-incremental search for
9687 a string supplied by the user. The search string may match
9688 anywhere in a history line.
bb70624e 9689
b8c60bc9
CR
9690‘history-search-backward ()’
9691 Search backward through the history for the string of characters
ac50fbac
CR
9692 between the start of the current line and the point. The search
9693 string must match at the beginning of a history line. This is a
b8c60bc9
CR
9694 non-incremental search. By default, this command is unbound, but
9695 may be bound to the Page Down key on some keyboards.
bb70624e 9696
b8c60bc9
CR
9697‘history-search-forward ()’
9698 Search forward through the history for the string of characters
ac50fbac
CR
9699 between the start of the current line and the point. The search
9700 string must match at the beginning of a history line. This is a
b8c60bc9
CR
9701 non-incremental search. By default, this command is unbound, but
9702 may be bound to the Page Up key on some keyboards.
ac50fbac 9703
b8c60bc9
CR
9704‘history-substring-search-backward ()’
9705 Search backward through the history for the string of characters
ac50fbac
CR
9706 between the start of the current line and the point. The search
9707 string may match anywhere in a history line. This is a
9708 non-incremental search. By default, this command is unbound.
9709
b8c60bc9
CR
9710‘history-substring-search-forward ()’
9711 Search forward through the history for the string of characters
ac50fbac
CR
9712 between the start of the current line and the point. The search
9713 string may match anywhere in a history line. This is a
bb70624e
JA
9714 non-incremental search. By default, this command is unbound.
9715
b8c60bc9 9716‘yank-nth-arg (M-C-y)’
bb70624e 9717 Insert the first argument to the previous command (usually the
28ef6c31
JA
9718 second word on the previous line) at point. With an argument N,
9719 insert the Nth word from the previous command (the words in the
9720 previous command begin with word 0). A negative argument inserts
95732b49 9721 the Nth word from the end of the previous command. Once the
b8c60bc9
CR
9722 argument N is computed, this uses the history expansion facilities
9723 to extract the Nth word, as if the ‘!N’ history expansion had been
9724 specified.
bb70624e 9725
b8c60bc9 9726‘yank-last-arg (M-. or M-_)’
bb70624e 9727 Insert last argument to the previous command (the last word of the
495aee44 9728 previous history entry). With a numeric argument, behave exactly
b8c60bc9 9729 like ‘yank-nth-arg’. Successive calls to ‘yank-last-arg’ move back
a0c0a00f
CR
9730 through the history list, inserting the last word (or the word
9731 specified by the argument to the first call) of each line in turn.
9732 Any numeric argument supplied to these successive calls determines
9733 the direction to move through the history. A negative argument
b8c60bc9
CR
9734 switches the direction through the history (back or forward). This
9735 uses the history expansion facilities to extract the last word, as
9736 if the ‘!$’ history expansion had been specified.
b80f6443 9737
b8c60bc9 9738‘operate-and-get-next (C-o)’
8868edaf
CR
9739 Accept the current line for return to the calling application as if
9740 a newline had been entered, and fetch the next line relative to the
9741 current line from the history for editing. A numeric argument, if
9742 supplied, specifies the history entry to use instead of the current
9743 line.
9744
b8c60bc9 9745‘fetch-history ()’
74091dd4
CR
9746 With a numeric argument, fetch that entry from the history list and
9747 make it the current line. Without an argument, move back to the
9748 first entry in the history list.
9749
bb70624e
JA
9750\1f
9751File: bashref.info, Node: Commands For Text, Next: Commands For Killing, Prev: Commands For History, Up: Bindable Readline Commands
9752
b80f6443
JA
97538.4.3 Commands For Changing Text
9754--------------------------------
bb70624e 9755
b8c60bc9 9756‘end-of-file (usually C-d)’
ac50fbac 9757 The character indicating end-of-file as set, for example, by
b8c60bc9 9758 ‘stty’. If this character is read when there are no characters on
ac50fbac
CR
9759 the line, and point is at the beginning of the line, Readline
9760 interprets it as the end of input and returns EOF.
9761
b8c60bc9 9762‘delete-char (C-d)’
ac50fbac 9763 Delete the character at point. If this function is bound to the
b8c60bc9
CR
9764 same character as the tty EOF character, as ‘C-d’ commonly is, see
9765 above for the effects. This may also be bound to the Delete key on
9766 some keyboards.
bb70624e 9767
b8c60bc9 9768‘backward-delete-char (Rubout)’
bb70624e 9769 Delete the character behind the cursor. A numeric argument means
b8c60bc9
CR
9770 to kill the characters, saving them on the kill ring, instead of
9771 deleting them.
bb70624e 9772
b8c60bc9 9773‘forward-backward-delete-char ()’
bb70624e
JA
9774 Delete the character under the cursor, unless the cursor is at the
9775 end of the line, in which case the character behind the cursor is
9776 deleted. By default, this is not bound to a key.
9777
b8c60bc9 9778‘quoted-insert (C-q or C-v)’
bb70624e 9779 Add the next character typed to the line verbatim. This is how to
b8c60bc9 9780 insert key sequences like ‘C-q’, for example.
bb70624e 9781
b8c60bc9
CR
9782‘self-insert (a, b, A, 1, !, ...)’
9783 Insert the character typed.
bb70624e 9784
b8c60bc9 9785‘bracketed-paste-begin ()’
a0c0a00f
CR
9786 This function is intended to be bound to the "bracketed paste"
9787 escape sequence sent by some terminals, and such a binding is
9788 assigned by default. It allows Readline to insert the pasted text
9789 as a single unit without treating each character as if it had been
9790 read from the keyboard. The characters are inserted as if each one
b8c60bc9 9791 was bound to ‘self-insert’ instead of executing any editing
a0c0a00f
CR
9792 commands.
9793
8868edaf 9794 Bracketed paste sets the region (the characters between point and
b8c60bc9 9795 the mark) to the inserted text. It sets the _active region_.
8868edaf 9796
b8c60bc9 9797‘transpose-chars (C-t)’
bb70624e
JA
9798 Drag the character before the cursor forward over the character at
9799 the cursor, moving the cursor forward as well. If the insertion
9800 point is at the end of the line, then this transposes the last two
9801 characters of the line. Negative arguments have no effect.
9802
b8c60bc9 9803‘transpose-words (M-t)’
bb70624e 9804 Drag the word before point past the word after point, moving point
f73dda09
JA
9805 past that word as well. If the insertion point is at the end of
9806 the line, this transposes the last two words on the line.
bb70624e 9807
b8c60bc9
CR
9808‘shell-transpose-words (M-C-t)’
9809 Drag the word before point past the word after point, moving point
9810 past that word as well. If the insertion point is at the end of
9811 the line, this transposes the last two words on the line. Word
9812 boundaries are the same as ‘shell-forward-word’ and
9813 ‘shell-backward-word’.
9814
9815‘upcase-word (M-u)’
bb70624e
JA
9816 Uppercase the current (or following) word. With a negative
9817 argument, uppercase the previous word, but do not move the cursor.
9818
b8c60bc9 9819‘downcase-word (M-l)’
bb70624e
JA
9820 Lowercase the current (or following) word. With a negative
9821 argument, lowercase the previous word, but do not move the cursor.
9822
b8c60bc9 9823‘capitalize-word (M-c)’
bb70624e
JA
9824 Capitalize the current (or following) word. With a negative
9825 argument, capitalize the previous word, but do not move the cursor.
9826
b8c60bc9 9827‘overwrite-mode ()’
7117c2d2
JA
9828 Toggle overwrite mode. With an explicit positive numeric argument,
9829 switches to overwrite mode. With an explicit non-positive numeric
9830 argument, switches to insert mode. This command affects only
b8c60bc9
CR
9831 ‘emacs’ mode; ‘vi’ mode does overwrite differently. Each call to
9832 ‘readline()’ starts in insert mode.
7117c2d2 9833
b8c60bc9 9834 In overwrite mode, characters bound to ‘self-insert’ replace the
7117c2d2 9835 text at point rather than pushing the text to the right.
b8c60bc9 9836 Characters bound to ‘backward-delete-char’ replace the character
7117c2d2
JA
9837 before point with a space.
9838
b8c60bc9
CR
9839 By default, this command is unbound, but may be bound to the Insert
9840 key on some keyboards.
7117c2d2 9841
bb70624e
JA
9842\1f
9843File: bashref.info, Node: Commands For Killing, Next: Numeric Arguments, Prev: Commands For Text, Up: Bindable Readline Commands
9844
b80f6443
JA
98458.4.4 Killing And Yanking
9846-------------------------
bb70624e 9847
b8c60bc9
CR
9848‘kill-line (C-k)’
9849 Kill the text from point to the end of the current line. With a
9850 negative numeric argument, kill backward from the cursor to the
9851 beginning of the line.
bb70624e 9852
b8c60bc9 9853‘backward-kill-line (C-x Rubout)’
a0c0a00f 9854 Kill backward from the cursor to the beginning of the current line.
8868edaf 9855 With a negative numeric argument, kill forward from the cursor to
b8c60bc9 9856 the end of the line.
bb70624e 9857
b8c60bc9 9858‘unix-line-discard (C-u)’
bb70624e
JA
9859 Kill backward from the cursor to the beginning of the current line.
9860
b8c60bc9 9861‘kill-whole-line ()’
28ef6c31
JA
9862 Kill all characters on the current line, no matter where point is.
9863 By default, this is unbound.
bb70624e 9864
b8c60bc9 9865‘kill-word (M-d)’
bb70624e
JA
9866 Kill from point to the end of the current word, or if between
9867 words, to the end of the next word. Word boundaries are the same
b8c60bc9 9868 as ‘forward-word’.
bb70624e 9869
b8c60bc9 9870‘backward-kill-word (M-<DEL>)’
bb70624e 9871 Kill the word behind point. Word boundaries are the same as
b8c60bc9 9872 ‘backward-word’.
bb70624e 9873
b8c60bc9 9874‘shell-kill-word (M-C-d)’
3185942a
JA
9875 Kill from point to the end of the current word, or if between
9876 words, to the end of the next word. Word boundaries are the same
b8c60bc9 9877 as ‘shell-forward-word’.
3185942a 9878
b8c60bc9 9879‘shell-backward-kill-word ()’
3185942a 9880 Kill the word behind point. Word boundaries are the same as
b8c60bc9 9881 ‘shell-backward-word’.
8868edaf 9882
b8c60bc9
CR
9883‘unix-word-rubout (C-w)’
9884 Kill the word behind point, using white space as a word boundary,
9885 saving the killed text on the kill-ring.
bb70624e 9886
b8c60bc9 9887‘unix-filename-rubout ()’
b80f6443 9888 Kill the word behind point, using white space and the slash
b8c60bc9 9889 character as the word boundaries, saving the killed text on the
b80f6443
JA
9890 kill-ring.
9891
b8c60bc9 9892‘delete-horizontal-space ()’
bb70624e
JA
9893 Delete all spaces and tabs around point. By default, this is
9894 unbound.
9895
b8c60bc9 9896‘kill-region ()’
bb70624e
JA
9897 Kill the text in the current region. By default, this command is
9898 unbound.
9899
b8c60bc9 9900‘copy-region-as-kill ()’
bb70624e
JA
9901 Copy the text in the region to the kill buffer, so it can be yanked
9902 right away. By default, this command is unbound.
9903
b8c60bc9 9904‘copy-backward-word ()’
a0c0a00f 9905 Copy the word before point to the kill buffer. The word boundaries
b8c60bc9 9906 are the same as ‘backward-word’. By default, this command is
a0c0a00f 9907 unbound.
bb70624e 9908
b8c60bc9 9909‘copy-forward-word ()’
bb70624e 9910 Copy the word following point to the kill buffer. The word
b8c60bc9 9911 boundaries are the same as ‘forward-word’. By default, this
bb70624e
JA
9912 command is unbound.
9913
b8c60bc9 9914‘yank (C-y)’
28ef6c31 9915 Yank the top of the kill ring into the buffer at point.
bb70624e 9916
b8c60bc9 9917‘yank-pop (M-y)’
bb70624e 9918 Rotate the kill-ring, and yank the new top. You can only do this
b8c60bc9 9919 if the prior command is ‘yank’ or ‘yank-pop’.
bb70624e
JA
9920
9921\1f
9922File: bashref.info, Node: Numeric Arguments, Next: Commands For Completion, Prev: Commands For Killing, Up: Bindable Readline Commands
9923
b80f6443
JA
99248.4.5 Specifying Numeric Arguments
9925----------------------------------
bb70624e 9926
b8c60bc9 9927‘digit-argument (M-0, M-1, ... M--)’
bb70624e 9928 Add this digit to the argument already accumulating, or start a new
b8c60bc9 9929 argument. ‘M--’ starts a negative argument.
bb70624e 9930
b8c60bc9 9931‘universal-argument ()’
bb70624e
JA
9932 This is another way to specify an argument. If this command is
9933 followed by one or more digits, optionally with a leading minus
a0c0a00f 9934 sign, those digits define the argument. If the command is followed
b8c60bc9 9935 by digits, executing ‘universal-argument’ again ends the numeric
a0c0a00f
CR
9936 argument, but is otherwise ignored. As a special case, if this
9937 command is immediately followed by a character that is neither a
9938 digit nor minus sign, the argument count for the next command is
9939 multiplied by four. The argument count is initially one, so
9940 executing this function the first time makes the argument count
9941 four, a second time makes the argument count sixteen, and so on.
9942 By default, this is not bound to a key.
bb70624e
JA
9943
9944\1f
9945File: bashref.info, Node: Commands For Completion, Next: Keyboard Macros, Prev: Numeric Arguments, Up: Bindable Readline Commands
9946
b80f6443
JA
99478.4.6 Letting Readline Type For You
9948-----------------------------------
bb70624e 9949
b8c60bc9 9950‘complete (<TAB>)’
a0c0a00f
CR
9951 Attempt to perform completion on the text before point. The actual
9952 completion performed is application-specific. Bash attempts
b8c60bc9
CR
9953 completion by first checking for any programmable completions for
9954 the command word (*note Programmable Completion::), otherwise
9955 treating the text as a variable (if the text begins with ‘$’),
9956 username (if the text begins with ‘~’), hostname (if the text
9957 begins with ‘@’), or command (including aliases, functions, and
9958 builtins) in turn. If none of these produces a match, it falls
9959 back to filename completion.
9960
9961‘possible-completions (M-?)’
495aee44
CR
9962 List the possible completions of the text before point. When
9963 displaying completions, Readline sets the number of columns used
b8c60bc9
CR
9964 for display to the value of ‘completion-display-width’, the value
9965 of the environment variable ‘COLUMNS’, or the screen width, in that
a0c0a00f 9966 order.
bb70624e 9967
b8c60bc9 9968‘insert-completions (M-*)’
bb70624e 9969 Insert all completions of the text before point that would have
b8c60bc9 9970 been generated by ‘possible-completions’, separated by a space.
bb70624e 9971
b8c60bc9
CR
9972‘menu-complete ()’
9973 Similar to ‘complete’, but replaces the word to be completed with a
9974 single match from the list of possible completions. Repeatedly
9975 executing ‘menu-complete’ steps through the list of possible
bb70624e 9976 completions, inserting each match in turn. At the end of the list
b8c60bc9
CR
9977 of completions, ‘menu-complete’ rings the bell (subject to the
9978 setting of ‘bell-style’) and restores the original text. An
9979 argument of N moves N positions forward in the list of matches; a
9980 negative argument moves backward through the list. This command is
9981 intended to be bound to <TAB>, but is unbound by default.
9982
9983‘menu-complete-backward ()’
9984 Identical to ‘menu-complete’, but moves backward through the list
9985 of possible completions, as if ‘menu-complete’ had been given a
9986 negative argument. This command is unbound by default.
9987
9988‘export-completions ()’
9989 Perform completion on the word before point as described above and
9990 write the list of possible completions to Readline's output stream
9991 using the following format, writing information on separate lines:
9992
9993 • the number of matches N;
9994 • the word being completed;
9995 • S:E, where S and E are the start and end offsets of the word
9996 in the Readline line buffer; then
9997 • each match, one per line
9998
9999 If there are no matches, the first line will be "0", and this
10000 command does not print any output after the S:E. If there is only
10001 a single match, this prints a single line containing it. If there
10002 is more than one match, this prints the common prefix of the
10003 matches, which may be empty, on the first line after the S:E, then
10004 the matches on subsequent lines. In this case, N will include the
10005 first line with the common prefix.
10006
10007 The user or application should be able to accommodate the
10008 possibility of a blank line. The intent is that the user or
10009 application reads N lines after the line containing S:E to obtain
10010 the match list. This command is unbound by default.
10011
10012‘delete-char-or-list ()’
bb70624e 10013 Deletes the character under the cursor if not at the beginning or
b8c60bc9
CR
10014 end of the line (like ‘delete-char’). At the end of the line, it
10015 behaves identically to ‘possible-completions’. This command is
bb70624e
JA
10016 unbound by default.
10017
b8c60bc9 10018‘complete-filename (M-/)’
bb70624e
JA
10019 Attempt filename completion on the text before point.
10020
b8c60bc9 10021‘possible-filename-completions (C-x /)’
a0c0a00f
CR
10022 List the possible completions of the text before point, treating it
10023 as a filename.
bb70624e 10024
b8c60bc9 10025‘complete-username (M-~)’
bb70624e
JA
10026 Attempt completion on the text before point, treating it as a
10027 username.
10028
b8c60bc9 10029‘possible-username-completions (C-x ~)’
a0c0a00f
CR
10030 List the possible completions of the text before point, treating it
10031 as a username.
bb70624e 10032
b8c60bc9 10033‘complete-variable (M-$)’
a0c0a00f
CR
10034 Attempt completion on the text before point, treating it as a shell
10035 variable.
bb70624e 10036
b8c60bc9 10037‘possible-variable-completions (C-x $)’
a0c0a00f
CR
10038 List the possible completions of the text before point, treating it
10039 as a shell variable.
bb70624e 10040
b8c60bc9 10041‘complete-hostname (M-@)’
bb70624e
JA
10042 Attempt completion on the text before point, treating it as a
10043 hostname.
10044
b8c60bc9 10045‘possible-hostname-completions (C-x @)’
a0c0a00f
CR
10046 List the possible completions of the text before point, treating it
10047 as a hostname.
bb70624e 10048
b8c60bc9 10049‘complete-command (M-!)’
bb70624e
JA
10050 Attempt completion on the text before point, treating it as a
10051 command name. Command completion attempts to match the text
10052 against aliases, reserved words, shell functions, shell builtins,
10053 and finally executable filenames, in that order.
10054
b8c60bc9 10055‘possible-command-completions (C-x !)’
a0c0a00f
CR
10056 List the possible completions of the text before point, treating it
10057 as a command name.
bb70624e 10058
b8c60bc9 10059‘dynamic-complete-history (M-<TAB>)’
bb70624e 10060 Attempt completion on the text before point, comparing the text
b8c60bc9 10061 against history list entries for possible completion matches.
bb70624e 10062
b8c60bc9 10063‘dabbrev-expand ()’
3185942a
JA
10064 Attempt menu completion on the text before point, comparing the
10065 text against lines from the history list for possible completion
10066 matches.
10067
b8c60bc9 10068‘complete-into-braces (M-{)’
bb70624e
JA
10069 Perform filename completion and insert the list of possible
10070 completions enclosed within braces so the list is available to the
28ef6c31 10071 shell (*note Brace Expansion::).
bb70624e
JA
10072
10073\1f
10074File: bashref.info, Node: Keyboard Macros, Next: Miscellaneous Commands, Prev: Commands For Completion, Up: Bindable Readline Commands
10075
b80f6443
JA
100768.4.7 Keyboard Macros
10077---------------------
bb70624e 10078
b8c60bc9 10079‘start-kbd-macro (C-x ()’
bb70624e
JA
10080 Begin saving the characters typed into the current keyboard macro.
10081
b8c60bc9 10082‘end-kbd-macro (C-x ))’
bb70624e
JA
10083 Stop saving the characters typed into the current keyboard macro
10084 and save the definition.
10085
b8c60bc9 10086‘call-last-kbd-macro (C-x e)’
bb70624e
JA
10087 Re-execute the last keyboard macro defined, by making the
10088 characters in the macro appear as if typed at the keyboard.
10089
b8c60bc9 10090‘print-last-kbd-macro ()’
74091dd4 10091 Print the last keyboard macro defined in a format suitable for the
ac50fbac
CR
10092 INPUTRC file.
10093
bb70624e
JA
10094\1f
10095File: bashref.info, Node: Miscellaneous Commands, Prev: Keyboard Macros, Up: Bindable Readline Commands
10096
b80f6443
JA
100978.4.8 Some Miscellaneous Commands
10098---------------------------------
bb70624e 10099
b8c60bc9 10100‘re-read-init-file (C-x C-r)’
bb70624e
JA
10101 Read in the contents of the INPUTRC file, and incorporate any
10102 bindings or variable assignments found there.
10103
b8c60bc9 10104‘abort (C-g)’
bb70624e 10105 Abort the current editing command and ring the terminal's bell
b8c60bc9 10106 (subject to the setting of ‘bell-style’).
bb70624e 10107
b8c60bc9 10108‘do-lowercase-version (M-A, M-B, M-X, ...)’
d233b485
CR
10109 If the metafied character X is upper case, run the command that is
10110 bound to the corresponding metafied lower case character. The
10111 behavior is undefined if X is already lower case.
bb70624e 10112
b8c60bc9
CR
10113‘prefix-meta (<ESC>)’
10114 Metafy the next character typed. Typing ‘<ESC> f’ is equivalent to
10115 typing ‘M-f’.
bb70624e 10116
b8c60bc9 10117‘undo (C-_ or C-x C-u)’
bb70624e
JA
10118 Incremental undo, separately remembered for each line.
10119
b8c60bc9 10120‘revert-line (M-r)’
bb70624e 10121 Undo all changes made to this line. This is like executing the
b8c60bc9 10122 ‘undo’ command enough times to get back to the initial state.
bb70624e 10123
b8c60bc9 10124‘tilde-expand (M-&)’
bb70624e
JA
10125 Perform tilde expansion on the current word.
10126
b8c60bc9
CR
10127‘set-mark (C-@)’
10128 Set the mark to the point. If a numeric argument is supplied, set
10129 the mark to that position.
bb70624e 10130
b8c60bc9
CR
10131‘exchange-point-and-mark (C-x C-x)’
10132 Swap the point with the mark. Set the current cursor position to
10133 the saved position, then set the mark to the old cursor position.
bb70624e 10134
b8c60bc9
CR
10135‘character-search (C-])’
10136 Read a character and move point to the next occurrence of that
10137 character. A negative argument searches for previous occurrences.
bb70624e 10138
b8c60bc9
CR
10139‘character-search-backward (M-C-])’
10140 Read a character and move point to the previous occurrence of that
10141 character. A negative argument searches for subsequent
bb70624e
JA
10142 occurrences.
10143
b8c60bc9 10144‘skip-csi-sequence ()’
0001803f 10145 Read enough characters to consume a multi-key sequence such as
b8c60bc9
CR
10146 those defined for keys like Home and End. CSI sequences begin with
10147 a Control Sequence Indicator (CSI), usually ‘ESC [’. If this
10148 sequence is bound to "\e[", keys producing CSI sequences have no
10149 effect unless explicitly bound to a Readline command, instead of
a0c0a00f 10150 inserting stray characters into the editing buffer. This is
b8c60bc9 10151 unbound by default, but usually bound to ‘ESC [’.
0001803f 10152
b8c60bc9
CR
10153‘insert-comment (M-#)’
10154 Without a numeric argument, insert the value of the ‘comment-begin’
10155 variable at the beginning of the current line. If a numeric
10156 argument is supplied, this command acts as a toggle: if the
a0c0a00f 10157 characters at the beginning of the line do not match the value of
b8c60bc9
CR
10158 ‘comment-begin’, insert the value; otherwise delete the characters
10159 in ‘comment-begin’ from the beginning of the line. In either case,
10160 the line is accepted as if a newline had been typed. The default
10161 value of ‘comment-begin’ causes this command to make the current
10162 line a shell comment. If a numeric argument causes the comment
10163 character to be removed, the line will be executed by the shell.
10164
10165‘dump-functions ()’
bb70624e
JA
10166 Print all of the functions and their key bindings to the Readline
10167 output stream. If a numeric argument is supplied, the output is
10168 formatted in such a way that it can be made part of an INPUTRC
10169 file. This command is unbound by default.
10170
b8c60bc9 10171‘dump-variables ()’
bb70624e
JA
10172 Print all of the settable variables and their values to the
10173 Readline output stream. If a numeric argument is supplied, the
10174 output is formatted in such a way that it can be made part of an
10175 INPUTRC file. This command is unbound by default.
10176
b8c60bc9 10177‘dump-macros ()’
bb70624e 10178 Print all of the Readline key sequences bound to macros and the
b8c60bc9
CR
10179 strings they output to the Readline output stream. If a numeric
10180 argument is supplied, the output is formatted in such a way that it
10181 can be made part of an INPUTRC file. This command is unbound by
10182 default.
bb70624e 10183
b8c60bc9
CR
10184‘execute-named-command (M-x)’
10185 Read a bindable Readline command name from the input and execute
10186 the function to which it's bound, as if the key sequence to which
10187 it was bound appeared in the input. If this function is supplied
10188 with a numeric argument, it passes that argument to the function it
10189 executes.
10190
10191‘spell-correct-word (C-x s)’
74091dd4 10192 Perform spelling correction on the current word, treating it as a
b8c60bc9 10193 directory or filename, in the same way as the ‘cdspell’ shell
74091dd4 10194 option. Word boundaries are the same as those used by
b8c60bc9
CR
10195 ‘shell-forward-word’.
10196
10197‘glob-complete-word (M-g)’
10198 Treat the word before point as a pattern for pathname expansion,
10199 with an asterisk implicitly appended, then use the pattern to
10200 generate a list of matching file names for possible completions.
10201
10202‘glob-expand-word (C-x *)’
10203 Treat the word before point as a pattern for pathname expansion,
10204 and insert the list of matching file names, replacing the word. If
10205 a numeric argument is supplied, append a ‘*’ before pathname
7117c2d2 10206 expansion.
bb70624e 10207
b8c60bc9
CR
10208‘glob-list-expansions (C-x g)’
10209 Display the list of expansions that would have been generated by
10210 ‘glob-expand-word’, and redisplay the line. If a numeric argument
10211 is supplied, append a ‘*’ before pathname expansion.
bb70624e 10212
b8c60bc9
CR
10213‘shell-expand-line (M-C-e)’
10214 Expand the line by performing shell word expansions. This performs
10215 alias and history expansion, $'STRING' and $"STRING" quoting, tilde
10216 expansion, parameter and variable expansion, arithmetic expansion,
10217 command and process substitution, word splitting, and quote
10218 removal. An explicit argument suppresses command and process
10219 substitution.
bb70624e 10220
b8c60bc9 10221‘history-expand-line (M-^)’
bb70624e
JA
10222 Perform history expansion on the current line.
10223
b8c60bc9 10224‘magic-space ()’
bb70624e 10225 Perform history expansion on the current line and insert a space
28ef6c31 10226 (*note History Interaction::).
bb70624e 10227
b8c60bc9 10228‘alias-expand-line ()’
28ef6c31 10229 Perform alias expansion on the current line (*note Aliases::).
bb70624e 10230
b8c60bc9 10231‘history-and-alias-expand-line ()’
bb70624e
JA
10232 Perform history and alias expansion on the current line.
10233
b8c60bc9
CR
10234‘insert-last-argument (M-. or M-_)’
10235 A synonym for ‘yank-last-arg’.
bb70624e 10236
b8c60bc9 10237‘edit-and-execute-command (C-x C-e)’
7117c2d2 10238 Invoke an editor on the current command line, and execute the
b8c60bc9
CR
10239 result as shell commands. Bash attempts to invoke ‘$VISUAL’,
10240 ‘$EDITOR’, and ‘emacs’ as the editor, in that order.
10241
10242‘display-shell-version (C-x C-v)’
10243 Display version information about the current instance of Bash.
b80f6443 10244
bb70624e
JA
10245\1f
10246File: bashref.info, Node: Readline vi Mode, Next: Programmable Completion, Prev: Bindable Readline Commands, Up: Command Line Editing
10247
b80f6443
JA
102488.5 Readline vi Mode
10249====================
bb70624e 10250
b8c60bc9 10251While the Readline library does not have a full set of ‘vi’ editing
bb70624e 10252functions, it does contain enough to allow simple editing of the line.
b8c60bc9
CR
10253The Readline ‘vi’ mode behaves as specified in the ‘sh’ description in
10254the POSIX standard.
bb70624e 10255
b8c60bc9
CR
10256 You can use the ‘set -o emacs’ and ‘set -o vi’ commands (*note The
10257Set Builtin::) to switch interactively between ‘emacs’ and ‘vi’ editing
10258modes, The Readline default is ‘emacs’ mode.
bb70624e 10259
b8c60bc9
CR
10260 When you enter a line in ‘vi’ mode, you are already placed in
10261'insertion' mode, as if you had typed an ‘i’. Pressing <ESC> switches
a0c0a00f 10262you into 'command' mode, where you can edit the text of the line with
b8c60bc9
CR
10263the standard ‘vi’ movement keys, move to previous history lines with ‘k’
10264and subsequent lines with ‘j’, and so forth.
bb70624e
JA
10265
10266\1f
10267File: bashref.info, Node: Programmable Completion, Next: Programmable Completion Builtins, Prev: Readline vi Mode, Up: Command Line Editing
10268
b80f6443
JA
102698.6 Programmable Completion
10270===========================
bb70624e 10271
b8c60bc9
CR
10272When the user attempts word completion for a command or an argument to a
10273command for which a completion specification (a “compspec”) has been
10274defined using the ‘complete’ builtin (*note Programmable Completion
10275Builtins::), Readline invokes the programmable completion facilities.
bb70624e 10276
b8c60bc9 10277 First, Bash identifies the command name. If a compspec has been
bb70624e 10278defined for that command, the compspec is used to generate the list of
0001803f 10279possible completions for the word. If the command word is the empty
b8c60bc9
CR
10280string (completion attempted at the beginning of an empty line), Bash
10281uses any compspec defined with the ‘-E’ option to ‘complete’. The ‘-I’
10282option to ‘complete’ indicates that the command word is the first
10283non-assignment word on the line, or after a command delimiter such as
10284‘;’ or ‘|’. This usually indicates command name completion.
10285
10286 If the command word is a full pathname, Bash searches for a compspec
10287for the full pathname first. If there is no compspec for the full
10288pathname, Bash attempts to find a compspec for the portion following the
10289final slash. If those searches do not result in a compspec, or if there
10290is no compspec for the command word, Bash uses any compspec defined with
10291the ‘-D’ option to ‘complete’ as the default. If there is no default
10292compspec, Bash performs alias expansion on the command word as a final
10293resort, and attempts to find a compspec for the command word resulting
10294from any successful expansion.
10295
10296 If a compspec is not found, Bash performs its default completion
10297described above (*note Commands For Completion::). Otherwise, once a
10298compspec has been found, Bash uses it to generate the list of matching
10299words.
10300
10301 First, Bash performs the ACTIONS specified by the compspec. This
10302only returns matches which are prefixes of the word being completed.
10303When the ‘-f’ or ‘-d’ option is used for filename or directory name
10304completion, Bash uses shell the variable ‘FIGNORE’ to filter the
10305matches. *Note Bash Variables::, for a description of ‘FIGNORE’.
10306
10307 Next, programmable completion generates matches specified by a
10308pathname expansion pattern supplied as an argument to the ‘-G’ option.
10309The words generated by the pattern need not match the word being
10310completed. Bash uses the ‘FIGNORE’ variable to filter the matches, but
10311does not use the ‘GLOBIGNORE’ shell variable.
10312
10313 Next, completion considers the string specified as the argument to
10314the ‘-W’ option. The string is first split using the characters in the
10315‘IFS’ special variable as delimiters. This honors shell quoting within
10316the string, in order to provide a mechanism for the words to contain
10317shell metacharacters or characters in the value of ‘IFS’. Each word is
10318then expanded using brace expansion, tilde expansion, parameter and
10319variable expansion, command substitution, and arithmetic expansion, as
10320described above (*note Shell Expansions::). The results are split using
10321the rules described above (*note Word Splitting::). The results of the
10322expansion are prefix-matched against the word being completed, and the
10323matching words become possible completions.
10324
10325 After these matches have been generated, Bash executes any shell
10326function or command specified with the ‘-F’ and ‘-C’ options. When the
10327command or function is invoked, Bash assigns values to the ‘COMP_LINE’,
10328‘COMP_POINT’, ‘COMP_KEY’, and ‘COMP_TYPE’ variables as described above
10329(*note Bash Variables::). If a shell function is being invoked, Bash
10330also sets the ‘COMP_WORDS’ and ‘COMP_CWORD’ variables. When the
ac50fbac
CR
10331function or command is invoked, the first argument ($1) is the name of
10332the command whose arguments are being completed, the second argument
10333($2) is the word being completed, and the third argument ($3) is the
b8c60bc9
CR
10334word preceding the word being completed on the current command line.
10335There is no filtering of the generated completions against the word
10336being completed; the function or command has complete freedom in
10337generating the matches and they do not need to match a prefix of the
10338word.
10339
10340 Any function specified with ‘-F’ is invoked first. The function may
10341use any of the shell facilities, including the ‘compgen’ and ‘compopt’
3185942a
JA
10342builtins described below (*note Programmable Completion Builtins::), to
10343generate the matches. It must put the possible completions in the
b8c60bc9 10344‘COMPREPLY’ array variable, one per array element.
bb70624e 10345
b8c60bc9 10346 Next, any command specified with the ‘-C’ option is invoked in an
bb70624e 10347environment equivalent to command substitution. It should print a list
b8c60bc9
CR
10348of completions, one per line, to the standard output. Backslash will
10349escape a newline, if necessary. These are added to the set of possible
bb70624e
JA
10350completions.
10351
b8c60bc9
CR
10352 After generating all of the possible completions, Bash applies any
10353filter specified with the ‘-X’ option to the completions in the list.
10354The filter is a pattern as used for pathname expansion; a ‘&’ in the
10355pattern is replaced with the text of the word being completed. A
10356literal ‘&’ may be escaped with a backslash; the backslash is removed
10357before attempting a match. Any completion that matches the pattern is
10358removed from the list. A leading ‘!’ negates the pattern; in this case
10359Bash removes any completion that does not match the pattern. If the
10360‘nocasematch’ shell option is enabled (see the description of ‘shopt’ in
10361*note The Shopt Builtin::), Bash performs the match without regard to
10362the case of alphabetic characters.
10363
10364 Finally, programmable completion adds any prefix and suffix specified
10365with the ‘-P’ and ‘-S’ options, respectively, to each completion, and
10366returns the result to Readline as the list of possible completions.
10367
28ef6c31 10368 If the previously-applied actions do not generate any matches, and
b8c60bc9
CR
10369the ‘-o dirnames’ option was supplied to ‘complete’ when the compspec
10370was defined, Bash attempts directory name completion.
28ef6c31 10371
b8c60bc9
CR
10372 If the ‘-o plusdirs’ option was supplied to ‘complete’ when the
10373compspec was defined, Bash attempts directory name completion and adds
10374any matches to the set of possible completions.
b80f6443 10375
a0c0a00f
CR
10376 By default, if a compspec is found, whatever it generates is returned
10377to the completion code as the full set of possible completions. The
b8c60bc9
CR
10378default Bash completions and the Readline default of filename completion
10379are disabled. If the ‘-o bashdefault’ option was supplied to ‘complete’
10380when the compspec was defined, and the compspec generates no matches,
10381Bash attempts its default completions. If the compspec and, if
10382attempted, the default Bash completions generate no matches, and the ‘-o
10383default’ option was supplied to ‘complete’ when the compspec was
10384defined, programmable completion performs Readline's default completion.
10385
10386 The options supplied to ‘complete’ and ‘compopt’ can control how
10387Readline treats the completions. For instance, the ‘-o fullquote’
10388option tells Readline to quote the matches as if they were filenames.
10389See the description of ‘complete’ (*note Programmable Completion
10390Builtins::) for details.
10391
10392 When a compspec indicates that it wants directory name completion,
7117c2d2
JA
10393the programmable completion functions force Readline to append a slash
10394to completed names which are symbolic links to directories, subject to
10395the value of the MARK-DIRECTORIES Readline variable, regardless of the
10396setting of the MARK-SYMLINKED-DIRECTORIES Readline variable.
10397
0001803f
CR
10398 There is some support for dynamically modifying completions. This is
10399most useful when used in combination with a default completion specified
b8c60bc9
CR
10400with ‘-D’. It's possible for shell functions executed as completion
10401functions to indicate that completion should be retried by returning an
0001803f
CR
10402exit status of 124. If a shell function returns 124, and changes the
10403compspec associated with the command on which completion is being
10404attempted (supplied as the first argument when the function is
10405executed), programmable completion restarts from the beginning, with an
b8c60bc9
CR
10406attempt to find a new compspec for that command. This can be used to
10407build a set of completions dynamically as completion is attempted,
10408rather than loading them all at once.
0001803f
CR
10409
10410 For instance, assuming that there is a library of compspecs, each
10411kept in a file corresponding to the name of the command, the following
10412default completion function would load completions dynamically:
10413
10414 _completion_loader()
10415 {
ac50fbac 10416 . "/etc/bash_completion.d/$1.sh" >/dev/null 2>&1 && return 124
0001803f 10417 }
ac50fbac 10418 complete -D -F _completion_loader -o bashdefault -o default
0001803f 10419
bb70624e 10420\1f
ac50fbac 10421File: bashref.info, Node: Programmable Completion Builtins, Next: A Programmable Completion Example, Prev: Programmable Completion, Up: Command Line Editing
bb70624e 10422
b80f6443
JA
104238.7 Programmable Completion Builtins
10424====================================
bb70624e 10425
ac50fbac
CR
10426Three builtin commands are available to manipulate the programmable
10427completion facilities: one to specify how the arguments to a particular
10428command are to be completed, and two to modify the completion as it is
10429happening.
bb70624e 10430
b8c60bc9
CR
10431‘compgen’
10432 compgen [-V VARNAME] [OPTION] [WORD]
bb70624e
JA
10433
10434 Generate possible completion matches for WORD according to the
b8c60bc9
CR
10435 OPTIONs, which may be any option accepted by the ‘complete’ builtin
10436 with the exceptions of ‘-p’, ‘-r’, ‘-D’, ‘-E’, and ‘-I’, and write
10437 the matches to the standard output.
10438
10439 If the ‘-V’ option is supplied, ‘compgen’ stores the generated
10440 completions into the indexed array variable VARNAME instead of
10441 writing them to the standard output.
10442
10443 When using the ‘-F’ or ‘-C’ options, the various shell variables
10444 set by the programmable completion facilities, while available,
10445 will not have useful values.
bb70624e
JA
10446
10447 The matches will be generated in the same way as if the
10448 programmable completion code had generated them directly from a
10449 completion specification with the same flags. If WORD is
b8c60bc9
CR
10450 specified, only those completions matching WORD will be displayed
10451 or stored.
bb70624e
JA
10452
10453 The return value is true unless an invalid option is supplied, or
10454 no matches were generated.
10455
b8c60bc9
CR
10456‘complete’
10457 complete [-abcdefgjksuv] [-o COMP-OPTION] [-DEI] [-A ACTION]
10458 [-G GLOBPAT] [-W WORDLIST] [-F FUNCTION] [-C COMMAND]
10459 [-X FILTERPAT] [-P PREFIX] [-S SUFFIX] NAME [NAME ...]
d233b485 10460 complete -pr [-DEI] [NAME ...]
bb70624e 10461
b8c60bc9
CR
10462 Specify how arguments to each NAME should be completed.
10463
10464 If the ‘-p’ option is supplied, or if no options or NAMEs are
10465 supplied, print existing completion specifications in a way that
10466 allows them to be reused as input. The ‘-r’ option removes a
10467 completion specification for each NAME, or, if no NAMEs are
10468 supplied, all completion specifications.
10469
10470 The ‘-D’ option indicates that other supplied options and actions
10471 should apply to the "default" command completion; that is,
10472 completion attempted on a command for which no completion has
10473 previously been defined. The ‘-E’ option indicates that other
10474 supplied options and actions should apply to "empty" command
10475 completion; that is, completion attempted on a blank line. The
10476 ‘-I’ option indicates that other supplied options and actions
8868edaf 10477 should apply to completion on the initial non-assignment word on
b8c60bc9 10478 the line, or after a command delimiter such as ‘;’ or ‘|’, which is
d233b485 10479 usually command name completion. If multiple options are supplied,
b8c60bc9
CR
10480 the ‘-D’ option takes precedence over ‘-E’, and both take
10481 precedence over ‘-I’. If any of ‘-D’, ‘-E’, or ‘-I’ are supplied,
d233b485
CR
10482 any other NAME arguments are ignored; these completions only apply
10483 to the case specified by the option.
bb70624e
JA
10484
10485 The process of applying these completion specifications when word
10486 completion is attempted is described above (*note Programmable
d233b485 10487 Completion::).
bb70624e
JA
10488
10489 Other options, if specified, have the following meanings. The
b8c60bc9
CR
10490 arguments to the ‘-G’, ‘-W’, and ‘-X’ options (and, if necessary,
10491 the ‘-P’ and ‘-S’ options) should be quoted to protect them from
10492 expansion before the ‘complete’ builtin is invoked.
bb70624e 10493
b8c60bc9 10494 ‘-o COMP-OPTION’
28ef6c31
JA
10495 The COMP-OPTION controls several aspects of the compspec's
10496 behavior beyond the simple generation of completions.
10497 COMP-OPTION may be one of:
10498
b8c60bc9 10499 ‘bashdefault’
b80f6443
JA
10500 Perform the rest of the default Bash completions if the
10501 compspec generates no matches.
10502
b8c60bc9 10503 ‘default’
7117c2d2
JA
10504 Use Readline's default filename completion if the
10505 compspec generates no matches.
28ef6c31 10506
b8c60bc9 10507 ‘dirnames’
28ef6c31
JA
10508 Perform directory name completion if the compspec
10509 generates no matches.
10510
b8c60bc9 10511 ‘filenames’
28ef6c31 10512 Tell Readline that the compspec generates filenames, so
b8c60bc9 10513 it can perform any filename-specific processing (such as
d233b485 10514 adding a slash to directory names, quoting special
a0c0a00f
CR
10515 characters, or suppressing trailing spaces). This option
10516 is intended to be used with shell functions specified
b8c60bc9
CR
10517 with ‘-F’.
10518
10519 ‘fullquote’
10520 Tell Readline to quote all the completed words even if
10521 they are not filenames.
28ef6c31 10522
b8c60bc9 10523 ‘noquote’
ac50fbac
CR
10524 Tell Readline not to quote the completed words if they
10525 are filenames (quoting filenames is the default).
10526
b8c60bc9 10527 ‘nosort’
a0c0a00f
CR
10528 Tell Readline not to sort the list of possible
10529 completions alphabetically.
10530
b8c60bc9 10531 ‘nospace’
7117c2d2
JA
10532 Tell Readline not to append a space (the default) to
10533 words completed at the end of the line.
10534
b8c60bc9
CR
10535 ‘plusdirs’
10536 After generating any matches defined by the compspec,
10537 attempt directory name completion and add any matches to
10538 the results of the other actions.
95732b49 10539
b8c60bc9 10540 ‘-A ACTION’
bb70624e
JA
10541 The ACTION may be one of the following to generate a list of
10542 possible completions:
10543
b8c60bc9
CR
10544 ‘alias’
10545 Alias names. May also be specified as ‘-a’.
bb70624e 10546
b8c60bc9 10547 ‘arrayvar’
bb70624e
JA
10548 Array variable names.
10549
b8c60bc9 10550 ‘binding’
bb70624e 10551 Readline key binding names (*note Bindable Readline
28ef6c31 10552 Commands::).
bb70624e 10553
b8c60bc9 10554 ‘builtin’
bb70624e 10555 Names of shell builtin commands. May also be specified
b8c60bc9 10556 as ‘-b’.
bb70624e 10557
b8c60bc9
CR
10558 ‘command’
10559 Command names. May also be specified as ‘-c’.
bb70624e 10560
b8c60bc9
CR
10561 ‘directory’
10562 Directory names. May also be specified as ‘-d’.
bb70624e 10563
b8c60bc9 10564 ‘disabled’
bb70624e
JA
10565 Names of disabled shell builtins.
10566
b8c60bc9 10567 ‘enabled’
bb70624e
JA
10568 Names of enabled shell builtins.
10569
b8c60bc9 10570 ‘export’
a0c0a00f 10571 Names of exported shell variables. May also be specified
b8c60bc9 10572 as ‘-e’.
bb70624e 10573
b8c60bc9
CR
10574 ‘file’
10575 File and directory names, similar to Readline's filename
10576 completion. May also be specified as ‘-f’.
bb70624e 10577
b8c60bc9 10578 ‘function’
bb70624e
JA
10579 Names of shell functions.
10580
b8c60bc9
CR
10581 ‘group’
10582 Group names. May also be specified as ‘-g’.
f73dda09 10583
b8c60bc9
CR
10584 ‘helptopic’
10585 Help topics as accepted by the ‘help’ builtin (*note Bash
a0c0a00f 10586 Builtins::).
bb70624e 10587
b8c60bc9 10588 ‘hostname’
bb70624e 10589 Hostnames, as taken from the file specified by the
b8c60bc9 10590 ‘HOSTFILE’ shell variable (*note Bash Variables::).
bb70624e 10591
b8c60bc9 10592 ‘job’
bb70624e 10593 Job names, if job control is active. May also be
b8c60bc9 10594 specified as ‘-j’.
bb70624e 10595
b8c60bc9
CR
10596 ‘keyword’
10597 Shell reserved words. May also be specified as ‘-k’.
bb70624e 10598
b8c60bc9 10599 ‘running’
bb70624e
JA
10600 Names of running jobs, if job control is active.
10601
b8c60bc9
CR
10602 ‘service’
10603 Service names. May also be specified as ‘-s’.
7117c2d2 10604
b8c60bc9
CR
10605 ‘setopt’
10606 Valid arguments for the ‘-o’ option to the ‘set’ builtin
28ef6c31 10607 (*note The Set Builtin::).
bb70624e 10608
b8c60bc9
CR
10609 ‘shopt’
10610 Shell option names as accepted by the ‘shopt’ builtin
28ef6c31 10611 (*note Bash Builtins::).
bb70624e 10612
b8c60bc9 10613 ‘signal’
bb70624e
JA
10614 Signal names.
10615
b8c60bc9 10616 ‘stopped’
bb70624e
JA
10617 Names of stopped jobs, if job control is active.
10618
b8c60bc9
CR
10619 ‘user’
10620 User names. May also be specified as ‘-u’.
bb70624e 10621
b8c60bc9 10622 ‘variable’
bb70624e 10623 Names of all shell variables. May also be specified as
b8c60bc9 10624 ‘-v’.
bb70624e 10625
b8c60bc9 10626 ‘-C COMMAND’
bb70624e 10627 COMMAND is executed in a subshell environment, and its output
74091dd4 10628 is used as the possible completions. Arguments are passed as
b8c60bc9 10629 with the ‘-F’ option.
bb70624e 10630
b8c60bc9 10631 ‘-F FUNCTION’
bb70624e 10632 The shell function FUNCTION is executed in the current shell
b8c60bc9
CR
10633 environment. When it is executed, the first argument ($1) is
10634 the name of the command whose arguments are being completed,
10635 the second argument ($2) is the word being completed, and the
10636 third argument ($3) is the word preceding the word being
ac50fbac 10637 completed, as described above (*note Programmable
b8c60bc9
CR
10638 Completion::). When ‘function’ finishes, programmable
10639 completion retrieves the possible completions from the value
10640 of the ‘COMPREPLY’ array variable.
bb70624e 10641
b8c60bc9
CR
10642 ‘-G GLOBPAT’
10643 Expand the filename expansion pattern GLOBPAT to generate the
10644 possible completions.
bb70624e 10645
b8c60bc9
CR
10646 ‘-P PREFIX’
10647 Add PREFIX to the beginning of each possible completion after
10648 all other options have been applied.
bb70624e 10649
b8c60bc9
CR
10650 ‘-S SUFFIX’
10651 Append SUFFIX to each possible completion after all other
a0c0a00f 10652 options have been applied.
bb70624e 10653
b8c60bc9
CR
10654 ‘-W WORDLIST’
10655 Split the WORDLIST using the characters in the ‘IFS’ special
10656 variable as delimiters, and expand each resulting word. Shell
10657 quoting is honored within WORDLIST in order to provide a
10658 mechanism for the words to contain shell metacharacters or
10659 characters in the value of ‘IFS’. The possible completions
10660 are the members of the resultant list which match a prefix of
10661 the word being completed.
495aee44 10662
b8c60bc9 10663 ‘-X FILTERPAT’
495aee44
CR
10664 FILTERPAT is a pattern as used for filename expansion. It is
10665 applied to the list of possible completions generated by the
10666 preceding options and arguments, and each completion matching
b8c60bc9 10667 FILTERPAT is removed from the list. A leading ‘!’ in
495aee44
CR
10668 FILTERPAT negates the pattern; in this case, any completion
10669 not matching FILTERPAT is removed.
10670
bb70624e 10671 The return value is true unless an invalid option is supplied, an
b8c60bc9
CR
10672 option other than ‘-p’, ‘-r’, ‘-D’, ‘-E’, or ‘-I’ is supplied
10673 without a NAME argument, an attempt is made to remove a completion
10674 specification for a NAME for which no specification exists, or an
10675 error occurs adding a completion specification.
bb70624e 10676
b8c60bc9 10677‘compopt’
d233b485 10678 compopt [-o OPTION] [-DEI] [+o OPTION] [NAME]
3185942a 10679 Modify completion options for each NAME according to the OPTIONs,
495aee44 10680 or for the currently-executing completion if no NAMEs are supplied.
3185942a
JA
10681 If no OPTIONs are given, display the completion options for each
10682 NAME or the current completion. The possible values of OPTION are
b8c60bc9 10683 those valid for the ‘complete’ builtin described above.
0001803f 10684
b8c60bc9
CR
10685 The ‘-D’ option indicates that other supplied options should apply
10686 to the "default" command completion; the ‘-E’ option indicates that
10687 other supplied options should apply to "empty" command completion;
10688 and the ‘-I’ option indicates that other supplied options should
10689 apply to completion on the initial word on the line. These are
10690 determined in the same way as the ‘complete’ builtin.
10691
10692 If multiple options are supplied, the ‘-D’ option takes precedence
10693 over ‘-E’, and both take precedence over ‘-I’
3185942a
JA
10694
10695 The return value is true unless an invalid option is supplied, an
10696 attempt is made to modify the options for a NAME for which no
10697 completion specification exists, or an output error occurs.
10698
ac50fbac
CR
10699\1f
10700File: bashref.info, Node: A Programmable Completion Example, Prev: Programmable Completion Builtins, Up: Command Line Editing
10701
107028.8 A Programmable Completion Example
10703=====================================
10704
10705The most common way to obtain additional completion functionality beyond
b8c60bc9
CR
10706the default actions ‘complete’ and ‘compgen’ provide is to use a shell
10707function and bind it to a particular command using ‘complete -F’.
ac50fbac 10708
b8c60bc9 10709 The following function provides completions for the ‘cd’ builtin. It
a0c0a00f 10710is a reasonably good example of what shell functions must do when used
b8c60bc9
CR
10711for completion. This function uses the word passed as ‘$2’ to determine
10712the directory name to complete. You can also use the ‘COMP_WORDS’ array
10713variable; the current word is indexed by the ‘COMP_CWORD’ variable.
ac50fbac 10714
b8c60bc9
CR
10715 The function relies on the ‘complete’ and ‘compgen’ builtins to do
10716much of the work, adding only the things that the Bash ‘cd’ does beyond
ac50fbac
CR
10717accepting basic directory names: tilde expansion (*note Tilde
10718Expansion::), searching directories in $CDPATH, which is described above
b8c60bc9
CR
10719(*note Bourne Shell Builtins::), and basic support for the ‘cdable_vars’
10720shell option (*note The Shopt Builtin::). ‘_comp_cd’ modifies the value
a0c0a00f 10721of IFS so that it contains only a newline to accommodate file names
b8c60bc9 10722containing spaces and tabs - ‘compgen’ prints the possible completions
a0c0a00f 10723it generates one per line.
ac50fbac
CR
10724
10725 Possible completions go into the COMPREPLY array variable, one
10726completion per array element. The programmable completion system
10727retrieves the completions from there when the function returns.
10728
10729 # A completion function for the cd builtin
10730 # based on the cd completion function from the bash_completion package
10731 _comp_cd()
10732 {
10733 local IFS=$' \t\n' # normalize IFS
10734 local cur _skipdot _cdpath
10735 local i j k
10736
d233b485 10737 # Tilde expansion, which also expands tilde to full pathname
ac50fbac
CR
10738 case "$2" in
10739 \~*) eval cur="$2" ;;
10740 *) cur=$2 ;;
10741 esac
10742
10743 # no cdpath or absolute pathname -- straight directory completion
10744 if [[ -z "${CDPATH:-}" ]] || [[ "$cur" == @(./*|../*|/*) ]]; then
10745 # compgen prints paths one per line; could also use while loop
10746 IFS=$'\n'
10747 COMPREPLY=( $(compgen -d -- "$cur") )
10748 IFS=$' \t\n'
10749 # CDPATH+directories in the current directory if not in CDPATH
10750 else
10751 IFS=$'\n'
10752 _skipdot=false
10753 # preprocess CDPATH to convert null directory names to .
10754 _cdpath=${CDPATH/#:/.:}
10755 _cdpath=${_cdpath//::/:.:}
10756 _cdpath=${_cdpath/%:/:.}
10757 for i in ${_cdpath//:/$'\n'}; do
10758 if [[ $i -ef . ]]; then _skipdot=true; fi
10759 k="${#COMPREPLY[@]}"
10760 for j in $( compgen -d -- "$i/$cur" ); do
10761 COMPREPLY[k++]=${j#$i/} # cut off directory
10762 done
10763 done
10764 $_skipdot || COMPREPLY+=( $(compgen -d -- "$cur") )
10765 IFS=$' \t\n'
10766 fi
10767
10768 # variable names if appropriate shell option set and no completions
10769 if shopt -q cdable_vars && [[ ${#COMPREPLY[@]} -eq 0 ]]; then
10770 COMPREPLY=( $(compgen -v -- "$cur") )
10771 fi
10772
10773 return 0
10774 }
10775
b8c60bc9
CR
10776 We install the completion function using the ‘-F’ option to
10777‘complete’:
ac50fbac
CR
10778
10779 # Tell readline to quote appropriate and append slashes to directories;
10780 # use the bash default completion for other arguments
10781 complete -o filenames -o nospace -o bashdefault -F _comp_cd cd
10782
10783Since we'd like Bash and Readline to take care of some of the other
10784details for us, we use several other options to tell Bash and Readline
b8c60bc9 10785what to do. The ‘-o filenames’ option tells Readline that the possible
ac50fbac
CR
10786completions should be treated as filenames, and quoted appropriately.
10787That option will also cause Readline to append a slash to filenames it
10788can determine are directories (which is why we might want to extend
b8c60bc9
CR
10789‘_comp_cd’ to append a slash if we're using directories found via
10790CDPATH: Readline can't tell those completions are directories). The ‘-o
10791nospace’ option tells Readline to not append a space character to the
10792directory name, in case we want to append to it. The ‘-o bashdefault’
a0c0a00f 10793option brings in the rest of the "Bash default" completions - possible
74091dd4 10794completions that Bash adds to the default Readline set. These include
a0c0a00f 10795things like command name completion, variable completion for words
b8c60bc9 10796beginning with ‘$’ or ‘${’, completions containing pathname expansion
8868edaf 10797patterns (*note Filename Expansion::), and so on.
a0c0a00f 10798
b8c60bc9
CR
10799 Once installed using ‘complete’, ‘_comp_cd’ will be called every time
10800we attempt word completion for a ‘cd’ command.
ac50fbac
CR
10801
10802 Many more examples - an extensive collection of completions for most
10803of the common GNU, Unix, and Linux commands - are available as part of
10804the bash_completion project. This is installed by default on many
10805GNU/Linux distributions. Originally written by Ian Macdonald, the
8868edaf 10806project now lives at <https://github.com/scop/bash-completion/>. There
a0c0a00f 10807are ports for other systems such as Solaris and Mac OS X.
ac50fbac
CR
10808
10809 An older version of the bash_completion package is distributed with
b8c60bc9 10810bash in the ‘examples/complete’ subdirectory.
ac50fbac 10811
bb70624e 10812\1f
3185942a 10813File: bashref.info, Node: Using History Interactively, Next: Installing Bash, Prev: Command Line Editing, Up: Top
bb70624e 10814
b80f6443
JA
108159 Using History Interactively
10816*****************************
bb70624e 10817
a0c0a00f
CR
10818This chapter describes how to use the GNU History Library interactively,
10819from a user's standpoint. It should be considered a user's guide. For
10820information on using the GNU History Library in other programs, see the
10821GNU Readline Library Manual.
bb70624e
JA
10822
10823* Menu:
10824
10825* Bash History Facilities:: How Bash lets you manipulate your command
10826 history.
10827* Bash History Builtins:: The Bash builtin commands that manipulate
10828 the command history.
10829* History Interaction:: What it feels like using History as a user.
10830
10831\1f
10832File: bashref.info, Node: Bash History Facilities, Next: Bash History Builtins, Up: Using History Interactively
10833
b80f6443
JA
108349.1 Bash History Facilities
10835===========================
bb70624e 10836
b8c60bc9
CR
10837When the ‘-o history’ option to the ‘set’ builtin is enabled (*note The
10838Set Builtin::), the shell provides access to the “command history”, the
10839list of commands previously typed. The value of the ‘HISTSIZE’ shell
10840variable is used as the number of commands to save in a history list:
10841the shell saves the text of the last ‘$HISTSIZE’ commands (default 500).
10842The shell stores each command in the history list prior to parameter and
b80f6443 10843variable expansion but after history expansion is performed, subject to
b8c60bc9
CR
10844the values of the shell variables ‘HISTIGNORE’ and ‘HISTCONTROL’.
10845
10846 When the shell starts up, Bash initializes the history list by
10847reading history entries from the file named by the ‘HISTFILE’ variable
10848(default ‘~/.bash_history’). This is referred to as the “history file”.
10849The history file is truncated, if necessary, to contain no more than the
10850number of history entries specified by the value of the ‘HISTFILESIZE’
10851variable. If ‘HISTFILESIZE’ is unset, or set to null, a non-numeric
10852value, or a numeric value less than zero, the history file is not
10853truncated.
10854
10855 When the history file is read, lines beginning with the history
10856comment character followed immediately by a digit are interpreted as
10857timestamps for the following history entry. These timestamps are
10858optionally displayed depending on the value of the ‘HISTTIMEFORMAT’
10859variable (*note Bash Variables::). When present, history timestamps
10860delimit history entries, making multi-line entries possible.
10861
10862 When a shell with history enabled exits, Bash copies the last
10863‘$HISTSIZE’ entries from the history list to the file named by
10864‘$HISTFILE’. If the ‘histappend’ shell option is set (*note Bash
10865Builtins::), Bash appends the entries to the history file, otherwise it
10866overwrites the history file. If ‘HISTFILE’ is unset or null, or if the
ac50fbac 10867history file is unwritable, the history is not saved. After saving the
b8c60bc9
CR
10868history, Bash truncates the history file to contain no more than
10869‘$HISTFILESIZE’ lines as described above.
10870
10871 If the ‘HISTTIMEFORMAT’ variable is set, the shell writes the
10872timestamp information associated with each history entry to the history
10873file, marked with the history comment character, so timestamps are
10874preserved across shell sessions. When the history file is read, lines
a0c0a00f 10875beginning with the history comment character followed immediately by a
b8c60bc9
CR
10876digit are interpreted as timestamps for the following history entry. As
10877above, when using ‘HISTTIMEFORMAT’, the timestamps delimit multi-line
10878history entries.
b80f6443 10879
b8c60bc9
CR
10880 The ‘fc’ builtin command will list or edit and re-execute a portion
10881of the history list. The ‘history’ builtin can display or modify the
10882history list and manipulate the history file. When using command-line
10883editing, search commands are available in each editing mode that provide
10884access to the history list (*note Commands For History::).
bb70624e
JA
10885
10886 The shell allows control over which commands are saved on the history
b8c60bc9
CR
10887list. The ‘HISTCONTROL’ and ‘HISTIGNORE’ variables are used to save
10888only a subset of the commands entered. If the ‘cmdhist’ shell option is
10889enabled, the shell attempts to save each line of a multi-line command in
10890the same history entry, adding semicolons where necessary to preserve
10891syntactic correctness. The ‘lithist’ shell option modifies ‘cmdhist’ by
10892saving the command with embedded newlines instead of semicolons. The
10893‘shopt’ builtin is used to set these options. *Note The Shopt
10894Builtin::, for a description of ‘shopt’.
bb70624e
JA
10895
10896\1f
10897File: bashref.info, Node: Bash History Builtins, Next: History Interaction, Prev: Bash History Facilities, Up: Using History Interactively
10898
b80f6443
JA
108999.2 Bash History Builtins
10900=========================
bb70624e 10901
a0c0a00f
CR
10902Bash provides two builtin commands which manipulate the history list and
10903history file.
bb70624e 10904
b8c60bc9 10905‘fc’
a0c0a00f
CR
10906 fc [-e ENAME] [-lnr] [FIRST] [LAST]
10907 fc -s [PAT=REP] [COMMAND]
bb70624e 10908
ac50fbac
CR
10909 The first form selects a range of commands from FIRST to LAST from
10910 the history list and displays or edits and re-executes them. Both
10911 FIRST and LAST may be specified as a string (to locate the most
a0c0a00f
CR
10912 recent command beginning with that string) or as a number (an index
10913 into the history list, where a negative number is used as an offset
8868edaf
CR
10914 from the current command number).
10915
10916 When listing, a FIRST or LAST of 0 is equivalent to -1 and -0 is
b8c60bc9 10917 equivalent to the current command (usually the ‘fc’ command);
8868edaf
CR
10918 otherwise 0 is equivalent to -1 and -0 is invalid.
10919
b8c60bc9
CR
10920 If LAST is not specified, it is set to the current command for
10921 listing and to FIRST otherwise. If FIRST is not specified, it is
10922 set to the previous command for editing and −16 for listing.
10923
10924 If the ‘-l’ flag is supplied, the commands are listed on standard
10925 output. The ‘-n’ flag suppresses the command numbers when listing.
10926 The ‘-r’ flag reverses the order of the listing.
10927
10928 Otherwise, ‘fc’ invokes the editor named by ENAME on a file
10929 containing those commands. If ENAME is not supplied, ‘fc’ uses the
10930 value of the following variable expansion:
10931 ‘${FCEDIT:-${EDITOR:-vi}}’. This says to use the value of the
10932 ‘FCEDIT’ variable if set, or the value of the ‘EDITOR’ variable if
10933 that is set, or ‘vi’ if neither is set. When editing is complete,
10934 ‘fc’ reads the file of edited commands and echoes and executes
10935 them.
10936
10937 In the second form, ‘fc’ re-executes COMMAND after replacing each
10938 instance of PAT in the selected command with REP. COMMAND is
8868edaf 10939 interpreted the same as FIRST above.
bb70624e 10940
b8c60bc9
CR
10941 A useful alias to use with the ‘fc’ command is ‘r='fc -s'’, so that
10942 typing ‘r cc’ runs the last command beginning with ‘cc’ and typing
10943 ‘r’ re-executes the last command (*note Aliases::).
bb70624e 10944
b8c60bc9
CR
10945 If the first form is used, the return value is zero unless an
10946 invalid option is encountered or FIRST or LAST specify history
10947 lines out of range. When editing and re-executing a file of
10948 commands, the return value is the value of the last command
10949 executed or failure if an error occurs with the temporary file. If
10950 the second form is used, the return status is that of the
10951 re-executed command, unless COMMAND does not specify a valid
10952 history entry, in which case ‘fc’ returns a non-zero status.
10953
10954‘history’
bb70624e
JA
10955 history [N]
10956 history -c
10957 history -d OFFSET
d233b485 10958 history -d START-END
bb70624e
JA
10959 history [-anrw] [FILENAME]
10960 history -ps ARG
10961
b8c60bc9
CR
10962 With no options, display the history list with numbers. Entries
10963 prefixed with a ‘*’ have been modified. An argument of N lists
10964 only the last N entries. If the shell variable ‘HISTTIMEFORMAT’ is
10965 set and not null, it is used as a format string for ‘strftime’(3)
10966 to display the time stamp associated with each displayed history
10967 entry. If ‘history’ uses ‘HISTTIMEFORMAT’, it does not print an
10968 intervening space between the formatted time stamp and the history
10969 entry.
b80f6443
JA
10970
10971 Options, if supplied, have the following meanings:
bb70624e 10972
b8c60bc9 10973 ‘-c’
bb70624e 10974 Clear the history list. This may be combined with the other
b8c60bc9 10975 options to replace the history list.
bb70624e 10976
b8c60bc9 10977 ‘-d OFFSET’
d233b485
CR
10978 Delete the history entry at position OFFSET. If OFFSET is
10979 positive, it should be specified as it appears when the
10980 history is displayed. If OFFSET is negative, it is
10981 interpreted as relative to one greater than the last history
10982 position, so negative indices count back from the end of the
b8c60bc9
CR
10983 history, and an index of ‘-1’ refers to the current ‘history
10984 -d’ command.
d233b485 10985
b8c60bc9 10986 ‘-d START-END’
74091dd4
CR
10987 Delete the range of history entries between positions START
10988 and END, inclusive. Positive and negative values for START
10989 and END are interpreted as described above.
bb70624e 10990
b8c60bc9
CR
10991 ‘-a’
10992 Append the "new" history lines to the history file. These are
a0c0a00f
CR
10993 history lines entered since the beginning of the current Bash
10994 session, but not already appended to the history file.
bb70624e 10995
b8c60bc9
CR
10996 ‘-n’
10997 Read the history lines not already read from the history file
10998 and add them to the current history list. These are lines
10999 appended to the history file since the beginning of the
11000 current Bash session.
bb70624e 11001
b8c60bc9 11002 ‘-r’
ac50fbac
CR
11003 Read the history file and append its contents to the history
11004 list.
bb70624e 11005
b8c60bc9
CR
11006 ‘-w’
11007 Write the current history list to the history file,
11008 overwriting the history file.
bb70624e 11009
b8c60bc9 11010 ‘-p’
bb70624e
JA
11011 Perform history substitution on the ARGs and display the
11012 result on the standard output, without storing the results in
11013 the history list.
11014
b8c60bc9
CR
11015 ‘-s’
11016 Add the ARGs to the end of the history list as a single entry.
11017 The last command in the history list is removed before adding
11018 the ARGs.
11019
11020 If a FILENAME argument is supplied with any of the ‘-w’, ‘-r’,
11021 ‘-a’, or ‘-n’ options, Bash uses FILENAME as the history file. If
11022 not, it uses the value of the ‘HISTFILE’ variable. If ‘HISTFILE’
11023 is unset or null, these options have no effect.
bb70624e 11024
b8c60bc9
CR
11025 If the ‘HISTTIMEFORMAT’ variable is set, ‘history’ writes the time
11026 stamp information associated with each history entry to the history
11027 file, marked with the history comment character as described above.
11028 When the history file is read, lines beginning with the history
11029 comment character followed immediately by a digit are interpreted
11030 as timestamps for the following history entry.
74091dd4
CR
11031
11032 The return value is 0 unless an invalid option is encountered, an
11033 error occurs while reading or writing the history file, an invalid
b8c60bc9
CR
11034 OFFSET or range is supplied as an argument to ‘-d’, or the history
11035 expansion supplied as an argument to ‘-p’ fails.
b80f6443 11036
bb70624e
JA
11037\1f
11038File: bashref.info, Node: History Interaction, Prev: Bash History Builtins, Up: Using History Interactively
ccc6cda3 11039
b80f6443
JA
110409.3 History Expansion
11041=====================
ccc6cda3 11042
b8c60bc9
CR
11043The shell provides a history expansion feature that is similar to the
11044history expansion provided by ‘csh’ (also referred to as history
11045substitution where appropriate). This section describes the syntax used
11046to manipulate the history information.
11047
11048 History expansion is enabled by default for interactive shells, and
11049can be disabled using the ‘+H’ option to the ‘set’ builtin command
11050(*note The Set Builtin::). Non-interactive shells do not perform
11051history expansion by default, but it can be enabled with ‘set -H’.
ccc6cda3 11052
bb70624e 11053 History expansions introduce words from the history list into the
a0c0a00f
CR
11054input stream, making it easy to repeat commands, insert the arguments to
11055a previous command into the current input line, or fix errors in
bb70624e 11056previous commands quickly.
ccc6cda3 11057
a0c0a00f 11058 History expansion is performed immediately after a complete line is
d233b485
CR
11059read, before the shell breaks it into words, and is performed on each
11060line individually. Bash attempts to inform the history expansion
11061functions about quoting still in effect from previous lines.
a0c0a00f 11062
bb70624e 11063 History expansion takes place in two parts. The first is to
b8c60bc9
CR
11064determine which entry from the history list should be used during
11065substitution. The second is to select portions of that entry to include
11066into the current one.
11067
11068 The entry selected from the history is called the “event”, and the
11069portions of that entry that are acted upon are “words”. Various
11070“modifiers” are available to manipulate the selected words. The entry
11071is split into words in the same fashion that Bash does when reading
11072input, so that several words surrounded by quotes are considered one
11073word. The “event designator” selects the event, the optional “word
11074designator” selects words from the event, and various optional
11075“modifiers” are available to manipulate the selected words.
11076
11077 History expansions are introduced by the appearance of the history
11078expansion character, which is ‘!’ by default. History expansions may
11079appear anywhere in the input, but do not nest.
d233b485
CR
11080
11081 History expansion implements shell-like quoting conventions: a
11082backslash can be used to remove the special handling for the next
11083character; single quotes enclose verbatim sequences of characters, and
11084can be used to inhibit history expansion; and characters enclosed within
11085double quotes may be subject to history expansion, since backslash can
11086escape the history expansion character, but single quotes may not, since
11087they are not treated specially within double quotes.
11088
b8c60bc9 11089 When using the shell, only ‘\’ and ‘'’ may be used to escape the
d233b485
CR
11090history expansion character, but the history expansion character is also
11091treated as quoted if it immediately precedes the closing double quote in
11092a double-quoted string.
11093
b8c60bc9
CR
11094 Several characters inhibit history expansion if found immediately
11095following the history expansion character, even if it is unquoted:
11096space, tab, newline, carriage return, ‘=’, and the other shell
11097metacharacters.
11098
11099 There is a special abbreviation for substitution, active when the
11100QUICK SUBSTITUTION character (described above under ‘histchars’) is the
11101first character on the line. It selects the previous history list
11102entry, using an event designator equivalent to ‘!!’, and substitutes one
11103string for another in that entry. It is described below (*note Event
11104Designators::). This is the only history expansion that does not begin
11105with the history expansion character.
11106
11107 Several shell options settable with the ‘shopt’ builtin (*note The
11108Shopt Builtin::) modify history expansion behavior If the ‘histverify’
11109shell option is enabled, and Readline is being used, history
11110substitutions are not immediately passed to the shell parser. Instead,
11111the expanded line is reloaded into the Readline editing buffer for
11112further modification. If Readline is being used, and the ‘histreedit’
11113shell option is enabled, a failed history expansion is reloaded into the
11114Readline editing buffer for correction.
11115
11116 The ‘-p’ option to the ‘history’ builtin command shows what a history
11117expansion will do before using it. The ‘-s’ option to the ‘history’
11118builtin may be used to add commands to the end of the history list
11119without actually executing them, so that they are available for
a0c0a00f 11120subsequent recall. This is most useful in conjunction with Readline.
bb70624e
JA
11121
11122 The shell allows control of the various characters used by the
b8c60bc9 11123history expansion mechanism with the ‘histchars’ variable, as explained
3185942a
JA
11124above (*note Bash Variables::). The shell uses the history comment
11125character to mark history timestamps when writing the history file.
bb70624e
JA
11126
11127* Menu:
11128
11129* Event Designators:: How to specify which history line to use.
11130* Word Designators:: Specifying which words are of interest.
11131* Modifiers:: Modifying the results of substitution.
ccc6cda3
JA
11132
11133\1f
bb70624e 11134File: bashref.info, Node: Event Designators, Next: Word Designators, Up: History Interaction
ccc6cda3 11135
b80f6443
JA
111369.3.1 Event Designators
11137-----------------------
ccc6cda3 11138
b8c60bc9
CR
11139An event designator is a reference to an entry in the history list. The
11140event designator consists of the portion of the word beginning with the
11141history expansion character, and ending with the word designator if one
11142is present, or the end of the word. Unless the reference is absolute,
11143events are relative to the current position in the history list.
ccc6cda3 11144
b8c60bc9 11145‘!’
bb70624e 11146 Start a history substitution, except when followed by a space, tab,
b8c60bc9
CR
11147 the end of the line, ‘=’, or the rest of the shell metacharacters
11148 defined above (*note Definitions::).
ccc6cda3 11149
b8c60bc9
CR
11150‘!N’
11151 Refer to history list entry N.
ccc6cda3 11152
b8c60bc9
CR
11153‘!-N’
11154 Refer to the history entry minus N.
ccc6cda3 11155
b8c60bc9
CR
11156‘!!’
11157 Refer to the previous entry. This is a synonym for ‘!-1’.
ccc6cda3 11158
b8c60bc9 11159‘!STRING’
495aee44
CR
11160 Refer to the most recent command preceding the current position in
11161 the history list starting with STRING.
ccc6cda3 11162
b8c60bc9 11163‘!?STRING[?]’
495aee44 11164 Refer to the most recent command preceding the current position in
b8c60bc9 11165 the history list containing STRING. The trailing ‘?’ may be
8868edaf 11166 omitted if the STRING is followed immediately by a newline. If
b8c60bc9
CR
11167 STRING is missing, this uses the string from the most recent
11168 search; it is an error if there is no previous search string.
ccc6cda3 11169
b8c60bc9 11170‘^STRING1^STRING2^’
bb70624e 11171 Quick Substitution. Repeat the last command, replacing STRING1
b8c60bc9 11172 with STRING2. Equivalent to ‘!!:s^STRING1^STRING2^’.
bb70624e 11173
b8c60bc9 11174‘!#’
bb70624e 11175 The entire command line typed so far.
ccc6cda3
JA
11176
11177\1f
bb70624e 11178File: bashref.info, Node: Word Designators, Next: Modifiers, Prev: Event Designators, Up: History Interaction
ccc6cda3 11179
b80f6443
JA
111809.3.2 Word Designators
11181----------------------
ccc6cda3 11182
b8c60bc9
CR
11183Word designators are used to select desired words from the event. They
11184are optional; if the word designator isn't supplied, the history
11185expansion uses the entire event. A ‘:’ separates the event
11186specification from the word designator. It may be omitted if the word
11187designator begins with a ‘^’, ‘$’, ‘*’, ‘-’, or ‘%’. Words are numbered
11188from the beginning of the line, with the first word being denoted by 0
11189(zero). That first word is usually the command word, and the arguments
11190begin with the second word. Words are inserted into the current line
a0c0a00f 11191separated by single spaces.
ccc6cda3 11192
bb70624e 11193 For example,
ccc6cda3 11194
b8c60bc9 11195‘!!’
bb70624e
JA
11196 designates the preceding command. When you type this, the
11197 preceding command is repeated in toto.
ccc6cda3 11198
b8c60bc9
CR
11199‘!!:$’
11200 designates the last word of the preceding command. This may be
11201 shortened to ‘!$’.
ccc6cda3 11202
b8c60bc9 11203‘!fi:2’
bb70624e 11204 designates the second argument of the most recent command starting
b8c60bc9 11205 with the letters ‘fi’.
ccc6cda3 11206
bb70624e 11207 Here are the word designators:
ccc6cda3 11208
b8c60bc9
CR
11209‘0 (zero)’
11210 The ‘0’th word. For the shell, and many other, applications, this
11211 is the command word.
ccc6cda3 11212
b8c60bc9 11213‘N’
bb70624e 11214 The Nth word.
ccc6cda3 11215
b8c60bc9
CR
11216‘^’
11217 The first argument: word 1.
ccc6cda3 11218
b8c60bc9
CR
11219‘$’
11220 The last word. This is usually the last argument, but expands to
11221 the zeroth word if there is only one word in the line.
ccc6cda3 11222
b8c60bc9
CR
11223‘%’
11224 The first word matched by the most recent ‘?STRING?’ search, if the
11225 search string begins with a character that is part of a word. By
11226 default, searches begin at the end of each line and proceed to the
11227 beginning, so the first word matched is the one closest to the end
11228 of the line.
ccc6cda3 11229
b8c60bc9
CR
11230‘X-Y’
11231 A range of words; ‘-Y’ abbreviates ‘0-Y’.
ccc6cda3 11232
b8c60bc9
CR
11233‘*’
11234 All of the words, except the ‘0’th. This is a synonym for ‘1-$’.
11235 It is not an error to use ‘*’ if there is just one word in the
11236 event; it expands to the empty string in that case.
bb70624e 11237
b8c60bc9
CR
11238‘X*’
11239 Abbreviates ‘X-$’.
bb70624e 11240
b8c60bc9
CR
11241‘X-’
11242 Abbreviates ‘X-$’ like ‘X*’, but omits the last word. If ‘x’ is
8868edaf 11243 missing, it defaults to 0.
b80f6443 11244
bb70624e 11245 If a word designator is supplied without an event specification, the
b8c60bc9 11246previous command is used as the event, equivalent to ‘!!’.
ccc6cda3
JA
11247
11248\1f
bb70624e 11249File: bashref.info, Node: Modifiers, Prev: Word Designators, Up: History Interaction
ccc6cda3 11250
b80f6443
JA
112519.3.3 Modifiers
11252---------------
ccc6cda3 11253
b80f6443 11254After the optional word designator, you can add a sequence of one or
b8c60bc9 11255more of the following modifiers, each preceded by a ‘:’. These modify,
8868edaf 11256or edit, the word or words selected from the history event.
ccc6cda3 11257
b8c60bc9
CR
11258‘h’
11259 Remove a trailing filename component, leaving only the head.
ccc6cda3 11260
b8c60bc9
CR
11261‘t’
11262 Remove all leading filename components, leaving the tail.
bb70624e 11263
b8c60bc9
CR
11264‘r’
11265 Remove a trailing suffix of the form ‘.SUFFIX’, leaving the
bb70624e
JA
11266 basename.
11267
b8c60bc9 11268‘e’
bb70624e
JA
11269 Remove all but the trailing suffix.
11270
b8c60bc9 11271‘p’
bb70624e
JA
11272 Print the new command but do not execute it.
11273
b8c60bc9 11274‘q’
bb70624e
JA
11275 Quote the substituted words, escaping further substitutions.
11276
b8c60bc9
CR
11277‘x’
11278 Quote the substituted words as with ‘q’, but break into words at
11279 spaces, tabs, and newlines. The ‘q’ and ‘x’ modifiers are mutually
11280 exclusive; expansion uses the last one supplied.
bb70624e 11281
b8c60bc9 11282‘s/OLD/NEW/’
bb70624e 11283 Substitute NEW for the first occurrence of OLD in the event line.
b8c60bc9 11284 Any character may be used as the delimiter in place of ‘/’. The
8868edaf 11285 delimiter may be quoted in OLD and NEW with a single backslash. If
b8c60bc9
CR
11286 ‘&’ appears in NEW, it is replaced with OLD. A single backslash
11287 quotes the ‘&’ in OLD and NEW. If OLD is null, it is set to the
11288 last OLD substituted, or, if no previous history substitutions took
11289 place, the last STRING in a !?STRING‘[?]’ search. If NEW is null,
11290 each matching OLD is deleted. The final delimiter is optional if
11291 it is the last character on the input line.
11292
11293‘&’
bb70624e
JA
11294 Repeat the previous substitution.
11295
b8c60bc9
CR
11296‘g’
11297‘a’
11298 Cause changes to be applied over the entire event line. This is
11299 used in conjunction with ‘s’, as in ‘gs/OLD/NEW/’, or with ‘&’.
b80f6443 11300
b8c60bc9
CR
11301‘G’
11302 Apply the following ‘s’ or ‘&’ modifier once to each word in the
8868edaf 11303 event.
b80f6443 11304
bb70624e 11305\1f
3185942a 11306File: bashref.info, Node: Installing Bash, Next: Reporting Bugs, Prev: Using History Interactively, Up: Top
bb70624e 11307
b80f6443
JA
1130810 Installing Bash
11309******************
b72432fd 11310
b80f6443 11311This chapter provides basic instructions for installing Bash on the
bb70624e
JA
11312various supported platforms. The distribution supports the GNU
11313operating systems, nearly every version of Unix, and several non-Unix
11314systems such as BeOS and Interix. Other independent ports exist for
b8c60bc9 11315Windows platforms.
ccc6cda3 11316
bb70624e 11317* Menu:
ccc6cda3 11318
bb70624e 11319* Basic Installation:: Installation instructions.
bb70624e
JA
11320* Compilers and Options:: How to set special options for various
11321 systems.
bb70624e
JA
11322* Compiling For Multiple Architectures:: How to compile Bash for more
11323 than one kind of system from
11324 the same source tree.
bb70624e 11325* Installation Names:: How to set the various paths used by the installation.
bb70624e 11326* Specifying the System Type:: How to configure Bash for a particular system.
bb70624e
JA
11327* Sharing Defaults:: How to share default configuration values among GNU
11328 programs.
bb70624e 11329* Operation Controls:: Options recognized by the configuration program.
bb70624e
JA
11330* Optional Features:: How to enable and disable optional features when
11331 building Bash.
ccc6cda3 11332
bb70624e
JA
11333\1f
11334File: bashref.info, Node: Basic Installation, Next: Compilers and Options, Up: Installing Bash
ccc6cda3 11335
b80f6443
JA
1133610.1 Basic Installation
11337=======================
ccc6cda3 11338
b80f6443 11339These are installation instructions for Bash.
ccc6cda3 11340
bb70624e 11341 The simplest way to compile Bash is:
ccc6cda3 11342
b8c60bc9
CR
11343 1. ‘cd’ to the directory containing the source code and type
11344 ‘./configure’ to configure Bash for your system. If you're using
11345 ‘csh’ on an old version of System V, you might need to type ‘sh
11346 ./configure’ instead to prevent ‘csh’ from trying to execute
11347 ‘configure’ itself.
ccc6cda3 11348
b8c60bc9 11349 Running ‘configure’ takes some time. While running, it prints
bb70624e 11350 messages telling which features it is checking for.
ccc6cda3 11351
b8c60bc9 11352 2. Type ‘make’ to compile Bash and build the ‘bashbug’ bug reporting
bb70624e 11353 script.
ccc6cda3 11354
b8c60bc9 11355 3. Optionally, type ‘make tests’ to run the Bash test suite.
ccc6cda3 11356
b8c60bc9 11357 4. Type ‘make install’ to install ‘bash’ and ‘bashbug’. This will
74091dd4
CR
11358 also install the manual pages and Info file, message translation
11359 files, some supplemental documentation, a number of example
11360 loadable builtin commands, and a set of header files for developing
11361 loadable builtins. You may need additional privileges to install
b8c60bc9
CR
11362 ‘bash’ to your desired destination, which may require ‘sudo make
11363 install’. More information about controlling the locations where
11364 ‘bash’ and other files are installed is below (*note Installation
74091dd4 11365 Names::).
ccc6cda3 11366
b8c60bc9 11367 The ‘configure’ shell script attempts to guess correct values for
bb70624e 11368various system-dependent variables used during compilation. It uses
b8c60bc9
CR
11369those values to create a ‘Makefile’ in each directory of the package
11370(the top directory, the ‘builtins’, ‘doc’, ‘po’, and ‘support’
11371directories, each directory under ‘lib’, and several others). It also
11372creates a ‘config.h’ file containing system-dependent definitions.
11373Finally, it creates a shell script named ‘config.status’ that you can
74091dd4 11374run in the future to recreate the current configuration, a file
b8c60bc9
CR
11375‘config.cache’ that saves the results of its tests to speed up
11376reconfiguring, and a file ‘config.log’ containing compiler output
11377(useful mainly for debugging ‘configure’). If at some point
11378‘config.cache’ contains results you don't want to keep, you may remove
74091dd4 11379or edit it.
a0c0a00f 11380
b8c60bc9 11381 To find out more about the options and arguments that the ‘configure’
a0c0a00f 11382script understands, type
ccc6cda3 11383
d233b485 11384 bash-4.2$ ./configure --help
ccc6cda3 11385
bb70624e 11386at the Bash prompt in your Bash source directory.
ccc6cda3 11387
d233b485
CR
11388 If you want to build Bash in a directory separate from the source
11389directory - to build for multiple architectures, for example - just use
11390the full path to the configure script. The following commands will
b8c60bc9
CR
11391build Bash in a directory under ‘/usr/local/build’ from the source code
11392in ‘/usr/local/src/bash-4.4’:
d233b485
CR
11393
11394 mkdir /usr/local/build/bash-4.4
11395 cd /usr/local/build/bash-4.4
11396 bash /usr/local/src/bash-4.4/configure
11397 make
11398
11399 See *note Compiling For Multiple Architectures:: for more information
11400about building in a directory separate from the source.
11401
bb70624e 11402 If you need to do unusual things to compile Bash, please try to
b8c60bc9 11403figure out how ‘configure’ could check whether or not to do them, and
bb70624e
JA
11404mail diffs or instructions to <bash-maintainers@gnu.org> so they can be
11405considered for the next release.
ccc6cda3 11406
b8c60bc9
CR
11407 The file ‘configure.ac’ is used to create ‘configure’ by a program
11408called Autoconf. You only need ‘configure.ac’ if you want to change it
11409or regenerate ‘configure’ using a newer version of Autoconf. If you do
74091dd4 11410this, make sure you are using Autoconf version 2.69 or newer.
ccc6cda3 11411
bb70624e 11412 You can remove the program binaries and object files from the source
b8c60bc9
CR
11413code directory by typing ‘make clean’. To also remove the files that
11414‘configure’ created (so you can compile Bash for a different kind of
11415computer), type ‘make distclean’.
ccc6cda3 11416
bb70624e
JA
11417\1f
11418File: bashref.info, Node: Compilers and Options, Next: Compiling For Multiple Architectures, Prev: Basic Installation, Up: Installing Bash
ccc6cda3 11419
b80f6443
JA
1142010.2 Compilers and Options
11421==========================
ccc6cda3 11422
a0c0a00f 11423Some systems require unusual options for compilation or linking that the
b8c60bc9 11424‘configure’ script does not know about. You can give ‘configure’
bb70624e
JA
11425initial values for variables by setting them in the environment. Using
11426a Bourne-compatible shell, you can do that on the command line like
11427this:
ccc6cda3 11428
bb70624e 11429 CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure
ccc6cda3 11430
b8c60bc9 11431 On systems that have the ‘env’ program, you can do it like this:
cce855bc 11432
bb70624e 11433 env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure
b72432fd 11434
bb70624e 11435 The configuration process uses GCC to build Bash if it is available.
ccc6cda3 11436
bb70624e
JA
11437\1f
11438File: bashref.info, Node: Compiling For Multiple Architectures, Next: Installation Names, Prev: Compilers and Options, Up: Installing Bash
ccc6cda3 11439
b80f6443
JA
1144010.3 Compiling For Multiple Architectures
11441=========================================
ccc6cda3 11442
b80f6443 11443You can compile Bash for more than one kind of computer at the same
bb70624e 11444time, by placing the object files for each architecture in their own
b8c60bc9
CR
11445directory. To do this, you must use a version of ‘make’ that supports
11446the ‘VPATH’ variable, such as GNU ‘make’. ‘cd’ to the directory where
11447you want the object files and executables to go and run the ‘configure’
d233b485 11448script from the source directory (*note Basic Installation::). You may
b8c60bc9
CR
11449need to supply the ‘--srcdir=PATH’ argument to tell ‘configure’ where
11450the source files are. ‘configure’ automatically checks for the source
11451code in the directory that ‘configure’ is in and in ‘..’.
ccc6cda3 11452
b8c60bc9 11453 If you have to use a ‘make’ that does not support the ‘VPATH’
bb70624e
JA
11454variable, you can compile Bash for one architecture at a time in the
11455source code directory. After you have installed Bash for one
b8c60bc9 11456architecture, use ‘make distclean’ before reconfiguring for another
bb70624e 11457architecture.
ccc6cda3 11458
bb70624e 11459 Alternatively, if your system supports symbolic links, you can use
b8c60bc9 11460the ‘support/mkclone’ script to create a build tree which has symbolic
a0c0a00f
CR
11461links back to each file in the source directory. Here's an example that
11462creates a build directory in the current directory from a source
b8c60bc9 11463directory ‘/usr/gnu/src/bash-2.0’:
ccc6cda3 11464
bb70624e 11465 bash /usr/gnu/src/bash-2.0/support/mkclone -s /usr/gnu/src/bash-2.0 .
ccc6cda3 11466
b8c60bc9 11467The ‘mkclone’ script requires Bash, so you must have already built Bash
bb70624e
JA
11468for at least one architecture before you can create build directories
11469for other architectures.
ccc6cda3 11470
bb70624e
JA
11471\1f
11472File: bashref.info, Node: Installation Names, Next: Specifying the System Type, Prev: Compiling For Multiple Architectures, Up: Installing Bash
ccc6cda3 11473
b80f6443
JA
1147410.4 Installation Names
11475=======================
ccc6cda3 11476
b8c60bc9
CR
11477By default, ‘make install’ will install into ‘/usr/local/bin’,
11478‘/usr/local/man’, etc.; that is, the “installation prefix” defaults to
11479‘/usr/local’. You can specify an installation prefix other than
11480‘/usr/local’ by giving ‘configure’ the option ‘--prefix=PATH’, or by
11481specifying a value for the ‘prefix’ ‘make’ variable when running ‘make
11482install’ (e.g., ‘make install prefix=PATH’). The ‘prefix’ variable
11483provides a default for ‘exec_prefix’ and other variables used when
11484installing Bash.
ccc6cda3 11485
bb70624e
JA
11486 You can specify separate installation prefixes for
11487architecture-specific files and architecture-independent files. If you
b8c60bc9 11488give ‘configure’ the option ‘--exec-prefix=PATH’, ‘make install’ will
bb70624e
JA
11489use PATH as the prefix for installing programs and libraries.
11490Documentation and other data files will still use the regular prefix.
ccc6cda3 11491
74091dd4 11492 If you would like to change the installation locations for a single
b8c60bc9
CR
11493run, you can specify these variables as arguments to ‘make’: ‘make
11494install exec_prefix=/’ will install ‘bash’ and ‘bashbug’ into ‘/bin’
11495instead of the default ‘/usr/local/bin’.
74091dd4 11496
b8c60bc9 11497 If you want to see the files Bash will install and where it will
74091dd4 11498install them without changing anything on your system, specify the
b8c60bc9 11499variable ‘DESTDIR’ as an argument to ‘make’. Its value should be the
74091dd4
CR
11500absolute directory path you'd like to use as the root of your sample
11501installation tree. For example,
11502
11503 mkdir /fs1/bash-install
11504 make install DESTDIR=/fs1/bash-install
11505
b8c60bc9 11506will install ‘bash’ into ‘/fs1/bash-install/usr/local/bin/bash’, the
74091dd4 11507documentation into directories within
b8c60bc9
CR
11508‘/fs1/bash-install/usr/local/share’, the example loadable builtins into
11509‘/fs1/bash-install/usr/local/lib/bash’, and so on. You can use the
11510usual ‘exec_prefix’ and ‘prefix’ variables to alter the directory paths
11511beneath the value of ‘DESTDIR’.
74091dd4
CR
11512
11513 The GNU Makefile standards provide a more complete description of
11514these variables and their effects.
11515
ccc6cda3 11516\1f
bb70624e 11517File: bashref.info, Node: Specifying the System Type, Next: Sharing Defaults, Prev: Installation Names, Up: Installing Bash
ccc6cda3 11518
b80f6443
JA
1151910.5 Specifying the System Type
11520===============================
ccc6cda3 11521
b8c60bc9 11522There may be some features ‘configure’ can not figure out automatically,
74091dd4 11523but needs to determine by the type of host Bash will run on. Usually
b8c60bc9
CR
11524‘configure’ can figure that out, but if it prints a message saying it
11525can not guess the host type, give it the ‘--host=TYPE’ option. ‘TYPE’
11526can either be a short name for the system type, such as ‘sun4’, or a
11527canonical name with three fields: ‘CPU-COMPANY-SYSTEM’ (e.g.,
11528‘i386-unknown-freebsd4.2’).
ccc6cda3 11529
b8c60bc9 11530 See the file ‘support/config.sub’ for the possible values of each
bb70624e 11531field.
ccc6cda3 11532
bb70624e
JA
11533\1f
11534File: bashref.info, Node: Sharing Defaults, Next: Operation Controls, Prev: Specifying the System Type, Up: Installing Bash
11535
b80f6443
JA
1153610.6 Sharing Defaults
11537=====================
bb70624e 11538
b8c60bc9
CR
11539If you want to set default values for ‘configure’ scripts to share, you
11540can create a site shell script called ‘config.site’ that gives default
11541values for variables like ‘CC’, ‘cache_file’, and ‘prefix’. ‘configure’
11542looks for ‘PREFIX/share/config.site’ if it exists, then
11543‘PREFIX/etc/config.site’ if it exists. Or, you can set the
11544‘CONFIG_SITE’ environment variable to the location of the site script.
11545A warning: the Bash ‘configure’ looks for a site script, but not all
11546‘configure’ scripts do.
ccc6cda3
JA
11547
11548\1f
bb70624e 11549File: bashref.info, Node: Operation Controls, Next: Optional Features, Prev: Sharing Defaults, Up: Installing Bash
ccc6cda3 11550
b80f6443
JA
1155110.7 Operation Controls
11552=======================
ccc6cda3 11553
b8c60bc9 11554‘configure’ recognizes the following options to control how it operates.
ccc6cda3 11555
b8c60bc9 11556‘--cache-file=FILE’
bb70624e 11557 Use and save the results of the tests in FILE instead of
b8c60bc9
CR
11558 ‘./config.cache’. Set FILE to ‘/dev/null’ to disable caching, for
11559 debugging ‘configure’.
ccc6cda3 11560
b8c60bc9
CR
11561‘--help’
11562 Print a summary of the options to ‘configure’, and exit.
ccc6cda3 11563
b8c60bc9
CR
11564‘--quiet’
11565‘--silent’
11566‘-q’
bb70624e 11567 Do not print messages saying which checks are being made.
ccc6cda3 11568
b8c60bc9 11569‘--srcdir=DIR’
bb70624e 11570 Look for the Bash source code in directory DIR. Usually
b8c60bc9 11571 ‘configure’ can determine that directory automatically.
ccc6cda3 11572
b8c60bc9
CR
11573‘--version’
11574 Print the version of Autoconf used to generate the ‘configure’
bb70624e 11575 script, and exit.
ccc6cda3 11576
b8c60bc9
CR
11577 ‘configure’ also accepts some other, not widely used, boilerplate
11578options. ‘configure --help’ prints the complete list.
ccc6cda3 11579
bb70624e
JA
11580\1f
11581File: bashref.info, Node: Optional Features, Prev: Operation Controls, Up: Installing Bash
ccc6cda3 11582
b80f6443
JA
1158310.8 Optional Features
11584======================
ccc6cda3 11585
b8c60bc9 11586The Bash ‘configure’ has a number of ‘--enable-FEATURE’ options, where
b80f6443 11587FEATURE indicates an optional part of Bash. There are also several
b8c60bc9
CR
11588‘--with-PACKAGE’ options, where PACKAGE is something like ‘bash-malloc’
11589or ‘afs’. To turn off the default use of a package, use
11590‘--without-PACKAGE’. To configure Bash without a feature that is
11591enabled by default, use ‘--disable-FEATURE’.
ccc6cda3 11592
b8c60bc9
CR
11593 Here is a complete list of the ‘--enable-’ and ‘--with-’ options that
11594the Bash ‘configure’ recognizes.
ccc6cda3 11595
b8c60bc9 11596‘--with-afs’
bb70624e 11597 Define if you are using the Andrew File System from Transarc.
ccc6cda3 11598
b8c60bc9
CR
11599‘--with-bash-malloc’
11600 Use the Bash version of ‘malloc’ in the directory ‘lib/malloc’.
11601 This is not the same ‘malloc’ that appears in GNU libc, but a
11602 custom version originally derived from the 4.2 BSD ‘malloc’. This
11603 ‘malloc’ is very fast, but wastes some space on each allocation,
11604 though it uses several techniques to minimize the waste. This
11605 option is enabled by default. The ‘NOTES’ file contains a list of
11606 systems for which this should be turned off, and ‘configure’
11607 disables this option automatically for a number of systems.
11608
11609‘--with-curses’
11610 Use the curses library instead of the termcap library. ‘configure’
11611 usually chooses this automatically, since most systems include the
11612 termcap functions in the curses library.
11613
11614‘--with-gnu-malloc’
11615 A synonym for ‘--with-bash-malloc’.
11616
11617‘--with-installed-readline[=PREFIX]’
bb70624e 11618 Define this to make Bash link with a locally-installed version of
b8c60bc9
CR
11619 Readline rather than the version in ‘lib/readline’. This works
11620 only with Readline 5.0 and later versions. If PREFIX is ‘yes’ or
11621 not supplied, ‘configure’ uses the values of the make variables
11622 ‘includedir’ and ‘libdir’, which are subdirectories of ‘prefix’ by
f73dda09
JA
11623 default, to find the installed version of Readline if it is not in
11624 the standard system include and library directories. If PREFIX is
b8c60bc9
CR
11625 ‘no’, Bash links with the version in ‘lib/readline’. If PREFIX is
11626 set to any other value, ‘configure’ treats it as a directory
f73dda09 11627 pathname and looks for the installed version of Readline in
b8c60bc9
CR
11628 subdirectories of that directory (include files in PREFIX/‘include’
11629 and the library in PREFIX/‘lib’). The Bash default is to link with
11630 a static library built in the ‘lib/readline’ subdirectory of the
11631 build directory.
ccc6cda3 11632
b8c60bc9 11633‘--with-libintl-prefix[=PREFIX]’
74091dd4 11634 Define this to make Bash link with a locally-installed version of
b8c60bc9 11635 the libintl library instead of the version in ‘lib/intl’.
74091dd4 11636
b8c60bc9 11637‘--with-libiconv-prefix[=PREFIX]’
74091dd4 11638 Define this to make Bash look for libiconv in PREFIX instead of the
b8c60bc9
CR
11639 standard system locations. The Bash distribution does not include
11640 this library.
ccc6cda3 11641
b8c60bc9
CR
11642‘--enable-minimal-config’
11643 This produces a shell with minimal features, closer to the
bb70624e 11644 historical Bourne shell.
ccc6cda3 11645
b8c60bc9 11646 There are several ‘--enable-’ options that alter how Bash is
74091dd4 11647compiled, linked, and installed, rather than changing run-time features.
ccc6cda3 11648
b8c60bc9 11649‘--enable-largefile’
f73dda09 11650 Enable support for large files
d233b485
CR
11651 (http://www.unix.org/version2/whatsnew/lfs20mar.html) if the
11652 operating system requires special compiler options to build
a0c0a00f
CR
11653 programs which can access large files. This is enabled by default,
11654 if the operating system provides large file support.
f73dda09 11655
b8c60bc9 11656‘--enable-profiling’
bb70624e 11657 This builds a Bash binary that produces profiling information to be
b8c60bc9 11658 processed by ‘gprof’ each time it is executed.
cce855bc 11659
b8c60bc9
CR
11660‘--enable-separate-helpfiles’
11661 Use external files for the documentation displayed by the ‘help’
74091dd4
CR
11662 builtin instead of storing the text internally.
11663
b8c60bc9
CR
11664‘--enable-static-link’
11665 This causes Bash to be linked statically, if ‘gcc’ is being used.
bb70624e 11666 This could be used to build a version to use as root's shell.
d166f048 11667
b8c60bc9 11668 The ‘minimal-config’ option can be used to disable all of the
bb70624e 11669following options, but it is processed first, so individual options may
b8c60bc9 11670be enabled using ‘enable-FEATURE’.
d166f048 11671
b8c60bc9
CR
11672 All of the following options except for ‘alt-array-implementation’,
11673‘disabled-builtins’, ‘direxpand-default’, ‘strict-posix-default’, and
11674‘xpg-echo-default’ are enabled by default, unless the operating system
74091dd4 11675does not provide the necessary support.
ccc6cda3 11676
b8c60bc9
CR
11677‘--enable-alias’
11678 Allow alias expansion and include the ‘alias’ and ‘unalias’
28ef6c31 11679 builtins (*note Aliases::).
ccc6cda3 11680
b8c60bc9
CR
11681‘--enable-alt-array-implementation’
11682 This builds Bash using an alternate implementation of arrays (*note
74091dd4
CR
11683 Arrays::) that provides faster access at the expense of using more
11684 memory (sometimes many times more, depending on how sparse an array
11685 is).
11686
b8c60bc9
CR
11687‘--enable-arith-for-command’
11688 Include support for the alternate form of the ‘for’ command that
11689 behaves like the C language ‘for’ statement (*note Looping
28ef6c31 11690 Constructs::).
ccc6cda3 11691
b8c60bc9 11692‘--enable-array-variables’
bb70624e 11693 Include support for one-dimensional array shell variables (*note
28ef6c31 11694 Arrays::).
ccc6cda3 11695
b8c60bc9
CR
11696‘--enable-bang-history’
11697 Include support for ‘csh’-like history substitution (*note History
28ef6c31 11698 Interaction::).
ccc6cda3 11699
b8c60bc9
CR
11700‘--enable-bash-source-fullpath-default’
11701 Set the default value of the ‘bash_source_fullpath’ shell option
11702 described above under *note The Shopt Builtin:: to be enabled.
11703 This controls how filenames are assigned to the ‘BASH_SOURCE’ array
11704 variable.
11705
11706‘--enable-brace-expansion’
11707 Include ‘csh’-like brace expansion ( ‘b{a,b}c’ ↦ ‘bac bbc’ ). See
11708 *note Brace Expansion::, for a complete description.
3185942a 11709
b8c60bc9
CR
11710‘--enable-casemod-attributes’
11711 Include support for case-modifying attributes in the ‘declare’
11712 builtin and assignment statements. Variables with the ‘uppercase’
3185942a
JA
11713 attribute, for example, will have their values converted to
11714 uppercase upon assignment.
11715
b8c60bc9 11716‘--enable-casemod-expansion’
3185942a 11717 Include support for case-modifying word expansions.
ccc6cda3 11718
b8c60bc9
CR
11719‘--enable-command-timing’
11720 Include support for recognizing ‘time’ as a reserved word and for
11721 displaying timing statistics for the pipeline following ‘time’
11722 (*note Pipelines::). This allows timing pipelines, shell compound
11723 commands, shell builtins, and shell functions, which an external
11724 command cannot do easily.
ccc6cda3 11725
b8c60bc9
CR
11726‘--enable-cond-command’
11727 Include support for the ‘[[’ conditional command. (*note
b80f6443
JA
11728 Conditional Constructs::).
11729
b8c60bc9 11730‘--enable-cond-regexp’
b80f6443 11731 Include support for matching POSIX regular expressions using the
b8c60bc9 11732 ‘=~’ binary operator in the ‘[[’ conditional command. (*note
28ef6c31 11733 Conditional Constructs::).
ccc6cda3 11734
b8c60bc9
CR
11735‘--enable-coprocesses’
11736 Include support for coprocesses and the ‘coproc’ reserved word
3185942a
JA
11737 (*note Pipelines::).
11738
b8c60bc9
CR
11739‘--enable-debugger’
11740 Include support for the Bash debugger (distributed separately).
95732b49 11741
b8c60bc9
CR
11742‘--enable-dev-fd-stat-broken’
11743 If calling ‘stat’ on /dev/fd/N returns different results than
11744 calling ‘fstat’ on file descriptor N, supply this option to enable
d233b485
CR
11745 a workaround. This has implications for conditional commands that
11746 test file attributes.
11747
b8c60bc9
CR
11748‘--enable-direxpand-default’
11749 Cause the ‘direxpand’ shell option (*note The Shopt Builtin::) to
ac50fbac
CR
11750 be enabled by default when the shell starts. It is normally
11751 disabled by default.
11752
b8c60bc9
CR
11753‘--enable-directory-stack’
11754 Include support for a ‘csh’-like directory stack and the ‘pushd’,
11755 ‘popd’, and ‘dirs’ builtins (*note The Directory Stack::).
ccc6cda3 11756
b8c60bc9
CR
11757‘--enable-disabled-builtins’
11758 Allow builtin commands to be invoked via ‘builtin xxx’ even after
11759 ‘xxx’ has been disabled using ‘enable -n xxx’. See *note Bash
11760 Builtins::, for details of the ‘builtin’ and ‘enable’ builtin
bb70624e 11761 commands.
ccc6cda3 11762
b8c60bc9
CR
11763‘--enable-dparen-arithmetic’
11764 Include support for the ‘((...))’ command (*note Conditional
28ef6c31 11765 Constructs::).
ccc6cda3 11766
b8c60bc9 11767‘--enable-extended-glob’
bb70624e 11768 Include support for the extended pattern matching features
3185942a 11769 described above under *note Pattern Matching::.
ccc6cda3 11770
b8c60bc9
CR
11771‘--enable-extended-glob-default’
11772 Set the default value of the ‘extglob’ shell option described above
0001803f
CR
11773 under *note The Shopt Builtin:: to be enabled.
11774
b8c60bc9 11775‘--enable-function-import’
a0c0a00f
CR
11776 Include support for importing function definitions exported by
11777 another instance of the shell from the environment. This option is
11778 enabled by default.
11779
b8c60bc9
CR
11780‘--enable-glob-asciiranges-default’
11781 Set the default value of the ‘globasciiranges’ shell option
74091dd4
CR
11782 described above under *note The Shopt Builtin:: to be enabled.
11783 This controls the behavior of character ranges when used in pattern
11784 matching bracket expressions.
ac50fbac 11785
b8c60bc9
CR
11786‘--enable-help-builtin’
11787 Include the ‘help’ builtin, which displays help on shell builtins
28ef6c31 11788 and variables (*note Bash Builtins::).
ccc6cda3 11789
b8c60bc9
CR
11790‘--enable-history’
11791 Include command history and the ‘fc’ and ‘history’ builtin commands
a0c0a00f 11792 (*note Bash History Facilities::).
ccc6cda3 11793
b8c60bc9 11794‘--enable-job-control’
a0c0a00f
CR
11795 This enables the job control features (*note Job Control::), if the
11796 operating system supports them.
ccc6cda3 11797
b8c60bc9 11798‘--enable-multibyte’
b80f6443
JA
11799 This enables support for multibyte characters if the operating
11800 system provides the necessary support.
11801
b8c60bc9 11802‘--enable-net-redirections’
bb70624e 11803 This enables the special handling of filenames of the form
b8c60bc9 11804 ‘/dev/tcp/HOST/PORT’ and ‘/dev/udp/HOST/PORT’ when used in
28ef6c31 11805 redirections (*note Redirections::).
ccc6cda3 11806
b8c60bc9 11807‘--enable-process-substitution’
28ef6c31
JA
11808 This enables process substitution (*note Process Substitution::) if
11809 the operating system provides the necessary support.
ccc6cda3 11810
b8c60bc9 11811‘--enable-progcomp’
95732b49
JA
11812 Enable the programmable completion facilities (*note Programmable
11813 Completion::). If Readline is not enabled, this option has no
11814 effect.
11815
b8c60bc9 11816‘--enable-prompt-string-decoding’
bb70624e 11817 Turn on the interpretation of a number of backslash-escaped
b8c60bc9 11818 characters in the ‘$PS0’, ‘$PS1’, ‘$PS2’, and ‘$PS4’ prompt
ac50fbac
CR
11819 strings. See *note Controlling the Prompt::, for a complete list
11820 of prompt string escape sequences.
ccc6cda3 11821
b8c60bc9 11822‘--enable-readline’
bb70624e 11823 Include support for command-line editing and history with the Bash
28ef6c31 11824 version of the Readline library (*note Command Line Editing::).
ccc6cda3 11825
b8c60bc9
CR
11826‘--enable-restricted’
11827 Include support for a “restricted shell”. If this is enabled, Bash
11828 enters a restricted mode when called as ‘rbash’. See *note The
11829 Restricted Shell::, for a description of restricted mode.
ccc6cda3 11830
b8c60bc9
CR
11831‘--enable-select’
11832 Include the ‘select’ compound command, which allows generation of
11833 simple menus (*note Conditional Constructs::).
ccc6cda3 11834
b8c60bc9
CR
11835‘--enable-single-help-strings’
11836 Store the text displayed by the ‘help’ builtin as a single string
95732b49 11837 for each help topic. This aids in translating the text to
a0c0a00f
CR
11838 different languages. You may need to disable this if your compiler
11839 cannot handle very long string literals.
95732b49 11840
b8c60bc9 11841‘--enable-strict-posix-default’
95732b49
JA
11842 Make Bash POSIX-conformant by default (*note Bash POSIX Mode::).
11843
b8c60bc9
CR
11844‘--enable-translatable-strings’
11845 Enable support for ‘$"STRING"’ translatable strings (*note Locale
74091dd4
CR
11846 Translation::).
11847
b8c60bc9
CR
11848‘--enable-usg-echo-default’
11849 A synonym for ‘--enable-xpg-echo-default’.
ccc6cda3 11850
b8c60bc9
CR
11851‘--enable-xpg-echo-default’
11852 Make the ‘echo’ builtin expand backslash-escaped characters by
11853 default, without requiring the ‘-e’ option. This sets the default
11854 value of the ‘xpg_echo’ shell option to ‘on’, which makes the Bash
11855 ‘echo’ behave more like the version specified in the Single Unix
a0c0a00f 11856 Specification, version 3. *Note Bash Builtins::, for a description
b8c60bc9 11857 of the escape sequences that ‘echo’ recognizes.
ccc6cda3 11858
b8c60bc9
CR
11859 The file ‘config-top.h’ contains C Preprocessor ‘#define’ statements
11860for options which are not settable from ‘configure’. Some of these are
a0c0a00f
CR
11861not meant to be changed; beware of the consequences if you do. Read the
11862comments associated with each definition for more information about its
11863effect.
ccc6cda3 11864
bb70624e
JA
11865\1f
11866File: bashref.info, Node: Reporting Bugs, Next: Major Differences From The Bourne Shell, Prev: Installing Bash, Up: Top
d166f048 11867
b80f6443
JA
11868Appendix A Reporting Bugs
11869*************************
ccc6cda3 11870
b80f6443 11871Please report all bugs you find in Bash. But first, you should make
bb70624e 11872sure that it really is a bug, and that it appears in the latest version
b8c60bc9
CR
11873of Bash. The latest released version of Bash is always available for
11874FTP from <ftp://ftp.gnu.org/pub/gnu/bash/> and from
74091dd4 11875<http://git.savannah.gnu.org/cgit/bash.git/snapshot/bash-master.tar.gz>.
ccc6cda3 11876
bb70624e 11877 Once you have determined that a bug actually exists, use the
b8c60bc9
CR
11878‘bashbug’ command to submit a bug report or use the form at the Bash
11879project page (https://savannah.gnu.org/projects/bash/). If you have a
11880fix, you are encouraged to submit that as well! Suggestions and
11881'philosophical' bug reports may be mailed to <bug-bash@gnu.org> or
11882<help-bash@gnu.org>.
ccc6cda3 11883
bb70624e 11884 All bug reports should include:
b8c60bc9
CR
11885 • The version number of Bash.
11886 • The hardware and operating system.
11887 • The compiler used to compile Bash.
11888 • A description of the bug behavior.
11889 • A short script or 'recipe' which exercises the bug and may be used
bb70624e 11890 to reproduce it.
ccc6cda3 11891
b8c60bc9 11892‘bashbug’ inserts the first three items automatically into the template
bb70624e
JA
11893it provides for filing a bug report.
11894
ac50fbac 11895 Please send all reports concerning this manual to <bug-bash@gnu.org>.
ccc6cda3
JA
11896
11897\1f
3185942a 11898File: bashref.info, Node: Major Differences From The Bourne Shell, Next: GNU Free Documentation License, Prev: Reporting Bugs, Up: Top
ccc6cda3 11899
b80f6443
JA
11900Appendix B Major Differences From The Bourne Shell
11901**************************************************
ccc6cda3 11902
b80f6443 11903Bash implements essentially the same grammar, parameter and variable
bb70624e 11904expansion, redirection, and quoting as the Bourne Shell. Bash uses the
0628567a 11905POSIX standard as the specification of how these features are to be
b8c60bc9
CR
11906implemented and how they should behave. There are some differences
11907between the traditional Bourne shell and Bash; this section quickly
11908details the differences of significance. A number of these differences
11909are explained in greater depth in previous sections. This section uses
11910the version of ‘sh’ included in SVR4.2 (the last version of the
11911historical Bourne shell) as the baseline reference.
ccc6cda3 11912
b8c60bc9
CR
11913 • Bash is POSIX-conformant, even where the POSIX specification
11914 differs from traditional ‘sh’ behavior (*note Bash POSIX Mode::).
ccc6cda3 11915
b8c60bc9 11916 • Bash has multi-character invocation options (*note Invoking
28ef6c31 11917 Bash::).
ccc6cda3 11918
b8c60bc9
CR
11919 • The Bash restricted mode is more useful (*note The Restricted
11920 Shell::); the SVR4.2 shell restricted mode is too limited.
11921
11922 • Bash has command-line editing (*note Command Line Editing::) and
11923 the ‘bind’ builtin.
11924
11925 • Bash provides a programmable word completion mechanism (*note
11926 Programmable Completion::), and builtin commands ‘complete’,
11927 ‘compgen’, and ‘compopt’, to manipulate it.
11928
11929 • Bash decodes a number of backslash-escape sequences in the prompt
11930 string variables (‘PS0’, ‘PS1’, ‘PS2’, and ‘PS4’) (*note
11931 Controlling the Prompt::).
ccc6cda3 11932
b8c60bc9 11933 • Bash expands and displays the ‘PS0’ prompt string variable.
ccc6cda3 11934
b8c60bc9
CR
11935 • Bash runs commands from the ‘PROMPT_COMMAND’ array variable before
11936 issuing each primary prompt.
11937
11938 • Bash has command history (*note Bash History Facilities::) and the
11939 ‘history’ and ‘fc’ builtins to manipulate it. The Bash history
b80f6443 11940 list maintains timestamp information and uses the value of the
b8c60bc9 11941 ‘HISTTIMEFORMAT’ variable to display it.
ccc6cda3 11942
b8c60bc9 11943 • Bash implements ‘csh’-like history expansion (*note History
28ef6c31 11944 Interaction::).
ccc6cda3 11945
b8c60bc9
CR
11946 • Bash supports the ‘$'...'’ quoting syntax, which expands ANSI-C
11947 backslash-escaped characters in the text between the single quotes
a0c0a00f 11948 (*note ANSI-C Quoting::).
ccc6cda3 11949
b8c60bc9
CR
11950 • Bash supports the ‘$"..."’ quoting syntax and performs
11951 locale-specific translation of the characters between the double
11952 quotes. The ‘-D’, ‘--dump-strings’, and ‘--dump-po-strings’
11953 invocation options list the translatable strings found in a script
11954 (*note Locale Translation::).
11955
11956 • Bash includes brace expansion (*note Brace Expansion::) and tilde
11957 expansion (*note Tilde Expansion::).
ccc6cda3 11958
b8c60bc9
CR
11959 • Bash implements command aliases and the ‘alias’ and ‘unalias’
11960 builtins (*note Aliases::).
ccc6cda3 11961
b8c60bc9
CR
11962 • Bash implements the ‘!’ reserved word to negate the return value of
11963 a pipeline (*note Pipelines::). This is very useful when an ‘if’
11964 statement needs to act only if a test fails. The Bash ‘-o
11965 pipefail’ option to ‘set’ will cause a pipeline to return a failure
11966 status if any command fails (*note The Set Builtin::).
11967
11968 • Bash has the ‘time’ reserved word and command timing (*note
28ef6c31 11969 Pipelines::). The display of the timing statistics may be
b8c60bc9
CR
11970 controlled with the ‘TIMEFORMAT’ variable.
11971
11972 • Bash provides coprocesses and the ‘coproc’ reserved word (*note
11973 Coprocesses::).
ccc6cda3 11974
b8c60bc9 11975 • Bash implements the ‘for (( EXPR1 ; EXPR2 ; EXPR3 ))’ arithmetic
bb70624e 11976 for command, similar to the C language (*note Looping
28ef6c31 11977 Constructs::).
ccc6cda3 11978
b8c60bc9 11979 • Bash includes the ‘select’ compound command, which allows the
28ef6c31 11980 generation of simple menus (*note Conditional Constructs::).
ccc6cda3 11981
b8c60bc9 11982 • Bash includes the ‘[[’ compound command, which makes conditional
a0c0a00f
CR
11983 testing part of the shell grammar (*note Conditional Constructs::),
11984 including optional regular expression matching.
95732b49 11985
b8c60bc9
CR
11986 • Bash provides optional case-insensitive matching for the ‘case’ and
11987 ‘[[’ constructs (*note Conditional Constructs::).
ccc6cda3 11988
b8c60bc9
CR
11989 • Bash provides additional ‘case’ statement action list terminators:
11990 ‘;&’ and ‘;;&’ (*note Conditional Constructs::).
ccc6cda3 11991
b8c60bc9
CR
11992 • Bash provides shell arithmetic, the ‘((’ compound command (*note
11993 Conditional Constructs::), the ‘let’ builtin, and arithmetic
11994 expansion (*note Shell Arithmetic::).
11995
11996 • Bash has one-dimensional array variables (*note Arrays::), and the
11997 appropriate variable expansions and assignment syntax to use them.
11998 Several of the Bash builtins take options to act on arrays. Bash
11999 provides a number of built-in array variables.
ccc6cda3 12000
b8c60bc9
CR
12001 • Variables present in the shell's initial environment are
12002 automatically exported to child processes (*note Command Execution
12003 Environment::). The Bourne shell does not normally do this unless
12004 the variables are explicitly marked using the ‘export’ command.
ccc6cda3 12005
b8c60bc9
CR
12006 • Bash can expand positional parameters beyond ‘$9’ using ‘${NUM}’
12007 (*note Shell Parameter Expansion::).
ccc6cda3 12008
b8c60bc9
CR
12009 • Bash supports the ‘+=’ assignment operator, which appends to the
12010 value of the variable named on the left hand side (*note Shell
12011 Parameters::).
95732b49 12012
b8c60bc9 12013 • Bash includes the POSIX pattern removal ‘%’, ‘#’, ‘%%’ and ‘##’
bb70624e 12014 expansions to remove leading or trailing substrings from variable
28ef6c31 12015 values (*note Shell Parameter Expansion::).
ccc6cda3 12016
b8c60bc9 12017 • The expansion ‘${#xx}’, which returns the length of ‘${xx}’, is
28ef6c31 12018 supported (*note Shell Parameter Expansion::).
ccc6cda3 12019
b8c60bc9
CR
12020 • The expansion ‘${var:’OFFSET‘[:’LENGTH‘]}’, which expands to the
12021 substring of ‘var’'s value of length LENGTH, beginning at OFFSET,
28ef6c31 12022 is present (*note Shell Parameter Expansion::).
ccc6cda3 12023
b8c60bc9 12024 • The expansion ‘${VAR/[/]’PATTERN‘[/’REPLACEMENT‘]}’, which matches
74091dd4 12025 PATTERN and replaces it with REPLACEMENT in the value of VAR, is
b8c60bc9
CR
12026 available (*note Shell Parameter Expansion::), with a mechanism to
12027 use the matched text in REPLACEMENT.
ccc6cda3 12028
b8c60bc9 12029 • The expansion ‘${!PREFIX*}’ expansion, which expands to the names
bb70624e 12030 of all shell variables whose names begin with PREFIX, is available
28ef6c31 12031 (*note Shell Parameter Expansion::).
ccc6cda3 12032
b8c60bc9
CR
12033 • Bash has indirect variable expansion using ‘${!word}’ (*note Shell
12034 Parameter Expansion::) and implements the ‘nameref’ variable
12035 attribute for automatic indirect variable expansion.
ccc6cda3 12036
b8c60bc9
CR
12037 • Bash includes a set of parameter transformation word expansions of
12038 the form ‘${var@X}’, where ‘X’ specifies the transformation (*note
12039 Shell Parameter Expansion::).
ccc6cda3 12040
b8c60bc9
CR
12041 • The POSIX ‘$()’ form of command substitution is implemented (*note
12042 Command Substitution::), and preferred to the Bourne shell's ‘``’
bb70624e 12043 (which is also implemented for backwards compatibility).
ccc6cda3 12044
b8c60bc9
CR
12045 • Bash implements a variant of command substitution that runs the
12046 enclosed command in the current shell execution environment: ‘${
12047 COMMAND;}’ or ‘${|COMMAND;}’ (*note Command Substitution::).
12048
12049 • Bash has process substitution (*note Process Substitution::).
12050
12051 • Bash automatically assigns variables that provide information about
12052 the current user (‘UID’, ‘EUID’, and ‘GROUPS’), the current host
12053 (‘HOSTTYPE’, ‘OSTYPE’, ‘MACHTYPE’, and ‘HOSTNAME’), and the
12054 instance of Bash that is running (‘BASH’, ‘BASH_VERSION’, and
12055 ‘BASH_VERSINFO’). *Note Bash Variables::, for details.
12056
12057 • Bash uses many variables to provide functionality and customize
12058 shell behavior that the Bourne shell does not. Examples include
12059 ‘RANDOM’, ‘SRANDOM’, ‘EPOCHSECONDS’, ‘EPOCHREALTIME’, ‘TIMEFORMAT’,
12060 ‘BASHPID’, ‘BASH_XTRACEFD’, ‘GLOBIGNORE’, ‘HISTIGNORE’, and
12061 ‘BASH_VERSION’. *Note Bash Variables::, for a complete list.
ccc6cda3 12062
b8c60bc9
CR
12063 • Bash uses the ‘GLOBSORT’ shell variable to control how to sort the
12064 results of filename expansion (*note Filename Expansion::).
ccc6cda3 12065
b8c60bc9
CR
12066 • Bash uses the ‘IFS’ variable to split only the results of
12067 expansion, not all words (*note Word Splitting::). This closes a
12068 longstanding shell security hole.
ccc6cda3 12069
b8c60bc9
CR
12070 • The filename expansion bracket expression code uses ‘!’ and ‘^’ to
12071 negate the set of characters between the brackets (*note Filename
12072 Expansion::). The Bourne shell uses only ‘!’.
ac50fbac 12073
b8c60bc9 12074 • Bash implements the full set of POSIX filename expansion operators,
74091dd4
CR
12075 including character classes, equivalence classes, and collating
12076 symbols (*note Filename Expansion::).
ccc6cda3 12077
b8c60bc9
CR
12078 • Bash implements extended pattern matching features when the
12079 ‘extglob’ shell option is enabled (*note Pattern Matching::).
ccc6cda3 12080
b8c60bc9
CR
12081 • The ‘globstar’ shell option extends filename expansion to
12082 recursively scan directories and subdirectories for matching
12083 filenames (*note Pattern Matching::).
ccc6cda3 12084
b8c60bc9
CR
12085 • It is possible to have a variable and a function with the same
12086 name; ‘sh’ does not separate the two name spaces.
ccc6cda3 12087
b8c60bc9
CR
12088 • Bash functions are permitted to have local variables using the
12089 ‘local’ builtin, and thus users can write useful recursive
12090 functions (*note Bash Builtins::).
ccc6cda3 12091
b8c60bc9 12092 • Bash performs filename expansion on filenames specified as operands
28ef6c31 12093 to input and output redirection operators (*note Redirections::).
ccc6cda3 12094
b8c60bc9
CR
12095 • Bash contains the ‘<>’ redirection operator, allowing a file to be
12096 opened for both reading and writing, and the ‘&>’ redirection
bb70624e 12097 operator, for directing standard output and standard error to the
28ef6c31 12098 same file (*note Redirections::).
d166f048 12099
b8c60bc9
CR
12100 • Bash includes the ‘<<<’ redirection operator, allowing a string to
12101 be used as the standard input to a command (*note Redirections::).
95732b49 12102
b8c60bc9 12103 • Bash implements the ‘[n]<&WORD’ and ‘[n]>&WORD’ redirection
95732b49
JA
12104 operators, which move one file descriptor to another.
12105
b8c60bc9 12106 • Bash treats a number of filenames specially when they are used in
28ef6c31 12107 redirection operators (*note Redirections::).
ccc6cda3 12108
b8c60bc9
CR
12109 • Bash provides the {VAR}<WORD capability to have the shell allocate
12110 file descriptors for redirections and assign them to VAR (*note
12111 Redirections::). This works with multiple redirection operators.
12112
12113 • Bash can open network connections to arbitrary machines and
28ef6c31 12114 services with the redirection operators (*note Redirections::).
ccc6cda3 12115
b8c60bc9
CR
12116 • The ‘noclobber’ option is available to avoid overwriting existing
12117 files with output redirection (*note The Set Builtin::). The ‘>|’
12118 redirection operator may be used to override ‘noclobber’.
ccc6cda3 12119
b8c60bc9
CR
12120 • Variable assignments preceding commands affect only that command,
12121 even builtins and functions (*note Environment::). In ‘sh’, all
12122 variable assignments preceding commands are global unless the
12123 command is executed from the file system.
12124
12125 • Bash includes a number of features to support a separate debugger
12126 for shell scripts: variables (‘BASH_ARGC’, ‘BASH_ARGV’,
12127 ‘BASH_LINENO’, ‘BASH_SOURCE’), the ‘DEBUG’, ‘RETURN’, and ‘ERR’
12128 traps, ‘declare -F’, and the ‘caller’ builtin.
b72432fd 12129
b8c60bc9
CR
12130 • Bash implements a ‘csh’-like directory stack, and provides the
12131 ‘pushd’, ‘popd’, and ‘dirs’ builtins to manipulate it (*note The
12132 Directory Stack::). Bash also makes the directory stack visible as
12133 the value of the ‘DIRSTACK’ shell variable.
12134
12135 • Bash allows a function to override a builtin with the same name,
bb70624e 12136 and provides access to that builtin's functionality within the
b8c60bc9 12137 function via the ‘builtin’ and ‘command’ builtins (*note Bash
28ef6c31 12138 Builtins::).
ccc6cda3 12139
b8c60bc9
CR
12140 • Bash includes the ‘caller’ builtin (*note Bash Builtins::), which
12141 displays the context of any active subroutine call (a shell
12142 function or a script executed with the ‘.’ or ‘source’ builtins).
12143 This supports the Bash debugger.
12144
12145 • The Bash ‘cd’ and ‘pwd’ builtins (*note Bourne Shell Builtins::)
12146 each take ‘-L’ and ‘-P’ options to switch between logical and
12147 physical modes.
ccc6cda3 12148
b8c60bc9
CR
12149 • The ‘command’ builtin allows selectively skipping shell functions
12150 when performing command lookup (*note Bash Builtins::).
cce855bc 12151
b8c60bc9
CR
12152 • Bash uses the ‘declare’ builtin to modify the full set of variable
12153 and function attributes, and to assign values to variables.
12154
12155 • The ‘disown’ builtin can remove a job from the internal shell job
12156 table (*note Job Control Builtins::) or suppress sending ‘SIGHUP’
12157 to a job when the shell exits as the result of a ‘SIGHUP’.
12158
12159 • The ‘enable’ builtin (*note Bash Builtins::) can enable or disable
12160 individual builtins and implements support for dynamically loading
12161 builtin commands from shared objects.
12162
12163 • The Bash ‘exec’ builtin takes additional options that allow users
bb70624e
JA
12164 to control the contents of the environment passed to the executed
12165 command, and what the zeroth argument to the command is to be
28ef6c31 12166 (*note Bourne Shell Builtins::).
cce855bc 12167
b8c60bc9
CR
12168 • Shell functions may be exported to children via the environment
12169 using ‘export -f’ (*note Shell Functions::).
cce855bc 12170
b8c60bc9
CR
12171 • The Bash ‘export’ and ‘readonly’ builtins (*note Bourne Shell
12172 Builtins:: can take a ‘-f’ option to act on shell functions, a ‘-p’
12173 option to display variables with various attributes set in a format
12174 that can be used as shell input, a ‘-n’ option to remove various
12175 variable attributes, and ‘name=value’ arguments to set variable
12176 attributes and values simultaneously.
ccc6cda3 12177
b8c60bc9 12178 • The Bash ‘hash’ builtin allows a name to be associated with an
bb70624e 12179 arbitrary filename, even when that filename cannot be found by
b8c60bc9 12180 searching the ‘$PATH’, using ‘hash -p’ (*note Bourne Shell
28ef6c31 12181 Builtins::).
ccc6cda3 12182
b8c60bc9 12183 • Bash includes a ‘help’ builtin for quick reference to shell
28ef6c31 12184 facilities (*note Bash Builtins::).
ccc6cda3 12185
b8c60bc9
CR
12186 • Bash includes the ‘mapfile’ builtin to quickly read the contents of
12187 a file into an indexed array variable (*note Bash Builtins::).
12188
12189 • The ‘printf’ builtin is available to display formatted output
12190 (*note Bash Builtins::), and has additional custom format
12191 specifiers and an option to assign the formatted output directly to
12192 a shell variable.
12193
12194 • The Bash ‘read’ builtin (*note Bash Builtins::) will read a line
12195 ending in ‘\’ with the ‘-r’ option, and will use the ‘REPLY’
12196 variable as a default if no non-option arguments are supplied.
12197
12198 • The ‘read’ builtin (*note Bash Builtins::) accepts a prompt string
12199 with the ‘-p’ option and will use Readline to obtain the line when
12200 given the ‘-e’ or ‘-E’ options, with the ability to insert text
12201 into the line using the ‘-i’ option. The ‘read’ builtin also has
12202 additional options to control input: the ‘-s’ option will turn off
12203 echoing of input characters as they are read, the ‘-t’ option will
12204 allow ‘read’ to time out if input does not arrive within a
12205 specified number of seconds, the ‘-n’ option will allow reading
12206 only a specified number of characters rather than a full line, and
12207 the ‘-d’ option will read until a particular character rather than
12208 newline.
12209
12210 • The ‘return’ builtin may be used to abort execution of scripts
12211 executed with the ‘.’ or ‘source’ builtins (*note Bourne Shell
28ef6c31 12212 Builtins::).
d166f048 12213
b8c60bc9 12214 • Bash has much more optional behavior controllable with the ‘set’
28ef6c31 12215 builtin (*note The Set Builtin::).
cce855bc 12216
b8c60bc9 12217 • The ‘-x’ (‘xtrace’) option displays commands other than simple
b80f6443
JA
12218 commands when performing an execution trace (*note The Set
12219 Builtin::).
12220
b8c60bc9
CR
12221 • Bash includes the ‘shopt’ builtin, for finer control of shell
12222 optional capabilities (*note The Shopt Builtin::), and allows these
12223 options to be set and unset at shell invocation (*note Invoking
12224 Bash::).
12225
12226 • The ‘test’ builtin (*note Bourne Shell Builtins::) is slightly
bb70624e
JA
12227 different, as it implements the POSIX algorithm, which specifies
12228 the behavior based on the number of arguments.
ccc6cda3 12229
b8c60bc9
CR
12230 • The ‘trap’ builtin (*note Bourne Shell Builtins::) allows a ‘DEBUG’
12231 pseudo-signal specification, similar to ‘EXIT’. Commands specified
12232 with a ‘DEBUG’ trap are executed before every simple command, ‘for’
12233 command, ‘case’ command, ‘select’ command, every arithmetic ‘for’
a0c0a00f 12234 command, and before the first command executes in a shell function.
b8c60bc9
CR
12235 The ‘DEBUG’ trap is not inherited by shell functions unless the
12236 function has been given the ‘trace’ attribute or the ‘functrace’
12237 option has been enabled using the ‘shopt’ builtin. The ‘extdebug’
12238 shell option has additional effects on the ‘DEBUG’ trap.
12239
12240 The ‘trap’ builtin (*note Bourne Shell Builtins::) allows an ‘ERR’
12241 pseudo-signal specification, similar to ‘EXIT’ and ‘DEBUG’.
12242 Commands specified with an ‘ERR’ trap are executed after a simple
12243 command fails, with a few exceptions. The ‘ERR’ trap is not
12244 inherited by shell functions unless the ‘-o errtrace’ option to the
12245 ‘set’ builtin is enabled.
12246
12247 The ‘trap’ builtin (*note Bourne Shell Builtins::) allows a
12248 ‘RETURN’ pseudo-signal specification, similar to ‘EXIT’ and
12249 ‘DEBUG’. Commands specified with a ‘RETURN’ trap are executed
b80f6443 12250 before execution resumes after a shell function or a shell script
b8c60bc9 12251 executed with ‘.’ or ‘source’ returns. The ‘RETURN’ trap is not
a0c0a00f 12252 inherited by shell functions unless the function has been given the
b8c60bc9
CR
12253 ‘trace’ attribute or the ‘functrace’ option has been enabled using
12254 the ‘shopt’ builtin.
f73dda09 12255
b8c60bc9 12256 • The Bash ‘type’ builtin is more extensive and gives more
28ef6c31 12257 information about the names it finds (*note Bash Builtins::).
cce855bc 12258
b8c60bc9
CR
12259 • The ‘ulimit’ builtin provides control over many more per-process
12260 resources (*note Bash Builtins::).
d166f048 12261
b8c60bc9
CR
12262 • The Bash ‘umask’ builtin uses the ‘-p’ option to display the output
12263 in the form of a ‘umask’ command that may be reused as input (*note
12264 Bourne Shell Builtins::).
ccc6cda3 12265
b8c60bc9
CR
12266 • The Bash ‘wait’ builtin has a ‘-n’ option to wait for the next
12267 child to exit, possibly selecting from a list of supplied jobs, and
12268 the ‘-p’ option to store information about a terminated child
12269 process in a shell variable.
ccc6cda3 12270
b8c60bc9
CR
12271 • The SVR4.2 shell behaves differently when invoked as ‘jsh’ (it
12272 turns on job control).
95732b49 12273
b8c60bc9
CR
12274 • The SVR4.2 shell has two privilege-related builtins (‘mldmode’ and
12275 ‘priv’) not present in Bash.
ccc6cda3 12276
b8c60bc9 12277 • Bash does not have the ‘stop’ or ‘newgrp’ builtins.
d166f048 12278
b8c60bc9 12279 • Bash does not use the ‘SHACCT’ variable or perform shell
bb70624e 12280 accounting.
d166f048 12281
b8c60bc9 12282 • The SVR4.2 ‘sh’ uses a ‘TIMEOUT’ variable like Bash uses ‘TMOUT’.
28ef6c31 12283
3185942a 12284More features unique to Bash may be found in *note Bash Features::.
ccc6cda3 12285
b80f6443
JA
12286B.1 Implementation Differences From The SVR4.2 Shell
12287====================================================
ccc6cda3 12288
b80f6443
JA
12289Since Bash is a completely new implementation, it does not suffer from
12290many of the limitations of the SVR4.2 shell. For instance:
ccc6cda3 12291
b8c60bc9
CR
12292 • Bash does not fork a subshell when redirecting into or out of a
12293 shell control structure such as an ‘if’ or ‘while’ statement.
ccc6cda3 12294
b8c60bc9
CR
12295 • Bash does not allow unbalanced quotes. The SVR4.2 shell will
12296 silently insert a needed closing quote at ‘EOF’ under certain
bb70624e 12297 circumstances. This can be the cause of some hard-to-find errors.
ccc6cda3 12298
b8c60bc9
CR
12299 • The SVR4.2 shell uses a baroque memory management scheme based on
12300 trapping ‘SIGSEGV’. If the shell is started from a process with
12301 ‘SIGSEGV’ blocked (e.g., by using the ‘system()’ C library function
a0c0a00f 12302 call), it misbehaves badly.
ccc6cda3 12303
b8c60bc9
CR
12304 • In a questionable attempt at security, the SVR4.2 shell, when
12305 invoked without the ‘-p’ option, will alter its real and effective
bb70624e
JA
12306 UID and GID if they are less than some magic threshold value,
12307 commonly 100. This can lead to unexpected results.
ccc6cda3 12308
b8c60bc9
CR
12309 • The SVR4.2 shell does not allow users to trap ‘SIGSEGV’, ‘SIGALRM’,
12310 or ‘SIGCHLD’.
ccc6cda3 12311
b8c60bc9
CR
12312 • The SVR4.2 shell does not allow the ‘IFS’, ‘MAILCHECK’, ‘PATH’,
12313 ‘PS1’, or ‘PS2’ variables to be unset.
ccc6cda3 12314
b8c60bc9 12315 • The SVR4.2 shell treats ‘^’ as the undocumented equivalent of ‘|’.
ccc6cda3 12316
b8c60bc9
CR
12317 • Bash allows multiple option arguments when it is invoked (‘-x -v’);
12318 the SVR4.2 shell allows only one option argument (‘-xv’). In fact,
a0c0a00f 12319 some versions of the shell dump core if the second argument begins
b8c60bc9 12320 with a ‘-’.
ccc6cda3 12321
b8c60bc9 12322 • The SVR4.2 shell exits a script if any builtin fails; Bash exits a
0628567a
JA
12323 script only if one of the POSIX special builtins fails, and only
12324 for certain failures, as enumerated in the POSIX standard.
ccc6cda3 12325
b8c60bc9
CR
12326 • If the ‘lastpipe’ option is enabled, and job control is not active,
12327 Bash runs the last element of a pipeline in the current shell
12328 execution environment.
ccc6cda3
JA
12329
12330\1f
3185942a 12331File: bashref.info, Node: GNU Free Documentation License, Next: Indexes, Prev: Major Differences From The Bourne Shell, Up: Top
b80f6443 12332
3185942a
JA
12333Appendix C GNU Free Documentation License
12334*****************************************
b80f6443 12335
0001803f 12336 Version 1.3, 3 November 2008
b80f6443 12337
b8c60bc9 12338 Copyright © 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
a0c0a00f 12339 <http://fsf.org/>
b80f6443
JA
12340
12341 Everyone is permitted to copy and distribute verbatim copies
12342 of this license document, but changing it is not allowed.
12343
12344 0. PREAMBLE
12345
12346 The purpose of this License is to make a manual, textbook, or other
b8c60bc9 12347 functional and useful document “free” in the sense of freedom: to
b80f6443
JA
12348 assure everyone the effective freedom to copy and redistribute it,
12349 with or without modifying it, either commercially or
12350 noncommercially. Secondarily, this License preserves for the
12351 author and publisher a way to get credit for their work, while not
12352 being considered responsible for modifications made by others.
12353
12354 This License is a kind of "copyleft", which means that derivative
12355 works of the document must themselves be free in the same sense.
12356 It complements the GNU General Public License, which is a copyleft
12357 license designed for free software.
12358
12359 We have designed this License in order to use it for manuals for
12360 free software, because free software needs free documentation: a
12361 free program should come with manuals providing the same freedoms
12362 that the software does. But this License is not limited to
12363 software manuals; it can be used for any textual work, regardless
a0c0a00f
CR
12364 of subject matter or whether it is published as a printed book. We
12365 recommend this License principally for works whose purpose is
b80f6443
JA
12366 instruction or reference.
12367
12368 1. APPLICABILITY AND DEFINITIONS
12369
12370 This License applies to any manual or other work, in any medium,
a0c0a00f
CR
12371 that contains a notice placed by the copyright holder saying it can
12372 be distributed under the terms of this License. Such a notice
b80f6443
JA
12373 grants a world-wide, royalty-free license, unlimited in duration,
12374 to use that work under the conditions stated herein. The
12375 "Document", below, refers to any such manual or work. Any member
a0c0a00f
CR
12376 of the public is a licensee, and is addressed as "you". You accept
12377 the license if you copy, modify or distribute the work in a way
12378 requiring permission under copyright law.
b80f6443
JA
12379
12380 A "Modified Version" of the Document means any work containing the
12381 Document or a portion of it, either copied verbatim, or with
12382 modifications and/or translated into another language.
12383
12384 A "Secondary Section" is a named appendix or a front-matter section
12385 of the Document that deals exclusively with the relationship of the
12386 publishers or authors of the Document to the Document's overall
12387 subject (or to related matters) and contains nothing that could
12388 fall directly within that overall subject. (Thus, if the Document
12389 is in part a textbook of mathematics, a Secondary Section may not
12390 explain any mathematics.) The relationship could be a matter of
12391 historical connection with the subject or with related matters, or
12392 of legal, commercial, philosophical, ethical or political position
12393 regarding them.
12394
12395 The "Invariant Sections" are certain Secondary Sections whose
a0c0a00f
CR
12396 titles are designated, as being those of Invariant Sections, in the
12397 notice that says that the Document is released under this License.
12398 If a section does not fit the above definition of Secondary then it
12399 is not allowed to be designated as Invariant. The Document may
12400 contain zero Invariant Sections. If the Document does not identify
12401 any Invariant Sections then there are none.
b80f6443
JA
12402
12403 The "Cover Texts" are certain short passages of text that are
12404 listed, as Front-Cover Texts or Back-Cover Texts, in the notice
12405 that says that the Document is released under this License. A
12406 Front-Cover Text may be at most 5 words, and a Back-Cover Text may
12407 be at most 25 words.
12408
12409 A "Transparent" copy of the Document means a machine-readable copy,
12410 represented in a format whose specification is available to the
12411 general public, that is suitable for revising the document
a0c0a00f
CR
12412 straightforwardly with generic text editors or (for images composed
12413 of pixels) generic paint programs or (for drawings) some widely
12414 available drawing editor, and that is suitable for input to text
12415 formatters or for automatic translation to a variety of formats
12416 suitable for input to text formatters. A copy made in an otherwise
12417 Transparent file format whose markup, or absence of markup, has
12418 been arranged to thwart or discourage subsequent modification by
12419 readers is not Transparent. An image format is not Transparent if
12420 used for any substantial amount of text. A copy that is not
12421 "Transparent" is called "Opaque".
b80f6443
JA
12422
12423 Examples of suitable formats for Transparent copies include plain
12424 ASCII without markup, Texinfo input format, LaTeX input format,
a0c0a00f
CR
12425 SGML or XML using a publicly available DTD, and standard-conforming
12426 simple HTML, PostScript or PDF designed for human modification.
12427 Examples of transparent image formats include PNG, XCF and JPG.
12428 Opaque formats include proprietary formats that can be read and
12429 edited only by proprietary word processors, SGML or XML for which
12430 the DTD and/or processing tools are not generally available, and
12431 the machine-generated HTML, PostScript or PDF produced by some word
12432 processors for output purposes only.
b80f6443
JA
12433
12434 The "Title Page" means, for a printed book, the title page itself,
12435 plus such following pages as are needed to hold, legibly, the
12436 material this License requires to appear in the title page. For
12437 works in formats which do not have any title page as such, "Title
12438 Page" means the text near the most prominent appearance of the
12439 work's title, preceding the beginning of the body of the text.
12440
0001803f
CR
12441 The "publisher" means any person or entity that distributes copies
12442 of the Document to the public.
12443
b80f6443
JA
12444 A section "Entitled XYZ" means a named subunit of the Document
12445 whose title either is precisely XYZ or contains XYZ in parentheses
12446 following text that translates XYZ in another language. (Here XYZ
12447 stands for a specific section name mentioned below, such as
12448 "Acknowledgements", "Dedications", "Endorsements", or "History".)
12449 To "Preserve the Title" of such a section when you modify the
12450 Document means that it remains a section "Entitled XYZ" according
12451 to this definition.
12452
12453 The Document may include Warranty Disclaimers next to the notice
12454 which states that this License applies to the Document. These
12455 Warranty Disclaimers are considered to be included by reference in
12456 this License, but only as regards disclaiming warranties: any other
12457 implication that these Warranty Disclaimers may have is void and
12458 has no effect on the meaning of this License.
12459
12460 2. VERBATIM COPYING
12461
12462 You may copy and distribute the Document in any medium, either
12463 commercially or noncommercially, provided that this License, the
12464 copyright notices, and the license notice saying this License
12465 applies to the Document are reproduced in all copies, and that you
12466 add no other conditions whatsoever to those of this License. You
12467 may not use technical measures to obstruct or control the reading
12468 or further copying of the copies you make or distribute. However,
12469 you may accept compensation in exchange for copies. If you
a0c0a00f
CR
12470 distribute a large enough number of copies you must also follow the
12471 conditions in section 3.
b80f6443
JA
12472
12473 You may also lend copies, under the same conditions stated above,
12474 and you may publicly display copies.
12475
12476 3. COPYING IN QUANTITY
12477
12478 If you publish printed copies (or copies in media that commonly
12479 have printed covers) of the Document, numbering more than 100, and
12480 the Document's license notice requires Cover Texts, you must
12481 enclose the copies in covers that carry, clearly and legibly, all
12482 these Cover Texts: Front-Cover Texts on the front cover, and
12483 Back-Cover Texts on the back cover. Both covers must also clearly
12484 and legibly identify you as the publisher of these copies. The
a0c0a00f
CR
12485 front cover must present the full title with all words of the title
12486 equally prominent and visible. You may add other material on the
12487 covers in addition. Copying with changes limited to the covers, as
12488 long as they preserve the title of the Document and satisfy these
12489 conditions, can be treated as verbatim copying in other respects.
b80f6443
JA
12490
12491 If the required texts for either cover are too voluminous to fit
12492 legibly, you should put the first ones listed (as many as fit
12493 reasonably) on the actual cover, and continue the rest onto
12494 adjacent pages.
12495
12496 If you publish or distribute Opaque copies of the Document
a0c0a00f
CR
12497 numbering more than 100, you must either include a machine-readable
12498 Transparent copy along with each Opaque copy, or state in or with
12499 each Opaque copy a computer-network location from which the general
12500 network-using public has access to download using public-standard
12501 network protocols a complete Transparent copy of the Document, free
12502 of added material. If you use the latter option, you must take
12503 reasonably prudent steps, when you begin distribution of Opaque
12504 copies in quantity, to ensure that this Transparent copy will
12505 remain thus accessible at the stated location until at least one
12506 year after the last time you distribute an Opaque copy (directly or
12507 through your agents or retailers) of that edition to the public.
b80f6443
JA
12508
12509 It is requested, but not required, that you contact the authors of
a0c0a00f
CR
12510 the Document well before redistributing any large number of copies,
12511 to give them a chance to provide you with an updated version of the
12512 Document.
b80f6443
JA
12513
12514 4. MODIFICATIONS
12515
12516 You may copy and distribute a Modified Version of the Document
12517 under the conditions of sections 2 and 3 above, provided that you
a0c0a00f
CR
12518 release the Modified Version under precisely this License, with the
12519 Modified Version filling the role of the Document, thus licensing
12520 distribution and modification of the Modified Version to whoever
12521 possesses a copy of it. In addition, you must do these things in
12522 the Modified Version:
b80f6443
JA
12523
12524 A. Use in the Title Page (and on the covers, if any) a title
a0c0a00f
CR
12525 distinct from that of the Document, and from those of previous
12526 versions (which should, if there were any, be listed in the
12527 History section of the Document). You may use the same title
12528 as a previous version if the original publisher of that
12529 version gives permission.
b80f6443
JA
12530
12531 B. List on the Title Page, as authors, one or more persons or
12532 entities responsible for authorship of the modifications in
12533 the Modified Version, together with at least five of the
12534 principal authors of the Document (all of its principal
12535 authors, if it has fewer than five), unless they release you
12536 from this requirement.
12537
12538 C. State on the Title page the name of the publisher of the
12539 Modified Version, as the publisher.
12540
12541 D. Preserve all the copyright notices of the Document.
12542
12543 E. Add an appropriate copyright notice for your modifications
12544 adjacent to the other copyright notices.
12545
12546 F. Include, immediately after the copyright notices, a license
12547 notice giving the public permission to use the Modified
12548 Version under the terms of this License, in the form shown in
12549 the Addendum below.
12550
12551 G. Preserve in that license notice the full lists of Invariant
12552 Sections and required Cover Texts given in the Document's
12553 license notice.
12554
12555 H. Include an unaltered copy of this License.
12556
12557 I. Preserve the section Entitled "History", Preserve its Title,
12558 and add to it an item stating at least the title, year, new
a0c0a00f
CR
12559 authors, and publisher of the Modified Version as given on the
12560 Title Page. If there is no section Entitled "History" in the
12561 Document, create one stating the title, year, authors, and
12562 publisher of the Document as given on its Title Page, then add
12563 an item describing the Modified Version as stated in the
12564 previous sentence.
b80f6443
JA
12565
12566 J. Preserve the network location, if any, given in the Document
12567 for public access to a Transparent copy of the Document, and
12568 likewise the network locations given in the Document for
a0c0a00f
CR
12569 previous versions it was based on. These may be placed in the
12570 "History" section. You may omit a network location for a work
12571 that was published at least four years before the Document
12572 itself, or if the original publisher of the version it refers
12573 to gives permission.
b80f6443
JA
12574
12575 K. For any section Entitled "Acknowledgements" or "Dedications",
a0c0a00f
CR
12576 Preserve the Title of the section, and preserve in the section
12577 all the substance and tone of each of the contributor
b80f6443
JA
12578 acknowledgements and/or dedications given therein.
12579
a0c0a00f
CR
12580 L. Preserve all the Invariant Sections of the Document, unaltered
12581 in their text and in their titles. Section numbers or the
12582 equivalent are not considered part of the section titles.
b80f6443
JA
12583
12584 M. Delete any section Entitled "Endorsements". Such a section
12585 may not be included in the Modified Version.
12586
12587 N. Do not retitle any existing section to be Entitled
12588 "Endorsements" or to conflict in title with any Invariant
12589 Section.
12590
12591 O. Preserve any Warranty Disclaimers.
12592
12593 If the Modified Version includes new front-matter sections or
12594 appendices that qualify as Secondary Sections and contain no
a0c0a00f
CR
12595 material copied from the Document, you may at your option designate
12596 some or all of these sections as invariant. To do this, add their
12597 titles to the list of Invariant Sections in the Modified Version's
12598 license notice. These titles must be distinct from any other
12599 section titles.
b80f6443
JA
12600
12601 You may add a section Entitled "Endorsements", provided it contains
12602 nothing but endorsements of your Modified Version by various
12603 parties--for example, statements of peer review or that the text
12604 has been approved by an organization as the authoritative
12605 definition of a standard.
12606
12607 You may add a passage of up to five words as a Front-Cover Text,
a0c0a00f
CR
12608 and a passage of up to 25 words as a Back-Cover Text, to the end of
12609 the list of Cover Texts in the Modified Version. Only one passage
12610 of Front-Cover Text and one of Back-Cover Text may be added by (or
12611 through arrangements made by) any one entity. If the Document
12612 already includes a cover text for the same cover, previously added
12613 by you or by arrangement made by the same entity you are acting on
12614 behalf of, you may not add another; but you may replace the old
12615 one, on explicit permission from the previous publisher that added
12616 the old one.
b80f6443
JA
12617
12618 The author(s) and publisher(s) of the Document do not by this
12619 License give permission to use their names for publicity for or to
12620 assert or imply endorsement of any Modified Version.
12621
12622 5. COMBINING DOCUMENTS
12623
12624 You may combine the Document with other documents released under
12625 this License, under the terms defined in section 4 above for
a0c0a00f
CR
12626 modified versions, provided that you include in the combination all
12627 of the Invariant Sections of all of the original documents,
b80f6443
JA
12628 unmodified, and list them all as Invariant Sections of your
12629 combined work in its license notice, and that you preserve all
12630 their Warranty Disclaimers.
12631
12632 The combined work need only contain one copy of this License, and
12633 multiple identical Invariant Sections may be replaced with a single
12634 copy. If there are multiple Invariant Sections with the same name
12635 but different contents, make the title of each such section unique
12636 by adding at the end of it, in parentheses, the name of the
12637 original author or publisher of that section if known, or else a
12638 unique number. Make the same adjustment to the section titles in
12639 the list of Invariant Sections in the license notice of the
12640 combined work.
12641
12642 In the combination, you must combine any sections Entitled
12643 "History" in the various original documents, forming one section
12644 Entitled "History"; likewise combine any sections Entitled
12645 "Acknowledgements", and any sections Entitled "Dedications". You
12646 must delete all sections Entitled "Endorsements."
12647
12648 6. COLLECTIONS OF DOCUMENTS
12649
12650 You may make a collection consisting of the Document and other
12651 documents released under this License, and replace the individual
12652 copies of this License in the various documents with a single copy
12653 that is included in the collection, provided that you follow the
a0c0a00f
CR
12654 rules of this License for verbatim copying of each of the documents
12655 in all other respects.
b80f6443
JA
12656
12657 You may extract a single document from such a collection, and
12658 distribute it individually under this License, provided you insert
a0c0a00f
CR
12659 a copy of this License into the extracted document, and follow this
12660 License in all other respects regarding verbatim copying of that
12661 document.
b80f6443
JA
12662
12663 7. AGGREGATION WITH INDEPENDENT WORKS
12664
12665 A compilation of the Document or its derivatives with other
a0c0a00f
CR
12666 separate and independent documents or works, in or on a volume of a
12667 storage or distribution medium, is called an "aggregate" if the
b80f6443
JA
12668 copyright resulting from the compilation is not used to limit the
12669 legal rights of the compilation's users beyond what the individual
3185942a 12670 works permit. When the Document is included in an aggregate, this
b80f6443
JA
12671 License does not apply to the other works in the aggregate which
12672 are not themselves derivative works of the Document.
12673
12674 If the Cover Text requirement of section 3 is applicable to these
12675 copies of the Document, then if the Document is less than one half
12676 of the entire aggregate, the Document's Cover Texts may be placed
12677 on covers that bracket the Document within the aggregate, or the
12678 electronic equivalent of covers if the Document is in electronic
12679 form. Otherwise they must appear on printed covers that bracket
12680 the whole aggregate.
12681
12682 8. TRANSLATION
12683
12684 Translation is considered a kind of modification, so you may
12685 distribute translations of the Document under the terms of section
12686 4. Replacing Invariant Sections with translations requires special
12687 permission from their copyright holders, but you may include
12688 translations of some or all Invariant Sections in addition to the
12689 original versions of these Invariant Sections. You may include a
12690 translation of this License, and all the license notices in the
12691 Document, and any Warranty Disclaimers, provided that you also
12692 include the original English version of this License and the
12693 original versions of those notices and disclaimers. In case of a
12694 disagreement between the translation and the original version of
12695 this License or a notice or disclaimer, the original version will
12696 prevail.
12697
12698 If a section in the Document is Entitled "Acknowledgements",
12699 "Dedications", or "History", the requirement (section 4) to
12700 Preserve its Title (section 1) will typically require changing the
12701 actual title.
12702
12703 9. TERMINATION
12704
12705 You may not copy, modify, sublicense, or distribute the Document
0001803f
CR
12706 except as expressly provided under this License. Any attempt
12707 otherwise to copy, modify, sublicense, or distribute it is void,
12708 and will automatically terminate your rights under this License.
12709
12710 However, if you cease all violation of this License, then your
12711 license from a particular copyright holder is reinstated (a)
a0c0a00f
CR
12712 provisionally, unless and until the copyright holder explicitly and
12713 finally terminates your license, and (b) permanently, if the
0001803f
CR
12714 copyright holder fails to notify you of the violation by some
12715 reasonable means prior to 60 days after the cessation.
12716
12717 Moreover, your license from a particular copyright holder is
12718 reinstated permanently if the copyright holder notifies you of the
12719 violation by some reasonable means, this is the first time you have
12720 received notice of violation of this License (for any work) from
12721 that copyright holder, and you cure the violation prior to 30 days
12722 after your receipt of the notice.
12723
12724 Termination of your rights under this section does not terminate
a0c0a00f
CR
12725 the licenses of parties who have received copies or rights from you
12726 under this License. If your rights have been terminated and not
12727 permanently reinstated, receipt of a copy of some or all of the
12728 same material does not give you any rights to use it.
b80f6443 12729
a0c0a00f 12730 10. FUTURE REVISIONS OF THIS LICENSE
b80f6443
JA
12731
12732 The Free Software Foundation may publish new, revised versions of
12733 the GNU Free Documentation License from time to time. Such new
12734 versions will be similar in spirit to the present version, but may
12735 differ in detail to address new problems or concerns. See
a0c0a00f 12736 <http://www.gnu.org/copyleft/>.
b80f6443
JA
12737
12738 Each version of the License is given a distinguishing version
12739 number. If the Document specifies that a particular numbered
12740 version of this License "or any later version" applies to it, you
12741 have the option of following the terms and conditions either of
12742 that specified version or of any later version that has been
a0c0a00f
CR
12743 published (not as a draft) by the Free Software Foundation. If the
12744 Document does not specify a version number of this License, you may
12745 choose any version ever published (not as a draft) by the Free
12746 Software Foundation. If the Document specifies that a proxy can
12747 decide which future versions of this License can be used, that
0001803f
CR
12748 proxy's public statement of acceptance of a version permanently
12749 authorizes you to choose that version for the Document.
12750
a0c0a00f 12751 11. RELICENSING
0001803f
CR
12752
12753 "Massive Multiauthor Collaboration Site" (or "MMC Site") means any
12754 World Wide Web server that publishes copyrightable works and also
12755 provides prominent facilities for anybody to edit those works. A
12756 public wiki that anybody can edit is an example of such a server.
12757 A "Massive Multiauthor Collaboration" (or "MMC") contained in the
12758 site means any set of copyrightable works thus published on the MMC
12759 site.
12760
12761 "CC-BY-SA" means the Creative Commons Attribution-Share Alike 3.0
12762 license published by Creative Commons Corporation, a not-for-profit
12763 corporation with a principal place of business in San Francisco,
12764 California, as well as future copyleft versions of that license
12765 published by that same organization.
12766
12767 "Incorporate" means to publish or republish a Document, in whole or
12768 in part, as part of another Document.
12769
12770 An MMC is "eligible for relicensing" if it is licensed under this
12771 License, and if all works that were first published under this
12772 License somewhere other than this MMC, and subsequently
12773 incorporated in whole or in part into the MMC, (1) had no cover
12774 texts or invariant sections, and (2) were thus incorporated prior
12775 to November 1, 2008.
12776
12777 The operator of an MMC Site may republish an MMC contained in the
12778 site under CC-BY-SA on the same site at any time before August 1,
12779 2009, provided the MMC is eligible for relicensing.
12780
3185942a
JA
12781ADDENDUM: How to use this License for your documents
12782====================================================
b80f6443
JA
12783
12784To use this License in a document you have written, include a copy of
12785the License in the document and put the following copyright and license
12786notices just after the title page:
12787
12788 Copyright (C) YEAR YOUR NAME.
12789 Permission is granted to copy, distribute and/or modify this document
0001803f 12790 under the terms of the GNU Free Documentation License, Version 1.3
b80f6443 12791 or any later version published by the Free Software Foundation;
3185942a
JA
12792 with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
12793 Texts. A copy of the license is included in the section entitled ``GNU
b80f6443
JA
12794 Free Documentation License''.
12795
12796 If you have Invariant Sections, Front-Cover Texts and Back-Cover
a0c0a00f 12797Texts, replace the "with...Texts." line with this:
b80f6443
JA
12798
12799 with the Invariant Sections being LIST THEIR TITLES, with
12800 the Front-Cover Texts being LIST, and with the Back-Cover Texts
12801 being LIST.
12802
12803 If you have Invariant Sections without Cover Texts, or some other
12804combination of the three, merge those two alternatives to suit the
12805situation.
12806
12807 If your document contains nontrivial examples of program code, we
a0c0a00f
CR
12808recommend releasing these examples in parallel under your choice of free
12809software license, such as the GNU General Public License, to permit
12810their use in free software.
b80f6443
JA
12811
12812\1f
3185942a
JA
12813File: bashref.info, Node: Indexes, Prev: GNU Free Documentation License, Up: Top
12814
12815Appendix D Indexes
12816******************
12817
12818* Menu:
12819
12820* Builtin Index:: Index of Bash builtin commands.
12821* Reserved Word Index:: Index of Bash reserved words.
12822* Variable Index:: Quick reference helps you find the
12823 variable you want.
12824* Function Index:: Index of bindable Readline functions.
12825* Concept Index:: General index for concepts described in
12826 this manual.
12827
12828\1f
12829File: bashref.info, Node: Builtin Index, Next: Reserved Word Index, Up: Indexes
ccc6cda3 12830
3185942a
JA
12831D.1 Index of Shell Builtin Commands
12832===================================
ccc6cda3 12833
b80f6443 12834\0\b[index\0\b]
ccc6cda3
JA
12835* Menu:
12836
e8ce775d 12837* :: Bourne Shell Builtins.
b80f6443 12838 (line 11)
b8c60bc9
CR
12839* .: Bourne Shell Builtins.
12840 (line 17)
e8ce775d 12841* [: Bourne Shell Builtins.
b8c60bc9 12842 (line 339)
b80f6443 12843* alias: Bash Builtins. (line 11)
e8ce775d 12844* bg: Job Control Builtins.
b80f6443 12845 (line 7)
b8c60bc9 12846* bind: Bash Builtins. (line 24)
e8ce775d 12847* break: Bourne Shell Builtins.
b8c60bc9
CR
12848 (line 47)
12849* builtin: Bash Builtins. (line 133)
12850* caller: Bash Builtins. (line 142)
e8ce775d 12851* cd: Bourne Shell Builtins.
b8c60bc9
CR
12852 (line 55)
12853* command: Bash Builtins. (line 159)
bb70624e 12854* compgen: Programmable Completion Builtins.
ac50fbac 12855 (line 12)
bb70624e 12856* complete: Programmable Completion Builtins.
b8c60bc9 12857 (line 37)
3185942a 12858* compopt: Programmable Completion Builtins.
b8c60bc9 12859 (line 258)
e8ce775d 12860* continue: Bourne Shell Builtins.
b8c60bc9
CR
12861 (line 106)
12862* declare: Bash Builtins. (line 179)
bb70624e 12863* dirs: Directory Stack Builtins.
b80f6443 12864 (line 7)
e8ce775d 12865* disown: Job Control Builtins.
b8c60bc9
CR
12866 (line 120)
12867* echo: Bash Builtins. (line 284)
12868* enable: Bash Builtins. (line 337)
e8ce775d 12869* eval: Bourne Shell Builtins.
b8c60bc9 12870 (line 115)
e8ce775d 12871* exec: Bourne Shell Builtins.
b8c60bc9 12872 (line 123)
e8ce775d 12873* exit: Bourne Shell Builtins.
b8c60bc9 12874 (line 145)
e8ce775d 12875* export: Bourne Shell Builtins.
b8c60bc9
CR
12876 (line 152)
12877* false: Bourne Shell Builtins.
12878 (line 175)
cce855bc 12879* fc: Bash History Builtins.
b80f6443 12880 (line 10)
e8ce775d 12881* fg: Job Control Builtins.
ac50fbac 12882 (line 17)
e8ce775d 12883* getopts: Bourne Shell Builtins.
b8c60bc9 12884 (line 180)
e8ce775d 12885* hash: Bourne Shell Builtins.
b8c60bc9
CR
12886 (line 232)
12887* help: Bash Builtins. (line 375)
cce855bc 12888* history: Bash History Builtins.
b8c60bc9 12889 (line 59)
e8ce775d 12890* jobs: Job Control Builtins.
b8c60bc9 12891 (line 28)
e8ce775d 12892* kill: Job Control Builtins.
b8c60bc9
CR
12893 (line 61)
12894* let: Bash Builtins. (line 404)
12895* local: Bash Builtins. (line 413)
12896* logout: Bash Builtins. (line 438)
12897* mapfile: Bash Builtins. (line 443)
bb70624e 12898* popd: Directory Stack Builtins.
b8c60bc9
CR
12899 (line 37)
12900* printf: Bash Builtins. (line 488)
bb70624e 12901* pushd: Directory Stack Builtins.
b8c60bc9 12902 (line 71)
e8ce775d 12903* pwd: Bourne Shell Builtins.
b8c60bc9
CR
12904 (line 264)
12905* read: Bash Builtins. (line 558)
12906* readarray: Bash Builtins. (line 669)
e8ce775d 12907* readonly: Bourne Shell Builtins.
b8c60bc9 12908 (line 276)
e8ce775d 12909* return: Bourne Shell Builtins.
b8c60bc9 12910 (line 301)
3185942a 12911* set: The Set Builtin. (line 11)
e8ce775d 12912* shift: Bourne Shell Builtins.
b8c60bc9 12913 (line 326)
3185942a 12914* shopt: The Shopt Builtin. (line 9)
b8c60bc9 12915* source: Bash Builtins. (line 678)
e8ce775d 12916* suspend: Job Control Builtins.
b8c60bc9 12917 (line 139)
e8ce775d 12918* test: Bourne Shell Builtins.
b8c60bc9 12919 (line 339)
e8ce775d 12920* times: Bourne Shell Builtins.
b8c60bc9 12921 (line 439)
e8ce775d 12922* trap: Bourne Shell Builtins.
b8c60bc9
CR
12923 (line 445)
12924* true: Bourne Shell Builtins.
12925 (line 511)
12926* type: Bash Builtins. (line 683)
12927* typeset: Bash Builtins. (line 720)
12928* ulimit: Bash Builtins. (line 726)
e8ce775d 12929* umask: Bourne Shell Builtins.
b8c60bc9
CR
12930 (line 516)
12931* unalias: Bash Builtins. (line 834)
e8ce775d 12932* unset: Bourne Shell Builtins.
b8c60bc9 12933 (line 534)
e8ce775d 12934* wait: Job Control Builtins.
b8c60bc9 12935 (line 86)
ccc6cda3
JA
12936
12937\1f
3185942a 12938File: bashref.info, Node: Reserved Word Index, Next: Variable Index, Prev: Builtin Index, Up: Indexes
ccc6cda3 12939
3185942a
JA
12940D.2 Index of Shell Reserved Words
12941=================================
ccc6cda3 12942
b80f6443 12943\0\b[index\0\b]
ccc6cda3
JA
12944* Menu:
12945
3185942a 12946* !: Pipelines. (line 9)
cce855bc 12947* [[: Conditional Constructs.
b8c60bc9 12948 (line 128)
cce855bc 12949* ]]: Conditional Constructs.
b8c60bc9 12950 (line 128)
a0c0a00f
CR
12951* {: Command Grouping. (line 21)
12952* }: Command Grouping. (line 21)
e8ce775d 12953* case: Conditional Constructs.
b80f6443
JA
12954 (line 28)
12955* do: Looping Constructs. (line 12)
12956* done: Looping Constructs. (line 12)
e8ce775d 12957* elif: Conditional Constructs.
b80f6443 12958 (line 7)
e8ce775d 12959* else: Conditional Constructs.
b80f6443 12960 (line 7)
e8ce775d 12961* esac: Conditional Constructs.
b80f6443 12962 (line 28)
e8ce775d 12963* fi: Conditional Constructs.
b80f6443 12964 (line 7)
ac50fbac 12965* for: Looping Constructs. (line 32)
b80f6443 12966* function: Shell Functions. (line 13)
e8ce775d 12967* if: Conditional Constructs.
b80f6443 12968 (line 7)
e8ce775d 12969* in: Conditional Constructs.
b80f6443 12970 (line 28)
cce855bc 12971* select: Conditional Constructs.
74091dd4 12972 (line 84)
e8ce775d 12973* then: Conditional Constructs.
b80f6443 12974 (line 7)
3185942a 12975* time: Pipelines. (line 9)
b80f6443 12976* until: Looping Constructs. (line 12)
ac50fbac 12977* while: Looping Constructs. (line 22)
ccc6cda3
JA
12978
12979\1f
3185942a 12980File: bashref.info, Node: Variable Index, Next: Function Index, Prev: Reserved Word Index, Up: Indexes
ccc6cda3 12981
3185942a
JA
12982D.3 Parameter and Variable Index
12983================================
ccc6cda3 12984
b80f6443 12985\0\b[index\0\b]
ccc6cda3
JA
12986* Menu:
12987
8868edaf 12988* _: Bash Variables. (line 13)
b8c60bc9
CR
12989* -: Special Parameters. (line 48)
12990* !: Special Parameters. (line 57)
12991* ?: Special Parameters. (line 44)
12992* @: Special Parameters. (line 23)
12993* *: Special Parameters. (line 10)
12994* #: Special Parameters. (line 41)
12995* $: Special Parameters. (line 53)
12996* $_: Bash Variables. (line 14)
12997* $-: Special Parameters. (line 49)
12998* $!: Special Parameters. (line 58)
12999* $?: Special Parameters. (line 45)
13000* $@: Special Parameters. (line 24)
13001* $*: Special Parameters. (line 11)
13002* $#: Special Parameters. (line 42)
13003* $$: Special Parameters. (line 54)
13004* $0: Special Parameters. (line 63)
13005* 0: Special Parameters. (line 62)
74091dd4
CR
13006* active-region-end-color: Readline Init File Syntax.
13007 (line 51)
13008* active-region-start-color: Readline Init File Syntax.
13009 (line 38)
e8ce775d 13010* auto_resume: Job Control Variables.
b80f6443 13011 (line 6)
b8c60bc9
CR
13012* BASH: Bash Variables. (line 24)
13013* BASH_ALIASES: Bash Variables. (line 44)
13014* BASH_ARGC: Bash Variables. (line 53)
13015* BASH_ARGV: Bash Variables. (line 67)
13016* BASH_ARGV0: Bash Variables. (line 80)
13017* BASH_CMDS: Bash Variables. (line 88)
13018* BASH_COMMAND: Bash Variables. (line 97)
13019* BASH_COMPAT: Bash Variables. (line 104)
13020* BASH_ENV: Bash Variables. (line 120)
13021* BASH_EXECUTION_STRING: Bash Variables. (line 126)
13022* BASH_LINENO: Bash Variables. (line 129)
13023* BASH_LOADABLES_PATH: Bash Variables. (line 139)
13024* BASH_MONOSECONDS: Bash Variables. (line 143)
13025* BASH_REMATCH: Bash Variables. (line 150)
13026* BASH_SOURCE: Bash Variables. (line 158)
13027* BASH_SUBSHELL: Bash Variables. (line 166)
13028* BASH_TRAPSIG: Bash Variables. (line 172)
13029* BASH_VERSINFO: Bash Variables. (line 178)
13030* BASH_VERSION: Bash Variables. (line 201)
13031* BASH_XTRACEFD: Bash Variables. (line 205)
13032* BASHOPTS: Bash Variables. (line 27)
13033* BASHPID: Bash Variables. (line 37)
e8ce775d 13034* bell-style: Readline Init File Syntax.
74091dd4 13035 (line 64)
95732b49 13036* bind-tty-special-chars: Readline Init File Syntax.
74091dd4 13037 (line 71)
a0c0a00f 13038* blink-matching-paren: Readline Init File Syntax.
b8c60bc9 13039 (line 79)
e8ce775d 13040* CDPATH: Bourne Shell Variables.
b80f6443 13041 (line 9)
b8c60bc9 13042* CHILD_MAX: Bash Variables. (line 217)
a0c0a00f 13043* colored-completion-prefix: Readline Init File Syntax.
b8c60bc9 13044 (line 84)
ac50fbac 13045* colored-stats: Readline Init File Syntax.
b8c60bc9
CR
13046 (line 94)
13047* COLUMNS: Bash Variables. (line 224)
ac50fbac 13048* comment-begin: Readline Init File Syntax.
b8c60bc9
CR
13049 (line 100)
13050* COMP_CWORD: Bash Variables. (line 230)
13051* COMP_KEY: Bash Variables. (line 236)
13052* COMP_LINE: Bash Variables. (line 242)
13053* COMP_POINT: Bash Variables. (line 247)
13054* COMP_TYPE: Bash Variables. (line 255)
13055* COMP_WORDBREAKS: Bash Variables. (line 265)
13056* COMP_WORDS: Bash Variables. (line 271)
495aee44 13057* completion-display-width: Readline Init File Syntax.
b8c60bc9 13058 (line 104)
495aee44 13059* completion-ignore-case: Readline Init File Syntax.
b8c60bc9 13060 (line 111)
495aee44 13061* completion-map-case: Readline Init File Syntax.
b8c60bc9 13062 (line 116)
ac50fbac 13063* completion-prefix-display-length: Readline Init File Syntax.
b8c60bc9 13064 (line 122)
3185942a 13065* completion-query-items: Readline Init File Syntax.
b8c60bc9
CR
13066 (line 131)
13067* COMPREPLY: Bash Variables. (line 278)
95732b49 13068* convert-meta: Readline Init File Syntax.
b8c60bc9
CR
13069 (line 142)
13070* COPROC: Bash Variables. (line 284)
13071* DIRSTACK: Bash Variables. (line 288)
ac50fbac 13072* disable-completion: Readline Init File Syntax.
b8c60bc9 13073 (line 154)
a0c0a00f 13074* echo-control-characters: Readline Init File Syntax.
b8c60bc9 13075 (line 159)
e8ce775d 13076* editing-mode: Readline Init File Syntax.
74091dd4 13077 (line 164)
b8c60bc9
CR
13078* EMACS: Bash Variables. (line 298)
13079* emacs-mode-string: Readline Init File Syntax.
13080 (line 170)
13081* enable-active-region The: Readline Init File Syntax.
13082 (line 180)
a0c0a00f 13083* enable-bracketed-paste: Readline Init File Syntax.
b8c60bc9 13084 (line 193)
e8ce775d 13085* enable-keypad: Readline Init File Syntax.
b8c60bc9
CR
13086 (line 202)
13087* enable-meta-key: Readline Init File Syntax.
74091dd4 13088 (line 207)
b8c60bc9
CR
13089* ENV: Bash Variables. (line 303)
13090* EPOCHREALTIME: Bash Variables. (line 308)
13091* EPOCHSECONDS: Bash Variables. (line 316)
13092* EUID: Bash Variables. (line 323)
13093* EXECIGNORE: Bash Variables. (line 327)
13094* expand-tilde: Readline Init File Syntax.
13095 (line 217)
13096* FCEDIT: Bash Variables. (line 339)
13097* FIGNORE: Bash Variables. (line 342)
13098* force-meta-prefix: Readline Init File Syntax.
13099 (line 221)
13100* FUNCNAME: Bash Variables. (line 348)
13101* FUNCNEST: Bash Variables. (line 365)
13102* GLOBIGNORE: Bash Variables. (line 370)
13103* GLOBSORT: Bash Variables. (line 377)
13104* GROUPS: Bash Variables. (line 415)
13105* histchars: Bash Variables. (line 421)
13106* HISTCMD: Bash Variables. (line 437)
13107* HISTCONTROL: Bash Variables. (line 443)
13108* HISTFILE: Bash Variables. (line 461)
13109* HISTFILESIZE: Bash Variables. (line 467)
13110* HISTIGNORE: Bash Variables. (line 481)
f73dda09 13111* history-preserve-point: Readline Init File Syntax.
b8c60bc9 13112 (line 234)
ac50fbac 13113* history-size: Readline Init File Syntax.
b8c60bc9
CR
13114 (line 240)
13115* HISTSIZE: Bash Variables. (line 505)
13116* HISTTIMEFORMAT: Bash Variables. (line 512)
e8ce775d 13117* HOME: Bourne Shell Variables.
b80f6443 13118 (line 13)
e8ce775d 13119* horizontal-scroll-mode: Readline Init File Syntax.
b8c60bc9
CR
13120 (line 250)
13121* HOSTFILE: Bash Variables. (line 521)
13122* HOSTNAME: Bash Variables. (line 532)
13123* HOSTTYPE: Bash Variables. (line 535)
e8ce775d 13124* IFS: Bourne Shell Variables.
b80f6443 13125 (line 18)
b8c60bc9 13126* IGNOREEOF: Bash Variables. (line 538)
e8ce775d 13127* input-meta: Readline Init File Syntax.
b8c60bc9
CR
13128 (line 258)
13129* INPUTRC: Bash Variables. (line 547)
13130* INSIDE_EMACS: Bash Variables. (line 551)
b72432fd 13131* isearch-terminators: Readline Init File Syntax.
b8c60bc9 13132 (line 269)
e8ce775d 13133* keymap: Readline Init File Syntax.
b8c60bc9 13134 (line 276)
74091dd4
CR
13135* LANG: Creating Internationalized Scripts.
13136 (line 51)
b8c60bc9
CR
13137* LANG <1>: Bash Variables. (line 557)
13138* LC_ALL: Bash Variables. (line 561)
13139* LC_COLLATE: Bash Variables. (line 565)
13140* LC_CTYPE: Bash Variables. (line 572)
74091dd4
CR
13141* LC_MESSAGES: Creating Internationalized Scripts.
13142 (line 51)
b8c60bc9
CR
13143* LC_MESSAGES <1>: Bash Variables. (line 577)
13144* LC_NUMERIC: Bash Variables. (line 581)
13145* LC_TIME: Bash Variables. (line 585)
13146* LINENO: Bash Variables. (line 589)
13147* LINES: Bash Variables. (line 596)
13148* MACHTYPE: Bash Variables. (line 602)
e8ce775d 13149* MAIL: Bourne Shell Variables.
b8c60bc9
CR
13150 (line 24)
13151* MAILCHECK: Bash Variables. (line 606)
e8ce775d 13152* MAILPATH: Bourne Shell Variables.
b8c60bc9
CR
13153 (line 29)
13154* MAPFILE: Bash Variables. (line 614)
e8ce775d 13155* mark-modified-lines: Readline Init File Syntax.
b8c60bc9 13156 (line 306)
7117c2d2 13157* mark-symlinked-directories: Readline Init File Syntax.
b8c60bc9 13158 (line 311)
f73dda09 13159* match-hidden-files: Readline Init File Syntax.
b8c60bc9 13160 (line 316)
495aee44 13161* menu-complete-display-prefix: Readline Init File Syntax.
b8c60bc9 13162 (line 323)
e8ce775d 13163* meta-flag: Readline Init File Syntax.
b8c60bc9
CR
13164 (line 258)
13165* OLDPWD: Bash Variables. (line 618)
e8ce775d 13166* OPTARG: Bourne Shell Variables.
b8c60bc9
CR
13167 (line 36)
13168* OPTERR: Bash Variables. (line 621)
e8ce775d 13169* OPTIND: Bourne Shell Variables.
b8c60bc9
CR
13170 (line 40)
13171* OSTYPE: Bash Variables. (line 626)
e8ce775d 13172* output-meta: Readline Init File Syntax.
b8c60bc9 13173 (line 328)
7117c2d2 13174* page-completions: Readline Init File Syntax.
b8c60bc9 13175 (line 337)
e8ce775d 13176* PATH: Bourne Shell Variables.
b8c60bc9
CR
13177 (line 44)
13178* PIPESTATUS: Bash Variables. (line 629)
13179* POSIXLY_CORRECT: Bash Variables. (line 639)
13180* PPID: Bash Variables. (line 649)
13181* PROMPT_COMMAND: Bash Variables. (line 653)
13182* PROMPT_DIRTRIM: Bash Variables. (line 659)
13183* PS0: Bash Variables. (line 665)
e8ce775d 13184* PS1: Bourne Shell Variables.
b80f6443 13185 (line 53)
b8c60bc9
CR
13186* PS2: Bourne Shell Variables.
13187 (line 58)
13188* PS3: Bash Variables. (line 670)
13189* PS4: Bash Variables. (line 675)
13190* PWD: Bash Variables. (line 683)
13191* RANDOM: Bash Variables. (line 686)
13192* READLINE_ARGUMENT: Bash Variables. (line 694)
13193* READLINE_LINE: Bash Variables. (line 698)
13194* READLINE_MARK: Bash Variables. (line 702)
13195* READLINE_POINT: Bash Variables. (line 708)
13196* REPLY: Bash Variables. (line 712)
3185942a 13197* revert-all-at-newline: Readline Init File Syntax.
b8c60bc9
CR
13198 (line 350)
13199* search-ignore-case: Readline Init File Syntax.
13200 (line 357)
13201* SECONDS: Bash Variables. (line 716)
13202* SHELL: Bash Variables. (line 726)
13203* SHELLOPTS: Bash Variables. (line 731)
13204* SHLVL: Bash Variables. (line 741)
e8ce775d 13205* show-all-if-ambiguous: Readline Init File Syntax.
b8c60bc9 13206 (line 362)
b80f6443 13207* show-all-if-unmodified: Readline Init File Syntax.
b8c60bc9 13208 (line 368)
ac50fbac 13209* show-mode-in-prompt: Readline Init File Syntax.
b8c60bc9 13210 (line 377)
0001803f 13211* skip-completed-text: Readline Init File Syntax.
b8c60bc9
CR
13212 (line 383)
13213* SRANDOM: Bash Variables. (line 746)
74091dd4
CR
13214* TEXTDOMAIN: Creating Internationalized Scripts.
13215 (line 51)
13216* TEXTDOMAINDIR: Creating Internationalized Scripts.
13217 (line 51)
b8c60bc9
CR
13218* TIMEFORMAT: Bash Variables. (line 755)
13219* TMOUT: Bash Variables. (line 794)
13220* TMPDIR: Bash Variables. (line 806)
13221* UID: Bash Variables. (line 810)
a0c0a00f 13222* vi-cmd-mode-string: Readline Init File Syntax.
b8c60bc9 13223 (line 396)
a0c0a00f 13224* vi-ins-mode-string: Readline Init File Syntax.
b8c60bc9 13225 (line 407)
e8ce775d 13226* visible-stats: Readline Init File Syntax.
b8c60bc9 13227 (line 418)
ccc6cda3
JA
13228
13229\1f
3185942a 13230File: bashref.info, Node: Function Index, Next: Concept Index, Prev: Variable Index, Up: Indexes
ccc6cda3 13231
3185942a
JA
13232D.4 Function Index
13233==================
ccc6cda3 13234
b80f6443 13235\0\b[index\0\b]
ccc6cda3
JA
13236* Menu:
13237
e8ce775d 13238* abort (C-g): Miscellaneous Commands.
a0c0a00f
CR
13239 (line 10)
13240* accept-line (Newline or Return): Commands For History.
13241 (line 6)
13242* alias-expand-line (): Miscellaneous Commands.
b8c60bc9
CR
13243 (line 134)
13244* backward-char (C-b): Commands For Moving. (line 18)
13245* backward-delete-char (Rubout): Commands For Text. (line 18)
a0c0a00f 13246* backward-kill-line (C-x Rubout): Commands For Killing.
8868edaf 13247 (line 11)
a0c0a00f 13248* backward-kill-word (M-<DEL>): Commands For Killing.
8868edaf 13249 (line 28)
b8c60bc9 13250* backward-word (M-b): Commands For Moving. (line 26)
a0c0a00f 13251* beginning-of-history (M-<): Commands For History.
b8c60bc9 13252 (line 22)
a0c0a00f 13253* beginning-of-line (C-a): Commands For Moving. (line 6)
b8c60bc9 13254* bracketed-paste-begin (): Commands For Text. (line 35)
a0c0a00f 13255* call-last-kbd-macro (C-x e): Keyboard Macros. (line 13)
b8c60bc9 13256* capitalize-word (M-c): Commands For Text. (line 73)
e8ce775d 13257* character-search (C-]): Miscellaneous Commands.
b8c60bc9 13258 (line 41)
e8ce775d 13259* character-search-backward (M-C-]): Miscellaneous Commands.
b8c60bc9
CR
13260 (line 45)
13261* clear-display (M-C-l): Commands For Moving. (line 52)
13262* clear-screen (C-l): Commands For Moving. (line 57)
28ef6c31 13263* complete (<TAB>): Commands For Completion.
a0c0a00f
CR
13264 (line 6)
13265* complete-command (M-!): Commands For Completion.
b8c60bc9 13266 (line 105)
a0c0a00f 13267* complete-filename (M-/): Commands For Completion.
b8c60bc9 13268 (line 74)
a0c0a00f 13269* complete-hostname (M-@): Commands For Completion.
b8c60bc9 13270 (line 97)
a0c0a00f 13271* complete-into-braces (M-{): Commands For Completion.
b8c60bc9 13272 (line 124)
a0c0a00f 13273* complete-username (M-~): Commands For Completion.
b8c60bc9 13274 (line 81)
a0c0a00f 13275* complete-variable (M-$): Commands For Completion.
b8c60bc9 13276 (line 89)
a0c0a00f 13277* copy-backward-word (): Commands For Killing.
b8c60bc9 13278 (line 62)
a0c0a00f 13279* copy-forward-word (): Commands For Killing.
b8c60bc9 13280 (line 67)
a0c0a00f 13281* copy-region-as-kill (): Commands For Killing.
b8c60bc9 13282 (line 58)
a0c0a00f 13283* dabbrev-expand (): Commands For Completion.
b8c60bc9 13284 (line 119)
a0c0a00f 13285* delete-char (C-d): Commands For Text. (line 12)
b72432fd 13286* delete-char-or-list (): Commands For Completion.
b8c60bc9 13287 (line 68)
a0c0a00f 13288* delete-horizontal-space (): Commands For Killing.
b8c60bc9 13289 (line 50)
a0c0a00f
CR
13290* digit-argument (M-0, M-1, ... M--): Numeric Arguments. (line 6)
13291* display-shell-version (C-x C-v): Miscellaneous Commands.
b8c60bc9 13292 (line 148)
d233b485 13293* do-lowercase-version (M-A, M-B, M-X, ...): Miscellaneous Commands.
a0c0a00f 13294 (line 14)
b8c60bc9 13295* downcase-word (M-l): Commands For Text. (line 69)
e8ce775d 13296* dump-functions (): Miscellaneous Commands.
b8c60bc9 13297 (line 71)
e8ce775d 13298* dump-macros (): Miscellaneous Commands.
b8c60bc9 13299 (line 83)
e8ce775d 13300* dump-variables (): Miscellaneous Commands.
b8c60bc9 13301 (line 77)
a0c0a00f 13302* dynamic-complete-history (M-<TAB>): Commands For Completion.
b8c60bc9 13303 (line 115)
d233b485 13304* edit-and-execute-command (C-x C-e): Miscellaneous Commands.
b8c60bc9 13305 (line 143)
a0c0a00f
CR
13306* end-kbd-macro (C-x )): Keyboard Macros. (line 9)
13307* end-of-file (usually C-d): Commands For Text. (line 6)
13308* end-of-history (M->): Commands For History.
b8c60bc9
CR
13309 (line 25)
13310* end-of-line (C-e): Commands For Moving. (line 10)
e8ce775d 13311* exchange-point-and-mark (C-x C-x): Miscellaneous Commands.
d233b485 13312 (line 37)
b8c60bc9
CR
13313* execute-named-command (M-x): Miscellaneous Commands.
13314 (line 90)
13315* export-completions (): Commands For Completion.
13316 (line 44)
74091dd4 13317* fetch-history (): Commands For History.
b8c60bc9
CR
13318 (line 108)
13319* forward-backward-delete-char (): Commands For Text. (line 23)
13320* forward-char (C-f): Commands For Moving. (line 14)
a0c0a00f 13321* forward-search-history (C-s): Commands For History.
b8c60bc9
CR
13322 (line 35)
13323* forward-word (M-f): Commands For Moving. (line 22)
a0c0a00f 13324* glob-complete-word (M-g): Miscellaneous Commands.
b8c60bc9 13325 (line 103)
74091dd4 13326* glob-expand-word (C-x *): Miscellaneous Commands.
b8c60bc9 13327 (line 108)
74091dd4 13328* glob-list-expansions (C-x g): Miscellaneous Commands.
b8c60bc9 13329 (line 114)
a0c0a00f 13330* history-and-alias-expand-line (): Miscellaneous Commands.
b8c60bc9 13331 (line 137)
a0c0a00f 13332* history-expand-line (M-^): Miscellaneous Commands.
b8c60bc9 13333 (line 127)
a0c0a00f 13334* history-search-backward (): Commands For History.
b8c60bc9 13335 (line 53)
a0c0a00f 13336* history-search-forward (): Commands For History.
b8c60bc9 13337 (line 60)
d233b485 13338* history-substring-search-backward (): Commands For History.
b8c60bc9 13339 (line 67)
d233b485 13340* history-substring-search-forward (): Commands For History.
b8c60bc9 13341 (line 73)
e8ce775d 13342* insert-comment (M-#): Miscellaneous Commands.
b8c60bc9 13343 (line 59)
e8ce775d 13344* insert-completions (M-*): Commands For Completion.
b8c60bc9 13345 (line 24)
a0c0a00f 13346* insert-last-argument (M-. or M-_): Miscellaneous Commands.
b8c60bc9 13347 (line 140)
a0c0a00f
CR
13348* kill-line (C-k): Commands For Killing.
13349 (line 6)
13350* kill-region (): Commands For Killing.
b8c60bc9 13351 (line 54)
a0c0a00f 13352* kill-whole-line (): Commands For Killing.
a0c0a00f 13353 (line 19)
8868edaf
CR
13354* kill-word (M-d): Commands For Killing.
13355 (line 23)
a0c0a00f 13356* magic-space (): Miscellaneous Commands.
b8c60bc9 13357 (line 130)
cce855bc 13358* menu-complete (): Commands For Completion.
b8c60bc9 13359 (line 28)
0001803f 13360* menu-complete-backward (): Commands For Completion.
b8c60bc9 13361 (line 39)
a0c0a00f 13362* next-history (C-n): Commands For History.
b8c60bc9
CR
13363 (line 18)
13364* next-screen-line (): Commands For Moving. (line 45)
ccc6cda3 13365* non-incremental-forward-search-history (M-n): Commands For History.
b8c60bc9 13366 (line 47)
ccc6cda3 13367* non-incremental-reverse-search-history (M-p): Commands For History.
b8c60bc9 13368 (line 41)
8868edaf 13369* operate-and-get-next (C-o): Commands For History.
b8c60bc9
CR
13370 (line 101)
13371* overwrite-mode (): Commands For Text. (line 77)
a0c0a00f 13372* possible-command-completions (C-x !): Commands For Completion.
b8c60bc9 13373 (line 111)
e8ce775d 13374* possible-completions (M-?): Commands For Completion.
b8c60bc9 13375 (line 17)
a0c0a00f 13376* possible-filename-completions (C-x /): Commands For Completion.
b8c60bc9 13377 (line 77)
a0c0a00f 13378* possible-hostname-completions (C-x @): Commands For Completion.
b8c60bc9 13379 (line 101)
a0c0a00f 13380* possible-username-completions (C-x ~): Commands For Completion.
b8c60bc9 13381 (line 85)
a0c0a00f 13382* possible-variable-completions (C-x $): Commands For Completion.
b8c60bc9 13383 (line 93)
28ef6c31 13384* prefix-meta (<ESC>): Miscellaneous Commands.
d233b485 13385 (line 19)
a0c0a00f
CR
13386* previous-history (C-p): Commands For History.
13387 (line 13)
b8c60bc9 13388* previous-screen-line (): Commands For Moving. (line 38)
a0c0a00f 13389* print-last-kbd-macro (): Keyboard Macros. (line 17)
b8c60bc9 13390* quoted-insert (C-q or C-v): Commands For Text. (line 28)
e8ce775d 13391* re-read-init-file (C-x C-r): Miscellaneous Commands.
a0c0a00f 13392 (line 6)
b8c60bc9 13393* redraw-current-line (): Commands For Moving. (line 62)
a0c0a00f 13394* reverse-search-history (C-r): Commands For History.
b8c60bc9 13395 (line 29)
e8ce775d 13396* revert-line (M-r): Miscellaneous Commands.
d233b485 13397 (line 26)
b8c60bc9 13398* self-insert (a, b, A, 1, !, ...): Commands For Text. (line 32)
e8ce775d 13399* set-mark (C-@): Miscellaneous Commands.
d233b485 13400 (line 33)
a0c0a00f 13401* shell-backward-kill-word (): Commands For Killing.
8868edaf 13402 (line 37)
b8c60bc9 13403* shell-backward-word (M-C-b): Commands For Moving. (line 34)
a0c0a00f 13404* shell-expand-line (M-C-e): Miscellaneous Commands.
74091dd4 13405 (line 119)
b8c60bc9 13406* shell-forward-word (M-C-f): Commands For Moving. (line 30)
8868edaf
CR
13407* shell-kill-word (M-C-d): Commands For Killing.
13408 (line 32)
b8c60bc9 13409* shell-transpose-words (M-C-t): Commands For Text. (line 58)
0001803f 13410* skip-csi-sequence (): Miscellaneous Commands.
b8c60bc9 13411 (line 50)
74091dd4 13412* spell-correct-word (C-x s): Miscellaneous Commands.
b8c60bc9 13413 (line 97)
a0c0a00f
CR
13414* start-kbd-macro (C-x (): Keyboard Macros. (line 6)
13415* tilde-expand (M-&): Miscellaneous Commands.
d233b485 13416 (line 30)
8868edaf
CR
13417* transpose-chars (C-t): Commands For Text. (line 47)
13418* transpose-words (M-t): Commands For Text. (line 53)
28ef6c31 13419* undo (C-_ or C-x C-u): Miscellaneous Commands.
d233b485 13420 (line 23)
a0c0a00f
CR
13421* universal-argument (): Numeric Arguments. (line 10)
13422* unix-filename-rubout (): Commands For Killing.
b8c60bc9 13423 (line 45)
a0c0a00f 13424* unix-line-discard (C-u): Commands For Killing.
8868edaf 13425 (line 16)
a0c0a00f 13426* unix-word-rubout (C-w): Commands For Killing.
b8c60bc9
CR
13427 (line 41)
13428* upcase-word (M-u): Commands For Text. (line 65)
a0c0a00f 13429* yank (C-y): Commands For Killing.
b8c60bc9 13430 (line 72)
a0c0a00f 13431* yank-last-arg (M-. or M-_): Commands For History.
b8c60bc9 13432 (line 89)
a0c0a00f 13433* yank-nth-arg (M-C-y): Commands For History.
b8c60bc9 13434 (line 79)
a0c0a00f 13435* yank-pop (M-y): Commands For Killing.
b8c60bc9 13436 (line 75)
ccc6cda3
JA
13437
13438\1f
3185942a 13439File: bashref.info, Node: Concept Index, Prev: Function Index, Up: Indexes
ccc6cda3 13440
3185942a
JA
13441D.5 Concept Index
13442=================
ccc6cda3 13443
b80f6443 13444\0\b[index\0\b]
ccc6cda3
JA
13445* Menu:
13446
b80f6443
JA
13447* alias expansion: Aliases. (line 6)
13448* arithmetic evaluation: Shell Arithmetic. (line 6)
e8ce775d 13449* arithmetic expansion: Arithmetic Expansion.
b80f6443 13450 (line 6)
b8c60bc9 13451* arithmetic operators: Shell Arithmetic. (line 18)
b80f6443
JA
13452* arithmetic, shell: Shell Arithmetic. (line 6)
13453* arrays: Arrays. (line 6)
13454* background: Job Control Basics. (line 6)
13455* Bash configuration: Basic Installation. (line 6)
13456* Bash installation: Basic Installation. (line 6)
b8c60bc9
CR
13457* binary arithmetic operators: Shell Arithmetic. (line 18)
13458* bitwise arithmetic operators: Shell Arithmetic. (line 18)
e8ce775d 13459* Bourne shell: Basic Shell Features.
b80f6443
JA
13460 (line 6)
13461* brace expansion: Brace Expansion. (line 6)
b8c60bc9 13462* builtin: Definitions. (line 21)
e8ce775d 13463* command editing: Readline Bare Essentials.
b80f6443 13464 (line 6)
e8ce775d 13465* command execution: Command Search and Execution.
b80f6443 13466 (line 6)
cce855bc 13467* command expansion: Simple Command Expansion.
b80f6443 13468 (line 6)
e8ce775d 13469* command history: Bash History Facilities.
b80f6443 13470 (line 6)
e8ce775d 13471* command search: Command Search and Execution.
b80f6443 13472 (line 6)
e8ce775d 13473* command substitution: Command Substitution.
b80f6443 13474 (line 6)
3185942a 13475* command timing: Pipelines. (line 9)
b80f6443 13476* commands, compound: Compound Commands. (line 6)
e8ce775d 13477* commands, conditional: Conditional Constructs.
b80f6443
JA
13478 (line 6)
13479* commands, grouping: Command Grouping. (line 6)
13480* commands, lists: Lists. (line 6)
13481* commands, looping: Looping Constructs. (line 6)
13482* commands, pipelines: Pipelines. (line 6)
13483* commands, shell: Shell Commands. (line 6)
13484* commands, simple: Simple Commands. (line 6)
13485* comments, shell: Comments. (line 6)
8868edaf
CR
13486* Compatibility Level: Shell Compatibility Mode.
13487 (line 6)
13488* Compatibility Mode: Shell Compatibility Mode.
13489 (line 6)
bb70624e 13490* completion builtins: Programmable Completion Builtins.
b80f6443 13491 (line 6)
b8c60bc9 13492* conditional arithmetic operator: Shell Arithmetic. (line 18)
b80f6443 13493* configuration: Basic Installation. (line 6)
b8c60bc9 13494* control operator: Definitions. (line 25)
3185942a 13495* coprocess: Coprocesses. (line 6)
b80f6443 13496* directory stack: The Directory Stack. (line 6)
b8c60bc9 13497* dollar-single quote quoting: ANSI-C Quoting. (line 6)
e8ce775d 13498* editing command lines: Readline Bare Essentials.
b80f6443
JA
13499 (line 6)
13500* environment: Environment. (line 6)
13501* evaluation, arithmetic: Shell Arithmetic. (line 6)
13502* event designators: Event Designators. (line 6)
cce855bc 13503* execution environment: Command Execution Environment.
b80f6443 13504 (line 6)
b8c60bc9 13505* exit status: Definitions. (line 30)
a0c0a00f 13506* exit status <1>: Exit Status. (line 6)
b80f6443 13507* expansion: Shell Expansions. (line 6)
e8ce775d 13508* expansion, arithmetic: Arithmetic Expansion.
b80f6443
JA
13509 (line 6)
13510* expansion, brace: Brace Expansion. (line 6)
13511* expansion, filename: Filename Expansion. (line 9)
e8ce775d 13512* expansion, parameter: Shell Parameter Expansion.
b80f6443
JA
13513 (line 6)
13514* expansion, pathname: Filename Expansion. (line 9)
13515* expansion, tilde: Tilde Expansion. (line 6)
13516* expressions, arithmetic: Shell Arithmetic. (line 6)
e8ce775d 13517* expressions, conditional: Bash Conditional Expressions.
b80f6443 13518 (line 6)
b8c60bc9
CR
13519* field: Definitions. (line 34)
13520* filename: Definitions. (line 39)
b80f6443
JA
13521* filename expansion: Filename Expansion. (line 9)
13522* foreground: Job Control Basics. (line 6)
13523* functions, shell: Shell Functions. (line 6)
cce855bc 13524* history builtins: Bash History Builtins.
b80f6443 13525 (line 6)
b8c60bc9 13526* history events: Event Designators. (line 10)
b80f6443 13527* history expansion: History Interaction. (line 6)
e8ce775d 13528* history list: Bash History Facilities.
b80f6443 13529 (line 6)
ac50fbac 13530* History, how to use: A Programmable Completion Example.
d233b485 13531 (line 113)
b8c60bc9 13532* identifier: Definitions. (line 55)
b80f6443
JA
13533* initialization file, readline: Readline Init File. (line 6)
13534* installation: Basic Installation. (line 6)
e8ce775d 13535* interaction, readline: Readline Interaction.
b80f6443 13536 (line 6)
b8c60bc9 13537* interactive shell: Invoking Bash. (line 137)
b80f6443 13538* interactive shell <1>: Interactive Shells. (line 6)
b80f6443 13539* internationalization: Locale Translation. (line 6)
74091dd4
CR
13540* internationalized scripts: Creating Internationalized Scripts.
13541 (line 3)
b8c60bc9
CR
13542* job: Definitions. (line 42)
13543* job control: Definitions. (line 46)
a0c0a00f 13544* job control <1>: Job Control Basics. (line 6)
e8ce775d 13545* kill ring: Readline Killing Commands.
a0c0a00f 13546 (line 18)
e8ce775d 13547* killing text: Readline Killing Commands.
b80f6443
JA
13548 (line 6)
13549* localization: Locale Translation. (line 6)
b8c60bc9 13550* login shell: Invoking Bash. (line 134)
b80f6443 13551* matching, pattern: Pattern Matching. (line 6)
b8c60bc9
CR
13552* metacharacter: Definitions. (line 50)
13553* name: Definitions. (line 55)
b80f6443 13554* native languages: Locale Translation. (line 6)
e8ce775d 13555* notation, readline: Readline Bare Essentials.
b80f6443 13556 (line 6)
b8c60bc9 13557* operator, shell: Definitions. (line 61)
e8ce775d 13558* parameter expansion: Shell Parameter Expansion.
b80f6443
JA
13559 (line 6)
13560* parameters: Shell Parameters. (line 6)
e8ce775d 13561* parameters, positional: Positional Parameters.
b80f6443
JA
13562 (line 6)
13563* parameters, special: Special Parameters. (line 6)
13564* pathname expansion: Filename Expansion. (line 9)
13565* pattern matching: Pattern Matching. (line 6)
13566* pipeline: Pipelines. (line 6)
13567* POSIX: Definitions. (line 9)
b8c60bc9
CR
13568* POSIX description: Bash POSIX Mode. (line 9)
13569* POSIX Mode: Bash POSIX Mode. (line 48)
13570* process group: Definitions. (line 66)
13571* process group ID: Definitions. (line 70)
e8ce775d 13572* process substitution: Process Substitution.
b80f6443 13573 (line 6)
bb70624e 13574* programmable completion: Programmable Completion.
b80f6443 13575 (line 6)
ac50fbac
CR
13576* prompting: Controlling the Prompt.
13577 (line 6)
b80f6443
JA
13578* quoting: Quoting. (line 6)
13579* quoting, ANSI: ANSI-C Quoting. (line 6)
bb70624e 13580* Readline, how to use: Job Control Variables.
a0c0a00f 13581 (line 23)
b80f6443 13582* redirection: Redirections. (line 6)
b8c60bc9 13583* reserved word: Definitions. (line 74)
8868edaf 13584* reserved words: Reserved Words. (line 6)
e8ce775d 13585* restricted shell: The Restricted Shell.
b80f6443 13586 (line 6)
b8c60bc9 13587* return status: Definitions. (line 79)
b80f6443
JA
13588* shell arithmetic: Shell Arithmetic. (line 6)
13589* shell function: Shell Functions. (line 6)
13590* shell script: Shell Scripts. (line 6)
13591* shell variable: Shell Parameters. (line 6)
13592* shell, interactive: Interactive Shells. (line 6)
b8c60bc9 13593* signal: Definitions. (line 82)
b80f6443 13594* signal handling: Signals. (line 6)
b8c60bc9 13595* special builtin: Definitions. (line 86)
a0c0a00f 13596* special builtin <1>: Special Builtins. (line 6)
b80f6443 13597* startup files: Bash Startup Files. (line 6)
74091dd4
CR
13598* string translations: Creating Internationalized Scripts.
13599 (line 3)
b80f6443
JA
13600* suspending jobs: Job Control Basics. (line 6)
13601* tilde expansion: Tilde Expansion. (line 6)
b8c60bc9 13602* token: Definitions. (line 90)
b80f6443 13603* translation, native languages: Locale Translation. (line 6)
b8c60bc9 13604* unary arithmetic operators: Shell Arithmetic. (line 18)
b80f6443 13605* variable, shell: Shell Parameters. (line 6)
28ef6c31 13606* variables, readline: Readline Init File Syntax.
95732b49 13607 (line 37)
b8c60bc9 13608* word: Definitions. (line 94)
b80f6443 13609* word splitting: Word Splitting. (line 6)
e8ce775d 13610* yanking text: Readline Killing Commands.
b80f6443 13611 (line 6)
ccc6cda3 13612
ccc6cda3
JA
13613\1f
13614Tag Table:
b8c60bc9
CR
13615Node: Top\7f894
13616Node: Introduction\7f2828
13617Node: What is Bash?\7f3044
13618Node: What is a shell?\7f4180
13619Node: Definitions\7f6793
13620Node: Basic Shell Features\7f10123
13621Node: Shell Syntax\7f11350
13622Node: Shell Operation\7f12380
13623Node: Quoting\7f13674
13624Node: Escape Character\7f15015
13625Node: Single Quotes\7f15553
13626Node: Double Quotes\7f15905
13627Node: ANSI-C Quoting\7f17253
13628Node: Locale Translation\7f18650
13629Node: Creating Internationalized Scripts\7f20056
13630Node: Comments\7f24257
13631Node: Shell Commands\7f25027
13632Node: Reserved Words\7f25969
13633Node: Simple Commands\7f26837
13634Node: Pipelines\7f27502
13635Node: Lists\7f30761
13636Node: Compound Commands\7f32636
13637Node: Looping Constructs\7f33648
13638Node: Conditional Constructs\7f36200
13639Node: Command Grouping\7f51273
13640Node: Coprocesses\7f52768
13641Node: GNU Parallel\7f55457
13642Node: Shell Functions\7f56378
13643Node: Shell Parameters\7f64829
13644Node: Positional Parameters\7f69733
13645Node: Special Parameters\7f70826
13646Node: Shell Expansions\7f74290
13647Node: Brace Expansion\7f76482
13648Node: Tilde Expansion\7f79821
13649Node: Shell Parameter Expansion\7f82779
13650Node: Command Substitution\7f103425
13651Node: Arithmetic Expansion\7f106957
13652Node: Process Substitution\7f108136
13653Node: Word Splitting\7f109247
13654Node: Filename Expansion\7f111694
13655Node: Pattern Matching\7f114921
13656Node: Quote Removal\7f120647
13657Node: Redirections\7f120954
13658Node: Executing Commands\7f131220
13659Node: Simple Command Expansion\7f131890
13660Node: Command Search and Execution\7f134001
13661Node: Command Execution Environment\7f136448
13662Node: Environment\7f139899
13663Node: Exit Status\7f141805
13664Node: Signals\7f143866
13665Node: Shell Scripts\7f148798
13666Node: Shell Builtin Commands\7f152099
13667Node: Bourne Shell Builtins\7f154213
13668Node: Bash Builtins\7f180863
13669Node: Modifying Shell Behavior\7f217790
13670Node: The Set Builtin\7f218135
13671Node: The Shopt Builtin\7f230132
13672Node: Special Builtins\7f247187
13673Node: Shell Variables\7f248179
13674Node: Bourne Shell Variables\7f248616
13675Node: Bash Variables\7f251127
13676Node: Bash Features\7f290254
13677Node: Invoking Bash\7f291271
13678Node: Bash Startup Files\7f297858
13679Node: Interactive Shells\7f303103
13680Node: What is an Interactive Shell?\7f303514
13681Node: Is this Shell Interactive?\7f304179
13682Node: Interactive Shell Behavior\7f305006
13683Node: Bash Conditional Expressions\7f308770
13684Node: Shell Arithmetic\7f314190
13685Node: Aliases\7f317522
13686Node: Arrays\7f320659
13687Node: The Directory Stack\7f328250
13688Node: Directory Stack Builtins\7f329050
13689Node: Controlling the Prompt\7f333498
13690Node: The Restricted Shell\7f336386
13691Node: Bash POSIX Mode\7f339271
13692Node: Shell Compatibility Mode\7f358220
13693Node: Job Control\7f367230
13694Node: Job Control Basics\7f367690
13695Node: Job Control Builtins\7f374061
13696Node: Job Control Variables\7f380746
13697Node: Command Line Editing\7f381980
13698Node: Introduction and Notation\7f383686
13699Node: Readline Interaction\7f386041
13700Node: Readline Bare Essentials\7f387232
13701Node: Readline Movement Commands\7f389043
13702Node: Readline Killing Commands\7f390042
13703Node: Readline Arguments\7f392068
13704Node: Searching\7f393128
13705Node: Readline Init File\7f395374
13706Node: Readline Init File Syntax\7f396680
13707Node: Conditional Init Constructs\7f423508
13708Node: Sample Init File\7f427896
13709Node: Bindable Readline Commands\7f431019
13710Node: Commands For Moving\7f432560
13711Node: Commands For History\7f435027
13712Node: Commands For Text\7f440420
13713Node: Commands For Killing\7f444548
13714Node: Numeric Arguments\7f447339
13715Node: Commands For Completion\7f448494
13716Node: Keyboard Macros\7f454193
13717Node: Miscellaneous Commands\7f454897
13718Node: Readline vi Mode\7f461467
13719Node: Programmable Completion\7f462447
13720Node: Programmable Completion Builtins\7f471187
13721Node: A Programmable Completion Example\7f482927
13722Node: Using History Interactively\7f488275
13723Node: Bash History Facilities\7f488959
13724Node: Bash History Builtins\7f492697
13725Node: History Interaction\7f499171
13726Node: Event Designators\7f504124
13727Node: Word Designators\7f505705
13728Node: Modifiers\7f508100
13729Node: Installing Bash\7f510040
13730Node: Basic Installation\7f511159
13731Node: Compilers and Options\7f515038
13732Node: Compiling For Multiple Architectures\7f515791
13733Node: Installation Names\7f517547
13734Node: Specifying the System Type\7f519784
13735Node: Sharing Defaults\7f520533
13736Node: Operation Controls\7f521250
13737Node: Optional Features\7f522272
13738Node: Reporting Bugs\7f534655
13739Node: Major Differences From The Bourne Shell\7f536015
13740Node: GNU Free Documentation License\7f557444
13741Node: Indexes\7f582624
13742Node: Builtin Index\7f583078
13743Node: Reserved Word Index\7f590179
13744Node: Variable Index\7f592627
13745Node: Function Index\7f610043
13746Node: Concept Index\7f624041
ccc6cda3
JA
13747\1f
13748End Tag Table
8868edaf
CR
13749
13750\1f
13751Local Variables:
13752coding: utf-8
13753End: