简体   繁体   English

在运行bash命令之前,bashrc不会加载

[英]bashrc not loading until run bash command

I am running freshly installed Arch Linux. 我正在运行全新安装的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. 当我登录用户(运行bash)并尝试使用.bashrc中的别名时,它给了我“找不到命令”错误。 But, if I reenter bash via the 'bash' command, the command works just fine. 但是,如果我通过“ bash”命令重新输入bash,则该命令可以正常工作。

Yes, I am already in bash. 是的,我已经受到重击。

env initially: 最初的环境:

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. 所以我不太确定问题出在哪里。

Read the INVOCATION section from "bash(1)" for full details (that's the man page for bash; use man bash ). 阅读“ bash(1)”中的“ INVOCATION”部分以获取全部详细信息(这是bash的手册页;请使用man bash )。 Your first shell upon logging in is a "login shell", which means that the .bashrc file is not sourced. 登录时的第一个外壳是“登录外壳”,这意味着.bashrc文件不是源文件。 Your second invocation creates an interactive shell, where .bashrc is sourced. 第二次调用将创建一个交互式外壳,该外壳来自.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文件的内容,则可以.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." bash在其手册页中,“ [...]按照该顺序查找~/.bash_profile~/.bash_login~/.profile ,并从存在且可读的第一个命令中读取并执行命令。” Conventions and policies of your local system will determine which, if any, of these files already exist. 本地系统的约定和策略将确定这些文件中已经存在的文件(如果有)。

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文件中的命令,从而进一步更改后续登录的行为。

您是否查看过~/.profile~/.bash_login~/.bash_profile文件?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM