avatar
Bsx's tiny website
still alive...?
Invalid Date
if you like it...
Linux下环境配置文件的执行与配置
2022-10-22
linux, shell, os
226需阅读2分钟

几种shell

interactive login shell:登录系统后启动的shell,可以从键盘读取指令

interactive non-login shell:例如在当前shell中通过命令行启动的shell

non-interactive non-login shell:执行shell脚本时启动的shell


以下配置文件执行顺序介绍

  • /etc/profile
  • /etc/bashrc
  • ~/.bash_profile
  • ~/.bashrc
  • ~/.bash_login
  • ~/.profile
  • ~/.bash_logout

启动 interactive login shell 时的执行顺序

SHELL
# 伪代码 execute /etc/profile IF ~/.bash_profile exists THEN execute ~/.bash_profile ELSE IF ~/.bash_login exist THEN execute ~/.bash_login ELSE IF ~/.profile exist THEN execute ~/.profile END IF END IF END IF

用户注销时会执行

SHELL
# 伪代码 IF ~/.bash_logout exists THEN execute ~/.bash_logout END IF

启动 interactive non-login shell 的执行顺序

SHELL
# 伪代码 IF ~/.bashrc exists THEN execute ~/.bashrc END IF

当执行 ~/.bashrc 时会顺带执行 /etc/bashrc

SHELL
# cat ~/.bashrc if [ -f /etc/bashrc ]; then . /etc/bashrc fi

Important

启动 non-interactive shell 例如执行脚本时不会读取配置文件

;
© 2024 BsxAbout meStill exploring...
GitHub·Twitter·Pixiv·Mail·Telegram
Powered by nextjs 14.