OSX - ZSH - PATH - /usr/bin duplicated
Asked Answered
R

3

7

I need some help to understand why my path looks like the way it looks.

Issuing echo $PATH in zsh returns :

/Library/Frameworks/Python.framework/Versions/3.2/bin:/usr/bin/:/bin:/usr/sbin:/sbin:
/usr/local/bin:/usr/X11/bin:/usr/local/go/bin:/usr/bin

Now, let's have a closer look of the different parts :

- /Library/Frameworks/Python.framework/Versions/3.2/bin:

it comes from my .zprofile (Python 3 installation)

- /usr/bin/: 
- /bin: 
- /usr/sbin:
- /sbin:
- /usr/local/bin:

These parts come from my /etc/paths folder.

- /usr/X11/bin:

This part come from my etc/path.d folder

- /usr/local/go/bin:

This part was added during GO installation.

- /usr/bin

???

I have looked at -/etc/paths -.zshrc -.zprofile -.profile -/etc/profile -.zshenv. None of them sourced or added a second /user/bin neither to the PATH.

How can I remove the second /user/bin from my PATH if I don't know which file to edit?

Thank you.

Ricard answered 24/7, 2012 at 16:25 Comment(2)
You can have a look at what your shell does when it is launched: zsh -x -i -c exit. Or if you are only looking for path related issues: zsh -x -i -c exit 2>&1 | grep -C 2 -i pathOpposable
Hi Sebastian, thank you for your time. I am to new to zsh and shell scripting to understand your two commands. I tested them.Ricard
S
23

In ZSH, removing duplicates in the PATH variable is done via typeset -U PATH and not typeset -u PATH(the latter would just convert the content to uppercase..)

Serendipity answered 10/1, 2014 at 22:33 Comment(2)
actually in the doc is 'path', not 'PATH'. zsh.sourceforge.io/Guide/zshguide02.html#l24Selfridge
It's because of the context. It's said "The incantation `typeset -U path', where the -U stands for unique, tells the shell that it should not add anything to $path if it's there already" so if your path variable is named $PATH you should use uppercase. If you look a bit above you'll understand why they don't use uppercase right here.Linnealinnean
V
0

While this doesn't explain where the second /usr/bin comes from, you can put typeset -u PATH after the last place you append anything to $PATH. This will remove duplicate entries.

Vierno answered 31/3, 2013 at 4:54 Comment(0)
H
0

Use zsh to enter the command zsh shell and then use typeset -u PATH to remove the duplicates. I have used small -u in typeset, but it has turned the variables into uppercase and hasnt removed the duplicates.

Huai answered 8/9, 2022 at 11:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.