Environment variable

$printenv (or $env) # TODO: I need to investigate what is difference in printenv Vs. env.

(This command will print ALL environment variables.)

$printenv USER

$echo $USER

(This will show value for environment variable = USER )

$printenv | grep RUBY

(This will show only those environment variable that contain RUBY. We have used grep command for this.)

$export EDITOR=atom

(This will set environment variable EDITOR which did not exist before. This does not appear to be true based on my experiment, as given below.)


(This will change value of environment variable EDITOR which existed before. Note that we do not use "export" in this case.)

The problem with export command is that it will be available for that session only. Once we close the terminal, the value will be gone. To make the environment variable available for ALL terminal sessions, we need to add it to the shell.

$echo $SHELL will tell which shell I am using. It is bin/bash in may case.

So I need to open ~/.bashrc file and add the command $export EDITOR=codium so that the environment variable EDITOR will be available for all terminal sessions.

On Ubuntu machine: For more details, see https://help.ubuntu.com/community/EnvironmentVariables


This is what I tried in the terminal window:

$ export FUN=sunday

$ echo $FUN   #sunday

$ export FUN=holiday

$ echo $FUN   #holiday

$ FUN=weekend

$ echo $FUN   #weekend