In Bash, variables usually have a $ prefix to denote a variable. For example, echo $USER will print the current user to the terminal. Environment variables are special variables used by the OS, shell, or applications to store system-wide and process-specific information

User and Session variables

These variables define personal details, such as username, or session-specific settings, such as the terminal prompt style or other customisation. Some of the major user/session variables are:

  • $USER
  • $HOME
  • $SHELL
  • $PS1

PS1 is a variable that defines the style and content of the command prompt1.

System and execution variables

Whenever we run a command, such as ls, the system will check environmental variables to determine which ls program to run and where to display the output. In other words, this is different from personal variables in that these affect where system settings and binaries will be discovered.

Two major variables are $PATH and $DISPLAY; the former defines where executable might be found, while the latter defines where graphic output is to be directed.

We can temporarily update our $PATH by doing export PATH=$PATH:/new/path.

Footnotes

  1. Note that this is not always the case. My shell of choice, fish, doesn’t use $PS1 and instead uses a function called fish_prompt