bash how to list environment variables

Answer

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 export command:

export

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

env

In fact, env run some program in modified environment. In next example, env will run only with 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 next example, we defined FUNKY_FUNCTION first:

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

Next command include shell variables to output:

( set -o posix ; set ) | less

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