BASH Frequently-Asked Questions

BASH Frequently-Asked Questions

Post by Chet Ram » Mon, 04 Aug 1997 04:00:00



Archive-name: unix-faq/shell/bash
Posting-Frequency: monthly
Submitted-By: c...@po.cwru.edu (Chet Ramey)
Last-Modified: Mon Jul 21 17:29:00 EDT 1997
FAQ-Version: 2.5
Bash-Version: 2.01
URL: ftp://slc2.ins.cwru.edu/pub/bash/FAQ
Maintainer: c...@po.cwru.edu (Chet Ramey)

This is the Bash FAQ, version 2.5, for Bash version 2.01.

This document contains a set of frequently-asked questions concerning
Bash, the GNU Bourne-Again Shell.  Bash is a freely-available command
interpreter with advanced features for both interactive use and shell
programming.

Another good source of basic information about shells is the collection
of FAQ articles periodically posted to comp.unix.shell.

Questions and comments concerning this document should be sent to
c...@po.cwru.edu.

This document is available for anonymous FTP with the URL

ftp://slc2.ins.cwru.edu/pub/bash/FAQ

----------
Contents:

Section A:  The Basics

1) What is it?
2) What's the latest version?
3) Where can I get it?
4) On what machines will bash run?
5) Will bash run on operating systems other than Unix?
6) How can I build bash with gcc?
7) How can I make bash my login shell?
8) I just changed my login shell to bash, and now I can't FTP into my
   machine.  Why not?
9) What's the `POSIX 1003.2 standard'?
10) What is the bash `posix mode'?

Section B:  The latest version

11) What's new in version 2.01?
12) Are there any user-visible incompatibilities between bash-2.01 and
    bash-1.14.7?

Section C:  Differences from other Unix shells

13) How does bash differ from sh, the Bourne shell?
14) How does bash differ from the Korn shell, version ksh88?
15) Which new features in ksh-93 are not in bash, and which are?

Section D:  Why does bash do some things differently than other Unix shells?

16) Why does bash run a different version of `command' than
    `which command' says it will?
17) Why doesn't bash treat brace expansions exactly like csh?
18) Why doesn't bash have csh variable modifiers?
19) How can I make my csh aliases work when I convert to bash?
20) How can I pipe standard output and standard error from one command to
    another, like csh does with `|&'?
21) Now that I've converted from ksh to bash, are there equivalents to
    ksh features like autoloaded functions and the `whence' command?

Section E:  How can I get bash to do certain things, and why does bash do
            things the way it does?

22) Why is the bash builtin `test' slightly different from /bin/test?
23) Why does bash sometimes say `Broken pipe'?
24) How can I get bash to read and display eight-bit characters?
25) How do I write a function `x' to replace builtin command `x', but
    still invoke the command from within the function?
26) When I have terminal escape sequences in my prompt, why does bash
    wrap lines at the wrong column?
27) How can I find the value of a shell variable whose name is the value
    of another shell variable?
28) If I pipe the output of a command into `read variable', why doesn't
    the output show up in $variable when the read command finishes?
29) I have a bunch of shell scripts that use backslash-escaped characters
    in arguments to `echo'.  Bash doesn't interpret these characters.  Why
    not, and how can I make it understand them?
30) Why doesn't a while or for loop get suspended when I type ^Z?
31) How can I make the bash `time' reserved word print timing output that
    looks like the output from my system's /usr/bin/time?

Section F:  Things to watch out for on certain Unix versions

32) Why can't I use command line editing in my `cmdtool'?
33) I built bash on Solaris 2.  Why do globbing expansions and filename
    completion chop off the first few characters of each filename?
34) Why does bash dump core after I interrupt username completion or
    `~user' tilde expansion on a machine running NIS?
35) I'm running SVR4.2.  Why is the line erased every time I type `@'?
36) Why does bash report syntax errors when my C News scripts use a
    redirection before a subshell command?

Section G:  Where do I go from here?

37) How do I report bugs in bash, and where should I look for fixes and
    advice?
38) What kind of bash documentation is there?
39) What's coming in future versions?
40) What's on the bash `wish list'?
41) When will the next release appear?

----------
Section A:  The Basics

1)  What is it?

Bash is a Unix command interpreter (shell).  It is an implementation of
the Posix 1003.2 shell standard, and resembles the Korn and System V
shells.

Bash contains a number of enhancements over those shells, both
for interactive use and shell programming.  Features geared
toward interactive use include command line editing, command
history, job control, aliases, and prompt expansion.  Programming
features include additional variable expansions, shell
arithmetic, and a number of variables and options to control
shell behavior.

Bash was originally written by Brian Fox of the Free Software
Foundation.  The current developer and maintainer is Chet Ramey
of Case Western Reserve University.

