Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to get a list of all environment variables (shell variables? exported variables?) and their values at a given time, in zsh.
What is the proper way to do this?

share|improve this question
up vote 21 down vote accepted

It sounds like you want env.

share|improve this answer
that was embarrassing! Thanks. But now that we are on it, if I didn't have anyone to ask, how could I have found this? – Ali Feb 3 '12 at 15:07
@Ali Well, env isn't specific to zsh, it's a standalone program. Having said that, the number one result on Google for "list environment variables" says to use env, so I guess that's one way ;-) – Chris Down Feb 3 '12 at 15:14
I mean if I didn't have internet connection! I know I would die in a few days without Internet connection, but in those few days how can I look this up in the documentation/man...? – Ali Feb 3 '12 at 15:17
you could do something like apropos environment – glenn jackman Feb 3 '12 at 15:37
@glennjackman that's very useful, people like me who havent' spent their child hood at a unix terminal don't know these things. I was messing with DOS and Windows 3.11! – Ali Feb 3 '12 at 15:49

export prints out the list of environment variables and their values. The values are quoted, the output of export is suitable for reading back into the shell. The variables are printed in alphabetical order.

If you want shell variables as well, use set. If you want shell variables with type annotations (exported, integer, etc.), use typeset.

You can use export and set on other shells as well, but most don't quote the output, so it's not parseable. typeset is available (with different behavior) on ksh and bash.

If you want the environment variables, there's also the env command, which prints unsorted, unquoted

If you only want the names, access the parameters associative array. The keys are the parameter names and the values indicate the types.

share|improve this answer
echo $ZSH_VERSION returns 5.0.5, but when I do env | grep ZSH_VERSION I don't see any matches. Is ZSH_VERSION not an environment variable? What am I missing? – Josh Dec 26 '14 at 1:57
@Josh It's a shell variable, not exported to the environment. – Gilles Dec 26 '14 at 9:58

Your Answer


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.