1 .de SE \" start example
14 Bash \- The GNU shell*
17 Case Western Reserve University
20 *An earlier version of this article appeared in The Linux Journal.
26 is the shell, or command language interpreter,
27 that will appear in the GNU operating system.
28 The name is an acronym for
29 the \*QBourne-Again SHell\*U, a pun on Steve Bourne, the author
30 of the direct ancestor of the current
33 which appeared in the Seventh Edition Bell Labs Research version
36 Bash is an \fBsh\fP\-compatible shell that incorporates useful
37 features from the Korn shell (\fBksh\fP) and the C shell (\fBcsh\fP),
38 described later in this article. It is ultimately intended to be a
39 conformant implementation of the IEEE POSIX Shell and Utilities
40 specification (IEEE Working Group 1003.2). It offers functional
41 improvements over sh for both interactive and programming use.
43 While the GNU operating system will most likely include a version
44 of the Berkeley shell csh, Bash will be the default shell.
45 Like other GNU software, Bash is quite portable. It currently runs
46 on nearly every version of
48 and a few other operating systems \- an independently-supported
49 port exists for OS/2, and there are rumors of ports to DOS and
50 Windows NT. Ports to \s-1UNIX\s+1-like systems such as QNX and Minix
51 are part of the distribution.
53 The original author of Bash
54 was Brian Fox, an employee of the Free Software Foundation. The
55 current developer and maintainer is Chet Ramey, a volunteer who
56 works at Case Western Reserve University.
61 is a name originally coined by Richard Stallman for a family of open
62 system standards based on \s-1UNIX\s+1. There are a number of aspects of \s-1UNIX\s+1
63 under consideration for standardization, from the basic system services
64 at the system call and C library level to applications and tools to system
65 administration and management. Each area of standardization is
66 assigned to a working group in the 1003 series.
68 The POSIX Shell and Utilities standard has been developed by IEEE Working
69 Group 1003.2 (POSIX.2).\(dd
71 \(ddIEEE, \fIIEEE Standard for Information Technology -- Portable
72 Operating System Interface (POSIX) Part 2: Shell and Utilities\fP,
75 It concentrates on the command interpreter
76 interface and utility programs
77 commonly executed from the command line or by other programs.
78 An initial version of the standard has been
79 approved and published by the IEEE, and work is currently underway to
81 There are four primary areas of work in the 1003.2 standard:
83 Aspects of the shell's syntax and command language.
84 A number of special builtins such as
88 are being specified as part of the shell, since their
89 functionality usually cannot be implemented by a separate executable;
91 A set of utilities to be called by shell scripts and applications.
92 Examples are programs like
97 Utilities commonly implemented as shell builtins
98 are described in this section, such as
102 An expansion of this section's scope, termed the User Portability
103 Extension, or UPE, has standardized interactive programs such as
108 A group of functional interfaces to services provided by the
109 shell, such as the traditional \f(CRsystem()\fP
110 C library function. There are functions to perform shell word
111 expansions, perform filename expansion (\fIglobbing\fP), obtain values
112 of POSIX.2 system configuration variables, retrieve values of
113 environment variables (\f(CRgetenv()\fP\^), and other services;
115 A suite of \*Qdevelopment\*U utilities such as
117 (the POSIX.2 version of \fIcc\fP),
121 Bash is concerned with the aspects of the shell's behavior
122 defined by POSIX.2. The shell command language has of
123 course been standardized, including the basic flow control
124 and program execution constructs, I/O redirection and
125 pipelining, argument handling, variable expansion, and quoting.
128 builtins, which must be implemented as part of the shell to
129 provide the desired functionality, are specified as being
130 part of the shell; examples of these are
134 Other utilities appear in the sections of POSIX.2 not
135 devoted to the shell which are commonly (and in some
136 cases must be) implemented as builtin commands, such as
140 POSIX.2 also specifies aspects of the shell's
141 interactive behavior as part of
142 the UPE, including job control and command line editing.
143 Interestingly enough, only \fIvi\fP-style line editing commands
144 have been standardized; \fIemacs\fP editing commands were left
145 out due to objections.
147 While POSIX.2 includes much of what the shell has traditionally
148 provided, some important things have been omitted as being
149 \*Qbeyond its scope.\*U There is, for instance, no mention of
150 a difference between a
152 shell and any other interactive shell (since POSIX.2 does not
153 specify a login program). No fixed startup files are defined,
154 either \- the standard does not mention
159 Since the Bourne shell
160 provides Bash with most of its philosophical underpinnings,
161 Bash inherits most of its features and functionality from sh.
162 Bash implements all of the traditional sh flow
163 control constructs (\fIfor\fP, \fIif\fP, \fIwhile\fP, etc.).
164 All of the Bourne shell builtins, including those not specified in
165 the POSIX.2 standard, appear in Bash. Shell \fIfunctions\fP,
166 introduced in the SVR2 version of the Bourne shell,
167 are similar to shell scripts, but are defined using a special
168 syntax and are executed in the same process as the calling shell.
169 Bash has shell functions
170 which behave in a fashion upward-compatible with sh functions.
171 There are certain shell
172 variables that Bash interprets in the same way as sh, such as
177 Bash implements essentially the same grammar, parameter and
178 variable expansion semantics, redirection, and quoting as the
179 Bourne shell. Where differences appear between the POSIX.2
180 standard and traditional sh behavior, Bash follows POSIX.
182 The Korn Shell (\fBksh\fP) is a descendent of the Bourne shell written
183 at AT&T Bell Laboratories by David Korn\(dg. It provides a number of
184 useful features that POSIX and Bash have adopted. Many of the
185 interactive facilities in POSIX.2 have their roots in the ksh:
186 for example, the POSIX and ksh job control facilities are nearly
187 identical. Bash includes features from the Korn Shell for both
188 interactive use and shell programming. For programming, Bash provides
196 the ability to remove substrings from variables based on patterns,
197 and shell arithmetic.
199 \(dgMorris Bolsky and David Korn, \fIThe KornShell Command and
200 Programming Language\fP, Prentice Hall, 1989.
203 expands to a random number each time it is referenced; assigning a
206 seeds the random number generator.
208 is the default variable used by the
210 builtin when no variable names are supplied as arguments.
213 builtin is used to define variables and give them attributes
214 such as \fBreadonly\fP.
215 Bash arithmetic allows the evaluation of an expression and the
216 substitution of the result. Shell variables may be used as operands,
217 and the result of an expression may be assigned to a variable.
218 Nearly all of the operators from the C language are available,
219 with the same precedence rules:
221 $ echo $((3 + 5 * 32))
225 For interactive use, Bash implements ksh-style aliases and builtins
228 (discussed below) and
230 Bash aliases allow a string to be substituted for a command name.
231 They can be used to create a mnemonic for a \s-1UNIX\s+1 command
232 name (\f(CRalias del=rm\fP), to expand a single word to a complex command
233 (\f(CRalias news='xterm -g 80x45 -title trn -e trn -e -S1 -N &'\fP), or to
234 ensure that a command is invoked with a basic set of options
235 (\f(CRalias ls="/bin/ls -F"\fP).
237 The C shell (\fBcsh\fP)\(dg, originally written by Bill Joy while at
238 Berkeley, is widely used and quite popular for its interactive
239 facilities. Bash includes a csh-compatible history expansion
240 mechanism (\*Q! history\*U), brace expansion, access to a stack
241 of directories via the
246 builtins, and tilde expansion, to generate users' home directories.
247 Tilde expansion has also been adopted by both the Korn Shell and
250 \(dgBill Joy, An Introduction to the C Shell, \fIUNIX User's Supplementary
251 Documents\fP, University of California at Berkeley, 1986.
254 There were certain areas in which POSIX.2 felt standardization
255 was necessary, but no existing implementation provided the proper
256 behavior. The working group invented and standardized functionality
257 in these areas, which Bash implements. The
259 builtin was invented so that shell functions could be written to
260 replace builtins; it makes the capabilities of the builtin
261 available to the function. The reserved word \*Q!\*U was added
262 to negate the return value of a command or pipeline; it was nearly
263 impossible to express \*Qif not x\*U cleanly using the sh language.
264 There exist multiple incompatible implementations of the
266 builtin, which tests files for type and other attributes and performs
267 arithmetic and string comparisons.
268 POSIX considered none of these correct, so the standard
269 behavior was specified in terms of the number of arguments to the
270 command. POSIX.2 dictates exactly what will happen when four or
271 fewer arguments are given to
273 and leaves the behavior undefined when more arguments are supplied.
274 Bash uses the POSIX.2 algorithm, which was conceived by David Korn.
276 Features not in the Bourne Shell
278 There are a number of minor differences between Bash and the
279 version of sh present on most other versions of \s-1UNIX\s+1. The majority
280 of these are due to the POSIX standard, but some are the result of
281 Bash adopting features from other shells. For instance, Bash
282 includes the new \*Q!\*U reserved word, the
284 builtin, the ability of the
286 builtin to correctly return a line ending with a backslash, symbolic
289 builtin, variable substring removal, a way to get the length of a variable,
290 and the new algorithm for the
292 builtin from the POSIX.2 standard, none of which appear in sh.
294 Bash also implements the \*Q$(...)\*U command substitution syntax,
295 which supersedes the sh `...` construct.
296 The \*Q$(...)\*U construct expands to the output of the command
298 parentheses, with trailing newlines removed. The sh syntax is
299 accepted for backwards compatibility, but the \*Q$(...)\*U form
300 is preferred because its quoting rules are much simpler and it
303 The Bourne shell does not provide such features as brace expansion,
305 to define a variable and a function with the same name, local variables
306 in shell functions, the ability to enable and disable individual
307 builtins or write a function to replace a builtin, or a means to
308 export a shell function to a child process.
311 a long-standing shell security hole by not using the
313 variable to split each word read by the shell, but splitting only
314 the results of expansion (ksh and the 4.4 BSD sh have fixed this
315 as well). Useful behavior such as a means to abort
316 execution of a script read with the \*Q.\*U command using the
317 \fBreturn\fP builtin or automatically
318 exporting variables in the shell's environment to children is also
319 not present in the Bourne shell. Bash provides a much more powerful
320 environment for both interactive use and programming.
322 Bash-specific Features
324 This section details a few of the features which make Bash unique.
325 Most of them provide improved interactive use, but a few programming
326 improvements are present as well. Full descriptions of these
327 features can be found in the Bash documentation.
331 Bash executes startup files differently than other shells. The Bash
332 behavior is a compromise between the csh principle of startup files
333 with fixed names executed for each shell and the sh
334 \*Qminimalist\*U behavior. An interactive instance of Bash started
335 as a login shell reads and executes
337 (the file .bash_profile in the user's home directory), if it exists.
338 An interactive non-login shell reads and executes
340 A non-interactive shell (one begun to execute a shell script, for
341 example) reads no fixed startup file, but uses the value of the variable
343 if set, as the name of a startup file. The ksh practice of reading
345 for every shell, with the accompanying difficulty of defining the
346 proper variables and functions for interactive and non-interactive
347 shells or having the file read only for interactive shells, was
348 considered too complex. Ease of use won out here. Interestingly,
349 the next release of ksh will change to reading
351 only for interactive shells.
355 There are a few builtins which are new or have been extended in Bash.
358 builtin allows builtin commands to be turned on and off arbitrarily.
359 To use the version of
361 found in a user's search path rather than the Bash builtin,
362 \f(CRenable -n echo\fP suffices. The
365 quick synopses of the shell facilities without requiring
366 access to a manual page.
370 in that it bypasses shell functions and directly executes builtin
371 commands. Access to a csh-style stack of directories is provided
381 insert and remove directories from the stack, respectively, and
383 lists the stack contents. On systems that allow fine-grained control
386 builtin can be used to tune these settings.
388 allows a user to control,
389 among other things, whether core dumps are to be generated,
390 how much memory the shell or a child process is allowed to allocate,
391 and how large a file created by a child process can grow. The
393 command will stop the shell process when job control is active; most
394 other shells do not allow themselves to be stopped like that.
400 shows what will happen when a word is typed as a command:
403 export is a shell builtin
412 builtin cd ${1+"$@"} && xtitle $HOST: $PWD
417 modes tell what a command word is (reserved word, alias, function, builtin,
418 or file) or which version of a command will be executed based on
419 a user's search path. Some of this functionality has been adopted
420 by POSIX.2 and folded into the
424 Editing and Completion
426 One area in which Bash shines is command line editing. Bash uses the
428 library to read and edit lines when interactive. Readline is a
429 powerful and flexible input facility that a user can configure to
430 individual tastes. It allows lines to be edited using either emacs
431 or vi commands, where those commands are appropriate. The full
432 capability of emacs is not present \- there is no way to execute
433 a named command with M-x, for instance \- but the existing commands
434 are more than adequate. The vi mode is compliant with
435 the command line editing standardized by POSIX.2.
437 Readline is fully customizable. In addition to the basic commands
438 and key bindings, the library allows users to define additional
439 key bindings using a startup file. The
441 file, which defaults to the file
443 is read each time readline initializes, permitting users to
444 maintain a consistent interface across a set of programs. Readline
445 includes an extensible interface, so each program using the
446 library can add its own bindable commands and program-specific
447 key bindings. Bash uses this facility to add bindings
448 that perform history expansion or shell word expansions on the current
451 Readline interprets a number of
452 variables which further tune its behavior. Variables
453 exist to control whether or not eight-bit characters are directly
454 read as input or converted to meta-prefixed key sequences (a
455 meta-prefixed key sequence consists of the character with the
456 eighth bit zeroed, preceded by the
458 character, usually escape, which selects an alternate keymap), to
459 decide whether to output characters with the eighth bit set
460 directly or as a meta-prefixed key sequence, whether or not to
461 wrap to a new screen line when a line being edited is longer than
462 the screen width, the keymap to which subsequent key bindings should
463 apply, or even what happens when readline wants to
464 ring the terminal's bell. All of these variables can be set in
467 The startup file understands a set of C
468 preprocessor-like conditional constructs which allow variables or
469 key bindings to be assigned based on the application using readline,
470 the terminal currently being used, or the editing mode. Users can
471 add program-specific bindings to make their lives easier: I have
472 bindings that let me edit the value of
474 and double-quote the current or previous word:
476 # Macros that are convenient for shell interaction
479 "\eC-xp": "PATH=${PATH}\ee\eC-e\eC-a\eef\eC-f"
480 # prepare to type a quoted word -- insert open and close double
481 # quotes and move to just after the open quote
482 "\eC-x\e"": "\e"\e"\eC-b"
483 # Quote the current or previous word
484 "\eC-xq": "\eeb\e"\eef\e""
489 command to re-read the file, so users can edit the file, change
490 some bindings, and begin to use them almost immediately.
494 builtin for more dyamic control of readline than the startup file
497 is used in several ways. In
499 mode, it can display the current key bindings, list all the
500 readline editing directives available for binding, list which keys
501 invoke a given directive, or output the current set of key
502 bindings in a format that can be incorporated directly into an inputrc
505 mode, it reads a series of key bindings directly from a file and
506 passes them to readline. In its most common usage,
508 takes a single string and passes it directly to readline, which
509 interprets the line as if it had just been read from the inputrc file.
510 Both key bindings and variable assignments may appear in the
514 The readline library also provides an interface for \fIword completion\fP.
517 character (usually TAB) is typed, readline looks at the word currently
518 being entered and computes the set of filenames of which the current
519 word is a valid prefix.
520 If there is only one possible completion, the
521 rest of the characters are inserted directly, otherwise the
522 common prefix of the set of filenames is added to the current word.
523 A second TAB character entered immediately after a non-unique
524 completion causes readline to list the possible completions; there is
525 an option to have the list displayed immediately.
526 Readline provides hooks so that applications can provide specific types
527 of completion before the default filename completion is attempted.
528 This is quite flexible, though it is not completely user-programmable.
529 Bash, for example, can complete filenames, command names (including aliases,
530 builtins, shell reserved words, shell functions, and executables found
531 in the file system), shell variables, usernames, and hostnames. It
532 uses a set of heuristics that, while not perfect, is generally quite
533 good at determining what type of completion to attempt.
537 Access to the list of commands previously entered (the \fIcommand history\fP)
538 is provided jointly by Bash and the readline library. Bash provides
539 variables (\fB$HISTFILE\fP, \fB$HISTSIZE\fP, and \fB$HISTCONTROL\fP)
544 builtins to manipulate the history list.
547 specifes the file where Bash writes the command history on exit and
550 is used to limit the number of commands saved in the history.
552 provides a crude form of control over which commands are saved on
553 the history list: a value of
555 means to not save commands which begin with a space; a value of
557 means to not save commands identical to the last command saved.
558 \fB$HISTCONTROL\fP was named \fB$history_control\fP in earlier
559 versions of Bash; the old name is still accepted for backwards
562 command can read or write files containing the history list
563 and display the current list contents. The
565 builtin, adopted from POSIX.2 and the Korn Shell, allows display
566 and re-execution, with optional editing,
567 of commands from the history list. The readline
568 library offers a set of commands to search the history list for
569 a portion of the current input line or a string typed by the user.
572 library, generally incorporated directly into the readline library,
573 implements a facility for history recall, expansion, and re-execution
574 of previous commands very similar to csh
575 (\*Qbang history\*U, so called because the exclamation point
576 introduces a history substitution):
581 echo a b c d e f g h i
591 The command history is only
592 saved when the shell is interactive, so it is not available for use
597 There are a number of convenience variables that Bash interprets
598 to make life easier. These include
600 which is a set of filename suffixes identifying files to exclude when
601 completing filenames;
603 which is automatically set to a string describing the type of
604 hardware on which Bash is currently executing;
605 .B command_oriented_history ,
606 which directs Bash to save all lines of a multiple-line
607 command such as a \fIwhile\fP or \fIfor\fP loop in a single
608 history entry, allowing easy re-editing; and
610 whose value indicates the number of consecutive EOF characters that
611 an interactive shell will read before exiting \- an easy way to keep
612 yourself from being logged out accidentally. The
614 variable alters the way the shell treats simple command names:
615 if job control is active, and this variable is set, single-word
616 simple commands without redirections cause the shell to first
617 look for and restart a suspended job with that name before
618 starting a new process.
622 Since sh offers no convenient way to generate arbitrary strings that
623 share a common prefix or suffix (filename expansion requires that
624 the filenames exist), Bash implements \fIbrace expansion\fP, a
625 capability picked up from csh.
626 Brace expansion is similar to filename expansion, but the strings
627 generated need not correspond to existing files. A brace expression
628 consists of an optional
630 followed by a pair of braces enclosing a series of comma-separated
631 strings, and an optional
633 The preamble is prepended to each string within the braces, and the
634 postamble is then appended to each resulting string:
640 As this example demonstrates, the results of brace expansion are not
641 sorted, as they are by filename expansion.
645 On systems that can support it, Bash provides a facility known as
646 \fIprocess substitution\fP. Process substitution is similar to command
647 substitution in that its specification includes a command to execute,
648 but the shell does not collect the command's output and insert it into
649 the command line. Rather, Bash opens a pipe to the command, which
650 is run in the background. The shell uses named pipes (FIFOs) or the
652 method of naming open files to expand the process
653 substitution to a filename which connects to the pipe when opened.
654 This filename becomes the result of the expansion. Process substitution
655 can be used to compare the outputs of two different versions of an
656 application as part of a regression test:
658 $ cmp <(old_prog) <(new_prog)
663 One of the more popular interactive features that Bash provides is
664 the ability to customize the prompt. Both
668 the primary and secondary prompts, are expanded before being
669 displayed. Parameter and variable expansion is performed when
670 the prompt string is expanded, so any shell variable can be
671 put into the prompt (e.g.,
673 which indicates how deeply the current shell is nested).
674 Bash specially interprets characters in the prompt string
675 preceded by a backslash. Some of these backslash escapes are
677 the current time, the date, the current working directory,
678 the username, and the command number or history number of the command
679 being entered. There is even a backslash escape to cause the shell
680 to change its prompt when running as root after an \fIsu\fP.
681 Before printing each primary prompt, Bash expands the variable
683 and, if it has a value, executes the expanded value as a command,
684 allowing additional prompt customization. For example, this assignment
685 causes the current user, the current host, the time, the last
686 component of the current working directory, the level of shell
687 nesting, and the history number of the current command to be embedded
688 into the primary prompt:
690 $ PS1='\eu@\eh [\et] \eW($SHLVL:\e!)\e$ '
691 chet@odin [21:03:44] documentation(2:636)$ cd ..
692 chet@odin [21:03:54] src(2:637)$
695 The string being assigned is surrounded by single quotes so that if
696 it is exported, the value of
698 will be updated by a child shell:
700 chet@odin [21:17:35] src(2:638)$ export PS1
701 chet@odin [21:17:40] src(2:639)$ bash
702 chet@odin [21:17:46] src(3:696)$
705 The \fP\e$\fP escape is displayed
706 as \*Q\fB$\fP\*U when running as a normal user, but as \*Q\fB#\fP\*U when
711 Since Berkeley introduced symbolic links in 4.2 BSD, one of their most
712 annoying properties has been the \*Qwarping\*U to a completely
713 different area of the file system when using
715 and the resultant non-intuitive behavior of \*Q\fBcd ..\fP\*U.
716 The \s-1UNIX\s+1 kernel treats symbolic links
718 When the kernel is translating a pathname
719 in which one component is a symbolic link, it replaces all or part
720 of the pathname while processing the link. If the contents of the symbolic
721 link begin with a slash, the kernel replaces the
722 pathname entirely; if not, the link contents replace
723 the current component. In either case, the symbolic link
724 is visible. If the link value is an absolute pathname,
725 the user finds himself in a completely different part of the file
730 view of the file system. In this default mode, command and filename
731 completion and builtin commands such as
735 which change the current working directory transparently follow
736 symbolic links as if they were directories.
739 variable, which holds the shell's idea of the current working directory,
740 depends on the path used to reach the directory rather than its
741 physical location in the local file system hierarchy. For example:
749 /net/share/sun4/local/bin
754 /net/share/sun4/local
762 One problem with this, of
763 course, arises when programs that do not understand the shell's logical
764 notion of the file system interpret \*Q..\*U differently. This generally
765 happens when Bash completes filenames containing \*Q..\*U according to a
766 logical hierarchy which does not correspond to their physical location.
767 For users who find this troublesome, a corresponding
769 view of the file system is available:
776 /net/share/sun4/local/bin
781 One of the most significant improvements in version 1.13 of Bash was the
782 change to \*Qeight-bit cleanliness\*U. Previous versions used the
783 eighth bit of characters to mark whether or not they were
784 quoted when performing word expansions. While this did not affect
785 the majority of users, most of whom used only seven-bit ASCII characters,
786 some found it confining. Beginning with version 1.13, Bash
787 implemented a different quoting mechanism that did not alter the
788 eighth bit of characters. This allowed Bash
789 to manipulate files with \*Qodd\*U characters in their names, but
790 did nothing to help users enter those names, so
791 version 1.13 introduced changes to readline that
792 made it eight-bit clean as well. Options exist that force readline to
793 attach no special significance to characters with the eighth bit set
794 (the default behavior is to convert these characters to meta-prefixed
795 key sequences) and to output these characters without conversion to
796 meta-prefixed sequences. These changes, along with the expansion of
797 keymaps to a full eight bits, enable readline to work with most of the
798 ISO-8859 family of character sets, used by many European countries.
802 Although Bash is intended to be POSIX.2 conformant, there are areas in
803 which the default behavior is not compatible with the standard. For
804 users who wish to operate in a strict POSIX.2 environment, Bash
805 implements a \fIPOSIX mode\fP. When this mode is active, Bash modifies
806 its default operation where it differs from POSIX.2 to match the
807 standard. POSIX mode is entered when Bash is started with the
809 option. This feature is also available as an option to the
810 \fBset\fP builtin, \fBset -o posix\fP.
811 For compatibility with other GNU software that attempts to be POSIX.2
812 compliant, Bash also enters POSIX mode if the variable
814 is set when Bash is started or assigned a value during execution.
816 is accepted as well, to be compatible with some older GNU utilities.
817 When Bash is started in POSIX mode, for example, it sources the
818 file named by the value of
820 rather than the \*Qnormal\*U startup files, and does not allow
821 reserved words to be aliased.
823 New Features and Future Plans
825 There are several features introduced in the current
826 version of Bash, version 1.14, and a number under consideration
827 for future releases. This section will briefly detail the new
828 features in version 1.14 and describe several features
829 that may appear in later versions.
831 New Features in Bash-1.14
833 The new features available in Bash-1.14 answer several of
834 the most common requests for enhancements. Most notably, there
836 for including non-visible character sequences in prompts, such as
837 those which cause a terminal to print characters in different
838 colors or in standout mode. There was nothing preventing the use
839 of these sequences in earlier
840 versions, but the readline redisplay algorithm assumed each
841 character occupied physical screen space and would wrap lines
844 Readline has a few new
845 variables, several new bindable commands, and some additional
846 emacs mode default key bindings. A new history search
847 mode has been implemented: in this mode, readline searches the
848 history for lines beginning with the characters between the
849 beginning of the current line and the cursor. The existing readline
850 incremental search commands no longer match identical lines more
852 Filename completion now expands variables in directory names.
853 The history expansion facilities are now nearly
854 completely csh-compatible: missing modifiers have been added and
855 history substitution has been extended.
857 Several of the features described earlier, such as
861 are new in version 1.14.
862 There is a new shell variable,
864 to which Bash assigns a value that identifies the
865 version of \s-1UNIX\s+1 it's
866 running on (great for putting architecture-specific binary directories
867 into the \fB$PATH\fP).
868 Two variables have been renamed:
871 .B $history_control ,
875 .B $hostname_completion_file .
876 In both cases, the old names are accepted for backwards
877 compatibility. The ksh
879 construct, which allows the generation of simple menus,
880 has been implemented. New capabilities have been added
881 to existing variables:
883 can now take values of
889 understands the value
891 which combines the two previously acceptable values. The
893 builtin has acquired options to print out specific members of the
896 variable, which forces a physical view of the file system,
897 has been superseded by the
901 builtin (equivalent to \fBset -o physical\fP); the variable is retained
902 for backwards compatibility. The version string contained in
904 now includes an indication of the patch level as well as the
906 Some little-used features have
913 variable are gone. There is now an organized test suite that can be
914 run as a regression test when building a new version of Bash.
916 The documentation has been thoroughly overhauled:
917 there is a new manual page on the readline library and the \fIinfo\fP
918 file has been updated to reflect the current version.
919 As always, as many bugs as possible have been fixed, although some
924 There are a few features that I hope to include in later Bash releases.
925 Some are based on work already done in other shells.
927 In addition to simple variables, a future release of Bash will include
928 one-dimensional arrays, using the ksh
929 implementation of arrays as a model. Additions to the ksh syntax,
930 such as \fIvarname\fP=( ... ) to assign a list of words directly to
931 an array and a mechanism to allow
934 builtin to read a list of values directly into an array, would be
935 desirable. Given those extensions, the ksh
937 syntax may not be worth supporting (the
939 option assigns a list of values to an array, but is a rather
940 peculiar special case).
942 Some shells include a means of \fIprogrammable\fP word
943 completion, where the user specifies on a per-command basis how the
944 arguments of the command are to be treated when completion is attempted:
945 as filenames, hostnames, executable files, and so on. The other
946 aspects of the current Bash implementation could remain as-is; the
947 existing heuristics would still be valid. Only when completing the
948 arguments to a simple command would the programmable completion be
951 It would also be nice to give the user finer-grained
952 control over which commands are saved onto the history list. One
953 proposal is for a variable, tentatively named
955 which would contain a colon-separated list of commands. Lines beginning
956 with these commands, after the restrictions of
958 have been applied, would not be placed onto the history list. The
959 shell pattern-matching capabilities could also be available when
960 specifying the contents of
963 One thing that newer shells such as
967 provide is a command to dynamically load code
968 implementing additional builtin commands into a running shell.
969 This new builtin would take an object file or shared library
970 implementing the \*Qbody\*U of the
971 builtin (\fIxxx_builtin()\fP for those familiar with Bash internals)
972 and a structure containing the name of the new command, the function
973 to call when the new builtin is invoked (presumably defined in the
974 shared object specified as an argument), and the documentation to be
977 command (possibly present in the shared object as well). It would
978 manage the details of extending the internal table of builtins.
980 A few other builtins would also be desirable: two are the POSIX.2
982 command, which prints the values of system configuration variables
983 defined by POSIX.2, and a
985 builtin, which causes a shell running
986 with job control active to \*Qforget about\*U one or more
987 background jobs in its internal jobs table. Using
989 for example, a user could retrieve a value for
991 guaranteed to find all of the POSIX standard utilities, or
992 find out how long filenames may be in the file system containing
993 a specified directory.
995 There are no implementation timetables for any of these features, nor
996 are there concrete plans to include them. If anyone has comments on
997 these proposals, feel free to send me electronic mail.
999 Reflections and Lessons Learned
1001 The lesson that has been repeated most often during Bash
1002 development is that there are dark corners in the Bourne shell,
1003 and people use all of them. In the original description of the
1004 Bourne shell, quoting and the shell grammar are both poorly
1005 specified and incomplete; subsequent descriptions have not helped
1006 much. The grammar presented in Bourne's paper describing
1007 the shell distributed with the Seventh Edition of \s-1UNIX\s+1\(dg
1008 is so far off that it does not allow the command \f(CWwho|wc\fP.
1009 In fact, as Tom Duff states:
1011 Nobody really knows what the
1012 Bourne shell's grammar is. Even examination of the source code is
1015 \(dgS. R. Bourne, \*QUNIX Time-Sharing System: The UNIX Shell\*U,
1016 \fIBell System Technical Journal\fP, 57(6), July-August, 1978, pp. 1971-1990.
1019 \(ddTom Duff, \*QRc \- A Shell for Plan 9 and \s-1UNIX\s+1 systems\*U,
1020 \fIProc. of the Summer 1990 EUUG Conference\fP, London, July, 1990,
1024 The POSIX.2 standard includes a \fIyacc\fP grammar that comes close
1025 to capturing the Bourne shell's behavior, but it disallows some
1026 constructs which sh accepts without complaint \- and there are
1027 scripts out there that use them. It took a few versions and
1028 several bug reports before Bash implemented sh-compatible quoting,
1029 and there are still some \*Qlegal\*U sh constructs which Bash flags as
1030 syntax errors. Complete sh compatibility is a tough nut.
1032 The shell is bigger and slower than I would like, though the current
1033 version is substantially faster than previously. The readline library
1034 could stand a substantial rewrite. A hand-written parser to replace
1035 the current \fIyacc\fP-generated one would probably result in a speedup,
1036 and would solve one glaring problem: the shell could parse
1037 commands in \*Q$(...)\*U constructs
1038 as they are entered, rather than reporting errors when the construct
1041 As always, there is some chaff to go with the wheat.
1042 Areas of duplicated functionality need to be cleaned
1043 up. There are several cases where Bash treats a variable specially to
1044 enable functionality available another way (\fB$notify\fP vs.
1045 \fBset -o notify\fP and \fB$nolinks\fP vs. \fBset -o physical\fP, for
1046 instance); the special treatment of the variable name should probably
1047 be removed. A few more things could stand removal; the
1048 .B $allow_null_glob_expansion
1050 .B $glob_dot_filenames
1051 variables are of particularly questionable value.
1052 The \fB$[...]\fP arithmetic evaluation syntax is redundant now that
1053 the POSIX-mandated \fB$((...))\fP construct has been implemented,
1054 and could be deleted.
1055 It would be nice if the text output by the
1057 builtin were external to the shell rather than compiled into it.
1058 The behavior enabled by
1059 .B $command_oriented_history ,
1060 which causes the shell to attempt to save all lines of a multi-line
1061 command in a single history entry, should be made the default and
1062 the variable removed.
1067 GNU software, Bash is available for anonymous FTP from
1068 .I prep.ai.mit.edu:/pub/gnu
1069 and from other GNU software mirror sites. The current version is in
1070 .I bash-1.14.1.tar.gz
1071 in that directory. Use
1073 to find the nearest archive site. The
1074 latest version is always available for FTP from
1075 .I bash.CWRU.Edu:/pub/dist.
1076 Bash documentation is available for FTP from
1077 .I bash.CWRU.Edu:/pub/bash.
1079 The Free Software Foundation sells tapes and CD-ROMs
1080 containing Bash; send electronic mail to
1081 \f(CRgnu@prep.ai.mit.edu\fP or call \f(CR+1-617-876-3296\fP
1082 for more information.
1084 Bash is also distributed with several versions of \s-1UNIX\s+1-compatible
1085 systems. It is included as /bin/sh and /bin/bash on several Linux
1086 distributions (more about the difference in a moment), and as contributed
1087 software in BSDI's BSD/386* and FreeBSD.
1089 *BSD/386 is a trademark of Berkeley Software Design, Inc.
1092 The Linux distribution deserves special mention. There are two
1093 configurations included in the standard Bash distribution: a
1094 \*Qnormal\*U configuration, in which all of the standard features
1095 are included, and a \*Qminimal\*U configuration, which omits job
1096 control, aliases, history and command line editing, the directory
1099 process substitution, prompt string special character decoding, and the
1101 construct. This minimal version is designed to be a drop-in replacement
1102 for the traditional \s-1UNIX\s+1 /bin/sh, and is included as the Linux
1103 /bin/sh in several packagings.
1107 Bash is a worthy successor to sh.
1108 It is sufficiently portable
1109 to run on nearly every version of \s-1UNIX\s+1 from
1110 4.3 BSD to SVR4.2, and several \s-1UNIX\s+1 workalikes.
1111 It is robust enough to replace sh on most of those systems,
1112 and provides more functionality. It has several thousand regular users,
1113 and their feedback has helped to make it as good as it is today \- a
1114 testament to the benefits of free software.