Benches macOS

4

Fixing PATH (and MANPATH) once and for all

apple Verified

Imported from the Apple Support Forums via the Wayback Machine 🔗

I think the list of directories in PATH should be:

/Users/cb/bin:

/opt/local/bin:

/opt/local/sbin:

/usr/local/bin:

/usr/bin:

/bin:

/usr/local/sbin:

/usr/sbin:

/sbin:

/usr/X11R6/bin:

/usr/local/teTeX/bin/powerpc-apple-darwin-current

Do you agree? Comments and suggestions welcome.

Background:

I am trying to sort thru the endless confusion and set up PATH (and MANPATH) right, once and for all. Every package I install seems to have its own idea of what these variables should be.

I could set up a wrapper script for every installed command - but some subsystems, like Aquamacs and Python, let you create and use subshells. If the PATH in your subshell isn't the same as the one you use every day in bash, you could create bugs which are nearly impossible to track down.

My solution is to create $HOME/.setShells.sh -- which sets a uniform set of paths (and which will probably rewrite man.conf in the bargain). But I want to make sure that I'm choosing the right baseline, which is what the list above is supposed to be.

I'd appreciate your thoughts and/or assistance.

4 replies

Sign in or join Beachball Help to reply.

  1. 0

    b3and88

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Correct is what's correct for you. You have to consider and repect how the vanilla system sets up the environment, and realize that the software you install and configure to make the machine yours will be different for everybody.

    Your list looks reasonable. Of course we all know that PATH is searched in the order listed, so your ~/bin takes precedence over everything, and stuff you install in /opt and /usr/local takes precedence over the vanilla system.

    You don't need a wrapper for every command. Environment variables are inherited. You simply need to set this stuff up in your ~/.bashrc and everything you run from the shell will inherit the environment. I think PATH may be exported automatically, but it never hurts to do so explicitly. So set those variables with lines like ...

    export PATH=

    export MANPATH=

    It's important to understand the subtle difference between executing a shell command file and sourceing it.

    bash# ./file

    ... will run the file in a subshell, so any variables and environment changes will only be known to the subshell. Your interactive shell is the parent process of the subshell.

    bash# . ./file

    ... will run the file in the current shell rather than forking a subshell, so any variables, functions, aliases, or environment changes will remain in effect.

    When a shell starts, your ~/.bashrc is sourced, not executed.

    Message was edited by: b3and88

    because he can't spel

  2. 0

    Bill Scott

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    The way I have been doing it is to test for the presence of a bin directory, and if it there, to add it:

    <pre>

    if [[ -d /opt/local/bin ]]; then

    APPEND_PATH=$APPEND_PATH:/opt/local/bin

    fi

    if [[ -d /opt/local/sbin ]]; then

    APPEND_PATH=$APPEND_PATH:/opt/local/sbin

    fi</pre>

    This is part of my
    /etc/zshenv file (bash will obey the same syntax) and I have internally defined $APPEND_PATH and $PREPEND_PATH

    zsh also has another nice feature:

    typeset -U path

    That makes sure your path doesn't grow out of control if you start subshells.

  3. 0

    cb0

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    b3and88:

    Good comments. Yes of course everyone has PATHS that are suited to their particular environments -- I am trying to determine if there is a common core

    among Darwin users. If a sensible intersection exists, my intent is harmonize it with man.config, MANPATH, EMACSPATH, etc etc --- and publish the result somewhere as guidance for people who are as frustrated as I am by this mess.

    I know I spend too much time making sure I invoke what I think I'm invoking, and ditto for all the associated bits and pieces (like man pages, subshells) etc.

    Since I'm doing the work anyway, I thought I'd try to do it right this time.

    incidentally, here's the latest version of my list:

    /Users/cb/bin:

    /opt/local/bin:

    /opt/local/sbin:

    /usr/local/bin:

    /usr/bin:

    /bin:

    /usr/local/sbin:

    /usr/sbin:

    /sbin:

    /usr/X11R6/bin:

    /usr/local/teTeX/bin/powerpc-apple-darwin-current

    Bill Scoot:

    Yes, I actually reworked fink's shell functions that do something cvery similar --- but I hadn't considered zsh --- thanks for the tip.

  4. 0

    Bill Scott

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    For the minimum path, I think

    MIN_PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/libexec

    is all that is required.

    Then if you add in X11, you have

    /usr/X11R6/bin

    and if you install 3rd-party stuff, you will need

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

    and if you install the Developer Tools, it helps to have

    /Developer/Tools

    and if you have fink, /sw/bin and /sw/sbin get put in if you source /sw/bin/init.sh

    and if you have MacPorts, /opt/local/bin and /opt/local/sbin are possibilities,

    Individual users may have ~/bin or ~/.bin

    and so on. That, in essence, is what that zshenv script I set up does. Almost all of it is bash-compliant.