变量
普通变量 KEY=Value
环境变量 export KEY=Value , declare -x KEY=Value
变量的应用 $KEY ${KEY}
撤销: unset KEY
变量的作用域
普通变量的作用域为当前shell
环境变量的作用域为当前shell以及子shell
bash 的配置文件
profile 为交互式登录的shell进程提供配置
bashrc 为非交互登录的shell 进程提供配置
交互 | 非交互 | |
---|---|---|
profile | bashrc | |
su - username | su username | |
定义 | 直接通过某终端输入账号和密码后登录打开的shell 进程 | 图形界面下打开的终端,运行脚本 |
文件 | /etc/profile | /etc/bashrc |
全局 | /etc/profile.d/*.sh | |
本人 | ~/bash_profile | ~/.bashrc |
功用 | 1)用于定义环境变量 2)运行命令或脚本 | 1)定义本地变量 2)定义命令别名 |
顺序 | /etc/profile->/etc/profile.d/*->/.bash_profile->/.bashrc->/etc/bashrc | ~/.bashrc->/etc/bashrc->/etc/profile.d/*.sh |
source 或 . /PATH_FILE | source 或 . /PATH_FILE |
捕捉信号
kill -l
trap -l
man 7 singals
trap ‘COMMAND’ SIGNALS
常用的可以进行捕捉的信号
HUP,INT
在bash中使用ACSII颜色