作者LinBuoRen (林博仁)
看板Linux
標題[分享] .profile.d 分散式的 profile 設定檔管理
時間Wed Apr 19 16:57:38 2017
# .profile.d #
# 分散式的 profile 設定檔管理專案 #
<
https://github.com/Lin-Buo-Ren/.profile.d>
.profile 為類 Unix 作業系統中使用者登入後會一次性載入並執行的設定檔,主要用來
設定使用者的環境變數(包含作為可執行檔搜索路徑的 `PATH` 環境變數)。
本專案是用來放置原本使用者會放置於`〈家目錄〉/.profile` 個人設定檔的腳本片段,
這樣就可以最小程度地讓使用者自訂的 .profile 片段汙染 GNU/Linux 作業系統散佈版
本提供的版本且讓該片段可以被重複利用。
您需要在家目錄中新建 .profile.d 目錄(如果該目錄原本還沒存在的話),然後將您的
profile 個人設定檔片段以 .source.sh 副檔名寫進 .profile.d 目錄中,.profile 中
的程式會自動引入(source)並執行。
## 特色 / Features ##
* 備有將指定目錄插入 shell 可執行檔搜尋路徑(`PATH` 環境變數)中的工具函式
* 如果指定目錄不存在或是 `PATH` 中已有相同路徑將不會添加,避免增加搜尋路徑的多
餘時間
## 設定 / Setup ##
1. 將本版控庫拓製(clone)或下載解開到家目錄中的 .profile.d 目錄,確定
`README.setup` 與其他檔案位於 ~/.profile.d 目錄中
2. 在 ~/.profile 設定檔中加入下列內容:
# Setup .profile.d/
#
https://github.com/Lin-Buo-Ren/.profile.d
. "${HOME}/.profile.d/README.setup"
您需要重新登出再登入才能讓設定生效
## 注意 / Remark ##
.profile 為通用的 script 程式,應使用 [POSIX.1-2008 規範的 shell script 語法
](
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html )而
非 Bash 等殼層程式的專有語法撰寫
## 授權條款 / License ##
GPLv3+
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 180.217.183.10
※ 文章網址: https://webptt.com/m.aspx?n=bbs/Linux/M.1492592267.A.91E.html
※ 編輯: LinBuoRen (180.217.183.10), 04/19/2017 16:59:24
※ 編輯: LinBuoRen (180.217.183.10), 04/19/2017 17:00:08
1F:噓 dou0228: source 裡面放中文路徑? 04/19 17:01
source 裡面放中文路徑哪裡不對了 0w0???
※ 編輯: LinBuoRen (180.217.183.10), 04/19/2017 17:48:58
2F:推 holishing: 純補個血 04/19 17:58
3F:推 Alica: 複製貼上一不小心就u8←→b5轉碼了 還是盡量避免啦 04/19 18:09
平常遇不到這個使用情境,可以講得更詳細一點嗎?
※ 編輯: LinBuoRen (180.217.183.10), 04/19/2017 18:14:00
4F:→ kenduest: 其實不同 shell 基本上設定檔案不大一樣 04/19 19:07
5F:→ kenduest: centos 來說用 bash, bash 是有機會讀取 .profile 04/19 19:07
6F:→ kenduest: 但是那也是 .bash_profile 找不到這類才有機會使用到 04/19 19:08
一般來說解法是在 .bash_profile 中再 source .profile
7F:推 Bencrie: 幫補 04/19 19:36
※ 編輯: LinBuoRen (61.228.183.179), 04/19/2017 20:05:59
8F:→ kenduest: 一般 centos 的 .bash_profile 主要是讀入 .bashrc 04/19 20:08
profile 跟 run commands 用途應該差蠻多的才對
profile 只有 login shell 會讀,run commands 則是 shell 每次載入必讀
老實說我不太能理解為何需要在 *profile 中 source bashrc?
更新:剛剛查了一下不知道為什麼 bash 的 login shell 真的不會讀 bashrc,需要在 *profile 中主動 source 才會讀
9F:→ kenduest: source .profile 必要性?其實我感覺主要是使用者 04/19 20:08
10F:→ kenduest: 要瞭解 shell 程式讀取檔案的項目,貿然套 .profile 04/19 20:08
11F:→ kenduest: 不一定也正確。有人用 csh 這類不就破工了? 檔名不同 04/19 20:09
不相容 POSIX 的 shell 本來就沒轍啊
12F:→ kenduest: 簡單說這篇文章陳述的內容考量部分比較少就是 04/19 20:11
※ 編輯: LinBuoRen (61.228.183.179), 04/19/2017 20:38:40
※ 編輯: LinBuoRen (61.228.183.179), 04/19/2017 20:39:45
※ 編輯: LinBuoRen (61.228.183.179), 04/19/2017 20:58:53
※ 編輯: LinBuoRen (61.228.183.179), 04/19/2017 21:05:24
13F:推 ddtsatan: 推 04/19 21:55
14F:→ kenduest: 原帖樓主可以裝一下redhat或是centos瞭解它的設定檔案 04/19 22:22
15F:→ kenduest: 設定規劃流程 04/19 22:22
16F:→ kenduest: 整體來說個人覺得您這一篇整個幫助性不高 04/19 22:23
17F:→ kenduest: 其實你只需要提供簡單幾行 for 迴圈敘述就好了 04/19 22:25
18F:→ kenduest: 說明提供的一些腳本達能目的用途就好了 04/19 22:30
其實無所謂,因為我是拿來滿足我自己的需求用的
※ 編輯: LinBuoRen (61.228.183.179), 04/20/2017 00:19:57
19F:→ kpier2: 釣老人也很好用 XD 04/20 01:00
20F:→ kenduest: 老人大多有自己一套方式 04/20 16:39
21F:推 rickieyang: Life finds a way... 04/20 17:22
22F:推 Neisseria: 其實直接改 PATH 比較直觀,包成函數反而要想一下 04/22 22:20
23F:→ Neisseria: shell scripting 本來就是每個人用自已的 04/22 22:21
24F:→ Neisseria: 除非要寫 pyenv 這種工具,不用追求相容性 04/22 22:21
25F:推 jasonfenglu: 如果直接用environment modules? 04/23 15:25