The env and printenv commands 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 and printenv commands. export must be used for foo to be in the output of the env and printenv commands.
export foo="bar"
Now the foo variable should be included in the output of the env and printenv commands.
~]$ 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 and printenv commands.
echo $foo
Did you find this article helpful?
If so, consider buying me a coffee over at