It is so easy to do that in zsh
:
typeset -U path
That's all.
As you can imagine -U
stands for 'unique'. From doc:
-U For arrays (but not for associative arrays), keep only the
first occurrence of each duplicated value. This may also be
set for colon-separated special parameters like PATH or FIG‐
NORE, etc. This flag has a different meaning when used with
Btw. just care it is not -u
. This flag just converts the content to uppercase.
All OK!
Appendix
You may wonder why is path
instead of PATH
? In zsh
they are different but related things. The $path
array variable is tied to the $PATH
scalar string variable. The $path
helps to find external programs, i.e. anything not part of the shell, any command other than a builtin, function or alias. Any modification on $path
or $PATH
is reflected in the other.
If you check them, you will see:
$ echo $path
/usr/local/bin /usr/bin /bin /sbin
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/sbin
For more details you can go to : A User's Guide to the Z-Shell -
Path
Top comments (0)