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.

politicus
  • 459
  • 6
  • 14
  • 4
    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 path` – Sebastian Stumpf Jul 24 '12 at 16:37
  • Hi Sebastian, thank you for your time. I am to new to zsh and shell scripting to understand your two commands. I tested them. – politicus Jul 24 '12 at 16:49

3 Answers3

20

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..)

Clemens
  • 619
  • 6
  • 10
  • actually in the doc is 'path', not 'PATH'. https://zsh.sourceforge.io/Guide/zshguide02.html#l24 – King. Mar 09 '23 at 04:23
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.

Mark Nichols
  • 1,407
  • 2
  • 19
  • 25
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.