








                      [1mBash - The GNU shell*[0m


                           [4mChet[24m [4mRamey[0m
                 [4mCase[24m [4mWestern[24m [4mReserve[24m [4mUniversity[0m
                        [4mchet@po.cwru.edu[0m


[1m1.  Introduction[0m

     [1mBash [22mis the shell, or  command  language  interpreter,  that
will  appear in the GNU operating system.  The name is an acronym
for the "Bourne-Again SHell", a pun on Steve Bourne,  the  author
of  the  direct  ancestor of the current shell [4m/bin/sh[24m, which ap-
peared in the Seventh Edition Bell Labs Research version of UNIX.

     Bash is an [1msh[22m-compatible shell that incorporates useful fea-
tures from the Korn shell ([1mksh[22m) and the C shell ([1mcsh[22m),  described
later in this article.  It is ultimately intended to be a confor-
mant  implementation of the IEEE POSIX Shell and Utilities speci-
fication (IEEE Working Group 1003.2).  It offers  functional  im-
provements over sh for both interactive and programming use.

     While  the  GNU  operating system will most likely include a
version of the Berkeley shell  csh,  Bash  will  be  the  default
shell.  Like other GNU software, Bash is quite portable.  It cur-
rently  runs on nearly every version of and a few other operating
systems - an independently-supported port exists  for  OS/2,  and
there  are rumors of ports to DOS and Windows NT.  Ports to UNIX-
like systems such as QNX and Minix are part of the distribution.

     The original author of Bash was Brian Fox,  an  employee  of
the  Free  Software  Foundation.  The current developer and main-
tainer is Chet Ramey, a volunteer who works at Case  Western  Re-
serve University.

[1m2.  What's POSIX, anyway?[0m

     [4mPOSIX[24m  is a name originally coined by Richard Stallman for a
family of open system standards based on UNIX.  There are a  num-
ber  of  aspects of UNIX under consideration for standardization,
from the basic system services at the system call and  C  library
level to applications and tools to system administration and man-
agement.   Each  area of standardization is assigned to a working
group in the 1003 series.

     The POSIX Shell and Utilities standard has been developed by

-----------
*An  earlier  version  of this article appeared in The Linux
Journal.









                               -2-


IEEE Working Group 1003.2 (POSIX.2).  It concentrates on the com-
mand interpreter interface and utility programs commonly executed
from the command line or by other programs.  An  initial  version
of  the standard has been approved and published by the IEEE, and
work is currently underway to update it.  There are four  primary
areas of work in the 1003.2 standard:

+o    Aspects  of the shell's syntax and command language.  A num-
     ber of special builtins such as [1mcd [22mand [1mexec [22mare being speci-
     fied as part of the shell, since their functionality usually
     cannot be implemented by a separate executable;

+o    A set of utilities to be called by shell scripts and  appli-
     cations.   Examples  are  programs  like  [4msed,[24m  [4mtr,[24m and [4mawk.[0m
     Utilities commonly implemented as  shell  builtins  are  de-
     scribed  in  this section, such as [1mtest [22mand [1mkill[22m.  An expan-
     sion of this section's scope, termed  the  User  Portability
     Extension,  or  UPE,  has  standardized interactive programs
     such as [4mvi[24m and [4mmailx;[0m

+o    A group of functional interfaces to services provided by the
     shell, such as the traditional system() C library  function.
     There  are  functions to perform shell word expansions, per-
     form filename expansion ([4mglobbing[24m), obtain values of POSIX.2
     system configuration variables, retrieve values of  environ-
     ment variables (getenv()), and other services;

+o    A  suite of "development" utilities such as [4mc89[24m (the POSIX.2
     version of [4mcc[24m), and [4myacc.[0m

     Bash is concerned with the aspects of the  shell's  behavior
defined  by  POSIX.2.   The  shell command language has of course
been standardized, including the basic flow control  and  program
execution  constructs,  I/O  redirection and pipelining, argument
handling, variable expansion, and quoting.  The [4mspecial[24m builtins,
which must be implemented as part of the shell to provide the de-
sired functionality, are specified as being part  of  the  shell;
examples of these are [1meval [22mand [1mexport[22m.  Other utilities appear in
the  sections  of POSIX.2 not devoted to the shell which are com-
monly (and in some cases must be)  implemented  as  builtin  com-
mands,  such as [1mread [22mand [1mtest[22m.  POSIX.2 also specifies aspects of
the shell's interactive behavior as part of  the  UPE,  including
job control and command line editing.  Interestingly enough, only
[4mvi[24m-style  line  editing  commands  have  been standardized; [4memacs[0m
editing commands were left out due to objections.

     While POSIX.2 includes much of what the shell has tradition-
ally provided, some important things have been omitted  as  being
"beyond its scope."  There is, for instance, no mention of a dif-
ference  between  a  [4mlogin[24m  shell and any other interactive shell
-----------
IEEE, [4mIEEE[24m [4mStandard[24m [4mfor[24m [4mInformation[24m [4mTechnology[24m  [4m--[24m  [4mPortable[0m
[4mOperating[24m  [4mSystem[24m [4mInterface[24m [4m(POSIX)[24m [4mPart[24m [4m2:[24m [4mShell[24m [4mand[24m [4mUtili-[0m
[4mties[24m, 1992.









                               -3-


(since POSIX.2 does not  specify  a  login  program).   No  fixed
startup files are defined, either - the standard does not mention
[4m.profile[24m.

[1m3.  Basic Bash features[0m

     Since the Bourne shell provides Bash with most of its philo-
sophical  underpinnings,  Bash  inherits most of its features and
functionality from sh.  Bash implements all of the traditional sh
flow control constructs ([4mfor[24m,  [4mif[24m,  [4mwhile[24m,  etc.).   All  of  the
Bourne  shell  builtins,  including  those  not  specified in the
POSIX.2 standard, appear in Bash.  Shell [4mfunctions[24m, introduced in
the SVR2 version of  the  Bourne  shell,  are  similar  to  shell
scripts,  but are defined using a special syntax and are executed
in the same process as the calling shell.  Bash has  shell  func-
tions  which  behave in a fashion upward-compatible with sh func-
tions.  There are certain shell variables that Bash interprets in
the same way as sh, such as [1mPS1[22m, [1mIFS[22m, and [1mPATH[22m.  Bash  implements
essentially  the  same  grammar, parameter and variable expansion
semantics, redirection, and quoting as the Bourne  shell.   Where
differences  appear  between the POSIX.2 standard and traditional
sh behavior, Bash follows POSIX.

     The Korn Shell ([1mksh[22m) is a descendant  of  the  Bourne  shell
written  at  AT&T Bell Laboratories by David Korn.  It provides a
number of useful features that POSIX and Bash have adopted.  Many
of the interactive facilities in POSIX.2 have their roots in  the
ksh:  for  example,  the POSIX and ksh job control facilities are
nearly identical. Bash includes features from the Korn Shell  for
both  interactive  use  and  shell programming.  For programming,
Bash provides variables such as [1mRANDOM  [22mand  [1mREPLY[22m,  the  [1mtypeset[0m
builtin, the ability to remove substrings from variables based on
patterns,  and shell arithmetic.  [1mRANDOM [22mexpands to a random num-
ber each time it is referenced; assigning a value to [1mRANDOM [22mseeds
the random number generator.  [1mREPLY [22mis the default variable  used
by  the [1mread [22mbuiltin when no variable names are supplied as argu-
ments.  The [1mtypeset [22mbuiltin is used to define variables and  give
them  attributes  such  as  [1mreadonly[22m.  Bash arithmetic allows the
evaluation of an expression and the substitution of  the  result.
Shell variables may be used as operands, and the result of an ex-
pression may be assigned to a variable.  Nearly all of the opera-
tors  from the C language are available, with the same precedence
rules:
     $ echo $((3 + 5 * 32))
     163

For  interactive  use,  Bash  implements  ksh-style  aliases  and
builtins such as [1mfc [22m(discussed below) and [1mjobs[22m.  Bash aliases al-
low  a  string to be substituted for a command name.  They can be
used to create a mnemonic for a UNIX command name (alias del=rm),
to expand a single word to a complex command  (alias  news='xterm
-----------
Morris Bolsky and David Korn, [4mThe[24m [4mKornShell[24m [4mCommand[24m [4mand[24m [4mPro-[0m
[4mgramming[24m [4mLanguage[24m, Prentice Hall, 1989.









                               -4-


-g  80x45  -title  trn  -e trn -e -S1 -N &'), or to ensure that a
command is invoked with a basic set of options (alias ls="/bin/ls
-F").

     The C shell ([1mcsh[22m), originally written by Bill Joy  while  at
Berkeley,  is  widely  used and quite popular for its interactive
facilities.  Bash includes  a  csh-compatible  history  expansion
mechanism  ("!  history"),  brace expansion, access to a stack of
directories via the [1mpushd[22m, [1mpopd[22m, and [1mdirs [22mbuiltins, and tilde ex-
pansion, to generate users' home  directories.   Tilde  expansion
has also been adopted by both the Korn Shell and POSIX.2.

     There  were certain areas in which POSIX.2 felt standardiza-
tion was necessary, but no existing implementation  provided  the
proper  behavior.   The  working  group invented and standardized
functionality in these areas, which Bash implements.  The [1mcommand[0m
builtin was invented so that shell functions could be written  to
replace builtins; it makes the capabilities of the builtin avail-
able  to the function.  The reserved word "!" was added to negate
the return value of a command or pipeline; it was nearly impossi-
ble to express "if not x" cleanly using the sh  language.   There
exist  multiple incompatible implementations of the [1mtest [22mbuiltin,
which tests files for type  and  other  attributes  and  performs
arithmetic  and  string  comparisons.   POSIX  considered none of
these correct, so the standard behavior was specified in terms of
the number of arguments to the command.  POSIX.2 dictates exactly
what will happen when four or fewer arguments are given to  [1mtest[22m,
and  leaves  the  behavior undefined when more arguments are sup-
plied.  Bash uses the POSIX.2 algorithm, which was  conceived  by
David Korn.

[1m3.1.  Features not in the Bourne Shell[0m

     There are a number of minor differences between Bash and the
version of sh present on most other versions of UNIX.  The major-
ity  of these are due to the POSIX standard, but some are the re-
sult of Bash adopting features from other shells.  For  instance,
Bash includes the new "!" reserved word, the [1mcommand [22mbuiltin, the
ability  of  the  [1mread  [22mbuiltin to correctly return a line ending
with a backslash, symbolic arguments to the [1mumask [22mbuiltin,  vari-
able  substring  removal,  a way to get the length of a variable,
and the new algorithm for the [1mtest [22mbuiltin from the POSIX.2 stan-
dard, none of which appear in sh.

     Bash also implements the "$(...)" command substitution  syn-
tax,  which supersedes the sh `...` construct.  The "$(...)" con-
struct expands to the output of the command contained within  the
parentheses,  with  trailing  newlines removed.  The sh syntax is
accepted for backwards compatibility, but the  "$(...)"  form  is
preferred  because  its  quoting rules are much simpler and it is
-----------
Bill  Joy,  An Introduction to the C Shell, [4mUNIX[24m [4mUser's[24m [4mSup-[0m
[4mplementary[24m [4mDocuments[24m, University of California at  Berkeley,
1986.









                               -5-


easier to nest.

     The Bourne shell does not provide such features as brace ex-
pansion, the ability to define a variable and a function with the
same name, local variables in shell functions, the ability to en-
able and disable individual builtins or write a function  to  re-
place a builtin, or a means to export a shell function to a child
process.

     Bash  has  closed a long-standing shell security hole by not
using the [1m$IFS [22mvariable to split each word read by the shell, but
splitting only the results of expansion (ksh and the 4.4  BSD  sh
have  fixed  this  as  well).  Useful behavior such as a means to
abort execution of a script read with the "." command  using  the
[1mreturn  [22mbuiltin  or  automatically  exporting  variables  in  the
shell's environment to children is also not present in the Bourne
shell.  Bash provides a much more powerful environment  for  both
interactive use and programming.

[1m4.  Bash-specific Features[0m

     This  section  details a few of the features which make Bash
unique.  Most of them provide improved interactive use, but a few
programming improvements are present as well.  Full  descriptions
of these features can be found in the Bash documentation.

[1m4.1.  Startup Files[0m

     Bash  executes  startup files differently than other shells.
The Bash behavior is a compromise between the  csh  principle  of
startup files with fixed names executed for each shell and the sh
"minimalist"  behavior.   An interactive instance of Bash started
as a login shell reads and  executes  [4m~/.bash_profile[24m  (the  file
.bash_profile  in  the  user's home directory), if it exists.  An
interactive non-login shell reads and executes [4m~/.bashrc[24m.  A non-
interactive shell (one begun to execute a shell script, for exam-
ple) reads no fixed startup file, but uses the value of the vari-
able [1m$ENV[22m, if set, as the name of a startup file.  The ksh  prac-
tice  of reading [1m$ENV [22mfor every shell, with the accompanying dif-
ficulty of defining the proper variables and functions for inter-
active and non-interactive shells or having the  file  read  only
for  interactive shells, was considered too complex.  Ease of use
won out here.  Interestingly, the next release of ksh will change
to reading [1m$ENV [22monly for interactive shells.

[1m4.2.  New Builtin Commands[0m

     There are a few builtins which are new or have been extended
in Bash.  The [1menable [22mbuiltin allows builtin commands to be turned
on and off arbitrarily.  To use the version of [4mecho[24m  found  in  a
user's  search  path rather than the Bash builtin, enable -n echo
suffices.  The [1mhelp [22mbuiltin provides quick synopses of the  shell
facilities without requiring access to a manual page.  [1mBuiltin [22mis
similar  to  [1mcommand  [22min  that  it  bypasses  shell functions and









                               -6-


directly executes builtin commands.  Access to a csh-style  stack
of  directories  is  provided  via  the  [1mpushd[22m,  [1mpopd[22m,  and  [1mdirs[0m
builtins.  [1mPushd [22mand [1mpopd [22minsert and remove directories from  the
stack,  respectively, and [1mdirs [22mlists the stack contents.  On sys-
tems that allow fine-grained control  of  resources,  the  [1mulimit[0m
builtin can be used to tune these settings.  [1mUlimit [22mallows a user
to control, among other things, whether core dumps are to be gen-
erated,  how  much memory the shell or a child process is allowed
to allocate, and how large a file created by a child process  can
grow.   The  [1msuspend [22mcommand will stop the shell process when job
control is active; most other shells do not allow  themselves  to
be stopped like that.  [1mType, [22mthe Bash answer to [1mwhich [22mand [1mwhence,[0m
shows what will happen when a word is typed as a command:
     $ type export
     export is a shell builtin
     $ type -t export
     builtin
     $ type bash
     bash is /bin/bash
     $ type cd
     cd is a function
     cd ()
     {
         builtin cd ${1+"$@"} && xtitle $HOST: $PWD
     }

Various  modes tell what a command word is (reserved word, alias,
function, builtin, or file) or which version of a command will be
executed based on a user's search path.  Some of this functional-
ity has been adopted by POSIX.2 and folded into the [1mcommand [22mutil-
ity.

[1m4.3.  Editing and Completion[0m

     One area in which Bash shines is command line editing.  Bash
uses the [4mreadline[24m library to read and edit  lines  when  interac-
tive.   Readline is a powerful and flexible input facility that a
user can configure to individual tastes.  It allows lines  to  be
edited  using  either  emacs or vi commands, where those commands
are appropriate.  The full capability of emacs is not  present  -
there is no way to execute a named command with M-x, for instance
-  but the existing commands are more than adequate.  The vi mode
is compliant  with  the  command  line  editing  standardized  by
POSIX.2.

     Readline  is  fully  customizable.  In addition to the basic
commands and key bindings, the library allows users to define ad-
ditional key bindings using a startup file.   The  [4minputrc[24m  file,
which defaults to the file [4m~/.inputrc[24m, is read each time readline
initializes,  permitting users to maintain a consistent interface
across a set of programs.  Readline includes an extensible inter-
face, so each program using the library can add its own  bindable
commands  and  program-specific key bindings.  Bash uses this fa-
cility to add bindings that perform history  expansion  or  shell









                               -7-


word expansions on the current input line.

     Readline interprets a number of variables which further tune
its  behavior.   Variables exist to control whether or not eight-
bit characters are directly read as input or converted  to  meta-
prefixed  key sequences (a meta-prefixed key sequence consists of
the character with the eighth bit zeroed, preceded by  the  [4mmeta-[0m
[4mprefix[24m  character,  usually  escape,  which  selects an alternate
keymap), to decide whether to output characters with  the  eighth
bit  set  directly or as a meta-prefixed key sequence, whether or
not to wrap to a new screen line when  a  line  being  edited  is
longer  than the screen width, the keymap to which subsequent key
bindings should apply, or even what happens when  readline  wants
to  ring  the terminal's bell.  All of these variables can be set
in the inputrc file.

     The startup file understands a set  of  C  preprocessor-like
conditional  constructs  which allow variables or key bindings to
be assigned based on the application using readline, the terminal
currently being used, or the editing mode.  Users  can  add  pro-
gram-specific  bindings to make their lives easier:  I have bind-
ings that let me edit the value of  [1m$PATH  [22mand  double-quote  the
current or previous word:
     # Macros that are convenient for shell interaction
     $if Bash
     # edit the path
     "\C-xp": "PATH=${PATH}\e\C-e\C-a\ef\C-f"
     # prepare to type a quoted word -- insert open and close double
     # quotes and move to just after the open quote
     "\C-x\"": "\"\"\C-b"
     # Quote the current or previous word
     "\C-xq": "\eb\"\ef\""
     $endif

There  is  a  readline  command to re-read the file, so users can
edit the file, change some bindings, and begin to use them almost
immediately.

     Bash implements the [1mbind [22mbuiltin for more dynamic control of
readline than the startup file permits.  [1mBind [22mis used in  several
ways.   In  [4mlist[24m  mode,  it can display the current key bindings,
list all the readline editing directives available  for  binding,
list  which  keys invoke a given directive, or output the current
set of key bindings in a format that can be incorporated directly
into an inputrc file.  In [4mbatch[24m mode, it reads a  series  of  key
bindings  directly  from  a file and passes them to readline.  In
its most common usage, [1mbind [22mtakes a single string and  passes  it
directly to readline, which interprets the line as if it had just
been  read from the inputrc file.  Both key bindings and variable
assignments may appear in the string given to [1mbind[22m.

     The readline library also provides  an  interface  for  [4mword[0m
[4mcompletion[24m.   When  the  [4mcompletion[24m  character  (usually  TAB) is
typed, readline looks at the word  currently  being  entered  and









                               -8-


computes  the  set  of  filenames  of which the current word is a
valid prefix.  If there is only one possible completion, the rest
of the characters are inserted  directly,  otherwise  the  common
prefix  of  the set of filenames is added to the current word.  A
second TAB character entered immediately after a non-unique  com-
pletion  causes  readline to list the possible completions; there
is an option to have the list  displayed  immediately.   Readline
provides hooks so that applications can provide specific types of
completion  before  the default filename completion is attempted.
This is quite flexible, though it is not completely user-program-
mable.  Bash, for example, can complete filenames, command  names
(including  aliases,  builtins, shell reserved words, shell func-
tions, and executables found in the  file  system),  shell  vari-
ables,  usernames,  and  hostnames.   It uses a set of heuristics
that, while not perfect, is generally quite good  at  determining
what type of completion to attempt.

[1m4.4.  History[0m

     Access  to the list of commands previously entered (the [4mcom-[0m
[4mmand[24m [4mhistory[24m) is provided jointly by Bash and  the  readline  li-
brary.  Bash provides variables ([1m$HISTFILE[22m, [1m$HISTSIZE[22m, and [1m$HIST-[0m
[1mCONTROL[22m)  and  the [1mhistory [22mand [1mfc [22mbuiltins to manipulate the his-
tory list.  The value of [1m$HISTFILE [22mspecifies the file where  Bash
writes  the  command  history  on  exit  and reads it on startup.
[1m$HISTSIZE [22mis used to limit the number of commands  saved  in  the
history.   [1m$HISTCONTROL  [22mprovides  a  crude  form of control over
which commands are saved on the history list: a value of  [4mignore-[0m
[4mspace[24m  means  to  not  save  commands which begin with a space; a
value of [4mignoredups[24m means to not save commands identical  to  the
last  command  saved.  [1m$HISTCONTROL [22mwas named [1m$history_control [22min
earlier versions of Bash; the old  name  is  still  accepted  for
backwards  compatibility.   The [1mhistory [22mcommand can read or write
files containing the history list and display  the  current  list
contents.   The  [1mfc  [22mbuiltin,  adopted  from POSIX.2 and the Korn
Shell, allows display and re-execution, with optional editing, of
commands from the history list.  The readline  library  offers  a
set  of  commands to search the history list for a portion of the
current input line or a string typed by the user.   Finally,  the
[4mhistory[24m  library,  generally incorporated directly into the read-
line library, implements a facility for  history  recall,  expan-
sion,  and  re-execution of previous commands very similar to csh
("bang history", so called because the exclamation  point  intro-
duces a history substitution):
     $ echo a b c d e
     a b c d e
     $ !! f g h i
     echo a b c d e f g h i
     a b c d e f g h i
     $ !-2
     echo a b c d e
     a b c d e
     $ echo !-2:1-4
     echo a b c d









                               -9-


     a b c d

The  command history is only saved when the shell is interactive,
so it is not available for use by shell scripts.

[1m4.5.  New Shell Variables[0m

     There are a number of convenience variables that Bash inter-
prets to make life easier.  These include [1mFIGNORE[22m, which is a set
of filename suffixes identifying files to exclude when completing
filenames; [1mHOSTTYPE[22m, which is automatically set to a  string  de-
scribing  the type of hardware on which Bash is currently execut-
ing; [1mcommand_oriented_history[22m, which directs  Bash  to  save  all
lines of a multiple-line command such as a [4mwhile[24m or [4mfor[24m loop in a
single  history  entry,  allowing easy re-editing; and [1mIGNOREEOF[22m,
whose value indicates the number of  consecutive  EOF  characters
that  an interactive shell will read before exiting - an easy way
to  keep  yourself  from  being  logged  out  accidentally.   The
[1mauto_resume  [22mvariable alters the way the shell treats simple com-
mand names: if job control is active, and this variable  is  set,
single-word  simple commands without redirections cause the shell
to first look for and restart a suspended job with that name  be-
fore starting a new process.

[1m4.6.  Brace Expansion[0m

     Since  sh  offers  no  convenient  way to generate arbitrary
strings that share a common prefix or suffix (filename  expansion
requires  that the filenames exist), Bash implements [4mbrace[24m [4mexpan-[0m
[4msion[24m, a capability picked up from csh.  Brace expansion is  simi-
lar  to  filename  expansion,  but the strings generated need not
correspond to existing files.  A brace expression consists of  an
optional  [4mpreamble[24m,  followed by a pair of braces enclosing a se-
ries of comma-separated strings, and an optional [4mpostamble[24m.   The
preamble  is  prepended to each string within the braces, and the
postamble is then appended to each resulting string:
     $ echo a{d,c,b}e
     ade ace abe

As this example demonstrates, the results of brace expansion  are
not sorted, as they are by filename expansion.

[1m4.7.  Process Substitution[0m

     On  systems  that  can  support it, Bash provides a facility
known as [4mprocess[24m [4msubstitution[24m.  Process substitution  is  similar
to command substitution in that its specification includes a com-
mand  to  execute,  but  the shell does not collect the command's
output and insert it into the command line.  Rather, Bash opens a
pipe to the command, which is run in the background.   The  shell
uses  named  pipes  (FIFOs)  or the [4m/dev/fd[24m method of naming open
files to expand the process substitution to a filename which con-
nects to the pipe when opened.  This filename becomes the  result
of  the  expansion.   Process substitution can be used to compare









                               -10-


the outputs of two different versions of an application  as  part
of a regression test:
     $ cmp <(old_prog) <(new_prog)

[1m4.8.  Prompt Customization[0m

     One  of the more popular interactive features that Bash pro-
vides is the ability to customize  the  prompt.   Both  [1m$PS1  [22mand
[1m$PS2,  [22mthe primary and secondary prompts, are expanded before be-
ing displayed.  Parameter and  variable  expansion  is  performed
when  the prompt string is expanded, so any shell variable can be
put into the prompt (e.g., [1m$SHLVL[22m, which indicates how deeply the
current shell is nested).  Bash specially  interprets  characters
in  the  prompt  string  preceded  by a backslash.  Some of these
backslash escapes are replaced with the current time,  the  date,
the current working directory, the username, and the command num-
ber  or  history  number  of the command being entered.  There is
even a backslash escape to cause the shell to change  its  prompt
when  running  as root after an [4msu[24m.  Before printing each primary
prompt, Bash expands the variable [1m$PROMPT_COMMAND [22mand, if it  has
a value, executes the expanded value as a command, allowing addi-
tional prompt customization.  For example, this assignment causes
the  current user, the current host, the time, the last component
of the current working directory, the level of shell nesting, and
the history number of the current command to be embedded into the
primary prompt:
     $ PS1='\u@\h [\t] \W($SHLVL:\!)\$ '
     chet@odin [21:03:44] documentation(2:636)$ cd ..
     chet@odin [21:03:54] src(2:637)$

The string being assigned is surrounded by single quotes so  that
if it is exported, the value of [1m$SHLVL [22mwill be updated by a child
shell:
     chet@odin [21:17:35] src(2:638)$ export PS1
     chet@odin [21:17:40] src(2:639)$ bash
     chet@odin [21:17:46] src(3:696)$

The  \$ escape is displayed as "[1m$[22m" when running as a normal user,
but as "[1m#[22m" when running as root.

[1m4.9.  File System Views[0m

     Since Berkeley introduced symbolic links in 4.2 BSD, one  of
their  most  annoying properties has been the "warping" to a com-
pletely different area of the file system when using [1mcd[22m, and  the
resultant  non-intuitive  behavior  of  "[1mcd ..[22m".  The UNIX kernel
treats symbolic links [4mphysically[24m.  When the kernel is translating
a pathname in which one component is a symbolic link, it replaces
all or part of the pathname while processing the  link.   If  the
contents  of the symbolic link begin with a slash, the kernel re-
places the pathname entirely; if not, the link  contents  replace
the current component.  In either case, the symbolic link is vis-
ible.   If the link value is an absolute pathname, the user finds
himself in a completely different part of the file system.









                               -11-


     Bash provides a [4mlogical[24m view of the file  system.   In  this
default  mode,  command  and filename completion and builtin com-
mands such as [1mcd [22mand [1mpushd [22mwhich change the current  working  di-
rectory  transparently  follow symbolic links as if they were di-
rectories.  The [1m$PWD [22mvariable, which holds the  shell's  idea  of
the  current working directory, depends on the path used to reach
the directory rather than its physical location in the local file
system hierarchy.  For example:
     $ cd /usr/local/bin
     $ echo $PWD
     /usr/local/bin
     $ pwd
     /usr/local/bin
     $ /bin/pwd
     /net/share/sun4/local/bin
     $ cd ..
     $ pwd
     /usr/local
     $ /bin/pwd
     /net/share/sun4/local
     $ cd ..
     $ pwd
     /usr
     $ /bin/pwd
     /usr

One problem with this, of course, arises when  programs  that  do
not  understand the shell's logical notion of the file system in-
terpret ".." differently.  This generally happens when Bash  com-
pletes filenames containing ".." according to a logical hierarchy
which  does not correspond to their physical location.  For users
who find this troublesome, a corresponding [4mphysical[24m view  of  the
file system is available:
     $ cd /usr/local/bin
     $ pwd
     /usr/local/bin
     $ set -o physical
     $ pwd
     /net/share/sun4/local/bin

[1m4.10.  Internationalization[0m

     One  of the most significant improvements in version 1.13 of
Bash was the change to "eight-bit  cleanliness".   Previous  ver-
sions  used  the  eighth bit of characters to mark whether or not
they were quoted when performing word expansions.  While this did
not affect the majority of users, most of whom used  only  seven-
bit  ASCII  characters,  some found it confining.  Beginning with
version 1.13, Bash implemented a different quoting mechanism that
did not alter the eighth bit of characters.  This allowed Bash to
manipulate files with "odd" characters in their  names,  but  did
nothing  to  help users enter those names, so version 1.13 intro-
duced changes to readline that made it eight-bit clean  as  well.
Options   exist   that   force  readline  to  attach  no  special









                               -12-


significance to characters with the eighth bit set  (the  default
behavior  is to convert these characters to meta-prefixed key se-
quences) and to output these  characters  without  conversion  to
meta-prefixed sequences.  These changes, along with the expansion
of  keymaps  to  a  full eight bits, enable readline to work with
most of the ISO-8859 family of character sets, used by many Euro-
pean countries.

[1m4.11.  POSIX Mode[0m

     Although Bash is intended to be  POSIX.2  conformant,  there
are  areas  in  which the default behavior is not compatible with
the standard.  For users who wish to operate in a strict  POSIX.2
environment, Bash implements a [4mPOSIX[24m [4mmode[24m.  When this mode is ac-
tive,  Bash  modifies its default operation where it differs from
POSIX.2 to match the standard.  POSIX mode is entered  when  Bash
is  started  with the [1m-posix [22moption.  This feature is also avail-
able as an option to the [1mset [22mbuiltin, [1mset -o posix[22m.  For compati-
bility with other GNU software that attempts to be  POSIX.2  com-
pliant, Bash also enters POSIX mode if the variable [1m$POSIXLY_COR-[0m
[1mRECT  [22mis set when Bash is started or assigned a value during exe-
cution.  [1m$POSIX_PEDANTIC [22mis accepted as well,  to  be  compatible
with  some  older  GNU  utilities.  When Bash is started in POSIX
mode, for example, it sources the file named by the value of [1m$ENV[0m
rather than the "normal" startup files, and does  not  allow  re-
served words to be aliased.

[1m5.  New Features and Future Plans[0m

     There are several features introduced in the current version
of  Bash,  version 1.14, and a number under consideration for fu-
ture releases.  This section will briefly detail the new features
in version 1.14 and describe several features that may appear  in
later versions.

[1m5.1.  New Features in Bash-1.14[0m

     The  new  features  available in Bash-1.14 answer several of
the most common requests for enhancements.  Most  notably,  there
is  a  mechanism for including non-visible character sequences in
prompts, such as those which cause a terminal to print characters
in different colors or in standout mode.  There was nothing  pre-
venting  the  use of these sequences in earlier versions, but the
readline redisplay  algorithm  assumed  each  character  occupied
physical screen space and would wrap lines prematurely.

     Readline  has a few new variables, several new bindable com-
mands, and some additional emacs mode default  key  bindings.   A
new history search mode has been implemented: in this mode, read-
line searches the history for lines beginning with the characters
between  the  beginning  of the current line and the cursor.  The
existing readline incremental search  commands  no  longer  match
identical  lines more than once.  Filename completion now expands
variables in directory names.  The history  expansion  facilities









                               -13-


are  now nearly completely csh-compatible: missing modifiers have
been added and history substitution has been extended.

     Several of the features described earlier, such  as  [1mset  -o[0m
[1mposix  [22mand  [1m$POSIX_PEDANTIC[22m, are new in version 1.14.  There is a
new shell variable, [1mOSTYPE[22m, to which Bash assigns  a  value  that
identifies the version of UNIX it's running on (great for putting
architecture-specific  binary  directories  into the [1m$PATH[22m).  Two
variables have been renamed: [1m$HISTCONTROL [22mreplaces  [1m$history_con-[0m
[1mtrol[22m,  and [1m$HOSTFILE [22mreplaces [1m$hostname_completion_file[22m.  In both
cases, the old names are accepted  for  backwards  compatibility.
The  ksh  [4mselect[24m construct, which allows the generation of simple
menus, has been implemented.  New capabilities have been added to
existing variables: [1m$auto_resume [22mcan now take values of [4mexact[24m  or
[4msubstring[24m,  and  [1m$HISTCONTROL  [22munderstands  the value [4mignoreboth[24m,
which combines the two previously acceptable  values.   The  [1mdirs[0m
builtin has acquired options to print out specific members of the
directory  stack.  The [1m$nolinks [22mvariable, which forces a physical
view of the file system, has been superseded by the [1m-P [22moption  to
the  [1mset [22mbuiltin (equivalent to [1mset -o physical[22m); the variable is
retained for backwards compatibility.  The  version  string  con-
tained  in  [1m$BASH_VERSION [22mnow includes an indication of the patch
level as well as the "build version".  Some little-used  features
have   been   removed:    the   [1mbye  [22msynonym  for  [1mexit  [22mand  the
[1m$NO_PROMPT_VARS [22mvariable are gone.  There  is  now  an  organized
test  suite  that can be run as a regression test when building a
new version of Bash.

     The documentation has been thoroughly overhauled: there is a
new manual page on the readline library and  the  [4minfo[24m  file  has
been  updated to reflect the current version.  As always, as many
bugs as possible have been fixed, although some surely remain.

[1m5.2.  Other Features[0m

     There are a few features that I hope  to  include  in  later
Bash  releases.   Some  are  based  on work already done in other
shells.

     In addition to simple variables, a future  release  of  Bash
will include one-dimensional arrays, using the ksh implementation
of  arrays as a model.  Additions to the ksh syntax, such as [4mvar-[0m
[4mname[24m=( ... ) to assign a list of words directly to an array and a
mechanism to allow the [1mread [22mbuiltin to read a list of values  di-
rectly  into  an  array,  would be desirable.  Given those exten-
sions, the ksh [1mset -A [22msyntax may not be worth supporting (the  [1m-A[0m
option  assigns a list of values to an array, but is a rather pe-
culiar special case).

     Some shells include a means of [4mprogrammable[24m word completion,
where the user specifies on a per-command basis how the arguments
of the command are to be treated when completion is attempted: as
filenames, hostnames, executable files, and so on.  The other as-
pects of the current Bash implementation could remain as-is;  the









                               -14-


existing  heuristics  would still be valid.  Only when completing
the arguments to a simple command would the programmable  comple-
tion be in effect.

     It would also be nice to give the user finer-grained control
over  which  commands  are saved onto the history list.  One pro-
posal is for a  variable,  tentatively  named  [1mHISTIGNORE[22m,  which
would  contain  a colon-separated list of commands.  Lines begin-
ning with these commands, after the restrictions of  [1m$HISTCONTROL[0m
have  been  applied,  would  not be placed onto the history list.
The shell pattern-matching capabilities could also  be  available
when specifying the contents of [1m$HISTIGNORE[22m.

     One  thing  that  newer  shells  such as [1mwksh [22m(also known as
[1mdtksh[22m) provide is a command to dynamically load code implementing
additional builtin commands  into  a  running  shell.   This  new
builtin  would take an object file or shared library implementing
the "body" of the builtin ([4mxxx_builtin()[24m for those familiar  with
Bash  internals)  and  a structure containing the name of the new
command, the function to call when the  new  builtin  is  invoked
(presumably  defined  in  the shared object specified as an argu-
ment), and the documentation to be printed by  the  [1mhelp  [22mcommand
(possibly present in the shared object as well).  It would manage
the details of extending the internal table of builtins.

     A  few  other  builtins would also be desirable: two are the
POSIX.2 [1mgetconf [22mcommand, which prints the values of  system  con-
figuration  variables  defined  by POSIX.2, and a [1mdisown [22mbuiltin,
which causes a shell running with job control active  to  "forget
about"  one  or  more background jobs in its internal jobs table.
Using [1mgetconf[22m, for example, a user could  retrieve  a  value  for
[1m$PATH  [22mguaranteed to find all of the POSIX standard utilities, or
find out how long filenames may be in the file system  containing
a specified directory.

     There are no implementation timetables for any of these fea-
tures,  nor  are there concrete plans to include them.  If anyone
has comments on these proposals, feel free to send me  electronic
mail.

[1m6.  Reflections and Lessons Learned[0m

     The lesson that has been repeated most often during Bash de-
velopment is that there are dark corners in the Bourne shell, and
people  use  all  of  them.   In  the original description of the
Bourne shell, quoting and the shell grammar are both poorly spec-
ified and incomplete; subsequent  descriptions  have  not  helped
much.   The  grammar  presented  in Bourne's paper describing the
shell distributed with the Seventh Edition of UNIX is so far  off
that  it does not allow the command who|wc.  In fact, as Tom Duff
states:

     Nobody really knows what the Bourne shell's grammar is.










                               -15-


     Even examination of the source code is little help.

The  POSIX.2 standard includes a [4myacc[24m grammar that comes close to
capturing the Bourne shell's behavior, but it disallows some con-
structs which sh  accepts  without  complaint  -  and  there  are
scripts out there that use them.  It took a few versions and sev-
eral  bug  reports before Bash implemented sh-compatible quoting,
and there are still some "legal" sh constructs which  Bash  flags
as syntax errors.  Complete sh compatibility is a tough nut.

     The shell is bigger and slower than I would like, though the
current  version  is  substantially  faster than previously.  The
readline library could stand a substantial rewrite.  A hand-writ-
ten parser to replace the current [4myacc[24m-generated one would proba-
bly result in a speedup, and would  solve  one  glaring  problem:
the shell could parse commands in "$(...)" constructs as they are
entered,  rather  than reporting errors when the construct is ex-
panded.

     As always, there is some chaff to go with the wheat.   Areas
of  duplicated  functionality  need  to be cleaned up.  There are
several cases where Bash treats a variable  specially  to  enable
functionality  available  another way ([1m$notify [22mvs.  [1mset -o notify[0m
and [1m$nolinks [22mvs. [1mset -o  physical[22m,  for  instance);  the  special
treatment of the variable name should probably be removed.  A few
more  things  could stand removal; the [1m$allow_null_glob_expansion[0m
and [1m$glob_dot_filenames [22mvariables are of  particularly  question-
able value.  The [1m$[...] [22marithmetic evaluation syntax is redundant
now  that  the  POSIX-mandated [1m$((...)) [22mconstruct has been imple-
mented, and could be deleted.  It would be nice if the text  out-
put  by  the  [1mhelp [22mbuiltin were external to the shell rather than
compiled into it.  The behavior enabled by [1m$command_oriented_his-[0m
[1mtory[22m, which causes the shell to attempt to save all  lines  of  a
multi-line  command in a single history entry, should be made the
default and the variable removed.

[1m7.  Availability[0m

     As with all other GNU software, Bash is available for anony-
mous FTP from [4mprep.ai.mit.edu:/pub/gnu[24m and from other  GNU  soft-
ware  mirror sites.  The current version is in [4mbash-1.14.1.tar.gz[0m
in that directory.  Use [4marchie[24m to find the nearest archive  site.
The   latest   version   is   always   available   for  FTP  from
[4mbash.CWRU.Edu:/pub/dist.[24m  Bash documentation is available for FTP
from [4mbash.CWRU.Edu:/pub/bash.[0m


-----------
S. R. Bourne, "UNIX Time-Sharing System:  The  UNIX  Shell",
[4mBell[24m [4mSystem[24m [4mTechnical[24m [4mJournal[24m, 57(6), July-August, 1978, pp.
1971-1990.
Tom  Duff, "Rc - A Shell for Plan 9 and UNIX systems", [4mProc.[0m
[4mof[24m [4mthe[24m [4mSummer[24m [4m1990[24m [4mEUUG[24m [4mConference[24m, London, July, 1990,  pp.
21-33.









                               -16-


     The Free Software Foundation sells tapes  and  CD-ROMs  con-
taining Bash; send electronic mail to gnu@prep.ai.mit.edu or call
+1-617-876-3296 for more information.

     Bash  is also distributed with several versions of UNIX-com-
patible systems.  It is included as /bin/sh and /bin/bash on sev-
eral Linux distributions (more about the difference in a moment),
and as contributed software in BSDI's BSD/386* and FreeBSD.

     The Linux distribution deserves special mention.  There  are
two  configurations included in the standard Bash distribution: a
"normal" configuration, in which all of the standard features are
included, and a "minimal" configuration, which omits job control,
aliases, history and command line editing,  the  directory  stack
and  [1mpushd/popd/dirs, [22mprocess substitution, prompt string special
character decoding, and the [4mselect[24m construct.  This minimal  ver-
sion  is designed to be a drop-in replacement for the traditional
UNIX /bin/sh, and is included as the  Linux  /bin/sh  in  several
packagings.

[1m8.  Conclusion[0m

     Bash  is  a  worthy  successor  to  sh.   It is sufficiently
portable to run on nearly every version of UNIX from 4.3  BSD  to
SVR4.2,  and several UNIX workalikes.  It is robust enough to re-
place sh on most of those systems, and provides more  functional-
ity.   It  has several thousand regular users, and their feedback
has helped to make it as good as it is today - a testament to the
benefits of free software.























-----------
*BSD/386 is a trademark of Berkeley Software Design, Inc.






