| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This section describes features unique to Bash.
| 6.1 Invoking Bash | Command line options that you can give to Bash. | |
| 6.2 Bash Startup Files | When and how Bash executes scripts. | |
| 6.3 Interactive Shells | What an interactive shell is. | |
| 6.4 Bash Conditional Expressions | Primitives used in composing expressions for
the test builtin.
| |
| 6.5 Shell Arithmetic | Arithmetic on shell variables. | |
| 6.6 Aliases | Substituting one command for another. | |
| 6.7 Arrays | Array Variables. | |
| 6.8 The Directory Stack | History of visited directories. | |
| 6.9 Controlling the Prompt | Controlling the PS1 string. | |
| 6.10 The Restricted Shell | A more controlled mode of shell execution. | |
| 6.11 Bash POSIX Mode | Making Bash behave more closely to what the POSIX standard specifies. |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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 (see section 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 to be recognized.
--debuggerArrange for the debugger profile to be executed before the shell
starts. Turns on extended debugging mode (see The Shopt Builtin
for a description of the extdebug option to the shopt
builtin) and shell function tracing
(see The Set Builtin for a description of the -o functrace
option).
--dump-po-stringsA list of all double-quoted strings preceded by `$'
is printed on the standard output
in the GNU gettext PO (portable object) file format.
Equivalent to `-D' except for the output format.
--dump-stringsEquivalent to `-D'.
--helpDisplay a usage message on standard output and exit successfully.
--init-file filename--rcfile filenameExecute commands from filename (instead of `~/.bashrc') in an interactive shell.
--loginEquivalent to `-l'.
--noeditingDo not use the GNU Readline library (see section Command Line Editing) to read command lines when the shell is interactive.
--noprofileDon'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.
--norcDon't read the `~/.bashrc' initialization file in an
interactive shell. This is on by default if the shell is
invoked as sh.
--posixChange the behavior of Bash where the default operation differs from the POSIX standard to match the standard. This is intended to make Bash behave as a strict superset of that standard. See section Bash POSIX Mode, for a description of the Bash POSIX mode.
--restrictedMake the shell a restricted shell (see section The Restricted Shell).
--verboseEquivalent to `-v'. Print shell input lines as they're read.
--versionShow 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 stringRead and execute commands from string after processing the
options, then exit. Any remaining arguments are assigned to the
positional parameters, starting with $0.
-iForce the shell to run interactively. Interactive shells are described in Interactive Shells.
-lMake 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 -l' or `exec bash --login' will replace the current shell with a Bash login shell. See section Bash Startup Files, for a description of the special behavior of a login shell.
-rMake the shell a restricted shell (see section The Restricted Shell).
-sIf 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.
-DA list of all double-quoted strings preceded by `$'
is printed on the standard output.
These are the strings that
are subject to language translation when the current locale
is not C or POSIX (see section Locale-Specific 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 (see section The Shopt Builtin).
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. See section 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 (see section 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.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This section describes 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 (see section Tilde Expansion).
Interactive shells are described in Interactive Shells.
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.
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
|
after (or before) any login-specific initializations.
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:
|
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.
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.
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.
Bash attempts to determine when it is being run with its standard input
connected to a a network connection, as if by the remote shell
daemon, usually rshd, or the secure shell daemon sshd.
If Bash determines it is being run in
this fashion, 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.
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.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| 6.3.1 What is an Interactive Shell? | What determines whether a shell is Interactive. | |
| 6.3.2 Is this Shell Interactive? | How to tell if a shell is interactive. | |
| 6.3.3 Interactive Shell Behavior | What changes in a interactive shell? |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
An interactive shell
is one started without non-option arguments, unless `-s' is
specified, without specifying the `-c' option, and
whose input and error 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.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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
|
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
When the shell is running interactively, it changes its behavior in several ways.
SIGTTIN, SIGTTOU, and SIGTSTP.
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.
PROMPT_COMMAND variable as a command
before printing the primary prompt, $PS1
(see section Bash Variables).
ignoreeof option to set -o
instead of exiting immediately when it receives an EOF on its
standard input when reading a command (see section The Set Builtin).
$HISTFILE
when an interactive shell exits.
SIGTERM
(see section Signals).
SIGINT is caught and handled
((see section Signals).
SIGINT will interrupt some shell builtins.
SIGHUP to all jobs on exit
if the huponexit shell option has been enabled (see section Signals).
MAIL, MAILPATH, and MAILCHECK shell variables
(see section Bash Variables).
${var:?word} expansions
(see section Shell Parameter Expansion).
exec will not cause the shell to exit
(see section Bourne Shell Builtins).
cd
builtin is enabled by default (see the description of the cdspell
option to the shopt builtin in The Shopt Builtin).
TMOUT variable and exit
if a command is not read within the specified number of seconds after
printing $PS1 (see section Bash Variables).
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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.
Unless otherwise specified, primaries that operate on files follow symbolic links and operate on the target of the link, rather than the link itself.
-a fileTrue if file exists.
-b fileTrue if file exists and is a block special file.
-c fileTrue if file exists and is a character special file.
-d fileTrue if file exists and is a directory.
-e fileTrue if file exists.
-f fileTrue if file exists and is a regular file.
-g fileTrue if file exists and its set-group-id bit is set.
-h fileTrue if file exists and is a symbolic link.
-k fileTrue if file exists and its "sticky" bit is set.
-p fileTrue if file exists and is a named pipe (FIFO).
-r fileTrue if file exists and is readable.
-s fileTrue if file exists and has a size greater than zero.
-t fdTrue if file descriptor fd is open and refers to a terminal.
-u fileTrue if file exists and its set-user-id bit is set.
-w fileTrue if file exists and is writable.
-x fileTrue if file exists and is executable.
-O fileTrue if file exists and is owned by the effective user id.
-G fileTrue if file exists and is owned by the effective group id.
-L fileTrue if file exists and is a symbolic link.
-S fileTrue if file exists and is a socket.
-N fileTrue if file exists and has been modified since it was last read.
file1 -nt file2True if file1 is newer (according to modification date) than file2, or if file1 exists and file2 does not.
file1 -ot file2True if file1 is older than file2, or if file2 exists and file1 does not.
file1 -ef file2True if file1 and file2 refer to the same device and inode numbers.
-o optnameTrue if shell option optname is enabled.
The list of options appears in the description of the `-o'
option to the set builtin (see section The Set Builtin).
-z stringTrue if the length of string is zero.
-n stringstringTrue if the length of string is non-zero.
string1 == string2True if the strings are equal. `=' may be used in place of `==' for strict POSIX compliance.
string1 != string2True if the strings are not equal.
string1 < string2True if string1 sorts before string2 lexicographically in the current locale.
string1 > string2True if string1 sorts after string2 lexicographically in the current locale.
arg1 OP arg2OP 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.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The shell allows arithmetic expressions to be evaluated, as one of
the shell expansions or by the let and the `-i' option
to the declare builtins.
Evaluation is done in fixed-width integers with no check for overflow, though division by 0 is trapped and flagged as an error. The operators and their precedence, associativity, and values 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 --idvariable 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 : exprconditional operator
= *= /= %= += -= <<= >>= &= ^= |=assignment
expr1 , expr2comma
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. A shell variable that is null or unset evaluates to 0 when referenced by name without using the parameter expansion syntax. The value of a variable is evaluated as an arithmetic expression when it is referenced, or when a variable which has been given the integer attribute using `declare -i' is assigned a value. A null value evaluates to 0. 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 interchangeably 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.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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 characters `/', `$', ``', `=' and any of the
shell metacharacters or quoting characters listed above may not appear
in an alias name.
The replacement text may contain any valid
shell input, including shell metacharacters.
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
(see section Shell Functions).
Aliases are not expanded when the shell is not interactive,
unless the expand_aliases shell option is set using
shopt (see section The Shopt Builtin).
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.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Bash provides one-dimensional indexed and associative array variables.
Any variable may be used as an indexed 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.
Indexed arrays are referenced using integers (including arithmetic
expressions (see section Shell Arithmetic) and are zero-based;
associative arrays use arbitrary strings.
An indexed 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.
Associative arrays are created using
declare -A name. |
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.
Indexed array assignments do not require the bracket and subscript.
When assigning to indexed arrays, 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.
When assigning to an associative array, the subscript is required.
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.
If the double-quoted expansion occurs within a word, the expansion of
the first parameter is joined with the beginning part of the original
word, and the expansion of the last parameter is joined with the last
part of the original word.
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 with a subscript of 0.
The unset builtin is used to destroy arrays.
unset name[subscript]
destroys the array element at index subscript.
Care must be taken to avoid unwanted side effects caused by filename
generation.
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 indexed
array and a `-A' option to specify an associative 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.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| 6.8.1 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.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
dirsdirs [+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.
+NDisplays the Nth directory (counting from the left of the
list printed by dirs when invoked without options), starting
with zero.
-NDisplays the Nth directory (counting from the right of the
list printed by dirs when invoked without options), starting
with zero.
-cClears the directory stack by deleting all of the elements.
-lProduces a longer listing; the default listing format uses a tilde to denote the home directory.
-pCauses dirs to print the directory stack with one entry per
line.
-vCauses dirs to print the directory stack with one entry per
line, prefixing each entry with its index in the stack.
popdpopd [+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.
+NRemoves the Nth directory (counting from the left of the
list printed by dirs), starting with zero.
-NRemoves the Nth directory (counting from the right of the
list printed by dirs), starting with zero.
-nSuppresses the normal change of directory when removing directories from the stack, so that only the stack is manipulated.
pushdpushd [-n] [+N | -N | dir ] |
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.
-nSuppresses the normal change of directory when adding directories to the stack, so that only the stack is manipulated.
+NBrings 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.
-NBrings 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.
dirMakes the current working directory be the top of the stack, and then
executes the equivalent of `cd dir'.
cds to dir.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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:
\aA bell character.
\dThe date, in "Weekday Month Date" format (e.g., "Tue May 26").
\D{format}The format is passed to strftime(3) and the result is inserted
into the prompt string; an empty format results in a locale-specific
time representation. The braces are required.
\eAn escape character.
\hThe hostname, up to the first `.'.
\HThe hostname.
\jThe number of jobs currently managed by the shell.
\lThe basename of the shell's terminal device name.
\nA newline.
\rA carriage return.
\sThe name of the shell, the basename of $0 (the portion
following the final slash).
\tThe time, in 24-hour HH:MM:SS format.
\TThe time, in 12-hour HH:MM:SS format.
\@The time, in 12-hour am/pm format.
\AThe time, in 24-hour HH:MM format.
\uThe username of the current user.
\vThe version of Bash (e.g., 2.00)
\VThe release of Bash, version + patchlevel (e.g., 2.00.0)
\wThe current working directory, with $HOME abbreviated with a tilde
(uses the $PROMPT_DIRTRIM variable).
\WThe basename of $PWD, with $HOME abbreviated with a tilde.
\!The history number of this command.
\#The command number of this command.
\$If the effective uid is 0, #, otherwise $.
\nnnThe 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 (see section 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 (see section Bash Builtin Commands).
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If Bash is started with the name rbash, or the
`--restricted'
or
`-r'
option is supplied at invocation, the shell becomes restricted.
A restricted shell is used to
set up an environment more controlled than the standard shell.
A restricted shell behaves identically to bash
with the exception that the following are disallowed or not performed:
cd builtin.
SHELL, PATH,
ENV, or BASH_ENV variables.
.
builtin command.
hash builtin command.
SHELLOPTS from the shell environment at startup.
exec builtin to replace the shell with another command.
enable builtin.
enable builtin command to enable disabled shell builtins.
command builtin.
These restrictions are enforced after any startup files are read.
When a command that is found to be a shell script is executed
(see section Shell Scripts), rbash turns off any restrictions in
the shell spawned to execute the script.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Starting Bash with the `--posix' command-line option or executing `set -o posix' while Bash is running will cause Bash to conform more closely to the POSIX standard by changing the behavior to match that specified by POSIX in areas where the Bash default differs.
When invoked as sh, Bash enters POSIX mode after reading the
startup files.
The following list is what's changed when `POSIX mode' is in effect:
$PATH to find the new location. This is also available with
`shopt -s checkhash'.
SIGTSTP.
bg builtin uses the required format to describe each job placed
in the background, which does not include an indication of whether the job
is the current or previous job.
PS1 and PS2 expansions of `!' to
the history number and `!!' to `!' are enabled,
and parameter expansion is performed on the values of PS1 and
PS2 regardless of the setting of the promptvars option.
$ENV) rather than
the normal Bash files.
$HISTFILE).
kill builtin does not accept signal names with a `SIG'
prefix.
. filename
is not found.
names. That is, they may not
contain characters other than letters, digits, and underscores, and
may not start with a digit. Declaring a function with an invalid name
causes a fatal syntax error in non-interactive shells.
CDPATH is set, the cd builtin will not implicitly
append the current directory to it. This means that cd will
fail if no valid directory name can be constructed from
any of the entries in $CDPATH, even if the a directory with
the same name as the name given as an argument to cd exists
in the current directory.
for statement or the selection variable in a
select statement is a readonly variable.
export and readonly builtin commands display their
output in the format required by POSIX.
trap builtin displays signal names without the leading
SIG.
trap builtin doesn't check the first argument for a possible
signal specification and revert the signal handling to the original
disposition if it is, unless that argument consists solely of digits and
is a valid signal number. If users want to reset the handler for a given
signal to the original disposition, they should use `-' as the
first argument.
. and source builtins do not search the current directory
for the filename argument if it is not found by searching PATH.
alias builtin displays alias definitions, it does not
display them with a leading `alias ' unless the `-p' option
is supplied.
set builtin is invoked without options, it does not display
shell function names and definitions.
set builtin is invoked without options, it displays
variable values without quotes, unless they contain shell metacharacters,
even if the result contains nonprinting characters.
cd builtin is invoked in logical mode, and the pathname
constructed from $PWD and the directory name supplied as an argument
does not refer to an existing directory, cd will fail instead of
falling back to physical mode.
pwd builtin is supplied the `-P' option, it resets
$PWD to a pathname containing no symlinks.
pwd builtin verifies that the value it prints is the same as the
current directory, even if it is not asked to check the file system with the
`-P' option.
fc builtin does not include an
indication of whether or not a history entry has been modified.
fc is ed.
type and command builtins will not report a non-executable
file as having been found, though the shell will attempt to execute such a
file if it is the only so-named file found in $PATH.
vi editing mode will invoke the vi editor directly when
the `v' command is run, instead of checking $VISUAL and
$EDITOR.
xpg_echo option is enabled, Bash does not attempt to interpret
any arguments to echo as options. Each argument is displayed, after
escape characters are converted.
ulimit builtin uses a block size of 512 bytes for the `-c'
and `-f' options.
There is other POSIX behavior that Bash does not implement by default even when in POSIX mode. Specifically:
fc builtin checks $EDITOR as a program to edit history
entries if FCEDIT is unset, rather than defaulting directly to
ed. fc uses ed if EDITOR is unset.
xpg_echo option to be enabled for
the echo builtin to be fully conformant.
Bash can be configured to be POSIX-conformant by default, by specifying
the `--enable-strict-posix-default' to configure when building
(see section Optional Features).
| [ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on February, 24 2009 using texi2html 1.76.