You can edit an environment variable in-place by running vared:
$ vared PATH
It will give you a readline-style buffer to edit the variable's contents and will save them back to the environment after you're done.
environmentpathreadlinevaredzsh
Sometimes you need to iterate over variable names and access their values. In shell script, you would do something like this to get the values of FOO and BAR:
$ FOO=apple
$ BAR=orange
$ VARS="FOO BAR"
$ for v in $VARS ; do echo ${!v} ; done
The above works in bash. Use this in Zsh:
$ for v in $VARS ; do echo ${(P)v} ; done
(The 'P' flag on ${v} causes a further variable lookup before ${v} is evaluated.)
Thanks to Cliff for the tip!
bashcommandsenvironmentevaluationiterationloopshellzsh