zsh config - to export or not to export?
If you want programs run from zsh to see the var, export it.
For path, you probably want to export.
Instead of export PATH=/some/path
you probably want export PATH="$PATH:/some/path"
, unless you intend to clear out the system preset path completely.
Demure already answered your specific question. However, this is a zsh
question and about PATH
. So here is another point: besides the standard variable $PATH
, there is also $path
, which is an array. Here you see the difference (colons or not...):
$ print $PATH
/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
$ print $path
/bin /usr/bin /usr/local/bin /usr/X11R6/bin
Both variants are automatically kept in sync. So, what's the benefit of using an array?
- The latter you can declare via
typeset -U path
to "keep only the first occurrence of each duplicated value" (fromman zshbuiltins
). That means this keeps your path clean, even if you successively source your~/.zshrc
(because you changed it or whatever) and do not clutter it up with the same values again and again. - You can use
path+=(/new/path)
to add a new directory to your PATH. To remove an element you have to use some tricks, see e.g. https://stackoverflow.com/q/3435355/2037712 or http://www.zsh.org/mla/users//2005/msg01132.html - You can easily loop over the elements in the PATH via
for i ($path) { print $i # or do something else }
Finally, here is an excerpt from my config:
typeset -U path
path=(/new/path1
/new/path2
$path)
export PATH