标签:Environment Configuration

共 1 篇相关文章

IT 累计浏览 4,510

.bash_pfofile、.bash_logout和.bashrc

Linux 下 .bash_profile、.bashrc 和 .bash_logout 对 bash 有特殊含义,能在登录、调用 shell 或退出时自动建立登录账号环境。如果主目录下没有这些文件,用户登录会使用默认的系统文件 /etc/profile。其中 .bash_profile 最重要,在用户每次登录系统时被读取并执行,用于定义登录账号的基本环境,包括 PATH 路径和 alias 别名设置等;修改后需退出并重新登录才生效,也可用 source .bash_profile 让更改立即生效。而 .bash_profile 只被登录 shell 读取,若初始 shell 为 cshell,执行 bash 切换到 bash 环境时不会读取 .bash_profile,此时读取的是 .bashrc。

.bash_logout 则在每次登录 shell 退出时被读取执行,可用于定制用户环境,比如删除账号内临时文件、记录登录系统所花时间等;该文件不存在则退出时不执行其他命令。简单来说,.bash_profile 类似编程中的构造函数,登录 shell 时用于环境初始化;.bashrc 是 .bash_profile 的替补;.bash_logout 类似析构函数,登录 shell 退出时按其指示办事。