2)  What's the latest version?

The latest version is 2.01, first made available on June 6, 1997.

3)  Where can I get it?

Bash is the GNU project's shell, and so is available from the
master GNU archive site, prep.ai.mit.edu, and its mirrors.  The
latest version is also available for FTP from slc2.ins.cwru.edu,
the maintainer's machine.  The following URLs tell how to get
version 2.01:

ftp://prep.ai.mit.edu/pub/gnu/bash-2.01.tar.gz
ftp://slc2.ins.cwru.edu/pub/dist/bash-2.01.tar.gz

Formatted versions of the documentation are available with the URLs:

ftp://prep.ai.mit.edu/pub/gnu/bash-doc-2.01.tar.gz
ftp://slc2.ins.cwru.edu/pub/dist/bash-doc-2.01.tar.gz

4)  On what machines will bash run?

Bash has been ported to nearly every version of UNIX.  All you
should have to do to build it on a machine for which a port
exists is to type `configure' and then `make'.  The build process
will attempt to discover the version of UNIX you have and tailor
itself accordingly, using a script created by GNU autoconf.

More information appears in the file `INSTALL' in the distribution.

5) Will bash run on operating systems other than Unix?

Configuration specifics for Unix-like systems such as QNX and
LynxOS are included in the distribution.  Previous versions of
bash have been ported to Minix, but I don't believe anyone has
built bash-2.x on Minix yet.

Bash has been ported to versions of Windows implementing the Win32
programming interface.  This includes Windows 95 and Windows NT.
The port was done by Cygnus Solutions as part of their GNU-Win32
project.  For more information about the project, look at the URL

http://www.cygnus.com/misc/gnu-win32

Cygnus has ported bash-1.14.7.  Maybe someday they (or I) will port
bash-2.01 (or later) to the GNU-Win32 environment.

D. J. Delorie has ported bash-1.14.7 to run under MS-DOS, as part of
the DJGPP project.  For more information on the project, see

http://www.delorie.com/djgpp/

I picked up a binary of bash-1.14.7 that is purported to work with
the DJGPP V2 environment from

ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2gnu/bsh1147b.zip

The corresponding source is

ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2gnu/bsh1147s.zip

A port of bash-1.12 is available for OS/2 from

ftp://hobbes.nmsu.edu/os2/unix/bash_112.zip

I haven't looked at it.

6) How can I build bash with gcc?

Bash configures to use gcc by default if it is available.  Read the
file INSTALL in the distribution for more information.

7)  How can I make bash my login shell?

Some machines let you use `chsh' to change your login shell.  Other
systems use `passwd -s'.  If one of these works for you, that's all
you need.  Note that many systems require the full pathname to a shell
to appear in /etc/shells before you can make it your login shell.  For
this, you may need the assistance of your friendly local system
administrator.

If you cannot do this, you can still use bash as your login shell, but
you need to perform some tricks.  The basic idea is to add a command
to your login shell's startup file to replace your login shell with
bash.

For example, if your login shell is csh or tcsh, and you have installed
bash in /usr/gnu/bin/bash, add the following line to ~/.login:

        if ( -f /usr/gnu/bin/bash ) exec /usr/gnu/bin/bash --login

(the `--login' tells bash that it is a login shell).

It's not a good idea to put this command into ~/.cshrc, because every
csh you run without the `-f' option, even ones started to run csh scripts,
reads that file.  If you must put the command in ~/.cshrc, use something
like

        if ( $?prompt ) exec /usr/gnu/bin/bash --login

to ensure that bash is exec'd only when the csh is interactive.

If your login shell is sh or ksh, you have to do two things.

First, create an empty file in your home directory named `.bash_profile'.
The existence of this file will prevent the exec'd bash from trying to
read ~/.profile, and re-execing itself over and over again.  ~/.bash_profile
is the first file bash tries to read initialization commands from when
it is invoked as a login shell.

Next, add a line similar to the above to ~/.profile:

        [ -f /usr/gnu/bin/bash ] && exec /usr/gnu/bin/bash --login

This will cause login shells to replace themselves with bash running as
a login shell.  Once you have this working, you can copy your initialization
code from ~/.profile to ~/.bash_profile.

8) I just changed my login shell to bash, and now I can't FTP into my
   machine.  Why not?

You must add the full pathname to bash to the file /etc/shells.  As
noted in the answer to the previous question, many systems require
this before you can make bash your login shell.

Most versions of ftpd use this file to prohibit `special' users
such as `uucp' and `news' from using FTP.

9)  What's the `POSIX 1003.2 standard'?

POSIX is a name originally coined by Richard Stallman for a
family of open system standards based on UNIX.  There are a
number of aspects ...

