This is bashref.info, produced by makeinfo version 4.0f from
bashref.texi.

INFO-DIR-SECTION Utilities
START-INFO-DIR-ENTRY
* Bash: (bash).                     The GNU Bourne-Again SHell.
END-INFO-DIR-ENTRY

This text is a brief description of the features that are present in
the Bash shell.

This is Edition 2.5a, last updated 13 November 2001,
of `The GNU Bash Reference Manual',
for `Bash', Version 2.05a.

Copyright (C) 1991-2001 Free Software Foundation, Inc.

Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
are preserved on all copies.

Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided that the entire
resulting derived work is distributed under the terms of a permission
notice identical to this one.

Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions,
except that this permission notice may be stated in a translation approved
by the Free Software Foundation.


File: bashref.info,  Node: Bash Variables,  Prev: Bourne Shell Variables,  Up: Shell Variables

Bash Variables
==============

   These variables are set or used by Bash, but other shells do not
normally treat them specially.

   A few variables used by Bash are described in different chapters:
variables for controlling the job control facilities (*note Job Control
Variables::).

`BASH'
     The full pathname used to execute the current instance of Bash.

`BASH_ENV'
     If this variable is set when Bash is invoked to execute a shell
     script, its value is expanded and used as the name of a startup
     file to read before executing the script.  *Note Bash Startup
     Files::.

`BASH_VERSION'
     The version number of the current instance of Bash.

`BASH_VERSINFO'
     A readonly array variable (*note Arrays::) whose members hold
     version information for this instance of Bash.  The values
     assigned to the array members are as follows:

    `BASH_VERSINFO[0]'
          The major version number (the RELEASE).

    `BASH_VERSINFO[1]'
          The minor version number (the VERSION).

    `BASH_VERSINFO[2]'
          The patch level.

    `BASH_VERSINFO[3]'
          The build version.

    `BASH_VERSINFO[4]'
          The release status (e.g., BETA1).

    `BASH_VERSINFO[5]'
          The value of `MACHTYPE'.

`COLUMNS'
     Used by the `select' builtin command to determine the terminal
     width when printing selection lists.  Automatically set upon
     receipt of a `SIGWINCH'.

`COMP_CWORD'
     An index into `${COMP_WORDS}' of the word containing the current
     cursor position.  This variable is available only in shell
     functions invoked by the programmable completion facilities (*note
     Programmable Completion::).

`COMP_LINE'
     The current command line.  This variable is available only in
     shell functions and external commands invoked by the programmable
     completion facilities (*note Programmable Completion::).

`COMP_POINT'
     The index of the current cursor position relative to the beginning
     of the current command.  If the current cursor position is at the
     end of the current command, the value of this variable is equal to
     `${#COMP_LINE}'.  This variable is available only in shell
     functions and external commands invoked by the programmable
     completion facilities (*note Programmable Completion::).

`COMP_WORDS'
     An array variable consisting of the individual words in the
     current command line.  This variable is available only in shell
     functions invoked by the programmable completion facilities (*note
     Programmable Completion::).

`COMPREPLY'
     An array variable from which Bash reads the possible completions
     generated by a shell function invoked by the programmable
     completion facility (*note Programmable Completion::).

`DIRSTACK'
     An array variable containing the current contents of the directory
     stack.  Directories appear in the stack in the order they are
     displayed by the `dirs' builtin.  Assigning to members of this
     array variable may be used to modify directories already in the
     stack, but the `pushd' and `popd' builtins must be used to add and
     remove directories.  Assignment to this variable will not change
     the current directory.  If `DIRSTACK' is unset, it loses its
     special properties, even if it is subsequently reset.

`EUID'
     The numeric effective user id of the current user.  This variable
     is readonly.

`FCEDIT'
     The editor used as a default by the `-e' option to the `fc'
     builtin command.

`FIGNORE'
     A colon-separated list of suffixes to ignore when performing
     filename completion.  A file name whose suffix matches one of the
     entries in `FIGNORE' is excluded from the list of matched file
     names.  A sample value is `.o:~'

`FUNCNAME'
     The name of any currently-executing shell function.  This variable
     exists only when a shell function is executing.  Assignments to
     `FUNCNAME' have no effect and return an error status.  If
     `FUNCNAME' is unset, it loses its special properties, even if it
     is subsequently reset.

`GLOBIGNORE'
     A colon-separated list of patterns defining the set of filenames to
     be ignored by filename expansion.  If a filename matched by a
     filename expansion pattern also matches one of the patterns in
     `GLOBIGNORE', it is removed from the list of matches.

`GROUPS'
     An array variable containing the list of groups of which the
     current user is a member.  Assignments to `GROUPS' have no effect
     and return an error status.  If `GROUPS' is unset, it loses its
     special properties, even if it is subsequently reset.

`histchars'
     Up to three characters which control history expansion, quick
     substitution, and tokenization (*note History Interaction::).  The
     first character is the HISTORY EXPANSION character, that is, the
     character which signifies the start of a history expansion,
     normally `!'.  The second character is the character which
     signifies `quick substitution' when seen as the first character on
     a line, normally `^'.  The optional third character is the
     character which indicates that the remainder of the line is a
     comment when found as the first character of a word, usually `#'.
     The history comment character causes history substitution to be
     skipped for the remaining words on the line.  It does not
     necessarily cause the shell parser to treat the rest of the line
     as a comment.

`HISTCMD'
     The history number, or index in the history list, of the current
     command.  If `HISTCMD' is unset, it loses its special properties,
     even if it is subsequently reset.

