Bash How to List Environment Variables

Reading Time: < 1 minute

Bash How to List Environment Variables

If you want to print all environment variables, you can use printenv. Command printenv print all or just part of environment variables:

printenv

If you want to get names of variables, that was exported, you can use the export command:

export

You can use also the just env command. If you want to see all environment variables:

env

In fact, env run some program in a modified environment. In the next example, env will run only with a variable called “DIRECTORY”:

env -i DIRECTORY="/etc/mydir" bash
env

If you want to see functions, that you have declared, you can use “declare -f”. Maybe you have not defined any function. To overcome this, in the next example, we defined FUNKY_FUNCTION first:

FUNKY_FUNCTION ()
{
echo ":-)"
}
declare -f

The next command includes shell variables to output:

( set -o posix ; set ) | less

This command shows not only shell variables, but environment variables too.

Leave a Comment