








                   [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
UNIX(R) shell [4m/bin/sh[24m, which appeared in the Seventh Edition
Bell Labs Research version of UNIX.

     Bash is an [1msh[22m-compatible shell that incorporates useful
features from the Korn shell ([1mksh[22m) and the  C  shell  ([1mcsh[22m),
described  later in this article.  It is ultimately intended
to be a conformant implementation of the  IEEE  POSIX  Shell
and Utilities specification (IEEE Working Group 1003.2).  It
offers functional improvements 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  de-
fault  shell.  Like other GNU software, Bash is quite porta-
ble.  It currently runs on nearly every version of UNIX  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
maintainer is Chet Ramey, a  volunteer  who  works  at  Case
Western Reserve 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  number  of  aspects  of UNIX under consideration for
standardization, from the basic system services at the  sys-
tem  call  and  C library level to applications and tools to
system administration and management.  Each  area  of  stan-
dardization  is  assigned  to  a  working  group in the 1003
-----------
*An  earlier  version  of this article appeared in
The Linux Journal.









                             -2-


series.

     The POSIX Shell and Utilities standard has been  devel-
oped  by  IEEE  Working  Group 1003.2 (POSIX.2).  It concen-
trates on the command interpreter interface and utility pro-
grams  commonly  executed  from the command line or by other
programs.  An initial version of the standard has  been  ap-
proved  and published by the IEEE, and work is currently un-
derway 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
     number of special builtins such as [1mcd [22mand [1mexec [22mare  be-
     ing  specified  as part of the shell, since their func-
     tionality usually cannot be implemented by  a  separate
     executable;

+o    A  set  of  utilities to be called by shell scripts and
     applications.  Examples are programs like [4msed,[24m [4mtr,[24m  and
     [4mawk.[24m   Utilities commonly implemented as shell builtins
     are described in this section, such as [1mtest  [22mand  [1mkill[22m.
     An  expansion  of this section's scope, termed the User
     Portability Extension, or UPE, has standardized  inter-
     active 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  li-
     brary  function.   There are functions to perform shell
     word expansions, perform filename expansion ([4mglobbing[24m),
     obtain  values  of  POSIX.2  system configuration vari-
     ables,  retrieve  values   of   environment   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  be-
havior  defined  by POSIX.2.  The shell command language has
of course been standardized, including the basic  flow  con-
trol  and  program execution constructs, I/O redirection and
pipelining, argument handling, variable expansion, and quot-
ing.   The  [4mspecial[24m  builtins,  which must be implemented as
part of the shell to provide the desired 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 commonly (and in
some cases must be) implemented as builtin commands, 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,
-----------
IEEE,  [4mIEEE[24m [4mStandard[24m [4mfor[24m [4mInformation[24m [4mTechnology[24m [4m--[0m
[4mPortable[24m [4mOperating[24m [4mSystem[24m [4mInterface[24m  [4m(POSIX)[24m  [4mPart[0m
[4m2:[24m [4mShell[24m [4mand[24m [4mUtilities[24m, 1992.









                             -3-


only [4mvi[24m-style line editing commands have been  standardized;
[4memacs[24m editing commands were left out due to objections.

     While  POSIX.2 includes much of what the shell has tra-
ditionally provided, some important things have been omitted
as  being  "beyond  its  scope."  There is, for instance, no
mention of a difference between a [4mlogin[24m shell and any  other
interactive  shell  (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
philosophical underpinnings, Bash inherits most of its  fea-
tures 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 functions which behave
in a fashion upward-compatible with sh functions.  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 essen-
tially 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 [22mbuiltin, the ability
to remove substrings from variables based on  patterns,  and
shell  arithmetic.   [1mRANDOM  [22mexpands to a random number 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
arguments.   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 expression may be assigned to a variable.
-----------
Morris  Bolsky  and David Korn, [4mThe[24m [4mKornShell[24m [4mCom-[0m
[4mmand[24m  [4mand[24m  [4mProgramming[24m  [4mLanguage[24m,  Prentice  Hall,
1989.









                             -4-


Nearly all of the operators from the C language  are  avail-
able, 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 allow 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 -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 inter-
active 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[0m
builtins,  and  tilde expansion, to generate users' home di-
rectories.  Tilde expansion has also been  adopted  by  both
the Korn Shell and POSIX.2.

     There  were  certain  areas in which POSIX.2 felt stan-
dardization 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 [22mbuiltin was invented so that shell
functions could be written to replace builtins; it makes the
capabilities  of the builtin available to the function.  The
reserved word "!" was added to negate the return value of  a
command or pipeline; it was nearly impossible 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  argu-
ments  are  given to [1mtest[22m, and leaves the behavior undefined
when more arguments are supplied.  Bash uses the POSIX.2 al-
gorithm, 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 majority of these are due to the POSIX standard,
but some are the result of Bash adopting features from other
shells.   For  instance,  Bash includes the new "!" reserved
-----------
Bill  Joy,  An  Introduction  to the C Shell, [4mUNIX[0m
[4mUser's[24m [4mSupplementary[24m [4mDocuments[24m, University of Cal-
ifornia at Berkeley, 1986.









                             -5-


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, variable substring  removal,
a way to get the length of a variable, and the new algorithm
for the [1mtest [22mbuiltin from  the  POSIX.2  standard,  none  of
which appear in sh.

     Bash  also implements the "$(...)" command substitution
syntax,  which  supersedes  the  sh  `...`  construct.   The
"$(...)" construct expands to the output of the command con-
tained within the parentheses, with  trailing  newlines  re-
moved.   The sh syntax is accepted for backwards compatibil-
ity, but the "$(...)" form is preferred because its  quoting
rules are much simpler and it is easier to nest.

     The  Bourne  shell  does  not  provide such features as
brace expansion, the ability to  define  a  variable  and  a
function  with the same name, local variables in shell func-
tions, the ability to enable and disable individual builtins
or  write a function to replace a builtin, or a means to ex-
port 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 ex-
porting 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  pro-
gramming.

[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 example) reads no fixed
startup file, but uses the value of the  variable  [1m$ENV[22m,  if
set,  as  the  name  of a startup file.  The ksh practice of









                             -6-


reading [1m$ENV [22mfor every shell, with the  accompanying  diffi-
culty of defining the proper variables and functions for in-
teractive 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 ex-
tended  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 ac-
cess to a manual page.  [1mBuiltin [22mis  similar  to  [1mcommand  [22min
that  it  bypasses  shell  functions  and  directly executes
builtin commands.  Access to a csh-style stack  of  directo-
ries  is  provided  via  the [1mpushd[22m, [1mpopd[22m, and [1mdirs [22mbuiltins.
[1mPushd [22mand [1mpopd [22minsert and remove directories from the stack,
respectively, and [1mdirs [22mlists the stack contents.  On systems
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  generated,  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, [22mshows  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 functionality has been adopted by  POSIX.2  and
folded into the [1mcommand [22mutility.













                             -7-


[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
interactive.   Readline is a powerful and flexible input fa-
cility 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 ba-
sic  commands  and key bindings, the library allows users to
define additional 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 interface, so each program using  the
library  can  add its own bindable commands and program-spe-
cific key bindings.  Bash uses this facility to add bindings
that  perform  history expansion or shell 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  con-
verted  to  meta-prefixed key sequences (a meta-prefixed key
sequence consists of the character with the eighth  bit  ze-
roed, preceded by the [4mmeta-prefix[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 read-
line, the terminal currently  being  used,  or  the  editing
mode.  Users can add program-specific bindings to make their
lives easier:  I have bindings 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"









                             -8-


     # 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 con-
trol of readline than the startup  file  permits.   [1mBind  [22mis
used in several ways.  In [4mlist[24m mode, it can display the cur-
rent key bindings, list all the readline editing  directives
available for binding, list which keys invoke a given direc-
tive, 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 us-
age, [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[24m [4mcompletion[24m.  When  the  [4mcompletion[24m  character  (usually
TAB)  is  typed,  readline looks at the word currently being
entered and computes the set of filenames of which the  cur-
rent  word is a valid prefix.  If there is only one possible
completion, the rest of  the  characters  are  inserted  di-
rectly,  otherwise the common prefix of the set of filenames
is added to the current word.  A second  TAB  character  en-
tered immediately after a non-unique completion causes read-
line 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 at-
tempted.  This is quite flexible,  though  it  is  not  com-
pletely  user-programmable.  Bash, for example, can complete
filenames, command names (including aliases, builtins, shell
reserved  words,  shell  functions, and executables found in
the file system), shell variables, usernames, and hostnames.
It uses a set of heuristics that, while not perfect, is gen-
erally quite good at determining what type of completion  to
attempt.

[1m4.4.  History[0m

     Access  to the list of commands previously entered (the
[4mcommand[24m [4mhistory[24m) is provided jointly by Bash and  the  read-
line  library.   Bash  provides variables ([1m$HISTFILE[22m, [1m$HIST-[0m
[1mSIZE[22m, and [1m$HISTCONTROL[22m) and the [1mhistory [22mand [1mfc  [22mbuiltins  to
manipulate  the history list.  The value of [1m$HISTFILE [22mspeci-
fies 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[0m









                             -9-


provides  a  crude  form  of control over which commands are
saved on the history list: a value of [4mignorespace[24m  means  to
not  save  commands which begin with a space; a value of [4mig-[0m
[4mnoredups[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 cur-
rent  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 his-
tory  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 readline library,
implements a facility for history recall, expansion, and re-
execution  of  previous  commands very similar to csh ("bang
history", so called because the exclamation point introduces
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
     a b c d

The command history is only saved when the shell is interac-
tive, 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
interprets  to  make  life  easier.   These include [1mFIGNORE[22m,
which is a set of filename suffixes identifying files to ex-
clude when completing filenames; [1mHOSTTYPE[22m, which is automat-
ically set to a string describing the type  of  hardware  on
which Bash is currently executing; [1mcommand_oriented_history[22m,
which directs Bash to save all lines of a multiple-line com-
mand  such as a [4mwhile[24m or [4mfor[24m loop in a single history entry,
allowing easy re-editing; and [1mIGNOREEOF[22m, whose  value  indi-
cates  the  number of consecutive EOF characters that an in-
teractive 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
command  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 before starting a new process.










                            -10-


[1m4.6.  Brace Expansion[0m

     Since sh offers no convenient way to generate arbitrary
strings  that  share a common prefix or suffix (filename ex-
pansion requires that the filenames exist), Bash  implements
[4mbrace[24m [4mexpansion[24m, a capability picked up from csh.  Brace ex-
pansion is similar 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  series  of  comma-separated
strings,  and  an  optional  [4mpostamble[24m.   The  preamble   is
prepended  to each string within the braces, and the postam-
ble 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 facil-
ity known as [4mprocess[24m [4msubstitution[24m.  Process substitution  is
similar  to  command  substitution in that its specification
includes a command to execute, but the shell does  not  col-
lect  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 connects to the
pipe when opened.  This filename becomes the result  of  the
expansion.   Process substitution can be used to compare 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
provides is the ability to customize the prompt.  Both  [1m$PS1[0m
and  [1m$PS2,  [22mthe  primary and secondary prompts, are expanded
before being 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 in-
dicates  how deeply the current shell is nested).  Bash spe-
cially interprets characters in the prompt  string  preceded
by  a  backslash.   Some  of these backslash escapes are re-
placed with the current time, the date, the current  working
directory,  the  username, and the command number or history
number of the command being entered.  There is even a  back-
slash  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,









                            -11-


allowing additional 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 completely 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  replaces  the  pathname  en-
tirely; if not, the link contents replace the current compo-
nent.  In either case, the symbolic link is visible.  If the
link  value  is an absolute pathname, the user finds himself
in a completely different part of the file system.

     Bash provides a [4mlogical[24m view of the  file  system.   In
this  default  mode,  command  and  filename  completion and
builtin commands such as [1mcd [22mand [1mpushd [22mwhich change the  cur-
rent  working  directory transparently follow symbolic links
as if they were directories.  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









                            -12-


     $ /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 interpret ".." differently.  This  generally  happens
when Bash completes filenames containing ".." according to a
logical hierarchy which does not correspond to their  physi-
cal location.  For users who find this troublesome, a corre-
sponding [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 versions used the eighth bit of characters to  mark
whether  or not they were quoted when performing word expan-
sions.  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  im-
plemented  a  different quoting mechanism that did not alter
the eighth bit of characters.  This allowed Bash to  manipu-
late  files  with  "odd"  characters in their names, but did
nothing to help users enter those names, so version 1.13 in-
troduced changes to readline that made it eight-bit clean as
well.  Options exist that force readline to attach  no  spe-
cial significance to characters with the eighth bit set (the
default behavior is to convert these characters to meta-pre-
fixed  key sequences) 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 charac-
ter sets, used by many European 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 compat-
ible  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 active, Bash modifies its default opera-
tion where it differs from POSIX.2 to  match  the  standard.
POSIX  mode  is entered when Bash is started with the [1m-posix[0m









                            -13-


option.  This feature is also available as an option to  the
[1mset [22mbuiltin, [1mset -o posix[22m.  For compatibility with other GNU
software that attempts to be POSIX.2  compliant,  Bash  also
enters  POSIX  mode  if the variable [1m$POSIXLY_CORRECT [22mis set
when Bash is started or assigned a value  during  execution.
[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 [22mrather than the "normal" startup files,  and  does  not
allow reserved 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 considera-
tion  for future releases.  This section will briefly detail
the new features in version 1.14 and describe  several  fea-
tures 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 se-
quences in prompts, such as those which cause a terminal  to
print  characters  in  different colors or in standout mode.
There was nothing preventing the use of these  sequences  in
earlier  versions,  but the readline redisplay algorithm as-
sumed each character  occupied  physical  screen  space  and
would wrap lines prematurely.

     Readline  has a few new variables, several new bindable
commands, and some additional emacs mode default  key  bind-
ings.   A  new  history search mode has been implemented: in
this mode, readline 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  direc-
tory names.  The history expansion facilities 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[0m
[1m-o posix [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$HISTCON-[0m
[1mTROL   [22mreplaces  [1m$history_control[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 con-
struct, which allows the generation  of  simple  menus,  has
been  implemented.   New  capabilities  have  been  added to









                            -14-


existing variables: [1m$auto_resume [22mcan now take values of  [4mex-[0m
[4mact[24m or [4msubstring[24m, and [1m$HISTCONTROL [22munderstands the value [4mig-[0m
[4mnoreboth[24m, which combines the two previously acceptable  val-
ues.   The  [1mdirs  [22mbuiltin  has acquired options to print out
specific members of the directory stack.  The [1m$nolinks [22mvari-
able,  which  forces a physical view of the file system, has
been superseded by the [1m-P [22moption to the [1mset [22mbuiltin (equiva-
lent to [1mset -o physical[22m); the variable is retained for back-
wards  compatibility.   The  version  string  contained   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  orga-
nized  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[0m
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 im-
plementation of arrays as a model.   Additions  to  the  ksh
syntax,  such  as  [4mvarname[24m=( ... ) to assign a list of words
directly to an array and  a  mechanism  to  allow  the  [1mread[0m
builtin  to  read  a  list of values directly into an array,
would be desirable.  Given those extensions, the ksh [1mset  -A[0m
syntax  may not be worth supporting (the [1m-A [22moption assigns a
list of values to an array, but is a rather peculiar special
case).

     Some  shells  include a means of [4mprogrammable[24m word com-
pletion, where the user specifies on a per-command basis how
the  arguments of the command are to be treated when comple-
tion  is  attempted:  as  filenames,  hostnames,  executable
files, and so on.  The other aspects of the current Bash im-
plementation could remain  as-is;  the  existing  heuristics
would still be valid.  Only when completing the arguments to
a simple command would the programmable completion be in ef-
fect.

     It  would  also  be nice to give the user finer-grained
control over which commands are saved onto the history list.
One  proposal  is  for a variable, tentatively named [1mHISTIG-[0m
[1mNORE[22m, which would contain a  colon-separated  list  of  com-
mands.   Lines  beginning  with  these  commands,  after the









                            -15-


restrictions of [1m$HISTCONTROL [22mhave 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  imple-
menting  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 contain-
ing  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 argument), and the documentation to
be printed by the [1mhelp  [22mcommand  (possibly  present  in  the
shared  object as well).  It would manage the details of ex-
tending 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 sys-
tem configuration variables defined by POSIX.2, and a [1mdisown[0m
builtin,  which  causes a shell running with job control ac-
tive 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
features,  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 development 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 gram-
mar are both poorly specified and incomplete; subsequent de-
scriptions 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 gram-
     mar is.  Even examination of the  source  code  is
     little help.
-----------
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 sys-
tems", [4mProc.[24m [4mof[24m [4mthe[24m [4mSummer[24m [4m1990[24m  [4mEUUG[24m  [4mConference[24m,









                            -16-


The  POSIX.2  standard  includes  a  [4myacc[24m grammar that comes
close to capturing the Bourne shell's behavior, but it  dis-
allows  some constructs which sh accepts without complaint -
and there are scripts out there that use them.   It  took  a
few versions and several 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 pre-
viously.  The readline library could stand a substantial re-
write.   A  hand-written parser to replace the current [4myacc[24m-
generated one would probably result in a speedup, and  would
solve  one  glaring problem:  the shell could parse commands
in "$(...)" constructs as they are entered, rather than  re-
porting errors when the construct is expanded.

     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 spe-
cially to enable functionality available another  way  ([1m$no-[0m
[1mtify  [22mvs.   [1mset  -o notify [22mand [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 [22mand  [1m$glob_dot_file-[0m
[1mnames [22mvariables are of particularly questionable value.  The
[1m$[...] [22marithmetic evaluation syntax is  redundant  now  that
the  POSIX-mandated [1m$((...)) [22mconstruct has been implemented,
and could be deleted.  It would be nice if the  text  output
by  the  [1mhelp [22mbuiltin were external to the shell rather than
compiled into it.  The  behavior  enabled  by  [1m$command_ori-[0m
[1mented_history[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
anonymous FTP from [4mprep.ai.mit.edu:/pub/gnu[24m and  from  other
GNU  software  mirror  sites.   The  current  version  is in
[4mbash-1.14.1.tar.gz[24m 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  docu-
mentation is available for FTP from [4mbash.CWRU.Edu:/pub/bash.[0m

     The  Free  Software  Foundation sells tapes and CD-ROMs
containing 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-
compatible systems.  It is included as /bin/sh and /bin/bash
-----------
London, July, 1990, pp. 21-33.









                            -17-


on several 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 distri-
bution: a "normal" configuration, in which all of the  stan-
dard  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 version 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 replace sh on most of those systems,  and  provides  more
functionality.   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 De-
sign, Inc.






