Login Shell 和 Non-Login Shell 有什么区别 ?

什么是 Shell?
Shell 是一个命令解释器或一个程序,它读取和解释用户发给它的命令。
Shell 执行基本命令,如运行程序,输入文本、打印输出。它还负责处理错误以及其他需要用户干预的情况。可以使用 Shell 自动执行现有任务或完全创建新任务。
Shell 为系统中的许多工具提供了一个公共接口。例如,如果 Shell 执行一个操作需要一个系统命令,它将搜索该命令,然后代表用户执行它。
有哪些不同类型的 Shell?
本例中使用了 non-login Shell 或 login shell, 它使用 Bash Shell。Shell 执行预配置的脚本来建立它们的环境。
Shell 在 Linux 操作系统架构中扮演着重要角色。它从用户接收输入并向内核发送指令,从内核接收输出并将其返回给用户。
什么是 Login Shell?
当用户通过终端、SSH 或其他方式成功登录 Linux 操作系统,或者使用“su -”命令切换用户,将创建一个 login shell。
当一个 login shell 启动时,它执行以下预先配置的脚本设置环境:
- Login shell invokes
/etc/profile -
/etc/profileinvokes scripts in /etc/profile.d/*.sh - Then executes users
~/.bash_profile -
~/.bash_profileinvokes users~/.bashrc -
~/.bashrcinvokes/etc/bashrc
什么是 Non-Login Shell?
non-login shell 由 login shell 启动。例如,一个 shell 从另一个 shell 启动,或者从一个 non-login shell 的程序启动。
对于不用于登录系统的 shell,执行以下脚本设置 shell 环境。
- Non login shell first executes
~/.bashrc - Then
~/.bashrcexecutes/etc/bashrc -
/etc/bashrccalls the scripts in/etc/profile.d
如何区分 Login / Non-Login Shell
执行以下命令查看当前 shell 是 login shell 还是 non-login shell:
echo $0
login shell 输出为 -bash or -su . non-login shell 输出为 bash or su

我的开源项目
评论已关闭
