bash文件的详细解读

一、bash的分类

1. 按生效范围分类

  • 全局生效
    /etc/profile
    /etc/profile.d/*.sh
    /etc/bashrc
  • 个人用户生效
    ~/.bash_profile
    ~/.bashrc

2.按功能分类

  • profile类-----用于定义环境变量,运行命令或者脚本
  • bashrc类-----用于别名、函数、本地变量

二、配置文件生效的顺序

1.交互式登录
通过ssh、telent等远程连接方式登录
通过su - 用户名 切换用户
/etc/profile--->/etc/profile.d/*.sh---> ~/.bashrc_profile--->~/.bashrc--->/etc/bashrc

2.非交互式登录
su name 切换用户
通过图形界面打开终端窗口
~/.bashrc--->/etc/bashrc--->/etc/profile/*.sh

3.退出时运行的脚本
用户退出时自动运行~/.bash_logout,可以用户创建自动备份、清理文件等等

4.配置文件的生效

  • 重新启动shell
  • sorurce ~/.bashrc 等价于 . ~/.bashrc
posted @ 2017-08-02 20:44  农夫三拳L  阅读(524)  评论(0编辑  收藏  举报