read more »

 
 
 

BASH Frequently-Asked Questions

Post by Chet Ram » Tue, 05 Aug 1997 04:00:00


Archive-name: unix-faq/shell/bash
Posting-Frequency: monthly
Submitted-By: c...@po.cwru.edu (Chet Ramey)
Last-Modified: Mon Jul 21 17:29:00 EDT 1997
FAQ-Version: 2.5
Bash-Version: 2.01
URL: ftp://slc2.ins.cwru.edu/pub/bash/FAQ
Maintainer: c...@po.cwru.edu (Chet Ramey)

This is the Bash FAQ, version 2.5, for Bash version 2.01.

This document contains a set of frequently-asked questions concerning
Bash, the GNU Bourne-Again Shell.  Bash is a freely-available command
interpreter with advanced features for both interactive use and shell
programming.

Another good source of basic information about shells is the collection
of FAQ articles periodically posted to comp.unix.shell.

Questions and comments concerning this document should be sent to
c...@po.cwru.edu.

This document is available for anonymous FTP with the URL

ftp://slc2.ins.cwru.edu/pub/bash/FAQ

----------
Contents:

Section A:  The Basics

1) What is it?
2) What's the latest version?
3) Where can I get it?
4) On what machines will bash run?
5) Will bash run on operating systems other than Unix?
6) How can I build bash with gcc?
7) How can I make bash my login shell?
8) I just changed my login shell to bash, and now I can't FTP into my
   machine.  Why not?
9) What's the `POSIX 1003.2 standard'?
10) What is the bash `posix mode'?

Section B:  The latest version

11) What's new in version 2.01?
12) Are there any user-visible incompatibilities between bash-2.01 and
    bash-1.14.7?

Section C:  Differences from other Unix shells

13) How does bash differ from sh, the Bourne shell?
14) How does bash differ from the Korn shell, version ksh88?
15) Which new features in ksh-93 are not in bash, and which are?

Section D:  Why does bash do some things differently than other Unix shells?

16) Why does bash run a different version of `command' than
    `which command' says it will?
17) Why doesn't bash treat brace expansions exactly like csh?
18) Why doesn't bash have csh variable modifiers?
19) How can I make my csh aliases work when I convert to bash?
20) How can I pipe standard output and standard error from one command to
    another, like csh does with `|&'?
21) Now that I've converted from ksh to bash, are there equivalents to
    ksh features like autoloaded functions and the `whence' command?

Section E:  How can I get bash to do certain things, and why does bash do
            things the way it does?

22) Why is the bash builtin `test' slightly different from /bin/test?
23) Why does bash sometimes say `Broken pipe'?
24) How can I get bash to read and display eight-bit characters?
25) How do I write a function `x' to replace builtin command `x', but
    still invoke the command from within the function?
26) When I have terminal escape sequences in my prompt, why does bash
    wrap lines at the wrong column?
27) How can I find the value of a shell variable whose name is the value
    of another shell variable?
28) If I pipe the output of a command into `read variable', why doesn't
    the output show up in $variable when the read command finishes?
29) I have a bunch of shell scripts that use backslash-escaped characters
    in arguments to `echo'.  Bash doesn't interpret these characters.  Why
    not, and how can I make it understand them?
30) Why doesn't a while or for loop get suspended when I type ^Z?
31) How can I make the bash `time' reserved word print timing output that
    looks like the output from my system's /usr/bin/time?

Section F:  Things to watch out for on certain Unix versions

32) Why can't I use command line editing in my `cmdtool'?
33) I built bash on Solaris 2.  Why do globbing expansions and filename
    completion chop off the first few characters of each filename?
34) Why does bash dump core after I interrupt username completion or
    `~user' tilde expansion on a machine running NIS?
35) I'm running SVR4.2.  Why is the line erased every time I type `@'?
36) Why does bash report syntax errors when my C News scripts use a
    redirection before a subshell command?

Section G:  Where do I go from here?

37) How do I report bugs in bash, and where should I look for fixes and
    advice?
38) What kind of bash documentation is there?
39) What's coming in future versions?
40) What's on the bash `wish list'?
41) When will the next release appear?

----------
Section A:  The Basics

1)  What is it?

Bash is a Unix command interpreter (shell).  It is an implementation of
the Posix 1003.2 shell standard, and resembles the Korn and System V
shells.

Bash contains a number of enhancements over those shells, both
for interactive use and shell programming.  Features geared
toward interactive use include command line editing, command
history, job control, aliases, and prompt expansion.  Programming
features include additional variable expansions, shell
arithmetic, and a number of variables and options to control
shell behavior.

Bash was originally written by Brian Fox of the Free Software
Foundation.  The current developer and maintainer is Chet Ramey
of Case Western Reserve University.

