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
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 (
integer, etc.), use
You can use
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.