Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
add comment

2 Answers 2

up vote 14 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
2  
@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
1  
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
2  
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
add comment

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
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.