航母有多少台发动机:环境变量之.bash_profile和.bashrc说明

来源:百度文库 编辑:九乡新闻网 时间:2024/04/26 05:57:05
百度首页 | 百度空间 |登录
jiaxi
加喜和英英的家
主页博客相册|个人档案 |好友
查看文章
.bash_profile和.bashrc说明(转)
2008-01-02 15:55
/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 运行的
通常二者设置大致相同,所以通常前者会调用后者。

* 每次bash作为login shell启动时会执行.bash_profile。
主要有(我所知道的)有以下几种情形:
a) 每次登录到服务器时默认启动的shell
b) “su -l [USER]”时进入的shell
c) “bash --login”进入的shell
* 每次bash作为普通的交互shell(interactive shell)启动时会执行.bashrc
常见的有:
i) “su [USER]”进入的shell
ii) 直接运行“bash”命令进入的shell。
** 注意
1, 在shell脚本中“#!/usr/bin/bash”启动的bash并不执行.bashrc。因为这里的bash不是
interactive shell。
2, bash作为login shell(login bash)启动时并不执行.bashrc。虽然该shell也是interactive shell,
但它不是普通的shell。
* 一般.bash_profile里都会调用.bashrc
尽管login bash启动时不会自动执行.bashrc,惯例上会在.bash_profile中显式调用.bashrc。
,-------------------------------------
| if [ -f ~/.bashrc ]; then
|    . ~/.bashrc
| fi
`-------------------------------------
.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
BASH_ENV=$HOME/.bashrc
USERNAME="root"
export USERNAME BASH_ENV PATH
类别:Linux |添加到搜藏 | 浏览(252) |评论 (0)
上一篇:生成uImage    下一篇:2008年的十大预测
相关文章:
.bash_profile, .bashrc — ZZ.bash_profile 与 .bashrc 文件
.bash_profile, .bashrc, login ....bash_profile和.bashrc的什么区...
最近读者:
登录后,您就出现在这里。
jieshuai20短发也飄羿石明轻灵TsuiLeon6669980xrathitdigwtxzengzhaonong
网友评论:
发表评论:
姓 名:   注册 |登录 *姓名最长为50字节
网址或邮箱: (选填)
内 容: 插入表情
▼ 闪光字
验证码:
看不清?

");//-->
©2009 Baidu