您的位置:首页 > 运维架构 > Shell

shell - 配置文件

2020-08-11 15:09 1236 查看

shell - 配置文件

bash shell 的配置文件很多,分类如下

生效范围分类

全局配置类:

/etc/profile
/etc/profile.d/*.sh
/etc/bashrc

个人配置类:

~/.bash_profile
~/.bashrc

功能分类

profile 类

profile 类为交互式登录的shell 提供配置,用于定义环境变量或运行命令和脚本

全局:/etc/profile, /etc/profile.d/*.sh
个人:~/.bash_profile

bashrc类

bashrc类为非交互式和交互式登录的shell 提供配置,用于定义命令别名和函数或定义本地变量

全局:/etc/bashrc
个人:~/.bashrc

编辑配置文件生效

修改profile 和bashrc 文件后需生效两种方法

1 重新启动shell 进程
2 source | . 配置文件名

注意:source 会在当前shell 中执行脚本,一般只用于执行配置文件,或在脚本中调用另一个脚本的场景

shell 登录两种方式分类

交互式登录

1 直接通过终端输入账号密码登录
2 使用 su - UserName 切换的用户

配置配置生效和执行顺序

#放在每个文件最前
/etc/profile
/etc/profile.d/*.sh
/etc/bashrc~/.bash_profile
~/.bashrc/etc/bashrc

#放在每个文件最后
/etc/profile.d/*.sh
/etc/bashrc
/etc/profile
/etc/bashrc		#该文件会执行两次
~/.bashrc
~/.bash_profile

注意:文件之间的调用关系,写在同一个文件的不同位置,将影响文件的执行顺序

非交互式登录

su UserName
图形界面下打开的终端
执行脚本
任何其他的bash 实例

执行顺序

/etc/profile.d/*.sh
/etc/bashrc
~/.bashrc

bash 退出任务

保存在~/.bash_logout 文件中(用户),在退出登录shell 时运行。用于创建自动备份,清除临时文件

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: