Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am used to the bash set command listing only a list of the environment settings, eg. PATH and such.

However, on an Ubuntu system I just set up, executing set dumps 2000 lines of text, including lots of functions like this:

dequote () 
{ 
    eval printf %s "$1" 2> /dev/null
}

How do I print only the environment variables?

share|improve this question
    
Note that your Ubuntu system almost certainly is using bash as well - it's the default on new installs. –  Andrew Ferrier Feb 27 '13 at 10:24
add comment

2 Answers

up vote 2 down vote accepted

By default set shows the shell variables, not just the environment variables. In bash functions are considered part of the variables. See http://askubuntu.com/questions/26318/environment-variable-vs-shell-variable-whats-the-difference .

If you use env or printenv they will show the environment exported to child processes, which is not necessarily the same as your bash environment:

$ foo=1
$ printenv foo
$ export foo
$ printenv foo
1

The bash declare and typeset builtins can list all types of variables, to omit functions:

declare -F

The output of these is in a form suitable for recreating the state in a shell script, so it's a little verbose, though you can distinguish between arrays, integers and other types (depending on version). See also the output of export -p.

And from http://stackoverflow.com/questions/1305237/how-to-list-variables-declared-in-script-in-bash you can tell bash to use POSIX mode, and set behaves "properly":

( set -o posix ; set ) 

That's run in a subshell so it doesn't alter your running shell, and it correctly picks up variables not yet exported into the inherited environment.

share|improve this answer
add comment

If you want to list all the environment variables, simply enter env.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.