Bootstrap FreeKB - Linux Commands - List environment variables using the printenv command
Linux Commands - List environment variables using the printenv command

Updated:   |  Linux Commands articles

The env and printenv commands will list all of the environment variables that have been set.

~]$ printenv
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 and printenv command.

export foo="bar"

 

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

~]$ printenv
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 command.

echo $foo

 




Did you find this article helpful?

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



Comments


Add a Comment


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