2)  What's the latest version?

The latest version is 2.01, first made available on June 6, 1997.

3)  Where can I get it?

Bash is the GNU project's shell, and so is available from the
master GNU archive site, prep.ai.mit.edu, and its mirrors.  The
latest version is also available for FTP from slc2.ins.cwru.edu,
the maintainer's machine.  The following URLs tell how to get
version 2.01:

ftp://prep.ai.mit.edu/pub/gnu/bash-2.01.tar.gz
ftp://slc2.ins.cwru.edu/pub/dist/bash-2.01.tar.gz

Formatted versions of the documentation are available with the URLs:

ftp://prep.ai.mit.edu/pub/gnu/bash-doc-2.01.tar.gz
ftp://slc2.ins.cwru.edu/pub/dist/bash-doc-2.01.tar.gz

4)  On what machines will bash run?

Bash has been ported to nearly every version of UNIX.  All you
should have to do to build it on a machine for which a port
exists is to type `configure' and then `make'.  The build process
will attempt to discover the version of UNIX you have and tailor
itself accordingly, using a script created by GNU autoconf.

More information appears in the file `INSTALL' in the distribution.

5) Will bash run on operating systems other than Unix?

Configuration specifics for Unix-like systems such as QNX and
LynxOS are included in the distribution.  Previous versions of
bash have been ported to Minix, but I don't believe anyone has
built bash-2.x on Minix yet.

Bash has been ported to versions of Windows implementing the Win32
programming interface.  This includes Windows 95 and Windows NT.
The port was done by Cygnus Solutions as part of their GNU-Win32
project.  For more information about the project, look at the URL

http://www.cygnus.com/misc/gnu-win32

Cygnus has ported bash-1.14.7.  Maybe someday they (or I) will port
bash-2.01 (or later) to the GNU-Win32 environment.

D. J. Delorie has ported bash-1.14.7 to run under MS-DOS, as part of
the DJGPP project.  For more information on the project, see

http://www.delorie.com/djgpp/

I picked up a binary of bash-1.14.7 that is purported to work with
the DJGPP V2 environment from

ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2gnu/bsh1147b.zip

The corresponding source is

ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2gnu/bsh1147s.zip

A port of bash-1.12 is available for OS/2 from

ftp://hobbes.nmsu.edu/os2/unix/bash_112.zip

I haven't looked at it.

6) How can I build bash with gcc?

Bash configures to use gcc by default if it is available.  Read the
file INSTALL in the distribution for more information.

7)  How can I make bash my login shell?

Some machines let you use `chsh' to change your login shell.  Other
systems use `passwd -s'.  If one of these works for you, that's all
you need.  Note that many systems require the full pathname to a shell
to appear in /etc/shells before you can make it your login shell.  For
this, you may need the assistance of your friendly local system
administrator.

If you cannot do this, you can still use bash as your login shell, but
you need to perform some tricks.  The basic idea is to add a command
to your login shell's startup file to replace your login shell with
bash.

For example, if your login shell is csh or tcsh, and you have installed
bash in /usr/gnu/bin/bash, add the following line to ~/.login:

        if ( -f /usr/gnu/bin/bash ) exec /usr/gnu/bin/bash --login

(the `--login' tells bash that it is a login shell).

It's not a good idea to put this command into ~/.cshrc, because every
csh you run without the `-f' option, even ones started to run csh scripts,
reads that file.  If you must put the command in ~/.cshrc, use something
like

        if ( $?prompt ) exec /usr/gnu/bin/bash --login

to ensure that bash is exec'd only when the csh is interactive.

If your login shell is sh or ksh, you have to do two things.

First, create an empty file in your home directory named `.bash_profile'.
The existence of this file will prevent the exec'd bash from trying to
read ~/.profile, and re-execing itself over and over again.  ~/.bash_profile
is the first file bash tries to read initialization commands from when
it is invoked as a login shell.

Next, add a line similar to the above to ~/.profile:

        [ -f /usr/gnu/bin/bash ] && exec /usr/gnu/bin/bash --login

This will cause login shells to replace themselves with bash running as
a login shell.  Once you have this working, you can copy your initialization
code from ~/.profile to ~/.bash_profile.

8) I just changed my login shell to bash, and now I can't FTP into my
   machine.  Why not?

You must add the full pathname to bash to the file /etc/shells.  As
noted in the answer to the previous question, many systems require
this before you can make bash your login shell.

Most versions of ftpd use this file to prohibit `special' users
such as `uucp' and `news' from using FTP.

9)  What's the `POSIX 1003.2 standard'?

POSIX is a name originally coined by Richard Stallman for a
family of open system standards based on UNIX.  There are a
number of aspects ...

read more »