Search code examples
pathosx-mountain-lionbash

Joining array into $PATH in bash on OSX


Trying to customize the $PATH env variable on OSX with the following in .profile:

PATH=(
    $HOME/bin
    /usr/local/bin
    /usr/bin
    /bin
    /usr/sbin/
    /sbin
)

PATH=$(IFS=:; echo "${PATH[*]}")
export PATH

When this is loaded, I verified the path by doing echo $PATH and the output looks correct:

echo $PATH
/Users/apple/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

However, it doesn't look like any of the above path works.

ls
- bash: (something like not able to find command ls, which is in /usr/bin)

What am I missing here?


Solution

  • Change PATH array variable name to something different, like:

    P=(
        $HOME/bin
        /usr/local/bin
        /usr/bin
        /bin
        /usr/sbin/
        /sbin
    )
    
    PATH=$(IFS=:; echo "${P[*]}")
    export PATH
    

    I'm not sure why, though. If I figure that out, I'll update this answer.

    Update: for a little bit more info on this, see this topic.