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:


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


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


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

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:

    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.

Was this information helpful to you? You have the power to keep it alive.
Each donated € will be spent on running and expanding this page about UNIX Shell.