How to list all variables names and their current values?

Solution 1:

For bash: (the standard shell in Ubuntu)

Enter the following command in a terminal to print all the environment variables:

printenv

For further information about this command, read the printenv man page.


To show a list including the "shell variables" you can enter the next command:

( set -o posix ; set ) | less

This will show you not only the shell variables, but the environment variables too.

For more information related with this topic read:


For zsh: (an advanced shell)

Use the following command:

( setopt posixbuiltin; set; ) | less

For more information about ZSH options, see zshoptions man page.

Solution 2:

You can see all variables with the declare builtin.

declare -p

If you're only interested in environment variables, use

declare -xp

Run help declare to see what the other options are.