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

标签 linux bash shell vim terminal

不知道怎么形容。它只是在我使用 vim 和 set shell=bash -l 时发生。然后我发现一个叫mm的命令可以在terminal中执行,但是在vim中却无法执行。

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

最佳答案

来自 $ man bash:

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it 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.

When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists.

所以:

shell   | files loaded    
--------+-----------------
bash -l | /etc/profile    
        | ~/.bash_profile 
        | ~/.bash_login
        | ~/.profile     
--------+-----------------
bash -i | ~/.bashrc

关于linux - bash -i 中可用的命令无法在 bash -l 中访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9716849/

相关文章:

linux - cURL cookie 语法(来自 bash CLI,不是 cookie 文件)

linux - 如何验证 shell 脚本中的参数数量(强制和可选)?

linux - 如何在bash中将结果转换为整数

html - Xidel 提取标签内的数据——原始输出

c - UART 没有读取我想要的那么多数据

Bash 循环获取文件名中的前 12 个字符,使用输出为每个文件运行 touch -t 命令

BASH,目录更新时自动运行脚本?

shell - 为现有png图片添加标签,使用convert

Linux Shell-Script 代码没有按预期执行

linux - "type"命令在 Git Bash 上未按预期工作