List of All Bash Environment Variables – Linux 2018

A shell is a program that runs operating system commands. Bash has more than 50 predefined variables.These variables, created when Bash is first started, provide information about the Bash session and can be used to control some of the shell’s features.

Some of these variables have special properties that might be lost if you unset the variable and then create a new one with the same name.

For example, the variable RANDOM contains a random number. If you delete RANDOM with unset and declare a new variable called RANDOM, this new variable is a normal shell variable and does not contain random numbers.Therefore, it’s best to avoid creating variables with the same name as the predefined variables.

Environment variables are the variables Linux shares between a program and the program that executed it. Like layers of an onion, each program must explicitly export a variable into the environment for the next program to see it.

Here we’ve listed out all Bash Environment Variables which are as follows:

$* 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.
$? 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 filename 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 filenames for the declared functions in the shell.
BASH_SUBSHELL The number of subshells 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 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 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.
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 local category for the shell.
LC_ALL Overrides the LANG variable, defining a local 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 local setting used when interpreting double-quoted strings preceded by a dollar sign.
LC_NUMERIC Determines the local 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.
PS1 The primary command line prompt string.
PS2 The secondary command line prompt 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 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 also like:

Sarcastic Writer

Step by step hacking tutorials about wireless cracking, kali linux, metasploit, ethical hacking, seo tips and tricks, malware analysis and scanning.

Related Posts