bashrc 和 profile 区别 #
shell分类 #
login and non-login shell:
使用 su -
命令,或者 ssh
登录服务器,都会默认为该用户启动 login shell,此模式下会执行 /etc/profile 和 ~/.profile ,但不会执行任何 rc 文件,所以一般会在 profile 里面手动去执行 rc 文件。
interactive and non-interactive shell:
交互式shell提供了命令提示符 PS1
,可以输入命令,此模式下会执行 /etc/basrc 和 ~/.bashrc 。
非交互式shell一般是通过 bash -c CMD
来执行的bash,此模式下不会执行任何 rc 文件。
在 Ubuntu 或 Debian 系统中,没有 /etc/bashrc ,而会有 /etc/bash.bashrc 文件。
bashrc 和 profile #
profile:
全局 shell 配置文件,用于设置环境变量等。
bashrc:
交互式 shell 初始化配置文件,用于补充 function、alias 等。