Joining array into $PATH in bash on OSX

 ̄綄美尐妖づ 提交于 2019-12-11 08:15:13

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/18568933/joining-array-into-path-in-bash-on-osx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!