Value of an environment variable

If you wish to see the value of an environment variable the easiest way to do so is to print the contents of the variable in your shell. To do so you have to use the following command:

echo $var_name

If there is an environment variable defined named var_name then the above command will output its contents in standard output (your shell). If there is no variable with that name defined the above command will output an empty line. If you see var_name outputed in your shell you probably forgot to type in the $ sign before the name of your variable. Remember that echo simply echoes a string in standard output so if you do not specify that the string you typed is a variable ($ sign) then it will simply output your string.

Now if you do not exactly remember the name of your environment variable the easiest way to find out if it is defined or not would be to output all the environment variables defined and either move your way through the list like

printenv

or pipe the output to grep providing a part of the name of the variable like

printenv | grep name

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s