List of Bash Environment Variables in Linux

Linux Bash Environment Variables Techhyme

The Environment Variables form a simple and effective way to pass information about the current operating environment to the program being executed.

Also Read:

The bash shell also utilizes many environment variables. While environment variables aren’t commands, they often affect how shell commands operate, so it’s important to know the shell environment variables.

Two common examples of Linux environment variables are the $PATH and $HOME variables.

Variable Description
$* Contains all of the command line parameters as a single text value.
$@ Contains all of the command line parameters as separate text values.
$# The number of command line parameters.
$7 The exit status of the most recently used foreground process.
The current command line option flags.
$$ The process ID (PID) of the current shell.
$! The PID of the most recently executed background process.
$0 The name of the command from the command line.
$_ The absolute pathname of the shell.
BASH The full file name used to invoke the shell.
BASH_ARGC The number of parameters in the current subroutine.
BASH_ARGV An array containing all of the command line parameters specified .
BASH_COMMAND The name of the command currently being executed.
BASH_ENV When set, each bash script attempts to execute a startup file defined by this variable before running.
BASH_EXECUTION_STRING The command used in the -c command line option.
BASH_LINENO An array containing the line numbers of each command in the script.
BASH_REMATCH An array containing text elements that match a specified regular expression.
BASH_SOURCE An array containing source file names for the declared functions in the shell.
BASH_SUBSHELL The number of sub shells spawned by the current shell.
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.
COM_WORDBREAKS A set of characters used as word separators when performing word completion.
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 file name completion.
FUNCNAME The name of the currently executing shell function.
GLOBIGNORE A colon-separated list of patterns defining the set of file names to be ignored by file name expansion.
GROUPS A variable array containing the list of groups of which the current user is a member.
histchars Up to three characters that 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.
HISTIGN0RE 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.
H0STFILE Contains the name of the file that should be read when the shell needs to complete a hostname.
H0STNAME The name of the current host.
H0STTYPE A string describing the machine the bash shell is running on.
IGN0REE0F The number of consecutive EOF characters the shell must receive before exiting. If this value doesn’t exist, the default is 1.
INPUTRC The name of the redline initialization file (the default is. Input).
LANG The locale category for the shell.
LC_ALL Overrides the LANG variable, defining a locale category.
LC_C0LLATE Sets the collation order used when sorting string values.
LC_CTYPE Determines the interpretation of characters used in file name 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.
LINEN0 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 cup company system format.
MAILCHECK How often (in seconds) the shell should check for new mail (default is 60}.
0LDPWD The previous working directory used in the shell.
0PTERR If set to 1, the bash shell displays errors generated by the getopts command.
0STYPE 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.
P0SIXLY_C0RRECT 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.
PS1 The primary command line prompts string.
PS2 The secondary command line prompts string.
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 O 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 1 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 O indicates to wait indefinitely.
UID The numeric real user ID of the current user.

You can display the environment variables using the set built-in command. The default shell environment variables set at boot time can and often do vary between different Linux distributions.

You may also like:

Related Posts