Default Linux Shell Environment Variables
There are specific environment variables that the bash shell uses by default to define the system environment. You can always count on these variables being set on your Linux system. Since the bash shell is a derivative of the original Unix Bourne shell, it also includes environment variables originally defined in that shell.
By far the most important environment variable in this list is the PATH environment variable. When you enter a command in the shell command line interface (CLI), the shell must search
the system to find the program. The PATH environment variable defines the directories it searches looking for commands. On my Linux system, the PATH environment variable looks like this:
$ echo $PATH
/usr/kerberos/bin:/usr/lib/ccache:/usr/local/bin:/bin:/usr/bin:
/home/rich/bin
$
This shows that there are six directories where the shell looks for commands. Each directory in
the PATH is separated by a colon. There’s nothing at the end of the PATH variable indicating the end of the directory listing. You can add additional directories to the PATH simply by adding another colon, and adding the new directory. The PATH also shows the order in which it looks for commands.
Besides the default Bourne environment variables, the bash shell also provides a few variables of
its own.
The bash Shell Bourne Variables
CDPATH A colon-separated list of directories used as a search path for the cd command.
HOME The current user’s home directory.
IFS A list of characters that separate fields used by the shell to split text strings.
MAIL The filename for the current user’s mailbox. The bash shell checks this file
for new mail.
MAILPATH A colon-separated list of multiple filenames for the current user’s mailbox. The
bash shell checks each file in this list for new mail.
OPTARG The value of the last option argument processed by the getopts command.
OPTIND The index value of the last option argument processed by the getopts
command.
PATH A colon-separated list of directories where the shell looks for commands.
PS1 The primary shell command line interface prompt string.
PS2 The secondary shell command line interface prompt string.
The bash Shell Environment Variables
BASH The full pathname to execute the current instance of the bash shell.
BASH_ENV When set, each bash script attempts to execute a startup file defined by
this variable before running.
BASH_VERSION The version number of the current instance of the bash shell.
BASH_VERSINFO A variable array that contains the individual major and minor version
numbers of the current instance of the bash shell.
COLUMNS Contains the terminal width of the terminal used for the current
instance of the bash shell.
COMP_CWORD An index into the variable COMP WORDS, which contains the current
cursor position.
COMP_LINE The current command line.
COMP_POINT The index of the current cursor position relative to the beginning of the current command.
COMP_WORDS A variable array that contains the individual words on the current command line.
COMPREPLY A variable array that contains the possible completion codes generated by a shell function.
DIRSTACK A variable array that contains the current contents of the directory stack.
EUID The numeric effective user ID of the current user.
FCEDIT The default editor used by the fc command.
FIGNORE A colon-separated list of suffixes to ignore when performing filename completion.
FUNCNAME The name of the currently executing shell function.
GLOBIGNORE A colon-separated list of patterns defining the set of filenames to be ignored by filename expansion.
GROUPS A variable array containing the list of groups of which the current user is a member.
histchars Up to three characters which control history expansion.
HISTCMD The history number of the current command.
HISTCONTROL Controls what commands are entered in the shell history list.
HISTFILE The name of the file to save the shell history list (.bash history by default).
HISTFILESIZE The maximum number of lines to save in the history file.
HISTIGNORE A colon-separated list of patterns used to decide which commands are ignored for the history file.
HISTSIZE The maximum number of commands stored in the history file.
HOSTFILE Contains the name of the file that should be read when the shell needs to complete a hostname.
HOSTNAME The name of the current host.
HOSTTYPE A string describing the machine the bash shell is running on.
IGNOREEOF The number of consecutive EOF characters the shell must receive before exiting. If this value doesn’t exist, the default is one.
INPUTRC The name of the Readline initialization file (the default is .inputrc).
LANG The locale category for the shell.
LC_ALL Overrides the LANG variable, defining a locale category.
LC_COLLATE Sets the collation order used when sorting string values.
LC_CTYPE Determines the interpretation of characters used in filename expansion and pattern matching.
LC_MESSAGES Determines the locale setting used when interpreting double-quoted strings preceded by a dollar sign.
LC_NUMERIC Determines the locale setting used when formatting numbers.
LINENO The line number in a script currently executing.
LINES Defines the number of lines available on the terminal.
MACHTYPE A string defining the system type in cpu-company-system format
MAILCHECK How often (in seconds) the shell should check for new mail (default is 60).
OLDPWD The previous working directory used in the shell.
OPTERR If set to 1, the bash shell displays errors generated by the getopts command.
OSTYPE A string defining the operating system the shell is running on.
PIPESTATUS A variable array containing a list of exit status values from the processes in the foreground process.
POSIXLY CORRECT If set, bash starts in POSIX mode.
PPID The process ID (PID) of the bash shell’s parent process.
PROMPT_COMMAND If set, the command to execute before displaying the primary prompt.
PS3 The prompt to use for the select command.
PS4 The prompt displayed before the command line is echoed if the bash -x parameter is used.
PWD The current working directory.
RANDOM Returns a random number between 0 and 32767. Assigning a value to this variable seeds the random number generator.
REPLY The default variable for the read command.
SECONDS The number of seconds since the shell was started. Assigning a value resets the timer to the value.
SHELLOPTS A colon-separated list of enabled bash shell options.
SHLVL Indicates the shell level, incremented by one each time a new bash shell is started.
TIMEFORMAT A format specifying how the shell displays time values.
TMOUT The value of how long (in seconds) the select and read commands should wait for input. The default of zero indicates to wait indefinitely.
UID The numeric real user id of the current user.
You may notice that not all of the default environment variables are shown when I used the set command. The reason for this is that although these are the default environment variables, not all of them are required to contain a value.
Tags: shell
Related Articles