Some environmental and shell variables are very useful and are referenced fairly often.Here are some common environmental variables that you will come across:
SHELL
: This describes the shell that will be interpreting any commands you type in. In most cases, this will be bash by default, but other values can be set if you prefer other options.TERM
: This specifies the type of terminal to emulate when running the shell. Different hardware terminals can be emulated for different operating requirements. You usually won’t need to worry about this though.USER
: The current logged in user.PWD
: The current working directory.OLDPWD
: The previous working directory. This is kept by the shell in order to switch back to your previous directory by running cd -
.LS_COLORS
: This defines color codes that are used to optionally add colored output to the ls
command. This is used to distinguish different file types and provide more info to the user at a glance.MAIL
: The path to the current user’s mailbox.PATH
: A list of directories that the system will check when looking for commands. When a user types in a command, the system will check directories in this order for the executable.LANG
: The current language and localization settings, including character encoding.HOME
: The current user’s home directory._
: The most recent previously executed command.How To Read and Set Environmental and Shell Variables on Linux | DigitalOcean
<aside> 💡 The shell has one environment variable, which is called the Internal Field Separator (IFS). This variable indicates how the words are separated on the command line. The IFS variable is, normally or by default, a white space (' '). The IFS variable is used as a word separator (token) for the for command. In many documents, IFS can be any one of the white space, ':', '|', ': ' or any other desired character.
</aside>
A positional parameter is a parameter denoted by one or more digits, other than the single digit 0. Positional parameters are assigned from the shell’s arguments when it is invoked, and may be reassigned using the set builtin command. Positional parameter N may be referenced as ${N}, or as $N when N consists of a single digit. Positional parameters may not be assigned to with assignment statements. The set and shift builtins are used to set and unset them. The positional parameters are temporarily replaced when a shell function is executed. When a positional parameter consisting of more than a single digit is expanded, it must be enclosed in braces.