`HISTCONTROL'
     A value of `ignorespace' means to not enter lines which begin with
     a space or tab into the history list.  A value of `ignoredups'
     means to not enter lines which match the last entered line.  A
     value of `ignoreboth' combines the two options.  Unset, or set to
     any other value than those above, means to save all lines on the
     history list.  The second and subsequent lines of a multi-line
     compound command are not tested, and are added to the history
     regardless of the value of `HISTCONTROL'.

`HISTFILE'
     The name of the file to which the command history is saved.  The
     default value is `~/.bash_history'.

`HISTFILESIZE'
     The maximum number of lines contained in the history file.  When
     this variable is assigned a value, the history file is truncated,
     if necessary, to contain no more than that number of lines.  The
     history file is also truncated to this size after writing it when
     an interactive shell exits.  The default value is 500.

`HISTIGNORE'
     A colon-separated list of patterns used to decide which command
     lines should be saved on the history list.  Each pattern is
     anchored at the beginning of the line and must match the complete
     line (no implicit `*' is appended).  Each pattern is tested
     against the line after the checks specified by `HISTCONTROL' are
     applied.  In addition to the normal shell pattern matching
     characters, `&' matches the previous history line.  `&' may be
     escaped using a backslash; the backslash is removed before
     attempting a match.  The second and subsequent lines of a
     multi-line compound command are not tested, and are added to the
     history regardless of the value of `HISTIGNORE'.

     `HISTIGNORE' subsumes the function of `HISTCONTROL'.  A pattern of
     `&' is identical to `ignoredups', and a pattern of `[ ]*' is
     identical to `ignorespace'.  Combining these two patterns,
     separating them with a colon, provides the functionality of
     `ignoreboth'.

`HISTSIZE'
     The maximum number of commands to remember on the history list.
     The default value is 500.

`HOSTFILE'
     Contains the name of a file in the same format as `/etc/hosts' that
     should be read when the shell needs to complete a hostname.  The
     list of possible hostname completions may be changed while the
     shell is running; the next time hostname completion is attempted
     after the value is changed, Bash adds the contents of the new file
     to the existing list.  If `HOSTFILE' is set, but has no value,
     Bash attempts to read `/etc/hosts' to obtain the list of possible
     hostname completions.  When `HOSTFILE' is unset, the hostname list
     is cleared.

`HOSTNAME'
     The name of the current host.

`HOSTTYPE'
     A string describing the machine Bash is running on.

`IGNOREEOF'
     Controls the action of the shell on receipt of an `EOF' character
     as the sole input.  If set, the value denotes the number of
     consecutive `EOF' characters that can be read as the first
     character on an input line before the shell will exit.  If the
     variable exists but does not have a numeric value (or has no
     value) then the default is 10.  If the variable does not exist,
     then `EOF' signifies the end of input to the shell.  This is only
     in effect for interactive shells.

`INPUTRC'
     The name of the Readline initialization file, overriding the
     default of `~/.inputrc'.

`LANG'
     Used to determine the locale category for any category not
     specifically selected with a variable starting with `LC_'.

`LC_ALL'
     This variable overrides the value of `LANG' and any other `LC_'
     variable specifying a locale category.

`LC_COLLATE'
     This variable determines the collation order used when sorting the
     results of filename expansion, and determines the behavior of
     range expressions, equivalence classes, and collating sequences
     within filename expansion and pattern matching (*note Filename
     Expansion::).

`LC_CTYPE'
     This variable determines the interpretation of characters and the
     behavior of character classes within filename expansion and pattern
     matching (*note Filename Expansion::).

`LC_MESSAGES'
     This variable determines the locale used to translate double-quoted
     strings preceded by a `$' (*note Locale Translation::).

`LC_NUMERIC'
     This variable determines the locale category used for number
     formatting.

`LINENO'
     The line number in the script or shell function currently
     executing.

`LINES'
     Used by the `select' builtin command to determine the column length
     for printing selection lists.  Automatically set upon receipt of a
     `SIGWINCH'.

`MACHTYPE'
     A string that fully describes the system type on which Bash is
     executing, in the standard GNU CPU-COMPANY-SYSTEM format.

`MAILCHECK'
     How often (in seconds) that the shell should check for mail in the
     files specified in the `MAILPATH' or `MAIL' variables.  The
     default is 60 seconds.  When it is time to check for mail, the
     shell does so before displaying the primary prompt.  If this
     variable is unset, or set to a value that is not a number greater
     than or equal to zero, the shell disables mail checking.

`OLDPWD'
     The previous working directory as set by the `cd' builtin.

`OPTERR'
     If set to the value 1, Bash displays error messages generated by
     the `getopts' builtin command.

`OSTYPE'
     A string describing the operating system Bash is running on.

`PIPESTATUS'
     An array variable (*note Arrays::) containing a list of exit
     status values from the processes in the most-recently-executed
     foreground pipeline (which may contain only a single command).

`POSIXLY_CORRECT'
     If this variable is in the environment when `bash' starts, the
     shell enters POSIX mode (*note Bash POSIX Mode::) before reading
     the startup files, as if the `--posix' invocation option had been
     supplied.  If it is set while the shell is running, `bash' enables
     POSIX mode, as if the command
          `set -o posix'

     had been executed.

`PPID'
     The process ID of the shell's parent process.  This variable is
     readonly.

`PROMPT_COMMAND'
     If set, the value is interpreted as a command to execute before
     the printing of each primary prompt (`$PS1').

