bash 为什么 ~/.bash_profile 不起作用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18350252/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 06:19:34  来源:igfitidea点击:

Why ~/.bash_profile doesn't work?

bash.bash-profile

提问by AntonioK

I'm using Linux Mint. My login shell (cat /etc/passwd | grep myUserName) is bash.

我正在使用 Linux Mint。我的登录 shell ( cat /etc/passwd | grep myUserName) 是 bash。

After I start my graphical desktop environment and run terminal emulator from it, I could see that .bash_profileis not sourced (environment vars that exportin it is unset). But if I login from text console (ctrl+alt+F1) or manually run bash -lfrom terminal emulator, .bash_profileworks fine.

在我启动我的图形桌面环境并从中运行终端模拟器后,我可以看到它.bash_profile没有来源(其中的环境变量export未设置)。但是,如果我从文本控制台登录(ctrl+ alt+ F1)或手动运行bash -l的终端仿真器,.bash_profile工作正常。

Am I wrong when I think that .bash_profileshould source when X starts and all export'ed vars should be available in terminal, running from X?

当我认为.bash_profile应该在 X 启动并且所有export'ed vars 应该在终端中可用,从 X 运行时,我错了吗?

采纳答案by chepner

You can probably change the default command that a new terminal window runs to be a login shell, which would then source your .bash_profile. How to do that is off-topic for Stack Overflow, however.

您可能可以将新终端窗口运行的默认命令更改为登录 shell,然后该命令将提供您的.bash_profile. 然而,如何做到这一点对于 Stack Overflow 来说是题外话。

The other issue is the shells currently started by your terminal emulator inherit their environment not from another login shell, but from your window manager or desktop environment itself. There is probably some configuration file to which you can add environment variables, which will serve the same purpose as .bash_profile. Again, this is specific to your WM/DE and off-topic for Stack Overflow.

另一个问题是当前由终端模拟器启动的 shell 不是从另一个登录 shell 继承它们的环境,而是从您的窗口管理器或桌面环境本身继承。可能有一些配置文件可以添加环境变量,它们的作用与.bash_profile. 同样,这特定于您的 WM/DE 和 Stack Overflow 的题外话。

回答by Aleks-Daniel Jakimenko-A.

Use .bashrcinstead of .bash_profile

使用.bashrc代替.bash_profile

Here is some explanation: http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html

这里有一些解释:http: //www.joshstaiger.org/archives/2005/07/bash_profile_vs.html