Quantcast
Channel: CodeSection,代码区,Linux操作系统:Ubuntu_Centos_Debian - CodeSec
Viewing all articles
Browse latest Browse all 11063

shell脚本编程__bash的配置

$
0
0

shell 脚本编程__bash的配置

一、 bash 的配置文件:

按生效范围划分,存在两类:

全局配置:

/etc/profile

/etc/profile.d/*.sh

/etc/bashrc

个人配置:

~/.bash_profile

~/.bashrc

二、 shell 登陆的两种方式:

1 、交互式登录: Xshell 等软件登陆和终端的字符界面登陆

(1) 直接通过终端输入账号密码登录;

(2) 使用“ su -UserName ”切换的用户(完全切换)

执行顺序:

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


shell脚本编程__bash的配置

2 、非交互式登录:

(1)su UserName (不完全切换)

(2) 图形界面下打开的终端

(3) 执行脚本

执行顺序:

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

三、 profile 类和 bashrc 类:

按功能划分,存在两类:

profiile 类和 bashrc 类

1 、 profile 类:为交互式登录的 shell 提供配置

全局: /etc/profile, /etc/profile.d/*.sh

个人: ~/.bash_profile

功用:

(1) 用于定义环境变量

(2) 运行命令或脚本

2 、 bashrc 类:为非交互式和交互式登录的 shell 提供配置

全局: /etc/bashrc

个人: ~/.bashrc

功用:

(1) 定义命令别名和函数

(2) 定义本地变量

四、编辑配置文件生效:修改 profile 和 bashrc 文件后需生效

两种方法 :

1 重新启动 shell 进程

2 . 或 source

例 :. ~/.bashrc

五、 bash 退出任务 ;

保存在 ~/.bash_logout 文件中(用户)

在退出登录 shell 时运行

用于:创建自动备份;清除临时文件

事例:

1、 让用户(管理员或所有用户)的 PATH 环境变量的值多出一个路径,例如: /usr/local/apache2/bin


shell脚本编程__bash的配置

2、 用户 chesfer 登录时自动启用别名 rm=‘rm i’


shell脚本编程__bash的配置

3 、用户登录时,显示红色字体的警示提醒信息“ hi,dangerous !”


shell脚本编程__bash的配置

Viewing all articles
Browse latest Browse all 11063

Trending Articles