`PS3'
     The value of this variable is used as the prompt for the `select'
     command.  If this variable is not set, the `select' command
     prompts with `#? '

`PS4'
     The value is the prompt printed before the command line is echoed
     when the `-x' option is set (*note The Set Builtin::).  The first
     character of `PS4' is replicated multiple times, as necessary, to
     indicate multiple levels of indirection.  The default is `+ '.

`PWD'
     The current working directory as set by the `cd' builtin.

`RANDOM'
     Each time this parameter is referenced, a random integer between 0
     and 32767 is generated.  Assigning a value to this variable seeds
     the random number generator.

`REPLY'
     The default variable for the `read' builtin.

`SECONDS'
     This variable expands to the number of seconds since the shell was
     started.  Assignment to this variable resets the count to the
     value assigned, and the expanded value becomes the value assigned
     plus the number of seconds since the assignment.

`SHELLOPTS'
     A colon-separated list of enabled shell options.  Each word in the
     list is a valid argument for the `-o' option to the `set' builtin
     command (*note The Set Builtin::).  The options appearing in
     `SHELLOPTS' are those reported as `on' by `set -o'.  If this
     variable is in the environment when Bash starts up, each shell
     option in the list will be enabled before reading any startup
     files.  This variable is readonly.

`SHLVL'
     Incremented by one each time a new instance of Bash is started.
     This is intended to be a count of how deeply your Bash shells are
     nested.

`TIMEFORMAT'
     The value of this parameter is used as a format string specifying
     how the timing information for pipelines prefixed with the `time'
     reserved word should be displayed.  The `%' character introduces an
     escape sequence that is expanded to a time value or other
     information.  The escape sequences and their meanings are as
     follows; the braces denote optional portions.

    `%%'
          A literal `%'.

    `%[P][l]R'
          The elapsed time in seconds.

    `%[P][l]U'
          The number of CPU seconds spent in user mode.

    `%[P][l]S'
          The number of CPU seconds spent in system mode.

    `%P'
          The CPU percentage, computed as (%U + %S) / %R.

     The optional P is a digit specifying the precision, the number of
     fractional digits after a decimal point.  A value of 0 causes no
     decimal point or fraction to be output.  At most three places
     after the decimal point may be specified; values of P greater than
     3 are changed to 3.  If P is not specified, the value 3 is used.

     The optional `l' specifies a longer format, including minutes, of
     the form MMmSS.FFs.  The value of P determines whether or not the
     fraction is included.

     If this variable is not set, Bash acts as if it had the value
          `$'\nreal\t%3lR\nuser\t%3lU\nsys\t%3lS''
     If the value is null, no timing information is displayed.  A
     trailing newline is added when the format string is displayed.

`TMOUT'
     If set to a value greater than zero, the value is interpreted as
     the number of seconds to wait for input after issuing the primary
     prompt when the shell is interactive.  Bash terminates after that
     number of seconds if input does not arrive.

`UID'
     The numeric real user id of the current user.  This variable is
     readonly.


File: bashref.info,  Node: Bash Features,  Next: Job Control,  Prev: Shell Variables,  Up: Top

Bash Features
*************

   This section describes features unique to Bash.

* Menu:

* Invoking Bash::		Command line options that you can give
				to Bash.
* Bash Startup Files::		When and how Bash executes scripts.
* Interactive Shells::		What an interactive shell is.
* Bash Conditional Expressions::	Primitives used in composing expressions for
				the `test' builtin.
* Shell Arithmetic::		Arithmetic on shell variables.
* Aliases::			Substituting one command for another.
* Arrays::			Array Variables.
* The Directory Stack::		History of visited directories.
* Printing a Prompt::		Controlling the PS1 string.
* The Restricted Shell::	A more controlled mode of shell execution.
* Bash POSIX Mode::		Making Bash behave more closely to what
				the POSIX standard specifies.


File: bashref.info,  Node: Invoking Bash,  Next: Bash Startup Files,  Up: Bash Features

Invoking Bash
=============

     bash [long-opt] [-ir] [-abefhkmnptuvxdBCDHP] [-o OPTION] [-O SHOPT_OPTION] [ARGUMENT ...]
     bash [long-opt] [-abefhkmnptuvxdBCDHP] [-o OPTION] [-O SHOPT_OPTION] -c STRING [ARGUMENT ...]
     bash [long-opt] -s [-abefhkmnptuvxdBCDHP] [-o OPTION] [-O SHOPT_OPTION] [ARGUMENT ...]

   In addition to the single-character shell command-line options
(*note The Set Builtin::), there are several multi-character options
that you can use.  These options must appear on the command line before
the single-character options in order for them to be recognized.

`--dump-po-strings'
     A list of all double-quoted strings preceded by `$' is printed on
     the standard ouput in the GNU `gettext' PO (portable object) file
     format.  Equivalent to `-D' except for the output format.

`--dump-strings'
     Equivalent to `-D'.

`--help'
     Display a usage message on standard output and exit sucessfully.

