Linux 101 : Linux environment variables


 The PATH variable represents the locations where Linux goes to find paths to programs, when we don't mention their full path on the command line. To display the PATH variable, we use the below command:

The USER variable contains the current user we are logged in as:

The PWD variable contains the current directory we are in:

The HOME variable displays our home directory's path:

The "$$" variable displays the ID of the current shell instance. It changes when we move to another shell, for example after the "su username" command, where we move to another shell for the new user:

To see the Linux environment variables, we use the below command:

The variable "!!" executes the last command:

Below are some other built-in bash variables:

  • LOGNAME : refers to user's login name
  • OLDPWD : refers to previous working directory 
  • SHELL : refers to the path to the shell 
  • TERM : refers to the type of the terminal

The below example displays the variable "TERM":

If we change these variables using the bash command "variabe=new_value", the change is not permanent.
For the changes to persist, we will need to put these variables inside a file called "~/.bash_profile" or "~/.bashrc" depending on the bash.
Remark: 
The "~" sign refers to our home directory.

Comments

Leave as a comment:

Archive