Table A-5 shows a complete list of environment variables available in bash 3.0. The letters in the Type column of the table have the following meanings: A = Array, L = colon-separated list, R = read-only, U = unsetting it causes it to lose its special meaning.
Note that the variables beginning BASH_
and beginning COMP
, as well as the variables DIRSTACK, FUNCNAME, GLOBIGNORE, GROUPS, HISTIGNORE,
HOSTNAME, HISTTIMEFORMAT, LANG, LC_ALL, LC_COLLATE, LC_MESSAGE, MACHTYPE,
PIPESTATUS, SHELLOPTS
, and TIMEFORMAT
are not available in versions prior
to 2.0. BASH_ENV
replaces ENV
found in earlier versions.
Table A-5. Built-in shell environment variables
Variable | Type | Description |
---|---|---|
* | R | A single string containing the positional parameters
given to the current script or function, separated by the first
character of |
@ | R | Each of the positional parameters given to the
current script or function, given as a list of double-quoted
strings (e.g., |
# | R | The number of arguments given to the current script or function. |
- | R | Options given to the shell on invocation. |
? | R | Exit status of the previous command. |
_ | R | Last argument to the previous command. |
$ | R | Process ID of the shell process. |
! | R | Process ID of the last background command. |
0 | R | Name of the shell or shell script. |
| The full pathname used to invoke this instance of bash. | |
| A | An array of values, which are the number of
parameters in each frame of the current bash
execution call stack. The number of parameters to the current
subroutine (shell function or script executed with . or |
| A | All of the parameters in the current bash execution call stack. The final parameter of the last subroutine call is at the top of the stack; the first parameter of the initial call is at the bottom. |
| The command currently being executed or about to be executed, unless the shell is executing a command as the result of a trap, in which case it is the command executing at the time of the trap. | |
| The command argument to the | |
| The name of a file to run as the environment file when the shell is invoked. | |
| A | An array whose members are the line numbers in source
files corresponding to each member of |
| AR | An array whose members are assigned by the =~ binary operator to the [[ conditional command. The element with index 0 is the portion of the string matching the entire regular expression. The element with index n is the portion of the string matching the nth parenthesized subexpression. |
| A | An array containing the source filenames
corresponding to the elements in the |
| Incremented by 1 each time a subshell or subshell environment is spawned. The initial value is 0. A subshell is a forked copy of the parent shell and shares it’s environment. | |
| The version number of this instance of bash. | |
| AR | Version information for this instance of bash. Each element of the array holds parts of the version number. |
| L | A list of directories for the cd command to search. |
| An index into | |
| The current command line. This variable is available only in shell functions and external commands invoked by the programmable completion facilities. | |
| 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 | |
| U | The set of characters that the Readline library
treats as word separators when performing word completion. If
|
| A | An array of the individual words in the current command line. This variable is available only in shell functions invoked by the programmable completion facilities. |
| A | The possible completions generated by a shell function invoked by the programmable completion facility. |
| ARU | The current contents of the directory stack. |
| R | The effective user ID of the current user. |
| ARU | An array containing the names of all shell functions currently in the execution call stack. The element with index 0 is the name of any currently-executing shell function. The bottom-most element is “main.” This variable exists only when a shell function is executing. |
| The default editor for the fc command. | |
| L | A list of names to ignore when doing filename completion. |
| L | A list of patterns defining filenames to ignore during pathname expansion. |
| AR | An array containing a list of groups of which the current user is a member. |
| The Internal Field Separator: a list of characters that act as word separators. Normally set to space, tab, and newline. | |
| U | The history number of the current command. |
| A list of patterns, separated by colons (:), which
can have the following values: | |
| The name of the command history file. | |
| A list of patterns to decide what should be retained in the history list. | |
| The number of lines kept in the command history. | |
| The maximum number of lines kept in the history file. | |
| If set and not null, its value is used as a format string for strftime(3) to print the timestamp associated with each history entry displayed by the history built-in. If this variable is set, timestamps are written to the history file so they may be preserved across shell sessions. | |
| The home (login) directory. | |
| The file to be used for hostname completion. | |
| The name of the current host. | |
| The type of machine bash is running on. | |
| The number of EOF characters received before exiting an interactive shell. | |
| The readline startup file. | |
| Used to determine the locale category for any
category not specifically selected with variable starting with
| |
| Overrides the value of | |
| Determines the collation order used when sorting the results of pathname expansion. | |
| Determines the interpretation of characters and the behavior of character classes within pathname expansion and pattern matching. | |
| This variable determines the locale used to translate double-quoted strings preceded by a $. | |
| Determines the locale category used for number formatting. | |
| U | The number of the line that just ran in a script or function. |
| A string describing the system on which bash is executing. | |
| The name of the file to check for new mail. | |
| How often (in seconds) to check for new mail. | |
| L | A list of filenames to check for new mail, if
|
| The previous working directory. | |
| The value of the last option argument processed by
| |
| If set to 1, display error messages from | |
| The number of the first argument after options. | |
| The operating system on which bash is executing. | |
| L | The search path for commands. |
| A | An array variable containing a list of exit status values from the processes in the most recently executed foreground pipeline. |
| If in the environment when bash
starts, the shell enters posix mode before reading the startup
files, as if the | |
| The value is executed as a command before the primary prompt is issued. | |
| The primary command prompt string. | |
| The prompt string for line continuations. | |
| The prompt string for the select command. | |
| The prompt string for the xtrace option. | |
| R | The process ID of the parent process. |
| The current working directory. | |
| U | A random number between 0 and |
| The user’s response to the select command; result of the read command if no variable names are given. | |
| U | The number of seconds since the shell was invoked. |
| The full pathname of the shell. | |
| LR | A list of enabled shell options. |
| Incremented by 1 each time a new instance (not a subshell) of bash is invoked. This intended to be a count of how deeply your bash shells are nested. | |
| Specifies the format for the output from using the time reserved word on a command pipeline. | |
| If set to a positive integer, the number of seconds after which the shell automatically terminates if no input is received. | |
| R | The user ID of the current user. |
| Controls how job control works (values are | |
| Specifies what to use as the history control characters. Normally set to the string !^#. |
3.137.216.175