`--init-file FILENAME'
`--rcfile FILENAME'
     Execute commands from FILENAME (instead of `~/.bashrc') in an
     interactive shell.

`--login'
     Make this shell act as if it had been directly invoked by login.
     When the shell is interactive, this is equivalent to starting a
     login shell with `exec -l bash'.  When the shell is not
     interactive, the login shell startup files will be executed.
     `exec bash --login' will replace the current shell with a Bash
     login shell.  *Note Bash Startup Files::, for a description of the
     special behavior of a login shell.

`--noediting'
     Do not use the GNU Readline library (*note Command Line Editing::)
     to read  command lines when the shell is interactive.

`--noprofile'
     Don't load the system-wide startup file `/etc/profile' or any of
     the personal initialization files `~/.bash_profile',
     `~/.bash_login', or `~/.profile' when Bash is invoked as a login
     shell.

`--norc'
     Don't read the `~/.bashrc' initialization file in an interactive
     shell.  This is on by default if the shell is invoked as `sh'.

`--posix'
     Change the behavior of Bash where the default operation differs
     from the POSIX 1003.2 standard to match the standard.  This is
     intended to make Bash behave as a strict superset of that
     standard.  *Note Bash POSIX Mode::, for a description of the Bash
     POSIX mode.

`--restricted'
     Make the shell a restricted shell (*note The Restricted Shell::).

`--verbose'
     Equivalent to `-v'.  Print shell input lines as they're read.

`--version'
     Show version information for this instance of Bash on the standard
     output and exit successfully.

   There are several single-character options that may be supplied at
invocation which are not available with the `set' builtin.

`-c STRING'
     Read and execute commands from STRING after processing the
     options, then exit.  Any remaining arguments are assigned to the
     positional parameters, starting with `$0'.

`-i'
     Force the shell to run interactively.  Interactive shells are
     described in *Note Interactive Shells::.

`-r'
     Make the shell a restricted shell (*note The Restricted Shell::).

`-s'
     If this option is present, or if no arguments remain after option
     processing, then commands are read from the standard input.  This
     option allows the positional parameters to be set when invoking an
     interactive shell.

`-D'
     A list of all double-quoted strings preceded by `$' is printed on
     the standard ouput.  These are the strings that are subject to
     language translation when the current locale is not `C' or `POSIX'
     (*note Locale Translation::).  This implies the `-n' option; no
     commands will be executed.

`[-+]O [SHOPT_OPTION]'
     SHOPT_OPTION is one of the shell options accepted by the `shopt'
     builtin (*note Shell Builtin Commands::).  If SHOPT_OPTION is
     present, `-O' sets the value of that option; `+O' unsets it.  If
     SHOPT_OPTION is not supplied, the names and values of the shell
     options accepted by `shopt' are printed on the standard output.
     If the invocation option is `+O', the output is displayed in a
     format that may be reused as input.

`--'
     A `--' signals the end of options and disables further option
     processing.  Any arguments after the `--' are treated as filenames
     and arguments.

   A _login_ shell is one whose first character of argument zero is
`-', or one invoked with the `--login' option.

   An _interactive_ shell is one started without non-option arguments,
unless `-s' is specified, without specifying the `-c' option, and whose
input and output are both connected to terminals (as determined by
`isatty(3)'), or one started with the `-i' option.  *Note Interactive
Shells::, for more information.

   If arguments remain after option processing, and neither the `-c'
nor the `-s' option has been supplied, the first argument is assumed to
be the name of a file containing shell commands (*note Shell Scripts::).
When Bash is invoked in this fashion, `$0' is set to the name of the
file, and the positional parameters are set to the remaining arguments.
Bash reads and executes commands from this file, then exits.  Bash's
exit status is the exit status of the last command executed in the
script.  If no commands are executed, the exit status is 0.


File: bashref.info,  Node: Bash Startup Files,  Next: Interactive Shells,  Prev: Invoking Bash,  Up: Bash Features

Bash Startup Files
==================

   This section describs how Bash executes its startup files.  If any
of the files exist but cannot be read, Bash reports an error.  Tildes
are expanded in file names as described above under Tilde Expansion
(*note Tilde Expansion::).

   Interactive shells are described in *Note Interactive Shells::.

Invoked as an interactive login shell, or with `--login'
........................................................

   When Bash is invoked as an interactive login shell, or as a
non-interactive shell with the `--login' option, it first reads and
executes commands from the file `/etc/profile', if that file exists.
After reading that file, it looks for `~/.bash_profile',
`~/.bash_login', and `~/.profile', in that order, and reads and
executes commands from the first one that exists and is readable.  The
`--noprofile' option may be used when the shell is started to inhibit
this behavior.

   When a login shell exits, Bash reads and executes commands from the
file `~/.bash_logout', if it exists.

Invoked as an interactive non-login shell
.........................................

   When an interactive shell that is not a login shell is started, Bash
reads and executes commands from `~/.bashrc', if that file exists.
This may be inhibited by using the `--norc' option.  The `--rcfile
FILE' option will force Bash to read and execute commands from FILE
instead of `~/.bashrc'.

   So, typically, your `~/.bash_profile' contains the line
     `if [ -f ~/.bashrc ]; then . ~/.bashrc; fi'

after (or before) any login-specific initializations.

Invoked non-interactively
.........................

   When Bash is started non-interactively, to run a shell script, for
example, it looks for the variable `BASH_ENV' in the environment,
expands its value if it appears there, and uses the expanded value as
the name of a file to read and execute.  Bash behaves as if the
following command were executed:
     `if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi'

but the value of the `PATH' variable is not used to search for the file
name.

   As noted above, if a non-interactive shell is invoked with the
`--login' option, Bash attempts to read and execute commands from the
login shell startup files.

Invoked with name `sh'
......................

   If Bash is invoked with the name `sh', it tries to mimic the startup
behavior of historical versions of `sh' as closely as possible, while
conforming to the POSIX standard as well.

   When invoked as an interactive login shell, or as a non-interactive
shell with the `--login' option, it first attempts to read and execute
commands from `/etc/profile' and `~/.profile', in that order.  The
`--noprofile' option may be used to inhibit this behavior.  When
invoked as an interactive shell with the name `sh', Bash looks for the
variable `ENV', expands its value if it is defined, and uses the
expanded value as the name of a file to read and execute.  Since a
shell invoked as `sh' does not attempt to read and execute commands
from any other startup files, the `--rcfile' option has no effect.  A
non-interactive shell invoked with the name `sh' does not attempt to
read any other startup files.

   When invoked as `sh', Bash enters POSIX mode after the startup files
are read.

Invoked in POSIX mode
.....................

   When Bash is started in POSIX mode, as with the `--posix' command
line option, it follows the POSIX standard for startup files.  In this
mode, interactive shells expand the `ENV' variable and commands are
read and executed from the file whose name is the expanded value.  No
other startup files are read.

Invoked by remote shell daemon
..............................

   Bash attempts to determine when it is being run by the remote shell
daemon, usually `rshd'.  If Bash determines it is being run by rshd, it
reads and executes commands from `~/.bashrc', if that file exists and
is readable.  It will not do this if invoked as `sh'.  The `--norc'
option may be used to inhibit this behavior, and the `--rcfile' option
may be used to force another file to be read, but `rshd' does not
generally invoke the shell with those options or allow them to be
specified.

Invoked with unequal effective and real UID/GIDs
................................................

   If Bash is started with the effective user (group) id not equal to
the real user (group) id, and the `-p' option is not supplied, no
startup files are read, shell functions are not inherited from the
environment, the `SHELLOPTS' variable, if it appears in the
environment, is ignored, and the effective user id is set to the real
user id.  If the `-p' option is supplied at invocation, the startup
behavior is the same, but the effective user id is not reset.


File: bashref.info,  Node: Interactive Shells,  Next: Bash Conditional Expressions,  Prev: Bash Startup Files,  Up: Bash Features

Interactive Shells
==================

* Menu:

* What is an Interactive Shell?::	What determines whether a shell is Interactive.
* Is this Shell Interactive?::	How to tell if a shell is interactive.
* Interactive Shell Behavior::	What changes in a interactive shell?


File: bashref.info,  Node: What is an Interactive Shell?,  Next: Is this Shell Interactive?,  Up: Interactive Shells

What is an Interactive Shell?
-----------------------------

   An interactive shell is one started without non-option arguments,
unless `-s' is specified, without specifiying the `-c' option, and
whose input and output are both connected to terminals (as determined
by `isatty(3)'), or one started with the `-i' option.

   An interactive shell generally reads from and writes to a user's
terminal.

   The `-s' invocation option may be used to set the positional
parameters when an interactive shell is started.


File: bashref.info,  Node: Is this Shell Interactive?,  Next: Interactive Shell Behavior,  Prev: What is an Interactive Shell?,  Up: Interactive Shells

Is this Shell Interactive?
--------------------------

   To determine within a startup script whether or not Bash is running
interactively, test the value of the `-' special parameter.  It
contains `i' when the shell is interactive.  For example:

     case "$-" in
     *i*)	echo This shell is interactive ;;
     *)	echo This shell is not interactive ;;
     esac

   Alternatively, startup scripts may examine the variable `PS1'; it is
unset in non-interactive shells, and set in interactive shells.  Thus:

     if [ -z "$PS1" ]; then
             echo This shell is not interactive
     else
             echo This shell is interactive
     fi


File: bashref.info,  Node: Interactive Shell Behavior,  Prev: Is this Shell Interactive?,  Up: Interactive Shells

Interactive Shell Behavior
--------------------------

   When the shell is running interactively, it changes its behavior in
several ways.

  1. Startup files are read and executed as described in *Note Bash
     Startup Files::.

  2. Job Control (*note Job Control::) is enabled by default.  When job
     control is in effect, Bash ignores the keyboard-generated job
     control signals `SIGTTIN', `SIGTTOU', and `SIGTSTP'.

  3. Bash expands and displays `PS1' before reading the first line of a
     command, and expands and displays `PS2' before reading the second
     and subsequent lines of a multi-line command.

  4. Bash executes the value of the `PROMPT_COMMAND' variable as a
     command before printing the primary prompt, `$PS1' (*note Bash
     Variables::).

  5. Readline (*note Command Line Editing::) is used to read commands
     from the user's terminal.

  6. Bash inspects the value of the `ignoreeof' option to `set -o'
     instead of exiting immediately when it receives an `EOF' on its
     standard input when reading a command (*note The Set Builtin::).

  7. Command history (*note Bash History Facilities::) and history
     expansion (*note History Interaction::) are enabled by default.
     Bash will save the command history to the file named by `$HISTFILE'
     when an interactive shell exits.

  8. Alias expansion (*note Aliases::) is performed by default.

  9. In the absence of any traps, Bash ignores `SIGTERM' (*note
     Signals::).

 10. In the absence of any traps, `SIGINT' is caught and handled
     ((*note Signals::).  `SIGINT' will interrupt some shell builtins.

 11. An interactive login shell sends a `SIGHUP' to all jobs on exit if
     the `hupoxexit' shell option has been enabled (*note Signals::).

 12. The `-n' invocation option is ignored, and `set -n' has no effect
     (*note The Set Builtin::).

 13. Bash will check for mail periodically, depending on the values of
     the `MAIL', `MAILPATH', and `MAILCHECK' shell variables (*note
     Bash Variables::).

 14. Expansion errors due to references to unbound shell variables after
     `set -u' has been enabled will not cause the shell to exit (*note
     The Set Builtin::).

 15. The shell will not exit on expansion errors caused by VAR being
     unset or null in `${VAR:?WORD}' expansions (*note Shell Parameter
     Expansion::).

 16. Redirection errors encountered by shell builtins will not cause the
     shell to exit.

 17. When running in POSIX mode, a special builtin returning an error
     status will not cause the shell to exit (*note Bash POSIX Mode::).

 18. A failed `exec' will not cause the shell to exit (*note Bourne
     Shell Builtins::).

 19. Parser syntax errors will not cause the shell to exit.

 20. Simple spelling correction for directory arguments to the `cd'
     builtin is enabled by default (see the description of the `cdspell'
     option to the `shopt' builtin in *Note Bash Builtins::).

 21. The shell will check the value of the `TMOUT' variable and exit if
     a command is not read within the specified number of seconds after
     printing `$PS1' (*note Bash Variables::).



File: bashref.info,  Node: Bash Conditional Expressions,  Next: Shell Arithmetic,  Prev: Interactive Shells,  Up: Bash Features

Bash Conditional Expressions
============================

   Conditional expressions are used by the `[[' compound command and
the `test' and `[' builtin commands.

   Expressions may be unary or binary.  Unary expressions are often
used to examine the status of a file.  There are string operators and
numeric comparison operators as well.  If the FILE argument to one of
the primaries is of the form `/dev/fd/N', then file descriptor N is
checked.  If the FILE argument to one of the primaries is one of
`/dev/stdin', `/dev/stdout', or `/dev/stderr', file descriptor 0, 1, or
2, respectively, is checked.

`-a FILE'
     True if FILE exists.

`-b FILE'
     True if FILE exists and is a block special file.

`-c FILE'
     True if FILE exists and is a character special file.

`-d FILE'
     True if FILE exists and is a directory.

`-e FILE'
     True if FILE exists.

`-f FILE'
     True if FILE exists and is a regular file.

`-g FILE'
     True if FILE exists and its set-group-id bit is set.

`-h FILE'
     True if FILE exists and is a symbolic link.

`-k FILE'
     True if FILE exists and its "sticky" bit is set.

`-p FILE'
     True if FILE exists and is a named pipe (FIFO).

`-r FILE'
     True if FILE exists and is readable.

`-s FILE'
     True if FILE exists and has a size greater than zero.

`-t FD'
     True if file descriptor FD is open and refers to a terminal.

`-u FILE'
     True if FILE exists and its set-user-id bit is set.

`-w FILE'
     True if FILE exists and is writable.

`-x FILE'
     True if FILE exists and is executable.

`-O FILE'
     True if FILE exists and is owned by the effective user id.

`-G FILE'
     True if FILE exists and is owned by the effective group id.

`-L FILE'
     True if FILE exists and is a symbolic link.

`-S FILE'
     True if FILE exists and is a socket.

`-N FILE'
     True if FILE exists and has been modified since it was last read.

`FILE1 -nt FILE2'
     True if FILE1 is newer (according to modification date) than FILE2.

`FILE1 -ot FILE2'
     True if FILE1 is older than FILE2.

`FILE1 -ef FILE2'
     True if FILE1 and FILE2 have the same device and inode numbers.

`-o OPTNAME'
     True if shell option OPTNAME is enabled.  The list of options
     appears in the description of the `-o' option to the `set' builtin
     (*note The Set Builtin::).

`-z STRING'
     True if the length of STRING is zero.

`-n STRING'
`STRING'
     True if the length of STRING is non-zero.

`STRING1 == STRING2'
     True if the strings are equal.  `=' may be used in place of `=='.

`STRING1 != STRING2'
     True if the strings are not equal.

`STRING1 < STRING2'
     True if STRING1 sorts before STRING2 lexicographically in the
     current locale.

`STRING1 > STRING2'
     True if STRING1 sorts after STRING2 lexicographically in the
     current locale.

`ARG1 OP ARG2'
     `OP' is one of `-eq', `-ne', `-lt', `-le', `-gt', or `-ge'.  These
     arithmetic binary operators return true if ARG1 is equal to, not
     equal to, less than, less than or equal to, greater than, or
     greater than or equal to ARG2, respectively.  ARG1 and ARG2 may be
     positive or negative integers.


File: bashref.info,  Node: Shell Arithmetic,  Next: Aliases,  Prev: Bash Conditional Expressions,  Up: Bash Features

Shell Arithmetic
================

   The shell allows arithmetic expressions to be evaluated, as one of
the shell expansions or by the `let' builtin.

   Evaluation is done in long integers with no check for overflow,
though division by 0 is trapped and flagged as an error.  The operators
and their precedence and associativity are the same as in the C
language.  The following list of operators is grouped into levels of
equal-precedence operators.  The levels are listed in order of
decreasing precedence.

`ID++ ID--'
     variable post-increment and post-decrement

`++ID --ID'
     variable pre-increment and pre-decrement

`- +'
     unary minus and plus

`! ~'
     logical and bitwise negation

`**'
     exponentiation

`* / %'
     multiplication, division, remainder

`+ -'
     addition, subtraction

`<< >>'
     left and right bitwise shifts

`<= >= < >'
     comparison

`== !='
     equality and inequality

`&'
     bitwise AND

`^'
     bitwise exclusive OR

`|'
     bitwise OR

`&&'
     logical AND

`||'
     logical OR

`expr ? expr : expr'
     conditional evaluation

`= *= /= %= += -= <<= >>= &= ^= |='
     assignment

`expr1 , expr2'
     comma

   Shell variables are allowed as operands; parameter expansion is
performed before the expression is evaluated.  Within an expression,
shell variables may also be referenced by name without using the
parameter expansion syntax.  The value of a variable is evaluated as an
arithmetic expression when it is referenced.  A shell variable need not
have its integer attribute turned on to be used in an expression.

   Constants with a leading 0 are interpreted as octal numbers.  A
leading `0x' or `0X' denotes hexadecimal.  Otherwise, numbers take the
form [BASE`#']N, where BASE is a decimal number between 2 and 64
representing the arithmetic base, and N is a number in that base.  If
BASE`#' is omitted, then base 10 is used.  The digits greater than 9
are represented by the lowercase letters, the uppercase letters, `@',
and `_', in that order.  If BASE is less than or equal to 36, lowercase
and uppercase letters may be used interchangably to represent numbers
between 10 and 35.

   Operators are evaluated in order of precedence.  Sub-expressions in
parentheses are evaluated first and may override the precedence rules
above.


File: bashref.info,  Node: Aliases,  Next: Arrays,  Prev: Shell Arithmetic,  Up: Bash Features

Aliases
=======

   ALIASES allow a string to be substituted for a word when it is used
as the first word of a simple command.  The shell maintains a list of
aliases that may be set and unset with the `alias' and `unalias'
builtin commands.

   The first word of each simple command, if unquoted, is checked to see
if it has an alias.  If so, that word is replaced by the text of the
alias.  The alias name and the replacement text may contain any valid
shell input, including shell metacharacters, with the exception that
the alias name may not contain `='.  The first word of the replacement
text is tested for aliases, but a word that is identical to an alias
being expanded is not expanded a second time.  This means that one may
alias `ls' to `"ls -F"', for instance, and Bash does not try to
recursively expand the replacement text. If the last character of the
alias value is a space or tab character, then the next command word
following the alias is also checked for alias expansion.

   Aliases are created and listed with the `alias' command, and removed
with the `unalias' command.

   There is no mechanism for using arguments in the replacement text,
as in `csh'.  If arguments are needed, a shell function should be used
(*note Shell Functions::).

   Aliases are not expanded when the shell is not interactive, unless
the `expand_aliases' shell option is set using `shopt' (*note Bash
Builtins::).

   The rules concerning the definition and use of aliases are somewhat
confusing.  Bash always reads at least one complete line of input
before executing any of the commands on that line.  Aliases are
expanded when a command is read, not when it is executed.  Therefore, an
alias definition appearing on the same line as another command does not
take effect until the next line of input is read.  The commands
following the alias definition on that line are not affected by the new
alias.  This behavior is also an issue when functions are executed.
Aliases are expanded when a function definition is read, not when the
function is executed, because a function definition is itself a
compound command.  As a consequence, aliases defined in a function are
not available until after that function is executed.  To be safe,
always put alias definitions on a separate line, and do not use `alias'
in compound commands.

   For almost every purpose, shell functions are preferred over aliases.


File: bashref.info,  Node: Arrays,  Next: The Directory Stack,  Prev: Aliases,  Up: Bash Features

Arrays
======

   Bash provides one-dimensional array variables.  Any variable may be
used as an array; the `declare' builtin will explicitly declare an
array.  There is no maximum limit on the size of an array, nor any
requirement that members be indexed or assigned contiguously.  Arrays
are zero-based.

   An array is created automatically if any variable is assigned to
using the syntax
     name[SUBSCRIPT]=VALUE

The SUBSCRIPT is treated as an arithmetic expression that must evaluate
to a number greater than or equal to zero.  To explicitly declare an
array, use
     declare -a NAME

The syntax
     declare -a NAME[SUBSCRIPT]

is also accepted; the SUBSCRIPT is ignored.  Attributes may be
specified for an array variable using the `declare' and `readonly'
builtins.  Each attribute applies to all members of an array.

   Arrays are assigned to using compound assignments of the form
     name=(value1 ... valueN)

where each VALUE is of the form `[[SUBSCRIPT]=]'STRING.  If the
optional subscript is supplied, that index is assigned to; otherwise
the index of the element assigned is the last index assigned to by the
statement plus one.  Indexing starts at zero.  This syntax is also
accepted by the `declare' builtin.  Individual array elements may be
assigned to using the `name['SUBSCRIPT`]='VALUE syntax introduced above.

   Any element of an array may be referenced using
`${name['SUBSCRIPT`]}'.  The braces are required to avoid conflicts
with the shell's filename expansion operators.  If the SUBSCRIPT is `@'
or `*', the word expands to all members of the array NAME.  These
subscripts differ only when the word appears within double quotes.  If
the word is double-quoted, `${name[*]}' expands to a single word with
the value of each array member separated by the first character of the
`IFS' variable, and `${name[@]}' expands each element of NAME to a
separate word.  When there are no array members, `${name[@]}' expands
to nothing.  This is analogous to the expansion of the special
parameters `@' and `*'.  `${#name['SUBSCRIPT`]}' expands to the length
of `${name['SUBSCRIPT`]}'.  If SUBSCRIPT is `@' or `*', the expansion
is the number of elements in the array.  Referencing an array variable
without a subscript is equivalent to referencing element zero.

   The `unset' builtin is used to destroy arrays.  `unset'
