Path Variable Pitfalls and Tips
Pitfalls
-
Incorrect use of the tilde expansion.
export PATH=~/.dir:$PATHexpands to/home/username/.direxport PATH="~/.dir"expands to~/.direxport PATH="$HOME/.dir"expands to/home/username/.direxport PATH=$HOME/.direxpands to/home/username/.dir
-
Specifying the incorrect directory.
- N.B. The exact parent directory of the desired executable must be specified – not the grandparent, great-grandparent, etc.
- For example, if you want to run the program
foo.shwhich lives in/usr/bin/run/foo.sh, add the/usr/bin/rundirectory to your path; having/usr/binin your path is not sufficient.
Tips
-
According to the user guide, set your path in
.zshenv. -
Add
typeset -U pathto your.zshenvto not add duplicate entries to your path. -
Modify your path like
path=(~/bin ~/progs/bin $path).- PATH and path both set the search path for commands. These two variables are equivalent, except that one is a string and one is an array. If the user modifies PATH, the shell changes path as well, and vice versa. 1
Additional Sources: