日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > linux >内容正文

linux

Linux中环境变量文件profile、bashrc、bash_profile之间的区别和联系

發(fā)布時(shí)間:2025/5/22 linux 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Linux中环境变量文件profile、bashrc、bash_profile之间的区别和联系 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

/etc/profile:此文件為系統(tǒng)的每個(gè)用戶設(shè)置環(huán)境信息,當(dāng)用戶第一次登錄時(shí),該文件被執(zhí)行.并從/etc/profile.d目錄的配置文件中搜集shell的設(shè)置.

英文描述為:

# /etc/profile

# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc

# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.

所以如果你有對(duì)/etc/profile有修改的話必須得重啟你的修改才會(huì)生效,此修改對(duì)每個(gè)用戶都生效。

/etc/bashrc:為每一個(gè)運(yùn)行bash shell的用戶執(zhí)行此文件.當(dāng)bash shell被打開時(shí),該文件被讀取.

英文描述為:

# /etc/bashrc

# System wide functions and aliases
# Environment stuff goes in /etc/profile

# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.

如果你想對(duì)所有的使用bash的用戶修改某個(gè)配置并在以后打開的bash都生效的話可以修改這個(gè)文件,修改這個(gè)文件不用重啟,重新打開一個(gè)bash即可生效。

~/.bash_profile:每個(gè)用戶都可使用該文件輸入專用于自己使用的shell信息,當(dāng)用戶登錄時(shí),該文件僅僅執(zhí)行一次!默認(rèn)情況下,他設(shè)置一些環(huán)境變量,執(zhí)行用戶的.bashrc文件.

此文件類似于/etc/profile,也是需要需要重啟才會(huì)生效,/etc/profile對(duì)所有用戶生效,~/.bash_profile只對(duì)當(dāng)前用戶生效。

~/.bashrc:該文件包含專用于你的bash shell的bash信息,當(dāng)?shù)卿洉r(shí)以及每次打開新的shell時(shí),該文件被讀取.(每個(gè)用戶都有一個(gè).bashrc文件,在用戶目錄下)

此文件類似于/etc/bashrc,不需要重啟生效,重新打開一個(gè)bash即可生效,??/etc/bashrc對(duì)所有用戶新打開的bash都生效,但~/.bashrc只對(duì)當(dāng)前用戶新打開的bash生效。

~/.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)用后者。

轉(zhuǎn)載于:https://www.cnblogs.com/huangmr0811/p/5571047.html

《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀

總結(jié)

以上是生活随笔為你收集整理的Linux中环境变量文件profile、bashrc、bash_profile之间的区别和联系的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。