.bash_profile, .bashrc, login shell与normal shell(转)

.bash_profile, .bashrc, login shell与normal shell(转)[@more@]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。

主要有(我所知道的)有以下几种情形:

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-2.05b$ cat .bashrc
| echo "in bashrc"
| export TEST="rc"
|
| -bash-2.05b$ cat .bash_profile
| echo "in bash profile"
|
| -bash-2.05b$ cat test.sh
| #!/bin/bash
| echo $TEST
| bash-2.05b$
`-------------------------------------


..bash_profile, .bashrc, login shell与normal shell -*-outline-*-

(last-edit-by: lgfang 10/19/2006 23:32:32>)

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。

主要有(我所知道的)有以下几种情形:

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-2.05b$ cat .bashrc
| echo "in bashrc"
| export TEST="rc"
|
| -bash-2.05b$ cat .bash_profile
| echo "in bash profile"
|
| -bash-2.05b$ cat test.sh
| #!/bin/bash
| echo $TEST
| bash-2.05b$
`-------------------------------------

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10617542/viewspace-961945/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10617542/viewspace-961945/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值