set:显示(设置)shell变量 包括的私有变量以及用户变量,不一样类的shell有不一样的私有变量 bash,ksh,csh每中shell私有变量都不同html
env:显示(设置)用户变量变量linux
export:显示(设置)当前导出成用户变量的shell变量。shell
举个例子来说:bash
[www.linuxidc.com@linuxidc ~]$ aaa=bbb --shell变量设定
[www.linuxidc.com@linuxidc ~]$ echo $aaa
bbb
[www.linuxidc.com@linuxidc ~]$ env| grep aaa --设置完当前用户变量并无
[www.linuxidc.com@linuxidc ~]$ set| grep aaa --shell变量有
aaa=bbb
[www.linuxidc.com@linuxidc ~]$ export| grep aaa --这个指的export也没导出,导出变量也没有
[www.linuxidc.com@linuxidc ~]$ export aaa --那么用export 导出一下
[www.linuxidc.com@linuxidc ~]$ env| grep aaa --发现用户变量内存在了
aaa=bbb
总结:linux 分 shell变量(set),用户变量(env), shell变量包含用户变量,export是一种命令工具,是显示那些经过export命令把shell变量中包含的用户变量导入给用户变量的那些变量.工具
最根本的设置、更改变量的配置文件 ~/.bash_profile ~/.bashrc ~/.bash_logouthtm
~/.bash_profile 用户登陆时被读取,其中包含的命令被执行内存
~/.bashrc 启动新的shell时被读取,并执行get
~/.bash_logout shell 登陆退出时被读取it
引自io
.bash_profile会用在login shell .bashrc 使用在interactive non-login shell
Bash下每一个用户均可以配置两个初始文件:.bash_profile和.bashrc,文件存储在~根目录中。man bash中的相关解释以下:
,---------------------------------------------------------------------------- | ~/.bash_profile | The personal initialization file, executed for login shells | ~/.bashrc | The individual per-interactive-shell startup file `----------------------------------------------------------------------------
每次bash做为login shell启动时会执行.bash_profile。
每次bash做为普通的交互shell(interactive shell)启动时会执行.bashrc
注意 1)在shell脚本中“#!/usr/bin/bash”启动的bash并不执行.bashrc。由于这里的bash不是interactive shell。
2)bash做为login shell(login bash)启动时并不执行.bashrc。虽然该shell也是interactive shell,但它不是普通的shell。
尽管login bash启动时不会自动执行.bashrc,惯例上会在.bash_profile中显式调用.bashrc。因此在你的.bash_profile文件中,极可能会看到以下的代码片断: [plain] view plaincopy在CODE上查看代码片派生到个人代码片 if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
.bashrc 使用在interactive non-login shell。意思是你每次运行一个bash脚本的话,.bashrc就会被执行一次。有个简单的方法,你在.bash_profile和.bashrc里 都用echo打印点东西。,就能够看到着两个文件都是何时被执行的了。
编辑/etc/profile修改全局环境变量 编辑.bash_profile修改当前用户的环境变量 修改完成以后source一下便可生效,例如source ~/.bash_profile
ps: 常会看到xxxrc ——以“rc”结尾的配置文件。“rc”好像是“Runtime Command”的意思。