Setting path in bash_profile

主宰稳场 提交于 2019-12-04 10:56:07

问题


Why does setting a PATH require the :${PATH} at the end?

PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"

When I append a path to this I would do

PATH=$PATH:...

How do I append a PATH without going to a new line. That is, how would I append a PATH to the original PATH statement.

If I wanted to put the following all in the first line, for instance. How does this interact with the :${PATH} part?

PATH=$PATH:/usr/local/mysql/bin

回答1:


There's a difference between appending an existing path to the front or the end of the $PATH environment variable. The way bash resolves execution paths is by starting from the front of the list. That means if you have these two directories in your path:

PATH="/dir1/bin:/dir2/bin"

And they both have the executable test.sh in it, then when you run test.sh, it'll execute the one in /dir1/bin/test.sh since that directory appears first in the path.

Additionally, ${PATH} is the same as $PATH.

PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"

is simply adding /Library/Frameworks/Python.framework/Versions/2.7/bin to the front of the path and

PATH=$PATH:/usr/local/mysql/bin

is simply adding /usr/local/mysql/bin to the end of the path.

So how do you do both in one line? Something like this:

PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}:/usr/local/mysql/bin"


来源:https://stackoverflow.com/questions/19231286/setting-path-in-bash-profile

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