NAME[SUBSCRIPT] destroys the array element at index SUBSCRIPT.  `unset'
NAME, where NAME is an array, removes the entire array. A subscript of
`*' or `@' also removes the entire array.

   The `declare', `local', and `readonly' builtins each accept a `-a'
option to specify an array.  The `read' builtin accepts a `-a' option
to assign a list of words read from the standard input to an array, and
can read values from the standard input into individual array elements.
The `set' and `declare' builtins display array values in a way that
allows them to be reused as input.


File: bashref.info,  Node: The Directory Stack,  Next: Printing a Prompt,  Prev: Arrays,  Up: Bash Features

The Directory Stack
===================

* Menu:

* Directory Stack Builtins::		Bash builtin commands to manipulate
					the directory stack.

   The directory stack is a list of recently-visited directories.  The
`pushd' builtin adds directories to the stack as it changes the current
directory, and the `popd' builtin removes specified directories from
the stack and changes the current directory to the directory removed.
The `dirs' builtin displays the contents of the directory stack.

   The contents of the directory stack are also visible as the value of
the `DIRSTACK' shell variable.


File: bashref.info,  Node: Directory Stack Builtins,  Up: The Directory Stack

Directory Stack Builtins
------------------------

`dirs'
          dirs [+N | -N] [-clpv]
     Display the list of currently remembered directories.  Directories
     are added to the list with the `pushd' command; the `popd' command
     removes directories from the list.
    `+N'
          Displays the Nth directory (counting from the left of the
          list printed by `dirs' when invoked without options), starting
          with zero.

    `-N'
          Displays the Nth directory (counting from the right of the
          list printed by `dirs' when invoked without options), starting
          with zero.

    `-c'
          Clears the directory stack by deleting all of the elements.

    `-l'
          Produces a longer listing; the default listing format uses a
          tilde to denote the home directory.

    `-p'
          Causes `dirs' to print the directory stack with one entry per
          line.

    `-v'
          Causes `dirs' to print the directory stack with one entry per
          line, prefixing each entry with its index in the stack.

