Linux Commands - env (list environment variables)

The env command will list all of the environment variables that have been set. Something like this should be returned.

~]$ env
HOSTNAME=server1.example.com
SHELL=/bin/bash
USER=john.doe

 

Lets say you've create a variable named "foo" that contain a value of "bar".

foo="bar"

 

When you echo $foo, bar is returned.

echo $foo
bar

 

However, foo will not be included in the output of the env command. export must be used for foo to be in the output of the env command.

export foo="bar"

 

Now the foo variable should be included in the output of the env command.

~]$ env
HOSTNAME=server1.example.com
SHELL=/bin/bash
USER=john.doe
foo=bar

 

The unset command will undefine the variable. In this example, the foo variable will no longer be defined.

unset foo

 

Now, when you attempt to echo $foo, nothing is returned, since foo has been unset. And the foo variable will not be included in the output of the env command.

echo $foo

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee

Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.





Please enter 0f41d in the box below so that we can be sure you are a human.