新聞中心
bashrc與profile有什么區(qū)別?,要搞清bashrc與profile的區(qū)別首先要弄明白什么是交互式shell和非交互式shell,什么是login shell 和non-login shell,下面為大家分享一下bashrc與profile具體區(qū)別。

創(chuàng)新互聯(lián)長期為上千余家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對不同對象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為泌陽企業(yè)提供專業(yè)的網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè),泌陽網(wǎng)站改版等技術(shù)服務(wù)。擁有十多年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開發(fā)。
交互式模式就是shell等待你的輸入,并且執(zhí)行你提交的命令。這種模式被稱作交互式是因?yàn)閟hell與用戶進(jìn)行交互。這種模式也是大多數(shù)用戶非常熟悉的:登錄、執(zhí)行一些命令、簽退。當(dāng)你簽退后,shell也終止了。 shell也可以運(yùn)行在另外一種模式:非交互式模式。在這種模式下,shell不與你進(jìn)行交互,而是讀取存放在文件中的命令,并且執(zhí)行它們。當(dāng)它讀到文件的結(jié)尾,shell也就終止了。
? 對于個(gè)別用戶的啟動配置文件
用戶HOME(家)目錄/.bashrc
head -1 ~/.bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
用戶HOME(家)目錄/.profile
head -1 ~/.profile
# ~/.profile: executed by Bourne-compatible login shells.
? 對于全部用戶的啟動配置文件
head -1 /etc/bash.bashrc
# System-wide .bashrc file for interactive bash(1) shells.
head -2 /etc/profile
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1)
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
? bashrc和profile的差異
從上面的英文描述可以知道,bashrc和profile的差異在于:
1. bashrc是在系統(tǒng)啟動后就會自動運(yùn)行。
2. profile是在用戶登錄后才會運(yùn)行。
3. 進(jìn)行設(shè)置后,可運(yùn)用source bashrc命令更新bashrc,也可運(yùn)用source profile命令更新profile。
PS:通常我們修改bashrc,有些linux的發(fā)行版本不一定有profile這個(gè)文件,本文用的系統(tǒng)是Ubuntu 15.10
4. /etc/profile中設(shè)定的變量(全局)的可以作用于任何用戶,而~/.bashrc等中設(shè)定的變量(局部)只能繼承/etc/profile中的變量,他們是"父子"關(guān)系。
? 補(bǔ)充介紹
另外,需要補(bǔ)充說明介紹bashrc相關(guān)的幾個(gè)文件: ~/.bash_profile: 每個(gè)用戶都可使用該文件輸入專用于自己使用的shell信息,當(dāng)用戶登錄時(shí),該文件僅僅執(zhí)行一次!默認(rèn)情況下,他設(shè)置一些環(huán)境變量,執(zhí)行用戶的.bashrc文件。 ~/.bash_logout: 當(dāng)每次退出系統(tǒng)(退出bash shell)時(shí),執(zhí)行該文件。 ~/.bash_profile 是交互式、login方式進(jìn)入bash運(yùn)行的,~/.bashrc是
本文名稱:詳解bashrc與profile區(qū)別
分享地址:http://m.fisionsoft.com.cn/article/djjjojs.html


咨詢
建站咨詢
