.bash_profile和.bashrc说明
此文件為系統(tǒng)的每個(gè)用戶設(shè)置環(huán)境信息,當(dāng)用戶第一次登錄時(shí),該文件被執(zhí)行。并從/etc/profile.d目錄的配置文件中搜集shell的設(shè)置.
/etc/bashrc:
為每一個(gè)運(yùn)行bash shell的用戶執(zhí)行此文件.當(dāng)bash shell被打開時(shí),該文件被讀取.
~/.bash_profile:
每個(gè)用戶都可使用該文件輸入專用于自己使用的shell信息,當(dāng)用戶登錄時(shí),該文件僅僅執(zhí)行一次!默認(rèn)情況下,他設(shè)置一些環(huán)境變量,執(zhí)行用戶的.bashrc文件.
~/.bashrc:
該文件包含專用于你的bash shell的bash信息,當(dāng)?shù)卿洉r(shí)以及每次打開新的shell時(shí),該該文件被讀取.
~/.bash_logout:
當(dāng)每次退出系統(tǒng)(退出bash shell)時(shí),執(zhí)行該文件.?
另外,/etc/profile中設(shè)定的變量(全局)的可以作用于任何用戶,而~/.bashrc等中設(shè)定的變量(局部)只能繼承/etc/profile中的變量,他們是"父子"關(guān)系.?
~/.bash_profile 是交互式、login 方式進(jìn)入 bash 運(yùn)行的
~/.bashrc 是交互式 non-login 方式進(jìn)入 bash 運(yùn)行的
通常二者設(shè)置大致相同,所以通常前者會(huì)調(diào)用后者。
?
* 每次bash作為login shell啟動(dòng)時(shí)會(huì)執(zhí)行.bash_profile。
主要有(我所知道的)有以下幾種情形:
a) 每次登錄到服務(wù)器時(shí)默認(rèn)啟動(dòng)的shell
b) “su -l [USER]”時(shí)進(jìn)入的shell
c) “bash --login”進(jìn)入的shell
* 每次bash作為普通的交互shell(interactive shell)啟動(dòng)時(shí)會(huì)執(zhí)行.bashrc
常見的有:
i) “su [USER]”進(jìn)入的shell
ii) 直接運(yùn)行“bash”命令進(jìn)入的shell。
** 注意
1, 在shell腳本中“#!/usr/bin/bash”啟動(dòng)的bash并不執(zhí)行.bashrc。因?yàn)檫@里的bash不是
??? interactive shell。
2, bash作為login shell(login bash)啟動(dòng)時(shí)并不執(zhí)行.bashrc。雖然該shell也是interactive shell,
?? 但它不是普通的shell。
* 一般.bash_profile里都會(huì)調(diào)用.bashrc
盡管login bash啟動(dòng)時(shí)不會(huì)自動(dòng)執(zhí)行.bashrc,慣例上會(huì)在.bash_profile中顯式調(diào)用.bashrc。
,-------------------------------------
| if [ -f ~/.bashrc ]; then
|??? . ~/.bashrc
| fi
`-------------------------------------
?.bash_profile顯示內(nèi)容如下:
# .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_E
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的.bash_profile和.bashrc说明的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ubuntu之Unable to loc
- 下一篇: shell--指“提供使用者使用界面”的