Linux bashrc 直到运行 bash 命令才加载
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18393521/
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
bashrc not loading until run bash command
提问by mauzy_broadway
I am running freshly installed Arch Linux. When I log into a user (running bash) and try to use an alias from .bashrc, it gives me the 'command not found' error. But, if I reenter bash via the 'bash' command, the command works just fine.
我正在运行新安装的 Arch Linux。当我登录用户(运行 bash)并尝试使用 .bashrc 中的别名时,它给了我“找不到命令”错误。但是,如果我通过 'bash' 命令重新输入 bash,该命令就可以正常工作。
Yes, I am already in bash.
是的,我已经在 bash 中了。
env initially:
env 最初:
SHELL=/usr/bin/bash
env after running bash, it remains:
运行 bash 后的 env ,它仍然是:
SHELL=/usr/bin/bash
So I'm not quite sure where the problem is.
所以我不太确定问题出在哪里。
采纳答案by sjnarv
Read the INVOCATION section from "bash(1)" for full details (that's the man page for bash; use man bash
). Your first shell upon logging in is a "login shell", which means that the .bashrc
file is not sourced. Your second invocation creates an interactive shell, where .bashrc
is sourced.
阅读“bash(1)”中的 INVOCATION 部分以获取完整的详细信息(这是 bash 的手册页;使用man bash
)。您登录时的第一个 shell 是“登录 shell”,这意味着该.bashrc
文件不是来源。您的第二次调用创建了一个交互式 shell,.bashrc
来源是哪里。
If you always want the content of your .bashrc
file processed, you can add the following lines to your .bash_profile
file, creating that file if it does not already exist:
如果您始终希望.bashrc
处理文件的内容,您可以将以下几行添加到您的.bash_profile
文件中,如果该文件尚不存在,则创建该文件:
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
Per its man page, bash "[...] looks for ~/.bash_profile
, ~/.bash_login
, and ~/.profile
, in that order, and reads and executes commands from the first one that exists and is readable." Conventions and policies of your local system will determine which, if any, of these files already exist.
按照其手册页,打击“[...]验看~/.bash_profile
,~/.bash_login
以及~/.profile
,按照这个顺序读取并执行命令,从存在并且可读的第一个。” 您本地系统的约定和策略将确定这些文件中的哪些(如果有)已经存在。
A word of caution: be aware that creating a new .bash_profile
in your home directory could have the unintended side-effect of preventing the reading and executing of commands in a .bash_login
or .profile
file already present, changing further the behavior of subsequent logins.
警告:请注意,.bash_profile
在您的主目录中创建新目录可能会产生意想不到的副作用,即阻止读取和执行已存在的.bash_login
或.profile
文件中的命令,从而进一步改变后续登录的行为。
回答by Paul Evans
Have you looked at your ~/.profile
, ~/.bash_login
and ~/.bash_profile
files?
你看过你的~/.profile
,~/.bash_login
和~/.bash_profile
文件吗?