Linux Environment Variables

ENV

Displays all the environment variables

$ env
$ env | grep HOME
$ printenv
$ printenv HOME

$ env WHO='Prashanth Sams' | grep WHO
WHO=Prashanth Sams

SET

Displays all the environment variables as well as shell variables(also called local variables)

$ set
$ set | less
  • Unset environment variables
$ export WHO='Prashanth Sams'
$ unset WHO

Persistent Environment variables

Environment variables are loaded from the following files on starting each shell session

/etc/environment
/etc/profile
~/.bashrc

Default Environment variables

Different ways to find the machine username

$ whoami
prashanthsams

$ echo $USER
prashanthsams

$ bash -c 'echo $USER'
prashanthsams

$ echo $HOME
/Users/prashanthsams

Leave a comment