.bash_profile, .bashrc, login shell与normal shell
2009-02-23 10:02
387 查看
Bash下每个用户都可以配置两个初始文件:.bash_profile和.bashrc。man bash中的相关解释如下:
~/.bash_profile
The personal initialization file, executed for login shells
~/.bashrc
The individual per-interactive-shell startup file
以前一直没细想两者的区别,今天整理了一下。
每次登录到服务器时默认启动的shell
“su -l [USER]”时进入的shell
“bash —login”进入的shell
“su [USER]”进入的shell
直接运行“bash”命令进入的shell。
bash作为login shell(login bash)启动时并不执行.bashrc。虽然该shell也是interactive shell,但它不是普通的shell。
~/.bash_profile
The personal initialization file, executed for login shells
~/.bashrc
The individual per-interactive-shell startup file
以前一直没细想两者的区别,今天整理了一下。
每次bash作为login shell启动时会执行.bash_profile。
主要有(我所知道的)有以下几种情形:每次登录到服务器时默认启动的shell
“su -l [USER]”时进入的shell
“bash —login”进入的shell
每次bash作为普通的交互shell(interactive shell)启动时会执行.bashrc
常见的有:“su [USER]”进入的shell
直接运行“bash”命令进入的shell。
注意
在shell脚本中“#!/usr/bin/bash”启动的bash并不执行.bashrc。因为这里的 bash不是interactive shell。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$
相关文章推荐
- 环境配置文件: login, non-login shell, /etc/profile, ~/.bash_profile, source, ~/.bashrc
- 关于login/interactive/no-interactive shell和profile/bash_profile/bashrc
- 配置文件.profile,.login,.bash_profile和.bashrc的区别
- .profile,.login,.bash_profile和.bashrc的区别
- shell的初始化文件:/etc/profile和/etc /bashrc(bash.bashrc)
- shell的初始化文件:/etc/profile和/etc/bashrc(bash.bashrc)
- shell的初始化文件:/etc/profile和/etc /bashrc(bash.bashrc)
- 关于shell启动时调用的几个配置文件/etc/profile .profile .bash_profile .bashrc等
- shell的初始化文件:/etc/profile和/etc/bashrc(bash.bashrc)
- bashrc,bash_profile等shell配置文件详解
- 【shell】/etc/bashrc、~/.bashrc、~/.bash_profile的区别和作用
- shell登录时的环境是如何配置的呢?—— bashrc、profile、bash.bashrc关系
- 练习 3:Bash:Shell、.profile、.bashrc、.bash_history。
- Bash初始化文件/etc/profile .bash_pro-file .bash_login .profile .bash_logout /etc/bashrc .bashrc
- /etc/profile与/etc/bashrc、交互式与非交互式、login与non-login shell的区别
- shell: .bash_profile和.bashrc的区别(如何设置生效)
- profile && login && bash_profile && bashrc的区别
- shell的初始化文件:/etc/profile和/etc /bashrc(bash.bashrc)
- /etc/profile、~/.bashrc、/etc/bashrc、~/.bash_profile、 ~/.bash_login、 ~/.profile、/etc/environment
- Linux中profile、bashrc、bash_profile之间的区别和联系