Chinaunix首页 | 论坛 | 博客
  • 博客访问: 285573
  • 博文数量: 84
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: -10
  • 用 户 组: 普通用户
  • 注册时间: 2016-07-05 09:11
文章分类
文章存档

2015年(1)

2014年(6)

2013年(8)

2012年(1)

2011年(6)

2010年(2)

2009年(16)

2008年(44)

我的朋友

分类: LINUX

2008-05-01 11:10:36

/etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行.
并从/etc/profile.d目录的配置文件中搜集shell的设置.
/etc/bashrc:为每一个运行bash shell的用户执行此文件.当bash shell被打开时,该文件被读取.
~/.bash_profile:每个用户都可使用该文件输入专用于自己使用的shell信息,当用户登录时,该
文件仅仅执行一次!默认情况下,他设置一些环境变量,执行用户的.bashrc文件.
~/.bashrc:该文件包含专用于你的bash shell的bash信息,当登录时以及每次打开新的shell时,该
该文件被读取.
~/.bash_logout:当每次退出系统(退出bash shell)时,执行该文件.
 
另外,/etc/profile中设定的变量(全局)的可以作用于任何用户,而~/.bashrc等中设定的变量(局部)只能继承/etc/profile中的变量,他们是"父子"关系.

~/.bash_profile 是交互式、login 方式进入 bash 运行的
~/.bashrc 是交互式 non-login 方式进入 bash 运行的
通常二者设置大致相同,所以通常前者会调用后者。
 
[root@test wangzm]# cat .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi
# User specific environment and startup programs
kk=oo
PATH=$PATH:$HOME/bin

[root@test wangzm]# cat .bashrc
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi
cc=dd
# User specific aliases and function
 
[root@wangzm]# cat /etc/profile
JAVA_HOME=/home/jdk1.6.0_10
[root@wangzm]# echo $JAVA_HOME
/home/jdk1.6.0_10

********************************************
[root@wangzm]# cat .bash_profile
rr=tt
[root@wangzm]# su - wangzm
-bash-3.2$ echo $rr
tt
********************************************
 
[root@wangzm]# cat .bashrc
hh=kk
[root@wangzm]# su - wangzm
-bash-3.2$ echo $hh

-bash-3.2$

*********************************************
[root@wangzm]# cat /etc/bashrc
mm=nn
[root@wangzm]# su - wangzm
-bash-3.2$ echo $mm

-bash-3.2$

************************************************

[root@wangzm]# cat .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
[root@wangzm]# cat .bashrc
hh=kk
[root@wangzm]# su - wangzm
-bash-3.2$ echo $hh
kk

******************************************************
[root@wangzm]# cat .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
[root@wangzm]# cat .bashrc
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi
# User specific aliases and function
[root@wangzm]# cat /etc/bashrc
mm=nn
[root@wangzm]# su - wangzm
[wangzm@~]$ echo $mm
nn
***********************************************************
 
~/.bashrc该文件 和/etc/profile ~/.bash_profile 最大的不同是,每次执行bash时,~/.bashrc都会被再次读取,
也就是变量会再次地设置,而/etc/profile,~/.bash_profile 只有在登录时才读取
之间关系如下
 所有用户登录时(所有shell) /etc/profile会被执行
 su - user 每个用户登录时 .bash_profile会执行,进而去执行./bashrc, ./etc/bashrc(所以在.bashrc 和 /etc/bashrc里设置变量都会被执行)
 所有用户登录时(bash) /etc/bashrc会执行
 每次执行bash时,~/.bashrc都会被再次读取
在/etc/bashrc设置变量,会被执行两次,一次是登录被执行,一次su - user时候又被执行一次。
 
注:实际上 .bashrc 和/etc/bashrc不能自己执行,是.bash_profile 和.bashrc脚本里执行的。
 
========================================================
阅读(717) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~