bash 在 bash_profile 中设置路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19231286/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Setting path in bash_profile
提问by Mars
Why does setting a PATHrequire the :${PATH}at the end?
为什么设置 aPATH需要:${PATH}在最后?
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 PATHwithout going to a new line. That is, how would I append a PATHto the original PATHstatement.
如何在PATH不换行的情况下追加 a 。也就是说,我将如何将 a 附加PATH到原始PATH语句中。
If I wanted to put the following all in the first line, for instance. How does this interact with the :${PATH}part?
例如,如果我想将以下所有内容放在第一行。这如何与:${PATH}零件相互作用?
PATH=$PATH:/usr/local/mysql/bin
回答by Jon Lin
There's a difference between appending an existing path to the front or the end of the $PATHenvironment 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环境变量的前面或末尾是有区别的。bash 解析执行路径的方式是从列表的前面开始。这意味着如果您的路径中有这两个目录:
PATH="/dir1/bin:/dir2/bin"
And they both have the executable test.shin it, then when you run test.sh, it'll execute the one in /dir1/bin/test.shsince that directory appears first in the path.
而且它们都包含可执行文件test.sh,然后当您运行时test.sh,它将执行其中的一个,/dir1/bin/test.sh因为该目录首先出现在路径中。
Additionally, ${PATH}is the same as $PATH.
此外,${PATH}与$PATH.
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
is simply adding /Library/Frameworks/Python.framework/Versions/2.7/binto the front of the pathand
只是添加/Library/Frameworks/Python.framework/Versions/2.7/bin到路径的前面并且
PATH=$PATH:/usr/local/mysql/bin
is simply adding /usr/local/mysql/binto the end of the path.
只是添加/usr/local/mysql/bin到路径的末尾。
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"