`popd'
          popd [+N | -N] [-n]

     Remove the top entry from the directory stack, and `cd' to the new
     top directory.  When no arguments are given, `popd' removes the
     top directory from the stack and performs a `cd' to the new top
     directory.  The elements are numbered from 0 starting at the first
     directory listed with `dirs'; i.e., `popd' is equivalent to `popd
     +0'.
    `+N'
          Removes the Nth directory (counting from the left of the list
          printed by `dirs'), starting with zero.

    `-N'
          Removes the Nth directory (counting from the right of the
          list printed by `dirs'), starting with zero.

    `-n'
          Suppresses the normal change of directory when removing
          directories from the stack, so that only the stack is
          manipulated.

`pushd'
          pushd [DIR | +N | -N] [-n]

     Save the current directory on the top of the directory stack and
     then `cd' to DIR.  With no arguments, `pushd' exchanges the top
     two directories.

    `+N'
          Brings the Nth directory (counting from the left of the list
          printed by `dirs', starting with zero) to the top of the list
          by rotating the stack.

    `-N'
          Brings the Nth directory (counting from the right of the list
          printed by `dirs', starting with zero) to the top of the list
          by rotating the stack.

    `-n'
          Suppresses the normal change of directory when adding
          directories to the stack, so that only the stack is
          manipulated.

    `DIR'
          Makes the current working directory be the top of the stack,
          and then executes the equivalent of ``cd' DIR'.  `cd's to DIR.


File: bashref.info,  Node: Printing a Prompt,  Next: The Restricted Shell,  Prev: The Directory Stack,  Up: Bash Features

Controlling the Prompt
======================

   The value of the variable `PROMPT_COMMAND' is examined just before
