Go to the previous, next section.
This section describes the features unique to Bash.
Along with the single character shell command-line options (See section The Set Builtin) there are several other options that you can use. These options must appear on the command line before the single character command options to be recognized.
csh. If you wanted to replace your current login shell with a Bash login shell, you would say `exec bash -login'.
When and how Bash executes startup files.
For Login shells (subject to the -noprofile option): On logging in: If `/etc/profile' exists, then source it. If `~/.bash_profile' exists, then source it, else if `~/.bash_login' exists, then source it, else if `~/.profile' exists, then source it. On logging out: If `~/.bash_logout' exists, source it. For non-login interactive shells (subject to the -norc and -rcfile options): On starting up: If `~/.bashrc' exists, then source it. For non-interactive shells: On starting up: If the environment variable
ENVis non-null, expand the variable and source the file named by the value. If Bash is not started in Posix mode, it looks for
So, typically, your
~/.bash_profile contains the line
after (or before) any login specific initializations.
if [ -f
~/.bashrc]; then source
If Bash is invoked as
sh, it tries to mimic the behavior of
sh as closely as possible. For a login shell, it attempts to
source only `/etc/profile' and `~/.profile', in that order.
-noprofile option may still be used to disable this behavior.
A shell invoked as
sh does not attempt to source any other
When Bash is started in POSIX mode, as with the
-posix command line option, it follows the Posix 1003.2
standard for startup files. In this mode, the
variable is expanded and that file sourced; no other startup files
You may wish to determine within a startup script whether Bash is
running interactively or not. To do this, 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
You can ask an interactive Bash to not run your `~/.bashrc' file
-norc flag. You can change the name of the
`~/.bashrc' file to any other file name with
filename. You can ask Bash to not run your
`~/.bash_profile' file with the
This section describes builtin commands which are unique to or have been extended in Bash.
builtin [shell-builtin [args]]Run a shell builtin. This is useful when you wish to rename a shell builtin to be a function, but need the functionality of the builtin within the function itself.
bind [-m keymap] [-lvd] [-q name] bind [-m keymap] -f filename bind [-m keymap] keyseq:function-name
Display current Readline (see section Command Line Editing) key and function bindings, or bind a key sequence to a Readline function or macro. The binding syntax accepted is identical to that of `.inputrc' (see section Readline Init File), but each binding must be passed as a separate argument: `"\C-x\C-r":re-read-init-file'. Options, if supplied, have the following meanings:
viis equivalent to
emacsis equivalent to
command [-pVv] command [args ...]Runs command with arg ignoring shell functions. If you have a shell function called
ls, and you wish to call the command
ls, you can say `command ls'. The
-poption means to use a default value for
$PATHthat is guaranteed to find all of the standard utilities.
If either the
-v option is supplied, a
description of command is printed. The
causes a single word indicating the command or file name used to
invoke command to be printed; the
-V option produces
a more verbose description.
declare [-frxi] [name[=value]]
Declare variables and/or give them attributes. If no names
are given, then display the values of variables instead.
-f means to use function names only.
-r says to
make names readonly.
-x says to mark names
-i says that the variable is to be treated as
an integer; arithmetic evaluation (see section Shell Arithmetic) is
performed when the variable is assigned a value. Using
- turns off the attribute instead. When used in
declare makes names local, as with the
enable [-n] [-a] [name ...]Enable and disable builtin shell commands. This allows you to use a disk command which has the same name as a shell builtin. If
-nis used, the names become disabled. Otherwise names are enabled. For example, to use the
testbinary found via
$PATHinstead of the shell builtin version, type `enable -n test'. The
-aoption means to list each builtin with an indication of whether or not it is enabled.
help [pattern]Display helpful information about builtin commands. If pattern is specified,
helpgives detailed help on all commands matching pattern, otherwise a list of the builtins is printed.
local name[=value]For each argument, create a local variable called name, and give it value.
localcan only be used within a function; it makes the variable name have a visible scope restricted to that function and its children.
type [-all] [-type | -path] [name ...]For each name, indicate how it would be interpreted if used as a command name.
-type flag is used,
type returns a single word
which is one of "alias", "function", "builtin", "file" or
"keyword", if name is an alias, shell function, shell builtin,
disk file, or shell reserved word, respectively.
-path flag is used,
type either returns the name
of the disk file that would be executed, or nothing if
would not return "file".
-all flag is used, returns all of the places that contain
an executable named file. This includes aliases and functions,
if and only if the
-path flag is not also used.
-p as equivalent to
ulimit [-acdmstfpnuvSH] [limit]
Ulimitprovides control over the resources available to processes started by the shell, on systems that allow such control. If an option is given, it is interpreted as follows:
-Hoption is not given).
If limit is given, it is the new value of the specified resource. Otherwise, the current value of the specified resource is printed. If no option is given, then `-f' is assumed. Values are in 1024-byte increments, except for `-t', which is in seconds, `-p', which is in units of 512-byte blocks, and `-n' and `-u', which are unscaled values.
This builtin is so overloaded that it deserves its own section.
set [-abefhkmnptuvxldCHP] [-o option] [argument ...]
Set the flag corresponding to option-name:
vi-style line editing interface.
$ENVfile is not processed, and shell functions are not inherited from the environment. This is enabled automatically on startup if the effective user (group) id is not equal to the real user (group) id. Turning this option off causes the effective user and group ids to be set to the real user and group ids.
cdwhich change the current directory. The physical directory is used instead.
-voptions are turned off. If there are no arguments, the positional parameters remain unchanged.
Using `+' rather than `-' causes these flags to be
turned off. The flags can also be used upon invocation of the
shell. The current set of flags may be found in
remaining N arguments are positional parameters and are
assigned, in order, to
no arguments are given, all shell variables are printed.
These variables are set or used by bash, but other shells do not normally treat them specially.
HISTCMDis unset, it loses its special properties, even if it is subsequently reset.
FIGNOREis excluded from the list of matched file names. A sample value is `.o:~'
EOFcharacter as the sole input. If set, then the value of it is the number of consecutive
EOFcharacters that can be read as the first characters 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
EOFsignifies the end of input to the shell. This is only in effect for interactive shells.
cdwhich change the current directory.
For example, if `/usr/sys' is a link to `/usr/local/sys' then:
$ cd /usr/sys; echo $PWD /usr/sys $ cd ..; pwd /usr
nolinks exists, then:
$ cd /usr/sys; echo $PWD /usr/local/sys $ cd ..; pwd /usr/local
See also the description of the
-P option to the
builtin, section The Set Builtin.
The shell allows arithmetic expressions to be evaluated, as one of
the shell expansions or by the
Evaluation is done in long integers with no check for overflow, though division by 0 is trapped and flagged as an error. The following list of operators is grouped into levels of equal-precedence operators. The levels are listed in order of decreasing precedence.
* / %
<= >= < >
= *= /= %= += -= <<= >>= &= ^= |=
Shell variables are allowed as operands; parameter expansion is performed before the expression is evaluated. The value of a parameter is coerced to a long integer within an expression. 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.
0X denotes hexadecimal. Otherwise,
numbers take the form [base#]n, where base is a
decimal number between 2 and 36 representing the arithmetic
base, and n is a number in that base. If base is
omitted, then base 10 is used.
Operators are evaluated in order of precedence. Sub-expressions in parentheses are evaluated first and may override the precedence rules above.
Arithmetic expansion allows the evaluation of an arithmetic expression and the substitution of the result. There are two formats for arithmetic expansion:
$[ expression ] $(( expression ))
The expression is treated as if it were within double quotes, but a double quote inside the braces or parentheses is not treated specially. All tokens in the expression undergo parameter expansion, command substitution, and quote removal. Arithmetic substitutions may be nested.
The evaluation is performed according to the rules listed above. If the expression is invalid, Bash prints a message indicating failure and no substitution occurs.
let expression [expression]The
letbuiltin allows arithmetic to be performed on shell variables. Each expression is evaluated according to the rules given previously (see section Arithmetic Evaluation). If the last expression evaluates to 0,
letreturns 1; otherwise 0 is returned.
The value of the variable
$PROMPT_COMMAND is examined just before
Bash prints each primary prompt. If it is set and non-null, then the
value is executed just as if you had typed it on the command line.
In addition, the following table describes the special characters which
can appear in the
$0(the portion following the final slash).
Go to the previous, next section.