bash -i中可用的命令无法在bash -l中访问

Fra*_*eng 3 linux vim bash shell terminal

我不知道如何描述它.它恰好发生在我使用vim和set shell=bash -l.然后我发现一个mm可以在终端中执行的命令无法在vim中执行.

我还发现,当我编写此命令run.sh并执行此脚本时.它仍然报道command not found.我认为我的$HOME/.bash*文件一定有问题$HOME/.profile.我相信它.profile几乎是一样的.bashrc.

rom*_*inl 5

来自$ man bash:

当bash作为交互式登录shell或作为具有--login选项的非交互式shell调用时,它首先从文件/ etc/profile中读取并执行命令(如果该文件存在).在读取该文件之后,它按顺序查找〜/ .bash_profile,〜/ .bash_login和〜/ .profile,并从存在且可读的第一个命令中读取并执行命令.

当启动不是登录shell的交互式shell时,如果该文件存在,bash将从〜/ .bashrc读取并执行命令.

所以:

shell   | files loaded    
--------+-----------------
bash -l | /etc/profile    
        | ~/.bash_profile 
        | ~/.bash_login
        | ~/.profile     
--------+-----------------
bash -i | ~/.bashrc
Run Code Online (Sandbox Code Playgroud)

  • 但请注意,加载第一个用户配置文件后,bash -l将停止.习惯上设置`.bash_profile`依次加载`.bashrc`和`.profile`,但除非以这种方式明确配置,否则不会发生这种情况. (2认同)