Bash prints each primary prompt.  If `PROMPT_COMMAND' is set and has a
non-null value, then the value is executed just as if it had been typed
on the command line.

   In addition, the following table describes the special characters
which can appear in the prompt variables:

`\a'
     A bell character.

`\d'
     The date, in "Weekday Month Date" format (e.g., "Tue May 26").

`\e'
     An escape character.

`\h'
     The hostname, up to the first `.'.

`\H'
     The hostname.

`\j'
     The number of jobs currently managed by the shell.

`\l'
     The basename of the shell's terminal device name.

`\n'
     A newline.

`\r'
     A carriage return.

`\s'
     The name of the shell, the basename of `$0' (the portion following
     the final slash).

`\t'
     The time, in 24-hour HH:MM:SS format.

`\T'
     The time, in 12-hour HH:MM:SS format.

`\@'
     The time, in 12-hour am/pm format.

`\A'
     The time, in 24-hour HH:MM format.

`\u'
     The username of the current user.

`\v'
     The version of Bash (e.g., 2.00)

`\V'
     The release of Bash, version + patchlevel (e.g., 2.00.0)

`\w'
     The current working directory.

`\W'
     The basename of `$PWD'.

`\!'
     The history number of this command.

`\#'
     The command number of this command.

`\$'
     If the effective uid is 0, `#', otherwise `$'.

`\NNN'
     The character whose ASCII code is the octal value NNN.

`\\'
     A backslash.

`\['
     Begin a sequence of non-printing characters.  This could be used to
     embed a terminal control sequence into the prompt.

`\]'
     End a sequence of non-printing characters.

   The command number and the history number are usually different: the
history number of a command is its position in the history list, which
may include commands restored from the history file (*note Bash History
Facilities::), while the command number is the position in the sequence
of commands executed during the current shell session.

   After the string is decoded, it is expanded via parameter expansion,
command substitution, arithmetic expansion, and quote removal, subject
to the value of the `promptvars' shell option (*note Bash Builtins::).

