bash/cygwin/$PATH:我真的必须重新启动才能改变 $PATH 吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1122924/
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
bash/cygwin/$PATH: Do I really have to reboot to alter $PATH?
提问by behindthefall
I wanted to use the Python installed under cygwin rather than one installed under WinXP directly, so I edited ~/.bashrc and sourced it. Nothing changed. I tried other things, but nothing I did changed $PATH in any way. So I rebooted. Aha; now $PATH has changed to what I wanted.
我想使用安装在cygwin下的Python,而不是直接安装在WinXP下的,所以我编辑了~/.bashrc并获取了它。没有改变。我尝试了其他的东西,但我没有以任何方式改变 $PATH 。所以我重新启动了。啊哈; 现在 $PATH 已更改为我想要的。
But, can anyone explain WHY this happened? When do changes to the environment (and its variables) made via cygwin (and bash) take effect only after a reboot?
但是,谁能解释为什么会这样?通过 cygwin(和 bash)对环境(及其变量)所做的更改何时仅在重新启动后生效?
(Is this any way to run a railroad?) (This question is unlikely to win any points, but I'm curious, and I'm also tired of wading through docs which don't help on this point.)
(这是运行铁路的任何方式吗?)(这个问题不太可能赢得任何分数,但我很好奇,而且我也厌倦了在这一点上没有帮助的文档。)
回答by Paused until further notice.
Try:
尝试:
PATH="${PATH}:${PYTHON}"; export PATH
Or:
或者:
export PATH="${PATH}:${PYTHON}"
the quotes preserve the spaces and newlines that you don'thave in your directory names. I repeat "don't".
引号保留了目录名称中没有的空格和换行符。我再说一遍“不要”。
If you want to change the path for the current environment and any subsequent processes, use something similar to either of the commands above; they are equivalent.
如果要更改当前环境和任何后续进程的路径,请使用类似于上述任一命令的内容;它们是等价的。
If you want to change the path for the next time you start Bash, edit ~/.bashrcand add one of the above (for example) or edit the existing PATHsetting command that you find there.
如果您想在下次启动 Bash 时更改路径,请编辑~/.bashrc并添加上述之一(例如)或编辑PATH您在那里找到的现有设置命令。
If you want to affect both the current environment and any subsequent ones (i.e. have an immediate and a "permanent" affect), edit ~/.bashrcand do one of the following: type one of the first two forms shown above orsource the ~/.bashrcfile. Sometimes, you may not want to do the sourcing if, for example, it would undo some temporary thing that you're making use of currently like have some other variables set differently than ~/.bashrcwould set (reset) them to.
如果您想影响当前环境和任何后续环境(即具有直接和“永久”影响),请编辑~/.bashrc并执行以下操作之一:键入上面显示的前两种形式之一或源~/.bashrc文件。有时,您可能不想进行采购,例如,如果它会撤消您当前正在使用的一些临时事物,例如将其他一些变量设置为与~/.bashrc设置(重置)不同的其他变量。
I don't think you need to worry about hash unless you're either doing some serious rearranging or adding some local replacements for system utilities perhaps.
我认为您不需要担心哈希,除非您正在进行一些认真的重新排列或为系统实用程序添加一些本地替代品。
回答by Freddy
If you want your changes to be permanent, you should modify the proper file (.bashrc in this case) and perform ONE of the following actions:
如果您希望更改是永久性的,您应该修改正确的文件(在本例中为 .bashrc)并执行以下操作之一:
- Restart the cygwin window
- source .bashrc (This should work, even if is not working for you)
- . .bashrc (that is dot <space> <filename>)
- 重新启动 cygwin 窗口
- source .bashrc (这应该可以工作,即使不适合你)
- . .bashrc(即点 <space> <filename>)
However, .bashrc is used by default when using a BASH shell, so if you are using another shell (csh, ksh, zsh, etc) then your changes will not be reflected by modifying .bashrc.
但是,在使用 BASH shell 时默认使用 .bashrc,因此如果您使用另一个 shell(csh、ksh、zsh 等),那么修改 .bashrc 将不会反映您的更改。
回答by ars
A couple of things to try and rule out at least:
至少要尝试排除以下几点:
Do you get the same behavior as the following from the shell? (Pasted from my cygwin, which works as expected.)
$ echo $PATH /usr/local/bin:/usr/bin:/bin $ export PATH=$PATH:/cygdrive/c/python/bin $ echo $PATH /usr/local/bin:/usr/bin:/bin:/cygdrive/c/python/bin
Is your bashrc setting the PATH in a similar way to the above? (i.e. the second command).
Does your bashrc contain a "source" or "." command anywhere? (Maybe it's sourcing another file which overwrites your PATH variable.)
您是否从 shell 获得与以下相同的行为?(粘贴自我的 cygwin,按预期工作。)
$ echo $PATH /usr/local/bin:/usr/bin:/bin $ export PATH=$PATH:/cygdrive/c/python/bin $ echo $PATH /usr/local/bin:/usr/bin:/bin:/cygdrive/c/python/bin
您的 bashrc 是否以与上述类似的方式设置 PATH?(即第二个命令)。
您的 bashrc 是否包含“源”或“.” 命令任何地方?(也许它正在获取另一个覆盖您的 PATH 变量的文件。)
回答by Ross Rogers
You may need to re-initialize bash's hashes after modifying the path variable:
修改路径变量后,您可能需要重新初始化 bash 的哈希值:
hash -r

