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?


It sounds like you want env.

| improve this answer | |
  • 3
    @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
  • 1
    NB: env only shows exported variables. Use set, as Gilles' answer suggests, to export all shell variables. – Alex Mar 12 '17 at 22:37
  • 1
    @Ali, if you wanted to find this without help, I would've started with man zsh or Googling for "zsh print variables" or similar. – Alex Mar 12 '17 at 22:41

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.

| improve this answer | |
  • 2
    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
  • 3
    @Josh It's a shell variable, not exported to the environment. – Gilles 'SO- stop being evil' Dec 26 '14 at 9:58
  • @Gilles How would we list all of those as well? – Daniel Que Sep 29 '16 at 20:52
  • @DanielQue Second paragraph of my answer – Gilles 'SO- stop being evil' Sep 29 '16 at 21:02
  • @Gilles It's weird, local variables like ZSH_HIGHLIGHT_STYLES don't show up when I use set, or any of the other commands. – Daniel Que Sep 29 '16 at 21:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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